IMP_Contents::getSummary PHP Method

getSummary() public method

Get summary info for a MIME ID.
public getSummary ( string $id, integer $mask ) : array
$id string The MIME ID.
$mask integer A bitmask indicating what information to return:
Always output:
  'type' = MIME type

IMP_Contents::SUMMARY_BYTES
  Output: parts = 'bytes'

IMP_Contents::SUMMARY_SIZE
  Output: parts = 'size'

IMP_Contents::SUMMARY_ICON
IMP_Contents::SUMMARY_ICON_RAW
  Output: parts = 'icon'

IMP_Contents::SUMMARY_DESCRIP
  Output: parts = 'description_raw'

IMP_Contents::SUMMARY_DESCRIP_LINK
  Output: parts = 'description'

IMP_Contents::SUMMARY_DOWNLOAD
  Output: parts = 'download', 'download_url'

IMP_Contents::SUMMARY_IMAGE_SAVE
  Output: parts = 'img_save'

IMP_Contents::SUMMARY_PRINT
IMP_Contents::SUMMARY_PRINT_STUB
  Output: parts = 'print'

IMP_Contents::SUMMARY_STRIP
  Output: parts = 'strip'
return array An array with the requested information.
    public function getSummary($id, $mask = 0)
    {
        $autodetect_link = false;
        $param_array = array();
        $this->_buildMessage();
        $part = array('bytes' => null, 'download' => null, 'download_url' => null, 'id' => $id, 'img_save' => null, 'size' => null, 'strip' => null);
        $mime_part = $this->getMimePart($id, array('nocontents' => true));
        if (!$mime_part) {
            return $part;
        }
        $mime_type = $mime_part->getType();
        /* If this is an attachment that has no specific MIME type info, see
         * if we can guess a rendering type. */
        if (in_array($mime_type, array('application/octet-stream', 'application/base64'))) {
            $mime_type = Horde_Mime_Magic::filenameToMIME($mime_part->getName());
            if ($mime_type == $mime_part->getType()) {
                $autodetect_link = true;
            } else {
                $mime_part = clone $mime_part;
                $mime_part->setType($mime_type);
                $param_array['ctype'] = $mime_type;
            }
        }
        $part['type'] = $mime_type;
        /* Is this part an attachment? */
        $is_atc = $mime_part->isAttachment();
        /* Get bytes/size information. */
        if ($mask & self::SUMMARY_BYTES || $mask & self::SUMMARY_SIZE) {
            $part['bytes'] = $size = $mime_part->getBytes();
            $part['size'] = $size > 1048576 ? sprintf(_("%s MB"), IMP::numberFormat($size / 1048576, 1)) : sprintf(_("%s KB"), max(round($size / 1024), 1));
        }
        /* Get part's icon. */
        if ($mask & self::SUMMARY_ICON || $mask & self::SUMMARY_ICON_RAW) {
            $part['icon'] = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->getIcon($mime_type);
            if ($mask & self::SUMMARY_ICON) {
                $part['icon'] = Horde_Themes_Image::tag($part['icon'], array('attr' => array('title' => $mime_type)));
            }
        } else {
            $part['icon'] = null;
        }
        /* Get part's description. */
        $description = $this->getPartName($mime_part, true);
        if ($mask & self::SUMMARY_DESCRIP_LINK) {
            if (($can_d = $this->canDisplay($mime_part, self::RENDER_FULL)) || $autodetect_link) {
                $part['description'] = $this->linkViewJS($mime_part, 'view_attach', htmlspecialchars($description), array('jstext' => sprintf(_("View %s"), $description), 'params' => array_filter(array_merge($param_array, array('autodetect' => !$can_d)))));
            } else {
                $part['description'] = htmlspecialchars($description);
            }
        }
        if ($mask & self::SUMMARY_DESCRIP) {
            $part['description_raw'] = $description;
        }
        /* Download column. */
        if ($is_atc && $mask & self::SUMMARY_DOWNLOAD) {
            $part['download'] = $this->linkView($mime_part, 'download_attach', '', array('attr' => array('download' => $mime_part->getName(true) ?: $mime_part->getPrimaryType()), 'class' => 'iconImg downloadAtc', 'jstext' => _("Download")));
            $part['download_url'] = $this->urlView($mime_part, 'download_attach');
        }
        /* Display the image save link if the required registry calls are
         * present. */
        if ($mask & self::SUMMARY_IMAGE_SAVE && $GLOBALS['registry']->hasMethod('images/selectGalleries') && $mime_part->getPrimaryType() == 'image') {
            $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'iconImg saveImgAtc', null, Horde::popupJs(IMP_Basic_Saveimage::url(), array('params' => array('muid' => strval($this->getIndicesOb()), 'id' => $id), 'height' => 200, 'width' => 450, 'urlencode' => true)) . 'return false;') . '</a>';
        }
        /* Add print link? */
        if (($mask & self::SUMMARY_PRINT || $mask & self::SUMMARY_PRINT_STUB) && $this->canDisplay($id, self::RENDER_FULL)) {
            $part['print'] = $mask & self::SUMMARY_PRINT ? $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'iconImg printAtc', 'jstext' => _("Print"), 'onload' => 'IMP_JS.printWindow', 'params' => $param_array)) : Horde::link('#', _("Print"), 'iconImg printAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
        }
        /* Strip Attachment? Allow stripping of base parts other than the
         * base multipart and the base text (body) part. */
        if ($mask & self::SUMMARY_STRIP && $id != 0 && intval($id) != 1 && strpos($id, '.') === false) {
            $part['strip'] = Horde::link(Horde::selfUrlParams()->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'muid' => strval($this->getIndicesOb()), 'token' => $GLOBALS['session']->getToken())), _("Strip Attachment"), 'iconImg deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . '</a>';
        }
        return $part;
    }

Usage Example

Example #1
0
 /**
  * Generate inline message display.
  *
  * @param array $options  Options:
  *   - mask: (integer) The mask needed for a getSummary() call.
  *   - mimeid: (string) Restrict output to this MIME ID (and children).
  *
  * @return array  See getInlineOutput().
  */
 protected function _getInlineOutput(array $options)
 {
     global $prefs, $registry;
     $atc_parts = $display_ids = $i = $metadata = $msgtext = $wrap_ids = array();
     $text_out = '';
     $view = $registry->getView();
     $contents_mask = isset($options['mask']) ? $options['mask'] : 0;
     $mimeid_filter = isset($options['mimeid']) ? new Horde_Mime_Id($options['mimeid']) : null;
     $show_parts = $prefs->getValue('parts_display');
     foreach ($this->contents->getMIMEMessage()->partIterator() as $part) {
         $mime_id = $part->getMimeId();
         $i[] = $mime_id;
         if (isset($display_ids[$mime_id]) || isset($atc_parts[$mime_id])) {
             continue;
         }
         if ($mimeid_filter && (strval($mimeid_filter) != $mime_id && !$mimeid_filter->isChild($mime_id))) {
             continue;
         }
         if (!($render_mode = $this->contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE_AUTO))) {
             if (IMP_Mime_Attachment::isAttachment($part)) {
                 if ($show_parts == 'atc') {
                     $atc_parts[$mime_id] = 1;
                 }
                 if ($contents_mask) {
                     $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true));
                 }
             }
             continue;
         }
         $render_part = $this->contents->renderMIMEPart($mime_id, $render_mode);
         if ($show_parts == 'atc' && IMP_Mime_Attachment::isAttachment($part) && (empty($render_part) || !($render_mode & IMP_Contents::RENDER_INLINE))) {
             $atc_parts[$mime_id] = 1;
         }
         if (empty($render_part)) {
             if ($contents_mask && IMP_Mime_Attachment::isAttachment($part)) {
                 $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true));
             }
             continue;
         }
         reset($render_part);
         while (list($id, $info) = each($render_part)) {
             $display_ids[$id] = 1;
             if (empty($info)) {
                 continue;
             }
             $part_text = $contents_mask && empty($info['nosummary']) ? $this->_formatSummary($this->contents->getSummary($id, $contents_mask), !empty($info['attach'])) : '';
             if (empty($info['attach'])) {
                 if (isset($info['status'])) {
                     if (!is_array($info['status'])) {
                         $info['status'] = array($info['status']);
                     }
                     $render_issues = array();
                     foreach ($info['status'] as $val) {
                         if (in_array($view, $val->views)) {
                             if ($val instanceof IMP_Mime_Status_RenderIssue) {
                                 $render_issues[] = $val;
                             } else {
                                 $part_text .= strval($val);
                             }
                         }
                     }
                     if (!empty($render_issues)) {
                         $render_issues_ob = new IMP_Mime_Status_RenderIssue_Display();
                         $render_issues_ob->addIssues($render_issues);
                         $part_text .= strval($render_issues_ob);
                     }
                 }
                 $part_text .= '<div class="mimePartData">' . $info['data'] . '</div>';
             } elseif ($show_parts == 'atc') {
                 $atc_parts[$id] = 1;
             }
             $msgtext[$id] = array('text' => $part_text, 'wrap' => empty($info['wrap']) ? null : $info['wrap']);
             if (isset($info['metadata'])) {
                 /* Format: array(identifier, ...[data]...) */
                 $metadata = array_merge($metadata, $info['metadata']);
             }
         }
     }
     if (!empty($msgtext)) {
         uksort($msgtext, 'strnatcmp');
     }
     reset($msgtext);
     while (list($id, $part) = each($msgtext)) {
         while (!empty($wrap_ids)) {
             $id_ob = new Horde_Mime_Id(end($wrap_ids));
             if ($id_ob->isChild($id)) {
                 break;
             }
             array_pop($wrap_ids);
             $text_out .= '</div>';
         }
         if (!empty($part['wrap'])) {
             $text_out .= '<div class="' . $part['wrap'] . '" impcontentsmimeid="' . $id . '">';
             $wrap_ids[] = $id;
         }
         $text_out .= '<div class="mimePartBase"' . (empty($part['wrap']) ? ' impcontentsmimeid="' . $id . '"' : '') . '>' . $part['text'] . '</div>';
     }
     $text_out .= str_repeat('</div>', count($wrap_ids));
     if (!strlen($text_out)) {
         $text_out = strval(new IMP_Mime_Status(null, _("There are no parts that can be shown inline.")));
     }
     $atc_parts = $show_parts == 'all' ? $i : array_keys($atc_parts);
     return array('atc_parts' => $atc_parts, 'display_ids' => array_keys($display_ids), 'metadata' => $metadata, 'msgtext' => $text_out, 'one_part' => count($i) === 1);
 }
All Usage Examples Of IMP_Contents::getSummary