1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // add smilies button to the comment field |
---|
5 | function set_smiliessupport() |
---|
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('picture', 'set_smiliessupport_prefilter'); |
---|
19 | } |
---|
20 | |
---|
21 | function set_smiliessupport_prefilter($content, &$smarty) |
---|
22 | { |
---|
23 | $search = '<div id="commentAdd">'; |
---|
24 | $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').$search; |
---|
25 | return str_replace($search, $replace, $content); |
---|
26 | } |
---|
27 | |
---|
28 | // return an array with available smilies (name and path) ## must received the unserialized configuration array |
---|
29 | function 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 |
---|
59 | function 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 | ?> |
---|