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