diff -r 000000000000 -r 1978f8d29bea LightboxGallery.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightboxGallery.php Tue May 26 01:50:16 2009 -0400 @@ -0,0 +1,177 @@ + tag that lets you have a gallery triggered on click of a thumbnail or something. Documentation at provided URL.", + "Author" : "Dan Fuhry", + "Version" : "0.1", + "Author URI" : "http://enanocms.org/" +} +**!*/ + +// 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();'); + +function lbgallery_process_tags(&$text) +{ + if ( !preg_match_all('#(.+?)#s', $text, $matches) ) + return true; + + lbgallery_add_headers(); + + foreach ( $matches[0] as $i => $match ) + { + $gallery = lbgallery_build_gallery($matches[2][$i], $matches[1][$i]); + $text = str_replace($match, $gallery, $text); + } +} + +function lbgallery_add_headers() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + $template->add_header(''); + $template->add_header(''); + $template->add_header(''); + $template->add_header(''); + $template->add_header(''); +} + +function lbgallery_build_gallery($gallerytag, $width) +{ + // parse out any text sections + $text = preg_replace('#^.*(.+?).*$#s', '$1', $gallerytag); + if ( $text == $gallerytag ) + $text = ''; + $gallerytag = preg_replace('#(.+?)#s', '', $gallerytag); + + $images = explode("\n", $gallerytag); + if ( empty($images) ) + { + return '
' . $lang->get('lboxgal_err_no_images') . '
'; + } + + $id = 'lbgal' . md5(microtime() . mt_rand()); + $inner = ''; + $width = intval($width); + if ( empty($width) ) + $width = 640; + + $imagelist = array(); + foreach ( $images as $line ) + { + $line = trim($line); + if ( empty($line) ) + continue; + + list($image) = explode('|', $line); + $image = sanitize_page_id(trim($image)); + if ( ($alt = strstr($line, '|')) ) + { + $alt = trim(substr($alt, 1)); + } + else + { + $alt = str_replace('_', ' ', dirtify_page_id($image)); + } + $imagelist[] = array($image, $alt); + $tag = ''; + if ( !isset($firstimageid) ) + { + $firstimagetag = $tag; + $firstimageid = $image; + $firstimagealt = $alt; + } + else + { + $inner .= $tag . '.'; + } + } + + if ( $text ) + { + $trigger = str_replace('', $firstimagetag, trim($text)); + } + else + { + list($image, $alt) = $imagelist[ array_rand($imagelist) ]; + $trigger = $firstimagetag . '' . htmlspecialchars($alt) . '' . ''; + } + + return "$trigger +
$inner
+
"; +} + +/**!language** + +The following text up to the closing comment tag is JSON language data. +It is not PHP code but your editor or IDE may highlight it as such. This +data is imported when the plugin is loaded for the first time; it provides +the strings displayed by this plugin's interface. + +You should copy and paste this block when you create your own plugins so +that these comments and the basic structure of the language data is +preserved. All language data is in the same format as the Enano core +language files in the /language/* directories. See the Enano Localization +Guide and Enano API Documentation for further information on the format of +language files. + +The exception in plugin language file format is that multiple languages +may be specified in the language block. This should be done by way of making +the top-level elements each a JSON language object, with elements named +according to the ISO-639-1 language they are representing. The path should be: + + root => language ID => categories array, ( strings object => category \ + objects => strings ) + +All text leading up to first curly brace is stripped by the parser; using +a code tag makes jEdit and other editors do automatic indentation and +syntax highlighting on the language data. The use of the code tag is not +necessary; it is only included as a tool for development. + + +{ + eng: { + categories: [ 'meta', 'lboxgal' ], + strings: { + meta: { + lboxgal: 'Lightbox gallery plugin' + }, + lboxgal: { + msg_docs: 'See lightboxgallery on enanocms.org for usage information.', + err_no_images: 'No images specified in gallery. %this.lboxgal_msg_docs%', + } + } + } +} + + +**!*/