Added <randomimage /> tag in trigger
authorDan
Tue, 26 May 2009 01:58:15 -0400
changeset 1 d2584c5a075c
parent 0 1978f8d29bea
child 2 e7eb457efdff
Added <randomimage /> tag in trigger
LightboxGallery.php
--- a/LightboxGallery.php	Tue May 26 01:50:16 2009 -0400
+++ b/LightboxGallery.php	Tue May 26 01:58:15 2009 -0400
@@ -12,7 +12,7 @@
 
 // Hook into wikitext render flow
 $plugins->attachHook('render_wikiformat_pre', 'lbgallery_process_tags($text);');
-$plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array();');
+$plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array(); $whitelist["randomimage"] = array("/");');
 
 function lbgallery_process_tags(&$text)
 {
@@ -112,14 +112,19 @@
   
   if ( $text )
   {
-    $trigger = str_replace('<a>', $firstimagetag, trim($text));
+    $trigger = trim($text);
   }
   else
   {
-    list($image, $alt) = $imagelist[ array_rand($imagelist) ];
-    $trigger = $firstimagetag . '<img alt="' . htmlspecialchars($alt) . '" src="' . makeUrlNS('Special', "DownloadFile/$image", "preview", true) . '" />' . '</a>';
+    $trigger = '<a><randomimage /></a>';
   }
   
+  $trigger = str_replace('<a>', $firstimagetag, $trigger);
+  
+  list($image, $alt) = $imagelist[ array_rand($imagelist) ];
+  $randomimage = '<img alt="' . htmlspecialchars($alt) . '" src="' . makeUrlNS('Special', "DownloadFile/$image", "preview", true) . '" />';
+  $trigger = str_replace(array('<randomimage>', '<randomimage/>', '<randomimage />'), $randomimage, $trigger);
+  
   return "$trigger<nowiki>
     <div style=\"display: none;\">$inner</div>
     <script type=\"text/javascript\">