Index: /extensions/SmiliesSupport/main.inc.php
===================================================================
--- /extensions/SmiliesSupport/main.inc.php	(revision 3304)
+++ /extensions/SmiliesSupport/main.inc.php	(revision 3304)
@@ -0,0 +1,34 @@
+<?php /*
+Plugin Name: SmiliesSupport
+Version: 2.0.a
+Description: Allow add Smilies for comments and descriptions. / Permet d'ajouter des Smilies pour les commentaires et les descriptions.
+Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=159
+Author: Atadilo
+Author URI: http://www.phpwebgallery.net
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+include_once(dirname(__FILE__).'/smiliessupport.inc.php');
+
+add_event_handler('init', 'init_smiliessupport');
+add_event_handler('render_comment_content', 'SmiliesParse', 60);
+add_event_handler('loc_begin_picture', 'set_smiliessupport_page');
+
+function init_smiliessupport()
+{
+  remove_event_handler('render_comment_content', 'parse_comment_content');
+}
+
+if (script_basename() == 'admin')
+{
+  add_event_handler('get_admin_plugin_menu_links', 'smiliessupport_admin_menu');
+
+  function smiliessupport_admin_menu($menu) {
+      array_push($menu,
+        array('NAME' => 'SmiliesSupport',
+              'URL' => get_admin_plugin_menu_link(dirname(__FILE__) . '/smiliessupport_admin.php')));
+      return $menu;
+  }
+}
+?>
Index: /extensions/SmiliesSupport/maintain.inc.php
===================================================================
--- /extensions/SmiliesSupport/maintain.inc.php	(revision 3304)
+++ /extensions/SmiliesSupport/maintain.inc.php	(revision 3304)
@@ -0,0 +1,25 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+function plugin_install()
+{
+  global $conf;
+
+  if (!isset($conf['smiliessupport']))
+  {
+    $q = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
+VALUES ("smiliessupport","plugins/SmiliesSupport/smilies,5,sourire.gif","Parametres SmiliesSupport");';
+    pwg_query($q);
+  }
+}
+
+function plugin_uninstall()
+{
+  global $conf;
+
+  if (isset($conf['smiliessupport']))
+  {
+    pwg_query('DELETE FROM ' . CONFIG_TABLE . ' WHERE param="smiliessupport" LIMIT 1;');
+  }
+}
Index: /extensions/SmiliesSupport/smilies/smilies.bak
===================================================================
--- /extensions/SmiliesSupport/smilies/smilies.bak	(revision 3304)
+++ /extensions/SmiliesSupport/smilies/smilies.bak	(revision 3304)
@@ -0,0 +1,20 @@
+:)		sourire.gif
+:-)		sourire.gif
+:D		happy.gif
+:-D		happy.gif
+;)		wink.gif
+;-)		wink.gif
+:P		langue.gif
+:p		langue.gif
+:-p		langue.gif
+:-P		langue.gif
+:(		triste.gif
+:-(		triste.gif
+;(		pleure.gif
+;-(		pleure.gif
+oO		perplexe.gif
+Oo		perplexe.gif
+:o		surpris.gif
+:O		surpris.gif
+:-o		surpris.gif
+:-O		surpris.gif
Index: /extensions/SmiliesSupport/smilies/smilies.txt
===================================================================
--- /extensions/SmiliesSupport/smilies/smilies.txt	(revision 3304)
+++ /extensions/SmiliesSupport/smilies/smilies.txt	(revision 3304)
@@ -0,0 +1,20 @@
+:)		sourire.gif
+:-)		sourire.gif
+:D		happy.gif
+:-D		happy.gif
+;)		wink.gif
+;-)		wink.gif
+:P		langue.gif
+:p		langue.gif
+:-p		langue.gif
+:-P		langue.gif
+:(		triste.gif
+:-(		triste.gif
+;(		pleure.gif
+;-(		pleure.gif
+oO		perplexe.gif
+Oo		perplexe.gif
+:o		surpris.gif
+:O		surpris.gif
+:-o		surpris.gif
+:-O		surpris.gif
Index: /extensions/SmiliesSupport/smiliessupport.inc.php
===================================================================
--- /extensions/SmiliesSupport/smiliessupport.inc.php	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport.inc.php	(revision 3304)
@@ -0,0 +1,88 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+function set_smiliessupport_page()
+{
+  global $template, $lang, $pwg_loaded_plugins;
+
+  if (!isset($pwg_loaded_plugins['bbcode_bar']))
+  {
+    $lang['comment'] .= SmiliesTable();
+  }
+}
+
+function SmiliesTable()
+{
+  global $conf, $template;
+
+  $conf_smiliessupport = explode("," , $conf['smiliessupport']);
+
+  $cnt = 1;
+  
+  $template->set_filename('smiliessupport_page', dirname(__FILE__).'/smiliessupport_page.tpl');
+  
+  $template->assign(array('REPRESENTANT' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$conf_smiliessupport[2]));
+  
+  if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
+  {
+    while (false !== ($file = readdir($handle)))
+    {
+      $trvalue = '';
+
+      if ($file != "." && $file != ".." && ( get_extension($file) == "gif" || get_extension($file) == "png"))
+      {
+        if (( $cnt > 0 ) && ( $cnt % $conf_smiliessupport[1] == 0 ))
+        {
+          $trvalue = '</tr><tr>';
+        }
+        $cnt = $cnt + 1;
+        $template->append('smiliesfiles',
+          array('PATH' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$file,
+                'TITLE' => ':'.get_filename_wo_extension($file).':',
+                'TR'=>$trvalue));
+      }
+    }
+  }
+  else
+  {
+    array_push($page['errors'], l10n('opendir failed : '.PHPWG_ROOT_PATH.$conf_smiliessupport[0].')' ));
+  }
+  return $template->parse('smiliessupport_page', true);
+}
+
+function SmiliesParse($str)
+{
+  global $conf;
+  
+  $conf_smiliessupport = explode("," , $conf['smiliessupport']);
+  
+  $def_path = $conf_smiliessupport[0].'/smilies.txt';
+  if ( file_exists($def_path) )
+  {
+    $def = file($def_path);
+    foreach($def as $v)
+    {
+      $v = trim($v);
+      if (preg_match('|^([^\t]*)[\t]+(.*)$|',$v,$matches))
+      {
+        $r[] = '/(\A|[\s]+|>)('.preg_quote($matches[1],'/').')([\s]+|[<]|\Z)/ms';					
+        $s[] = '<img src="'.$conf_smiliessupport[0].'/'.$matches[2].'" '.'alt="$2" title="$2" />';
+        $str = preg_replace($r, $s, $str);
+      }
+    }
+  } 
+  if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
+  {
+    while (false !== ($file = readdir($handle)))
+    { 
+      if ($file != "." && $file != ".." && ( get_extension($file) == "gif" || get_extension($file) == "png")) {
+        $v = ':'.get_filename_wo_extension($file).':'; 
+        $s = '<img src="'.$conf_smiliessupport[0].'/'.$file.'" '.'alt="'.get_filename_wo_extension($file).'" title="'.get_filename_wo_extension($file).'" />';
+        $str = str_replace($v, $s, $str);
+      }
+    }
+  }
+  return $str;
+}
+?>
Index: /extensions/SmiliesSupport/smiliessupport.js
===================================================================
--- /extensions/SmiliesSupport/smiliessupport.js	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport.js	(revision 3304)
@@ -0,0 +1,43 @@
+var theSelection = false;
+
+function SmiliesWrite(form, field, start, end, force) {
+	var textarea = document.forms[form].elements[field];	
+	
+	storeCaret(textarea);
+	
+	if (textarea.caretPos) {
+	  textarea.focus();
+		// Attempt to create a text range (IE).
+		theSelection = document.selection.createRange().text;		
+		if (force || theSelection != '') {
+			document.selection.createRange().text = start + theSelection + end;
+			textarea.focus();
+			return true;
+		}
+	} else if (typeof(textarea.selectionStart) != "undefined") {
+		// Mozilla text range replace.
+		var text = new Array();
+		text[0] = textarea.value.substr(0, textarea.selectionStart);
+		text[1] = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd-textarea.selectionStart);
+		text[2] = textarea.value.substr(textarea.selectionEnd);
+		caretPos = textarea.selectionEnd+start.length+end.length;
+		if (force || text[1] != '') {
+			textarea.value = text[0]+start+text[1]+end+text[2];
+			if (textarea.setSelectionRange) {
+				textarea.focus();
+				textarea.setSelectionRange(caretPos, caretPos);
+			}
+			return true;
+		}
+	} else if (force) {		
+		// Just put it on the end.
+		textarea.value += start+end;
+		textarea.focus(textarea.value.length-1);
+		return true;
+	}
+	return false;
+}
+
+function storeCaret(text) {
+	if (text.createTextRange) text.caretPos = document.selection.createRange().duplicate();
+}
Index: /extensions/SmiliesSupport/smiliessupport_admin.php
===================================================================
--- /extensions/SmiliesSupport/smiliessupport_admin.php	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport_admin.php	(revision 3304)
@@ -0,0 +1,68 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $conf, $template;
+
+$conf_smiliessupport = explode("," , $conf['smiliessupport']);
+// Enregistrement de la configuration
+if (isset($_POST['submit']))
+{
+	if (!isset($_POST['text1'])) $_POST['text1'] = 'plugins/SmiliesSupport/smilies';
+	if (!isset($_POST['text2'])) $_POST['text2'] = '5';
+	if (!isset($_POST['text3'])) $_POST['text3'] = 'sourire.gif';
+	
+	$conf_smiliessupport=array(
+		$_POST['text1'],
+		$_POST['text2'],
+		$_POST['text3']);
+		
+    $new_value_smiliessupport = implode ("," , $conf_smiliessupport);
+    $query = '
+UPDATE ' . CONFIG_TABLE . '
+  SET value="' . $new_value_smiliessupport . '"
+  WHERE param="smiliessupport"
+  LIMIT 1';
+    pwg_query($query);
+    
+	$smilies_file = PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/smilies.txt';	    
+
+	if (file_exists($smilies_file))
+  {
+		if  (@copy($smilies_file , get_filename_wo_extension($smilies_file).'.bak'))
+    {
+			$file = @fopen($smilies_file , "w");
+			fwrite($file , stripslashes($content_file = $_POST['text']));
+			fclose($file);        
+			array_push($page['infos'], l10n('Configuration saved.'));
+		}
+    else
+    {
+		  array_push($page['errors'], l10n('Configuration not saved. (copy : '.$smilies_file.' to '.get_filename_wo_extension($smilies_file).'.bak').')' );
+		}
+	}
+  else
+  {
+		array_push($page['errors'], l10n('Configuration not saved. (file exists : '.$smilies_file.')' ));
+	}
+}
+
+$template->assign(array('TEXT1_VALUE' => $conf_smiliessupport[0]));
+$template->assign(array('TEXT2_VALUE' => $conf_smiliessupport[1]));
+$template->assign(array('TEXT3_VALUE' => $conf_smiliessupport[2]));
+
+include_once(dirname(__FILE__) . '/smiliessupport.inc.php');
+$template->assign('SMILIESSUPPORT_PAGE', SmiliesTable());
+
+$smilies_file = PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/smilies.txt';
+$content_file = '';
+if (file_exists($smilies_file))
+{
+	$content_file = file_get_contents($smilies_file);
+	$template->assign(array('CONTENT_FILE' =>$content_file ));
+}
+	
+$template->set_filename('smiliessupport_conf', dirname(__FILE__).'/smiliessupport_admin.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
+
+?>
Index: /extensions/SmiliesSupport/smiliessupport_admin.tpl
===================================================================
--- /extensions/SmiliesSupport/smiliessupport_admin.tpl	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport_admin.tpl	(revision 3304)
@@ -0,0 +1,21 @@
+<div class="titrePage">
+	<h2>Smilies Support</h2>
+</div>
+<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data"> 
+<div align="center">
+	<fieldset>
+      <legend>SmiliesSupport</legend>	  
+	  <UL>			
+		<LI>Location : <input type="text" size="40" name="text1" value="{$TEXT1_VALUE}" /> </LI>
+		<LI>Nb Column : <input type="text" size="20" name="text2" value="{$TEXT2_VALUE}" /> </LI>		
+		<LI>Representant : <input type="text" size="20" name="text3" value="{$TEXT3_VALUE}" /> </LI>		
+	  <LI>{$SMILIESSUPPORT_PAGE}</LI>
+    </UL>
+	</fieldset>
+	<fieldset>
+		<legend>smilies.txt</legend>
+		<textarea rows="30" name="text" cols="100">{$CONTENT_FILE}</textarea>
+	</fieldset>	
+	<input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" />
+</div>
+</form>
Index: /extensions/SmiliesSupport/smiliessupport_page.css
===================================================================
--- /extensions/SmiliesSupport/smiliessupport_page.css	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport_page.css	(revision 3304)
@@ -0,0 +1,19 @@
+div #smiliesdiv {   
+    position:absolute; 
+	z-index:1000; 
+	width:10px;
+	visibility:hidden; 
+}
+
+.smiliestable {
+    background: buttonface;
+    border-top: 1px solid;
+    border-left: 1px solid;
+    border-bottom: 1px solid;
+    border-right: 1px solid;
+    margin: 1;
+}
+
+#smiliesdiv IMG {
+  cursor: pointer;
+}
Index: /extensions/SmiliesSupport/smiliessupport_page.tpl
===================================================================
--- /extensions/SmiliesSupport/smiliessupport_page.tpl	(revision 3304)
+++ /extensions/SmiliesSupport/smiliessupport_page.tpl	(revision 3304)
@@ -0,0 +1,18 @@
+{known_script id="smiliessupport" src=$ROOT_URL|@cat:"plugins/SmiliesSupport/smiliessupport.js"}
+{html_head}
+<link rel="stylesheet" type="text/css" href="{$ROOT_URL|@cat:"plugins/SmiliesSupport/smiliessupport_page.css"}" >
+{/html_head}
+
+<img id="allsmilies" src="{$REPRESENTANT}" title="All Smilies" onmouseover="document.getElementById('smiliesdiv').style.visibility='visible';" >
+<div id="smiliesdiv" >
+<table class="smiliestable" 
+onmouseover="document.getElementById('smiliesdiv').style.visibility='visible';"
+onmouseout="document.getElementById('smiliesdiv').style.visibility='hidden';" >
+	<tr>
+		{foreach from=$smiliesfiles item=smiliesfile} 
+		<td><img src="{$smiliesfile.PATH}" title="{$smiliesfile.TITLE}" onclick="SmiliesWrite('addComment', 'content', '', '{$smiliesfile.TITLE}', true); document.getElementById('smiliesdiv').style.visibility='hidden';"> </td>	
+		{$smiliesfile.TR}
+		{/foreach}
+	</tr>
+</table>
+</div>
