From 9ab7bc6b169619ac82c8e93f111d8d8fa905a2b8 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sun, 13 Sep 2009 03:48:22 -0400
Subject: [PATCH] - Added 'html_editor' hook (#1486068)

---
 program/include/main.inc |   62 ++++++++++++++++++++++--------
 1 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/program/include/main.inc b/program/include/main.inc
index 09b8c78..e79cc02 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -309,20 +309,20 @@
     'ANSIX31101983' => 'WINDOWS-1252',
     'ANSIX341968'   => 'WINDOWS-1252',
     'UNKNOWN8BIT'   => 'ISO-8859-15',
-    'XUNKNOWN'      => 'ISO-8859-15',
-    'XUSERDEFINED'  => 'ISO-8859-15',
+    'UNKNOWN'       => 'ISO-8859-15',
+    'USERDEFINED'   => 'ISO-8859-15',
     'KSC56011987'   => 'EUC-KR',
     'GB2312' 	    => 'GBK',
     'GB231280'	    => 'GBK',
     'UNICODE'	    => 'UTF-8',
     'UTF7IMAP'	    => 'UTF7-IMAP',
-    'XXBIG5'	    => 'BIG5',
     'TIS620'	    => 'WINDOWS-874',
     'ISO88599'	    => 'WINDOWS-1254',
     'ISO885911'	    => 'WINDOWS-874',
   );
 
-  $str = preg_replace('/[^a-z0-9]/i', '', $charset);
+  // allow a-z and 0-9 only and remove X- prefix (e.g. X-ROMAN8 => ROMAN8)
+  $str = preg_replace(array('/[^a-z0-9]/i', '/^x+/i'), '', $charset);
 
   if (isset($aliases[$str]))
     return $aliases[$str];
@@ -545,7 +545,7 @@
  * @return string   Field value or NULL if not available
  */
 function get_input_value($fname, $source, $allow_html=FALSE, $charset=NULL)
-  {
+{
   global $OUTPUT;
   $value = NULL;
   
@@ -582,7 +582,26 @@
     return rcube_charset_convert($value, $OUTPUT->get_charset(), $charset);
   else
     return $value;
+}
+
+/**
+ * Convert array of request parameters (prefixed with _)
+ * to a regular array with non-prefixed keys.
+ *
+ * @param  int   Source to get value from (GPC)
+ * @return array Hash array with all request parameters
+ */
+function request2param($mode = RCUBE_INPUT_GPC)
+{
+  $out = array();
+  $src = $mode == RCUBE_INPUT_GET ? $_GET : ($mode == RCUBE_INPUT_POST ? $_POST : $_REQUEST);
+  foreach ($src as $key => $value) {
+    $fname = $key[0] == '_' ? substr($key, 1) : $key;
+    $out[$fname] = get_input_value($key, $mode);
   }
+  
+  return $out;
+}
 
 /**
  * Remove all non-ascii and non-word chars
@@ -644,7 +663,7 @@
     while ($table_data && ($sql_arr = $db->fetch_assoc($table_data)))
     {
       $zebra_class = $c % 2 ? 'even' : 'odd';
-      $table->add_row(array('id' => 'rcmrow' . $sql_arr[$id_col], 'class' => "contact $zebra_class"));
+      $table->add_row(array('id' => 'rcmrow' . $sql_arr[$id_col], 'class' => $zebra_class));
 
       // format each col
       foreach ($a_show_cols as $col)
@@ -658,7 +677,7 @@
     foreach ($table_data as $row_data)
     {
       $zebra_class = $c % 2 ? 'even' : 'odd';
-      $table->add_row(array('id' => 'rcmrow' . $row_data[$id_col], 'class' => "contact $zebra_class"));
+      $table->add_row(array('id' => 'rcmrow' . $row_data[$id_col], 'class' => $zebra_class));
 
       // format each col
       foreach ($a_show_cols as $col)
@@ -958,8 +977,11 @@
   {
   $args = func_get_args();
 
-  if (class_exists('rcmail', false))
-    rcmail::get_instance()->plugins->exec_hook('console', $args);
+  if (class_exists('rcmail', false)) {
+    $rcmail = rcmail::get_instance();
+    if (is_object($rcmail->plugins))
+      $rcmail->plugins->exec_hook('console', $args);
+  }
 
   $msg = array();
   foreach ($args as $arg)
@@ -1356,17 +1378,23 @@
  */
 function rcube_html_editor($mode='')
 {
-  global $OUTPUT, $CONFIG;
+  global $RCMAIL, $CONFIG;
 
-  $lang = $tinylang = strtolower(substr($_SESSION['language'], 0, 2));
-  if (!file_exists(INSTALL_PATH . 'program/js/tiny_mce/langs/'.$tinylang.'.js'))
-    $tinylang = 'en';
+  $lang = strtolower(substr($_SESSION['language'], 0, 2));
+  if (!file_exists(INSTALL_PATH . 'program/js/tiny_mce/langs/'.$lang.'.js'))
+    $lang = 'en';
 
-  $OUTPUT->include_script('tiny_mce/tiny_mce.js');
-  $OUTPUT->include_script('editor.js');
-  $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.JQ($tinylang).'", '.intval($CONFIG['enable_spellcheck']).', "'.$mode.'");');
+  $hook = $RCMAIL->plugins->exec_hook('hmtl_editor', array('abort' => false,
+    'mode' => $mode, 'lang' => $lang));
+
+  if ($hook['abort'])
+    return;  
+
+  $RCMAIL->output->include_script('tiny_mce/tiny_mce.js');
+  $RCMAIL->output->include_script('editor.js');
+  $RCMAIL->output->add_script('rcmail_editor_init("$__skin_path",
+    "'.JQ($hook['lang']).'", '.intval($CONFIG['enable_spellcheck']).', "'.$hook['mode'].'");');
 }
-
 
 
 /**

--
Gitblit v1.9.1