-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmoothGalleryClass.php
328 lines (258 loc) · 11.3 KB
/
SmoothGalleryClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
class SmoothGallery {
var $parser;
var $set;
var $argumentArray, $galleriesArray;
var $errors;
function hasErrors() {
if ( $this->errors == '' ) {
return false;
} else {
return true;
}
}
function getErrors() {
return $this->errors;
}
function checkForErrors() {
foreach ( $this->galleriesArray["galleries"] as $galleryArray ) {
// We are being harsh for gallery sets.
// If even one gallery is missing all images, we
// are going to return an error to the user.
if ( !isset( $galleryArray["images"] ) ) {
$error = wfMsg( "smoothgallery-error" );
if ( isset( $galleryArray["missing_images"] ) && isset( $galleryArray["invalid_images"] ) ) {
$error .= wfMsg( "smoothgallery-no-images", implode( ", ", $galleryArray["missing_images"] ), count( $galleryArray["missing_images"] ) + count( $galleryArray["invalid_images"] ) ) ); // FIXME: 3rd (last) parameter should have the number of good images added.
$error .= wfMsg( "smoothgallery-invalid-images", implode( ", ", $galleryArray["invalid_images"] ) );
} elseif ( isset( $galleryArray["invalid_images"] ) ) {
$error .= wfMsg( "smoothgallery-invalid-images", implode( ", ", $galleryArray["invalid_images"] ) );
} elseif ( isset( $galleryArray["missing_images"] ) ) {
$error .= wfMsg( "smoothgallery-no-images", implode( ", ", $galleryArray["missing_images"] ), count( $galleryArray["missing_images"] ) ) ); // FIXME: 3rd (last) parameter should have the number of good images added.
} else {
$error .= wfMsg( "smoothgallery-not-found" );
}
if ( $this->errors == '' ) {
$this->errors = $error;
} else {
$this->errors .= "<br />" . $error;
}
}
}
}
function setArguments( $argumentArray ) {
$this->argumentArray = $argumentArray;
}
function setGalleries( $galleriesArray ) {
$this->galleriesArray = $galleriesArray;
}
function setParser( $parser ) {
$this->parser = $parser;
}
function setSet( $calledAsSet ) {
$this->set = $calledAsSet;
}
function toHTML () {
$output = '';
$fallbackOutput = '';
if ( $this->set ) {
// Open the div, and initialize any needed variables
$output = '<div id="' . $this->galleriesArray["gallery_set_name"] . '" style="width: ' . $this->argumentArray["width"] . ';height: ' . $this->argumentArray["height"] . '; display: none;" >';
// iterate through galleries, call renderGallery on each, and
// collect the fallback output
$i = 1;
foreach ( $this->galleriesArray["galleries"] as $galleryArray ) {
$output .= $this->renderGallery( $galleryArray );
$fallbackOutput .= $this->renderFallback( $galleryArray );
$i++;
}
$output .= '</div>';
$output .= '<div id="' . $this->galleriesArray["gallery_set_name"] . '-fallback">' . $fallbackOutput . '</div>';
$output .= $this->renderJavascript( $this->galleriesArray["gallery_set_name"] );
} else {
$output = $this->renderGallery( $this->galleriesArray["galleries"][0] );
$output .= $this->renderFallback( $this->galleriesArray["galleries"][0] );
$output .= $this->renderJavascript( $this->galleriesArray["galleries"][0]["gallery_name"] );
}
# flags for use by smoothGalleryParserOutput
$this->parser->mOutput->mSmoothGalleryTag = true;
if ( $this->set ) {
$this->parser->mOutput->mSmoothGallerySetTag = true;
}
// Finished, let's send it out
return $output;
}
function renderGallery ( $galleryArray ) {
global $wgSmoothGalleryDelimiter;
global $wgSmoothGalleryThumbHeight, $wgSmoothGalleryThumbWidth;
// Open the outer div of the gallery
if ( $this->set ) {
$output = '<div id="' . $galleryArray["gallery_name"] . '" class="galleryElement">';
$output .= '<h2>' . $galleryArray["gallery_name"] . '<h2>';
} else {
$output = '<div id="' . $galleryArray["gallery_name"] . '" style="width: ' . $this->argumentArray["width"] . ';height: ' . $this->argumentArray["height"] . '; display:none;">';
}
// TODO iterate over the images and output each
foreach ( $galleryArray["images"] as $imageArray ) {
if ( isset( $imageArray["external"] ) && $imageArray["external"] ) {
$thumbsizes = 'height="' . $wgSmoothGalleryThumbHeight . '" width="' . $wgSmoothGalleryThumbWidth . '" ';
$fullsizes = 'height="' . $this->argumentArray["height"] . '" width="' . $this->argumentArray["width"] . '" ';
} else {
$thumbsizes = '';
$fullsizes = '';
}
// Add the html for the image
$output .= '<div class="imageElement">';
$output .= '<h3>' . $imageArray["heading"] . '</h3>';
$output .= '<p>' . $imageArray["description"] . '</p>';
$output .= '<a href="' . $imageArray["full_url"] . '" title="open image" class="open"></a>';
$output .= '<a href="' . $imageArray["view_url"] . '" title="open image" class="open"></a>';
$output .= '<img src="' . $imageArray["full_thumb_url"] . '" class="full" alt="' . $imageArray["description"] . '" ' . $fullsizes . '/>';
if ( $this->argumentArray["carousel"] ) {
$output .= '<img src="' . $imageArray["icon_thumb_url"] . '" class="thumbnail" alt="' . $imageArray["description"] . '" ' . $thumbsizes . '/>';
}
$output .= '</div>';
}
// Close the outer div of the gallery
$output .= '</div>';
return $output;
}
function renderFallback ( $galleryArray ) {
$output = '';
if ( !isset( $galleryArray["images"] ) ) {
return $output;
}
if ( $this->argumentArray["fallback"] == "image" ) {
if ( !isset( $galleryArray["images"][0] ) ) {
return '';
}
$output .= '<div id="' . $galleryArray['gallery_name'] . '-fallback" class="MediaWikiSGallerySingleImage" style="width: ' . $this->argumentArray["width"] . ';height: ' . $this->argumentArray["height"] . ';" alt="' . $galleryArray["images"][0]["description"] . '">';
$output .= '<img src="' . $galleryArray["images"][0]["full_thumb_url"] . '" class="full" alt="' . $galleryArray["images"][0]["description"] . '" />';
$output .= '</div>';
} elseif ( $this->argumentArray["fallback"] == "image-warn" ) {
if ( !isset( $galleryArray["images"][0] ) ) {
return '';
}
$output .= '<div id="' . $galleryArray['gallery_name'] . '-fallback" class="MediaWikiSGalleryWarning" style="width: ' . $this->argumentArray["width"] . ';height: ' . $this->argumentArray["height"] . ';" alt="' . $galleryArray["images"][0]["description"] . '">';
$output .= wfMsg( "smoothgallery-javascript-disabled" );
$output .= '<div class="MediaWikiSGallerySingleImage">';
$output .= '<img src="' . $galleryArray["images"][0]["full_thumb_url"] . '" class="full" alt="' . $galleryArray["images"][0]["description"] . '" />';
$output .= '</div></div>';
} else {
$output .= $this->renderPlainGallery ( $galleryArray );
}
return $output;
}
function renderPlainGallery ( $galleryArray ) {
if ( !isset( $galleryArray["images"] ) ) {
return '';
}
// Wrapper div for plain old gallery, to be shown per default, if JS is off.
$output = '<div id="' . $galleryArray["gallery_name"] . '-fallback">';
$plain_gallery = new ImageGallery();
$i = 0;
foreach ( $galleryArray["images"] as $image ) {
if ( isset( $image["external"] ) && $image["external"] ) {
continue;
}
$plain_gallery->add( $image["image_object"]->getTitle(), $image["description"] ); // TODO: use text
$i++;
}
// Return an empty div if there are no usable images in the gallery.
// This can happen if all images are external.
if ( $i == 0 ) {
return $output . '</div>';
}
$output .= $plain_gallery->toHTML();
// Close the wrapper div for the plain old gallery
$output .= '</div>';
return $output;
}
function renderJavascript ( $name ) {
// Output the javascript needed for the gallery with any
// options the user requested
$output = '<script type="text/javascript">';
$output .= 'document.getElementById("' . $name . '-fallback").style.display = "none";'; // hide plain gallery
$output .= 'document.getElementById("' . $name . '").style.display = "block";'; // show smooth gallery
$output .= 'function startGallery_' . $name . '() {';
if ( $this->set ) {
$output .= "var MediaWikiSGallerySet = new gallerySet($('" . $name . "'), {";
} else {
$output .= "var MediaWikiSGallery = new gallery($('" . $name . "'), {";
}
$output .= 'thumbWidth: 100, thumbHeight: 75'; // would be nice if we could change this to 120x120 to re-use thumbnails...
// Add user provided options
if ( $this->argumentArray["timed"] ) {
$output .= ', timed: true';
$output .= ', delay: ' . $this->argumentArray["delay"];
}
if ( !$this->argumentArray["carousel"] ) {
$output .= ', showCarousel: false';
}
if ( !$this->argumentArray["showarrows"] ) {
$output .= ', showArrows: false';
}
if ( !$this->argumentArray["showinfopane"] ) {
$output .= ', showInfopane: false';
}
if ( !$this->argumentArray["slideinfozoneslide"] ) {
$output .= ', slideInfoZoneSlide: false';
}
if ( $this->argumentArray["slideinfozoneopacity"] ) {
$output .= ', slideInfoZoneOpacity: ' . $this->argumentArray["slideinfozoneopacity"];
}
# $output .= ', useHistoryManager: true';
# $output .= ', preloader: true';
# $output .= ', preloaderImage: true';
# $output .= ', preloaderErrorImage: true';
# $output .= ', carouselPreloader: true';
# $output .= ", textPreloadingCarousel: '" . wfMsg("smoothgallery-loading") . "'";
$output .= '});';
# $output .= 'HistoryManager.start();';
$output .= '}';
$output .= "window.addEvent('domready', startGallery_$name);";
# $output .= 'addOnloadHook(startGallery_' . $name . ');';
$output .= '</script>';
return $output;
}
static function setGalleryHeaders( $outputPage ) {
global $wgSmoothGalleryExtensionPath;
$extensionpath = $wgSmoothGalleryExtensionPath;
// Add mootools (required by SmoothGallery)
// You can use the compressed js if you want, but I
// generally don't trust them unless I wrote them myself
$outputPage->addScript( '<script src="' . $extensionpath . '/scripts/mootools.uncompressed.js" type="text/javascript"></script>' );
// Add SmoothGallery javascript
$outputPage->addScript( '<script src="' . $extensionpath . '/scripts/jd.gallery.js" type="text/javascript"></script>' );
$outputPage->addScript( '<script src="' . $extensionpath . '/scripts/HistoryManager.js" type="text/javascript"></script>' );
// Add SmoothGallery css
$outputPage->addLink(
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => $extensionpath . '/css/jd.gallery.css'
)
);
# $outputPage->addScript( '<link rel="stylesheet" href="' . $extensionpath . '/css/jd.gallery.css" type="text/css" media="screen" charset="utf-8" />' );
$outputPage->addScript( '<style type="text/css">.jdGallery .slideInfoZone { overflow:auto ! important; }</style>' );
return true;
}
static function setGallerySetHeaders( $outputPage ) {
global $wgSmoothGalleryExtensionPath;
$extensionpath = $wgSmoothGalleryExtensionPath;
$outputPage->addScript( '<script src="' . $extensionpath . '/scripts/jd.gallery.set.js" type="text/javascript"></script>' );
return true;
}
static function debug( $debugText, $debugArr = null ) {
global $wgSmoothGalleryDebug;
if ( isset( $debugArr ) ) {
if ( $wgSmoothGalleryDebug > 0 ) {
$text = $debugText . " " . implode( "::", $debugArr );
wfDebugLog( 'sgallery', $text, false );
}
} else {
if ( $wgSmoothGalleryDebug > 0 ) {
wfDebugLog( 'sgallery', $debugText, false );
}
}
}
}