IMP_Contents::canDisplay PHP Method

canDisplay() public method

Can this MIME part be displayed in the given mode?
public canDisplay ( mixed $part, integer $mask, string $type = null ) : integer
$part mixed The MIME part or a MIME ID string.
$mask integer One of the RENDER_ constants.
$type string The type to use (overrides the MIME ID if $id is a MIME part).
return integer The RENDER_ constant of the allowable display.
    public function canDisplay($part, $mask, $type = null)
    {
        if (!is_object($part) && !($part = $this->getMimePart($part, array('nocontents' => true)))) {
            return 0;
        }
        $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($part, array('contents' => $this, 'type' => $type));
        if ($mask & self::RENDER_INLINE_AUTO) {
            $mask |= self::RENDER_INLINE | self::RENDER_INFO;
        }
        if ($mask & self::RENDER_RAW && $viewer->canRender('raw')) {
            return self::RENDER_RAW;
        }
        if ($mask & self::RENDER_FULL && $viewer->canRender('full')) {
            return self::RENDER_FULL;
        }
        if ($mask & self::RENDER_INLINE) {
            if ($viewer->canRender('inline')) {
                return self::RENDER_INLINE;
            }
        } elseif ($mask & self::RENDER_INLINE_DISP_NO && $viewer->canRender('inline')) {
            return self::RENDER_INLINE_DISP_NO;
        }
        if ($mask & self::RENDER_INFO && $viewer->canRender('info')) {
            return self::RENDER_INFO;
        }
        return 0;
    }

Usage Example

Example #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::canDisplay