[23234] | 1 | <?php |
---|
[26075] | 2 | defined('SMILIES_ID') or die('Hacking attempt!'); |
---|
[23234] | 3 | |
---|
[26075] | 4 | function smiliessupport_admin_menu($menu) |
---|
[23234] | 5 | { |
---|
[26075] | 6 | $menu[] = array( |
---|
| 7 | 'NAME' => 'Smilies Support', |
---|
| 8 | 'URL' => SMILIES_ADMIN, |
---|
| 9 | ); |
---|
| 10 | return $menu; |
---|
[23234] | 11 | } |
---|
| 12 | |
---|
[26075] | 13 | function add_smiliessupport() |
---|
[23234] | 14 | { |
---|
[26075] | 15 | global $page, $pwg_loaded_plugins, $template, $conf; |
---|
[23234] | 16 | |
---|
[26075] | 17 | if (script_basename() == 'picture') |
---|
[23234] | 18 | { |
---|
[26075] | 19 | $prefilter = 'picture'; |
---|
| 20 | $textarea_id = 'contentid'; |
---|
| 21 | } |
---|
| 22 | else if (isset($page['section'])) |
---|
| 23 | { |
---|
| 24 | if ( |
---|
| 25 | script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums']) |
---|
| 26 | and $page['section'] == 'categories' and isset($page['category']) |
---|
| 27 | ) |
---|
[23234] | 28 | { |
---|
[26075] | 29 | $prefilter = 'comments_on_albums'; |
---|
| 30 | $textarea_id = 'contentid'; |
---|
[23234] | 31 | } |
---|
[26075] | 32 | else if ($page['section'] == 'guestbook') |
---|
| 33 | { |
---|
| 34 | $prefilter = 'guestbook'; |
---|
| 35 | $textarea_id = 'contentid'; |
---|
| 36 | } |
---|
| 37 | else if ($page['section'] == 'contact') |
---|
| 38 | { |
---|
| 39 | $prefilter = 'contactform'; |
---|
| 40 | $textarea_id = 'cf_content'; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | if (!isset($prefilter)) |
---|
[23234] | 45 | { |
---|
[26075] | 46 | return; |
---|
[23234] | 47 | } |
---|
[26075] | 48 | |
---|
| 49 | $template->assign(array( |
---|
| 50 | 'SMILIES_PATH' => SMILIES_PATH, |
---|
| 51 | 'SMILIES' => array( |
---|
| 52 | 'textarea_id' => $textarea_id, |
---|
| 53 | 'representant' => SMILIES_DIR . $conf['smiliessupport']['folder'] . '/' . $conf['smiliessupport']['representant'], |
---|
| 54 | 'files' => get_smilies(), |
---|
| 55 | ), |
---|
| 56 | )); |
---|
| 57 | |
---|
| 58 | $template->set_filename('smiliessupport', realpath(SMILIES_PATH . 'template/smiliessupport_page.tpl')); |
---|
| 59 | $template->parse('smiliessupport'); |
---|
[23234] | 60 | } |
---|
| 61 | |
---|
| 62 | // parse smilies |
---|
| 63 | function SmiliesParse($str) |
---|
| 64 | { |
---|
| 65 | global $conf; |
---|
[11294] | 66 | |
---|
[23234] | 67 | $root_path = get_absolute_root_url(); |
---|
| 68 | $folder = SMILIES_DIR.$conf['smiliessupport']['folder'].'/'; |
---|
| 69 | $str = ' '.$str; |
---|
| 70 | |
---|
| 71 | if ($handle = opendir($folder)) |
---|
| 72 | { |
---|
| 73 | while (false !== ($file = readdir($handle))) |
---|
| 74 | { |
---|
[26075] | 75 | if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport_ext'])) |
---|
[23234] | 76 | { |
---|
| 77 | $filename = get_filename_wo_extension($file); |
---|
| 78 | $v = ':'.$filename.':'; |
---|
| 79 | $s = '<img src="'.$root_path.$folder.$file.'" alt=":'.$filename.':"/>'; |
---|
| 80 | $str = str_replace($v, $s, $str); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | closedir($handle); |
---|
| 85 | } |
---|
| 86 | |
---|
[23236] | 87 | if (file_exists($folder.'smilies-custom.txt')) |
---|
[23234] | 88 | { |
---|
[23236] | 89 | $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES); |
---|
| 90 | } |
---|
| 91 | else if (file_exists($folder.'smilies.txt')) |
---|
| 92 | { |
---|
| 93 | $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES); |
---|
| 94 | } |
---|
| 95 | if (!empty($file)) |
---|
| 96 | { |
---|
| 97 | foreach ($file as $v) |
---|
[23234] | 98 | { |
---|
| 99 | $v = trim($v); |
---|
| 100 | if (preg_match('#^([^\s]+)[\s]+(.+)$#', $v, $matches)) |
---|
| 101 | { |
---|
| 102 | $filename = get_filename_wo_extension($matches[2]); |
---|
| 103 | $v = '#([^"])'.preg_quote($matches[1],'/').'#'; |
---|
| 104 | $t = '$1<img src="'.$root_path.$folder.$matches[2].'" alt=":'.$filename.':"/>'; |
---|
| 105 | $str = preg_replace($v, $t, $str); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | return trim($str); |
---|
| 111 | } |
---|
| 112 | |
---|
[26075] | 113 | function smiliessupport_action() |
---|
| 114 | { |
---|
| 115 | if (!isset($_GET['action'])) return; |
---|
| 116 | if (strpos($_GET['action'], 'ss_') !== 0) return; |
---|
| 117 | |
---|
| 118 | global $conf; |
---|
| 119 | |
---|
| 120 | $folder = SMILIES_DIR . ltrim($_GET['folder'], '/') . '/'; |
---|
| 121 | |
---|
| 122 | if ($_GET['action'] == 'ss_reset') |
---|
| 123 | { |
---|
| 124 | @unlink($folder.'smilies-custom.txt'); |
---|
| 125 | $_GET['action'] = 'ss_list'; |
---|
| 126 | } |
---|
| 127 | else if ($_GET['action'] == 'ss_list') |
---|
| 128 | { |
---|
| 129 | $short = array(); |
---|
| 130 | if (file_exists($folder.'smilies-custom.txt')) |
---|
| 131 | { |
---|
| 132 | $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES); |
---|
| 133 | } |
---|
| 134 | else if (file_exists($folder.'smilies.txt')) |
---|
| 135 | { |
---|
| 136 | $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES); |
---|
| 137 | } |
---|
| 138 | if (!empty($file)) |
---|
| 139 | { |
---|
| 140 | foreach ($file as $v) |
---|
| 141 | { |
---|
| 142 | if (preg_match('#^([^\s]+)[\s]+(.+)$#', trim($v), $matches)) |
---|
| 143 | { |
---|
| 144 | $short[ $matches[2] ][] = $matches[1]; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | $smilies = array(); |
---|
| 150 | $handle = opendir($folder); |
---|
| 151 | while (false !== ($file = readdir($handle))) |
---|
| 152 | { |
---|
| 153 | if ( $file != '.' && $file != '..' && in_array(get_extension($file), $conf['smiliessupport_ext']) ) |
---|
| 154 | { |
---|
| 155 | $smilies[$file] = array('title'=>':'.get_filename_wo_extension($file).':', 'file'=>$file, 'short'=>@$short[$file]); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | closedir($handle); |
---|
| 159 | |
---|
| 160 | echo json_encode(array('path'=>$folder, 'smilies'=>$smilies)); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | exit; |
---|
| 164 | } |
---|