コード例 #1
0
ファイル: xhtml.php プロジェクト: sawachan/dokuwiki
 /**
  * Renders internal and external media
  *
  * @author Andreas Gohr <*****@*****.**>
  * @param string $src       media ID
  * @param string $title     descriptive text
  * @param string $align     left|center|right
  * @param int    $width     width of media in pixel
  * @param int    $height    height of media in pixel
  * @param string $cache     cache|recache|nocache
  * @param bool   $render    should the media be embedded inline or just linked
  * @return string
  */
 function _media($src, $title = null, $align = null, $width = null, $height = null, $cache = null, $render = true)
 {
     $ret = '';
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         // first get the $title
         if (!is_null($title)) {
             $title = $this->_xmlEntities($title);
         } elseif ($ext == 'jpg' || $ext == 'jpeg') {
             //try to use the caption from IPTC/EXIF
             require_once DOKU_INC . 'inc/JpegMeta.php';
             $jpeg = new JpegMeta(mediaFN($src));
             if ($jpeg !== false) {
                 $cap = $jpeg->getTitle();
             }
             if (!empty($cap)) {
                 $title = $this->_xmlEntities($cap);
             }
         }
         if (!$render) {
             // if the picture is not supposed to be rendered
             // return the title of the picture
             if (!$title) {
                 // just show the sourcename
                 $title = $this->_xmlEntities(utf8_basename(noNS($src)));
             }
             return $title;
         }
         //add image tag
         $ret .= '<img src="' . ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev' => $this->_getLastMediaRevisionAt($src))) . '"';
         $ret .= ' class="media' . $align . '"';
         if ($title) {
             $ret .= ' title="' . $title . '"';
             $ret .= ' alt="' . $title . '"';
         } else {
             $ret .= ' alt=""';
         }
         if (!is_null($width)) {
             $ret .= ' width="' . $this->_xmlEntities($width) . '"';
         }
         if (!is_null($height)) {
             $ret .= ' height="' . $this->_xmlEntities($height) . '"';
         }
         $ret .= ' />';
     } elseif (media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) {
         // first get the $title
         $title = !is_null($title) ? $this->_xmlEntities($title) : false;
         if (!$render) {
             // if the file is not supposed to be rendered
             // return the title of the file (just the sourcename if there is no title)
             return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src)));
         }
         $att = array();
         $att['class'] = "media{$align}";
         if ($title) {
             $att['title'] = $title;
         }
         if (media_supportedav($mime, 'video')) {
             //add video
             $ret .= $this->_video($src, $width, $height, $att);
         }
         if (media_supportedav($mime, 'audio')) {
             //add audio
             $ret .= $this->_audio($src, $att);
         }
     } elseif ($mime == 'application/x-shockwave-flash') {
         if (!$render) {
             // if the flash is not supposed to be rendered
             // return the title of the flash
             if (!$title) {
                 // just show the sourcename
                 $title = utf8_basename(noNS($src));
             }
             return $this->_xmlEntities($title);
         }
         $att = array();
         $att['class'] = "media{$align}";
         if ($align == 'right') {
             $att['align'] = 'right';
         }
         if ($align == 'left') {
             $att['align'] = 'left';
         }
         $ret .= html_flashobject(ml($src, array('cache' => $cache), true, '&'), $width, $height, array('quality' => 'high'), null, $att, $this->_xmlEntities($title));
     } elseif ($title) {
         // well at least we have a title to display
         $ret .= $this->_xmlEntities($title);
     } else {
         // just show the sourcename
         $ret .= $this->_xmlEntities(utf8_basename(noNS($src)));
     }
     return $ret;
 }
コード例 #2
0
ファイル: xhtml.php プロジェクト: canneverbe/flyspray
 /**
  * Renders internal and external media
  *
  * @author Andreas Gohr <*****@*****.**>
  */
 function _media($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL)
 {
     $ret = '';
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         //add image tag
         $ret .= '<img src="' . ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache)) . '"';
         $ret .= ' class="media' . $align . '"';
         if (!is_null($title)) {
             $ret .= ' title="' . $this->_xmlEntities($title) . '"';
             $ret .= ' alt="' . $this->_xmlEntities($title) . '"';
         } elseif ($ext == 'jpg' || $ext == 'jpeg') {
             //try to use the caption from IPTC/EXIF
             require_once DOKU_INC . 'inc/JpegMeta.php';
             $jpeg = new JpegMeta(mediaFN($src));
             if ($jpeg !== false) {
                 $cap = $jpeg->getTitle();
             }
             if ($cap) {
                 $ret .= ' title="' . $this->_xmlEntities($cap) . '"';
                 $ret .= ' alt="' . $this->_xmlEntities($cap) . '"';
             }
         } else {
             $ret .= ' alt=""';
         }
         if (!is_null($width)) {
             $ret .= ' width="' . $this->_xmlEntities($width) . '"';
         }
         if (!is_null($height)) {
             $ret .= ' height="' . $this->_xmlEntities($height) . '"';
         }
         $ret .= ' />';
     } elseif ($mime == 'application/x-shockwave-flash') {
         $ret .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' . ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"';
         if (!is_null($width)) {
             $ret .= ' width="' . $this->_xmlEntities($width) . '"';
         }
         if (!is_null($height)) {
             $ret .= ' height="' . $this->_xmlEntities($height) . '"';
         }
         $ret .= '>' . DOKU_LF;
         $ret .= '<param name="movie" value="' . ml($src) . '" />' . DOKU_LF;
         $ret .= '<param name="quality" value="high" />' . DOKU_LF;
         $ret .= '<embed src="' . ml($src) . '"' . ' quality="high"';
         if (!is_null($width)) {
             $ret .= ' width="' . $this->_xmlEntities($width) . '"';
         }
         if (!is_null($height)) {
             $ret .= ' height="' . $this->_xmlEntities($height) . '"';
         }
         $ret .= ' type="application/x-shockwave-flash"' . ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' . DOKU_LF;
         $ret .= '</object>' . DOKU_LF;
     } elseif (!is_null($title)) {
         // well at least we have a title to display
         $ret .= $this->_xmlEntities($title);
     } else {
         // just show the sourcename
         $ret .= $this->_xmlEntities(noNS($src));
     }
     return $ret;
 }
コード例 #3
0
ファイル: xhtml.php プロジェクト: houshuang/folders2web
 /**
  * Renders internal and external media
  *
  * @author Andreas Gohr <*****@*****.**>
  */
 function _media($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $render = true)
 {
     $ret = '';
     list($ext, $mime, $dl) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         // first get the $title
         if (!is_null($title)) {
             $title = $this->_xmlEntities($title);
         } elseif ($ext == 'jpg' || $ext == 'jpeg') {
             //try to use the caption from IPTC/EXIF
             require_once DOKU_INC . 'inc/JpegMeta.php';
             $jpeg = new JpegMeta(mediaFN($src));
             if ($jpeg !== false) {
                 $cap = $jpeg->getTitle();
             }
             if ($cap) {
                 $title = $this->_xmlEntities($cap);
             }
         }
         if (!$render) {
             // if the picture is not supposed to be rendered
             // return the title of the picture
             if (!$title) {
                 // just show the sourcename
                 $title = $this->_xmlEntities(basename(noNS($src)));
             }
             return $title;
         }
         //add image tag
         $ret .= '<img src="' . ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache)) . '"';
         $ret .= ' class="media' . $align . '"';
         // make left/right alignment for no-CSS view work (feeds)
         if ($align == 'right') {
             $ret .= ' align="right"';
         }
         if ($align == 'left') {
             $ret .= ' align="left"';
         }
         if ($title) {
             $ret .= ' title="' . $title . '"';
             $ret .= ' alt="' . $title . '"';
         } else {
             $ret .= ' alt=""';
         }
         if (!is_null($width)) {
             $ret .= ' width="' . $this->_xmlEntities($width) . '"';
         }
         if (!is_null($height)) {
             $ret .= ' height="' . $this->_xmlEntities($height) . '"';
         }
         $ret .= ' />';
     } elseif ($mime == 'application/x-shockwave-flash') {
         if (!$render) {
             // if the flash is not supposed to be rendered
             // return the title of the flash
             if (!$title) {
                 // just show the sourcename
                 $title = basename(noNS($src));
             }
             return $this->_xmlEntities($title);
         }
         $att = array();
         $att['class'] = "media{$align}";
         if ($align == 'right') {
             $att['align'] = 'right';
         }
         if ($align == 'left') {
             $att['align'] = 'left';
         }
         $ret .= html_flashobject(ml($src, array('cache' => $cache), true, '&'), $width, $height, array('quality' => 'high'), null, $att, $this->_xmlEntities($title));
     } elseif ($title) {
         // well at least we have a title to display
         $ret .= $this->_xmlEntities($title);
     } else {
         // just show the sourcename
         $ret .= $this->_xmlEntities(basename(noNS($src)));
     }
     return $ret;
 }
コード例 #4
0
 /**
  * Replaces titles of non-labeled internal media links with their original filenames
  */
 function _replaceLinkTitle(&$event)
 {
     global $ID;
     global $conf;
     require_once DOKU_INC . 'inc/JpegMeta.php';
     $ns = getNS($ID);
     // get the instructions list from the handler
     $calls =& $event->data->calls;
     // array index numbers for readability
     list($handler_name, $instructions, $source, $title, $linking) = array(0, 1, 0, 1, 6);
     // scan media link and mark it with its original filename
     $last = count($calls) - 1;
     for ($i = 0; $i <= $last; $i++) {
         // NOTE: 'externalmedia' is processed here because there is a
         //       basename() bug in fetching its auto-filled linktext.
         //       For more details please see common->_correctBasename().
         if (!preg_match('/^(?:in|ex)ternalmedia$/', $calls[$i][$handler_name])) {
             continue;
         }
         $inst =& $calls[$i][$instructions];
         $filename = false;
         $linktext = $inst[$title];
         $linkonly = $inst[$linking] === 'linkonly';
         list($src, $hash) = explode('#', $inst[$source], 2);
         // get original filename
         if ($calls[$i][$handler_name] === 'internalmedia') {
             resolve_mediaid($ns, $src, $exists);
             list($ext, $mime, $dl) = mimetype($src);
             $filename = $this->_getOriginalFileName($src);
         } else {
             list($ext, $mime, $dl) = mimetype($src);
         }
         // prefetch auto-filled linktext
         if (!$linktext) {
             if (substr($mime, 0, 5) === 'image' && ($ext === 'jpg' || $ext === 'jpeg') && ($jpeg = new JpegMeta(mediaFN($src))) && ($caption = $jpeg->getTitle())) {
                 $linktext = $caption;
             } else {
                 $linktext = $this->common->_correctBasename(noNS($src));
             }
         }
         // add a marker (normally you cannot put '}}' in a media link title
         // and cannot put ':' in a filename)
         if ($filename === false) {
             $inst[$title] = $linktext;
         } elseif ($inst[$title] !== $linktext) {
             $inst[$title] = $linktext . '}}preservefilenames:autofilled:' . $filename;
         } else {
             $inst[$title] = $linktext . '}}preservefilenames::' . $filename;
         }
     }
 }