Exemple #1
0
/**
 * Format a value for display
 * @subpackage core/functions
 * @param string $name value name to find/format
 * @param array $haystack details to search for the value name
 * @param bool $type optional format type
 * @param mixed $default value to return if the name is not found
 * @return string
 */
function display_value($name, $haystack, $type = false, $default = '')
{
    if (!array_key_exists($name, $haystack)) {
        return $default;
    }
    $value = $haystack[$name];
    $res = false;
    if ($type) {
        $name = $type;
    }
    switch ($name) {
        case 'from':
            $value = preg_replace("/(\\<.+\\>)/U", '', $value);
            $res = str_replace('"', '', $value);
            break;
        case 'date':
            $res = human_readable_interval($value);
            break;
        case 'time':
            $res = strtotime($value);
            break;
        default:
            $res = $value;
            break;
    }
    return $res;
}
Exemple #2
0
 protected function output()
 {
     $res = array();
     $unread_only = false;
     if ($this->get('list_path', '') == 'unread') {
         $unread_only = true;
     }
     $cutoff = $this->get('wp_list_since', '');
     if ($cutoff) {
         $cutoff = strtotime($cutoff);
     } else {
         $cutoff = 0;
     }
     foreach ($this->get('wp_notice_data', array()) as $vals) {
         if (array_key_exists('id', $vals)) {
             $id = 'wordpress_0_' . $vals['id'];
             $url = '?page=message&list_path=wp_notifications&uid=' . $this->html_safe($id);
             if ($this->get('list_parent', '')) {
                 $url .= '&list_parent=' . $this->html_safe($this->get('list_parent', ''));
             }
             $style = 'email';
             $style = $this->get('news_list_style') ? 'news' : 'email';
             if ($this->get('is_mobile')) {
                 $style = 'news';
             }
             $subject = html_entity_decode($vals['subject']['text']);
             $from = ucfirst(str_replace('_', ' ', $vals['type']));
             $ts = $vals['timestamp'];
             if ($ts < $cutoff) {
                 continue;
             }
             $flags = array();
             if ((int) $vals['unread'] > 0) {
                 $flags[] = 'unseen';
             }
             if ($unread_only && !in_array('unseen', $flags, true)) {
                 continue;
             }
             $date = date('r', $ts);
             if ($style == 'news') {
                 $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('icon_callback', $flags), array('subject_callback', $subject, $url, $flags), array('safe_output_callback', 'source', 'WordPress'), array('safe_output_callback', 'from', $from), array('date_callback', human_readable_interval($date), $ts)), $id, $style, $this);
             } else {
                 $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('safe_output_callback', 'source', 'WordPress'), array('safe_output_callback', 'from', $from), array('subject_callback', $subject, $url, $flags), array('date_callback', human_readable_interval($date), $ts), array('icon_callback', $flags)), $id, $style, $this);
             }
         }
     }
     $this->out('formatted_message_list', $res);
 }
Exemple #3
0
 protected function output()
 {
     $res = array();
     $login_time = false;
     $unread_only = false;
     if ($this->get('login_time')) {
         $login_time = $this->get('login_time');
     }
     if ($this->get('list_path', '') == 'unread' || $this->get('github_unread', false)) {
         $unread_only = true;
     }
     $repo_id = $this->get('github_data_source_id');
     $repo = $this->get('github_data_source', 'Github');
     $cutoff = $this->get('github_list_since', '');
     if ($cutoff) {
         $cutoff = strtotime($cutoff);
     } else {
         $cutoff = 0;
     }
     foreach ($this->get('github_data', array()) as $event) {
         $id = 'github_' . $repo_id . '_' . $event['id'];
         $subject = build_github_subject($event, $this);
         $url = '?page=message&uid=' . $this->html_safe($id) . '&list_path=github_' . $this->html_safe($repo);
         if ($this->get('list_parent', '')) {
             $url .= '&list_parent=' . $this->html_safe($this->get('list_parent'));
         }
         $from = $event['actor']['login'];
         $ts = strtotime($event['created_at']);
         if ($ts < $cutoff) {
             continue;
         }
         if (Hm_Github_Uid_Cache::is_read($event['id'])) {
             $flags = array();
         } elseif (Hm_Github_Uid_Cache::is_unread($event['id'])) {
             $flags = array('unseen');
         } elseif ($ts && $login_time && $ts <= $login_time) {
             $flags = array();
         } else {
             $flags = array('unseen');
         }
         if ($unread_only && !in_array('unseen', $flags)) {
             continue;
         }
         $date = date('r', $ts);
         $style = $this->get('news_list_style') ? 'news' : 'email';
         if ($this->get('is_mobile')) {
             $style = 'news';
         }
         if ($style == 'news') {
             $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('icon_callback', $flags), array('subject_callback', $subject, $url, $flags), array('safe_output_callback', 'source', $repo), array('safe_output_callback', 'from', $from), array('date_callback', human_readable_interval($date), $ts)), $id, $style, $this);
         } else {
             $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('safe_output_callback', 'source', $repo), array('safe_output_callback', 'from', $from), array('subject_callback', $subject, $url, $flags), array('date_callback', human_readable_interval($date), $ts), array('icon_callback', $flags)), $id, $style, $this);
         }
     }
     $this->out('formatted_message_list', $res);
     $this->out('github_server_id', $repo_id);
 }
Exemple #4
0
/**
 * Format a list of message headers
 * @subpackage imap/functions
 * @param array $msg_list list of message headers
 * @param object $mod Hm_Output_Module
 * @param mixed $parent_list parent list id
 * @param string $style list style (email or news)
 * @return array
 */
function format_imap_message_list($msg_list, $output_module, $parent_list = false, $style = 'email')
{
    $res = array();
    if ($msg_list === array(false)) {
        return $msg_list;
    }
    foreach ($msg_list as $msg) {
        if (!$parent_list) {
            $parent_value = sprintf('imap_%d_%s', $msg['server_id'], $msg['folder']);
        } else {
            $parent_value = $parent_list;
        }
        if ($msg['server_name'] == 'Default-Auth-Server') {
            $msg['server_name'] = 'Default';
        }
        $id = sprintf("imap_%s_%s_%s", $msg['server_id'], $msg['uid'], $msg['folder']);
        if (!trim($msg['subject'])) {
            $msg['subject'] = '[No Subject]';
        }
        $subject = $msg['subject'];
        $from = preg_replace("/(\\<.+\\>)/U", '', $msg['from']);
        $from = str_replace('"', '', $from);
        if (!trim($from) && $style == 'email') {
            $from = '[No From]';
        }
        $timestamp = strtotime($msg['internal_date']);
        $date = translate_time_str(human_readable_interval($msg['internal_date']), $output_module);
        $flags = array();
        if (!stristr($msg['flags'], 'seen')) {
            $flags[] = 'unseen';
        }
        if (stristr($msg['flags'], 'deleted')) {
            $flags[] = 'deleted';
        }
        if (stristr($msg['flags'], 'flagged')) {
            $flags[] = 'flagged';
        }
        $source = $msg['server_name'];
        if ($msg['folder'] && $msg['folder'] != 'INBOX') {
            $source .= '-' . preg_replace("/^INBOX.{1}/", '', $msg['folder']);
        }
        $url = '?page=message&uid=' . $msg['uid'] . '&list_path=' . sprintf('imap_%d_%s', $msg['server_id'], $msg['folder']) . '&list_parent=' . $parent_value;
        if ($style == 'news') {
            $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('icon_callback', $flags), array('subject_callback', $subject, $url, $flags), array('safe_output_callback', 'source', $source), array('safe_output_callback', 'from', $from), array('date_callback', $date, $timestamp)), $id, $style, $output_module);
        } else {
            $res[$id] = message_list_row(array(array('checkbox_callback', $id), array('safe_output_callback', 'source', $source), array('safe_output_callback', 'from', $from), array('subject_callback', $subject, $url, $flags), array('date_callback', $date, $timestamp), array('icon_callback', $flags)), $id, $style, $output_module);
        }
    }
    return $res;
}