source: extensions/SmiliesSupport/smiliessupport.inc.php @ 15997

Last change on this file since 15997 was 15997, checked in by mistic100, 12 years ago

move some code from Comments on Albums and compatible with GuestBook

File size: 3.1 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')
6{
7  global $conf, $template, $page;
8 
9  load_language('plugin.lang', SMILIES_PATH);
10  $conf_smiliessupport = unserialize($conf['smiliessupport']);
11
12  $template->assign(array(
13    'SMILIES_PATH' => SMILIES_PATH,
14    'REPRESENTANT' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant'],
15    'smiliesfiles' => get_smilies($conf_smiliessupport),
16  ));
17 
18  $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); 
19}
20
21function set_smiliessupport_prefilter($content, &$smarty)
22{
23  $search = '#(<div id="guestbookAdd">|<div id="commentAdd">)#';
24  $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1';
25  return preg_replace($search, $replace, $content);
26}
27
28// return an array with available smilies (name and path) ## must received the unserialized configuration array
29function get_smilies($conf_smiliessupport)
30{
31  $accepted_ext = array('gif', 'jpg', 'png');
32 
33  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
34  {
35    $i = 1;
36    while (false !== ($file = readdir($handle)))
37    {
38      if ($file != '.' AND $file != '..' AND in_array(get_extension($file), $accepted_ext))
39      {
40        $smilies[] = array(
41          'PATH' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file,
42          'TITLE' => ':'.get_filename_wo_extension($file).':',
43          'TR' => ($i>0 AND $i%$conf_smiliessupport['cols'] == 0) ? '</tr><tr>' : null,
44        );
45        $i++;
46      }
47    }
48   
49    closedir($handle);
50    return $smilies;
51  } 
52  else 
53  {
54    return false;
55  }
56}
57
58// parse smilies
59function SmiliesParse($str)
60{
61  global $conf;
62
63  $conf_smiliessupport = unserialize($conf['smiliessupport']);
64  $def_path = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
65  $accepted_ext = array('gif', 'jpg', 'png');
66  $str = ' '.$str;
67 
68  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
69  {
70    while (false !== ($file = readdir($handle)))
71    { 
72      if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) 
73      {
74        $filename = get_filename_wo_extension($file);
75        $v = ':'.$filename.':'; 
76        $s = '<img src="'.SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file.'" alt=":'.$filename.':"/>';
77        $str = str_replace($v, $s, $str);
78      }
79    }
80   
81    closedir($handle);
82  }
83 
84  if (file_exists($def_path))
85  {
86    $def = file($def_path);
87    foreach($def as $v)
88    {
89      $v = trim($v);
90      if (preg_match('#^([^\t]+)[ \t]+(.+)$#', $v, $matches)) 
91      { 
92        $filename = get_filename_wo_extension($matches[2]);
93        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
94        $t = '$1<img src="'.SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$matches[2].'" alt=":'.$filename.':"/>';
95        $str = preg_replace($v, $t, $str);
96      }
97    }
98  } 
99 
100  return trim($str);
101}
102
103?>
Note: See TracBrowser for help on using the repository browser.