LightboxGallery.php
changeset 2 e7eb457efdff
parent 1 d2584c5a075c
child 3 b52509cf73af
equal deleted inserted replaced
1:d2584c5a075c 2:e7eb457efdff
     9   "Author URI"   : "http://enanocms.org/"
     9   "Author URI"   : "http://enanocms.org/"
    10 }
    10 }
    11 **!*/
    11 **!*/
    12 
    12 
    13 // Hook into wikitext render flow
    13 // Hook into wikitext render flow
    14 $plugins->attachHook('render_wikiformat_pre', 'lbgallery_process_tags($text);');
    14 $plugins->attachHook('render_wikiformat_posttemplates', 'lbgallery_process_tags($text);');
    15 $plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array(); $whitelist["randomimage"] = array("/");');
    15 $plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array(); $whitelist["randomimage"] = array("/");');
    16 
    16 
    17 function lbgallery_process_tags(&$text)
    17 function lbgallery_process_tags(&$text)
    18 {
    18 {
       
    19   // if there are no galleries in this blob, just get out here. also pulls all the matches we need.
    19   if ( !preg_match_all('#<lightboxgallery(?: maxwidth="?([0-9]+)"?)>(.+?)</lightboxgallery>#s', $text, $matches) )
    20   if ( !preg_match_all('#<lightboxgallery(?: maxwidth="?([0-9]+)"?)>(.+?)</lightboxgallery>#s', $text, $matches) )
    20     return true;
    21     return true;
    21   
    22   
    22   lbgallery_add_headers();
    23   lbgallery_add_headers();
    23   
    24   
    24   foreach ( $matches[0] as $i => $match )
    25   foreach ( $matches[0] as $i => $match )
    25   {
    26   {
       
    27     // actual parser loop is pretty simple.
    26     $gallery = lbgallery_build_gallery($matches[2][$i], $matches[1][$i]);
    28     $gallery = lbgallery_build_gallery($matches[2][$i], $matches[1][$i]);
    27     $text = str_replace($match, $gallery, $text);
    29     $text = str_replace($match, $gallery, $text);
    28   }
    30   }
    29 }
    31 }
    30 
    32 
    56         };
    58         };
    57         jQuery(selector).lightBox(settings);
    59         jQuery(selector).lightBox(settings);
    58       }
    60       }
    59     </script>');
    61     </script>');
    60 }
    62 }
       
    63 
       
    64 // The actual function to build the HTML behind a gallery.
    61 
    65 
    62 function lbgallery_build_gallery($gallerytag, $width)
    66 function lbgallery_build_gallery($gallerytag, $width)
    63 {
    67 {
    64   // parse out any text sections
    68   // parse out any text sections
    65   $text = preg_replace('#^.*<trigger>(.+?)</trigger>.*$#s', '$1', $gallerytag);
    69   $text = preg_replace('#^.*<trigger>(.+?)</trigger>.*$#s', '$1', $gallerytag);