From 03d772e80d9cc059eed12a24cd9e9a3dc850068a Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Sun, 23 Jan 2011 11:11:22 -0500 Subject: [PATCH] Also wrap unread count in span on server side (#1487720) --- program/include/main.inc | 151 ++++++++++++++++++++++++++++++++------------------ 1 files changed, 96 insertions(+), 55 deletions(-) diff --git a/program/include/main.inc b/program/include/main.inc index 160c835..d79ba2c 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -5,7 +5,7 @@ | program/include/main.inc | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2009, Roundcube Dev, - Switzerland | + | Copyright (C) 2005-2009, The Roundcube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -799,7 +799,7 @@ // format each col foreach ($a_show_cols as $col) - $table->add($col, Q($row_data[$col])); + $table->add($col, Q(is_array($row_data[$col]) ? $row_data[$col][0] : $row_data[$col])); $c++; } @@ -819,32 +819,43 @@ * @return string HTML field definition */ function rcmail_get_edit_field($col, $value, $attrib, $type='text') - { - $fname = '_'.$col; - $attrib['name'] = $fname; +{ + static $colcounts = array(); - if ($type=='checkbox') - { + $fname = '_'.$col; + $attrib['name'] = $fname . ($attrib['array'] ? '[]' : ''); + $attrib['class'] = trim($attrib['class'] . ' ff_' . $col); + + if ($type == 'checkbox') { $attrib['value'] = '1'; $input = new html_checkbox($attrib); - } - else if ($type=='textarea') - { + } + else if ($type == 'textarea') { $attrib['cols'] = $attrib['size']; $input = new html_textarea($attrib); - } - else + } + else if ($type == 'select') { + $input = new html_select($attrib); + $input->add('---', ''); + $input->add(array_values($attrib['options']), array_keys($attrib['options'])); + } + else { + if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden') + $attrib['type'] = 'text'; $input = new html_inputfield($attrib); + } // use value from post - if (!empty($_POST[$fname])) - $value = get_input_value($fname, RCUBE_INPUT_POST, - $type == 'textarea' && strpos($attrib['class'], 'mce_editor')!==false ? true : false); + if (isset($_POST[$fname])) { + $postvalue = get_input_value($fname, RCUBE_INPUT_POST, + $type == 'textarea' && strpos($attrib['class'], 'mce_editor')!==false ? true : false); + $value = $attrib['array'] ? $postvalue[intval($colcounts[$col]++)] : $postvalue; + } $out = $input->show($value); - + return $out; - } +} /** @@ -967,6 +978,37 @@ /** + * Improved equivalent to strtotime() + * + * @param string Date string + * @return int + */ +function rcube_strtotime($date) +{ + // check for MS Outlook vCard date format YYYYMMDD + if (preg_match('/^([12][90]\d\d)([01]\d)(\d\d)$/', trim($date), $matches)) { + return mktime(0,0,0, intval($matches[2]), intval($matches[3]), intval($matches[1])); + } + else if (is_numeric($date)) + return $date; + + // support non-standard "GMTXXXX" literal + $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); + + // if date parsing fails, we have a date in non-rfc format. + // remove token from the end and try again + while ((($ts = @strtotime($date)) === false) || ($ts < 0)) { + $d = explode(' ', $date); + array_pop($d); + if (!$d) break; + $date = implode(' ', $d); + } + + return $ts; +} + + +/** * Convert the given date to a human readable form * This uses the date formatting properties from config * @@ -980,22 +1022,8 @@ $ts = NULL; - if (is_numeric($date)) - $ts = $date; - else if (!empty($date)) - { - // support non-standard "GMTXXXX" literal - $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); - // if date parsing fails, we have a date in non-rfc format. - // remove token from the end and try again - while ((($ts = @strtotime($date))===false) || ($ts < 0)) - { - $d = explode(' ', $date); - array_pop($d); - if (!$d) break; - $date = implode(' ', $d); - } - } + if (!empty($date)) + $ts = rcube_strtotime($date); if (empty($ts)) return ''; @@ -1193,21 +1221,33 @@ if (!$RCMAIL->config->get('log_logins') || !$RCMAIL->user) return; - $address = $_SERVER['REMOTE_ADDR']; - // append the NGINX X-Real-IP header, if set - if (!empty($_SERVER['HTTP_X_REAL_IP'])) { - $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; - } - // append the X-Forwarded-For header, if set - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if (!empty($remote_ip)) - $address .= '(' . implode(',', $remote_ip) . ')'; - write_log('userlogins', sprintf('Successful login for %s (ID: %d) from %s', - $RCMAIL->user->get_username(), $RCMAIL->user->ID, $address)); + $RCMAIL->user->get_username(), $RCMAIL->user->ID, rcmail_remote_ip())); +} + + +/** + * Returns remote IP address and forwarded addresses if found + * + * @return string Remote IP address(es) + */ +function rcmail_remote_ip() +{ + $address = $_SERVER['REMOTE_ADDR']; + + // append the NGINX X-Real-IP header, if set + if (!empty($_SERVER['HTTP_X_REAL_IP'])) { + $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; + } + // append the X-Forwarded-For header, if set + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if (!empty($remote_ip)) + $address .= '(' . implode(',', $remote_ip) . ')'; + + return $address; } @@ -1219,7 +1259,7 @@ { return microtime(true); } - + /** * @access private @@ -1452,7 +1492,7 @@ $classes[] = 'unread'; $js_name = JQ($folder['id']); - $html_name = Q($foldername . ($unread ? " ($unread)" : '')); + $html_name = Q($foldername) . ($unread ? html::span('unreadcount', " ($unread)") : ''); $link_attrib = $folder['virtual'] ? array() : array( 'href' => rcmail_url('', array('_mbox' => $folder['id'])), 'onclick' => sprintf("return %s.command('list','%s',this)", JS_OBJECT_NAME, $js_name), @@ -1697,11 +1737,11 @@ ':-(' => 'smiley-frown', ':-D' => 'smiley-laughing', ':-)' => 'smiley-smile', - ':-/' => 'smiley-undecided', - ':-X' => 'smiley-embarassed', - '0:-)' => 'smiley-innocent', + ':-S' => 'smiley-undecided', + ':-$' => 'smiley-embarassed', + 'O:-)' => 'smiley-innocent', ':-|' => 'smiley-money-mouth', - ':-0' => 'smiley-surprised', + ':-O' => 'smiley-surprised', ';-)' => 'smiley-wink', ); @@ -1759,16 +1799,17 @@ * Replaces hostname variables * * @param string $name Hostname + * @param string $host Optional IMAP hostname * @return string */ -function rcube_parse_host($name) +function rcube_parse_host($name, $host='') { // %n - host $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']); // %d - domain name without first part, e.g. %d=mail.domain.tld, %m=domain.tld $d = preg_replace('/^[^\.]+\./', '', $n); // %h - IMAP host - $h = $_SESSION['imap_host']; + $h = $_SESSION['imap_host'] ? $_SESSION['imap_host'] : $host; // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld $z = preg_replace('/^[^\.]+\./', '', $h); -- Gitblit v1.9.1