NextGEN Gallery – WordPress Gallery Plugin - Version 1.3.4

Version Description

Download this release

Release Info

Developer alexrabe
Plugin Icon 128x128 NextGEN Gallery – WordPress Gallery Plugin
Version 1.3.4
Comparing to
See all releases

Code changes from version 1.3.3 to 1.3.4

Files changed (5) hide show
  1. admin/ajax.php +2 -2
  2. changelog.txt +8 -1
  3. lib/core.php +0 -1
  4. nggallery.php +4 -4
  5. nggfunctions.php +954 -951
admin/ajax.php CHANGED
@@ -18,8 +18,8 @@ function ngg_ajax_operation() {
18
  if ( !is_user_logged_in() )
19
  die('-1');
20
 
21
- // check for correct NextGEN capability
22
- if ( !current_user_can('NextGEN Upload images') || !current_user_can('NextGEN Manage gallery') )
23
  die('-1');
24
 
25
  // include the ngg function
18
  if ( !is_user_logged_in() )
19
  die('-1');
20
 
21
+ // check for correct NextGEN capability. TODO : Can we check here already for "can_manage_this_gallery($gallery->author)" ?
22
+ if ( !current_user_can('NextGEN Upload images') && !current_user_can('NextGEN Manage gallery') )
23
  die('-1');
24
 
25
  // include the ngg function
changelog.txt CHANGED
@@ -1,7 +1,14 @@
1
  NextGEN Gallery
2
  by Alex Rabe & NextGEN DEV Team
3
 
4
- v1.3.3 - 11.06.2009
 
 
 
 
 
 
 
5
  - Changed : Load Thickbox images via wp_footer()
6
  - Bugfix : Widget setting couldnot be saved
7
 
1
  NextGEN Gallery
2
  by Alex Rabe & NextGEN DEV Team
3
 
4
+ V1.3.4 - 07.06.2009
5
+ - Added : New filter ngg_gallery_object and ngg_image_object
6
+ - Bugfix : Fix double rendering of a gallery if two album shortcodes are used
7
+ - Bugfix : Fix for custom field ngg_gal_sort
8
+ - Bugfix : Changed capapbility check for upload
9
+ - Bugfix : Check for correct version OR memory limit
10
+
11
+ V1.3.3 - 11.06.2009
12
  - Changed : Load Thickbox images via wp_footer()
13
  - Bugfix : Widget setting couldnot be saved
14
 
lib/core.php CHANGED
@@ -231,7 +231,6 @@ class nggGallery {
231
 
232
  'int' => array(
233
  'ngg_gal_Images' => 'galImages',
234
- 'ngg_gal_Sort' => 'galSort',
235
  'ngg_gal_Columns' => 'galColumns',
236
  'ngg_paged_Galleries' => 'galPagedGalleries',
237
  'ngg_ir_Width' => 'irWidth',
231
 
232
  'int' => array(
233
  'ngg_gal_Images' => 'galImages',
 
234
  'ngg_gal_Columns' => 'galColumns',
235
  'ngg_paged_Galleries' => 'galPagedGalleries',
236
  'ngg_ir_Width' => 'irWidth',
nggallery.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: NextGEN Gallery
4
  Plugin URI: http://alexrabe.boelinger.com/?page_id=80
5
  Description: A NextGENeration Photo gallery for the Web 2.0.
6
  Author: Alex Rabe
7
- Version: 1.3.3
8
 
9
  Author URI: http://alexrabe.boelinger.com/
10
 
@@ -44,7 +44,7 @@ if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You
44
  if (!class_exists('nggLoader')) {
45
  class nggLoader {
46
 
47
- var $version = '1.3.3';
48
  var $dbversion = '1.3.1';
49
  var $minium_WP = '2.7';
50
  var $minium_WPMU = '2.7';
@@ -59,7 +59,7 @@ class nggLoader {
59
  $this->load_textdomain();
60
 
61
  // Stop the plugin if we missed the requirements
62
- if ( ( !$this->required_version() ) && ( !$this->check_memory_limit() ) )
63
  return;
64
 
65
  // Get some constants first
@@ -229,7 +229,7 @@ class nggLoader {
229
  require_once (dirname (__FILE__) . '/lib/core.php'); // 94.840
230
  require_once (dirname (__FILE__) . '/lib/ngg-db.php'); // 132.400
231
  require_once (dirname (__FILE__) . '/lib/image.php'); // 59.424
232
- require_once (dirname (__FILE__) . '/widgets/widgets.php'); // 298.792
233
 
234
  // We didn't need all stuff during a AJAX operation
235
  if ( defined('DOING_AJAX') )
4
  Plugin URI: http://alexrabe.boelinger.com/?page_id=80
5
  Description: A NextGENeration Photo gallery for the Web 2.0.
6
  Author: Alex Rabe
7
+ Version: 1.3.4
8
 
9
  Author URI: http://alexrabe.boelinger.com/
10
 
44
  if (!class_exists('nggLoader')) {
45
  class nggLoader {
46
 
47
+ var $version = '1.3.4';
48
  var $dbversion = '1.3.1';
49
  var $minium_WP = '2.7';
50
  var $minium_WPMU = '2.7';
59
  $this->load_textdomain();
60
 
61
  // Stop the plugin if we missed the requirements
62
+ if ( ( !$this->required_version() ) || ( !$this->check_memory_limit() ) )
63
  return;
64
 
65
  // Get some constants first
229
  require_once (dirname (__FILE__) . '/lib/core.php'); // 94.840
230
  require_once (dirname (__FILE__) . '/lib/ngg-db.php'); // 132.400
231
  require_once (dirname (__FILE__) . '/lib/image.php'); // 59.424
232
+ require_once (dirname (__FILE__) . '/widgets/widgets.php'); // 298.792
233
 
234
  // We didn't need all stuff during a AJAX operation
235
  if ( defined('DOING_AJAX') )
nggfunctions.php CHANGED
@@ -1,951 +1,954 @@
1
- <?php
2
-
3
- if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
4
-
5
- /**
6
- * Return a script for the Imagerotator flash slideshow. Can be used in any tmeplate with <?php echo nggShowSlideshow($galleryID, $width, $height) ?>
7
- * Require the script swfobject.js in the header or footer
8
- *
9
- * @access public
10
- * @param integer $galleryID ID of the gallery
11
- * @param integer $irWidth Width of the flash container
12
- * @param integer $irHeight Height of the flash container
13
- * @return the content
14
- */
15
- function nggShowSlideshow($galleryID, $width, $height) {
16
-
17
- require_once (dirname (__FILE__).'/lib/swfobject.php');
18
-
19
- $ngg_options = nggGallery::get_option('ngg_options');
20
-
21
- // remove media file from RSS feed
22
- if ( is_feed() ) {
23
- $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']';
24
- return $out;
25
- }
26
-
27
- // If the Imagerotator didn't exist, skip the output
28
- if ( NGGALLERY_IREXIST == false )
29
- return;
30
-
31
- if (empty($width) ) $width = (int) $ngg_options['irWidth'];
32
- if (empty($height)) $height = (int) $ngg_options['irHeight'];
33
-
34
- // init the flash output
35
- $swfobject = new swfobject( $ngg_options['irURL'] , 'so' . $galleryID, $width, $height, '7.0.0', 'false');
36
-
37
- $swfobject->message = '<p>'. __('The <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> and <a href="http://www.mozilla.com/firefox/">a browser with Javascript support</a> are needed..', 'nggallery').'</p>';
38
- $swfobject->add_params('wmode', 'opaque');
39
- $swfobject->add_params('allowfullscreen', 'true');
40
- $swfobject->add_params('bgcolor', $ngg_options['irScreencolor'], '000000', 'string', '#');
41
- $swfobject->add_attributes('styleclass', 'slideshow');
42
- $swfobject->add_attributes('name', 'so' . $galleryID);
43
-
44
- // adding the flash parameter
45
- $swfobject->add_flashvars( 'file', NGGALLERY_URLPATH.'xml/imagerotator.php?gid=' . $galleryID );
46
- $swfobject->add_flashvars( 'shuffle', $ngg_options['irShuffle'], 'true', 'bool');
47
- $swfobject->add_flashvars( 'linkfromdisplay', $ngg_options['irLinkfromdisplay'], 'false', 'bool');
48
- $swfobject->add_flashvars( 'shownavigation', $ngg_options['irShownavigation'], 'true', 'bool');
49
- $swfobject->add_flashvars( 'showicons', $ngg_options['irShowicons'], 'true', 'bool');
50
- $swfobject->add_flashvars( 'kenburns', $ngg_options['irKenburns'], 'false', 'bool');
51
- $swfobject->add_flashvars( 'overstretch', $ngg_options['irOverstretch'], 'false', 'string');
52
- $swfobject->add_flashvars( 'rotatetime', $ngg_options['irRotatetime'], 5, 'int');
53
- $swfobject->add_flashvars( 'transition', $ngg_options['irTransition'], 'random', 'string');
54
- $swfobject->add_flashvars( 'backcolor', $ngg_options['irBackcolor'], 'FFFFFF', 'string', '0x');
55
- $swfobject->add_flashvars( 'frontcolor', $ngg_options['irFrontcolor'], '000000', 'string', '0x');
56
- $swfobject->add_flashvars( 'lightcolor', $ngg_options['irLightcolor'], '000000', 'string', '0x');
57
- $swfobject->add_flashvars( 'screencolor', $ngg_options['irScreencolor'], '000000', 'string', '0x');
58
- if ($ngg_options['irWatermark'])
59
- $swfobject->add_flashvars( 'logo', $ngg_options['wmPath'], '', 'string');
60
- $swfobject->add_flashvars( 'audio', $ngg_options['irAudio'], '', 'string');
61
- $swfobject->add_flashvars( 'width', $width, '260');
62
- $swfobject->add_flashvars( 'height', $height, '320');
63
- // create the output
64
- $out = '<div class="slideshow">' . $swfobject->output() . '</div>';
65
- // add now the script code
66
- $out .= "\n".'<script type="text/javascript" defer="defer">';
67
- if ($ngg_options['irXHTMLvalid']) $out .= "\n".'<!--';
68
- if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//<![CDATA[';
69
- $out .= $swfobject->javascript();
70
- if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//]]>';
71
- if ($ngg_options['irXHTMLvalid']) $out .= "\n".'-->';
72
- $out .= "\n".'</script>';
73
-
74
- $out = apply_filters('ngg_show_slideshow_content', $out);
75
-
76
- return $out;
77
- }
78
-
79
- /**
80
- * nggShowGallery() - return a gallery
81
- *
82
- * @access public
83
- * @param int $galleryID
84
- * @param string $template (optional) name for a template file, look for gallery-$template
85
- * @return the content
86
- */
87
- function nggShowGallery( $galleryID, $template = '' ) {
88
-
89
- global $nggRewrite;
90
-
91
- $ngg_options = nggGallery::get_option('ngg_options');
92
-
93
- //Set sort order value, if not used (upgrade issue)
94
- $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
95
- $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
96
-
97
- // get gallery values
98
- $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
99
-
100
- if ( !$picturelist->gid )
101
- __('[Gallery not found]','nggallery');
102
- else
103
- $galleryID = (int) $picturelist->gid;
104
-
105
- // $_GET from wp_query
106
- $show = get_query_var('show');
107
- $pid = get_query_var('pid');
108
- $pageid = get_query_var('pageid');
109
-
110
- // set $show if slideshow first
111
- if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) {
112
- if ( is_home() )
113
- $pageid = get_the_ID();
114
-
115
- $show = 'slide';
116
- }
117
-
118
- // go on only on this page
119
- if ( !is_home() || $pageid == get_the_ID() ) {
120
-
121
- // 1st look for ImageBrowser link
122
- if ( !empty($pid) && $ngg_options['galImgBrowser'] ) {
123
- $out = nggShowImageBrowser( $galleryID, $mode );
124
- return $out;
125
- }
126
-
127
- // 2nd look for slideshow
128
- if ( $show == 'slide' ) {
129
- $args['show'] = "gallery";
130
- $out = '<div class="ngg-galleryoverview">';
131
- $out .= '<div class="slideshowlink"><a class="slideshowlink" href="' . $nggRewrite->get_permalink($args) . '">'.nggGallery::i18n($ngg_options['galTextGallery']).'</a></div>';
132
- $out .= nggShowSlideshow($galleryID, $ngg_options['irWidth'], $ngg_options['irHeight']);
133
- $out .= '</div>'."\n";
134
- $out .= '<div class="ngg-clear"></div>'."\n";
135
- return $out;
136
- }
137
- }
138
-
139
- // get all picture with this galleryid
140
- if ( is_array($picturelist) )
141
- $out = nggCreateGallery($picturelist, $galleryID, $template);
142
-
143
- $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID));
144
- return $out;
145
- }
146
-
147
- /**
148
- * Build a gallery output
149
- *
150
- * @access internal
151
- * @param array $picturelist
152
- * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link
153
- * @param string $template (optional) name for a template file, look for gallery-$template
154
- * @return the content
155
- */
156
- function nggCreateGallery($picturelist, $galleryID = false, $template = '') {
157
- global $nggRewrite;
158
-
159
- $ngg_options = nggGallery::get_option('ngg_options');
160
-
161
- // $_GET from wp_query
162
- $nggpage = get_query_var('nggpage');
163
- $pageid = get_query_var('pageid');
164
-
165
- // we need to know the current page id
166
- $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
167
-
168
- if ( !is_array($picturelist) )
169
- $picturelist = array($picturelist);
170
-
171
- // Populate galleries values from the first image
172
- $first_image = current($picturelist);
173
- $gallery = new stdclass;
174
- $gallery->ID = (int) $galleryID;
175
- $gallery->show_slideshow = false;
176
- $gallery->name = stripslashes ( $first_image->name );
177
- $gallery->title = stripslashes( $first_image->title );
178
- $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc));
179
- $gallery->pageid = $first_image->pageid;
180
- $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page;
181
- reset($picturelist);
182
-
183
- $maxElement = $ngg_options['galImages'];
184
- $thumbwidth = $ngg_options['thumbwidth'];
185
- $thumbheight = $ngg_options['thumbheight'];
186
-
187
- // fixed width if needed
188
- $gallery->columns = intval($ngg_options['galColumns']);
189
- $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:'. floor(100/$gallery->columns) .'%;"' : '';
190
-
191
- // set thumb size
192
- $thumbsize = '';
193
- if ($ngg_options['thumbfix']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbheight.'"';
194
- if ($ngg_options['thumbcrop']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbwidth.'"';
195
-
196
- // show slideshow link
197
- if ($galleryID) {
198
- if (($ngg_options['galShowSlide']) AND (NGGALLERY_IREXIST)) {
199
- $gallery->show_slideshow = true;
200
- $gallery->slideshow_link = $nggRewrite->get_permalink(array ('show' => "slide"));
201
- $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']);
202
- }
203
-
204
- if ($ngg_options['usePicLens']) {
205
- $gallery->show_piclens = true;
206
- $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});";
207
- }
208
- }
209
-
210
- // check for page navigation
211
- if ($maxElement > 0) {
212
- if ( !is_home() || $pageid == $current_page ) {
213
- $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
214
- }
215
- else $page = 1;
216
-
217
- $start = $offset = ( $page - 1 ) * $maxElement;
218
-
219
- $total = count($picturelist);
220
-
221
- // remove the element if we didn't start at the beginning
222
- if ($start > 0 ) array_splice($picturelist, 0, $start);
223
-
224
- // return the list of images we need
225
- array_splice($picturelist, $maxElement);
226
-
227
- $navigation = nggGallery::create_navigation($page, $total, $maxElement);
228
- } else {
229
- $navigation = '<div class="ngg-clear">&nbsp;</div>';
230
- }
231
-
232
- foreach ($picturelist as $key => $picture) {
233
- // choose link between imagebrowser or effect
234
- $link = ($ngg_options['galImgBrowser']) ? $nggRewrite->get_permalink( array('pid'=>$picture->pid) ) : $picture->imageURL;
235
-
236
- // get the effect code
237
- if ($galleryID)
238
- $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode($picturelist[0]->name);
239
- else
240
- $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title());
241
-
242
- // add a filter for the link
243
- $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture);
244
- $picturelist[$key]->thumbnailURL = $picture->thumbURL;
245
- $picturelist[$key]->size = $thumbsize;
246
- $picturelist[$key]->thumbcode = $thumbcode;
247
- $picturelist[$key]->caption = ( empty($picture->description) ) ? '&nbsp;' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description)) );
248
- $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description)) );
249
- $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext)) );
250
- // filter to add custom content for the output
251
- $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid);
252
- }
253
-
254
- // look for gallery-$template.php or pure gallery.php
255
- $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;
256
-
257
- // create the output
258
- $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation) );
259
-
260
- // apply a filter after the output
261
- $out = apply_filters('ngg_gallery_output', $out, $picturelist);
262
-
263
- return $out;
264
- }
265
-
266
- /**
267
- * nggShowAlbum() - return a album based on the id
268
- *
269
- * @access public
270
- * @param int | string $albumID
271
- * @param string (optional) $template
272
- * @return the content
273
- */
274
- function nggShowAlbum($albumID, $template = 'extend') {
275
-
276
- // $_GET from wp_query
277
- $gallery = get_query_var('gallery');
278
- $album = get_query_var('album');
279
-
280
- // in the case somebody uses the '0', it should be 'all' to show all galleries
281
- $albumID = ($albumID == 0) ? 'all' : $albumID;
282
-
283
- // first look for gallery variable
284
- if (!empty( $gallery )) {
285
-
286
- // subalbum support only one instance, you cam't use more of them in one post
287
- if ( isset($GLOBALS['subalbum']) )
288
- return;
289
-
290
- if ( ($albumID != $album) && ($albumID != 'all') )
291
- $GLOBALS['subalbum'] = true;
292
-
293
- // if gallery is is submit , then show the gallery instead
294
- $out = nggShowGallery( intval($gallery) );
295
- return $out;
296
- }
297
-
298
- if ( (empty( $gallery )) && (isset($GLOBALS['subalbum'])) )
299
- return;
300
-
301
- //redirect to subalbum only one time
302
- if (!empty( $album )) {
303
- $GLOBALS['subalbum'] = true;
304
- $albumID = $album;
305
- }
306
-
307
- // lookup in the database
308
- $album = nggdb::find_album( $albumID );
309
-
310
- // still no success ? , die !
311
- if( !$album )
312
- return __('[Album not found]','nggallery');
313
-
314
- $mode = ltrim($mode, ',');
315
-
316
- if ( is_array($album->gallery_ids) )
317
- $out = nggCreateAlbum( $album->gallery_ids, $template, $album );
318
-
319
- $out = apply_filters( 'ngg_show_album_content', $out, $album->id );
320
-
321
- return $out;
322
- }
323
-
324
- /**
325
- * nggCreateAlbum()
326
- *
327
- * @access internal
328
- * @param array $galleriesID
329
- * @param string (optional) $template name for a template file, look for album-$template
330
- * @param object (optional) $album result from the db
331
- * @return the content
332
- */
333
- function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) {
334
- // create a gallery overview div
335
-
336
- global $wpdb, $nggRewrite, $nggdb;
337
-
338
- // $_GET from wp_query
339
- $nggpage = get_query_var('nggpage');
340
-
341
- $ngg_options = nggGallery::get_option('ngg_options');
342
-
343
- //this option can currently only set via the custom fields
344
- $maxElement = (int) $ngg_options['galPagedGalleries'];
345
-
346
- $sortorder = $galleriesID;
347
- $galleries = array();
348
-
349
- // get the galleries information
350
- foreach ($galleriesID as $i => $value)
351
- $galleriesID[$i] = addslashes($value);
352
-
353
- $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
354
-
355
- //TODO: Check this, problem exist when previewpic = 0
356
- //$galleries = $wpdb->get_results('SELECT t.*, tt.* FROM '.$wpdb->nggallery.' AS t INNER JOIN '.$wpdb->nggpictures.' AS tt ON t.previewpic = tt.pid WHERE t.gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
357
-
358
- // get the counter values
359
- $picturesCounter = $wpdb->get_results('SELECT galleryid, COUNT(*) as counter FROM '.$wpdb->nggpictures.' WHERE galleryid IN (\''.implode('\',\'', $galleriesID).'\') AND exclude != 1 GROUP BY galleryid', OBJECT_K);
360
- if ( is_array($picturesCounter) ) {
361
- foreach ($picturesCounter as $key => $value)
362
- $unsort_galleries[$key]->counter = $value->counter;
363
- }
364
-
365
- // get the id's of the preview images
366
- $imagesID = array();
367
- if ( is_array($unsort_galleries) ) {
368
- foreach ($unsort_galleries as $gallery_row)
369
- $imagesID[] = $gallery_row->previewpic;
370
- }
371
- $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);
372
-
373
- // re-order them and populate some
374
- foreach ($sortorder as $key) {
375
-
376
- //if we have a prefix 'a' then it's a subalbum, instead a gallery
377
- if (substr( $key, 0, 1) == 'a') {
378
- // get the album content
379
- if ( !$subalbum = $nggdb->find_album(substr( $key, 1)) )
380
- continue;
381
-
382
- //populate the sub album values
383
- $galleries[$key]->counter = 0;
384
- if ($subalbum->previewpic > 0)
385
- $image = $nggdb->find_image( $subalbum->previewpic );
386
- $galleries[$key]->previewpic = $subalbum->previewpic;
387
- $galleries[$key]->previewurl = ($image->thumbURL) ? $image->thumbURL : '';
388
- $galleries[$key]->previewname = $subalbum->name;
389
-
390
- //link to the subalbum
391
- $args['album'] = $subalbum->id;
392
- $args['gallery'] = false;
393
- $args['nggpage'] = false;
394
- $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
395
- $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) );
396
- $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($subalbum->name) );
397
-
398
- continue;
399
- }
400
-
401
- // Add the counter value if avaible
402
- $galleries[$key] = $unsort_galleries[$key];
403
-
404
- // add the file name and the link
405
- if ($galleries[$key]->previewpic != 0) {
406
- $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
407
- $galleries[$key]->previewurl = get_option ('siteurl').'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
408
- } else {
409
- $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
410
- $galleries[$key]->previewpic = $first_image->pid;
411
- $galleries[$key]->previewname = $first_image->filename;
412
- $galleries[$key]->previewurl = get_option ('siteurl') . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
413
- }
414
-
415
- // choose between variable and page link
416
- if ($ngg_options['galNoPages']) {
417
- $args['album'] = $album->id;
418
- $args['gallery'] = $key;
419
- $args['nggpage'] = false;
420
- $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
421
-
422
- } else {
423
- $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
424
- }
425
-
426
- // description can contain HTML tags
427
- $galleries[$key]->galdesc = html_entity_decode ( stripslashes($galleries[$key]->galdesc) ) ;
428
-
429
- // i18n
430
- $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($galleries[$key]->title) ) ;
431
- }
432
-
433
- // check for page navigation
434
- if ($maxElement > 0) {
435
- if ( !is_home() || $pageid == get_the_ID() ) {
436
- $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
437
- }
438
- else $page = 1;
439
-
440
- $start = $offset = ( $page - 1 ) * $maxElement;
441
-
442
- $total = count($galleries);
443
-
444
- // remove the element if we didn't start at the beginning
445
- if ($start > 0 ) array_splice($galleries, 0, $start);
446
-
447
- // return the list of images we need
448
- array_splice($galleries, $maxElement);
449
-
450
- $navigation = nggGallery::create_navigation($page, $total, $maxElement);
451
- } else {
452
- $navigation = '<div class="ngg-clear">&nbsp;</div>';
453
- }
454
-
455
- // if sombody didn't enter any template , take the extend version
456
- $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;
457
-
458
- // create the output
459
- $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );
460
-
461
- return $out;
462
-
463
- }
464
-
465
- /**
466
- * nggShowImageBrowser()
467
- *
468
- * @access public
469
- * @param int|string $galleryID or gallery name
470
- * @param string $template (optional) name for a template file, look for imagebrowser-$template
471
- * @return the content
472
- */
473
- function nggShowImageBrowser($galleryID, $template = '') {
474
-
475
- global $wpdb;
476
-
477
- $ngg_options = nggGallery::get_option('ngg_options');
478
-
479
- //Set sort order value, if not used (upgrade issue)
480
- $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
481
- $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
482
-
483
- // get the pictures
484
- $picturelist = nggdb::get_ids_from_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
485
-
486
- if ( is_array($picturelist) )
487
- $out = nggCreateImageBrowser($picturelist, $template);
488
- else
489
- $out = __('[Gallery not found]','nggallery');
490
-
491
- $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);
492
-
493
- return $out;
494
-
495
- }
496
-
497
- /**
498
- * nggCreateImageBrowser()
499
- *
500
- * @access internal
501
- * @param array $picarray with pid
502
- * @param string $template (optional) name for a template file, look for imagebrowser-$template
503
- * @return the content
504
- */
505
- function nggCreateImageBrowser($picarray, $template = '') {
506
-
507
- global $nggRewrite;
508
-
509
- require_once( dirname (__FILE__) . '/lib/meta.php' );
510
-
511
- // $_GET from wp_query
512
- $pid = get_query_var('pid');
513
-
514
- // we need to know the current page id
515
- $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
516
-
517
- if ( !is_array($picarray) )
518
- $picarray = array($picarray);
519
-
520
- $total = count($picarray);
521
-
522
- // look for gallery variable
523
- if ( !empty( $pid )) {
524
- $act_pid = (int) $pid;
525
- } else {
526
- reset($picarray);
527
- $act_pid = current($picarray);
528
- }
529
-
530
- // get ids for back/next
531
- $key = array_search($act_pid,$picarray);
532
- if (!$key) {
533
- $act_pid = reset($picarray);
534
- $key = key($picarray);
535
- }
536
- $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
537
- $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;
538
-
539
- // get the picture data
540
- $picture = nggdb::find_image($act_pid);
541
-
542
- // if we didn't get some data, exit now
543
- if ($picture == null)
544
- return;
545
-
546
- // add more variables for render output
547
- $picture->href_link = $picture->get_href_link();
548
- $picture->previous_image_link = $nggRewrite->get_permalink(array ('pid' => $back_pid));
549
- $picture->previous_pid = $back_pid;
550
- $picture->next_image_link = $nggRewrite->get_permalink(array ('pid' => $next_pid));
551
- $picture->next_pid = $next_pid;
552
- $picture->number = $key + 1;
553
- $picture->total = $total;
554
- $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
555
- $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
556
- $picture->description = html_entity_decode( stripslashes($picture->description) );
557
- $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;
558
-
559
- // filter to add custom content for the output
560
- $picture = apply_filters('ngg_image_object', $picture, $act_pid);
561
-
562
- // let's get the meta data
563
- $meta = new nggMeta($picture->imagePath);
564
- $exif = $meta->get_EXIF();
565
- $iptc = $meta->get_IPTC();
566
- $xmp = $meta->get_XMP();
567
-
568
- // look for imagebrowser-$template.php or pure imagebrowser.php
569
- $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;
570
-
571
- // create the output
572
- $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
573
-
574
- return $out;
575
-
576
- }
577
-
578
- /**
579
- * nggSinglePicture() - show a single picture based on the id
580
- *
581
- * @access public
582
- * @param int $imageID, db-ID of the image
583
- * @param int (optional) $width, width of the image
584
- * @param int (optional) $height, height of the image
585
- * @param string $mode (optional) could be none, watermark, web20
586
- * @param string $float (optional) could be none, left, right
587
- * @param string $template (optional) name for a template file, look for singlepic-$template
588
- * @param string $caption (optional) additional caption text
589
- * @return the content
590
- */
591
- function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '') {
592
- global $post;
593
-
594
- $ngg_options = nggGallery::get_option('ngg_options');
595
-
596
- // get picturedata
597
- $picture = nggdb::find_image($imageID);
598
-
599
- // if we didn't get some data, exit now
600
- if ($picture == null)
601
- return __('[SinglePic not found]','nggallery');
602
-
603
- // add float to img
604
- switch ($float) {
605
-
606
- case 'left':
607
- $float =' ngg-left';
608
- break;
609
-
610
- case 'right':
611
- $float =' ngg-right';
612
- break;
613
-
614
- case 'center':
615
- $float =' ngg-center';
616
- break;
617
-
618
- default:
619
- $float ='';
620
- break;
621
- }
622
-
623
- // clean mode if needed
624
- $mode = ( eregi('web20|watermark', $mode) ) ? $mode : '';
625
-
626
- //let's initiate the url
627
- $picture->thumbnailURL = false;
628
-
629
- // check fo cached picture
630
- if ( ($ngg_options['imgCacheSinglePic']) && ($post->post_status == 'publish') )
631
- $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );
632
-
633
- // if we didn't use a cached image then we take the on-the-fly mode
634
- if (!$picture->thumbnailURL)
635
- $picture->thumbnailURL = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
636
-
637
- // add more variables for render output
638
- $picture->href_link = $picture->get_href_link();
639
- $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
640
- $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
641
- $picture->description = html_entity_decode( stripslashes($picture->description) );
642
- $picture->classname = 'ngg-singlepic'. $float;
643
- $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
644
- $picture->height = (int) $height;
645
- $picture->width = (int) $width;
646
- $picture->caption = $caption;
647
-
648
- // filter to add custom content for the output
649
- $picture = apply_filters('ngg_image_object', $picture, $imageID);
650
-
651
- // let's get the meta data
652
- $meta = new nggMeta($picture->imagePath);
653
- $exif = $meta->get_EXIF();
654
- $iptc = $meta->get_IPTC();
655
- $xmp = $meta->get_XMP();
656
-
657
- // look for singlepic-$template.php or pure singlepic.php
658
- $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;
659
-
660
- // create the output
661
- $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
662
-
663
- $out = apply_filters('ngg_show_singlepic_content', $out, $picture );
664
-
665
- return $out;
666
- }
667
-
668
- /**
669
- * nggShowGalleryTags() - create a gallery based on the tags
670
- *
671
- * @access public
672
- * @param string $taglist list of tags as csv
673
- * @return the content
674
- */
675
- function nggShowGalleryTags($taglist) {
676
-
677
- // $_GET from wp_query
678
- $pid = get_query_var('pid');
679
- $pageid = get_query_var('pageid');
680
-
681
- // get now the related images
682
- $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');
683
-
684
- // look for ImageBrowser if we have a $_GET('pid')
685
- if ( $pageid == get_the_ID() || !is_home() )
686
- if (!empty( $pid )) {
687
- foreach ($picturelist as $picture) {
688
- $picarray[] = $picture->pid;
689
- }
690
- $out = nggCreateImageBrowser($picarray);
691
- return $out;
692
- }
693
-
694
- // go on if not empty
695
- if ( empty($picturelist) )
696
- return;
697
-
698
- // show gallery
699
- if ( is_array($picturelist) )
700
- $out = nggCreateGallery($picturelist, false);
701
-
702
- $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
703
- return $out;
704
- }
705
-
706
- /**
707
- * nggShowRelatedGallery() - create a gallery based on the tags
708
- *
709
- * @access public
710
- * @param string $taglist list of tags as csv
711
- * @param integer $maxImages (optional) limit the number of images to show
712
- * @return the content
713
- */
714
- function nggShowRelatedGallery($taglist, $maxImages = 0) {
715
-
716
- $ngg_options = nggGallery::get_option('ngg_options');
717
-
718
- // get now the related images
719
- $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
720
-
721
- // go on if not empty
722
- if ( empty($picturelist) )
723
- return;
724
-
725
- // cut the list to maxImages
726
- if ( $maxImages > 0 )
727
- array_splice($picturelist, $maxImages);
728
-
729
- // *** build the gallery output
730
- $out = '<div class="ngg-related-gallery">';
731
- foreach ($picturelist as $picture) {
732
-
733
- // get the effect code
734
- $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());
735
-
736
- $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description)) . '" ' . $thumbcode . ' >';
737
- $out .= '<img title="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" alt="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" src="' . $picture->thumbURL . '" />';
738
- $out .= '</a>' . "\n";
739
- }
740
- $out .= '</div>' . "\n";
741
-
742
- $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
743
-
744
- return $out;
745
- }
746
-
747
- /**
748
- * nggShowAlbumTags() - create a gallery based on the tags
749
- *
750
- * @access public
751
- * @param string $taglist list of tags as csv
752
- * @return the content
753
- */
754
- function nggShowAlbumTags($taglist) {
755
-
756
- global $wpdb, $nggRewrite;
757
-
758
- // $_GET from wp_query
759
- $tag = get_query_var('gallerytag');
760
- $pageid = get_query_var('pageid');
761
-
762
- // look for gallerytag variable
763
- if ( $pageid == get_the_ID() || !is_home() ) {
764
- if (!empty( $tag )) {
765
-
766
- // avoid this evil code $sql = 'SELECT name FROM wp_ngg_tags WHERE slug = \'slug\' union select concat(0x7c,user_login,0x7c,user_pass,0x7c) from wp_users WHERE 1 = 1';
767
- $slug = attribute_escape( $tag );
768
- $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
769
- $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>';
770
- $out .= nggShowGalleryTags($slug);
771
- return $out;
772
-
773
- }
774
- }
775
-
776
- // get now the related images
777
- $picturelist = nggTags::get_album_images($taglist);
778
-
779
- // go on if not empty
780
- if ( empty($picturelist) )
781
- return;
782
-
783
- // re-structure the object that we can use the standard template
784
- foreach ($picturelist as $key => $picture) {
785
- $picturelist[$key]->previewpic = $picture->pid;
786
- $picturelist[$key]->previewname = $picture->filename;
787
- $picturelist[$key]->previewurl = get_option ('siteurl') . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
788
- $picturelist[$key]->counter = $picture->count;
789
- $picturelist[$key]->title = $picture->name;
790
- $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
791
- }
792
-
793
- //TODO: Add pagination later
794
- $navigation = '<div class="ngg-clear">&nbsp;</div>';
795
-
796
- // create the output
797
- $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );
798
-
799
- $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
800
-
801
- return $out;
802
- }
803
-
804
- /**
805
- * nggShowRelatedImages() - return related images based on category or tags
806
- *
807
- * @access public
808
- * @param string $type could be 'tags' or 'category'
809
- * @param integer $maxImages of images
810
- * @return the content
811
- */
812
- function nggShowRelatedImages($type = '', $maxImages = 0) {
813
- $ngg_options = nggGallery::get_option('ngg_options');
814
-
815
- if ($type == '') {
816
- $type = $ngg_options['appendType'];
817
- $maxImages = $ngg_options['maxImages'];
818
- }
819
-
820
- $sluglist = array();
821
-
822
- switch ($type) {
823
- case 'tags':
824
- if (function_exists('get_the_tags')) {
825
- $taglist = get_the_tags();
826
-
827
- if (is_array($taglist)) {
828
- foreach ($taglist as $tag) {
829
- $sluglist[] = $tag->slug;
830
- }
831
- }
832
- }
833
- break;
834
-
835
- case 'category':
836
- $catlist = get_the_category();
837
-
838
- if (is_array($catlist)) {
839
- foreach ($catlist as $cat) {
840
- $sluglist[] = $cat->category_nicename;
841
- }
842
- }
843
- break;
844
- }
845
-
846
- $sluglist = implode(',', $sluglist);
847
- $out = nggShowRelatedGallery($sluglist, $maxImages);
848
-
849
- return $out;
850
- }
851
-
852
- /**
853
- * Template function for theme authors
854
- *
855
- * @access public
856
- * @param string (optional) $type could be 'tags' or 'category'
857
- * @param integer (optional) $maxNumbers of images
858
- * @return void
859
- */
860
- function the_related_images($type = 'tags', $maxNumbers = 7) {
861
- echo nggShowRelatedImages($type, $maxNumbers);
862
- }
863
-
864
- /**
865
- * nggShowRandomRecent($type, $maxImages,$template) - return recent or random images
866
- *
867
- * @access public
868
- * @param string $type 'recent' or 'random'
869
- * @param integer $maxImages of images
870
- * @param string $template (optional) name for a template file, look for gallery-$template
871
- * @return the content
872
- */
873
- function nggShowRandomRecent($type, $maxImages, $template = '') {
874
-
875
- // $_GET from wp_query
876
- $pid = get_query_var('pid');
877
- $pageid = get_query_var('pageid');
878
-
879
- // get now the recent or random images
880
- if ($type == 'random')
881
- $picturelist = nggdb::get_random_images($maxImages);
882
- else
883
- $picturelist = nggdb::find_last_images(0, $maxImages, true);
884
-
885
- // look for ImageBrowser if we have a $_GET('pid')
886
- if ( $pageid == get_the_ID() || !is_home() )
887
- if (!empty( $pid )) {
888
- foreach ($picturelist as $picture) {
889
- $picarray[] = $picture->pid;
890
- }
891
- $out = nggCreateImageBrowser($picarray);
892
- return $out;
893
- }
894
-
895
- // go on if not empty
896
- if ( empty($picturelist) )
897
- return;
898
-
899
- // show gallery
900
- if ( is_array($picturelist) )
901
- $out = nggCreateGallery($picturelist, false, $template);
902
-
903
- $out = apply_filters('ngg_show_images_content', $out, $taglist);
904
-
905
- return $out;
906
- }
907
-
908
- /**
909
- * nggTagCloud() - return a tag cloud based on the wp core tag cloud system
910
- *
911
- * @param array $args
912
- * @param string $template (optional) name for a template file, look for gallery-$template
913
- * @return the content
914
- */
915
- function nggTagCloud($args ='', $template = '') {
916
- global $nggRewrite;
917
-
918
- // $_GET from wp_query
919
- $tag = get_query_var('gallerytag');
920
- $pageid = get_query_var('pageid');
921
-
922
- // look for gallerytag variable
923
- if ( $pageid == get_the_ID() || !is_home() ) {
924
- if (!empty( $tag )) {
925
-
926
- $slug = attribute_escape( $tag );
927
- $out = nggShowGalleryTags( $slug );
928
- return $out;
929
- }
930
- }
931
-
932
- $defaults = array(
933
- 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
934
- 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
935
- 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
936
- );
937
- $args = wp_parse_args( $args, $defaults );
938
-
939
- $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
940
-
941
- foreach ($tags as $key => $tag ) {
942
-
943
- $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
944
- $tags[ $key ]->id = $tag->term_id;
945
- }
946
-
947
- $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';
948
-
949
- return $out;
950
- }
951
- ?>
 
 
 
1
+ <?php
2
+
3
+ if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
4
+
5
+ /**
6
+ * Return a script for the Imagerotator flash slideshow. Can be used in any tmeplate with <?php echo nggShowSlideshow($galleryID, $width, $height) ?>
7
+ * Require the script swfobject.js in the header or footer
8
+ *
9
+ * @access public
10
+ * @param integer $galleryID ID of the gallery
11
+ * @param integer $irWidth Width of the flash container
12
+ * @param integer $irHeight Height of the flash container
13
+ * @return the content
14
+ */
15
+ function nggShowSlideshow($galleryID, $width, $height) {
16
+
17
+ require_once (dirname (__FILE__).'/lib/swfobject.php');
18
+
19
+ $ngg_options = nggGallery::get_option('ngg_options');
20
+
21
+ // remove media file from RSS feed
22
+ if ( is_feed() ) {
23
+ $out = '[' . nggGallery::i18n($ngg_options['galTextSlide']) . ']';
24
+ return $out;
25
+ }
26
+
27
+ // If the Imagerotator didn't exist, skip the output
28
+ if ( NGGALLERY_IREXIST == false )
29
+ return;
30
+
31
+ if (empty($width) ) $width = (int) $ngg_options['irWidth'];
32
+ if (empty($height)) $height = (int) $ngg_options['irHeight'];
33
+
34
+ // init the flash output
35
+ $swfobject = new swfobject( $ngg_options['irURL'] , 'so' . $galleryID, $width, $height, '7.0.0', 'false');
36
+
37
+ $swfobject->message = '<p>'. __('The <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> and <a href="http://www.mozilla.com/firefox/">a browser with Javascript support</a> are needed..', 'nggallery').'</p>';
38
+ $swfobject->add_params('wmode', 'opaque');
39
+ $swfobject->add_params('allowfullscreen', 'true');
40
+ $swfobject->add_params('bgcolor', $ngg_options['irScreencolor'], '000000', 'string', '#');
41
+ $swfobject->add_attributes('styleclass', 'slideshow');
42
+ $swfobject->add_attributes('name', 'so' . $galleryID);
43
+
44
+ // adding the flash parameter
45
+ $swfobject->add_flashvars( 'file', NGGALLERY_URLPATH.'xml/imagerotator.php?gid=' . $galleryID );
46
+ $swfobject->add_flashvars( 'shuffle', $ngg_options['irShuffle'], 'true', 'bool');
47
+ $swfobject->add_flashvars( 'linkfromdisplay', $ngg_options['irLinkfromdisplay'], 'false', 'bool');
48
+ $swfobject->add_flashvars( 'shownavigation', $ngg_options['irShownavigation'], 'true', 'bool');
49
+ $swfobject->add_flashvars( 'showicons', $ngg_options['irShowicons'], 'true', 'bool');
50
+ $swfobject->add_flashvars( 'kenburns', $ngg_options['irKenburns'], 'false', 'bool');
51
+ $swfobject->add_flashvars( 'overstretch', $ngg_options['irOverstretch'], 'false', 'string');
52
+ $swfobject->add_flashvars( 'rotatetime', $ngg_options['irRotatetime'], 5, 'int');
53
+ $swfobject->add_flashvars( 'transition', $ngg_options['irTransition'], 'random', 'string');
54
+ $swfobject->add_flashvars( 'backcolor', $ngg_options['irBackcolor'], 'FFFFFF', 'string', '0x');
55
+ $swfobject->add_flashvars( 'frontcolor', $ngg_options['irFrontcolor'], '000000', 'string', '0x');
56
+ $swfobject->add_flashvars( 'lightcolor', $ngg_options['irLightcolor'], '000000', 'string', '0x');
57
+ $swfobject->add_flashvars( 'screencolor', $ngg_options['irScreencolor'], '000000', 'string', '0x');
58
+ if ($ngg_options['irWatermark'])
59
+ $swfobject->add_flashvars( 'logo', $ngg_options['wmPath'], '', 'string');
60
+ $swfobject->add_flashvars( 'audio', $ngg_options['irAudio'], '', 'string');
61
+ $swfobject->add_flashvars( 'width', $width, '260');
62
+ $swfobject->add_flashvars( 'height', $height, '320');
63
+ // create the output
64
+ $out = '<div class="slideshow">' . $swfobject->output() . '</div>';
65
+ // add now the script code
66
+ $out .= "\n".'<script type="text/javascript" defer="defer">';
67
+ if ($ngg_options['irXHTMLvalid']) $out .= "\n".'<!--';
68
+ if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//<![CDATA[';
69
+ $out .= $swfobject->javascript();
70
+ if ($ngg_options['irXHTMLvalid']) $out .= "\n".'//]]>';
71
+ if ($ngg_options['irXHTMLvalid']) $out .= "\n".'-->';
72
+ $out .= "\n".'</script>';
73
+
74
+ $out = apply_filters('ngg_show_slideshow_content', $out);
75
+
76
+ return $out;
77
+ }
78
+
79
+ /**
80
+ * nggShowGallery() - return a gallery
81
+ *
82
+ * @access public
83
+ * @param int $galleryID
84
+ * @param string $template (optional) name for a template file, look for gallery-$template
85
+ * @return the content
86
+ */
87
+ function nggShowGallery( $galleryID, $template = '' ) {
88
+
89
+ global $nggRewrite;
90
+
91
+ $ngg_options = nggGallery::get_option('ngg_options');
92
+
93
+ //Set sort order value, if not used (upgrade issue)
94
+ $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
95
+ $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
96
+
97
+ // get gallery values
98
+ $picturelist = nggdb::get_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
99
+
100
+ if ( !$picturelist->gid )
101
+ __('[Gallery not found]','nggallery');
102
+ else
103
+ $galleryID = (int) $picturelist->gid;
104
+
105
+ // $_GET from wp_query
106
+ $show = get_query_var('show');
107
+ $pid = get_query_var('pid');
108
+ $pageid = get_query_var('pageid');
109
+
110
+ // set $show if slideshow first
111
+ if ( empty( $show ) AND ($ngg_options['galShowOrder'] == 'slide')) {
112
+ if ( is_home() )
113
+ $pageid = get_the_ID();
114
+
115
+ $show = 'slide';
116
+ }
117
+
118
+ // go on only on this page
119
+ if ( !is_home() || $pageid == get_the_ID() ) {
120
+
121
+ // 1st look for ImageBrowser link
122
+ if ( !empty($pid) && $ngg_options['galImgBrowser'] ) {
123
+ $out = nggShowImageBrowser( $galleryID, $mode );
124
+ return $out;
125
+ }
126
+
127
+ // 2nd look for slideshow
128
+ if ( $show == 'slide' ) {
129
+ $args['show'] = "gallery";
130
+ $out = '<div class="ngg-galleryoverview">';
131
+ $out .= '<div class="slideshowlink"><a class="slideshowlink" href="' . $nggRewrite->get_permalink($args) . '">'.nggGallery::i18n($ngg_options['galTextGallery']).'</a></div>';
132
+ $out .= nggShowSlideshow($galleryID, $ngg_options['irWidth'], $ngg_options['irHeight']);
133
+ $out .= '</div>'."\n";
134
+ $out .= '<div class="ngg-clear"></div>'."\n";
135
+ return $out;
136
+ }
137
+ }
138
+
139
+ // get all picture with this galleryid
140
+ if ( is_array($picturelist) )
141
+ $out = nggCreateGallery($picturelist, $galleryID, $template);
142
+
143
+ $out = apply_filters('ngg_show_gallery_content', $out, intval($galleryID));
144
+ return $out;
145
+ }
146
+
147
+ /**
148
+ * Build a gallery output
149
+ *
150
+ * @access internal
151
+ * @param array $picturelist
152
+ * @param bool $galleryID, if you supply a gallery ID, you can add a slideshow link
153
+ * @param string $template (optional) name for a template file, look for gallery-$template
154
+ * @return the content
155
+ */
156
+ function nggCreateGallery($picturelist, $galleryID = false, $template = '') {
157
+ global $nggRewrite;
158
+
159
+ $ngg_options = nggGallery::get_option('ngg_options');
160
+
161
+ // $_GET from wp_query
162
+ $nggpage = get_query_var('nggpage');
163
+ $pageid = get_query_var('pageid');
164
+
165
+ // we need to know the current page id
166
+ $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
167
+
168
+ if ( !is_array($picturelist) )
169
+ $picturelist = array($picturelist);
170
+
171
+ // Populate galleries values from the first image
172
+ $first_image = current($picturelist);
173
+ $gallery = new stdclass;
174
+ $gallery->ID = (int) $galleryID;
175
+ $gallery->show_slideshow = false;
176
+ $gallery->name = stripslashes ( $first_image->name );
177
+ $gallery->title = stripslashes( $first_image->title );
178
+ $gallery->description = html_entity_decode(stripslashes( $first_image->galdesc));
179
+ $gallery->pageid = $first_image->pageid;
180
+ $gallery->anchor = 'ngg-gallery-' . $galleryID . '-' . $current_page;
181
+ reset($picturelist);
182
+
183
+ $maxElement = $ngg_options['galImages'];
184
+ $thumbwidth = $ngg_options['thumbwidth'];
185
+ $thumbheight = $ngg_options['thumbheight'];
186
+
187
+ // fixed width if needed
188
+ $gallery->columns = intval($ngg_options['galColumns']);
189
+ $gallery->imagewidth = ($gallery->columns > 0) ? 'style="width:'. floor(100/$gallery->columns) .'%;"' : '';
190
+
191
+ // set thumb size
192
+ $thumbsize = '';
193
+ if ($ngg_options['thumbfix']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbheight.'"';
194
+ if ($ngg_options['thumbcrop']) $thumbsize = 'width="'.$thumbwidth.'" height="'.$thumbwidth.'"';
195
+
196
+ // show slideshow link
197
+ if ($galleryID) {
198
+ if (($ngg_options['galShowSlide']) AND (NGGALLERY_IREXIST)) {
199
+ $gallery->show_slideshow = true;
200
+ $gallery->slideshow_link = $nggRewrite->get_permalink(array ('show' => "slide"));
201
+ $gallery->slideshow_link_text = nggGallery::i18n($ngg_options['galTextSlide']);
202
+ }
203
+
204
+ if ($ngg_options['usePicLens']) {
205
+ $gallery->show_piclens = true;
206
+ $gallery->piclens_link = "javascript:PicLensLite.start({feedUrl:'" . htmlspecialchars( nggMediaRss::get_gallery_mrss_url($gallery->ID) ) . "'});";
207
+ }
208
+ }
209
+
210
+ // check for page navigation
211
+ if ($maxElement > 0) {
212
+ if ( !is_home() || $pageid == $current_page ) {
213
+ $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
214
+ }
215
+ else $page = 1;
216
+
217
+ $start = $offset = ( $page - 1 ) * $maxElement;
218
+
219
+ $total = count($picturelist);
220
+
221
+ // remove the element if we didn't start at the beginning
222
+ if ($start > 0 ) array_splice($picturelist, 0, $start);
223
+
224
+ // return the list of images we need
225
+ array_splice($picturelist, $maxElement);
226
+
227
+ $navigation = nggGallery::create_navigation($page, $total, $maxElement);
228
+ } else {
229
+ $navigation = '<div class="ngg-clear">&nbsp;</div>';
230
+ }
231
+
232
+ foreach ($picturelist as $key => $picture) {
233
+ // choose link between imagebrowser or effect
234
+ $link = ($ngg_options['galImgBrowser']) ? $nggRewrite->get_permalink( array('pid'=>$picture->pid) ) : $picture->imageURL;
235
+
236
+ // get the effect code
237
+ if ($galleryID)
238
+ $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode($picturelist[0]->name);
239
+ else
240
+ $thumbcode = ($ngg_options['galImgBrowser']) ? '' : $picture->get_thumbcode(get_the_title());
241
+
242
+ // add a filter for the link
243
+ $picturelist[$key]->imageURL = apply_filters('ngg_create_gallery_link', $link, $picture);
244
+ $picturelist[$key]->thumbnailURL = $picture->thumbURL;
245
+ $picturelist[$key]->size = $thumbsize;
246
+ $picturelist[$key]->thumbcode = $thumbcode;
247
+ $picturelist[$key]->caption = ( empty($picture->description) ) ? '&nbsp;' : html_entity_decode ( stripslashes(nggGallery::i18n($picture->description)) );
248
+ $picturelist[$key]->description = ( empty($picture->description) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->description)) );
249
+ $picturelist[$key]->alttext = ( empty($picture->alttext) ) ? ' ' : htmlspecialchars ( stripslashes(nggGallery::i18n($picture->alttext)) );
250
+ // filter to add custom content for the output
251
+ $picturelist[$key] = apply_filters('ngg_image_object', $picturelist[$key], $picture->pid);
252
+ }
253
+
254
+ // look for gallery-$template.php or pure gallery.php
255
+ $filename = ( empty($template) ) ? 'gallery' : 'gallery-' . $template;
256
+
257
+ //filter functions for custom addons
258
+ $gallery = apply_filters( 'ngg_gallery_object', $gallery, $galleryID );
259
+ $picturelist = apply_filters( 'ngg_image_object', $picturelist, $galleryID );
260
+
261
+ // create the output
262
+ $out = nggGallery::capture ( $filename, array ('gallery' => $gallery, 'images' => $picturelist, 'pagination' => $navigation) );
263
+
264
+ // apply a filter after the output
265
+ $out = apply_filters('ngg_gallery_output', $out, $picturelist);
266
+
267
+ return $out;
268
+ }
269
+
270
+ /**
271
+ * nggShowAlbum() - return a album based on the id
272
+ *
273
+ * @access public
274
+ * @param int | string $albumID
275
+ * @param string (optional) $template
276
+ * @return the content
277
+ */
278
+ function nggShowAlbum($albumID, $template = 'extend') {
279
+
280
+ // $_GET from wp_query
281
+ $gallery = get_query_var('gallery');
282
+ $album = get_query_var('album');
283
+
284
+ // in the case somebody uses the '0', it should be 'all' to show all galleries
285
+ $albumID = ($albumID == 0) ? 'all' : $albumID;
286
+
287
+ // first look for gallery variable
288
+ if (!empty( $gallery )) {
289
+
290
+ // subalbum support only one instance, you can't use more of them in one post
291
+ if ( isset($GLOBALS['subalbum']) || isset($GLOBALS['nggShowGallery']) )
292
+ return;
293
+
294
+ // if gallery is is submit , then show the gallery instead
295
+ $out = nggShowGallery( intval($gallery) );
296
+ $GLOBALS['nggShowGallery'] = true;
297
+
298
+ return $out;
299
+ }
300
+
301
+ if ( (empty( $gallery )) && (isset($GLOBALS['subalbum'])) )
302
+ return;
303
+
304
+ //redirect to subalbum only one time
305
+ if (!empty( $album )) {
306
+ $GLOBALS['subalbum'] = true;
307
+ $albumID = $album;
308
+ }
309
+
310
+ // lookup in the database
311
+ $album = nggdb::find_album( $albumID );
312
+
313
+ // still no success ? , die !
314
+ if( !$album )
315
+ return __('[Album not found]','nggallery');
316
+
317
+ $mode = ltrim($mode, ',');
318
+
319
+ if ( is_array($album->gallery_ids) )
320
+ $out = nggCreateAlbum( $album->gallery_ids, $template, $album );
321
+
322
+ $out = apply_filters( 'ngg_show_album_content', $out, $album->id );
323
+
324
+ return $out;
325
+ }
326
+
327
+ /**
328
+ * nggCreateAlbum()
329
+ *
330
+ * @access internal
331
+ * @param array $galleriesID
332
+ * @param string (optional) $template name for a template file, look for album-$template
333
+ * @param object (optional) $album result from the db
334
+ * @return the content
335
+ */
336
+ function nggCreateAlbum( $galleriesID, $template = 'extend', $album = 0) {
337
+ // create a gallery overview div
338
+
339
+ global $wpdb, $nggRewrite, $nggdb;
340
+
341
+ // $_GET from wp_query
342
+ $nggpage = get_query_var('nggpage');
343
+
344
+ $ngg_options = nggGallery::get_option('ngg_options');
345
+
346
+ //this option can currently only set via the custom fields
347
+ $maxElement = (int) $ngg_options['galPagedGalleries'];
348
+
349
+ $sortorder = $galleriesID;
350
+ $galleries = array();
351
+
352
+ // get the galleries information
353
+ foreach ($galleriesID as $i => $value)
354
+ $galleriesID[$i] = addslashes($value);
355
+
356
+ $unsort_galleries = $wpdb->get_results('SELECT * FROM '.$wpdb->nggallery.' WHERE gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
357
+
358
+ //TODO: Check this, problem exist when previewpic = 0
359
+ //$galleries = $wpdb->get_results('SELECT t.*, tt.* FROM '.$wpdb->nggallery.' AS t INNER JOIN '.$wpdb->nggpictures.' AS tt ON t.previewpic = tt.pid WHERE t.gid IN (\''.implode('\',\'', $galleriesID).'\')', OBJECT_K);
360
+
361
+ // get the counter values
362
+ $picturesCounter = $wpdb->get_results('SELECT galleryid, COUNT(*) as counter FROM '.$wpdb->nggpictures.' WHERE galleryid IN (\''.implode('\',\'', $galleriesID).'\') AND exclude != 1 GROUP BY galleryid', OBJECT_K);
363
+ if ( is_array($picturesCounter) ) {
364
+ foreach ($picturesCounter as $key => $value)
365
+ $unsort_galleries[$key]->counter = $value->counter;
366
+ }
367
+
368
+ // get the id's of the preview images
369
+ $imagesID = array();
370
+ if ( is_array($unsort_galleries) ) {
371
+ foreach ($unsort_galleries as $gallery_row)
372
+ $imagesID[] = $gallery_row->previewpic;
373
+ }
374
+ $albumPreview = $wpdb->get_results('SELECT pid, filename FROM '.$wpdb->nggpictures.' WHERE pid IN (\''.implode('\',\'', $imagesID).'\')', OBJECT_K);
375
+
376
+ // re-order them and populate some
377
+ foreach ($sortorder as $key) {
378
+
379
+ //if we have a prefix 'a' then it's a subalbum, instead a gallery
380
+ if (substr( $key, 0, 1) == 'a') {
381
+ // get the album content
382
+ if ( !$subalbum = $nggdb->find_album(substr( $key, 1)) )
383
+ continue;
384
+
385
+ //populate the sub album values
386
+ $galleries[$key]->counter = 0;
387
+ if ($subalbum->previewpic > 0)
388
+ $image = $nggdb->find_image( $subalbum->previewpic );
389
+ $galleries[$key]->previewpic = $subalbum->previewpic;
390
+ $galleries[$key]->previewurl = ($image->thumbURL) ? $image->thumbURL : '';
391
+ $galleries[$key]->previewname = $subalbum->name;
392
+
393
+ //link to the subalbum
394
+ $args['album'] = $subalbum->id;
395
+ $args['gallery'] = false;
396
+ $args['nggpage'] = false;
397
+ $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
398
+ $galleries[$key]->galdesc = html_entity_decode ( nggGallery::i18n($subalbum->albumdesc) );
399
+ $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($subalbum->name) );
400
+
401
+ continue;
402
+ }
403
+
404
+ // Add the counter value if avaible
405
+ $galleries[$key] = $unsort_galleries[$key];
406
+
407
+ // add the file name and the link
408
+ if ($galleries[$key]->previewpic != 0) {
409
+ $galleries[$key]->previewname = $albumPreview[$galleries[$key]->previewpic]->filename;
410
+ $galleries[$key]->previewurl = get_option ('siteurl').'/' . $galleries[$key]->path . '/thumbs/thumbs_' . $albumPreview[$galleries[$key]->previewpic]->filename;
411
+ } else {
412
+ $first_image = $wpdb->get_row('SELECT * FROM '. $wpdb->nggpictures .' WHERE exclude != 1 AND galleryid = '. $key .' ORDER by pid DESC limit 0,1');
413
+ $galleries[$key]->previewpic = $first_image->pid;
414
+ $galleries[$key]->previewname = $first_image->filename;
415
+ $galleries[$key]->previewurl = get_option ('siteurl') . '/' . $galleries[$key]->path . '/thumbs/thumbs_' . $first_image->filename;
416
+ }
417
+
418
+ // choose between variable and page link
419
+ if ($ngg_options['galNoPages']) {
420
+ $args['album'] = $album->id;
421
+ $args['gallery'] = $key;
422
+ $args['nggpage'] = false;
423
+ $galleries[$key]->pagelink = $nggRewrite->get_permalink($args);
424
+
425
+ } else {
426
+ $galleries[$key]->pagelink = get_permalink( $galleries[$key]->pageid );
427
+ }
428
+
429
+ // description can contain HTML tags
430
+ $galleries[$key]->galdesc = html_entity_decode ( stripslashes($galleries[$key]->galdesc) ) ;
431
+
432
+ // i18n
433
+ $galleries[$key]->title = html_entity_decode ( nggGallery::i18n($galleries[$key]->title) ) ;
434
+ }
435
+
436
+ // check for page navigation
437
+ if ($maxElement > 0) {
438
+ if ( !is_home() || $pageid == get_the_ID() ) {
439
+ $page = ( !empty( $nggpage ) ) ? (int) $nggpage : 1;
440
+ }
441
+ else $page = 1;
442
+
443
+ $start = $offset = ( $page - 1 ) * $maxElement;
444
+
445
+ $total = count($galleries);
446
+
447
+ // remove the element if we didn't start at the beginning
448
+ if ($start > 0 ) array_splice($galleries, 0, $start);
449
+
450
+ // return the list of images we need
451
+ array_splice($galleries, $maxElement);
452
+
453
+ $navigation = nggGallery::create_navigation($page, $total, $maxElement);
454
+ } else {
455
+ $navigation = '<div class="ngg-clear">&nbsp;</div>';
456
+ }
457
+
458
+ // if sombody didn't enter any template , take the extend version
459
+ $filename = ( empty($template) ) ? 'album-extend' : 'album-' . $template ;
460
+
461
+ // create the output
462
+ $out = nggGallery::capture ( $filename, array ('album' => $album, 'galleries' => $galleries, 'pagination' => $navigation) );
463
+
464
+ return $out;
465
+
466
+ }
467
+
468
+ /**
469
+ * nggShowImageBrowser()
470
+ *
471
+ * @access public
472
+ * @param int|string $galleryID or gallery name
473
+ * @param string $template (optional) name for a template file, look for imagebrowser-$template
474
+ * @return the content
475
+ */
476
+ function nggShowImageBrowser($galleryID, $template = '') {
477
+
478
+ global $wpdb;
479
+
480
+ $ngg_options = nggGallery::get_option('ngg_options');
481
+
482
+ //Set sort order value, if not used (upgrade issue)
483
+ $ngg_options['galSort'] = ($ngg_options['galSort']) ? $ngg_options['galSort'] : 'pid';
484
+ $ngg_options['galSortDir'] = ($ngg_options['galSortDir'] == 'DESC') ? 'DESC' : 'ASC';
485
+
486
+ // get the pictures
487
+ $picturelist = nggdb::get_ids_from_gallery($galleryID, $ngg_options['galSort'], $ngg_options['galSortDir']);
488
+
489
+ if ( is_array($picturelist) )
490
+ $out = nggCreateImageBrowser($picturelist, $template);
491
+ else
492
+ $out = __('[Gallery not found]','nggallery');
493
+
494
+ $out = apply_filters('ngg_show_imagebrowser_content', $out, $galleryID);
495
+
496
+ return $out;
497
+
498
+ }
499
+
500
+ /**
501
+ * nggCreateImageBrowser()
502
+ *
503
+ * @access internal
504
+ * @param array $picarray with pid
505
+ * @param string $template (optional) name for a template file, look for imagebrowser-$template
506
+ * @return the content
507
+ */
508
+ function nggCreateImageBrowser($picarray, $template = '') {
509
+
510
+ global $nggRewrite;
511
+
512
+ require_once( dirname (__FILE__) . '/lib/meta.php' );
513
+
514
+ // $_GET from wp_query
515
+ $pid = get_query_var('pid');
516
+
517
+ // we need to know the current page id
518
+ $current_page = (get_the_ID() == false) ? 0 : get_the_ID();
519
+
520
+ if ( !is_array($picarray) )
521
+ $picarray = array($picarray);
522
+
523
+ $total = count($picarray);
524
+
525
+ // look for gallery variable
526
+ if ( !empty( $pid )) {
527
+ $act_pid = (int) $pid;
528
+ } else {
529
+ reset($picarray);
530
+ $act_pid = current($picarray);
531
+ }
532
+
533
+ // get ids for back/next
534
+ $key = array_search($act_pid,$picarray);
535
+ if (!$key) {
536
+ $act_pid = reset($picarray);
537
+ $key = key($picarray);
538
+ }
539
+ $back_pid = ( $key >= 1 ) ? $picarray[$key-1] : end($picarray) ;
540
+ $next_pid = ( $key < ($total-1) ) ? $picarray[$key+1] : reset($picarray) ;
541
+
542
+ // get the picture data
543
+ $picture = nggdb::find_image($act_pid);
544
+
545
+ // if we didn't get some data, exit now
546
+ if ($picture == null)
547
+ return;
548
+
549
+ // add more variables for render output
550
+ $picture->href_link = $picture->get_href_link();
551
+ $picture->previous_image_link = $nggRewrite->get_permalink(array ('pid' => $back_pid));
552
+ $picture->previous_pid = $back_pid;
553
+ $picture->next_image_link = $nggRewrite->get_permalink(array ('pid' => $next_pid));
554
+ $picture->next_pid = $next_pid;
555
+ $picture->number = $key + 1;
556
+ $picture->total = $total;
557
+ $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
558
+ $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
559
+ $picture->description = html_entity_decode( stripslashes($picture->description) );
560
+ $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;
561
+
562
+ // filter to add custom content for the output
563
+ $picture = apply_filters('ngg_image_object', $picture, $act_pid);
564
+
565
+ // let's get the meta data
566
+ $meta = new nggMeta($picture->imagePath);
567
+ $exif = $meta->get_EXIF();
568
+ $iptc = $meta->get_IPTC();
569
+ $xmp = $meta->get_XMP();
570
+
571
+ // look for imagebrowser-$template.php or pure imagebrowser.php
572
+ $filename = ( empty($template) ) ? 'imagebrowser' : 'imagebrowser-' . $template;
573
+
574
+ // create the output
575
+ $out = nggGallery::capture ( $filename , array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
576
+
577
+ return $out;
578
+
579
+ }
580
+
581
+ /**
582
+ * nggSinglePicture() - show a single picture based on the id
583
+ *
584
+ * @access public
585
+ * @param int $imageID, db-ID of the image
586
+ * @param int (optional) $width, width of the image
587
+ * @param int (optional) $height, height of the image
588
+ * @param string $mode (optional) could be none, watermark, web20
589
+ * @param string $float (optional) could be none, left, right
590
+ * @param string $template (optional) name for a template file, look for singlepic-$template
591
+ * @param string $caption (optional) additional caption text
592
+ * @return the content
593
+ */
594
+ function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '' , $template = '', $caption = '') {
595
+ global $post;
596
+
597
+ $ngg_options = nggGallery::get_option('ngg_options');
598
+
599
+ // get picturedata
600
+ $picture = nggdb::find_image($imageID);
601
+
602
+ // if we didn't get some data, exit now
603
+ if ($picture == null)
604
+ return __('[SinglePic not found]','nggallery');
605
+
606
+ // add float to img
607
+ switch ($float) {
608
+
609
+ case 'left':
610
+ $float =' ngg-left';
611
+ break;
612
+
613
+ case 'right':
614
+ $float =' ngg-right';
615
+ break;
616
+
617
+ case 'center':
618
+ $float =' ngg-center';
619
+ break;
620
+
621
+ default:
622
+ $float ='';
623
+ break;
624
+ }
625
+
626
+ // clean mode if needed
627
+ $mode = ( eregi('web20|watermark', $mode) ) ? $mode : '';
628
+
629
+ //let's initiate the url
630
+ $picture->thumbnailURL = false;
631
+
632
+ // check fo cached picture
633
+ if ( ($ngg_options['imgCacheSinglePic']) && ($post->post_status == 'publish') )
634
+ $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode );
635
+
636
+ // if we didn't use a cached image then we take the on-the-fly mode
637
+ if (!$picture->thumbnailURL)
638
+ $picture->thumbnailURL = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
639
+
640
+ // add more variables for render output
641
+ $picture->href_link = $picture->get_href_link();
642
+ $picture->alttext = html_entity_decode( stripslashes($picture->alttext) );
643
+ $picture->linktitle = htmlspecialchars( stripslashes($picture->description) );
644
+ $picture->description = html_entity_decode( stripslashes($picture->description) );
645
+ $picture->classname = 'ngg-singlepic'. $float;
646
+ $picture->thumbcode = $picture->get_thumbcode( 'singlepic' . $imageID);
647
+ $picture->height = (int) $height;
648
+ $picture->width = (int) $width;
649
+ $picture->caption = $caption;
650
+
651
+ // filter to add custom content for the output
652
+ $picture = apply_filters('ngg_image_object', $picture, $imageID);
653
+
654
+ // let's get the meta data
655
+ $meta = new nggMeta($picture->imagePath);
656
+ $exif = $meta->get_EXIF();
657
+ $iptc = $meta->get_IPTC();
658
+ $xmp = $meta->get_XMP();
659
+
660
+ // look for singlepic-$template.php or pure singlepic.php
661
+ $filename = ( empty($template) ) ? 'singlepic' : 'singlepic-' . $template;
662
+
663
+ // create the output
664
+ $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp) );
665
+
666
+ $out = apply_filters('ngg_show_singlepic_content', $out, $picture );
667
+
668
+ return $out;
669
+ }
670
+
671
+ /**
672
+ * nggShowGalleryTags() - create a gallery based on the tags
673
+ *
674
+ * @access public
675
+ * @param string $taglist list of tags as csv
676
+ * @return the content
677
+ */
678
+ function nggShowGalleryTags($taglist) {
679
+
680
+ // $_GET from wp_query
681
+ $pid = get_query_var('pid');
682
+ $pageid = get_query_var('pageid');
683
+
684
+ // get now the related images
685
+ $picturelist = nggTags::find_images_for_tags($taglist , 'ASC');
686
+
687
+ // look for ImageBrowser if we have a $_GET('pid')
688
+ if ( $pageid == get_the_ID() || !is_home() )
689
+ if (!empty( $pid )) {
690
+ foreach ($picturelist as $picture) {
691
+ $picarray[] = $picture->pid;
692
+ }
693
+ $out = nggCreateImageBrowser($picarray);
694
+ return $out;
695
+ }
696
+
697
+ // go on if not empty
698
+ if ( empty($picturelist) )
699
+ return;
700
+
701
+ // show gallery
702
+ if ( is_array($picturelist) )
703
+ $out = nggCreateGallery($picturelist, false);
704
+
705
+ $out = apply_filters('ngg_show_gallery_tags_content', $out, $taglist);
706
+ return $out;
707
+ }
708
+
709
+ /**
710
+ * nggShowRelatedGallery() - create a gallery based on the tags
711
+ *
712
+ * @access public
713
+ * @param string $taglist list of tags as csv
714
+ * @param integer $maxImages (optional) limit the number of images to show
715
+ * @return the content
716
+ */
717
+ function nggShowRelatedGallery($taglist, $maxImages = 0) {
718
+
719
+ $ngg_options = nggGallery::get_option('ngg_options');
720
+
721
+ // get now the related images
722
+ $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
723
+
724
+ // go on if not empty
725
+ if ( empty($picturelist) )
726
+ return;
727
+
728
+ // cut the list to maxImages
729
+ if ( $maxImages > 0 )
730
+ array_splice($picturelist, $maxImages);
731
+
732
+ // *** build the gallery output
733
+ $out = '<div class="ngg-related-gallery">';
734
+ foreach ($picturelist as $picture) {
735
+
736
+ // get the effect code
737
+ $thumbcode = $picture->get_thumbcode( __('Related images for', 'nggallery') . ' ' . get_the_title());
738
+
739
+ $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description)) . '" ' . $thumbcode . ' >';
740
+ $out .= '<img title="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" alt="' . stripslashes(nggGallery::i18n($picture->alttext)) . '" src="' . $picture->thumbURL . '" />';
741
+ $out .= '</a>' . "\n";
742
+ }
743
+ $out .= '</div>' . "\n";
744
+
745
+ $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
746
+
747
+ return $out;
748
+ }
749
+
750
+ /**
751
+ * nggShowAlbumTags() - create a gallery based on the tags
752
+ *
753
+ * @access public
754
+ * @param string $taglist list of tags as csv
755
+ * @return the content
756
+ */
757
+ function nggShowAlbumTags($taglist) {
758
+
759
+ global $wpdb, $nggRewrite;
760
+
761
+ // $_GET from wp_query
762
+ $tag = get_query_var('gallerytag');
763
+ $pageid = get_query_var('pageid');
764
+
765
+ // look for gallerytag variable
766
+ if ( $pageid == get_the_ID() || !is_home() ) {
767
+ if (!empty( $tag )) {
768
+
769
+ // avoid this evil code $sql = 'SELECT name FROM wp_ngg_tags WHERE slug = \'slug\' union select concat(0x7c,user_login,0x7c,user_pass,0x7c) from wp_users WHERE 1 = 1';
770
+ $slug = attribute_escape( $tag );
771
+ $tagname = $wpdb->get_var( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE slug = %s", $slug ) );
772
+ $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') .' ">'.__('Overview', 'nggallery').'</a> | '.$tagname.'</span></div>';
773
+ $out .= nggShowGalleryTags($slug);
774
+ return $out;
775
+
776
+ }
777
+ }
778
+
779
+ // get now the related images
780
+ $picturelist = nggTags::get_album_images($taglist);
781
+
782
+ // go on if not empty
783
+ if ( empty($picturelist) )
784
+ return;
785
+
786
+ // re-structure the object that we can use the standard template
787
+ foreach ($picturelist as $key => $picture) {
788
+ $picturelist[$key]->previewpic = $picture->pid;
789
+ $picturelist[$key]->previewname = $picture->filename;
790
+ $picturelist[$key]->previewurl = get_option ('siteurl') . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
791
+ $picturelist[$key]->counter = $picture->count;
792
+ $picturelist[$key]->title = $picture->name;
793
+ $picturelist[$key]->pagelink = $nggRewrite->get_permalink( array('gallerytag'=>$picture->slug) );
794
+ }
795
+
796
+ //TODO: Add pagination later
797
+ $navigation = '<div class="ngg-clear">&nbsp;</div>';
798
+
799
+ // create the output
800
+ $out = nggGallery::capture ('album-compact', array ('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation) );
801
+
802
+ $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
803
+
804
+ return $out;
805
+ }
806
+
807
+ /**
808
+ * nggShowRelatedImages() - return related images based on category or tags
809
+ *
810
+ * @access public
811
+ * @param string $type could be 'tags' or 'category'
812
+ * @param integer $maxImages of images
813
+ * @return the content
814
+ */
815
+ function nggShowRelatedImages($type = '', $maxImages = 0) {
816
+ $ngg_options = nggGallery::get_option('ngg_options');
817
+
818
+ if ($type == '') {
819
+ $type = $ngg_options['appendType'];
820
+ $maxImages = $ngg_options['maxImages'];
821
+ }
822
+
823
+ $sluglist = array();
824
+
825
+ switch ($type) {
826
+ case 'tags':
827
+ if (function_exists('get_the_tags')) {
828
+ $taglist = get_the_tags();
829
+
830
+ if (is_array($taglist)) {
831
+ foreach ($taglist as $tag) {
832
+ $sluglist[] = $tag->slug;
833
+ }
834
+ }
835
+ }
836
+ break;
837
+
838
+ case 'category':
839
+ $catlist = get_the_category();
840
+
841
+ if (is_array($catlist)) {
842
+ foreach ($catlist as $cat) {
843
+ $sluglist[] = $cat->category_nicename;
844
+ }
845
+ }
846
+ break;
847
+ }
848
+
849
+ $sluglist = implode(',', $sluglist);
850
+ $out = nggShowRelatedGallery($sluglist, $maxImages);
851
+
852
+ return $out;
853
+ }
854
+
855
+ /**
856
+ * Template function for theme authors
857
+ *
858
+ * @access public
859
+ * @param string (optional) $type could be 'tags' or 'category'
860
+ * @param integer (optional) $maxNumbers of images
861
+ * @return void
862
+ */
863
+ function the_related_images($type = 'tags', $maxNumbers = 7) {
864
+ echo nggShowRelatedImages($type, $maxNumbers);
865
+ }
866
+
867
+ /**
868
+ * nggShowRandomRecent($type, $maxImages,$template) - return recent or random images
869
+ *
870
+ * @access public
871
+ * @param string $type 'recent' or 'random'
872
+ * @param integer $maxImages of images
873
+ * @param string $template (optional) name for a template file, look for gallery-$template
874
+ * @return the content
875
+ */
876
+ function nggShowRandomRecent($type, $maxImages, $template = '') {
877
+
878
+ // $_GET from wp_query
879
+ $pid = get_query_var('pid');
880
+ $pageid = get_query_var('pageid');
881
+
882
+ // get now the recent or random images
883
+ if ($type == 'random')
884
+ $picturelist = nggdb::get_random_images($maxImages);
885
+ else
886
+ $picturelist = nggdb::find_last_images(0, $maxImages, true);
887
+
888
+ // look for ImageBrowser if we have a $_GET('pid')
889
+ if ( $pageid == get_the_ID() || !is_home() )
890
+ if (!empty( $pid )) {
891
+ foreach ($picturelist as $picture) {
892
+ $picarray[] = $picture->pid;
893
+ }
894
+ $out = nggCreateImageBrowser($picarray);
895
+ return $out;
896
+ }
897
+
898
+ // go on if not empty
899
+ if ( empty($picturelist) )
900
+ return;
901
+
902
+ // show gallery
903
+ if ( is_array($picturelist) )
904
+ $out = nggCreateGallery($picturelist, false, $template);
905
+
906
+ $out = apply_filters('ngg_show_images_content', $out, $taglist);
907
+
908
+ return $out;
909
+ }
910
+
911
+ /**
912
+ * nggTagCloud() - return a tag cloud based on the wp core tag cloud system
913
+ *
914
+ * @param array $args
915
+ * @param string $template (optional) name for a template file, look for gallery-$template
916
+ * @return the content
917
+ */
918
+ function nggTagCloud($args ='', $template = '') {
919
+ global $nggRewrite;
920
+
921
+ // $_GET from wp_query
922
+ $tag = get_query_var('gallerytag');
923
+ $pageid = get_query_var('pageid');
924
+
925
+ // look for gallerytag variable
926
+ if ( $pageid == get_the_ID() || !is_home() ) {
927
+ if (!empty( $tag )) {
928
+
929
+ $slug = attribute_escape( $tag );
930
+ $out = nggShowGalleryTags( $slug );
931
+ return $out;
932
+ }
933
+ }
934
+
935
+ $defaults = array(
936
+ 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
937
+ 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
938
+ 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
939
+ );
940
+ $args = wp_parse_args( $args, $defaults );
941
+
942
+ $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
943
+
944
+ foreach ($tags as $key => $tag ) {
945
+
946
+ $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
947
+ $tags[ $key ]->id = $tag->term_id;
948
+ }
949
+
950
+ $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';
951
+
952
+ return $out;
953
+ }
954
+ ?>