1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10: $plugin_description = gettext("Prints a paged thumbs navigation on image.php, independent of the album.php’s thumbs.");
11: $plugin_author = "Malte Müller (acrylian)";
12: $option_interface = 'pagedthumbsOptions';
13:
14: 15: 16: 17:
18: class pagedthumbsOptions {
19:
20: function __construct() {
21: if (OFFSET_PATH == 2) {
22: setOptionDefault('pagedthumbs_imagesperpage', '10');
23: setOptionDefault('pagedthumbs_counter', '');
24: gettext($str = '« prev thumbs');
25: setOptionDefault('pagedthumbs_prevtext', getAllTranslations($str));
26: gettext($str = 'next thumbs »');
27: setOptionDefault('pagedthumbs_nexttext', getAllTranslations($str));
28: setOptionDefault('pagedthumbs_width', '50');
29: setOptionDefault('pagedthumbs_height', '50');
30: setOptionDefault('pagedthumbs_crop', '1');
31: setOptionDefault('pagedthumbs_placeholders', '');
32: setOptionDefault('pagedthumbs_pagelist', '');
33: setOptionDefault('pagedthumbs_pagelistprevnext', '');
34: setOptionDefault('pagedthumbs_pagelistlength', '6');
35: if (class_exists('cacheManager')) {
36: cacheManager::deleteThemeCacheSizes('paged_thumbs_nav');
37: cacheManager::addThemeCacheSize('paged_thumbs_nav', NULL, getOption('pagedthumbs_width'), getOption('pagedthumbs_height'), NULL, NULL, NULL, NULL, true, NULL, NULL, NULL);
38: }
39: }
40: }
41:
42: function getOptionsSupported() {
43: return array(gettext('Thumbs per page') => array('key' => 'pagedthumbs_imagesperpage', 'type' => OPTION_TYPE_TEXTBOX,
44: 'desc' => gettext("Controls the number of images on a page. You might need to change this after switching themes to make it look better.")),
45: gettext('Counter') => array('key' => 'pagedthumbs_counter', 'type' => OPTION_TYPE_CHECKBOX,
46: 'desc' => gettext("If you want to show the counter “x - y of z images”.")),
47: gettext('Prevtext') => array('key' => 'pagedthumbs_prevtext', 'type' => OPTION_TYPE_TEXTBOX,
48: 'desc' => gettext("The text for the previous thumbs."), 'multilingual' => 1),
49: gettext('Nexttext') => array('key' => 'pagedthumbs_nexttext', 'type' => OPTION_TYPE_TEXTBOX,
50: 'desc' => gettext("The text for the next thumbs."), 'multilingual' => 1),
51: gettext('Crop width') => array('key' => 'pagedthumbs_width', 'type' => OPTION_TYPE_TEXTBOX,
52: 'desc' => gettext("The thumb crop width is the maximum width when height is the shortest side")),
53: gettext('Crop height') => array('key' => 'pagedthumbs_height', 'type' => OPTION_TYPE_TEXTBOX,
54: 'desc' => gettext("The thumb crop height is the maximum height when width is the shortest side")),
55: gettext('Crop') => array('key' => 'pagedthumbs_crop', 'type' => OPTION_TYPE_CHECKBOX,
56: 'desc' => gettext("If checked the thumbnail will be a centered portion of the image with the given width and height after being resized to thumb size (by shortest side). Otherwise, it will be the full image resized to thumb size (by shortest side).")),
57: gettext('Placeholders') => array('key' => 'pagedthumbs_placeholders', 'type' => OPTION_TYPE_CHECKBOX,
58: 'desc' => gettext("if you want to use placeholder for layout reasons to fill up the thumbs if the number of thumbs does not match images per page. Recommended only for cropped thumbs.")),
59: gettext('Page list') => array('key' => 'pagedthumbs_pagelist', 'type' => OPTION_TYPE_CHECKBOX,
60: 'desc' => gettext("If you want the list of the pages to be shown.")),
61: gettext('Pages list prev and next links') => array('key' => 'pagedthumbs_pagelistprevnext', 'type' => OPTION_TYPE_CHECKBOX,
62: 'desc' => gettext("If you want to show previous and next thumb page links with the page list.")),
63: gettext('Pages list length') => array('key' => 'pagedthumbs_pagelistlength', 'type' => OPTION_TYPE_CHECKBOX,
64: 'desc' => gettext("The number of links for the page list."))
65: );
66: }
67:
68: }
69:
70: class pagedThumbsNav {
71:
72: var $imagesperpage;
73: var $counter;
74: var $prev;
75: var $next;
76: var $width;
77: var $height;
78: var $crop;
79: var $placeholders;
80: var $showpagelist;
81: var $pagelistprevnext;
82: var $pagelistlength;
83: var $totalimages;
84: var $totalpages;
85: var $images;
86: var $currentpage;
87: var $currentfloor;
88: var $currentciel;
89: var $currentimgnr;
90: var $searchimages;
91: var $prevpageimage;
92: var $nextpageimage;
93:
94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
109: function __construct($imagesperpage = 0, $counter = false, $prev = '', $next = '', $width = NULL, $height = NULL, $crop = NULL, $placeholders = NULL, $showpagelist = false, $pagelistprevnext = false, $pagelistlength = 6) {
110: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery;
111: if (is_null($crop)) {
112: $this->crop = getOption("pagedthumbs_crop");
113: } else {
114: $this->crop = $crop;
115: }
116: if (empty($imagesperpage)) {
117: $this->imagesperpage = getOption("pagedthumbs_imagesperpage");
118: } else {
119: $this->imagesperpage = $imagesperpage;
120: }
121: if (is_null($width)) {
122: $this->width = getOption("pagedthumbs_width");
123: } else {
124: $this->width = $width;
125: }
126: if (is_null($height)) {
127: $this->height = getOption("pagedthumbs_height");
128: } else {
129: $this->height = $height;
130: }
131: if (empty($prev)) {
132: $this->prev = get_language_string(getOption("pagedthumbs_prevtext"));
133: } else {
134: $this->prev = html_decode($prev);
135: }
136: if (empty($next)) {
137: $this->next = get_language_string(getOption("pagedthumbs_nexttext"));
138: } else {
139: $this->next = html_decode($next);
140: }
141: if (empty($counter)) {
142: $this->counter = getOption("pagedthumbs_counter");
143: }
144: if (is_null($placeholders)) {
145: $this->placeholders = getOption("pagedthumbs_placeholders");
146: } else {
147: $this->placeholders = $placeholders;
148: }
149: if (is_null($showpagelist)) {
150: $this->showpagelist = getOption("pagedthumbs_pagelist");
151: } else {
152: $this->showpagelist = $showpagelist;
153: }
154: if (empty($pagelistlength)) {
155: $this->pagelistlength = getOption("pagedthumbs_pagelistlength");
156: } else {
157: $this->pagelistlength = $pagelistlength;
158: }
159: if (is_null($pagelistprevnext)) {
160: $this->pagelistprevnext = getOption("pagedthumbs_pagelistprevnext");
161: } else {
162: $this->pagelistprevnext = $pagelistprevnext;
163: }
164:
165: if (in_context(ZP_SEARCH_LINKED)) {
166: if ($_zp_current_search->getNumImages() === 0) {
167: $this->searchimages = false;
168: } else {
169: $this->searchimages = true;
170: }
171: } else {
172: $this->searchimages = false;
173: }
174:
175: if (in_context(ZP_SEARCH_LINKED) && $this->searchimages) {
176: $this->images = $_zp_current_search->getImages();
177: } else {
178: $this->images = $_zp_current_album->getImages();
179: }
180: $this->currentimgnr = imageNumber();
181: $this->totalimages = count($this->images);
182: $this->totalpages = ceil($this->totalimages / $this->imagesperpage);
183: $this->currentpage = floor(($this->currentimgnr - 1) / $this->imagesperpage) + 1;
184: $this->currentciel = $this->currentpage * $this->imagesperpage - 1;
185: $this->currentfloor = $this->currentciel - $this->imagesperpage + 1;
186: }
187:
188:
189:
190: 191: 192: 193:
194: function getPrevThumbsLink() {
195: global $_zp_current_album;
196: $this->prevpageimage = "";
197: if ($this->totalpages > 1) {
198: $prevpageimagenr = ($this->currentpage * $this->imagesperpage) - ($this->imagesperpage + 1);
199: if ($this->currentpage > 1) {
200: if (is_array($this->images[$prevpageimagenr])) {
201: if (in_context(ZP_SEARCH_LINKED)) {
202: $albumobj = newAlbum($this->images[$prevpageimagenr]['folder']);
203: } else {
204: $albumobj = $_zp_current_album;
205: }
206: $this->prevpageimage = newImage($albumobj, $this->images[$prevpageimagenr]['filename']);
207: } else {
208: $this->prevpageimage = newImage($_zp_current_album, $this->images[$prevpageimagenr]);
209: }
210: return $this->prevpageimage->getLink();
211: }
212: }
213: }
214:
215: 216: 217: 218:
219: function printPrevThumbsLink() {
220: if ($this->currentpage == 1) {
221: echo "<div id=\"pagedthumbsnav-prevdisabled\">" . html_encode($this->prev);
222: } else {
223: echo "<div id=\"pagedthumbsnav-prev\">\n";
224: }
225:
226: echo "<a href=\"" . html_encode($this->getPrevThumbsLink()) . "\" title=\"" . gettext("previous thumbs") . "\">" . html_encode($this->prev) . "</a>\n";
227: echo "</div>";
228: }
229:
230: 231: 232: 233:
234: function getThumbs() {
235: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery;
236: $curimages = array_slice($this->images, $this->currentfloor, $this->imagesperpage);
237: $thumbs = array();
238: foreach ($curimages as $item) {
239: if (is_array($item)) {
240: if (in_context(ZP_SEARCH_LINKED)) {
241: $albumobj = newAlbum($item['folder']);
242: } else {
243: $albumobj = $_zp_current_album;
244: }
245: $thumbs[] = newImage($albumobj, $item['filename']);
246: } else {
247: $thumbs[] = newImage($_zp_current_album, $item);
248: }
249: }
250: return $thumbs;
251: }
252:
253: 254: 255: 256:
257: function printThumbs() {
258: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery;
259: echo "<div id='pagedthumbsimages'>";
260: $thumbs = $this->getThumbs();
261:
262: $number = 0;
263: foreach ($thumbs as $image) {
264: if ($image->getID() == $_zp_current_image->getID()) {
265: $css = " id='pagedthumbsnav-active' ";
266: } else {
267: $css = "";
268: }
269: echo "<a $css href=\"" . html_encode($image->getLink()) . "\" title=\"" . html_encode(getBare($image->getTitle())) . "\">";
270:
271: if ($this->crop) {
272: $html = "<img src='" . html_encode(pathurlencode($image->getCustomImage(null, $this->width, $this->height, $this->width, $this->height, null, null, true))) . "' alt=\"" . html_encode(getBare($image->getTitle())) . "\" width='" . $this->width . "' height='" . $this->height . "' />";
273: } else {
274: $maxwidth = $this->width;
275: $maxheight = $this->height;
276: getMaxSpaceContainer($maxwidth, $maxheight, $image, true);
277: $html = "<img src=\"" . html_encode(pathurlencode($image->getCustomImage(NULL, $maxwidth, $maxheight, NULL, NULL, NULL, NULL, true))) . "\" alt=\"" . html_encode(getBare($image->getTitle())) . "\" />";
278: }
279: echo zp_apply_filter('custom_image_html', $html, true);
280: echo "</a>\n";
281: $number++;
282: }
283: if ($this->placeholders) {
284: if ($number != $this->imagesperpage) {
285: $placeholdernr = $this->imagesperpage - ($number);
286: for ($nr2 = 1; $nr2 <= $placeholdernr; $nr2++) {
287: echo "<span class=\"placeholder\" style=\"width:" . $this->width . "px;height:" . $this->height . "px\"></span>";
288: }
289: }
290: }
291: echo "</div>";
292: }
293:
294: 295: 296: 297:
298: function getNextThumbsLink() {
299: global $_zp_current_album;
300: if ($this->totalpages > 1) {
301: if ($this->currentpage < $this->totalpages) {
302: $nextpageimagenr = $this->currentpage * $this->imagesperpage;
303: if (is_array($this->images[$nextpageimagenr])) {
304: if (in_context(ZP_SEARCH_LINKED)) {
305: $albumobj = newAlbum($this->images[$nextpageimagenr]['folder']);
306: } else {
307: $albumobj = $_zp_current_album;
308: }
309: $this->nextpageimage = newImage($albumobj, $this->images[$nextpageimagenr]['filename']);
310: } else {
311: $this->nextpageimage = newImage($_zp_current_album, $this->images[$nextpageimagenr]);
312: }
313: return $this->nextpageimage->getLink();
314: }
315: }
316: }
317:
318: 319: 320: 321:
322: function printNextThumbsLink() {
323: if ($this->currentpage == $this->totalpages) {
324: echo "<div id=\"pagedthumbsnav-nextdisabled\">" . html_encode($this->next);
325: } else {
326: echo "<div id=\"pagedthumbsnav-next\">\n";
327: }
328: echo "<a href=\"" . html_encode($this->getNextThumbsLink()) . "\" title=\"" . gettext("next thumbs") . "\">" . html_encode($this->next) . "</a>\n";
329: echo "</div>\n";
330: }
331:
332: 333: 334: 335:
336: function getCounter() {
337: $fromimage = $this->currentfloor + 1;
338: if ($this->totalimages < $this->currentciel) {
339: $toimage = $this->totalimages;
340: } else {
341: $toimage = $this->currentciel + 1;
342: }
343: $counter = array("fromimage" => $fromimage, "toimage" => $toimage);
344: return $counter;
345: }
346:
347: 348: 349: 350:
351: function printCounter() {
352: if ($this->counter) {
353: $counter = $this->getCounter();
354: echo "<p id=\"pagedthumbsnav-counter\">" . sprintf(gettext('Images %1$u-%2$u of %3$u (%4$u/%5$u)'), $counter["fromimage"], $counter["toimage"], $this->totalimages, $this->currentpage, $this->totalpages) . "</p>\n";
355: }
356: }
357:
358: 359: 360: 361:
362: function printPagesList() {
363: if ($this->showpagelist AND $this->totalpages > 1) {
364:
365:
366: $navlen = sanitize_numeric($this->pagelistlength);
367: $extralinks = 4;
368:
369: $len = floor(($navlen - $extralinks) / 2);
370: $j = max(round($extralinks / 2), min($this->currentpage - $len - (2 - round($extralinks / 2)), $this->totalpages - $navlen + $extralinks - 1));
371: $ilim = min($this->totalpages, max($navlen - round($extralinks / 2), $this->currentpage + floor($len)));
372: $k1 = round(($j - 2) / 2) + 1;
373: $k2 = $this->totalpages - round(($this->totalpages - $ilim) / 2);
374:
375: echo "<ul id=\"pagedthumbsnav-pagelist\">\n";
376:
377: if ($this->pagelistprevnext AND $this->totalpages > 1 AND is_object($this->prevpageimage)) {
378: echo "<li><a href=\"" . html_encode($this->prevpageimage->getLink()) . "\" title=\"" . gettext("previous thumbs") . "\">" . html_encode($this->prev) . "</a></li>\n";
379: }
380:
381: $this->printPagedThumbsNavPagelink($this->imagesperpage, $this->searchimages, $this->images, $this->currentpage, 1, 1);
382:
383:
384: if ($j > 2) {
385: $this->printPagedThumbsNavPagelink($this->imagesperpage, $this->searchimages, $this->images, $this->currentpage, $k1, "...");
386: }
387:
388: for ($i = $j; $i <= $ilim; $i++) {
389: $this->printPagedThumbsNavPagelink($this->imagesperpage, $this->searchimages, $this->images, $this->currentpage, $i, $i);
390: }
391:
392: if ($i < $this->totalpages) {
393: $this->printPagedThumbsNavPagelink($this->imagesperpage, $this->searchimages, $this->images, $this->currentpage, $i, "...");
394: }
395:
396: if ($i <= $this->totalpages) {
397: $this->printPagedThumbsNavPagelink($this->imagesperpage, $this->searchimages, $this->images, $this->currentpage, $this->totalpages, $this->totalpages);
398: }
399:
400: if ($this->pagelistprevnext AND $this->totalpages > 1 AND is_object($this->nextpageimage)) {
401: echo "<li><a href=\"" . html_encode($this->nextpageimage->getLink()) . "\" title=\"" . gettext("next thumbs") . "\">" . html_encode($this->next) . "</a></li>\n";
402: }
403: echo "</ul>\n";
404: }
405: }
406:
407: 408: 409: 410: 411: 412: 413: 414: 415:
416:
417: function printPagedThumbsNavPagelink($i, $linktext) {
418: global $_zp_gallery, $_zp_current_album;
419: $i = $i;
420: $linktex = $linktext;
421: $imagenr = ($i * $this->imagesperpage) - ($this->imagesperpage);
422: if (is_array($this->images[$imagenr])) {
423: $albumobj = newAlbum($this->images[$imagenr]['folder']);
424: $pageimage = newImage($_zp_current_album, $this->images[$imagenr]['filename']);
425: } else {
426: $pageimage = newImage($_zp_current_album, $this->images[$imagenr]);
427: }
428: if ($this->currentpage == $i) {
429: echo "<li class=\"pagedthumbsnav-pagelistactive\">" . html_encode($linktext) . "</a>\n";
430: } else {
431: echo "<li><a href=\"" . html_encode($pageimage->getLink()) . "\" title=\"Seite " . $i . "\">" . html_encode($linktext) . "</a></li>\n";
432: }
433: }
434:
435: }
436:
437:
438:
439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484:
485: function printPagedThumbsNav($imagesperpage = '', $counter = false, $prev = '', $next = '', $width = NULL, $height = NULL, $crop = NULL, $placeholders = NULL, $showpagelist = false, $pagelistprevnext = false, $pagelistlength = 6) {
486: $pagedthumbsobj = new pagedThumbsNav($imagesperpage, $counter, $prev, $next, $width, $height, $crop, $placeholders, $showpagelist, $pagelistprevnext, $pagelistlength);
487: echo "<div id=\"pagedthumbsnav\">\n";
488:
489:
490: $pagedthumbsobj->printPrevThumbsLink();
491: $pagedthumbsobj->printThumbs();
492: $pagedthumbsobj->printNextThumbsLink();
493: $pagedthumbsobj->printCounter();
494: $pagedthumbsobj->printPagesList();
495: echo "</div>\n";
496: }
497:
498: ?>