source: extensions/SmiliesSupport/include/smiliessupport.inc.php @ 23236

Last change on this file since 23236 was 23236, checked in by mistic100, 11 years ago

two columns display for shortcuts form, keep save of original smilies.txt file

File size: 2.9 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// add smilies button to the comment field
5function set_smiliessupport($prefilter='picture', $textarea_id='contentid')
6{
7  global $conf, $template;
8
9  $template->assign(array(
10    'SMILIES_PATH' => SMILIES_PATH,
11    'SMILIES_ID' =>   $textarea_id,
12    'REPRESENTANT' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$conf['smiliessupport']['representant'],
13    'smiliesfiles' => get_smilies(),
14  ));
15 
16  $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); 
17}
18
19function set_smiliessupport_prefilter($content, &$smarty)
20{
21  $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#';
22  $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1';
23  return preg_replace($search, $replace, $content);
24}
25
26// return an array with available smilies (name and path)
27function get_smilies()
28{
29  global $conf;
30 
31  if ($handle = opendir(SMILIES_DIR.$conf['smiliessupport']['folder']))
32  {
33    $i = 1;
34    while (false !== ($file = readdir($handle)))
35    {
36      if ($file != '.' and $file != '..' and in_array(get_extension($file), $conf['smiliessupport']['ext']))
37      {
38        $smilies[] = array(
39          'PATH' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$file,
40          'TITLE' => ':'.get_filename_wo_extension($file).':',
41          'TR' => ($i>0 and $i%$conf['smiliessupport']['cols'] == 0) ? '</tr><tr>' : null,
42        );
43        $i++;
44      }
45    }
46   
47    closedir($handle);
48    return $smilies;
49  } 
50  else 
51  {
52    return false;
53  }
54}
55
56// parse smilies
57function SmiliesParse($str)
58{
59  global $conf;
60 
61  $root_path = get_absolute_root_url();
62  $folder = SMILIES_DIR.$conf['smiliessupport']['folder'].'/';
63  $str = ' '.$str;
64 
65  if ($handle = opendir($folder))
66  {
67    while (false !== ($file = readdir($handle)))
68    { 
69      if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport']['ext'])) 
70      {
71        $filename = get_filename_wo_extension($file);
72        $v = ':'.$filename.':'; 
73        $s = '<img src="'.$root_path.$folder.$file.'" alt=":'.$filename.':"/>';
74        $str = str_replace($v, $s, $str);
75      }
76    }
77   
78    closedir($handle);
79  }
80 
81  if (file_exists($folder.'smilies-custom.txt'))
82  {
83    $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES);
84  }
85  else if (file_exists($folder.'smilies.txt'))
86  {
87    $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES);
88  }
89  if (!empty($file))
90  {
91    foreach ($file as $v)
92    {
93      $v = trim($v);
94      if (preg_match('#^([^\s]+)[\s]+(.+)$#', $v, $matches)) 
95      { 
96        $filename = get_filename_wo_extension($matches[2]);
97        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
98        $t = '$1<img src="'.$root_path.$folder.$matches[2].'" alt=":'.$filename.':"/>';
99        $str = preg_replace($v, $t, $str);
100      }
101    }
102  } 
103 
104  return trim($str);
105}
106
107?>
Note: See TracBrowser for help on using the repository browser.