[dokuwiki] gallery plugin improvement

  • From: "Dmitry Baikov" <dsbaikov@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Sun, 22 Oct 2006 20:55:17 +0400

Hello!

I made some changes to gallery plugin and hope it would be useful to somebody.
Default options can now be set from configuration page. Enabled
options can be disabled with no* keywords: noshowname, nodirect,
nolightbox, noreverse. To avoid code duplication I refactored option
parsing into separate function.


Regards,

Dmitry.
diff -r 9e77451eac33 syntax.php
--- a/syntax.php        Tue Oct 17 23:26:30 2006 +0400
+++ b/syntax.php        Sat Oct 21 23:43:29 2006 +0400
@@ -60,6 +60,19 @@ class syntax_plugin_gallery extends Doku
 
 
     /**
+     * Parse option
+     */
+    function parseOpt($params, $name) {
+        if(preg_match('/\b'.$name.'\b/i',$params,$match)) {
+           return true;
+        }else if(preg_match('/\bno'.$name.'\b/i',$params,$match)) {
+           return false;
+       }else{
+            return $this->getConf($name);
+        }
+    }
+
+    /**
      * Handle the match
      */
     function handle($match, $state, $pos, &$handler){
@@ -78,8 +91,8 @@ class syntax_plugin_gallery extends Doku
             $data['w'] = $match[1];
             $data['h'] = $match[2];
         }else{
-            $data['w'] = 120;
-            $data['h'] = 120;
+            $data['w'] = $this->getConf('thumbnail_width');
+            $data['h'] = $this->getConf('thumbnail_height');
         }
 
         //max lightbox dimensions
@@ -87,45 +100,32 @@ class syntax_plugin_gallery extends Doku
             $data['w_lightbox'] = $match[1];
             $data['h_lightbox'] = $match[2];
         }else{
-            $data['w_lightbox'] = 800;
-            $data['h_lightbox'] = 600;
+            $data['w_lightbox'] = $this->getConf('image_width');
+            $data['h_lightbox'] = $this->getConf('image_height');
         }
 
         //number of images per row
         if(preg_match('/\b(\d+)\b/i',$params,$match)){
             $data['cols'] = $match[1];
         }else{
-            $data['cols'] = 5;
+            $data['cols'] = $this->getConf('cols');
         }
 
         //show the filename
-        if(preg_match('/\bshowname\b/i',$params,$match)) {
-            $data['showname'] = true;
-        }else{
-            $data['showname'] = false;
-        }
-
+       $data['showname'] = $this->parseOpt($params, 'showname');
+
+        //lightbox style?
+       $data['lightbox'] = $this->parseOpt($params, 'lightbox');
+       
         //direct linking?
-        if(preg_match('/\bdirect\b/i',$params,$match)) {
-            $data['direct'] = true;
-        }else{
-            $data['direct'] = false;
-        }
-
-        //lightbox style?
-        if(preg_match('/\blightbox\b/i',$params,$match)) {
+       if($data['lightbox']) {
             $data['direct']   = true; //implicit direct linking
-            $data['lightbox'] = true;
-        }else{
-            $data['lightbox'] = false;
-        }
+       }else{
+           $data['direct'] = $this->parseOpt($params, 'direct');
+       }
 
         //reverse sort?
-        if(preg_match('/\breverse\b/i',$params,$match)) {
-            $data['reverse'] = true;
-        }else{
-            $data['reverse'] = false;
-        }
+       $data['reverse'] = $this->parseOpt($params, 'reverse');
 
         return $data;
     }
diff -r 9e77451eac33 conf/default.php
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/default.php  Sat Oct 21 23:44:12 2006 +0400
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Options for the gallery plugin
+ *
+ * @author Dmitry Baikov <dsbaikov@xxxxxxxxx>
+ */
+
+$conf['thumbnail_width']  = 120;
+$conf['thumbnail_height'] = 120;
+$conf['image_width']      = 800;
+$conf['image_height']     = 600;
+$conf['cols']             = 5;
+$conf['direct']           = 0;
+$conf['lightbox']         = 0;
+$conf['showname']         = 0;
+$conf['reverse']          = 0;
diff -r 9e77451eac33 conf/metadata.php
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/metadata.php Sat Oct 21 15:33:04 2006 +0400
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Options for the gallery plugin
+ *
+ * @author Dmitry Baikov <dsbaikov@xxxxxxxxx>
+ */
+
+$meta['thumbnail_width']  = array('numeric');
+$meta['thumbnail_height'] = array('numeric');
+$meta['image_width']      = array('numeric');
+$meta['image_height']     = array('numeric');
+$meta['cols']             = array('numeric');
+$meta['direct']           = array('onoff');
+$meta['lightbox']         = array('onoff');
+$meta['showname']         = array('onoff');
+$meta['reverse']          = array('onoff');
diff -r 9e77451eac33 lang/en/settings.php
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lang/en/settings.php      Sat Oct 21 16:03:02 2006 +0400
@@ -0,0 +1,16 @@
+<?php
+/**
+ * English language file for gallery plugin
+ *
+ * @author Dmitry Baikov <dsbaikov@xxxxxxxxx>
+ */
+
+$lang['thumbnail_width']  = 'Thumbnail image width';
+$lang['thumbnail_height'] = 'Thumbnail image height';
+$lang['image_width']      = 'Image width';
+$lang['image_height']     = 'Image height';
+$lang['cols']             = 'Images per row';
+$lang['direct']           = 'Direct linking';
+$lang['lightbox']         = 'Use Lightbox (implies direct linking)';
+$lang['showname']         = 'Show image filename';
+$lang['reverse']          = 'Reverse sort';

Other related posts:

  • » [dokuwiki] gallery plugin improvement