Changeset 26075 for extensions/SmiliesSupport/include/events.inc.php
- Timestamp:
- Dec 21, 2013, 11:02:21 PM (10 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmiliesSupport/include/events.inc.php
r24342 r26075 1 1 <?php 2 if (!defined('PHPWG_ROOT_PATH'))die('Hacking attempt!');2 defined('SMILIES_ID') or die('Hacking attempt!'); 3 3 4 // add smilies button to the comment field 5 function set_smiliessupport($prefilter='picture', $textarea_id='contentid') 4 function smiliessupport_admin_menu($menu) 6 5 { 7 global $conf, $template; 6 $menu[] = array( 7 'NAME' => 'Smilies Support', 8 'URL' => SMILIES_ADMIN, 9 ); 10 return $menu; 11 } 12 13 function add_smiliessupport() 14 { 15 global $page, $pwg_loaded_plugins, $template, $conf; 16 17 if (script_basename() == 'picture') 18 { 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 ) 28 { 29 $prefilter = 'comments_on_albums'; 30 $textarea_id = 'contentid'; 31 } 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)) 45 { 46 return; 47 } 8 48 9 49 $template->assign(array( 10 50 'SMILIES_PATH' => SMILIES_PATH, 11 'SMILIES_ID' => $textarea_id, 12 'REPRESENTANT' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$conf['smiliessupport']['representant'], 13 'smiliesfiles' => get_smilies(), 14 )); 15 16 $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); 17 } 18 19 function set_smiliessupport_prefilter($content, &$smarty) 20 { 21 $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#'; 22 $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1'; 23 return preg_replace($search, $replace, $content); 24 } 25 26 // return an array with available smilies (name and path) 27 function get_smilies() 28 { 29 global $conf; 30 31 if ($handle = opendir(SMILIES_DIR.$conf['smiliessupport']['folder'])) 32 { 33 $i = 1; 34 while (false !== ($file = readdir($handle))) 35 { 36 if ($file != '.' and $file != '..' and in_array(get_extension($file), $conf['smiliessupport']['ext'])) 37 { 38 $smilies[] = array( 39 'PATH' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$file, 40 'TITLE' => ':'.get_filename_wo_extension($file).':', 41 'TR' => ($i>0 and $i%$conf['smiliessupport']['cols'] == 0) ? '</tr><tr>' : null, 42 ); 43 $i++; 44 } 45 } 51 'SMILIES' => array( 52 'textarea_id' => $textarea_id, 53 'representant' => SMILIES_DIR . $conf['smiliessupport']['folder'] . '/' . $conf['smiliessupport']['representant'], 54 'files' => get_smilies(), 55 ), 56 )); 46 57 47 closedir($handle); 48 return $smilies; 49 } 50 else 51 { 52 return false; 53 } 58 $template->set_filename('smiliessupport', realpath(SMILIES_PATH . 'template/smiliessupport_page.tpl')); 59 $template->parse('smiliessupport'); 54 60 } 55 61 … … 67 73 while (false !== ($file = readdir($handle))) 68 74 { 69 if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport ']['ext']))75 if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport_ext'])) 70 76 { 71 77 $filename = get_filename_wo_extension($file); … … 105 111 } 106 112 107 ?> 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 }
Note: See TracChangeset
for help on using the changeset viewer.