[3304] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[9966] | 4 | // add smilies button to the comment field |
---|
[15997] | 5 | function set_smiliessupport($prefilter='picture') |
---|
[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 | |
---|
[15997] | 18 | $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); |
---|
[3304] | 19 | } |
---|
| 20 | |
---|
[11294] | 21 | function set_smiliessupport_prefilter($content, &$smarty) |
---|
| 22 | { |
---|
[15997] | 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); |
---|
[11294] | 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']); |
---|
[20208] | 64 | $folder = get_root_url().SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']; |
---|
[14526] | 65 | $def_path = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt'; |
---|
[10986] | 66 | $accepted_ext = array('gif', 'jpg', 'png'); |
---|
[11294] | 67 | $str = ' '.$str; |
---|
[10986] | 68 | |
---|
[14526] | 69 | if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'])) |
---|
[10986] | 70 | { |
---|
| 71 | while (false !== ($file = readdir($handle))) |
---|
| 72 | { |
---|
[11294] | 73 | if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) |
---|
| 74 | { |
---|
| 75 | $filename = get_filename_wo_extension($file); |
---|
| 76 | $v = ':'.$filename.':'; |
---|
[20208] | 77 | $s = '<img src="'.$folder.'/'.$file.'" alt=":'.$filename.':"/>'; |
---|
[10986] | 78 | $str = str_replace($v, $s, $str); |
---|
| 79 | } |
---|
| 80 | } |
---|
[14526] | 81 | |
---|
| 82 | closedir($handle); |
---|
[10986] | 83 | } |
---|
| 84 | |
---|
| 85 | if (file_exists($def_path)) |
---|
| 86 | { |
---|
| 87 | $def = file($def_path); |
---|
| 88 | foreach($def as $v) |
---|
| 89 | { |
---|
| 90 | $v = trim($v); |
---|
[11294] | 91 | if (preg_match('#^([^\t]+)[ \t]+(.+)$#', $v, $matches)) |
---|
| 92 | { |
---|
| 93 | $filename = get_filename_wo_extension($matches[2]); |
---|
[11450] | 94 | $v = '#([^"])'.preg_quote($matches[1],'/').'#'; |
---|
[20208] | 95 | $t = '$1<img src="'.$folder.'/'.$matches[2].'" alt=":'.$filename.':"/>'; |
---|
[11294] | 96 | $str = preg_replace($v, $t, $str); |
---|
[10986] | 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
[11294] | 101 | return trim($str); |
---|
[3304] | 102 | } |
---|
[9683] | 103 | |
---|
[3304] | 104 | ?> |
---|