]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/main.inc
Imported Upstream version 0.5.4+dfsg
[roundcube.git] / program / include / main.inc
index d02dca5e2d67db6d3c26f030c8b9da568fdc2b32..b341b18c4a81847164fa8c69f3f772dc93a6a62c 100644 (file)
@@ -15,7 +15,7 @@
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
 
- $Id: main.inc 4509 2011-02-09 10:51:50Z thomasb $
+ $Id: main.inc 4830 2011-06-02 12:36:32Z alec $
 
 */
 
@@ -89,6 +89,16 @@ function rcube_label($p, $domain=null)
   return rcmail::get_instance()->gettext($p, $domain);
 }
 
+/**
+ * Global wrapper of rcmail::text_exists()
+ * to check whether a text label is defined
+ *
+ * @see rcmail::text_exists()
+ */
+function rcube_label_exists($name, $domain=null)
+{
+  return rcmail::get_instance()->text_exists($name, $domain);
+}
 
 /**
  * Overwrite action variable
@@ -972,7 +982,7 @@ function parse_attrib_string($str)
  * @return string Formatted date string
  */
 function format_date($date, $format=NULL)
-  {
+{
   global $CONFIG;
   
   $ts = NULL;
@@ -996,7 +1006,7 @@ function format_date($date, $format=NULL)
 
   if (empty($ts))
     return '';
-   
+
   // get user's timezone
   if ($CONFIG['timezone'] === 'auto')
     $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : date('Z')/3600;
@@ -1008,7 +1018,7 @@ function format_date($date, $format=NULL)
 
   // convert time to user's timezone
   $timestamp = $ts - date('Z', $ts) + ($tz * 3600);
-  
+
   // get current timestamp in user's timezone
   $now = time();  // local time
   $now -= (int)date('Z'); // make GMT time
@@ -1016,30 +1026,33 @@ function format_date($date, $format=NULL)
   $now_date = getdate($now);
 
   $today_limit = mktime(0, 0, 0, $now_date['mon'], $now_date['mday'], $now_date['year']);
-  $week_limit = mktime(0, 0, 0, $now_date['mon'], $now_date['mday']-6, $now_date['year']);
+  $week_limit  = mktime(0, 0, 0, $now_date['mon'], $now_date['mday']-6, $now_date['year']);
 
   // define date format depending on current time
   if (!$format) {
-    if ($CONFIG['prettydate'] && $timestamp > $today_limit && $timestamp < $now)
-      return sprintf('%s %s', rcube_label('today'), date($CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i', $timestamp));
+    if ($CONFIG['prettydate'] && $timestamp > $today_limit && $timestamp < $now) {
+      $format = $CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i';
+      $today  = true;
+    }
     else if ($CONFIG['prettydate'] && $timestamp > $week_limit && $timestamp < $now)
       $format = $CONFIG['date_short'] ? $CONFIG['date_short'] : 'D H:i';
     else
       $format = $CONFIG['date_long'] ? $CONFIG['date_long'] : 'd.m.Y H:i';
-    }
+  }
 
   // strftime() format
-  if (preg_match('/%[a-z]+/i', $format))
-    return strftime($format, $timestamp);
+  if (preg_match('/%[a-z]+/i', $format)) {
+    $format = strftime($format, $timestamp);
+    return $today ? (rcube_label('today') . ' ' . $format) : $format;
+  }
 
   // parse format string manually in order to provide localized weekday and month names
   // an alternative would be to convert the date() format string to fit with strftime()
   $out = '';
-  for($i=0; $i<strlen($format); $i++)
-    {
+  for($i=0; $i<strlen($format); $i++) {
     if ($format{$i}=='\\')  // skip escape chars
       continue;
-    
+
     // write char "as-is"
     if ($format{$i}==' ' || $format{$i-1}=='\\')
       $out .= $format{$i};
@@ -1059,11 +1072,22 @@ function format_date($date, $format=NULL)
       $out .= strftime('%x %X', $timestamp);
     else
       $out .= date($format{$i}, $timestamp);
+  }
+
+  if ($today) {
+    $label = rcube_label('today');
+    // replcae $ character with "Today" label (#1486120)
+    if (strpos($out, '$') !== false) {
+      $out = preg_replace('/\$/', $label, $out, 1);
+    }
+    else {
+      $out = $label . ' ' . $out;
     }
-  
-  return $out;
   }
 
+  return $out;
+}
+
 
 /**
  * Compose a valid representation of name and e-mail address
@@ -1272,12 +1296,12 @@ function rcmail_mailbox_list($attrib)
 {
   global $RCMAIL;
   static $a_mailboxes;
-  
+
   $attrib += array('maxlength' => 100, 'realnames' => false);
 
   // add some labels to client
   $RCMAIL->output->add_label('purgefolderconfirm', 'deletemessagesconfirm');
-  
+
   $type = $attrib['type'] ? $attrib['type'] : 'ul';
   unset($attrib['type']);
 
@@ -1286,7 +1310,7 @@ function rcmail_mailbox_list($attrib)
 
   // get mailbox list
   $mbox_name = $RCMAIL->imap->get_mailbox_name();
-  
+
   // build the folders tree
   if (empty($a_mailboxes)) {
     // get mailbox list
@@ -1301,20 +1325,20 @@ function rcmail_mailbox_list($attrib)
   // allow plugins to alter the folder tree or to localize folder names
   $hook = $RCMAIL->plugins->exec_hook('render_mailboxlist', array('list' => $a_mailboxes, 'delimiter' => $delimiter));
 
-  if ($type=='select') {
+  if ($type == 'select') {
     $select = new html_select($attrib);
-    
+
     // add no-selection option
     if ($attrib['noselection'])
-      $select->add(rcube_label($attrib['noselection']), '0');
-    
+      $select->add(rcube_label($attrib['noselection']), '');
+
     rcmail_render_folder_tree_select($hook['list'], $mbox_name, $attrib['maxlength'], $select, $attrib['realnames']);
     $out = $select->show();
   }
   else {
     $js_mailboxlist = array();
     $out = html::tag('ul', $attrib, rcmail_render_folder_tree_html($hook['list'], $mbox_name, $js_mailboxlist, $attrib), html::$common_attrib);
-    
+
     $RCMAIL->output->add_gui_object('mailboxlist', $attrib['id']);
     $RCMAIL->output->set_env('mailboxes', $js_mailboxlist);
     $RCMAIL->output->set_env('collapsed_folders', $RCMAIL->config->get('collapsed_folders'));
@@ -1333,7 +1357,7 @@ function rcmail_mailbox_list($attrib)
 function rcmail_mailbox_select($p = array())
 {
   global $RCMAIL;
-  
+
   $p += array('maxlength' => 100, 'realnames' => false);
   $a_mailboxes = array();
 
@@ -1406,7 +1430,7 @@ function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='')
   if (strlen($subFolders))
     rcmail_build_folder_tree($arrFolders[$currentFolder]['folders'], $subFolders, $delm, $path.$delm);
 }
-  
+
 
 /**
  * Return html for a structured list &lt;ul&gt; for the mailbox tree
@@ -1416,7 +1440,7 @@ function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='')
 function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $attrib, $nestLevel=0)
 {
   global $RCMAIL, $CONFIG;
-  
+
   $maxlength = intval($attrib['maxlength']);
   $realnames = (bool)$attrib['realnames'];
   $msgcounts = $RCMAIL->imap->get_cache('messagecount');
@@ -1459,15 +1483,15 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $at
       $classes[] = 'inbox';
     else
       $classes[] = '_'.asciiwords($folder_class ? $folder_class : strtolower($folder['id']), true);
-      
+
     $classes[] = $zebra_class;
-    
+
     if ($folder['id'] == $mbox_name)
       $classes[] = 'selected';
 
     $collapsed = preg_match('/&'.rawurlencode($folder['id']).'&/', $RCMAIL->config->get('collapsed_folders'));
     $unread = $msgcounts ? intval($msgcounts[$folder['id']]['UNSEEN']) : 0;
-    
+
     if ($folder['virtual'])
       $classes[] = 'virtual';
     else if ($unread)
@@ -1491,9 +1515,9 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $at
         'style' => "position:absolute",
         'onclick' => sprintf("%s.command('collapse-folder', '%s')", JS_OBJECT_NAME, $js_name)
       ), '&nbsp;') : ''));
-    
+
     $jslist[$folder_id] = array('id' => $folder['id'], 'name' => $foldername, 'virtual' => $folder['virtual']);
-    
+
     if (!empty($folder['folders'])) {
       $out .= html::tag('ul', array('style' => ($collapsed ? "display:none;" : null)),
         rcmail_render_folder_tree_html($folder['folders'], $mbox_name, $jslist, $attrib, $nestLevel+1));
@@ -1513,32 +1537,28 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $at
  * @return string
  */
 function rcmail_render_folder_tree_select(&$arrFolders, &$mbox_name, $maxlength, &$select, $realnames=false, $nestLevel=0)
-  {
-  $idx = 0;
+{
   $out = '';
-  foreach ($arrFolders as $key=>$folder)
-    {
+
+  foreach ($arrFolders as $key=>$folder) {
     if (!$realnames && ($folder_class = rcmail_folder_classname($folder['id'])))
       $foldername = rcube_label($folder_class);
-    else
-      {
+    else {
       $foldername = $folder['name'];
-      
+
       // shorten the folder name to a given length
       if ($maxlength && $maxlength>1)
         $foldername = abbreviate_string($foldername, $maxlength);
-      }
+    }
 
     $select->add(str_repeat('&nbsp;', $nestLevel*4) . $foldername, $folder['id']);
 
     if (!empty($folder['folders']))
       $out .= rcmail_render_folder_tree_select($folder['folders'], $mbox_name, $maxlength, $select, $realnames, $nestLevel+1);
-
-    $idx++;
-    }
+  }
 
   return $out;
-  }
+}
 
 
 /**
@@ -1679,7 +1699,7 @@ function rcube_html_editor($mode='')
 {
   global $RCMAIL, $CONFIG;
 
-  $hook = $RCMAIL->plugins->exec_hook('hmtl_editor', array('mode' => $mode));
+  $hook = $RCMAIL->plugins->exec_hook('html_editor', array('mode' => $mode));
 
   if ($hook['abort'])
     return;  
@@ -1903,6 +1923,10 @@ function rcube_idn_convert($input, $is_utf=false)
 
   $domain = $is_utf ? idn_to_ascii($domain) : idn_to_utf8($domain);
 
+  if ($domain === false) {
+    return '';
+  }
+
   return $at ? $user . '@' . $domain : $domain;
 }