コード例 #1
0
ファイル: Related.php プロジェクト: raz0rsdge/horde
 /**
  * Render out the currently set contents.
  *
  * @param boolean $inline  Are we viewing inline?
  *
  * @return array  See self::render().
  */
 protected function _IMPrender($inline)
 {
     $related_id = $this->_mimepart->getMimeId();
     $used = array($related_id);
     if (!($id = $this->_init($inline))) {
         return array();
     }
     $render = $this->getConfigParam('imp_contents')->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL);
     if (!$inline) {
         foreach (array_keys($render) as $key) {
             if (!is_null($render[$key])) {
                 return array($related_id => $render[$key]);
             }
         }
         return null;
     }
     $data_id = null;
     $ret = array();
     foreach ($this->_mimepart->partIterator(false) as $val) {
         $ret[$val->getMimeId()] = null;
     }
     foreach (array_keys($render) as $val) {
         $ret[$val] = $render[$val];
         if ($ret[$val]) {
             $data_id = $val;
         }
     }
     if (!is_null($data_id)) {
         $this->_mimepart->setMetadata('viewable_part', $data_id);
         /* We want the inline display to show multipart/related vs. the
          * viewable MIME part.  This is because a multipart/related part
          * is not downloadable and clicking on the MIME part may not
          * produce the desired result in the full display (i.e. HTML parts
          * with related images). */
         if (strcmp($data_id, $related_id) !== 0) {
             $ret[$related_id] = $ret[$data_id];
             $ret[$data_id] = null;
         }
     }
     /* Fix for broken messages that don't refer to a related CID part
      * within the base part. */
     if ($cids_used = $this->_mimepart->getMetadata('related_cids_used')) {
         $used = array_merge($used, $cids_used);
     }
     $id_ob = new Horde_Mime_Id($id);
     foreach (array_diff(array_keys($ret), $used) as $val) {
         if (strcmp($val, $id) !== 0 && !$id_ob->isChild($val)) {
             $summary = $this->getConfigParam('imp_contents')->getSummary($val, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD);
             $status = new IMP_Mime_Status_RenderIssue($this->_mimepart, array(_("This part contains an attachment that can not be displayed within this part:"), implode(' ', array($summary['icon'], $summary['description'], $summary['size'], $summary['download']))));
             $status->action($status::WARNING);
             if (isset($ret[$related_id]['status'])) {
                 if (!is_array($ret[$related_id]['status'])) {
                     $ret[$related_id]['status'] = array($ret[$related_id]['status']);
                 }
             } else {
                 $ret[$related_id]['status'] = array();
             }
             $ret[$related_id]['status'][] = $status;
         }
     }
     return $ret;
 }
コード例 #2
0
ファイル: Plain.php プロジェクト: raz0rsdge/horde
 /**
  * Render the object.
  *
  * @param boolean $inline  Viewing inline?
  *
  * @return array  See parent::render().
  */
 protected function _impRender($inline)
 {
     global $injector, $prefs, $registry;
     $contents = $this->getConfigParam('imp_contents');
     $cache = $contents->getViewCache();
     $mime_id = $this->_mimepart->getMimeId();
     if (isset($cache->plain[$mime_id])) {
         return array($mime_id => null);
     }
     // Trim extra whitespace in the text.
     $charset = $this->_mimepart->getCharset();
     $text = trim($this->_mimepart->getContents());
     if ($text == '') {
         return array($mime_id => array('data' => '', 'type' => 'text/html; charset=' . $charset));
     }
     // Convert to the local charset.
     if ($inline) {
         $text = Horde_String::convertCharset($text, $charset, 'UTF-8');
         $charset = $this->getConfigParam('charset');
     }
     $type = 'text/html; charset=' . $charset;
     // Check for 'flowed' text data.
     if ($this->_mimepart->getContentTypeParameter('format') == 'flowed') {
         $text = $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp'));
     } else {
         /* A "From" located at the beginning of a line in the body text
          * will be escaped with a '>' by the IMAP server.  Remove this
          * escape character or else the line will display as being
          * quoted. Flowed conversion would have already taken care of this
          * for us. */
         $text = preg_replace('/(\\n+)> ?From(\\s+)/', "\$1From\$2", $text);
     }
     $text = IMP::filterText($text);
     // Build filter stack. Starts with HTML markup and tab expansion.
     $filters = array('text2html' => array('charset' => $charset, 'parselevel' => $inline ? Horde_Text_Filter_Text2html::MICRO : Horde_Text_Filter_Text2html::MICRO_LINKURL), 'tabs2spaces' => array());
     // Highlight quoted parts of an email.
     if ($prefs->getValue('highlight_text')) {
         $hideBlocks = $js_blocks = false;
         if ($registry->getView() !== $registry::VIEW_SMARTMOBILE) {
             $js_blocks = $inline;
             if ($inline) {
                 $show = $prefs->getValue('show_quoteblocks');
                 $hideBlocks = $show == 'hidden' || $show == 'thread' && $injector->getInstance('Horde_Variables')->page == 'thread';
                 if (!$hideBlocks && in_array($show, array('list', 'listthread'))) {
                     $list_info = $contents->getListInformation();
                     $hideBlocks = $list_info['exists'];
                 }
             }
         }
         if ($js_blocks) {
             $filters['highlightquotes'] = array('hideBlocks' => $hideBlocks, 'noJS' => $registry->getView() == Horde_Registry::VIEW_DYNAMIC);
         } else {
             $filters['Horde_Text_Filter_Highlightquotes'] = array('hideBlocks' => $hideBlocks);
         }
     }
     // Highlight simple markup of an email.
     if ($prefs->getValue('highlight_simple_markup')) {
         $filters['simplemarkup'] = array('html' => true);
     }
     // Dim signatures.
     if ($prefs->getValue('dim_signature')) {
         $filters['dimsignature'] = array();
     }
     if ($prefs->getValue('emoticons')) {
         $filters['emoticons'] = array('entities' => true);
     }
     // Run filters.
     $status = array();
     $text = $this->_textFilter($text, array_keys($filters), array_values($filters));
     if (strlen($text)) {
         // Wordwrap.
         $text = str_replace(array('  ', "\n "), array('  ', "\n "), $text);
         if (!strncmp($text, ' ', 1)) {
             $text = ' ' . substr($text, 1);
         }
     } else {
         $error = new IMP_Mime_Status_RenderIssue($this->_mimepart, array(_("Cannot display message text."), _("The message part may contain incorrect character set information preventing correct display.")));
         $error->action(IMP_Mime_Status::ERROR);
         $status[] = $error;
     }
     return array($mime_id => array('data' => "<div class=\"fixed leftAlign\">\n" . $text . '</div>', 'status' => $status, 'type' => $type));
 }