DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:lightbox

Lightbox with gallery plugin

If you are using Gallery plugin, you can have lightbox effects on your images with a little effort.

Gallery plugin has PrettyPhoto library already. So if you change few lines of source code of dokuwiki parser, You can have PrettyPhoto.

:!: If you upgrade your DokuWiki, these changes will be overwritten. So you must do them again :-\

Internal image

  • go to installation folder of your dokuwiki and find xhtml.php at inc/parser/xhtml.php.
  • find function internalmedia
  • delete or remark the line 1077
$link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
  • and insert two lines there.
/* gallery lightbox */ $link['url']= ml($src,array('cache'=>$cache));
/* gallery lightbox */ $link['rel']="lightbox[".$ID."]";                 

The final result is

    /**
     * Render an internal media file
     *
     * @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 string $linking   linkonly|detail|nolink
     * @param bool   $return    return HTML instead of adding to $doc
     * @return void|string
     */
    function internalmedia($src, $title = null, $align = null, $width = null,
                           $height = null, $cache = null, $linking = null, $return = false) {
        global $ID;
        list($src, $hash) = explode('#', $src, 2);
        resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true);
 
        $noLink = false;
        $render = ($linking == 'linkonly') ? false : true;
        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
 
        list($ext, $mime) = mimetype($src, false);
        if(substr($mime, 0, 5) == 'image' && $render) {
            // $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
            /* gallery lightbox */ $link['url']    = ml($src,array('cache'=>$cache));  //추가 vaslor
            /* gallery lightbox */ $link['rel']="lightbox[".$ID."]";                  //추가 vaslor
        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
            // don't link movies
            $noLink = true;
        } else {
            // add file icons
            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
            $link['class'] .= ' mediafile mf_'.$class;
            $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true);
            if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')';
        }
 
        if($hash) $link['url'] .= '#'.$hash;
 
        //markup non existing files
        if(!$exists) {
            $link['class'] .= ' wikilink2';
        }
 
        //output formatted
        if($return) {
            if($linking == 'nolink' || $noLink) return $link['name'];
            else return $this->_formatLink($link);
        } else {
            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
            else $this->doc .= $this->_formatLink($link);
        }
    }

External image

you can do same thing with external image.

  • find function externalmedia
  • just insert one line. no deletion.
  /* gallery lightbox */ $link['rel']="lightbox[".$ID."]";  // 추가.. vaslor
    /**
     * Render an external media file
     *
     * @param string $src     full media URL
     * @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 string $linking linkonly|detail|nolink
     * @param bool   $return  return HTML instead of adding to $doc
     */
    function externalmedia($src, $title = null, $align = null, $width = null,
                           $height = null, $cache = null, $linking = null, $return = false) {
        list($src, $hash) = explode('#', $src, 2);
        $noLink = false;
        $render = ($linking == 'linkonly') ? false : true;
        $link   = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
 
        $link['url'] = ml($src, array('cache' => $cache));
 
        list($ext, $mime) = mimetype($src, false);
        if(substr($mime, 0, 5) == 'image' && $render) {
            // link only jpeg images
            // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
            /* gallery lightbox */ $link['rel']="lightbox[".$ID."]";  // 추가.. vaslor
        } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
            // don't link movies
            $noLink = true;
        } else {
            // add file icons
            $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
            $link['class'] .= ' mediafile mf_'.$class;
        }
 
        if($hash) $link['url'] .= '#'.$hash;
 
        //output formatted
        if($return) {
            if($linking == 'nolink' || $noLink) return $link['name'];
            else return $this->_formatLink($link);
        } else {
            if($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
            else $this->doc .= $this->_formatLink($link);
        }
    }

Internal image with slideshow grouping

Why?

  • To decide which image will have lightbox slideshow
  • Group together images into slideshow on one page as you like

How?

  • Apply new internal image hash parameter ss [:slide-show:]
  • Grouping is done by the value of ss parametter which is number and it is mandatory

E.g.

{{imagefile1.jpg#ss=1?640x480}} <- Slideshow group #1
{{imagefile2.jpg#ss=1?640x480}} <- Slideshow group #1
{{imagefile3.jpg#ss=2?640x480}} <- Slideshow group #2
{{imagefile4.jpg#ss=2?640x480}} <- Slideshow group #2
{{imagefile5.jpg?640x480}} <- Image without slideshow! :)

:!: Notice that all hash parameters started by # sign are right after the filename and before the regular image link parameters, before the ? symbol!

How to implement this adjustment?

  • Find file inc/parser/xhtml.php
  • Find function internalmedia()
  • Find this line:
$link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
  • Insert 8 new lines before line above:
// activate lightbox slideshow group by #ss=1
if (!is_null(plugin_load('syntax', 'gallery'))) {
    $match = array();
    if (preg_match('/(?:^|(?<=&))ss=(\d+)(?:(?=&)|$)/', $hash, $match)) {
        $linking = 'direct';
        $link['rel'] = 'lightbox[gal-'.substr(md5($ID.'#ss='.$match[1]),4).']';
    }
}

Patch for DokuWiki version 2015-08-10a:

xhtml.php.patch
--- dokuwiki-old/inc/parser/xhtml.php   2015-08-23 15:57:26.000000000 +0200
+++ dokuwiki/inc/parser/xhtml.php   2016-08-04 15:30:31.732748953 +0200
@@ -1117,6 +1117,14 @@
 
         list($ext, $mime) = mimetype($src, false);
         if(substr($mime, 0, 5) == 'image' && $render) {
+            // activate lightbox slideshow group by #ss=1
+            if (!is_null(plugin_load('syntax', 'gallery'))) {
+                $match = array();
+                if (preg_match('/(?:^|(?<=&))ss=(\d+)(?:(?=&)|$)/', $hash, $match)) {
+                    $linking = 'direct';
+                    $link['rel'] = 'lightbox[gal-'.substr(md5($ID.'#ss='.$match[1]),4).']';
+                }
+            }
             $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct'));
         } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
             // don't link movies
tips/lightbox.txt · Last modified: 2016-08-05 03:59 by mirekn

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki