|
1 <?php |
|
2 /**!info** |
|
3 { |
|
4 "Plugin Name" : "Lightbox Gallery", |
|
5 "Plugin URI" : "http://enanocms.org/plugin/lightboxgallery", |
|
6 "Description" : "Adds a <lightboxgallery> tag that lets you have a gallery triggered on click of a thumbnail or something. Documentation at provided URL.", |
|
7 "Author" : "Dan Fuhry", |
|
8 "Version" : "0.1", |
|
9 "Author URI" : "http://enanocms.org/" |
|
10 } |
|
11 **!*/ |
|
12 |
|
13 // Hook into wikitext render flow |
|
14 $plugins->attachHook('render_wikiformat_pre', 'lbgallery_process_tags($text);'); |
|
15 $plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array();'); |
|
16 |
|
17 function lbgallery_process_tags(&$text) |
|
18 { |
|
19 if ( !preg_match_all('#<lightboxgallery(?: maxwidth="?([0-9]+)"?)>(.+?)</lightboxgallery>#s', $text, $matches) ) |
|
20 return true; |
|
21 |
|
22 lbgallery_add_headers(); |
|
23 |
|
24 foreach ( $matches[0] as $i => $match ) |
|
25 { |
|
26 $gallery = lbgallery_build_gallery($matches[2][$i], $matches[1][$i]); |
|
27 $text = str_replace($match, $gallery, $text); |
|
28 } |
|
29 } |
|
30 |
|
31 function lbgallery_add_headers() |
|
32 { |
|
33 global $db, $session, $paths, $template, $plugins; // Common objects |
|
34 |
|
35 $template->add_header('<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/jquery.js"></script>'); |
|
36 $template->add_header('<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/jquery-ui.js"></script>'); |
|
37 $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/lightboxgallery/jquery.lightbox-0.5.pack.js"></script>'); |
|
38 $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/lightboxgallery/jquery.lightbox-0.5.css" />'); |
|
39 $template->add_header('<script type="text/javascript"> |
|
40 var loaded_components = loaded_components || {}; |
|
41 loaded_components["jquery.js"] = true; |
|
42 loaded_components["jquery-ui.js"] = true; |
|
43 if ( window.pref_disable_js_fx ) |
|
44 { |
|
45 jQuery.fx.off = true; |
|
46 } |
|
47 function lbgallery_construct(selector) |
|
48 { |
|
49 var settings = { |
|
50 // Configuration related to images |
|
51 imageLoading: \'' . cdnPath . '/images/loading-big.gif\', // (string) Path and the name of the loading icon |
|
52 imageBtnPrev: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-prev.gif\', // (string) Path and the name of the prev button image |
|
53 imageBtnNext: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-next.gif\', // (string) Path and the name of the next button image |
|
54 imageBtnClose: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-close.gif\', // (string) Path and the name of the close btn |
|
55 imageBlank: \'' . cdnPath . '/images/spacer.gif\', // (string) Path and the name of a blank image (one pixel) |
|
56 }; |
|
57 jQuery(selector).lightBox(settings); |
|
58 } |
|
59 </script>'); |
|
60 } |
|
61 |
|
62 function lbgallery_build_gallery($gallerytag, $width) |
|
63 { |
|
64 // parse out any text sections |
|
65 $text = preg_replace('#^.*<trigger>(.+?)</trigger>.*$#s', '$1', $gallerytag); |
|
66 if ( $text == $gallerytag ) |
|
67 $text = ''; |
|
68 $gallerytag = preg_replace('#<trigger>(.+?)</trigger>#s', '', $gallerytag); |
|
69 |
|
70 $images = explode("\n", $gallerytag); |
|
71 if ( empty($images) ) |
|
72 { |
|
73 return '<div class="error-box-mini">' . $lang->get('lboxgal_err_no_images') . '</div>'; |
|
74 } |
|
75 |
|
76 $id = 'lbgal' . md5(microtime() . mt_rand()); |
|
77 $inner = ''; |
|
78 $width = intval($width); |
|
79 if ( empty($width) ) |
|
80 $width = 640; |
|
81 |
|
82 $imagelist = array(); |
|
83 foreach ( $images as $line ) |
|
84 { |
|
85 $line = trim($line); |
|
86 if ( empty($line) ) |
|
87 continue; |
|
88 |
|
89 list($image) = explode('|', $line); |
|
90 $image = sanitize_page_id(trim($image)); |
|
91 if ( ($alt = strstr($line, '|')) ) |
|
92 { |
|
93 $alt = trim(substr($alt, 1)); |
|
94 } |
|
95 else |
|
96 { |
|
97 $alt = str_replace('_', ' ', dirtify_page_id($image)); |
|
98 } |
|
99 $imagelist[] = array($image, $alt); |
|
100 $tag = '<a class="' . $id . '" href="' . makeUrlNS('Special', "DownloadFile/$image", "preview&width=$width&height=9999", true) . '" title="' . trim(htmlspecialchars(RenderMan::render($alt))) . '">'; |
|
101 if ( !isset($firstimageid) ) |
|
102 { |
|
103 $firstimagetag = $tag; |
|
104 $firstimageid = $image; |
|
105 $firstimagealt = $alt; |
|
106 } |
|
107 else |
|
108 { |
|
109 $inner .= $tag . '.</a>'; |
|
110 } |
|
111 } |
|
112 |
|
113 if ( $text ) |
|
114 { |
|
115 $trigger = str_replace('<a>', $firstimagetag, trim($text)); |
|
116 } |
|
117 else |
|
118 { |
|
119 list($image, $alt) = $imagelist[ array_rand($imagelist) ]; |
|
120 $trigger = $firstimagetag . '<img alt="' . htmlspecialchars($alt) . '" src="' . makeUrlNS('Special', "DownloadFile/$image", "preview", true) . '" />' . '</a>'; |
|
121 } |
|
122 |
|
123 return "$trigger<nowiki> |
|
124 <div style=\"display: none;\">$inner</div> |
|
125 <script type=\"text/javascript\"> |
|
126 addOnloadHook(function() |
|
127 { |
|
128 lbgallery_construct('a.$id'); |
|
129 }); |
|
130 </script></nowiki>"; |
|
131 } |
|
132 |
|
133 /**!language** |
|
134 |
|
135 The following text up to the closing comment tag is JSON language data. |
|
136 It is not PHP code but your editor or IDE may highlight it as such. This |
|
137 data is imported when the plugin is loaded for the first time; it provides |
|
138 the strings displayed by this plugin's interface. |
|
139 |
|
140 You should copy and paste this block when you create your own plugins so |
|
141 that these comments and the basic structure of the language data is |
|
142 preserved. All language data is in the same format as the Enano core |
|
143 language files in the /language/* directories. See the Enano Localization |
|
144 Guide and Enano API Documentation for further information on the format of |
|
145 language files. |
|
146 |
|
147 The exception in plugin language file format is that multiple languages |
|
148 may be specified in the language block. This should be done by way of making |
|
149 the top-level elements each a JSON language object, with elements named |
|
150 according to the ISO-639-1 language they are representing. The path should be: |
|
151 |
|
152 root => language ID => categories array, ( strings object => category \ |
|
153 objects => strings ) |
|
154 |
|
155 All text leading up to first curly brace is stripped by the parser; using |
|
156 a code tag makes jEdit and other editors do automatic indentation and |
|
157 syntax highlighting on the language data. The use of the code tag is not |
|
158 necessary; it is only included as a tool for development. |
|
159 |
|
160 <code> |
|
161 { |
|
162 eng: { |
|
163 categories: [ 'meta', 'lboxgal' ], |
|
164 strings: { |
|
165 meta: { |
|
166 lboxgal: 'Lightbox gallery plugin' |
|
167 }, |
|
168 lboxgal: { |
|
169 msg_docs: 'See <a href="http://enanocms.org/plugin/lightboxgallery">lightboxgallery on enanocms.org</a> for usage information.', |
|
170 err_no_images: 'No images specified in gallery. %this.lboxgal_msg_docs%', |
|
171 } |
|
172 } |
|
173 } |
|
174 } |
|
175 </code> |
|
176 |
|
177 **!*/ |