From 20e251599fa595102188bffb9fc5ffc4a1ca0166 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 16 Sep 2009 02:35:49 -0400
Subject: [PATCH] - return true after abort from write_log hook

---
 program/include/main.inc |   73 ++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/program/include/main.inc b/program/include/main.inc
index 3099a72..a99504c 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)
@@ -995,20 +1017,24 @@
   if (empty($CONFIG['log_date_format']))
     $CONFIG['log_date_format'] = 'd-M-Y H:i:s O';
   
+  $date = date($CONFIG['log_date_format']);
+  
   // trigger logging hook
   if (is_object($RCMAIL) && is_object($RCMAIL->plugins)) {
-    $log = $RCMAIL->plugins->exec_hook('write_log', array('name' => $name, 'line' => $line));
+    $log = $RCMAIL->plugins->exec_hook('write_log', array('name' => $name, 'date' => $date, 'line' => $line));
     $name = $log['name'];
     $line = $log['line'];
+    $date = $log['date'];
     if ($log['abort'])
-      return;
+      return true;
   }
  
-  $log_entry = sprintf("[%s]: %s\n", date($CONFIG['log_date_format']), $line);
+  $log_entry = sprintf("[%s]: %s\n", $date, $line);
 
   if ($CONFIG['log_driver'] == 'syslog') {
     $prio = $name == 'errors' ? LOG_ERR : LOG_INFO;
     syslog($prio, $log_entry);
+    return true;
   }
   else {
     // log_driver == 'file' is assumed here
@@ -1020,8 +1046,10 @@
       fwrite($fp, $log_entry);
       fflush($fp);
       fclose($fp);
+      return true;
     }
   }
+  return false;
 }
 
 
@@ -1350,17 +1378,22 @@
  */
 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';
+  $hook = $RCMAIL->plugins->exec_hook('hmtl_editor', array('mode' => $mode));
 
-  $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.'");');
+  if ($hook['abort'])
+    return;  
+
+  $lang = strtolower(substr($_SESSION['language'], 0, 2));
+  if (!file_exists(INSTALL_PATH . 'program/js/tiny_mce/langs/'.$lang.'.js'))
+    $lang = 'en';
+
+  $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($lang).'", '.intval($CONFIG['enable_spellcheck']).', "'.$mode.'");');
 }
-
 
 
 /**

--
Gitblit v1.9.1