Index: extensions/SmiliesSupport/include/events.inc.php
===================================================================
--- extensions/SmiliesSupport/include/smiliessupport.inc.php	(revision 23236)
+++ extensions/SmiliesSupport/include/events.inc.php	(revision 26075)
@@ -1,55 +1,61 @@
 <?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('SMILIES_ID') or die('Hacking attempt!');
 
-// add smilies button to the comment field
-function set_smiliessupport($prefilter='picture', $textarea_id='contentid')
+function smiliessupport_admin_menu($menu) 
 {
-  global $conf, $template;
+  $menu[] = array(
+    'NAME' => 'Smilies Support',
+    'URL' => SMILIES_ADMIN,
+    );
+  return $menu;
+}
+
+function add_smiliessupport() 
+{
+  global $page, $pwg_loaded_plugins, $template, $conf;
+  
+  if (script_basename() == 'picture') 
+  {
+    $prefilter = 'picture';
+    $textarea_id = 'contentid';
+  }
+  else if (isset($page['section']))
+  {
+    if (
+      script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums'])
+      and $page['section'] == 'categories' and isset($page['category'])
+      )
+    {
+      $prefilter = 'comments_on_albums';
+      $textarea_id = 'contentid';
+    }
+    else if ($page['section'] == 'guestbook') 
+    {
+      $prefilter = 'guestbook';
+      $textarea_id = 'contentid';
+    }
+    else if ($page['section'] == 'contact') 
+    {
+      $prefilter = 'contactform';
+      $textarea_id = 'cf_content';
+    }
+  }
+  
+  if (!isset($prefilter))
+  {
+    return;
+  }
 
   $template->assign(array(
     'SMILIES_PATH' => SMILIES_PATH,
-    'SMILIES_ID' =>   $textarea_id,
-    'REPRESENTANT' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$conf['smiliessupport']['representant'],
-    'smiliesfiles' => get_smilies(),
-  ));
-  
-  $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter');  
-}
-
-function set_smiliessupport_prefilter($content, &$smarty)
-{
-  $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#';
-  $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1';
-  return preg_replace($search, $replace, $content);
-}
-
-// return an array with available smilies (name and path)
-function get_smilies()
-{
-  global $conf;
-  
-  if ($handle = opendir(SMILIES_DIR.$conf['smiliessupport']['folder']))
-  {
-    $i = 1;
-    while (false !== ($file = readdir($handle)))
-    {
-      if ($file != '.' and $file != '..' and in_array(get_extension($file), $conf['smiliessupport']['ext']))
-      {
-        $smilies[] = array(
-          'PATH' => SMILIES_DIR.$conf['smiliessupport']['folder'].'/'.$file,
-          'TITLE' => ':'.get_filename_wo_extension($file).':',
-          'TR' => ($i>0 and $i%$conf['smiliessupport']['cols'] == 0) ? '</tr><tr>' : null,
-        );
-        $i++;
-      }
-    }
+    'SMILIES' => array(
+      'textarea_id' => $textarea_id,
+      'representant' => SMILIES_DIR . $conf['smiliessupport']['folder'] . '/' . $conf['smiliessupport']['representant'],
+      'files' => get_smilies(),
+      ),
+    ));
     
-    closedir($handle);
-    return $smilies;
-  } 
-  else 
-  {
-    return false;
-  }
+  $template->set_filename('smiliessupport', realpath(SMILIES_PATH . 'template/smiliessupport_page.tpl'));
+  $template->parse('smiliessupport');
 }
 
@@ -67,5 +73,5 @@
     while (false !== ($file = readdir($handle)))
     { 
-      if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport']['ext'])) 
+      if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport_ext'])) 
       {
         $filename = get_filename_wo_extension($file);
@@ -105,3 +111,54 @@
 }
 
-?>
+function smiliessupport_action()
+{
+  if (!isset($_GET['action'])) return;
+  if (strpos($_GET['action'], 'ss_') !== 0) return;
+  
+  global $conf;
+  
+  $folder = SMILIES_DIR . ltrim($_GET['folder'], '/') . '/';
+  
+  if ($_GET['action'] == 'ss_reset')
+  {
+    @unlink($folder.'smilies-custom.txt');
+    $_GET['action'] = 'ss_list';
+  }
+  else if ($_GET['action'] == 'ss_list')
+  {
+    $short = array();
+    if (file_exists($folder.'smilies-custom.txt'))
+    {
+      $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES);
+    }
+    else if (file_exists($folder.'smilies.txt'))
+    {
+      $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES);
+    }
+    if (!empty($file))
+    {
+      foreach ($file as $v)
+      {
+        if (preg_match('#^([^\s]+)[\s]+(.+)$#', trim($v), $matches)) 
+        {
+          $short[ $matches[2] ][] = $matches[1];
+        }
+      }
+    }
+
+    $smilies = array();
+    $handle = opendir($folder);
+    while (false !== ($file = readdir($handle)))
+    {
+      if ( $file != '.' && $file != '..' && in_array(get_extension($file), $conf['smiliessupport_ext']) )
+      {
+        $smilies[$file] = array('title'=>':'.get_filename_wo_extension($file).':', 'file'=>$file, 'short'=>@$short[$file]);
+      }
+    }
+    closedir($handle);
+    
+    echo json_encode(array('path'=>$folder, 'smilies'=>$smilies));
+  }
+  
+  exit;
+}
