[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); |
---|
[10986] | 10 | $conf_smiliessupport = explode(',' , $conf['smiliessupport']); |
---|
| 11 | |
---|
| 12 | $smilies = get_smilies($conf_smiliessupport); |
---|
[11294] | 13 | |
---|
| 14 | // edit field has different id |
---|
| 15 | // if ( |
---|
| 16 | // (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') |
---|
| 17 | // OR (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') |
---|
| 18 | // ) { |
---|
| 19 | // $template->assign('smilies_textarea', 'contenteditid'); |
---|
| 20 | // } else { |
---|
| 21 | // $template->assign('smilies_textarea', 'contentid'); |
---|
| 22 | // } |
---|
| 23 | $template->assign('smilies_textarea', 'contentid'); |
---|
| 24 | |
---|
| 25 | $template->assign(array( |
---|
| 26 | 'SMILIES_PATH' => SMILIES_PATH, |
---|
| 27 | 'REPRESENTANT' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$conf_smiliessupport[2], |
---|
| 28 | 'smiliesfiles' => $smilies, |
---|
| 29 | )); |
---|
| 30 | |
---|
| 31 | $template->set_prefilter('picture', 'set_smiliessupport_prefilter'); |
---|
[3304] | 32 | } |
---|
| 33 | |
---|
[11294] | 34 | function set_smiliessupport_prefilter($content, &$smarty) |
---|
| 35 | { |
---|
| 36 | $search = "<label>{'Comment'|@translate}"; |
---|
| 37 | $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').$search; |
---|
| 38 | return str_replace($search, $replace, $content); |
---|
| 39 | } |
---|
| 40 | |
---|
[9966] | 41 | // return an array with available smilies (name and path) ## must received the unserialized configuration array |
---|
| 42 | function get_smilies($conf_smiliessupport) |
---|
[3304] | 43 | { |
---|
[10986] | 44 | $accepted_ext = array('gif', 'jpg', 'png'); |
---|
| 45 | |
---|
| 46 | if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0])) |
---|
| 47 | { |
---|
| 48 | $i = 1; |
---|
| 49 | while (false !== ($file = readdir($handle))) |
---|
| 50 | { |
---|
| 51 | if ($file != '.' AND $file != '..' AND in_array(get_extension($file), $accepted_ext)) |
---|
| 52 | { |
---|
| 53 | $smilies[] = array( |
---|
| 54 | 'PATH' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$file, |
---|
| 55 | 'TITLE' => ':'.get_filename_wo_extension($file).':', |
---|
| 56 | 'TR' => ($i>0 AND $i%$conf_smiliessupport[1] == 0) ? '</tr><tr>' : null, |
---|
| 57 | ); |
---|
| 58 | $i++; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | return $smilies; |
---|
[11294] | 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
[10986] | 66 | return false; |
---|
| 67 | } |
---|
[9966] | 68 | } |
---|
| 69 | |
---|
| 70 | // parse smilies |
---|
[3304] | 71 | function SmiliesParse($str) |
---|
| 72 | { |
---|
[10986] | 73 | global $conf; |
---|
[9683] | 74 | |
---|
[10986] | 75 | $conf_smiliessupport = explode("," , $conf['smiliessupport']); |
---|
| 76 | $def_path = $conf_smiliessupport[0].'/smilies.txt'; |
---|
| 77 | $accepted_ext = array('gif', 'jpg', 'png'); |
---|
[11294] | 78 | $str = ' '.$str; |
---|
[10986] | 79 | |
---|
| 80 | if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0])) |
---|
| 81 | { |
---|
| 82 | while (false !== ($file = readdir($handle))) |
---|
| 83 | { |
---|
[11294] | 84 | if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) |
---|
| 85 | { |
---|
| 86 | $filename = get_filename_wo_extension($file); |
---|
| 87 | $v = ':'.$filename.':'; |
---|
| 88 | $s = '<img src="'.$conf_smiliessupport[0].'/'.$file.'" alt=":'.$filename.':"/>'; |
---|
[10986] | 89 | $str = str_replace($v, $s, $str); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if (file_exists($def_path)) |
---|
| 95 | { |
---|
| 96 | $def = file($def_path); |
---|
| 97 | foreach($def as $v) |
---|
| 98 | { |
---|
| 99 | $v = trim($v); |
---|
[11294] | 100 | if (preg_match('#^([^\t]+)[ \t]+(.+)$#', $v, $matches)) |
---|
| 101 | { |
---|
| 102 | $filename = get_filename_wo_extension($matches[2]); |
---|
[11450] | 103 | $v = '#([^"])'.preg_quote($matches[1],'/').'#'; |
---|
| 104 | $t = '$1<img src="'.$conf_smiliessupport[0].'/'.$matches[2].'" alt=":'.$filename.':"/>'; |
---|
[11294] | 105 | $str = preg_replace($v, $t, $str); |
---|
[10986] | 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
[11294] | 110 | return trim($str); |
---|
[3304] | 111 | } |
---|
[9683] | 112 | |
---|
[3304] | 113 | ?> |
---|