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