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

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

rewrite admin page
new set from Pidgin

File size: 2.7 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.txt'))
82  {
83    foreach (file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES) as $v)
84    {
85      $v = trim($v);
86      if (preg_match('#^([^\s]+)[\s]+(.+)$#', $v, $matches)) 
87      { 
88        $filename = get_filename_wo_extension($matches[2]);
89        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
90        $t = '$1<img src="'.$root_path.$folder.$matches[2].'" alt=":'.$filename.':"/>';
91        $str = preg_replace($v, $t, $str);
92      }
93    }
94  } 
95 
96  return trim($str);
97}
98
99?>
Note: See TracBrowser for help on using the repository browser.