author | Dan |
Mon, 03 Aug 2009 16:46:52 -0400 | |
changeset 4 | c2458c3b0365 |
parent 3 | b52509cf73af |
child 5 | dd7c762112b2 |
permissions | -rw-r--r-- |
0 | 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 |
|
2
e7eb457efdff
Changed hook to render_wikiformat_posttemplates to allow templating galleries
Dan
parents:
1
diff
changeset
|
14 |
$plugins->attachHook('render_wikiformat_posttemplates', 'lbgallery_process_tags($text);'); |
1 | 15 |
$plugins->attachHook('html_attribute_whitelist', '$whitelist["lightboxgallery"] = array("maxwidth"); $whitelist["trigger"] = array(); $whitelist["randomimage"] = array("/");'); |
0 | 16 |
|
17 |
function lbgallery_process_tags(&$text) |
|
18 |
{ |
|
2
e7eb457efdff
Changed hook to render_wikiformat_posttemplates to allow templating galleries
Dan
parents:
1
diff
changeset
|
19 |
// if there are no galleries in this blob, just get out here. also pulls all the matches we need. |
3 | 20 |
if ( !preg_match_all('#<lightboxgallery(?: maxwidth="?([0-9]+)"?)?>(.+?)</lightboxgallery>#s', $text, $matches) ) |
0 | 21 |
return true; |
22 |
||
23 |
lbgallery_add_headers(); |
|
24 |
||
25 |
foreach ( $matches[0] as $i => $match ) |
|
26 |
{ |
|
2
e7eb457efdff
Changed hook to render_wikiformat_posttemplates to allow templating galleries
Dan
parents:
1
diff
changeset
|
27 |
// actual parser loop is pretty simple. |
0 | 28 |
$gallery = lbgallery_build_gallery($matches[2][$i], $matches[1][$i]); |
29 |
$text = str_replace($match, $gallery, $text); |
|
30 |
} |
|
31 |
} |
|
32 |
||
33 |
function lbgallery_add_headers() |
|
34 |
{ |
|
35 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
36 |
||
4
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
37 |
if ( method_exists($template, 'preload_js') && method_exists($template, 'add_header_js') ) |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
38 |
{ |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
39 |
$template->preload_js(array('jquery', 'jquery-ui')); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
40 |
$template->add_header_js('<script type="text/javascript" src="' . scriptPath . '/plugins/lightboxgallery/jquery.lightbox-0.5.pack.js"></script>'); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
41 |
} |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
42 |
else |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
43 |
{ |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
44 |
$template->add_header('<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/jquery.js"></script>'); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
45 |
$template->add_header('<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/jquery-ui.js"></script>'); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
46 |
$template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/lightboxgallery/jquery.lightbox-0.5.pack.js"></script>'); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
47 |
} |
0 | 48 |
$template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/lightboxgallery/jquery.lightbox-0.5.css" />'); |
49 |
$template->add_header('<script type="text/javascript"> |
|
50 |
var loaded_components = loaded_components || {}; |
|
51 |
loaded_components["jquery.js"] = true; |
|
52 |
loaded_components["jquery-ui.js"] = true; |
|
53 |
if ( window.pref_disable_js_fx ) |
|
54 |
{ |
|
55 |
jQuery.fx.off = true; |
|
56 |
} |
|
57 |
function lbgallery_construct(selector) |
|
58 |
{ |
|
59 |
var settings = { |
|
60 |
// Configuration related to images |
|
61 |
imageLoading: \'' . cdnPath . '/images/loading-big.gif\', // (string) Path and the name of the loading icon |
|
62 |
imageBtnPrev: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-prev.gif\', // (string) Path and the name of the prev button image |
|
63 |
imageBtnNext: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-next.gif\', // (string) Path and the name of the next button image |
|
64 |
imageBtnClose: \'' . scriptPath . '/plugins/lightboxgallery/images/lightbox-btn-close.gif\', // (string) Path and the name of the close btn |
|
65 |
imageBlank: \'' . cdnPath . '/images/spacer.gif\', // (string) Path and the name of a blank image (one pixel) |
|
66 |
}; |
|
67 |
jQuery(selector).lightBox(settings); |
|
68 |
} |
|
69 |
</script>'); |
|
70 |
} |
|
71 |
||
2
e7eb457efdff
Changed hook to render_wikiformat_posttemplates to allow templating galleries
Dan
parents:
1
diff
changeset
|
72 |
// The actual function to build the HTML behind a gallery. |
e7eb457efdff
Changed hook to render_wikiformat_posttemplates to allow templating galleries
Dan
parents:
1
diff
changeset
|
73 |
|
0 | 74 |
function lbgallery_build_gallery($gallerytag, $width) |
75 |
{ |
|
76 |
// parse out any text sections |
|
77 |
$text = preg_replace('#^.*<trigger>(.+?)</trigger>.*$#s', '$1', $gallerytag); |
|
78 |
if ( $text == $gallerytag ) |
|
79 |
$text = ''; |
|
80 |
$gallerytag = preg_replace('#<trigger>(.+?)</trigger>#s', '', $gallerytag); |
|
81 |
||
82 |
$images = explode("\n", $gallerytag); |
|
83 |
if ( empty($images) ) |
|
84 |
{ |
|
85 |
return '<div class="error-box-mini">' . $lang->get('lboxgal_err_no_images') . '</div>'; |
|
86 |
} |
|
87 |
||
88 |
$id = 'lbgal' . md5(microtime() . mt_rand()); |
|
89 |
$inner = ''; |
|
90 |
$width = intval($width); |
|
91 |
if ( empty($width) ) |
|
92 |
$width = 640; |
|
93 |
||
94 |
$imagelist = array(); |
|
95 |
foreach ( $images as $line ) |
|
96 |
{ |
|
97 |
$line = trim($line); |
|
98 |
if ( empty($line) ) |
|
99 |
continue; |
|
100 |
||
101 |
list($image) = explode('|', $line); |
|
102 |
$image = sanitize_page_id(trim($image)); |
|
103 |
if ( ($alt = strstr($line, '|')) ) |
|
104 |
{ |
|
105 |
$alt = trim(substr($alt, 1)); |
|
106 |
} |
|
107 |
else |
|
108 |
{ |
|
109 |
$alt = str_replace('_', ' ', dirtify_page_id($image)); |
|
110 |
} |
|
111 |
$imagelist[] = array($image, $alt); |
|
4
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
112 |
$tag = '<a class="' . $id . '" href="' . makeUrlNS('Special', "DownloadFile/$image", "preview&width=$width&height=9999&fmt=jpg", true) . '" title="' . trim(htmlspecialchars(RenderMan::render($alt))) . '">'; |
0 | 113 |
if ( !isset($firstimageid) ) |
114 |
{ |
|
115 |
$firstimagetag = $tag; |
|
116 |
$firstimageid = $image; |
|
117 |
$firstimagealt = $alt; |
|
118 |
} |
|
119 |
else |
|
120 |
{ |
|
121 |
$inner .= $tag . '.</a>'; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
if ( $text ) |
|
126 |
{ |
|
1 | 127 |
$trigger = trim($text); |
0 | 128 |
} |
129 |
else |
|
130 |
{ |
|
1 | 131 |
$trigger = '<a><randomimage /></a>'; |
0 | 132 |
} |
133 |
||
1 | 134 |
$trigger = str_replace('<a>', $firstimagetag, $trigger); |
135 |
||
136 |
list($image, $alt) = $imagelist[ array_rand($imagelist) ]; |
|
137 |
$randomimage = '<img alt="' . htmlspecialchars($alt) . '" src="' . makeUrlNS('Special', "DownloadFile/$image", "preview", true) . '" />'; |
|
138 |
$trigger = str_replace(array('<randomimage>', '<randomimage/>', '<randomimage />'), $randomimage, $trigger); |
|
139 |
||
0 | 140 |
return "$trigger<nowiki> |
141 |
<div style=\"display: none;\">$inner</div> |
|
142 |
<script type=\"text/javascript\"> |
|
4
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
143 |
window.lbg_construct_$id = function() |
0 | 144 |
{ |
4
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
145 |
if ( window.jQuery && window.jQuery.fn.lightBox ) |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
146 |
{ |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
147 |
lbgallery_construct('a.$id'); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
148 |
} |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
149 |
else |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
150 |
{ |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
151 |
setTimeout(lbg_construct_$id, 200); |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
152 |
} |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
153 |
}; |
c2458c3b0365
Fixed some 1.1.7 Javascript setup code; set format of scaled images to JPEG (1.1.7+) to make operation faster
Dan
parents:
3
diff
changeset
|
154 |
addOnloadHook(window.lbg_construct_$id); |
0 | 155 |
</script></nowiki>"; |
156 |
} |
|
157 |
||
158 |
/**!language** |
|
159 |
||
160 |
The following text up to the closing comment tag is JSON language data. |
|
161 |
It is not PHP code but your editor or IDE may highlight it as such. This |
|
162 |
data is imported when the plugin is loaded for the first time; it provides |
|
163 |
the strings displayed by this plugin's interface. |
|
164 |
||
165 |
You should copy and paste this block when you create your own plugins so |
|
166 |
that these comments and the basic structure of the language data is |
|
167 |
preserved. All language data is in the same format as the Enano core |
|
168 |
language files in the /language/* directories. See the Enano Localization |
|
169 |
Guide and Enano API Documentation for further information on the format of |
|
170 |
language files. |
|
171 |
||
172 |
The exception in plugin language file format is that multiple languages |
|
173 |
may be specified in the language block. This should be done by way of making |
|
174 |
the top-level elements each a JSON language object, with elements named |
|
175 |
according to the ISO-639-1 language they are representing. The path should be: |
|
176 |
||
177 |
root => language ID => categories array, ( strings object => category \ |
|
178 |
objects => strings ) |
|
179 |
||
180 |
All text leading up to first curly brace is stripped by the parser; using |
|
181 |
a code tag makes jEdit and other editors do automatic indentation and |
|
182 |
syntax highlighting on the language data. The use of the code tag is not |
|
183 |
necessary; it is only included as a tool for development. |
|
184 |
||
185 |
<code> |
|
186 |
{ |
|
187 |
eng: { |
|
188 |
categories: [ 'meta', 'lboxgal' ], |
|
189 |
strings: { |
|
190 |
meta: { |
|
191 |
lboxgal: 'Lightbox gallery plugin' |
|
192 |
}, |
|
193 |
lboxgal: { |
|
194 |
msg_docs: 'See <a href="http://enanocms.org/plugin/lightboxgallery">lightboxgallery on enanocms.org</a> for usage information.', |
|
195 |
err_no_images: 'No images specified in gallery. %this.lboxgal_msg_docs%', |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
</code> |
|
201 |
||
202 |
**!*/ |