Пример #1
0
 /**
  * Renders internal and external media with exif info at bottom of each JPEG image
  *
  * @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 . 'lib/plugins/colorbox/JpegMetaGPS.php';
             $jpeg = new JpegMetaGPS(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
         if (($ext == 'jpg' || $ext == 'jpeg') && !$width && !strpos($src, 'wiki:dokuwiki')) {
             // force to scale image to 680px
             $ret .= '<img src="' . ml($src, array('w' => "680", 'h' => $height, 'cache' => $cache, 'rev' => $this->_getLastMediaRevisionAt($src))) . '"';
         } else {
             $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) . '"';
         }
         // add exif and gps info at the bottom of each image
         if ($ext == 'jpg' || $ext == 'jpeg') {
             //try to use the caption from IPTC/EXIF
             if (!$jepg) {
                 require_once DOKU_INC . 'lib/plugins/colorbox/JpegMetaGPS.php';
                 $jpeg = new JpegMetaGPS(mediaFN($src));
             }
             if ($jpeg !== false) {
                 $infoshort = $jpeg->getShortExifInfo();
                 $info = $jpeg->getExifInfo();
                 $gpslink = $jpeg->getGPSInfo();
                 $ret .= ' exif="' . implode(';', array_map(function ($v, $k) {
                     if ($v) {
                         return strtolower($k) . ':' . $v . '';
                     }
                 }, $infoshort, array_keys($infoshort))) . '"';
                 if ($gpslink) {
                     $ret .= ' map="' . $gpslink . '"';
                 }
                 $ret .= ' token="' . media_get_token($src, "1360", $height) . '"';
                 $ret .= '/></a>';
                 $ret .= '<div class="exiftitle">' . $title . '</div>';
                 $ret .= '<div class="exif">';
                 $ret .= implode(', ', array_map(function ($v, $k) {
                     return $k . '=' . $v;
                 }, $info, array_keys($info)));
                 if ($gpslink) {
                     $ret .= ' <a href=' . $gpslink . '>Google GPS Location';
                 }
                 $ret .= ' </a></div>';
                 $ret .= '<a>';
             }
         }
         //
     } 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
 /**
  * Defines how a thumbnail should look like
  */
 function _image(&$img, $data)
 {
     global $ID;
     global $conf;
     // calculate thumbnail size
     if (!$data['crop']) {
         $w = (int) $this->_meta($img, 'width');
         $h = (int) $this->_meta($img, 'height');
         if ($conf['syslog']) {
             syslog(LOG_WARNING, '[gallery:syntax.php] image file: ' . $conf['mediadir'] . utf8_encodeFN(str_replace(':', '/', $img['id'])) . $img['file'] . '. size: ' . $w . 'x' . $h);
         }
         if ($w && $h) {
             $dim = array();
             if ($w > $data['tw'] || $h > $data['th']) {
                 $fr = $w / $h;
                 if ($fr >= $data['tw'] / $data['th']) {
                     $w = $data['tw'];
                     $h = round($w / $fr);
                 } else {
                     $h = $data['th'];
                     $w = round($h * $fr);
                 }
                 $dim = array('w' => $w, 'h' => $h);
                 if ($conf['syslog']) {
                     syslog(LOG_WARNING, '[gallery:syntax.php] image file: ' . $conf['mediadir'] . utf8_encodeFN(str_replace(':', '/', $img['id'])) . $img['file'] . '. reize to: ' . $w . 'x' . $h);
                 }
             }
         } else {
             // this should not happen but if it does this usually means a corrupted image file therefore we want to log it
             syslog(LOG_WARNING, 'no size info found which is likely due to corrupted image file. force crop to ' . $data['tw'] . 'x' . $data['th'] . '. file: ' . $conf['mediadir'] . utf8_encodeFN(str_replace(':', '/', $img['id'])) . $img['file']);
             $data['crop'] = true;
             // no size info -> always crop
         }
     }
     if ($data['crop']) {
         $w = $data['tw'];
         $h = $data['th'];
         $dim = array('w' => $w, 'h' => $h);
     }
     //prepare img attributes
     $i = array();
     $i['width'] = $w;
     $i['height'] = $h;
     $i['border'] = 0;
     if ($this->_meta($img, 'title')) {
         $i['alt'] = $this->_meta($img, 'title');
     } else {
         $i['alt'] = end(explode(":", $img['id']));
     }
     $i['longdesc'] = str_replace("\n", ' ', $this->_meta($img, 'desc'));
     if (!$i['longdesc']) {
         unset($i['longdesc']);
     }
     $i['class'] = 'tn';
     // get exif and gps info
     $orientation = $img['meta']->getField("Orientation");
     if ($conf['syslog']) {
         syslog(LOG_WARNING, '[gallery:syntax.php] orientation: ' . $orientation);
     }
     switch ($orientation) {
         case 6:
             if ($i['width'] > $i['height']) {
                 // swap width and height if the image is going to be rotated vertically
                 if ($conf['syslog']) {
                     syslog(LOG_WARNING, 'swap width and height as the image is going to be rotated vertically');
                 }
                 $old_width = $i['width'];
                 $i['width'] = $i['height'];
                 $i['height'] = $old_width;
             }
             break;
         case 8:
             if ($i['width'] > $i['height']) {
                 // swap width and height if the image is going to be rotated vertically
                 if ($conf['syslog']) {
                     syslog(LOG_WARNING, 'swap width and height as the image is going to be rotated vertically');
                 }
                 $old_width = $i['width'];
                 $i['width'] = $i['height'];
                 $i['height'] = $old_width;
             }
             break;
     }
     require_once DOKU_INC . 'lib/plugins/colorbox/JpegMetaGPS.php';
     $jpeg = new JpegMetaGPS(mediaFN($img['id']));
     if ($jpeg !== false) {
         $info = $jpeg->getShortExifInfo();
         $gpslink = $jpeg->getGPSInfo();
         if ($info) {
             $i['exif'] = implode(';', array_map(function ($v, $k) {
                 if ($v) {
                     return strtolower($k) . ':' . $v . '';
                 }
             }, $info, array_keys($info)));
         }
         if ($gpslink) {
             $i['map'] = $gpslink;
         }
         $i['token'] = media_get_token($img['id'], "1360", "0");
     }
     $iatt = buildAttributes($i);
     $src = ml($img['id'], $dim);
     // prepare lightbox dimensions
     $w_lightbox = (int) $this->_meta($img, 'width');
     $h_lightbox = (int) $this->_meta($img, 'height');
     $dim_lightbox = array();
     if ($w_lightbox > $data['iw'] || $h_lightbox > $data['ih']) {
         $ratio = $this->_ratio($img, $data['iw'], $data['ih']);
         $w_lightbox = floor($w_lightbox * $ratio);
         $h_lightbox = floor($h_lightbox * $ratio);
         $dim_lightbox = array('w' => $w_lightbox, 'h' => $h_lightbox);
     }
     //prepare link attributes
     $a = array();
     $a['title'] = $this->_meta($img, 'title');
     if ($data['lightbox']) {
         $href = ml($img['id'], $dim_lightbox);
         $a['class'] = "lightbox JSnocheck";
         $a['rel'] = 'lightbox[gal-' . substr(md5($ID), 4) . ']';
         //unique ID for the gallery
     } elseif ($img['detail'] && !$data['direct']) {
         $href = $img['detail'];
     } else {
         $href = ml($img['id'], array('id' => $ID), $data['direct']);
     }
     $aatt = buildAttributes($a);
     // prepare output
     $ret = '';
     $ret .= '<a href="' . $href . '" ' . $aatt . '>';
     $ret .= '<img src="' . $src . '" ' . $iatt . ' />';
     $ret .= '</a>';
     return $ret;
 }