IMP_Contents::renderMIMEPart PHP Méthode

renderMIMEPart() public méthode

Render a MIME Part.
public renderMIMEPart ( string $mime_id, integer $mode, array $options = [] ) : array
$mime_id string The MIME ID to render.
$mode integer One of the RENDER_ constants.
$options array Additional options: - autodetect: (boolean) Attempt to auto-detect MIME type? - mime_part: (Horde_Mime_Part) The MIME part to render. - type: (string) Use this MIME type instead of the MIME type identified in the MIME part.
Résultat array See Horde_Mime_Viewer_Base::render(). The following fields may also be present in addition to the fields defined in Horde_Mime_Viewer_Base: - attach: (boolean) Force display of this part as an attachment. - js: (array) A list of javascript commands to run after the content is displayed on screen. - name: (string) Contains the MIME name information. - wrap: (string) If present, indicates that this part, and all child parts, will be wrapped in a DIV with the given class name.
    public function renderMIMEPart($mime_id, $mode, array $options = array())
    {
        $this->_buildMessage();
        $mime_part = empty($options['mime_part']) ? $this->getMimePart($mime_id) : $options['mime_part'];
        if (!$mime_part) {
            return array($mime_id => null);
        }
        if (!empty($options['autodetect']) && ($tempfile = Horde::getTempFile()) && ($fp = fopen($tempfile, 'w')) && !is_null($contents = $mime_part->getContents(array('stream' => true)))) {
            rewind($contents);
            while (!feof($contents)) {
                fwrite($fp, fread($contents, 65536));
            }
            fclose($fp);
            $options['type'] = Horde_Mime_Magic::analyzeFile($tempfile, empty($GLOBALS['conf']['mime']['magic_db']) ? null : $GLOBALS['conf']['mime']['magic_db']);
        }
        $type = empty($options['type']) ? null : $options['type'];
        $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, array('contents' => $this, 'type' => $type));
        switch ($mode) {
            case self::RENDER_INLINE:
            case self::RENDER_INLINE_AUTO:
            case self::RENDER_INLINE_DISP_NO:
                $textmode = 'inline';
                $limit = $viewer->getConfigParam('limit_inline_size');
                if ($limit && $mime_part->getBytes() > $limit) {
                    $data = '';
                    $status = new IMP_Mime_Status($mime_part, array(_("This message part cannot be viewed because it is too large."), $this->linkView($mime_part, 'download_attach', _("Click to download the data."))));
                    $status->icon('alerts/warning.png', _("Warning"));
                    if (method_exists($viewer, 'overLimitText')) {
                        $data = $viewer->overLimitText();
                        $status->addText(_("The initial portion of this text part is displayed below."));
                    }
                    return array($mime_id => array('data' => $data, 'name' => '', 'status' => $status, 'type' => 'text/html; charset=' . 'UTF-8'));
                }
                break;
            case self::RENDER_INFO:
                $textmode = 'info';
                break;
            case self::RENDER_RAW:
                $textmode = 'raw';
                break;
            case self::RENDER_RAW_FALLBACK:
                $textmode = $viewer->canRender('raw') ? 'raw' : 'full';
                break;
            case self::RENDER_FULL:
            default:
                $textmode = 'full';
                break;
        }
        $ret = $viewer->render($textmode);
        if (empty($ret)) {
            return $mode == self::RENDER_INLINE_AUTO ? $this->renderMIMEPart($mime_id, self::RENDER_INFO, $options) : array();
        }
        if (!empty($ret[$mime_id]) && !isset($ret[$mime_id]['name'])) {
            $ret[$mime_id]['name'] = $mime_part->getName(true);
        }
        /* Don't show empty parts. */
        if ($textmode == 'inline' && !is_null($ret[$mime_id]['data']) && !strlen($ret[$mime_id]['data']) && !isset($ret[$mime_id]['status'])) {
            $ret[$mime_id] = null;
        }
        return $ret;
    }

Usage Example

Exemple #1
0
 /**
  * Get a MIME Part for use in creating download.
  *
  * @param string $id  MIME ID.
  *
  * @return Horde_Mime_Part  MIME part.
  */
 protected function _getRawDownloadPart($id)
 {
     $mime = $this->_contents->getMIMEPart($id);
     if ($this->_contents->canDisplay($id, IMP_Contents::RENDER_RAW)) {
         $render = $this->_contents->renderMIMEPart($id, IMP_Contents::RENDER_RAW);
         $part = reset($render);
         $mime->setContents($part['data'], array('encoding' => 'binary'));
     }
     return $mime;
 }
All Usage Examples Of IMP_Contents::renderMIMEPart