1: <?php
2: 3: 4: 5:
6:
7:
8: require_once(dirname(__FILE__) . '/functions.php');
9: if (!defined('SEO_FULLWEBPATH')) {
10: define('SEO_FULLWEBPATH', FULLWEBPATH);
11: define('SEO_WEBPATH', WEBPATH);
12: }
13:
14:
15:
16:
17:
18:
19:
20:
21: 22: 23:
24: function getVersion() {
25: return ZENPHOTO_VERSION . ' [' . ZENPHOTO_RELEASE . ']';
26: }
27:
28: 29: 30:
31: function printVersion() {
32: echo getVersion();
33: }
34:
35: 36: 37:
38: function printZenJavascripts() {
39: global $_zp_current_album;
40: ?>
41: <script type="text/javascript" src="<?php echo WEBPATH . "/" . ZENFOLDER; ?>/js/jquery.js"></script>
42: <script type="text/javascript" src="<?php echo WEBPATH . "/" . ZENFOLDER; ?>/js/zenphoto.js"></script>
43: <?php
44: if (zp_loggedin()) {
45: ?>
46: <script type="text/javascript">
47:
48: var deleteAlbum1 = "<?php echo gettext("Are you sure you want to delete this entire album?"); ?>";
49: var deleteAlbum2 = "<?php echo gettext("Are you Absolutely Positively sure you want to delete the album? THIS CANNOT BE UNDONE!"); ?>";
50: var deleteImage = "<?php echo gettext("Are you sure you want to delete the image? THIS CANNOT BE UNDONE!"); ?>";
51: var deleteArticle = "<?php echo gettext("Are you sure you want to delete this article? THIS CANNOT BE UNDONE!"); ?>";
52: var deletePage = "<?php echo gettext("Are you sure you want to delete this page? THIS CANNOT BE UNDONE!"); ?>";
53:
54: </script>
55: <link rel="stylesheet" href="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/admintoolbox.css" type="text/css" />
56: <?php
57: }
58: }
59:
60: 61: 62: 63:
64: function adminToolbox() {
65: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery_page, $_zp_gallery, $_zp_current_admin_obj, $_zp_loggedin;
66: if (zp_loggedin()) {
67: $zf = FULLWEBPATH . "/" . ZENFOLDER;
68: $page = getCurrentPage();
69: ob_start();
70: ?>
71: <script type="text/javascript">
72:
73: function newAlbum(folder, albumtab) {
74: var album = prompt('<?php echo gettext('New album name?'); ?>', '<?php echo gettext('new album'); ?>');
75: if (album) {
76: launchScript('<?php echo $zf; ?>/admin-edit.php', ['action=newalbum', 'album=' + encodeURIComponent(folder), 'name=' + encodeURIComponent(album), 'albumtab=' + albumtab, 'XSRFToken=<?php echo getXSRFToken('newalbum'); ?>']);
77: }
78: }
79:
80: </script>
81: <div id="zp__admin_module">
82: <div id="zp__admin_info">
83: <span class="zp_logo">ZP</span>
84: <span class="zp_user"> <?php echo $_zp_current_admin_obj->getUser(); ?></span>
85: </div>
86: <button type="button" id="zp__admin_link" onclick="javascript:toggle('zp__admin_data');">
87: <?php echo gettext('Admin'); ?>
88: </button>
89: <div id="zp__admin_data" style="display: none;">
90:
91: <ul>
92: <?php
93: $outputA = ob_get_contents();
94: ob_end_clean();
95: ob_start();
96:
97: if (zp_loggedin(OVERVIEW_RIGHTS)) {
98: ?>
99: <li>
100: <?php printLinkHTML($zf . '/admin.php', gettext("Overview"), NULL, NULL, NULL); ?>
101: </li>
102: <?php
103: }
104: if (zp_loggedin(UPLOAD_RIGHTS | FILES_RIGHTS | THEMES_RIGHTS)) {
105: ?>
106: <li>
107: <?php printLinkHTML($zf . '/admin-upload.php', gettext("Upload"), NULL, NULL, NULL); ?>
108: </li>
109: <?php
110: }
111: if (zp_loggedin(ALBUM_RIGHTS)) {
112: ?>
113: <li>
114: <?php printLinkHTML($zf . '/admin-edit.php', gettext("Albums"), NULL, NULL, NULL); ?>
115: </li>
116: <?php
117: }
118: zp_apply_filter('admin_toolbox_global', $zf);
119:
120: if (zp_loggedin(TAGS_RIGHTS)) {
121: ?>
122: <li>
123: <?php printLinkHTML($zf . '/admin-tags.php', gettext("Tags"), NULL, NULL, NULL); ?>
124: </li>
125: <?php
126: }
127: if (zp_loggedin(USER_RIGHTS)) {
128: ?>
129: <li>
130: <?php printLinkHTML($zf . '/admin-users.php', gettext("Users"), NULL, NULL, NULL); ?>
131: </li>
132: <?php
133: }
134: if (zp_loggedin(OPTIONS_RIGHTS)) {
135: ?>
136: <li>
137: <?php printLinkHTML($zf . '/admin-options.php?tab=general', gettext("Options"), NULL, NULL, NULL); ?>
138: </li>
139: <?php
140: }
141: if (zp_loggedin(THEMES_RIGHTS)) {
142: ?>
143: <li>
144: <?php printLinkHTML($zf . '/admin-themes.php', gettext("Themes"), NULL, NULL, NULL); ?>
145: </li>
146: <?php
147: }
148: if (zp_loggedin(ADMIN_RIGHTS)) {
149: ?>
150: <li>
151: <?php printLinkHTML($zf . '/admin-plugins.php', gettext("Plugins"), NULL, NULL, NULL); ?>
152: </li>
153: <li>
154: <?php printLinkHTML($zf . '/admin-logs.php', gettext("Logs"), NULL, NULL, NULL); ?>
155: </li>
156: <?php
157: }
158:
159: $gal = getOption('custom_index_page');
160: if (empty($gal) || !file_exists(SERVERPATH . '/' . THEMEFOLDER . '/' . $_zp_gallery->getCurrentTheme() . '/' . internalToFilesystem($gal) . '.php')) {
161: $gal = 'index.php';
162: } else {
163: $gal .= '.php';
164: }
165: $inImage = false;
166: switch ($_zp_gallery_page) {
167: case 'index.php':
168: case $gal:
169:
170: if (zp_loggedin(ADMIN_RIGHTS)) {
171: ?>
172: <li>
173: <?php printLinkHTML($zf . '/admin-edit.php?page=edit', gettext("Sort Gallery"), NULL, NULL, NULL); ?>
174: </li>
175: <?php
176: }
177: if (zp_loggedin(UPLOAD_RIGHTS)) {
178:
179: if (GALLERY_SESSION) {
180: ?>
181: <li>
182: <a href="javascript:newAlbum('',true);"><?php echo gettext("New Album"); ?></a>
183: </li>
184: <?php
185: }
186: }
187: if ($_zp_gallery_page == 'index.php') {
188: $redirect = '';
189: } else {
190: $redirect = "&p=" . urlencode(stripSuffix($_zp_gallery_page));
191: }
192: if ($page > 1) {
193: $redirect .= "&page=$page";
194: }
195: zp_apply_filter('admin_toolbox_gallery', $zf);
196: break;
197: case 'image.php':
198: $inImage = true;
199: case 'album.php':
200:
201: $albumname = $_zp_current_album->name;
202: if ($_zp_current_album->isMyItem(ALBUM_RIGHTS)) {
203:
204: ?>
205: <li>
206: <?php printLinkHTML($zf . '/admin-edit.php?page=edit&album=' . pathurlencode($_zp_current_album->name), gettext('Edit album'), NULL, NULL, NULL); ?>
207: </li>
208: <?php
209: if (!$_zp_current_album->isDynamic()) {
210: if ($_zp_current_album->getNumAlbums()) {
211: ?>
212: <li>
213: <?php printLinkHTML($zf . '/admin-edit.php?page=edit&album=' . pathurlencode($albumname) . '&tab=subalbuminfo', gettext("Sort subalbums"), NULL, NULL, NULL); ?>
214: </li>
215: <?php
216: }
217: if ($_zp_current_album->getNumImages() > 0) {
218: ?>
219: <li>
220: <?php printLinkHTML($zf . '/admin-albumsort.php?page=edit&album=' . pathurlencode($albumname) . '&tab=sort', gettext("Sort images"), NULL, NULL, NULL); ?>
221: </li>
222: <?php
223: }
224: }
225:
226: if (GALLERY_SESSION) {
227: ?>
228: <li>
229: <a href="javascript:confirmDeleteAlbum('<?php echo $zf; ?>/admin-edit.php?page=edit&action=deletealbum&album=<?php echo urlencode(pathurlencode($albumname)) ?>&XSRFToken=<?php echo getXSRFToken('delete'); ?>');"
230: title="<?php echo gettext('Delete the album'); ?>"><?php echo gettext('Delete album'); ?></a>
231: </li>
232: <?php
233: }
234: }
235: if ($_zp_current_album->isMyItem(UPLOAD_RIGHTS) && !$_zp_current_album->isDynamic()) {
236:
237: ?>
238: <li>
239: <?php printLinkHTML($zf . '/admin-upload.php?album=' . pathurlencode($albumname), gettext("Upload Here"), NULL, NULL, NULL); ?>
240: </li>
241: <?php
242: if (GALLERY_SESSION) {
243: ?>
244: <li>
245: <a href="javascript:newAlbum('<?php echo pathurlencode($albumname); ?>',true);"><?php echo gettext("New Album Here"); ?></a>
246: </li>
247: <?php
248: }
249: }
250: zp_apply_filter('admin_toolbox_album', $albumname, $zf);
251: if ($inImage) {
252:
253: $imagename = $_zp_current_image->filename;
254: if (!$_zp_current_album->isDynamic()) {
255: if ($_zp_current_album->isMyItem(ALBUM_RIGHTS)) {
256:
257: if (GALLERY_SESSION) {
258: ?>
259: <li>
260: <a href="javascript:confirmDelete('<?php echo $zf; ?>/admin-edit.php?page=edit&action=deleteimage&album=<?php echo urlencode(pathurlencode($albumname)); ?>&image=<?php echo urlencode($imagename); ?>&XSRFToken=<?php echo getXSRFToken('delete'); ?>',deleteImage);"
261: title="<?php echo gettext("Delete the image"); ?>"><?php echo gettext("Delete image"); ?></a>
262: </li>
263: <?php
264: }
265: ?>
266: <li>
267: <a href="<?php echo $zf; ?>/admin-edit.php?page=edit&album=<?php echo pathurlencode($albumname); ?>&singleimage=<?php echo urlencode($imagename); ?>&tab=imageinfo&nopagination"
268: title="<?php echo gettext('Edit image'); ?>"><?php echo gettext('Edit image'); ?></a>
269: </li>
270: <?php
271: }
272:
273: zp_apply_filter('admin_toolbox_image', $albumname, $imagename, $zf);
274: }
275: $redirect = "&album=" . html_encode(pathurlencode($albumname)) . "&image=" . urlencode($imagename);
276: } else {
277:
278: $redirect = "&album=" . html_encode(pathurlencode($albumname));
279: if ($page > 1) {
280: $redirect .= "&page=$page";
281: }
282: }
283: break;
284: case 'search.php':
285: $words = $_zp_current_search->getSearchWords();
286: if (!empty($words)) {
287:
288: if (zp_loggedin(UPLOAD_RIGHTS)) {
289: $link = $zf . '/admin-dynamic-album.php?' . substr($_zp_current_search->getSearchParams(), 1);
290:
291: ?>
292: <li>
293: <a href="<?php echo $link; ?>" title="<?php echo gettext('Create an album from the search'); ?>" ><?php echo gettext('Create Album'); ?></a>
294: </li>
295: <?php
296: }
297: zp_apply_filter('admin_toolbox_search', $zf);
298: }
299: $redirect = "&p=search" . $_zp_current_search->getSearchParams() . "&page=$page";
300: break;
301: default:
302:
303: $gal = stripSuffix($_zp_gallery_page);
304: $redirect = "&p=" . urlencode($gal);
305: if ($page > 1) {
306: $redirect .= "&page=$page";
307: }
308: $redirect = zp_apply_filter('admin_toolbox_' . $gal, $redirect, $zf);
309: break;
310: }
311: $redirect = zp_apply_filter('admin_toolbox_close', $redirect, $zf);
312: if ($_zp_current_admin_obj->logout_link) {
313:
314: $sec = (int) ((SERVER_PROTOCOL == 'https') & true);
315: $link = SEO_FULLWEBPATH . '/index.php?logout=' . $sec . $redirect;
316: ?>
317: <li>
318: <a href="<?php echo $link; ?>"><?php echo gettext("Logout"); ?> </a>
319: </li>
320: <?php
321: }
322: $outputB = ob_get_contents();
323: ob_end_clean();
324: if ($outputB) {
325: echo $outputA . $outputB;
326: ?>
327: </ul>
328: </div>
329: </div>
330: <?php
331: }
332: }
333: }
334:
335:
336:
337:
338: 339: 340: 341: 342:
343: function getGalleryTitle() {
344: global $_zp_gallery;
345: return $_zp_gallery->getTitle();
346: }
347:
348: 349: 350: 351: 352:
353: function getBareGalleryTitle() {
354: return getBare(getGalleryTitle());
355: }
356:
357: 358: 359:
360: function printGalleryTitle() {
361: echo html_encodeTagged(getGalleryTitle());
362: }
363:
364: function printBareGalleryTitle() {
365: echo html_encode(getBareGalleryTitle());
366: }
367:
368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378:
379: function getHeadTitle($separator = ' | ', $listparentalbums = true, $listparentpages = true) {
380: global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_gallery_page, $_zp_current_category, $_zp_page, $_myFavorites;
381: $mainsitetitle = html_encode(getBare(getMainSiteName()));
382: $separator = html_encode($separator);
383: if ($mainsitetitle) {
384: $mainsitetitle = $separator . $mainsitetitle;
385: }
386: $gallerytitle = html_encode(getBareGalleryTitle());
387: if ($_zp_page > 1) {
388: $pagenumber = ' (' . $_zp_page . ')';
389: } else {
390: $pagenumber = '';
391: }
392: switch ($_zp_gallery_page) {
393: case 'index.php':
394: return $gallerytitle . $mainsitetitle . $pagenumber;
395: break;
396: case 'album.php':
397: case 'image.php':
398: if ($listparentalbums) {
399: $parents = getParentAlbums();
400: $parentalbums = '';
401: if (count($parents) != 0) {
402: $parents = array_reverse($parents);
403: foreach ($parents as $parent) {
404: $parentalbums .= html_encode(getBare($parent->getTitle())) . $separator;
405: }
406: }
407: } else {
408: $parentalbums = '';
409: }
410: $albumtitle = html_encode(getBareAlbumTitle()) . $pagenumber . $separator . $parentalbums . $gallerytitle . $mainsitetitle;
411: switch ($_zp_gallery_page) {
412: case 'album.php':
413: return $albumtitle;
414: break;
415: case 'image.php':
416: return html_encode(getBareImageTitle()) . $separator . $albumtitle;
417: break;
418: }
419: break;
420: case 'news.php':
421: if (function_exists("is_NewsArticle")) {
422: if (is_NewsArticle()) {
423: return html_encode(getBareNewsTitle()) . $pagenumber . $separator . gettext('News') . $separator . $gallerytitle . $mainsitetitle;
424: } else if (is_NewsCategory()) {
425: return html_encode(getBare($_zp_current_category->getTitle())) . $pagenumber . $separator . gettext('News') . $separator . $gallerytitle . $mainsitetitle;
426: } else {
427: return gettext('News') . $pagenumber . $separator . $gallerytitle . $mainsitetitle;
428: }
429: }
430: break;
431: case 'pages.php':
432: if ($listparentpages) {
433: $parents = $_zp_current_zenpage_page->getParents();
434: $parentpages = '';
435: if (count($parents) != 0) {
436: $parents = array_reverse($parents);
437: foreach ($parents as $parent) {
438: $obj = new ZenpagePage($parent);
439: $parentpages .= html_encode(getBare($obj->getTitle())) . $separator;
440: }
441: }
442: } else {
443: $parentpages = '';
444: }
445: return html_encode(getBarePageTitle()) . $pagenumber . $separator . $parentpages . $gallerytitle . $mainsitetitle;
446: break;
447: case '404.php':
448: return gettext('Object not found') . $separator . $gallerytitle . $mainsitetitle;
449: break;
450: default:
451: $custompage = stripSuffix($_zp_gallery_page);
452: $standard = array('contact' => gettext('Contact'), 'register' => gettext('Register'), 'search' => gettext('Search'), 'archive' => gettext('Archive view'), 'password' => gettext('Password required'));
453: if (is_object($_myFavorites)) {
454: $standard['favorites'] = gettext('My favorites');
455: }
456: if (array_key_exists($custompage, $standard)) {
457: return $standard[$custompage] . $pagenumber . $separator . $gallerytitle . $mainsitetitle;
458: } else {
459: return $custompage . $pagenumber . $separator . $gallerytitle . $mainsitetitle;
460: }
461: break;
462: }
463: }
464:
465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475:
476: function printHeadTitle($separator = ' | ', $listparentalbums = true, $listparentpages = true) {
477: echo '<title>' . getHeadTitle($separator, $listparentalbums, $listparentpages) . '</title>';
478: }
479:
480: 481: 482: 483: 484:
485: function getGalleryDesc() {
486: global $_zp_gallery;
487: return $_zp_gallery->getDesc();
488: }
489:
490: 491: 492: 493: 494:
495: function getBareGalleryDesc() {
496: return getBare(getGalleryDesc());
497: }
498:
499: 500: 501:
502: function printGalleryDesc() {
503: echo html_encodeTagged(getGalleryDesc());
504: }
505:
506: function printBareGalleryDesc() {
507: echo html_encode(getBareGalleryDesc());
508: }
509:
510: 511: 512: 513: 514: 515:
516: function getMainSiteName() {
517: global $_zp_gallery;
518: return $_zp_gallery->getWebsiteTitle();
519: }
520:
521: 522: 523: 524: 525: 526:
527: function getMainSiteURL() {
528: global $_zp_gallery;
529: return $_zp_gallery->getWebsiteURL();
530: }
531:
532: 533: 534: 535: 536:
537: function getGalleryIndexURL() {
538: global $_zp_current_album, $_zp_gallery_page;
539: if (func_num_args() !== 0) {
540: internal_deprecations::getGalleryIndexURL();
541: }
542: $custom_index = getOption('custom_index_page');
543: if ($custom_index) {
544: $link = rewrite_path('/' . _PAGE_ . '/' . $custom_index . '/', "/index.php?p=" . $custom_index);
545: } else {
546: $link = WEBPATH . "/";
547: }
548: if (in_context(ZP_ALBUM) && $_zp_gallery_page != 'index.php') {
549: $album = getUrAlbum($_zp_current_album);
550: if (($page = $album->getGalleryPage()) > 1) {
551: if ($custom_index) {
552: $link = rewrite_path('/' . _PAGE_ . '/' . $custom_index . '/' . $page . '/', "/index.php?p=" . $custom_index . "&page=" . $page);
553: } else {
554: $link = rewrite_path('/' . _PAGE_ . '/' . $page . '/', "/index.php?" . "page=" . $page);
555: }
556: }
557: }
558: return zp_apply_filter('getLink', $link, 'index.php', NULL);
559: }
560:
561: 562: 563: 564: 565: 566: 567: 568: 569:
570: function printGalleryIndexURL($after = NULL, $text = NULL, $printHomeURL = true) {
571: global $_zp_gallery_page;
572: if(is_null($text)) {
573: $text = gettext('Gallery');
574: }
575: $customgalleryindex = getOption('custom_index_page');
576: if($customgalleryindex && $printHomeURL) {
577: printSiteHomeURL($after);
578: }
579: if ($_zp_gallery_page == getOption('custom_index_page').'.php') {
580: $after = NULL;
581: }
582: if(!$customgalleryindex || ($customgalleryindex && in_array($_zp_gallery_page, array('image.php', 'album.php', 'gallery.php')))) {
583: printLinkHTML(getGalleryIndexURL(), $text, $text, 'galleryindexurl'); echo $after;
584: }
585: }
586:
587:
588: 589: 590: 591: 592: 593: 594: 595:
596: function getSiteHomeURL() {
597: return WEBPATH . '/';
598: }
599:
600: 601: 602: 603: 604: 605: 606:
607: function printSiteHomeURL($after = NULL, $text = NULL) {
608: global $_zp_gallery_page;
609: if ($_zp_gallery_page == 'index.php') {
610: $after = '';
611: }
612: if (is_null($text)) {
613: $text= gettext('Home');
614: }
615: printLinkHTML(getSiteHomeURL(), $text, $text, 'homeurl'); echo $after;
616: }
617:
618: 619: 620: 621: 622:
623: function getNumAlbums() {
624: global $_zp_gallery, $_zp_current_album, $_zp_current_search;
625: if (in_context(ZP_SEARCH) && is_null($_zp_current_album)) {
626: return $_zp_current_search->getNumAlbums();
627: } else if (in_context(ZP_ALBUM)) {
628: return $_zp_current_album->getNumAlbums();
629: } else {
630: return $_zp_gallery->getNumAlbums();
631: }
632: }
633:
634: 635: 636: 637: 638:
639: function getCurrentTheme() {
640: global $_zp_gallery;
641: return $_zp_gallery->getCurrentTheme();
642: }
643:
644:
645:
646:
647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659:
660: function next_album($all = false, $mine = NULL) {
661: global $_zp_albums, $_zp_gallery, $_zp_current_album, $_zp_page, $_zp_current_album_restore, $_zp_current_search;
662: if (($mine != NULL && gettype($mine) != 'boolean') || func_num_args() > 2) {
663: internal_deprecations::next_album();
664: }
665:
666: if (is_null($_zp_albums)) {
667: if (in_context(ZP_SEARCH)) {
668: $_zp_albums = $_zp_current_search->getAlbums($all ? 0 : $_zp_page, NULL, NULL, true, $mine);
669: } else if (in_context(ZP_ALBUM)) {
670: $_zp_albums = $_zp_current_album->getAlbums($all ? 0 : $_zp_page, NULL, NULL, true, $mine);
671: } else {
672: $_zp_albums = $_zp_gallery->getAlbums($all ? 0 : $_zp_page, NULL, NULL, true, $mine);
673: }
674: if (empty($_zp_albums)) {
675: return NULL;
676: }
677: $_zp_current_album_restore = $_zp_current_album;
678: $_zp_current_album = newAlbum(array_shift($_zp_albums), true, true);
679: save_context();
680: add_context(ZP_ALBUM);
681: return true;
682: } else if (empty($_zp_albums)) {
683: $_zp_albums = NULL;
684: $_zp_current_album = $_zp_current_album_restore;
685: restore_context();
686: return false;
687: } else {
688: $_zp_current_album = newAlbum(array_shift($_zp_albums), true, true);
689: return true;
690: }
691: }
692:
693: 694: 695: 696: 697:
698: function getCurrentPage() {
699: global $_zp_page;
700: return $_zp_page;
701: }
702:
703: 704: 705: 706: 707: 708:
709: function getAllAlbums($album = NULL) {
710: global $_zp_current_album, $_zp_gallery;
711: if (is_null($album))
712: $album = $_zp_current_album;
713: if (!is_object($album))
714: return;
715: $list = array();
716: $subalbums = $album->getAlbums(0);
717: if (is_array($subalbums)) {
718: foreach ($subalbums as $subalbum) {
719: $list[] = $subalbum;
720: $sub = newAlbum($subalbum);
721: $list = array_merge($list, getAllAlbums($sub));
722: }
723: }
724: return $list;
725: }
726:
727: 728: 729: 730: 731: 732: 733:
734: function getAllAccessibleAlbums($obj, &$albumlist, $scan) {
735: global $_zp_gallery;
736: $locallist = $obj->getAlbums();
737: foreach ($locallist as $folder) {
738: $album = newAlbum($folder);
739: If (!$album->isDynamic() && $album->checkAccess()) {
740: if ($scan)
741: $album->getImages();
742: $albumlist[] = $album->getID();
743: getAllAccessibleAlbums($album, $albumlist, $scan);
744: }
745: }
746: }
747:
748: 749: 750: 751: 752: 753: 754: 755:
756: function getTotalPages($_oneImagePage = false) {
757: global $_zp_gallery, $_zp_current_album, $_firstPageImages, $_zp_zenpage, $_zp_current_category;
758: if (in_context(ZP_ALBUM | ZP_SEARCH)) {
759: $albums_per_page = max(1, getOption('albums_per_page'));
760: $pageCount = (int) ceil(getNumAlbums() / $albums_per_page);
761: $imageCount = getNumImages();
762: if ($_oneImagePage) {
763: if ($_oneImagePage === true) {
764: $imageCount = min(1, $imageCount);
765: } else {
766: $imageCount = 0;
767: }
768: }
769: $images_per_page = max(1, getOption('images_per_page'));
770: $pageCount = ($pageCount + ceil(($imageCount - $_firstPageImages) / $images_per_page));
771: return $pageCount;
772: } else if (get_context() == ZP_INDEX) {
773: if (galleryAlbumsPerPage() != 0) {
774: return (int) ceil($_zp_gallery->getNumAlbums() / galleryAlbumsPerPage());
775: } else {
776: return NULL;
777: }
778: return NULL;
779: } else if (isset($_zp_zenpage)) {
780: if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
781: $cat = $_zp_current_category;
782: } else {
783: $cat = NULL;
784: }
785: return (int) ceil(count($_zp_zenpage->getArticles(0, NULL, true, NULL, NULL, NULL, $cat)) / ZP_ARTICLES_PER_PAGE);
786: }
787: }
788:
789: 790: 791: 792: 793: 794: 795:
796: function getPageNumURL($page, $total = null) {
797: global $_zp_current_album, $_zp_gallery, $_zp_current_search, $_zp_gallery_page;
798: if (is_null($total)) {
799: $total = getTotalPages();
800: }
801: if ($page <= 0 || $page > $total) {
802: return NULL;
803: }
804: if (in_context(ZP_SEARCH)) {
805: $searchwords = $_zp_current_search->codifySearchString();
806: $searchdate = $_zp_current_search->getSearchDate();
807: $searchfields = $_zp_current_search->getSearchFields(true);
808: $searchpagepath = getSearchURL($searchwords, $searchdate, $searchfields, $page, array('albums' => $_zp_current_search->getAlbumList()));
809: return $searchpagepath;
810: } else if (in_context(ZP_ALBUM)) {
811: return $_zp_current_album->getLink($page);
812: } else if (in_array($_zp_gallery_page, array('index.php', 'album.php', 'image.php'))) {
813: if (in_context(ZP_INDEX)) {
814: $pagination1 = '/';
815: $pagination2 = 'index.php';
816: if ($page > 1) {
817: $pagination1 .= _PAGE_ . '/' . $page . '/';
818: $pagination2 .= '?page=' . $page;
819: }
820: } else {
821: return NULL;
822: }
823: } else {
824:
825: $pg = stripSuffix($_zp_gallery_page);
826: $pagination1 = '/' . _PAGE_ . '/' . $pg . '/';
827: $pagination2 = 'index.php?p=' . $pg;
828: if ($page > 1) {
829: $pagination1 .= $page . '/';
830: $pagination2 .= '&page=' . $page;
831: }
832: }
833: return zp_apply_filter('getLink', rewrite_path($pagination1, $pagination2), $_zp_gallery_page, $page);
834: }
835:
836: 837: 838: 839: 840:
841: function hasNextPage() {
842: return (getCurrentPage() < getTotalPages());
843: }
844:
845: 846: 847: 848: 849:
850: function getNextPageURL() {
851: return getPageNumURL(getCurrentPage() + 1);
852: }
853:
854: 855: 856: 857: 858: 859: 860: 861:
862: function printNextPageURL($text, $title = NULL, $class = NULL, $id = NULL) {
863: if (hasNextPage()) {
864: printLinkHTML(getNextPageURL(), $text, $title, $class, $id);
865: } else {
866: echo "<span class=\"disabledlink\">$text</span>";
867: }
868: }
869:
870: 871: 872: 873: 874:
875: function hasPrevPage() {
876: return (getCurrentPage() > 1);
877: }
878:
879: 880: 881: 882: 883:
884: function getPrevPageURL() {
885: return getPageNumURL(getCurrentPage() - 1);
886: }
887:
888: 889: 890: 891: 892: 893: 894: 895:
896: function printPrevPageURL($text, $title = NULL, $class = NULL, $id = NULL) {
897: if (hasPrevPage()) {
898: printLinkHTML(getPrevPageURL(), $text, $title, $class, $id);
899: } else {
900: echo "<span class=\"disabledlink\">$text</span>";
901: }
902: }
903:
904: 905: 906: 907: 908: 909: 910: 911: 912:
913: function printPageNav($prevtext, $separator, $nexttext, $class = 'pagenav', $id = NULL) {
914: echo "<div" . (($id) ? " id=\"$id\"" : "") . " class=\"$class\">";
915: printPrevPageURL($prevtext, gettext("Previous Page"));
916: echo " $separator ";
917: printNextPageURL($nexttext, gettext("Next Page"));
918: echo "</div>\n";
919: }
920:
921: 922: 923: 924: 925: 926: 927:
928: function printPageList($class = 'pagelist', $id = NULL, $navlen = 9) {
929: printPageListWithNav(null, null, false, false, $class, $id, false, $navlen);
930: }
931:
932: 933: 934: 935: 936: 937: 938: 939: 940: 941:
942: function getPageNavList($_oneImagePage, $navlen, $firstlast, $current, $total) {
943: $result = array();
944: if (hasPrevPage()) {
945: $result['prev'] = getPrevPageURL();
946: } else {
947: $result['prev'] = NULL;
948: }
949: if ($firstlast) {
950: $result[1] = getPageNumURL(1, $total);
951: }
952:
953: if ($navlen == 0) {
954: $navlen = $total;
955: }
956: $extralinks = 2;
957: if ($firstlast)
958: $extralinks = $extralinks + 2;
959: $len = floor(($navlen - $extralinks) / 2);
960: $j = max(round($extralinks / 2), min($current - $len - (2 - round($extralinks / 2)), $total - $navlen + $extralinks - 1));
961: $ilim = min($total, max($navlen - round($extralinks / 2), $current + floor($len)));
962: $k1 = round(($j - 2) / 2) + 1;
963: $k2 = $total - round(($total - $ilim) / 2);
964:
965: for ($i = $j; $i <= $ilim; $i++) {
966: $result[$i] = getPageNumURL($i, $total);
967: }
968: if ($firstlast) {
969: $result[$total] = getPageNumURL($total, $total);
970: }
971: if (hasNextPage()) {
972: $result['next'] = getNextPageURL();
973: } else {
974: $result['next'] = NULL;
975: }
976: return $result;
977: }
978:
979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990:
991: function printPageListWithNav($prevtext, $nexttext, $_oneImagePage = false, $nextprev = true, $class = 'pagelist', $id = NULL, $firstlast = true, $navlen = 9) {
992: $current = getCurrentPage();
993: $total = max(1, getTotalPages($_oneImagePage));
994: $nav = getPageNavList($_oneImagePage, $navlen, $firstlast, $current, $total);
995: if ($total > 1) {
996: ?>
997: <div <?php if ($id) echo ' id="'.$id.'"'; ?> class="<?php echo $class; ?>">
998: <ul class="<?php echo $class; ?>">
999: <?php
1000: $prev = $nav['prev'];
1001: unset($nav['prev']);
1002: $next = $nav['next'];
1003: unset($nav['next']);
1004: if ($nextprev) {
1005: ?>
1006: <li class="prev">
1007: <?php
1008: if ($prev) {
1009: printLinkHTML($prev, html_encode($prevtext), gettext('Previous Page'));
1010: } else {
1011: ?>
1012: <span class="disabledlink"><?php echo html_encode($prevtext); ?></span>
1013: <?php
1014: }
1015: ?>
1016: </li>
1017: <?php
1018: }
1019: $last = NULL;
1020: if ($firstlast) {
1021: ?>
1022: <li class="<?php
1023: if ($current == 1)
1024: echo 'current';
1025: else
1026: echo 'first';
1027: ?>">
1028: <?php
1029: if ($current == 1) {
1030: echo '1';
1031: } else {
1032: printLinkHTML($nav[1], 1, gettext("Page 1"));
1033: }
1034: ?>
1035: </li>
1036: <?php
1037: $last = 1;
1038: unset($nav[1]);
1039: }
1040: foreach ($nav as $i => $link) {
1041: $d = $i - $last;
1042: if ($d > 2) {
1043: ?>
1044: <li>
1045: <?php
1046: $k1 = $i - (int) (($i - $last) / 2);
1047: printLinkHTML(getPageNumURL($k1, $total), '...', sprintf(ngettext('Page %u', 'Page %u', $k1), $k1));
1048: ?>
1049: </li>
1050: <?php
1051: } else if ($d == 2) {
1052: ?>
1053: <li>
1054: <?php
1055: $k1 = $last + 1;
1056: printLinkHTML(getPageNumURL($k1, $total), $k1, sprintf(ngettext('Page %u', 'Page %u', $k1), $k1));
1057: ?>
1058: </li>
1059: <?php
1060: }
1061: ?>
1062: <li<?php if ($current == $i) echo ' class="current"'; ?>>
1063: <?php
1064: if ($i == $current) {
1065: echo $i;
1066: } else {
1067: $title = sprintf(ngettext('Page %1$u', 'Page %1$u', $i), $i);
1068: printLinkHTML($link, $i, $title);
1069: }
1070: ?>
1071: </li>
1072: <?php
1073: $last = $i;
1074: unset($nav[$i]);
1075: if ($firstlast && count($nav) == 1) {
1076: break;
1077: }
1078: }
1079: if ($firstlast) {
1080: foreach ($nav as $i => $link) {
1081: $d = $i - $last;
1082: if ($d > 2) {
1083: $k1 = $i - (int) (($i - $last) / 2);
1084: ?>
1085: <li>
1086: <?php printLinkHTML(getPageNumURL($k1, $total), '...', sprintf(ngettext('Page %u', 'Page %u', $k1), $k1)); ?>
1087: </li>
1088: <?php
1089: } else if ($d == 2) {
1090: $k1 = $last + 1;
1091: ?>
1092: <li>
1093: <?php printLinkHTML(getPageNumURL($k1, $total), $k1, sprintf(ngettext('Page %u', 'Page %u', $k1), $k1)); ?>
1094: </li>
1095: <?php
1096: }
1097: ?>
1098: <li class="last<?php if ($current == $i) echo ' current'; ?>">
1099: <?php
1100: if ($current == $i) {
1101: echo $i;
1102: } else {
1103: printLinkHTML($link, $i, sprintf(ngettext('Page %u', 'Page %u', $i), $i));
1104: }
1105: ?>
1106: </li>
1107: <?php
1108: }
1109: }
1110: if ($nextprev) {
1111: ?>
1112: <li class="next">
1113: <?php
1114: if ($next) {
1115: printLinkHTML($next, html_encode($nexttext), gettext('Next Page'));
1116: } else {
1117: ?>
1118: <span class="disabledlink"><?php echo html_encode($nexttext); ?></span>
1119: <?php
1120: }
1121: ?>
1122: </li>
1123: <?php
1124: }
1125: ?>
1126: </ul>
1127: </div>
1128: <?php
1129: }
1130: }
1131:
1132:
1133:
1134:
1135: 1136: 1137: 1138: 1139:
1140: function makeAlbumCurrent($album) {
1141: global $_zp_current_album;
1142: $_zp_current_album = $album;
1143: set_context(ZP_INDEX | ZP_ALBUM);
1144: }
1145:
1146: 1147: 1148: 1149: 1150:
1151: function getAlbumTitle() {
1152: if (!in_context(ZP_ALBUM))
1153: return false;
1154: global $_zp_current_album;
1155: return $_zp_current_album->getTitle();
1156: }
1157:
1158: 1159: 1160: 1161: 1162:
1163: function getBareAlbumTitle() {
1164: return getBare(getAlbumTitle());
1165: }
1166:
1167: 1168: 1169: 1170: 1171:
1172: function getAnnotatedAlbumTitle() {
1173: global $_zp_current_album;
1174: $title = getBareAlbumTitle();
1175: $pwd = $_zp_current_album->getPassword();
1176: if (zp_loggedin() && !empty($pwd)) {
1177: $title .= "\n" . gettext('The album is password protected.');
1178: }
1179: if (!$_zp_current_album->getShow()) {
1180: $title .= "\n" . gettext('The album is un-published.');
1181: }
1182: return $title;
1183: }
1184:
1185: function printAnnotatedAlbumTitle() {
1186: echo html_encode(getAnnotatedAlbumTitle());
1187: }
1188:
1189: 1190: 1191: 1192: 1193: 1194:
1195: function printAlbumTitle() {
1196: echo html_encodeTagged(getAlbumTitle());
1197: }
1198:
1199: function printBareAlbumTitle() {
1200: echo html_encodeTagged(getBareAlbumTitle());
1201: }
1202:
1203: 1204: 1205: 1206: 1207:
1208: function albumNumber() {
1209: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery;
1210: $name = $_zp_current_album->getFileName();
1211: if (in_context(ZP_SEARCH)) {
1212: $albums = $_zp_current_search->getAlbums();
1213: } else if (in_context(ZP_ALBUM)) {
1214: $parent = $_zp_current_album->getParent();
1215: if (is_null($parent)) {
1216: $albums = $_zp_gallery->getAlbums();
1217: } else {
1218: $albums = $parent->getAlbums();
1219: }
1220: }
1221: $c = 0;
1222: foreach ($albums as $albumfolder) {
1223: $c++;
1224: if ($name == $albumfolder) {
1225: return $c;
1226: }
1227: }
1228: return false;
1229: }
1230:
1231: 1232: 1233: 1234: 1235: 1236:
1237: function getParentAlbums($album = null) {
1238: $parents = array();
1239: if (in_context(ZP_ALBUM)) {
1240: global $_zp_current_album, $_zp_current_search, $_zp_gallery;
1241: if (is_null($album)) {
1242: if (in_context(ZP_SEARCH_LINKED) && !in_context(ZP_ALBUM_LINKED)) {
1243: $album = $_zp_current_search->getDynamicAlbum();
1244: if (empty($album))
1245: return $parents;
1246: } else {
1247: $album = $_zp_current_album;
1248: }
1249: }
1250: while (!is_null($album = $album->getParent())) {
1251: array_unshift($parents, $album);
1252: }
1253: }
1254: return $parents;
1255: }
1256:
1257: 1258: 1259: 1260: 1261: 1262:
1263: function getAlbumBreadcrumb($title = NULL) {
1264: global $_zp_current_search, $_zp_gallery, $_zp_current_album, $_zp_last_album;
1265: $output = array();
1266: if (in_context(ZP_SEARCH_LINKED)) {
1267: $album = NULL;
1268: $dynamic_album = $_zp_current_search->getDynamicAlbum();
1269: if (empty($dynamic_album)) {
1270: if (!is_null($_zp_current_album)) {
1271: if (in_context(ZP_ALBUM_LINKED) && $_zp_last_album == $_zp_current_album->name) {
1272: $album = $_zp_current_album;
1273: }
1274: }
1275: } else {
1276: if (in_context(ZP_IMAGE) && in_context(ZP_ALBUM_LINKED)) {
1277: $album = $_zp_current_album;
1278: } else {
1279: $album = $dynamic_album;
1280: }
1281: }
1282: } else {
1283: $album = $_zp_current_album;
1284: }
1285: if ($album) {
1286: if (is_null($title)) {
1287: $title = $album->getTitle();
1288: if (empty($title)) {
1289: $title = gettext('Album Thumbnails');
1290: }
1291: }
1292: return array('link' => $album->getLink(), 'text' => $title, 'title' => getBare($title));
1293: }
1294: return false;
1295: }
1296:
1297: 1298: 1299: 1300: 1301: 1302: 1303:
1304: function printAlbumBreadcrumb($before = '', $after = '', $title = NULL) {
1305: if ($breadcrumb = getAlbumBreadcrumb($title)) {
1306: if ($before) {
1307: $output = '<span class="beforetext">' . html_encode($before) . '</span>';
1308: } else {
1309: $output = '';
1310: }
1311: $output .= '<a href="' . html_encode($breadcrumb['link']) . '" title="' . html_encode($breadcrumb['title']) . '">';
1312: $output .= html_encode($breadcrumb['text']);
1313: $output .= '</a>';
1314: if ($after) {
1315: $output .= '<span class="aftertext">' . html_encode($after) . '</span>';
1316: }
1317: echo $output;
1318: }
1319: }
1320:
1321: 1322: 1323: 1324: 1325: 1326: 1327: 1328: 1329: 1330:
1331: function printSearchBreadcrumb($between = NULL, $class = NULL, $search = NULL, $archive = NULL, $format = '%B %Y') {
1332: global $_zp_current_search;
1333: if (is_null($between)) {
1334: $between = ' | ';
1335: }
1336: if ($class) {
1337: $class = ' class="' . $class . '"';
1338: }
1339: if ($d = $_zp_current_search->getSearchDate()) {
1340: if (is_null($archive)) {
1341: $text = gettext('Archive');
1342: $textdecoration = true;
1343: } else {
1344: $text = getBare(html_encode($archive));
1345: $textdecoration = false;
1346: }
1347: echo "<a href=\"" . html_encode(getCustomPageURL('archive', NULL)) . "\"$class title=\"" . $text . "\">";
1348: printf('%s' . $text . '%s', $textdecoration ? '<em>' : '', $textdecoration ? '</em>' : '');
1349: echo "</a>";
1350: echo '<span class="betweentext">' . html_encode($between) . '</span>';
1351: if ($format) {
1352: $d = strtotime($d);
1353: $d = strftime($format, $d);
1354: }
1355: echo $d;
1356: } else {
1357: if (is_null($search)) {
1358: $text = gettext('Search');
1359: $textdecoration = true;
1360: } else {
1361: $text = getBare(html_encode($search));
1362: $textdecoration = false;
1363: }
1364: printf('%s' . $text . '%s', $textdecoration ? '<em>' : '', $textdecoration ? '</em>' : '');
1365: }
1366: }
1367:
1368: 1369: 1370: 1371: 1372:
1373: function getParentBreadcrumb() {
1374: global $_zp_gallery, $_zp_current_search, $_zp_current_album, $_zp_last_album;
1375: $output = array();
1376: if (in_context(ZP_SEARCH_LINKED)) {
1377: $page = $_zp_current_search->page;
1378: $searchwords = $_zp_current_search->getSearchWords();
1379: $searchdate = $_zp_current_search->getSearchDate();
1380: $searchfields = $_zp_current_search->getSearchFields(true);
1381: $search_album_list = $_zp_current_search->getAlbumList();
1382: if (!is_array($search_album_list)) {
1383: $search_album_list = array();
1384: }
1385: $searchpagepath = getSearchURL($searchwords, $searchdate, $searchfields, $page, array('albums' => $search_album_list));
1386: $dynamic_album = $_zp_current_search->getDynamicAlbum();
1387: if (empty($dynamic_album)) {
1388: if (empty($searchdate)) {
1389: $output[] = array('link' => $searchpagepath, 'title' => gettext("Return to search"), 'text' => gettext("Search"));
1390: if (is_null($_zp_current_album)) {
1391: return $output;
1392: } else {
1393: $parents = getParentAlbums();
1394: }
1395: } else {
1396: return array(array('link' => $searchpagepath, 'title' => gettext("Return to archive"), 'text' => gettext("Archive")));
1397: }
1398: } else {
1399: $album = $dynamic_album;
1400: $parents = getParentAlbums($album);
1401: if (in_context(ZP_ALBUM_LINKED)) {
1402: array_push($parents, $album);
1403: }
1404: }
1405:
1406: foreach ($parents as $key => $analbum) {
1407: $target = $analbum->name;
1408: if ($target !== $dynamic_album && !in_array($target, $search_album_list)) {
1409: unset($parents[$key]);
1410: }
1411: }
1412: } else {
1413: $parents = getParentAlbums();
1414: }
1415: $n = count($parents);
1416: if ($n > 0) {
1417: array_push($parents, $_zp_current_album);
1418: $index = -1;
1419: foreach ($parents as $parent) {
1420: $index++;
1421: if($index != 0) {
1422: $parentparent = $parents[$index-1];
1423: $page = $parent->getGalleryPage();
1424: $url = $parentparent->getLink($page);
1425: $output[] = array('link' => html_encode($url), 'title' => $parentparent->getTitle(), 'text' => $parentparent->getTitle());
1426: }
1427: }
1428: }
1429: return $output;
1430: }
1431:
1432: 1433: 1434: 1435: 1436: 1437: 1438: 1439: 1440:
1441: function printParentBreadcrumb($before = NULL, $between = NULL, $after = NULL, $truncate = NULL, $elipsis = NULL) {
1442: $crumbs = getParentBreadcrumb();
1443: if (!empty($crumbs)) {
1444: if (is_null($between)) {
1445: $between = ' | ';
1446: }
1447: if (is_null($after)) {
1448: $after = ' | ';
1449: }
1450: if (is_null($elipsis)) {
1451: $elipsis = '...';
1452: }
1453: if ($before) {
1454: $output = '<span class="beforetext">' . html_encode($before) . '</span>';
1455: } else {
1456: $output = '';
1457: }
1458: if ($between) {
1459: $between = '<span class="betweentext">' . html_encode($between) . '</span>';
1460: }
1461: $i = 0;
1462: foreach ($crumbs as $crumb) {
1463: if ($i > 0) {
1464: $output .= $between;
1465: }
1466:
1467: $desc = $crumb['title'];
1468: if (!empty($desc) && $truncate) {
1469: $desc = truncate_string($desc, $truncate, $elipsis);
1470: }
1471: $output .= '<a href="' . html_encode($crumb['link']) . '"' . ' title="' . html_encode(getBare($desc)) . '">' . html_encode($crumb['text']) . '</a>';
1472: $i++;
1473: }
1474: if ($after) {
1475: $output .= '<span class="aftertext">' . html_encode($after) . '</span>';
1476: }
1477: echo $output;
1478: }
1479: }
1480:
1481: 1482: 1483: 1484: 1485: 1486: 1487: 1488: 1489: 1490:
1491: function printHomeLink($before = '', $after = '', $title = NULL, $class = NULL, $id = NULL) {
1492: global $_zp_gallery;
1493: $site = rtrim($_zp_gallery->getWebsiteURL(), '/');
1494: if (!empty($site)) {
1495: $name = $_zp_gallery->getWebsiteTitle();
1496: if (empty($name)) {
1497: $name = gettext('Home');
1498: }
1499: if ($site != SEO_FULLWEBPATH) {
1500: if ($before) {
1501: echo '<span class="beforetext">' . html_encode($before) . '</span>';
1502: }
1503: printLinkHTML($site, $name, $title, $class, $id);
1504: if ($after) {
1505: echo '<span class="aftertext">' . html_encode($after) . '</span>';
1506: }
1507: }
1508: }
1509: }
1510:
1511: 1512: 1513: 1514: 1515: 1516:
1517: function getAlbumDate($format = null) {
1518: global $_zp_current_album;
1519: $d = $_zp_current_album->getDateTime();
1520: if (empty($d) || ($d == '0000-00-00 00:00:00')) {
1521: return false;
1522: }
1523: if (is_null($format)) {
1524: return $d;
1525: }
1526: return zpFormattedDate($format, strtotime($d));
1527: }
1528:
1529: 1530: 1531: 1532: 1533: 1534:
1535: function printAlbumDate($before = '', $format = NULL) {
1536: global $_zp_current_album;
1537: if (is_null($format)) {
1538: $format = DATE_FORMAT;
1539: }
1540: $date = getAlbumDate($format);
1541: if ($date) {
1542: if ($before) {
1543: $date = '<span class="beforetext">' . $before . '</span>' . $date;
1544: }
1545: }
1546: echo html_encodeTagged($date);
1547: }
1548:
1549: 1550: 1551: 1552: 1553:
1554: function getAlbumLocation() {
1555: global $_zp_current_album;
1556: return $_zp_current_album->getLocation();
1557: }
1558:
1559: 1560: 1561: 1562: 1563:
1564: function printAlbumLocation() {
1565: echo html_encodeTagged(getAlbumLocation());
1566: }
1567:
1568: 1569: 1570: 1571: 1572:
1573: function getAlbumDesc() {
1574: if (!in_context(ZP_ALBUM))
1575: return false;
1576: global $_zp_current_album;
1577: return $_zp_current_album->getDesc();
1578: }
1579:
1580: 1581: 1582: 1583: 1584:
1585: function getBareAlbumDesc() {
1586: return getBare(getAlbumDesc());
1587: }
1588:
1589: 1590: 1591: 1592: 1593:
1594: function printAlbumDesc() {
1595: global $_zp_current_album;
1596: echo html_encodeTagged(getAlbumDesc());
1597: }
1598:
1599: function printBareAlbumDesc() {
1600: echo html_encode(getBareAlbumDesc());
1601: }
1602:
1603: 1604: 1605: 1606: 1607:
1608: function getAlbumCustomData() {
1609: global $_zp_current_album;
1610: return $_zp_current_album->getCustomData();
1611: }
1612:
1613: 1614: 1615: 1616: 1617: 1618:
1619: function printAlbumCustomData() {
1620: echo html_encodeTagged(getAlbumCustomData());
1621: }
1622:
1623: 1624: 1625: 1626: 1627: 1628:
1629: function getAlbumData($field) {
1630: if (!in_context(ZP_IMAGE))
1631: return false;
1632: global $_zp_album_image;
1633: return get_language_string($_zp_album_image->get($field));
1634: }
1635:
1636: 1637: 1638: 1639: 1640: 1641: 1642:
1643: function printAlbumData($field, $label = '') {
1644: global $_zp_current_album;
1645: echo html_encodeTagged($_zp_current_album->get($field));
1646: }
1647:
1648: 1649: 1650: 1651: 1652: 1653:
1654: function getAlbumPage($album = NULL) {
1655: global $_zp_current_album, $_zp_current_image, $_zp_current_search, $_firstPageImages;
1656: if (is_null($album))
1657: $album = $_zp_current_album;
1658: $page = 0;
1659: if (in_context(ZP_IMAGE) && !in_context(ZP_SEARCH)) {
1660: if ($_zp_current_album->isDynamic()) {
1661: $search = $_zp_current_album->getSearchEngine();
1662: $imageindex = $search->getImageIndex($_zp_current_album->name, $_zp_current_image->filename);
1663: $numalbums = $search->getNumAlbums();
1664: } else {
1665: $imageindex = $_zp_current_image->getIndex();
1666: $numalbums = $album->getNumAlbums();
1667: }
1668: $imagepage = floor(($imageindex - $_firstPageImages) / max(1, getOption('images_per_page'))) + 1;
1669: $albumpages = ceil($numalbums / max(1, getOption('albums_per_page')));
1670: if ($albumpages == 0 && $_firstPageImages > 0)
1671: $imagepage++;
1672: $page = $albumpages + $imagepage;
1673: }
1674: return $page;
1675: }
1676:
1677: 1678: 1679: 1680: 1681: 1682:
1683: function getAlbumURL($album = NULL) {
1684: global $_zp_current_album;
1685: if (is_null($album))
1686: $album = $_zp_current_album;
1687: if (in_context(ZP_IMAGE)) {
1688: $page = getAlbumPage($album);
1689: if ($page <= 1)
1690: $page = 0;
1691: } else {
1692: $page = 0;
1693: }
1694: return $album->getLink($page);
1695: }
1696:
1697: 1698: 1699: 1700: 1701: 1702: 1703: 1704:
1705: function printAlbumURL($text, $title, $class = NULL, $id = NULL) {
1706: printLinkHTML(getAlbumURL(), $text, $title, $class, $id);
1707: }
1708:
1709: 1710: 1711: 1712: 1713:
1714: function getAlbumThumb() {
1715: global $_zp_current_album;
1716: return $_zp_current_album->getThumb();
1717: }
1718:
1719: 1720: 1721: 1722: 1723: 1724:
1725: function getPasswordProtectImage($extra) {
1726: global $_zp_themeroot;
1727: $image = '';
1728: $themedir = SERVERPATH . '/themes/' . basename($_zp_themeroot);
1729: if (file_exists(internalToFilesystem($themedir . '/images/err-passwordprotected.png'))) {
1730: $image = $_zp_themeroot . '/images/err-passwordprotected.png';
1731: } else if (file_exists(internalToFilesystem($themedir . '/images/err-passwordprotected.gif'))) {
1732: $image = $_zp_themeroot . '/images/err-passwordprotected.gif';
1733: } else {
1734: $image = WEBPATH . '/' . ZENFOLDER . '/images/err-passwordprotected.png';
1735: }
1736: return '<img src="' . $image . '" ' . $extra . ' alt="protected" />';
1737: }
1738:
1739: 1740: 1741: 1742: 1743: 1744: 1745:
1746: function printAlbumThumbImage($alt, $class = NULL, $id = NULL) {
1747: global $_zp_current_album, $_zp_themeroot;
1748: if (!$_zp_current_album->getShow()) {
1749: $class .= " not_visible";
1750: }
1751: $pwd = $_zp_current_album->getPassword();
1752: if (!empty($pwd)) {
1753: $class .= " password_protected";
1754: }
1755:
1756: $class = trim($class);
1757: if ($class) {
1758: $class = ' class="' . $class . '"';
1759: }
1760: if ($id) {
1761: $id = ' id="' . $id . '"';
1762: }
1763: $thumbobj = $_zp_current_album->getAlbumThumbImage();
1764: $sizes = getSizeDefaultThumb($thumbobj);
1765: $size = ' width="' . $sizes[0] . '" height="' . $sizes[1] . '"';
1766: if (!getOption('use_lock_image') || $_zp_current_album->isMyItem(LIST_RIGHTS) || empty($pwd)) {
1767: $html = '<img src="' . html_encode(pathurlencode($thumbobj->getThumb('album'))) . '"' . $size . ' alt="' . html_encode($alt) . '"' . $class . $id . ' />';
1768: $html = zp_apply_filter('standard_album_thumb_html', $html);
1769: echo $html;
1770: } else {
1771: echo getPasswordProtectImage($size);
1772: }
1773: }
1774:
1775: 1776: 1777: 1778: 1779: 1780: 1781: 1782: 1783: 1784: 1785: 1786: 1787: 1788:
1789: function getCustomAlbumThumb($size, $width = NULL, $height = NULL, $cropw = NULL, $croph = NULL, $cropx = NULL, $cropy = null, $effects = NULL) {
1790: global $_zp_current_album;
1791: $thumb = $_zp_current_album->getAlbumThumbImage();
1792: return $thumb->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, true, $effects);
1793: }
1794:
1795: 1796: 1797: 1798: 1799: 1800: 1801: 1802: 1803: 1804: 1805: 1806: 1807: 1808: 1809: 1810: 1811: 1812:
1813: function printCustomAlbumThumbImage($alt, $size, $width = NULL, $height = NULL, $cropw = NULL, $croph = NULL, $cropx = NULL, $cropy = null, $class = NULL, $id = NULL) {
1814: global $_zp_current_album;
1815: if (!$_zp_current_album->getShow()) {
1816: $class .= " not_visible";
1817: }
1818: $pwd = $_zp_current_album->getPassword();
1819: if (!empty($pwd)) {
1820: $class .= " password_protected";
1821: }
1822: $class = trim($class);
1823:
1824: $sizing = '';
1825: if (is_null($width)) {
1826: if (!is_null($cropw) && !is_null($croph)) {
1827: if (empty($height)) {
1828: $height = $size;
1829: }
1830: $s = round($height * ($cropw / $croph));
1831: if (!empty($s))
1832: $sizing = ' width="' . $s . '"';
1833: }
1834: } else {
1835: $sizing = ' width="' . $width . '"';
1836: }
1837: if (is_null($height)) {
1838: if (!is_null($cropw) && !is_null($croph)) {
1839: if (empty($width)) {
1840: $width = $size;
1841: }
1842: $s = round($width * ($croph / $cropw));
1843: if (!empty($s))
1844: $sizing = $sizing . ' height="' . $s . '"';
1845: }
1846: } else {
1847: $sizing = $sizing . ' height="' . $height . '"';
1848: }
1849: if (!getOption('use_lock_image') || $_zp_current_album->isMyItem(LIST_RIGHTS) || empty($pwd)) {
1850: $html = '<img src="' . html_encode(pathurlencode(getCustomAlbumThumb($size, $width, $height, $cropw, $croph, $cropx, $cropy))) . '"' . $sizing . ' alt="' . html_encode($alt) . '"' .
1851: (($class) ? ' class="' . $class . '"' : '') . (($id) ? ' id="' . $id . '"' : '') . " />";
1852: $html = zp_apply_filter('custom_album_thumb_html', $html);
1853: echo $html;
1854: } else {
1855: echo getPasswordProtectImage($sizing);
1856: }
1857: }
1858:
1859: 1860: 1861: 1862: 1863: 1864: 1865: 1866:
1867: function getMaxSpaceContainer(&$width, &$height, $image, $thumb = false) {
1868: global $_zp_gallery;
1869: $upscale = getOption('image_allow_upscale');
1870: $imagename = $image->filename;
1871: if (!isImagePhoto($image) & $thumb) {
1872: $imgfile = $image->getThumbImageFile();
1873: $image = zp_imageGet($imgfile);
1874: $s_width = zp_imageWidth($image);
1875: $s_height = zp_imageHeight($image);
1876: } else {
1877: $s_width = $image->get('width');
1878: if ($s_width == 0)
1879: $s_width = max($width, $height);
1880: $s_height = $image->get('height');
1881: if ($s_height == 0)
1882: $s_height = max($width, $height);
1883: }
1884:
1885: $newW = round($height / $s_height * $s_width);
1886: $newH = round($width / $s_width * $s_height);
1887: if (DEBUG_IMAGE)
1888: debugLog("getMaxSpaceContainer($width, $height, $imagename, $thumb): \$s_width=$s_width; \$s_height=$s_height; \$newW=$newW; \$newH=$newH; \$upscale=$upscale;");
1889: if ($newW > $width) {
1890: if ($upscale || $s_height > $newH) {
1891: $height = $newH;
1892: } else {
1893: $height = $s_height;
1894: $width = $s_width;
1895: }
1896: } else {
1897: if ($upscale || $s_width > $newW) {
1898: $width = $newW;
1899: } else {
1900: $height = $s_height;
1901: $width = $s_width;
1902: }
1903: }
1904: }
1905:
1906: 1907: 1908: 1909: 1910: 1911: 1912:
1913: function getCustomAlbumThumbMaxSpace($width, $height) {
1914: global $_zp_current_album;
1915: $albumthumb = $_zp_current_album->getAlbumThumbImage();
1916: getMaxSpaceContainer($width, $height, $albumthumb, true);
1917: return getCustomAlbumThumb(NULL, $width, $height, NULL, NULL, NULL, NULL);
1918: }
1919:
1920: 1921: 1922: 1923: 1924: 1925: 1926: 1927: 1928: 1929: 1930:
1931: function printCustomAlbumThumbMaxSpace($alt, $width, $height, $class = NULL, $id = NULL) {
1932: global $_zp_current_album;
1933: $albumthumb = $_zp_current_album->getAlbumThumbImage();
1934: getMaxSpaceContainer($width, $height, $albumthumb, true);
1935: printCustomAlbumThumbImage($alt, NULL, $width, $height, NULL, NULL, NULL, NULL, $class, $id);
1936: }
1937:
1938: 1939: 1940: 1941: 1942:
1943: function getNextAlbum() {
1944: global $_zp_current_album, $_zp_current_search, $_zp_gallery;
1945: if (in_context(ZP_SEARCH) || in_context(ZP_SEARCH_LINKED)) {
1946: $nextalbum = $_zp_current_search->getNextAlbum($_zp_current_album->name);
1947: } else if (in_context(ZP_ALBUM)) {
1948: $nextalbum = $_zp_current_album->getNextAlbum();
1949: } else {
1950: return null;
1951: }
1952: return $nextalbum;
1953: }
1954:
1955: 1956: 1957: 1958: 1959:
1960: function getNextAlbumURL() {
1961: $nextalbum = getNextAlbum();
1962: if ($nextalbum) {
1963: return $nextalbum->getLink();
1964: }
1965: return false;
1966: }
1967:
1968: 1969: 1970: 1971: 1972:
1973: function getPrevAlbum() {
1974: global $_zp_current_album, $_zp_current_search;
1975: if (in_context(ZP_SEARCH) || in_context(ZP_SEARCH_LINKED)) {
1976: $prevalbum = $_zp_current_search->getPrevAlbum($_zp_current_album->name);
1977: } else if (in_context(ZP_ALBUM)) {
1978: $prevalbum = $_zp_current_album->getPrevAlbum();
1979: } else {
1980: return null;
1981: }
1982: return $prevalbum;
1983: }
1984:
1985: 1986: 1987: 1988: 1989:
1990: function getPrevAlbumURL() {
1991: $prevalbum = getPrevAlbum();
1992: if ($prevalbum) {
1993: return $prevalbum->getLink();
1994: }
1995: return false;
1996: }
1997:
1998: 1999: 2000: 2001: 2002:
2003: function isImagePage() {
2004: if (getNumImages()) {
2005: global $_zp_page, $_firstPageImages;
2006: $imagestart = getTotalPages(2);
2007: if (!$_firstPageImages)
2008: $imagestart++;
2009: return $_zp_page >= $imagestart;
2010: }
2011: return false;
2012: }
2013:
2014: 2015: 2016: 2017: 2018:
2019: function isAlbumPage() {
2020: global $_zp_page;
2021: $pageCount = Ceil(getNumAlbums() / max(1, getOption('albums_per_page')));
2022: return ($_zp_page <= $pageCount);
2023: }
2024:
2025: 2026: 2027: 2028: 2029:
2030: function getNumImages() {
2031: global $_zp_current_album, $_zp_current_search;
2032: if ((in_context(ZP_SEARCH_LINKED) && !in_context(ZP_ALBUM_LINKED)) || in_context(ZP_SEARCH) && is_null($_zp_current_album)) {
2033: return $_zp_current_search->getNumImages();
2034: } else {
2035: return $_zp_current_album->getNumImages();
2036: }
2037: }
2038:
2039: 2040: 2041: 2042: 2043: 2044: 2045:
2046: function getTotalImagesIn($album) {
2047: global $_zp_gallery;
2048: $sum = $album->getNumImages();
2049: $subalbums = $album->getAlbums(0);
2050: while (count($subalbums) > 0) {
2051: $albumname = array_pop($subalbums);
2052: $album = newAlbum($albumname);
2053: $sum = $sum + getTotalImagesIn($album);
2054: }
2055: return $sum;
2056: }
2057:
2058: 2059: 2060: 2061: 2062: 2063: 2064: 2065: 2066: 2067: 2068: 2069: 2070: 2071:
2072: function next_image($all = false, $firstPageCount = NULL, $mine = NULL) {
2073: global $_zp_images, $_zp_current_image, $_zp_current_album, $_zp_page, $_zp_current_image_restore, $_zp_current_search, $_zp_gallery, $_firstPageImages;
2074: if (($mine != NULL && gettype($mine) != 'boolean') || func_num_args() > 3) {
2075: internal_deprecations::next_image();
2076: }
2077: if (is_null($firstPageCount)) {
2078: $firstPageCount = $_firstPageImages;
2079: }
2080: $imagePageOffset = getTotalPages(2);
2081: if ($all) {
2082: $imagePage = 1;
2083: $firstPageCount = 0;
2084: } else {
2085: $_firstPageImages = $firstPageCount;
2086: $imagePage = $_zp_page - $imagePageOffset;
2087: }
2088: if ($firstPageCount > 0 && $imagePageOffset > 0) {
2089: $imagePage = $imagePage + 1;
2090: }
2091: if ($imagePage <= 0) {
2092: return false;
2093: }
2094: if (is_null($_zp_images)) {
2095: if (in_context(ZP_SEARCH)) {
2096: $_zp_images = $_zp_current_search->getImages($all ? 0 : ($imagePage), $firstPageCount, NULL, NULL, true, $mine);
2097: } else {
2098: $_zp_images = $_zp_current_album->getImages($all ? 0 : ($imagePage), $firstPageCount, NULL, NULL, true, $mine);
2099: }
2100: if (empty($_zp_images)) {
2101: return NULL;
2102: }
2103: $_zp_current_image_restore = $_zp_current_image;
2104: $img = array_shift($_zp_images);
2105: $_zp_current_image = newImage($_zp_current_album, $img, true, true);
2106: save_context();
2107: add_context(ZP_IMAGE);
2108: return true;
2109: } else if (empty($_zp_images)) {
2110: $_zp_images = NULL;
2111: $_zp_current_image = $_zp_current_image_restore;
2112: restore_context();
2113: return false;
2114: } else {
2115: $img = array_shift($_zp_images);
2116: $_zp_current_image = newImage($_zp_current_album, $img, true, true);
2117: return true;
2118: }
2119: }
2120:
2121:
2122:
2123:
2124: 2125: 2126: 2127: 2128:
2129: function makeImageCurrent($image) {
2130: if (!is_object($image))
2131: return;
2132: global $_zp_current_album, $_zp_current_image;
2133: $_zp_current_image = $image;
2134: $_zp_current_album = $_zp_current_image->getAlbum();
2135: set_context(ZP_INDEX | ZP_ALBUM | ZP_IMAGE);
2136: }
2137:
2138: 2139: 2140: 2141: 2142:
2143: function getImageTitle() {
2144: if (!in_context(ZP_IMAGE))
2145: return false;
2146: global $_zp_current_image;
2147: return $_zp_current_image->getTitle();
2148: }
2149:
2150: 2151: 2152: 2153: 2154:
2155: function getBareImageTitle() {
2156: return getBare(getImageTitle());
2157: }
2158:
2159: 2160: 2161: 2162: 2163:
2164: function getAnnotatedImageTitle() {
2165: global $_zp_current_image;
2166: $title = getBareImageTitle();
2167: if (!$_zp_current_image->getShow()) {
2168: $title .= "\n" . gettext('The image is marked un-published.');
2169: }
2170: return $title;
2171: }
2172:
2173: function printAnnotatedImageTitle() {
2174: echo html_encode(getAnnotatedImageTitle());
2175: }
2176:
2177: 2178: 2179: 2180: 2181:
2182: function printImageTitle() {
2183: echo html_encodeTagged(getImageTitle());
2184: }
2185:
2186: function printBareImageTitle() {
2187: echo html_encode(getBareImageTitle());
2188: }
2189:
2190: 2191: 2192: 2193: 2194:
2195: function imageNumber() {
2196: global $_zp_current_image, $_zp_current_search, $_zp_current_album;
2197: $name = $_zp_current_image->getFileName();
2198: if (in_context(ZP_SEARCH) || (in_context(ZP_SEARCH_LINKED) && !in_context(ZP_ALBUM_LINKED))) {
2199: $folder = $_zp_current_image->imagefolder;
2200: $images = $_zp_current_search->getImages();
2201: $c = 0;
2202: foreach ($images as $image) {
2203: $c++;
2204: if ($name == $image['filename'] && $folder == $image['folder']) {
2205: return $c;
2206: }
2207: }
2208: } else {
2209: return $_zp_current_image->getIndex() + 1;
2210: }
2211: return false;
2212: }
2213:
2214: 2215: 2216: 2217: 2218: 2219: 2220:
2221: function getImageDate($format = null) {
2222: if (!in_context(ZP_IMAGE))
2223: return false;
2224: global $_zp_current_image;
2225: $d = $_zp_current_image->getDateTime();
2226: if (empty($d) || ($d == '0000-00-00 00:00:00')) {
2227: return false;
2228: }
2229: if (is_null($format)) {
2230: return $d;
2231: }
2232: return zpFormattedDate($format, strtotime($d));
2233: }
2234:
2235: 2236: 2237: 2238: 2239: 2240:
2241: function printImageDate($before = '', $format = null) {
2242: global $_zp_current_image;
2243: if (is_null($format)) {
2244: $format = DATE_FORMAT;
2245: }
2246: $date = getImageDate($format);
2247: if ($date) {
2248: if ($before) {
2249: $date = '<span class="beforetext">' . $before . '</span>' . $date;
2250: }
2251: }
2252: echo html_encodeTagged($date);
2253: }
2254:
2255:
2256: 2257: 2258: 2259: 2260:
2261: function getImageLocation() {
2262: if (!in_context(ZP_IMAGE))
2263: return false;
2264: global $_zp_current_image;
2265: return $_zp_current_image->getLocation();
2266: }
2267:
2268: 2269: 2270: 2271: 2272:
2273: function getImageCity() {
2274: if (!in_context(ZP_IMAGE))
2275: return false;
2276: global $_zp_current_image;
2277: return $_zp_current_image->getcity();
2278: }
2279:
2280: 2281: 2282: 2283: 2284:
2285: function getImageState() {
2286: if (!in_context(ZP_IMAGE))
2287: return false;
2288: global $_zp_current_image;
2289: return $_zp_current_image->getState();
2290: }
2291:
2292: 2293: 2294: 2295: 2296:
2297: function getImageCountry() {
2298: if (!in_context(ZP_IMAGE))
2299: return false;
2300: global $_zp_current_image;
2301: return $_zp_current_image->getCountry();
2302: }
2303:
2304: 2305: 2306: 2307: 2308: 2309:
2310: function getImageDesc() {
2311: if (!in_context(ZP_IMAGE))
2312: return false;
2313: global $_zp_current_image;
2314: return $_zp_current_image->getDesc();
2315: }
2316:
2317: 2318: 2319: 2320: 2321:
2322: function getBareImageDesc() {
2323: return getBare(getImageDesc());
2324: }
2325:
2326: 2327: 2328: 2329: 2330:
2331: function printImageDesc() {
2332: echo html_encodeTagged(getImageDesc());
2333: }
2334:
2335: function printBareImageDesc() {
2336: echo html_encode(getBareImageDesc());
2337: }
2338:
2339: 2340: 2341: 2342: 2343: 2344:
2345: function getImageData($field) {
2346: if (!in_context(ZP_IMAGE))
2347: return false;
2348: global $_zp_current_image;
2349: return get_language_string($_zp_current_image->get($field));
2350: }
2351:
2352: 2353: 2354: 2355: 2356:
2357: function getImageCustomData() {
2358: Global $_zp_current_image;
2359: return $_zp_current_image->getCustomData();
2360: }
2361:
2362: 2363: 2364: 2365: 2366: 2367:
2368: function printImageCustomData() {
2369: $data = getImageCustomData();
2370: $data = str_replace("\r\n", "\n", $data);
2371: $data = str_replace("\n", "<br />", $data);
2372: echo $data;
2373: }
2374:
2375: 2376: 2377: 2378: 2379: 2380: 2381:
2382: function printImageData($field, $label = '') {
2383: global $_zp_current_image;
2384: $text = getImageData($field);
2385: if (!empty($text)) {
2386: echo html_encodeTagged($label . $text);
2387: }
2388: }
2389:
2390: 2391: 2392: 2393: 2394:
2395: function hasNextImage() {
2396: global $_zp_current_image;
2397: if (is_null($_zp_current_image))
2398: return false;
2399: return $_zp_current_image->getNextImage();
2400: }
2401:
2402: 2403: 2404: 2405: 2406:
2407: function hasPrevImage() {
2408: global $_zp_current_image;
2409: if (is_null($_zp_current_image))
2410: return false;
2411: return $_zp_current_image->getPrevImage();
2412: }
2413:
2414: 2415: 2416: 2417: 2418:
2419: function getNextImageURL() {
2420: if (!in_context(ZP_IMAGE))
2421: return false;
2422: global $_zp_current_album, $_zp_current_image;
2423: if (is_null($_zp_current_image))
2424: return false;
2425: $nextimg = $_zp_current_image->getNextImage();
2426: return $nextimg->getLink();
2427: }
2428:
2429: 2430: 2431: 2432: 2433:
2434: function getPrevImageURL() {
2435: if (!in_context(ZP_IMAGE))
2436: return false;
2437: global $_zp_current_album, $_zp_current_image;
2438: if (is_null($_zp_current_image))
2439: return false;
2440: $previmg = $_zp_current_image->getPrevImage();
2441: return $previmg->getLink();
2442: }
2443:
2444: 2445: 2446: 2447: 2448:
2449: function getPrevImageThumb() {
2450: if (!in_context(ZP_IMAGE))
2451: return false;
2452: global $_zp_current_image;
2453: if (is_null($_zp_current_image))
2454: return false;
2455: $img = $_zp_current_image->getPrevImage();
2456: return $img->getThumb();
2457: }
2458:
2459: 2460: 2461: 2462: 2463:
2464: function getNextImageThumb() {
2465: if (!in_context(ZP_IMAGE))
2466: return false;
2467: global $_zp_current_image;
2468: if (is_null($_zp_current_image))
2469: return false;
2470: $img = $_zp_current_image->getNextImage();
2471: return $img->getThumb();
2472: }
2473:
2474: 2475: 2476: 2477: 2478:
2479: function getImageURL() {
2480: if (!in_context(ZP_IMAGE))
2481: return false;
2482: global $_zp_current_image;
2483: if (is_null($_zp_current_image))
2484: return false;
2485: return $_zp_current_image->getLink();
2486: }
2487:
2488: 2489: 2490: 2491: 2492: 2493: 2494: 2495:
2496: function printImageURL($text, $title, $class = NULL, $id = NULL) {
2497: printLinkHTML(getImageURL(), $text, $title, $class, $id);
2498: }
2499:
2500: 2501: 2502: 2503: 2504: 2505: 2506:
2507: function getImageMetaData($image = NULL, $displayonly = true) {
2508: global $_zp_current_image, $_zp_exifvars;
2509: if (is_null($image))
2510: $image = $_zp_current_image;
2511: if (is_null($image) || !$image->get('hasMetadata')) {
2512: return false;
2513: }
2514: $data = $image->getMetaData();
2515: if ($displayonly) {
2516: foreach ($data as $field => $value) {
2517: if (!$value || !$_zp_exifvars[$field][3]) {
2518: unset($data[$field]);
2519: }
2520: }
2521: }
2522: if (count($data) > 0) {
2523: return $data;
2524: }
2525: return false;
2526: }
2527:
2528: 2529: 2530: 2531: 2532: 2533: 2534: 2535: 2536:
2537: function printImageMetadata($title = NULL, $toggle = true, $id = 'imagemetadata', $class = null, $span = NULL) {
2538: global $_zp_exifvars, $_zp_current_image;
2539: if (false === ($exif = getImageMetaData($_zp_current_image, true))) {
2540: return;
2541: }
2542: if (is_null($title)) {
2543: $title = gettext('Image Info');
2544: }
2545: if ($class) {
2546: $class = ' class="' . $class . '"';
2547: }
2548: if (!$span) {
2549: $span = 'exif_link';
2550: }
2551: $dataid = $id . '_data';
2552: if ($id) {
2553: $id = ' id="' . $id . '"';
2554: }
2555: $refh = $refa = $style = '';
2556: if ($toggle == 'colorbox' && zp_has_filter('theme_head', 'colorbox::css')) {
2557: $refh = '<a href="#" class="colorbox" title="' . $title . '">';
2558: $refa = '</a>';
2559: $style = ' style="display:none"';
2560: } else if ($toggle) {
2561: $refh = '<a href="javascript:toggle(\'' . $dataid . '\');" title="' . $title . '">';
2562: $refa = '</a>';
2563: $style = ' style="display:none"';
2564: }
2565: ?>
2566: <span id="<?php echo $span; ?>" class="metadata_title">
2567: <?php echo $refh; ?><?php echo $title; ?><?php echo $refa; ?>
2568: </span>
2569: <div id="<?php echo $dataid; ?>"<?php echo $style; ?>>
2570: <div<?php echo $id . $class; ?>>
2571: <table>
2572: <?php
2573: foreach ($exif as $field => $value) {
2574: $label = $_zp_exifvars[$field][2];
2575: echo "<tr><td class=\"label\">$label:</td><td class=\"value\">";
2576: switch ($_zp_exifvars[$field][6]) {
2577: case 'time':
2578: echo zpFormattedDate(DATE_FORMAT, strtotime($value));
2579: break;
2580: default:
2581: echo html_encode($value);
2582: break;
2583: }
2584: echo "</td></tr>\n";
2585: }
2586: ?>
2587: </table>
2588: </div>
2589: </div>
2590: <?php
2591: }
2592:
2593: 2594: 2595: 2596: 2597: 2598: 2599: 2600: 2601: 2602: 2603: 2604: 2605:
2606: function getSizeCustomImage($size, $width = NULL, $height = NULL, $cw = NULL, $ch = NULL, $cx = NULL, $cy = NULL, $image = NULL) {
2607: global $_zp_current_image;
2608: if (is_null($image))
2609: $image = $_zp_current_image;
2610: if (is_null($image))
2611: return false;
2612:
2613: $h = $image->getHeight();
2614: $w = $image->getWidth();
2615: if (isImageVideo($image)) {
2616: return array($w, $h);
2617: }
2618:
2619: if (is_null($size) && !is_null($width) && !is_null($height)) {
2620: return array($width, $height);
2621: }
2622: $side = getOption('image_use_side');
2623: $us = getOption('image_allow_upscale');
2624: $args = getImageParameters(array($size, $width, $height, $cw, $ch, $cx, $cy, NULL, NULL, NULL, NULL, NULL, NULL, NULL), $image->album->name);
2625: @list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop, $thumbstandin, $passedWM, $adminrequest, $effects) = $args;
2626: if (!empty($size)) {
2627: $dim = $size;
2628: $width = $height = false;
2629: } else if (!empty($width)) {
2630: $dim = $width;
2631: $size = $height = false;
2632: } else if (!empty($height)) {
2633: $dim = $height;
2634: $size = $width = false;
2635: } else {
2636: $dim = 1;
2637: }
2638:
2639: if ($w == 0) {
2640: $hprop = 1;
2641: } else {
2642: $hprop = round(($h / $w) * $dim);
2643: }
2644: if ($h == 0) {
2645: $wprop = 1;
2646: } else {
2647: $wprop = round(($w / $h) * $dim);
2648: }
2649:
2650: if (($size && ($side == 'longest' && $h > $w) || ($side == 'height') || ($side == 'shortest' && $h < $w)) || $height) {
2651:
2652: $newh = $dim;
2653: $neww = $wprop;
2654: } else {
2655:
2656: $neww = $dim;
2657: $newh = $hprop;
2658: }
2659: if (!$us && $newh >= $h && $neww >= $w) {
2660: return array($w, $h);
2661: } else {
2662: if ($cw && $cw < $neww)
2663: $neww = $cw;
2664: if ($ch && $ch < $newh)
2665: $newh = $ch;
2666: if ($size && $ch && $cw) {
2667: $neww = $cw;
2668: $newh = $ch;
2669: }
2670: return array($neww, $newh);
2671: }
2672: }
2673:
2674: 2675: 2676: 2677: 2678: 2679: 2680: 2681:
2682: function getSizeDefaultImage($size = NULL, $image = NULL) {
2683: if (is_null($size))
2684: $size = getOption('image_size');
2685: return getSizeCustomImage($size, NULL, NULL, NULL, NULL, NULL, NULL, $image);
2686: }
2687:
2688: 2689: 2690: 2691: 2692: 2693: 2694:
2695: function getSizeFullImage($image = NULL) {
2696: global $_zp_current_image;
2697: if (is_null($image))
2698: $image = $_zp_current_image;
2699: if (is_null($image))
2700: return false;
2701: return array($image->getWidth(), $image->getHeight());
2702: }
2703:
2704: 2705: 2706: 2707: 2708: 2709: 2710:
2711: function getDefaultWidth($size = NULL, $image = NULL) {
2712: $size_a = getSizeDefaultImage($size, $image);
2713: return $size_a[0];
2714: }
2715:
2716: 2717: 2718: 2719: 2720: 2721: 2722:
2723: function getDefaultHeight($size = NULL, $image = NULL) {
2724: $size_a = getSizeDefaultImage($size, $image);
2725: return $size_a[1];
2726: }
2727:
2728: 2729: 2730: 2731: 2732: 2733: 2734:
2735: function getFullWidth($image = NULL) {
2736: global $_zp_current_image;
2737: if (is_null($image))
2738: $image = $_zp_current_image;
2739: if (is_null($image))
2740: return false;
2741: return $image->getWidth();
2742: }
2743:
2744: 2745: 2746: 2747: 2748: 2749: 2750:
2751: function getFullHeight($image = NULL) {
2752: global $_zp_current_image;
2753: if (is_null($image))
2754: $image = $_zp_current_image;
2755: if (is_null($image))
2756: return false;
2757: return $image->getHeight();
2758: }
2759:
2760: 2761: 2762: 2763: 2764: 2765: 2766:
2767: function isLandscape($image = NULL) {
2768: if (getFullWidth($image) >= getFullHeight($image))
2769: return true;
2770: return false;
2771: }
2772:
2773: 2774: 2775: 2776: 2777: 2778: 2779:
2780: function getDefaultSizedImage($image = NULL) {
2781: global $_zp_current_image;
2782: if (is_null($image))
2783: $image = $_zp_current_image;
2784: if (is_null($image))
2785: return false;
2786: return $image->getSizedImage(getOption('image_size'));
2787: }
2788:
2789: 2790: 2791: 2792: 2793: 2794: 2795:
2796: function printDefaultSizedImage($alt, $class = NULL, $id = NULL) {
2797: global $_zp_current_image;
2798: if (is_null($_zp_current_image))
2799: return;
2800: if (!$_zp_current_image->getShow()) {
2801: $class .= " not_visible";
2802: }
2803: $album = $_zp_current_image->getAlbum();
2804: $pwd = $album->getPassword();
2805: if (!empty($pwd)) {
2806: $class .= " password_protected";
2807: }
2808: if (isImagePhoto()) {
2809: $html = '<img src="' . html_encode(pathurlencode(getDefaultSizedImage())) . '" alt="' . html_encode($alt) . '"' .
2810: ' width="' . getDefaultWidth() . '" height="' . getDefaultHeight() . '"' .
2811: (($class) ? " class=\"$class\"" : "") .
2812: (($id) ? " id=\"$id\"" : "") . " />";
2813: $html = zp_apply_filter('standard_image_html', $html);
2814: echo $html;
2815: } else {
2816: echo $_zp_current_image->getContent();
2817: }
2818: }
2819:
2820: 2821: 2822: 2823: 2824:
2825: function getImageThumb() {
2826: global $_zp_current_image;
2827: if (is_null($_zp_current_image))
2828: return false;
2829: return $_zp_current_image->getThumb();
2830: }
2831:
2832: 2833: 2834: 2835: 2836:
2837: function printImageThumb($alt, $class = NULL, $id = NULL) {
2838: global $_zp_current_image;
2839: if (is_null($_zp_current_image))
2840: return;
2841: if (!$_zp_current_image->getShow()) {
2842: $class .= " not_visible";
2843: }
2844: $album = $_zp_current_image->getAlbum();
2845: $pwd = $album->getPassword();
2846: if (!empty($pwd)) {
2847: $class .= " password_protected";
2848: }
2849: $url = getImageThumb();
2850: $sizes = getSizeDefaultThumb();
2851: $size = ' width="' . $sizes[0] . '" height="' . $sizes[1] . '"';
2852: $class = trim($class);
2853: if ($class) {
2854: $class = ' class="' . $class . '"';
2855: }
2856: if ($id) {
2857: $id = ' id="' . $id . '"';
2858: }
2859: $html = '<img src="' . html_encode(pathurlencode($url)) . '"' . $size . ' alt="' . html_encode($alt) . '"' . $class . $id . " />";
2860: $html = zp_apply_filter('standard_image_thumb_html', $html);
2861: echo $html;
2862: }
2863:
2864: 2865: 2866: 2867: 2868: 2869:
2870: function getSizeDefaultThumb($image = NULL) {
2871: global $_zp_current_image;
2872: if (is_null($image)) {
2873: $image = $_zp_current_image;
2874: }
2875: $s = getOption('thumb_size');
2876: if (getOption('thumb_crop')) {
2877: $w = getOption('thumb_crop_width');
2878: $h = getOption('thumb_crop_height');
2879: if ($w > $h) {
2880:
2881: $h = round($h * $s / $w);
2882: $w = $s;
2883: } else {
2884:
2885: $w = round($w * $s / $h);
2886: $h = $s;
2887: }
2888: } else {
2889: $w = $h = $s;
2890: getMaxSpaceContainer($w, $h, $image, true);
2891: }
2892: return array($w, $h);
2893: }
2894:
2895: 2896: 2897: 2898: 2899: 2900: 2901:
2902: function getFullImageURL($image = NULL) {
2903: global $_zp_current_image;
2904: if (is_null($image)) {
2905: $image = $_zp_current_image;
2906: }
2907: if (is_null($image)) {
2908: return false;
2909: }
2910: $outcome = getOption('protect_full_image');
2911: if ($outcome == 'No access') {
2912: return NULL;
2913: }
2914: if ($outcome == 'Unprotected') {
2915: return $image->getFullImageURL();
2916: } else {
2917: return getProtectedImageURL($image, $outcome);
2918: }
2919: }
2920:
2921: 2922: 2923: 2924: 2925: 2926: 2927:
2928: function getUnprotectedImageURL($image = NULL) {
2929: global $_zp_current_image;
2930: if (is_null($image)) {
2931: $image = $_zp_current_image;
2932: }
2933: if (!is_null($image)) {
2934: return $image->getFullImageURL();
2935: }
2936: }
2937:
2938: 2939: 2940: 2941: 2942: 2943: 2944:
2945: function getProtectedImageURL($image = NULL, $disposal = NULL) {
2946: global $_zp_current_image;
2947: if (is_null($disposal)) {
2948: $disposal = getOption('protect_full_image');
2949: }
2950: if ($disposal == 'No access')
2951: return NULL;
2952: if (is_null($image)) {
2953: if (!in_context(ZP_IMAGE))
2954: return false;
2955: if (is_null($_zp_current_image))
2956: return false;
2957: $image = $_zp_current_image;
2958: }
2959: $album = $image->getAlbum();
2960: $watermark_use_image = getWatermarkParam($image, WATERMARK_FULL);
2961: if (!empty($watermark_use_image)) {
2962: $wmt = $watermark_use_image;
2963: } else {
2964: $wmt = false;
2965: }
2966: $args = array('FULL', NULL, NULL, NULL, NULL, NULL, NULL, (int) getOption('full_image_quality'), NULL, NULL, NULL, $wmt, false, NULL, NULL);
2967: $cache_file = getImageCacheFilename($album->name, $image->filename, $args);
2968: $cache_path = SERVERCACHE . $cache_file;
2969: if ($disposal != 'Download' && OPEN_IMAGE_CACHE && file_exists($cache_path)) {
2970: return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cache_file));
2971: } else if ($disposal == 'Unprotected') {
2972: return getImageURI($args, $album->name, $image->filename, $image->filemtime);
2973: } else {
2974: $params = '&q=' . getOption('full_image_quality');
2975: if (!empty($watermark_use_image)) {
2976: $params .= '&wmk=' . $watermark_use_image;
2977: }
2978: if ($disposal) {
2979: $params .= '&dsp=' . $disposal;
2980: }
2981: $params .= '&check=' . sha1(HASH_SEED . serialize($args));
2982: if (is_array($image->filename)) {
2983: $album = dirname($image->filename['source']);
2984: $image = basename($image->filename['source']);
2985: } else {
2986: $album = $album->name;
2987: $image = $image->filename;
2988: }
2989: return WEBPATH . '/' . ZENFOLDER . '/full-image.php?a=' . $album . '&i=' . $image . $params;
2990: }
2991: }
2992:
2993: 2994: 2995: 2996: 2997:
2998: function getSizedImageURL($size) {
2999: return getCustomImageURL($size);
3000: }
3001:
3002: 3003: 3004: 3005: 3006: 3007: 3008: 3009: 3010: 3011: 3012: 3013: 3014: 3015: 3016: 3017: 3018: 3019: 3020: 3021: 3022: 3023: 3024: 3025: 3026: 3027: 3028: 3029: 3030: 3031: 3032: 3033: 3034: 3035: 3036: 3037: 3038: 3039: 3040: 3041: 3042: 3043: 3044: 3045: 3046: 3047: 3048: 3049: 3050: 3051: 3052: 3053: 3054: 3055: 3056: 3057: 3058: 3059:
3060: function getCustomImageURL($size, $width = NULL, $height = NULL, $cropw = NULL, $croph = NULL, $cropx = NULL, $cropy = NULL, $thumbStandin = false, $effects = NULL) {
3061: global $_zp_current_image;
3062: if (is_null($_zp_current_image))
3063: return false;
3064: return $_zp_current_image->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin, $effects);
3065: }
3066:
3067: 3068: 3069: 3070: 3071: 3072: 3073: 3074: 3075: 3076: 3077: 3078: 3079: 3080: 3081: 3082: 3083: 3084: 3085: 3086: 3087: 3088: 3089: 3090: 3091:
3092: function printCustomSizedImage($alt, $size, $width = NULL, $height = NULL, $cropw = NULL, $croph = NULL, $cropx = NULL, $cropy = NULL, $class = NULL, $id = NULL, $thumbStandin = false, $effects = NULL) {
3093: global $_zp_current_image;
3094: if (is_null($_zp_current_image))
3095: return;
3096: if (!$_zp_current_image->getShow()) {
3097: $class .= " not_visible";
3098: }
3099: $album = $_zp_current_image->getAlbum();
3100: $pwd = $album->getPassword();
3101: if (!empty($pwd)) {
3102: $class .= " password_protected";
3103: }
3104: if ($size) {
3105: $dims = getSizeCustomImage($size);
3106: $sizing = ' width="' . $dims[0] . '" height="' . $dims[1] . '"';
3107: } else {
3108: $sizing = '';
3109: if ($width)
3110: $sizing .= ' width="' . $width . '"';
3111: if ($height)
3112: $sizing .= ' height="' . $height . '"';
3113: }
3114: if ($id)
3115: $id = ' id="' . $id . '"';
3116: if ($class)
3117: $id .= ' class="' . $class . '"';
3118: if (isImagePhoto() || $thumbStandin) {
3119: $html = '<img src="' . html_encode(pathurlencode(getCustomImageURL($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin, $effects))) . '"' .
3120: ' alt="' . html_encode($alt) . '"' .
3121: $id .
3122: $sizing .
3123: ' />';
3124: $html = zp_apply_filter('custom_image_html', $html, $thumbStandin);
3125: echo $html;
3126: } else {
3127: echo $_zp_current_image->getContent($width, $height);
3128: }
3129: }
3130:
3131: 3132: 3133: 3134: 3135: 3136: 3137: 3138:
3139: function getCustomSizedImageMaxSpace($width, $height) {
3140: global $_zp_current_image;
3141: if (is_null($_zp_current_image))
3142: return false;
3143: getMaxSpaceContainer($width, $height, $_zp_current_image);
3144: return getCustomImageURL(NULL, $width, $height);
3145: }
3146:
3147: 3148: 3149: 3150: 3151: 3152: 3153: 3154:
3155: function getCustomSizedImageThumbMaxSpace($width, $height) {
3156: global $_zp_current_image;
3157: if (is_null($_zp_current_image))
3158: return false;
3159: getMaxSpaceContainer($width, $height, $_zp_current_image, true);
3160: return getCustomImageURL(NULL, $width, $height, NULL, NULL, NULL, NULL, true);
3161: }
3162:
3163: 3164: 3165: 3166: 3167: 3168: 3169: 3170: 3171:
3172: function printCustomSizedImageThumbMaxSpace($alt, $width, $height, $class = NULL, $id = NULL) {
3173: global $_zp_current_image;
3174: if (is_null($_zp_current_image))
3175: return;
3176: getMaxSpaceContainer($width, $height, $_zp_current_image, true);
3177: printCustomSizedImage($alt, NULL, $width, $height, NULL, NULL, NULL, NULL, $class, $id, true);
3178: }
3179:
3180: 3181: 3182: 3183: 3184: 3185: 3186: 3187: 3188: 3189:
3190: function printCustomSizedImageMaxSpace($alt, $width, $height, $class = NULL, $id = NULL, $thumb = false) {
3191: global $_zp_current_image;
3192: if (is_null($_zp_current_image))
3193: return;
3194: getMaxSpaceContainer($width, $height, $_zp_current_image, $thumb);
3195: printCustomSizedImage($alt, NULL, $width, $height, NULL, NULL, NULL, NULL, $class, $id, $thumb);
3196: }
3197:
3198: 3199: 3200: 3201: 3202: 3203: 3204: 3205:
3206: function printSizedImageURL($size, $text, $title, $class = NULL, $id = NULL) {
3207: printLinkHTML(getSizedImageURL($size), $text, $title, $class, $id);
3208: }
3209:
3210: 3211: 3212: 3213: 3214: 3215: 3216: 3217:
3218: function filterImageQuery($result, $source) {
3219: if ($result) {
3220: while ($row = db_fetch_assoc($result)) {
3221: $image = newImage(null, $row);
3222: $album = $image->album;
3223: if ($album->name == $source || $album->checkAccess()) {
3224: if (isImagePhoto($image)) {
3225: if ($image->checkAccess()) {
3226: return $image;
3227: }
3228: }
3229: }
3230: }
3231: db_free_result($result);
3232: }
3233: return NULL;
3234: }
3235:
3236: 3237: 3238: 3239: 3240: 3241:
3242: function getRandomImages($daily = false) {
3243: global $_zp_gallery;
3244: if ($daily) {
3245: $potd = getSerializedArray(getOption('picture_of_the_day'));
3246: if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
3247: $album = newAlbum($potd['folder'], true, true);
3248: if ($album->exists) {
3249: $image = newImage($album, $potd['filename'], true);
3250: if ($image->exists) {
3251: return $image;
3252: }
3253: }
3254: }
3255: }
3256: if (zp_loggedin()) {
3257: $imageWhere = '';
3258: } else {
3259: $imageWhere = " AND " . prefix('images') . ".show=1";
3260: }
3261: $result = query('SELECT `folder`, `filename` ' .
3262: ' FROM ' . prefix('images') . ', ' . prefix('albums') .
3263: ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' .
3264: prefix('albums') . '.id ' . $imageWhere . ' ORDER BY RAND()');
3265:
3266: $image = filterImageQuery($result, NULL);
3267: if ($image) {
3268: if ($daily) {
3269: $potd = array('day' => time(), 'folder' => $image->getAlbumName(), 'filename' => $image->getFileName());
3270: setThemeOption('picture_of_the_day', serialize($potd), NULL, $_zp_gallery->getCurrentTheme());
3271: }
3272: return $image;
3273: }
3274: return NULL;
3275: }
3276:
3277: 3278: 3279: 3280: 3281: 3282: 3283: 3284:
3285: function getRandomImagesAlbum($rootAlbum = NULL, $daily = false) {
3286: global $_zp_current_album, $_zp_gallery;
3287: if (empty($rootAlbum) && !in_context(ZP_ALBUM)) {
3288: return null;
3289: }
3290: if (empty($rootAlbum)) {
3291: $album = $_zp_current_album;
3292: } else {
3293: if (is_object($rootAlbum)) {
3294: $album = $rootAlbum;
3295: } else {
3296: $album = newAlbum($rootAlbum);
3297: }
3298: }
3299: if ($daily && ($potd = getOption('picture_of_the_day:' . $album->name))) {
3300: $potd = getSerializedArray($potd);
3301: if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
3302: $rndalbum = newAlbum($potd['folder']);
3303: $image = newImage($rndalbum, $potd['filename']);
3304: if ($image->exists)
3305: return $image;
3306: }
3307: }
3308: $image = NULL;
3309: if ($album->isDynamic()) {
3310: $images = $album->getImages(0);
3311: shuffle($images);
3312: while (count($images) > 0) {
3313: $result = array_pop($images);
3314: if (Gallery::validImage($result['filename'])) {
3315: $image = newImage(newAlbum($result['folder']), $result['filename']);
3316: }
3317: }
3318: } else {
3319: $albumfolder = $album->getFileName();
3320: if ($album->isMyItem(LIST_RIGHTS)) {
3321: $imageWhere = '';
3322: $albumInWhere = '';
3323: } else {
3324: $imageWhere = " AND " . prefix('images') . ".show=1";
3325: $albumInWhere = prefix('albums') . ".show=1";
3326: }
3327: $query = "SELECT id FROM " . prefix('albums') . " WHERE ";
3328: if ($albumInWhere) {
3329: $query .= $albumInWhere . ' AND ';
3330: }
3331: $query .= "folder LIKE " . db_quote(db_LIKE_escape($albumfolder) . '%');
3332: $result = query($query);
3333: if ($result) {
3334: $albumids = array();
3335: while ($row = db_fetch_assoc($result)) {
3336: $albumids[] = $row['id'];
3337: }
3338: if (empty($albumids)) {
3339: $albumInWhere = ' AND ' . $albumInWhere;
3340: } else {
3341: $albumInWhere = ' AND ' . prefix('albums') . ".id IN (" . implode(',', $albumids) . ')';
3342: }
3343: db_free_result($result);
3344: $sql = 'SELECT `folder`, `filename` ' .
3345: ' FROM ' . prefix('images') . ', ' . prefix('albums') .
3346: ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' .
3347: prefix('albums') . '.id ' . $albumInWhere . $imageWhere . ' ORDER BY RAND()';
3348: $result = query($sql);
3349: $image = filterImageQuery($result, $album->name);
3350: }
3351: }
3352: if ($image) {
3353: if ($daily) {
3354: $potd = array('day' => time(), 'folder' => $image->getAlbumName(), 'filename' => $image->getFileName());
3355: setThemeOption('picture_of_the_day:' . $album->name, serialize($potd), NULL, $_zp_gallery->getCurrentTheme());
3356: }
3357: }
3358: return $image;
3359: }
3360:
3361: 3362: 3363: 3364: 3365: 3366: 3367: 3368: 3369: 3370: 3371: 3372:
3373: function printRandomImages($number = 5, $class = null, $option = 'all', $rootAlbum = '', $width = NULL, $height = NULL, $crop = NULL, $fullimagelink = false) {
3374: if (is_null($crop) && is_null($width) && is_null($height)) {
3375: $crop = 2;
3376: } else {
3377: if (is_null($width))
3378: $width = 85;
3379: if (is_null($height))
3380: $height = 85;
3381: if (is_null($crop)) {
3382: $crop = 1;
3383: } else {
3384: $crop = (int) $crop && true;
3385: }
3386: }
3387: if (!empty($class))
3388: $class = ' class="' . $class . '"';
3389: echo "<ul" . $class . ">";
3390: for ($i = 1; $i <= $number; $i++) {
3391: switch ($option) {
3392: case "all":
3393: $randomImage = getRandomImages();
3394: break;
3395: case "album":
3396: $randomImage = getRandomImagesAlbum($rootAlbum);
3397: break;
3398: }
3399: if (is_object($randomImage) && $randomImage->exists) {
3400: echo "<li>\n";
3401: if ($fullimagelink) {
3402: $randomImageURL = $randomImage->getFullimageURL();
3403: } else {
3404: $randomImageURL = $randomImage->getLink();
3405: }
3406: echo '<a href="' . html_encode($randomImageURL) . '" title="' . sprintf(gettext('View image: %s'), html_encode($randomImage->getTitle())) . '">';
3407: switch ($crop) {
3408: case 0:
3409: $sizes = getSizeCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, $randomImage);
3410: $html = '<img src="' . html_encode(pathurlencode($randomImage->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($randomImage->getTitle()) . '" />' . "\n";
3411: break;
3412: case 1:
3413: $sizes = getSizeCustomImage(NULL, $width, $height, $width, $height, NULL, NULL, $randomImage);
3414: $html = '<img src="' . html_encode(pathurlencode($randomImage->getCustomImage(NULL, $width, $height, $width, $height, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($randomImage->getTitle()) . '" />' . "\n";
3415: break;
3416: case 2:
3417: $sizes = getSizeDefaultThumb($randomImage);
3418:
3419: $html = $randomImage->filename." (".$randomImage->album->name.")";
3420: break;
3421: }
3422: echo zp_apply_filter('custom_image_html', $html, false);
3423: echo "</a>";
3424: echo "</li>\n";
3425: } else {
3426: break;
3427: }
3428: }
3429: echo "</ul>";
3430: }
3431:
3432: 3433: 3434: 3435: 3436: 3437:
3438: function getTags() {
3439: if (in_context(ZP_IMAGE)) {
3440: global $_zp_current_image;
3441: return $_zp_current_image->getTags();
3442: } else if (in_context(ZP_ALBUM)) {
3443: global $_zp_current_album;
3444: return $_zp_current_album->getTags();
3445: } else if (in_context(ZP_ZENPAGE_PAGE)) {
3446: global $_zp_current_zenpage_page;
3447: return $_zp_current_zenpage_page->getTags();
3448: } else if (in_context(ZP_ZENPAGE_NEWS_ARTICLE)) {
3449: global $_zp_current_zenpage_news;
3450: return $_zp_current_zenpage_news->getTags();
3451: }
3452: return array();
3453: }
3454:
3455: 3456: 3457: 3458: 3459: 3460: 3461: 3462: 3463: 3464:
3465: function printTags($option = 'links', $preText = NULL, $class = NULL, $separator = ', ') {
3466: global $_zp_current_search;
3467: if (is_null($class)) {
3468: $class = 'taglist';
3469: }
3470: $singletag = getTags();
3471: $tagstring = implode(', ', $singletag);
3472: if ($tagstring === '' or $tagstring === NULL) {
3473: $preText = '';
3474: }
3475: if (in_context(ZP_IMAGE)) {
3476: $object = "image";
3477: } else if (in_context(ZP_ALBUM)) {
3478: $object = "album";
3479: } else if (in_context(ZP_ZENPAGE_PAGE)) {
3480: $object = "pages";
3481: } else if (in_context(ZP_ZENPAGE_NEWS_ARTICLE)) {
3482: $object = "news";
3483: }
3484: if (count($singletag) > 0) {
3485: if (!empty($preText)) {
3486: echo "<span class=\"tags_title\">" . $preText . "</span>";
3487: }
3488: echo "<ul class=\"" . $class . "\">\n";
3489: if (is_object($_zp_current_search)) {
3490: $albumlist = $_zp_current_search->getAlbumList();
3491: } else {
3492: $albumlist = NULL;
3493: }
3494: $ct = count($singletag);
3495: $x = 0;
3496: foreach ($singletag as $atag) {
3497: if (++$x == $ct) {
3498: $separator = "";
3499: }
3500: if ($option === "links") {
3501: $links1 = "<a href=\"" . html_encode(getSearchURL(search_quote($atag), '', 'tags', 0, array('albums' => $albumlist))) . "\" title=\"" . html_encode($atag) . "\">";
3502: $links2 = "</a>";
3503: } else {
3504: $links1 = $links2 = '';
3505: }
3506: echo "\t<li>" . $links1 . $atag . $links2 . $separator . "</li>\n";
3507: }
3508: echo "</ul>";
3509: } else {
3510: echo "$tagstring";
3511: }
3512: }
3513:
3514: 3515: 3516: 3517: 3518: 3519: 3520: 3521: 3522: 3523: 3524: 3525: 3526: 3527: 3528: 3529: 3530: 3531:
3532: function printAllTagsAs($option, $class = '', $sort = NULL, $counter = FALSE, $links = TRUE, $maxfontsize = 2, $maxcount = 50, $mincount = 1, $limit = NULL, $minfontsize = 0.8, $exclude_unassigned = true, $checkaccess = false) {
3533: global $_zp_current_search;
3534: $option = strtolower($option);
3535: if ($class != "") {
3536: $class = ' class="' . $class . '"';
3537: }
3538: $tagcount = getAllTagsCount($exclude_unassigned, $checkaccess);
3539: if (!is_array($tagcount)) {
3540: return false;
3541: }
3542: switch ($sort) {
3543: case 'results':
3544: arsort($tagcount);
3545: if (!is_null($limit)) {
3546: $tagcount = array_slice($tagcount, 0, $limit);
3547: }
3548: break;
3549: case 'random':
3550: if (!is_null($limit)) {
3551: $tagcount = array_slice($tagcount, 0, $limit);
3552: }
3553: shuffle_assoc($tagcount);
3554: break;
3555: default:
3556: break;
3557: }
3558: ?>
3559: <ul<?php echo $class; ?>>
3560: <?php
3561: if (count($tagcount) > 0) {
3562: foreach ($tagcount as $key => $val) {
3563: if (!$counter) {
3564: $counter = "";
3565: } else {
3566: $counter = " (" . $val . ") ";
3567: }
3568: if ($option == "cloud") {
3569: if ($val <= $mincount) {
3570: $size = $minfontsize;
3571: } else {
3572: $size = min(max(round(($maxfontsize * ($val - $mincount)) / ($maxcount - $mincount), 2), $minfontsize), $maxfontsize);
3573: }
3574: $size = str_replace(',', '.', $size);
3575: $size = ' style="font-size:' . $size . 'em;"';
3576: } else {
3577: $size = '';
3578: }
3579: if ($val >= $mincount) {
3580: if ($links) {
3581: if (is_object($_zp_current_search)) {
3582: $albumlist = $_zp_current_search->getAlbumList();
3583: } else {
3584: $albumlist = NULL;
3585: }
3586: $link = getSearchURL(search_quote($key), '', 'tags', 0, array('albums' => $albumlist));
3587: ?>
3588: <li>
3589: <a href="<?php echo html_encode($link); ?>"<?php echo $size; ?>><?php echo $key . $counter; ?></a>
3590: </li>
3591: <?php
3592: } else {
3593: ?>
3594: <li<?php echo $size; ?>><?php echo $key . $counter; ?></li>
3595: <?php
3596: }
3597: }
3598: }
3599: } else {
3600: ?>
3601: <li><?php echo gettext('No popular tags'); ?></li>
3602: <?php
3603: }
3604: ?>
3605: </ul>
3606: <?php
3607: }
3608:
3609: 3610: 3611: 3612: 3613: 3614:
3615: function getAllDates($order = 'asc') {
3616: $alldates = array();
3617: $cleandates = array();
3618: $sql = "SELECT `date` FROM " . prefix('images');
3619: if (!zp_loggedin()) {
3620: $sql .= " WHERE `show` = 1";
3621: }
3622: $hidealbums = getNotViewableAlbums();
3623: if (!is_null($hidealbums)) {
3624: if (zp_loggedin()) {
3625: $sql .= ' WHERE ';
3626: } else {
3627: $sql .= ' AND ';
3628: }
3629: foreach ($hidealbums as $id) {
3630: $sql .= '`albumid`!=' . $id . ' AND ';
3631: }
3632: $sql = substr($sql, 0, -5);
3633: }
3634: $result = query($sql);
3635: if ($result) {
3636: while ($row = db_fetch_assoc($result)) {
3637: $alldates[] = $row['date'];
3638: }
3639: db_free_result($result);
3640: }
3641: foreach ($alldates as $adate) {
3642: if (!empty($adate)) {
3643: $cleandates[] = substr($adate, 0, 7) . "-01";
3644: }
3645: }
3646: $datecount = array_count_values($cleandates);
3647: if ($order == 'desc') {
3648: krsort($datecount);
3649: } else {
3650: ksort($datecount);
3651: }
3652: return $datecount;
3653: }
3654:
3655: 3656: 3657: 3658: 3659: 3660: 3661: 3662:
3663: function printAllDates($class = 'archive', $yearid = 'year', $monthid = 'month', $order = 'asc') {
3664: global $_zp_current_search, $_zp_gallery_page;
3665: if (empty($class)) {
3666: $classactive = 'archive_active';
3667: } else {
3668: $classactive = $class . '_active';
3669: $class = 'class="' . $class . '"';
3670: }
3671: if ($_zp_gallery_page == 'search.php') {
3672: $activedate = getSearchDate('%Y-%m');
3673: } else {
3674: $activedate = '';
3675: }
3676: if (!empty($yearid)) {
3677: $yearid = 'class="' . $yearid . '"';
3678: }
3679: if (!empty($monthid)) {
3680: $monthid = 'class="' . $monthid . '"';
3681: }
3682: $datecount = getAllDates($order);
3683: $lastyear = "";
3684: echo "\n<ul $class>\n";
3685: $nr = 0;
3686: while (list($key, $val) = each($datecount)) {
3687: $nr++;
3688: if ($key == '0000-00-01') {
3689: $year = "no date";
3690: $month = "";
3691: } else {
3692: $dt = strftime('%Y-%B', strtotime($key));
3693: $year = substr($dt, 0, 4);
3694: $month = substr($dt, 5);
3695: }
3696:
3697: if ($lastyear != $year) {
3698: $lastyear = $year;
3699: if ($nr != 1) {
3700: echo "</ul>\n</li>\n";
3701: }
3702: echo "<li $yearid>$year\n<ul $monthid>\n";
3703: }
3704: if (is_object($_zp_current_search)) {
3705: $albumlist = $_zp_current_search->getAlbumList();
3706: } else {
3707: $albumlist = NULL;
3708: }
3709: $datekey = substr($key, 0, 7);
3710: if ($activedate = $datekey) {
3711: $cl = ' class="' . $classactive . '"';
3712: } else {
3713: $cl = '';
3714: }
3715: echo '<li' . $cl . '><a href="' . html_encode(getSearchURL('', $datekey, '', 0, array('albums' => $albumlist))) . '">' . $month . ' (' . $val . ')</a></li>' . "\n";
3716: }
3717: echo "</ul>\n</li>\n</ul>\n";
3718: }
3719:
3720: 3721: 3722: 3723: 3724: 3725: 3726: 3727:
3728: function getCustomPageURL($page, $q = '') {
3729: global $_zp_current_album, $_zp_conf_vars;
3730: if (array_key_exists($page, $_zp_conf_vars['special_pages'])) {
3731: $result_r = preg_replace('~^_PAGE_/~', _PAGE_ . '/', $_zp_conf_vars['special_pages'][$page]['rewrite']) . '/';
3732: } else {
3733: $result_r = '/' . _PAGE_ . '/' . $page . '/';
3734: }
3735: $result = "index.php?p=$page";
3736:
3737: if (!empty($q)) {
3738: $result_r .= "?$q";
3739: $result .= "&$q";
3740: }
3741: return zp_apply_filter('getLink', rewrite_path($result_r, $result), $page . '.php', NULL);
3742: }
3743:
3744: 3745: 3746: 3747: 3748: 3749: 3750: 3751: 3752: 3753:
3754: function printCustomPageURL($linktext, $page, $q = '', $prev = '', $next = '', $class = NULL) {
3755: if (!is_null($class)) {
3756: $class = 'class="' . $class . '"';
3757: }
3758: echo $prev . "<a href=\"" . html_encode(getCustomPageURL($page, $q)) . "\" $class title=\"" . html_encode($linktext) . "\">" . html_encode($linktext) . "</a>" . $next;
3759: }
3760:
3761:
3762:
3763:
3764: 3765: 3766: 3767: 3768:
3769: function isArchive() {
3770: return isset($_REQUEST['date']);
3771: }
3772:
3773: 3774: 3775: 3776: 3777: 3778: 3779: 3780: 3781: 3782: 3783:
3784: function getSearchURL($words, $dates, $fields, $page, $object_list = NULL) {
3785: if (!is_null($object_list)) {
3786: if (array_key_exists(0, $object_list)) {
3787: internal_deprecations::getSearchURL();
3788: $object_list = array('albums' => $object_list);
3789: }
3790: }
3791: $urls = '';
3792: $rewrite = false;
3793: if (MOD_REWRITE) {
3794: $rewrite = true;
3795: if (is_array($object_list)) {
3796: foreach ($object_list as $obj) {
3797: if ($obj) {
3798: $rewrite = false;
3799: break;
3800: }
3801: }
3802: }
3803: }
3804:
3805: if ($rewrite) {
3806: if (empty($dates)) {
3807: $url = SEO_WEBPATH . '/' . _SEARCH_ . '/';
3808: } else {
3809: $url = SEO_WEBPATH . '/' . _ARCHIVE_ . '/';
3810: }
3811: } else {
3812: $url = SEO_WEBPATH . "/index.php?p=search";
3813: }
3814: if (!empty($fields) && empty($dates)) {
3815: if (!is_array($fields)) {
3816: $fields = explode(',', $fields);
3817: }
3818: $temp = $fields;
3819: if ($rewrite && count($fields) == 1 && array_shift($temp) == 'tags') {
3820: $url = SEO_WEBPATH . '/' . _TAGS_ . '/';
3821: } else {
3822: $search = new SearchEngine();
3823: $urls = $search->getSearchFieldsText($fields, 'searchfields=');
3824: }
3825: }
3826:
3827: if (!empty($words)) {
3828: if (is_array($words)) {
3829: foreach ($words as $key => $word) {
3830: $words[$key] = search_quote($word);
3831: }
3832: $words = implode(',', $words);
3833: }
3834: $words = strtr($words, array('%' => '__25__', '&' => '__26__', '#' => '__23__', '/' => '__2F__'));
3835: if ($rewrite) {
3836: $url .= urlencode($words) . '/';
3837: } else {
3838: $url .= "&words=" . urlencode($words);
3839: }
3840: }
3841: if (!empty($dates)) {
3842: if (is_array($dates)) {
3843: $dates = implode(',', $dates);
3844: }
3845: if ($rewrite) {
3846: $url .= $dates . '/';
3847: } else {
3848: $url .= "&date=$dates";
3849: }
3850: }
3851: if ($page > 1) {
3852: if ($rewrite) {
3853: $url .= "$page/";
3854: } else {
3855: if ($urls) {
3856: $urls .= '&';
3857: }
3858: $urls .= "page=$page";
3859: }
3860: }
3861: if (!empty($urls)) {
3862: if ($rewrite) {
3863: $url .= '?' . $urls;
3864: } else {
3865: $url .= '&' . $urls;
3866: }
3867: }
3868: if (is_array($object_list)) {
3869: foreach ($object_list as $key => $list) {
3870: if (!empty($list)) {
3871: $url .= '&in' . $key . '=' . html_encode(implode(',', $list));
3872: }
3873: }
3874: }
3875: return $url;
3876: }
3877:
3878: 3879: 3880: 3881: 3882: 3883: 3884: 3885: 3886: 3887: 3888: 3889: 3890: 3891: 3892: 3893: 3894: 3895: 3896: 3897: 3898: 3899: 3900:
3901: function printSearchForm($prevtext = NULL, $id = 'search', $buttonSource = NULL, $buttontext = '', $iconsource = NULL, $query_fields = NULL, $object_list = NULL, $within = NULL) {
3902: global $_zp_adminJS_loaded, $_zp_current_search;
3903: $engine = new SearchEngine();
3904: if (!is_null($_zp_current_search) && !$_zp_current_search->getSearchWords()) {
3905: $engine->clearSearchWords();
3906: }
3907: if (!is_null($object_list)) {
3908: if (array_key_exists(0, $object_list)) {
3909: trigger_error(gettext('printSearchForm $album_list parameter is deprecated. Pass array("albums"=>array(album, album, ...)) instead.'), E_USER_NOTICE);
3910: $object_list = array('albums' => $object_list);
3911: }
3912: }
3913: if (empty($buttontext)) {
3914: $buttontext = gettext("Search");
3915: }
3916: $zf = WEBPATH . "/" . ZENFOLDER;
3917: $searchwords = $engine->codifySearchString();
3918: if (substr($searchwords, -1, 1) == ',') {
3919: $searchwords = substr($searchwords, 0, -1);
3920: }
3921: if (empty($searchwords)) {
3922: $within = false;
3923: $hint = '%s';
3924: } else {
3925: $hint = gettext('%s within previous results');
3926: }
3927: if (preg_match('!\/(.*)[\.png|\.jpg|\.jpeg|\.gif]$!', $buttonSource)) {
3928: $buttonSource = 'src="' . $buttonSource . '" alt="' . $buttontext . '"';
3929: $button = 'title="' . sprintf($hint, $buttontext) . '"';
3930: $type = 'image';
3931: } else {
3932: $type = 'submit';
3933: if ($buttonSource) {
3934: $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttonSource) . '"';
3935: $buttonSource = '';
3936: } else {
3937: $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttontext) . '"';
3938: }
3939: }
3940: if (empty($iconsource)) {
3941: $iconsource = WEBPATH . '/' . ZENFOLDER . '/images/searchfields_icon.png';
3942: }
3943: if (is_null($within)) {
3944: $within = getOption('search_within');
3945: }
3946: if (MOD_REWRITE) {
3947: $searchurl = SEO_WEBPATH . '/' . _SEARCH_ . '/';
3948: } else {
3949: $searchurl = WEBPATH . "/index.php?p=search";
3950: }
3951: if (!$within) {
3952: $engine->clearSearchWords();
3953: }
3954:
3955: $fields = $engine->allowedSearchFields();
3956: if (!$_zp_adminJS_loaded) {
3957: $_zp_adminJS_loaded = true;
3958: ?>
3959: <script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/js/admin.js"></script>
3960: <?php
3961: }
3962: ?>
3963: <div id="<?php echo $id; ?>">
3964: <!-- search form -->
3965: <form method="post" action="<?php echo $searchurl; ?>" id="search_form">
3966: <script type="text/javascript">
3967:
3968: var within = <?php echo (int) $within; ?>;
3969: function search_(way) {
3970: within = way;
3971: if (way) {
3972: $('#search_submit').attr('title', '<?php echo sprintf($hint, $buttontext); ?>');
3973: } else {
3974: lastsearch = '';
3975: $('#search_submit').attr('title', '<?php echo $buttontext; ?>');
3976: }
3977: $('#search_input').val('');
3978: }
3979: $('#search_form').submit(function() {
3980: if (within) {
3981: var newsearch = $.trim($('#search_input').val());
3982: if (newsearch.substring(newsearch.length - 1) == ',') {
3983: newsearch = newsearch.substr(0, newsearch.length - 1);
3984: }
3985: if (newsearch.length > 0) {
3986: $('#search_input').val('(<?php echo $searchwords; ?>) AND (' + newsearch + ')');
3987: } else {
3988: $('#search_input').val('<?php echo $searchwords; ?>');
3989: }
3990: }
3991: return true;
3992: });
3993: $(document).ready(function() {
3994: $( $("#checkall_searchfields") ).on( "click", function() {
3995: $("#searchextrashow :checkbox").prop("checked", $("#checkall_searchfields").prop("checked") );
3996: });
3997: });
3998:
3999: </script>
4000: <?php echo $prevtext; ?>
4001: <div>
4002: <span class="tagSuggestContainer">
4003: <input type="text" name="words" value="" id="search_input" size="10" />
4004: </span>
4005: <?php if (count($fields) > 1 || $searchwords) { ?>
4006: <a href="javascript:toggle('searchextrashow');" ><img src="<?php echo $iconsource; ?>" title="<?php echo gettext('search options'); ?>" alt="<?php echo gettext('fields'); ?>" id="searchfields_icon" /></a>
4007: <?php } ?>
4008: <input type="<?php echo $type; ?>" <?php echo $button; ?> class="button buttons" id="search_submit" <?php echo $buttonSource; ?> data-role="none" />
4009: <?php
4010: if (is_array($object_list)) {
4011: foreach ($object_list as $key => $list) {
4012: ?>
4013: <input type="hidden" name="in<?php echo $key ?>" value="<?php
4014: if (is_array($list))
4015: echo html_encode(implode(',', $list));
4016: else
4017: echo html_encode($list);
4018: ?>" />
4019: <?php
4020: }
4021: }
4022: ?>
4023: <br />
4024: <?php
4025: if (count($fields) > 1 || $searchwords) {
4026: $fields = array_flip($fields);
4027: natcasesort($fields);
4028: $fields = array_flip($fields);
4029: if (is_null($query_fields)) {
4030: $query_fields = $engine->parseQueryFields();
4031: } else {
4032: if (!is_array($query_fields)) {
4033: $query_fields = $engine->numericFields($query_fields);
4034: }
4035: }
4036: if (count($query_fields) == 0) {
4037: $query_fields = $engine->allowedSearchFields();
4038: }
4039: ?>
4040: <div style="display:none;" id="searchextrashow">
4041: <?php
4042: if ($searchwords) {
4043: ?>
4044: <label>
4045: <input type="radio" name="search_within" id="search_within-1" value="1"<?php if ($within) echo ' checked="checked"'; ?> onclick="search_(1);" />
4046: <?php echo gettext('Within'); ?>
4047: </label>
4048: <label>
4049: <input type="radio" name="search_within" id="search_within-0" value="1"<?php if (!$within) echo ' checked="checked"'; ?> onclick="search_(0);" />
4050: <?php echo gettext('New'); ?>
4051: </label>
4052: <?php
4053: }
4054: if (count($fields) > 1) {
4055: ?>
4056: <ul>
4057: <li><label><input type="checkbox" name="checkall_searchfields" id="checkall_searchfields" checked="checked">* <?php echo gettext('Check/uncheck all'); ?> *</label></li>
4058: <?php
4059: foreach ($fields as $display => $key) {
4060: echo '<li><label><input id="SEARCH_' . $key . '" name="SEARCH_' . $key . '" type="checkbox"';
4061: if (in_array($key, $query_fields)) {
4062: echo ' checked="checked" ';
4063: }
4064: echo ' value="' . $key . '" /> ' . $display . "</label></li>" . "\n";
4065: }
4066: ?>
4067: </ul>
4068: <?php
4069: }
4070: ?>
4071: </div>
4072: <?php
4073: }
4074: ?>
4075: </div>
4076: </form>
4077: </div><!-- end of search form -->
4078: <?php
4079: }
4080:
4081: 4082: 4083: 4084: 4085: 4086:
4087: function getSearchWords() {
4088: global $_zp_current_search;
4089: if (!in_context(ZP_SEARCH))
4090: return '';
4091: return stripcslashes($_zp_current_search->codifySearchString());
4092: }
4093:
4094: 4095: 4096: 4097: 4098: 4099: 4100:
4101: function getSearchDate($format = '%B %Y') {
4102: if (in_context(ZP_SEARCH)) {
4103: global $_zp_current_search;
4104: $date = $_zp_current_search->getSearchDate();
4105: if (empty($date)) {
4106: return "";
4107: }
4108: if ($date == '0000-00') {
4109: return gettext("no date");
4110: };
4111: $dt = strtotime($date . "-01");
4112: return zpFormattedDate($format, $dt);
4113: }
4114: return false;
4115: }
4116:
4117: 4118: 4119: 4120: 4121: 4122: 4123: 4124: 4125: 4126: 4127: 4128: 4129: 4130:
4131: function setThemeColumns() {
4132: global $_zp_current_album, $_firstPageImages, $_oneImagePage;
4133: $_firstPageImages = false;
4134: if (($albumColumns = getOption('albums_per_row')) <= 1)
4135: $albumColumns = false;
4136: if (($imageColumns = getOption('images_per_row')) <= 1)
4137: $imageColumns = false;
4138: $albcount = max(1, getOption('albums_per_page'));
4139: if (($albumColumns) && (($albcount % $albumColumns) != 0)) {
4140: setOption('albums_per_page', $albcount = ((floor($albcount / $albumColumns) + 1) * $albumColumns), false);
4141: }
4142: $imgcount = max(1, getOption('images_per_page'));
4143: if (($imageColumns) && (($imgcount % $imageColumns) != 0)) {
4144: setOption('images_per_page', $imgcount = ((floor($imgcount / $imageColumns) + 1) * $imageColumns), false);
4145: }
4146: if ((getOption('thumb_transition') && !$_oneImagePage) && in_context(ZP_ALBUM | ZP_SEARCH) && $albumColumns && $imageColumns) {
4147: $count = getNumAlbums();
4148: if ($count == 0) {
4149: $_firstPageImages = 0;
4150: }
4151: $rowssused = ceil(($count % $albcount) / $albumColumns);
4152: $leftover = floor(max(1, getOption('images_per_page')) / $imageColumns) - $rowssused;
4153: $_firstPageImages = max(0, $leftover * $imageColumns);
4154: if ($_firstPageImages == $imgcount) {
4155: $_firstPageImages = 0;
4156: }
4157: }
4158: }
4159:
4160:
4161:
4162:
4163:
4164: 4165: 4166: 4167: 4168: 4169: 4170:
4171: function checkForGuest(&$hint = NULL, &$show = NULL) {
4172: global $_zp_gallery, $_zp_gallery_page, $_zp_current_zenpage_page, $_zp_current_category, $_zp_current_zenpage_news;
4173: $authType = zp_apply_filter('checkForGuest', NULL);
4174: if (!is_null($authType))
4175: return $authType;
4176: if (in_context(ZP_SEARCH)) {
4177: $hash = getOption('search_password');
4178: if (getOption('search_user') != '')
4179: $show = true;
4180: $hint = get_language_string(getOption('search_hint'));
4181: $authType = 'zp_search_auth';
4182: if (empty($hash)) {
4183: $hash = $_zp_gallery->getPassword();
4184: if ($_zp_gallery->getUser() != '')
4185: $show = true;
4186: $hint = $_zp_gallery->getPasswordHint();
4187: $authType = 'zp_gallery_auth';
4188: }
4189: if (!empty($hash) && zp_getCookie($authType) == $hash) {
4190: return $authType;
4191: }
4192: } else if (!is_null($_zp_current_zenpage_news)) {
4193: $authType = $_zp_current_zenpage_news->checkAccess($hint, $show);
4194: return $authType;
4195: } else if (isset($_GET['album'])) {
4196: list($album, $image) = rewrite_get_album_image('album', 'image');
4197: if ($authType = checkAlbumPassword($album, $hint)) {
4198: return $authType;
4199: } else {
4200: $alb = newAlbum($album);
4201: if ($alb->getUser() != '')
4202: $show = true;
4203: return false;
4204: }
4205: } else {
4206: $hash = $_zp_gallery->getPassword();
4207: if ($_zp_gallery->getUser() != '')
4208: $show = true;
4209: $hint = $_zp_gallery->getPasswordHint();
4210: if (!empty($hash) && zp_getCookie('zp_gallery_auth') == $hash) {
4211: return 'zp_gallery_auth';
4212: }
4213: }
4214: if (empty($hash))
4215: return 'zp_public_access';
4216: return false;
4217: }
4218:
4219: 4220: 4221: 4222: 4223: 4224: 4225: 4226: 4227: 4228: 4229: 4230: 4231: 4232:
4233: function checkAccess(&$hint = NULL, &$show = NULL) {
4234: global $_zp_current_album, $_zp_current_search, $_zp_gallery, $_zp_gallery_page,
4235: $_zp_current_zenpage_page, $_zp_current_zenpage_news;
4236: if (GALLERY_SECURITY != 'public')
4237: $show = true;
4238:
4239: if ($_zp_gallery->isUnprotectedPage(stripSuffix($_zp_gallery_page)))
4240: return true;
4241: if (zp_loggedin()) {
4242: $fail = zp_apply_filter('isMyItemToView', NULL);
4243: if (!is_null($fail)) {
4244: return $fail;
4245: }
4246: switch ($_zp_gallery_page) {
4247: case 'album.php':
4248: case 'image.php':
4249: if ($_zp_current_album->isMyItem(LIST_RIGHTS)) {
4250: return true;
4251: }
4252: break;
4253: case 'search.php':
4254: if (zp_loggedin(VIEW_SEARCH_RIGHTS)) {
4255: return true;
4256: }
4257: break;
4258: default:
4259: if (zp_loggedin(VIEW_GALLERY_RIGHTS)) {
4260: return true;
4261: }
4262: break;
4263: }
4264: }
4265: if (GALLERY_SECURITY == 'public' && ($access = checkForGuest($hint, $show))) {
4266: return $access;
4267: }
4268: return false;
4269: }
4270:
4271: 4272: 4273: 4274: 4275:
4276: function getPageRedirect() {
4277: global $_zp_login_error, $_zp_password_form_printed, $_zp_current_search, $_zp_gallery_page,
4278: $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news;
4279: switch ($_zp_gallery_page) {
4280: case 'index.php':
4281: $action = '/index.php';
4282: break;
4283: case 'album.php':
4284: $action = '/index.php?userlog=1&album=' . pathurlencode($_zp_current_album->name);
4285: break;
4286: case 'image.php':
4287: $action = '/index.php?userlog=1&album=' . pathurlencode($_zp_current_album->name) . '&image=' . urlencode($_zp_current_image->filename);
4288: break;
4289: case 'pages.php':
4290: $action = '/index.php?userlog=1&p=pages&title=' . urlencode(getPageTitlelink());
4291: break;
4292: case 'news.php':
4293: $action = '/index.php?userlog=1&p=news';
4294: if (!is_null($_zp_current_zenpage_news)) {
4295: $action .= '&title=' . urlencode($_zp_current_zenpage_news->getTitlelink());
4296: }
4297: break;
4298: case 'password.php':
4299: $action = str_replace(SEO_WEBPATH, '', getRequestURI());
4300: if ($action == '/' . _PAGE_ . '/password' || $action == '/index.php?p=password') {
4301: $action = '/index.php';
4302: }
4303: break;
4304: default:
4305: if (in_context(ZP_SEARCH)) {
4306: $action = '/index.php?userlog=1&p=search' . $_zp_current_search->getSearchParams();
4307: } else {
4308: $action = '/index.php?userlog=1&p=' . substr($_zp_gallery_page, 0, -4);
4309: }
4310: }
4311: return SEO_WEBPATH . $action;
4312: }
4313:
4314: 4315: 4316: 4317: 4318: 4319: 4320: 4321: 4322: 4323:
4324: function printPasswordForm($_password_hint, $_password_showuser = NULL, $_password_showProtected = true, $_password_redirect = NULL) {
4325: global $_zp_login_error, $_zp_password_form_printed, $_zp_current_search, $_zp_gallery, $_zp_gallery_page,
4326: $_zp_current_album, $_zp_current_image, $theme, $_zp_current_zenpage_page, $_zp_authority;
4327: if ($_zp_password_form_printed)
4328: return;
4329: $_zp_password_form_printed = true;
4330:
4331: if (is_null($_password_redirect))
4332: $_password_redirect = getPageRedirect();
4333:
4334: if (is_null($_password_showuser))
4335: $_password_showuser = $_zp_gallery->getUserLogonField();
4336: ?>
4337: <div id="passwordform">
4338: <?php
4339: if ($_password_showProtected && !$_zp_login_error) {
4340: ?>
4341: <p>
4342: <?php echo gettext("The page you are trying to view is password protected."); ?>
4343: </p>
4344: <?php
4345: }
4346: if ($loginlink = zp_apply_filter('login_link', NULL)) {
4347: $logintext = gettext('login');
4348: ?>
4349: <a href="<?php echo $loginlink; ?>" title="<?php echo $logintext; ?>"><?php echo $logintext; ?></a>
4350: <?php
4351: } else {
4352: $_zp_authority->printLoginForm($_password_redirect, false, $_password_showuser, false, $_password_hint);
4353: }
4354: ?>
4355: </div>
4356: <?php
4357: }
4358:
4359: 4360: 4361: 4362:
4363: function printZenphotoLink() {
4364: echo gettext("Powered by <a href=\"http://www.zenphoto.org\" title=\"A simpler web album\"><span id=\"zen-part\">zen</span><span id=\"photo-part\">PHOTO</span></a>");
4365: }
4366:
4367: 4368: 4369: 4370: 4371: 4372: 4373:
4374: function exposeZenPhotoInformations($obj = '', $plugins = '', $theme = '') {
4375: global $_zp_filters;
4376: $a = basename($obj);
4377: if ($a != 'full-image.php') {
4378: echo "\n<!-- zenphoto version " . ZENPHOTO_VERSION;
4379: if (TEST_RELEASE) {
4380: echo " [" . ZENPHOTO_FULL_RELEASE . "]";
4381: echo " THEME: " . $theme . " (" . $a . ")";
4382: $graphics = zp_graphicsLibInfo();
4383: $graphics = sanitize(str_replace('<br />', ', ', $graphics['Library_desc']), 3);
4384: echo " GRAPHICS LIB: " . $graphics . " { memory: " . INI_GET('memory_limit') . " }";
4385: echo ' PLUGINS: ';
4386: if (count($plugins) > 0) {
4387: sort($plugins);
4388: foreach ($plugins as $plugin) {
4389: echo $plugin . ' ';
4390: }
4391: } else {
4392: echo 'none ';
4393: }
4394: }
4395: echo " -->";
4396: }
4397: }
4398:
4399: 4400: 4401: 4402: 4403: 4404: 4405: 4406: 4407: 4408: 4409: 4410: 4411: 4412: 4413: 4414: 4415: 4416: 4417: 4418: 4419:
4420: function getCodeblock($number = 1, $object = NULL) {
4421: global $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_gallery, $_zp_gallery_page;
4422: if (!$number) {
4423: setOptionDefault('codeblock_first_tab', 0);
4424: }
4425: if (!is_object($object)) {
4426: if ($_zp_gallery_page == 'index.php') {
4427: $object = $_zp_gallery;
4428: }
4429: if (in_context(ZP_ALBUM)) {
4430: $object = $_zp_current_album;
4431: }
4432: if (in_context(ZP_IMAGE)) {
4433: $object = $_zp_current_image;
4434: }
4435: if (in_context(ZP_ZENPAGE_PAGE)) {
4436: if ($_zp_current_zenpage_page->checkAccess()) {
4437: $object = $_zp_current_zenpage_page;
4438: }
4439: }
4440: if (in_context(ZP_ZENPAGE_NEWS_ARTICLE)) {
4441: if ($_zp_current_zenpage_news->checkAccess()) {
4442: $object = $_zp_current_zenpage_news;
4443: }
4444: }
4445: }
4446: if (!is_object($object)) {
4447: return NULL;
4448: }
4449: $codeblock = getSerializedArray($object->getcodeblock());
4450: $codeblock = zp_apply_filter('codeblock', @$codeblock[$number], $object, $number);
4451: if ($codeblock) {
4452: $codeblock = applyMacros($codeblock);
4453: }
4454: return $codeblock;
4455: }
4456:
4457: 4458: 4459: 4460: 4461: 4462: 4463: 4464:
4465: function printCodeblock($number = 1, $what = NULL) {
4466: $codeblock = getCodeblock($number, $what);
4467: if ($codeblock) {
4468: $context = get_context();
4469: eval('?>' . $codeblock);
4470: set_context($context);
4471: }
4472: }
4473:
4474: 4475: 4476: 4477: 4478: 4479: 4480: 4481: 4482: 4483: 4484:
4485: function checkPageValidity($request, $gallery_page, $page) {
4486: global $_zp_gallery, $_firstPageImages, $_oneImagePage, $_zp_zenpage, $_zp_current_category;
4487: $count = NULL;
4488: switch ($gallery_page) {
4489: case 'album.php':
4490: case 'search.php':
4491: $albums_per_page = max(1, getOption('albums_per_page'));
4492: $pageCount = (int) ceil(getNumAlbums() / $albums_per_page);
4493: $imageCount = getNumImages();
4494: if ($_oneImagePage) {
4495: if ($_oneImagePage === true) {
4496: $imageCount = min(1, $imageCount);
4497: } else {
4498: $imageCount = 0;
4499: }
4500: }
4501: $images_per_page = max(1, getOption('images_per_page'));
4502: $count = ($pageCount + (int) ceil(($imageCount - $_firstPageImages) / $images_per_page));
4503: break;
4504: case 'index.php':
4505: if (galleryAlbumsPerPage() != 0) {
4506: $count = (int) ceil($_zp_gallery->getNumAlbums() / galleryAlbumsPerPage());
4507: }
4508: break;
4509: case 'news.php':
4510: if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
4511: $count = count($_zp_current_category->getArticles());
4512: } else {
4513: $count = count($_zp_zenpage->getArticles());
4514: }
4515: $count = (int) ceil($count / ZP_ARTICLES_PER_PAGE);
4516: break;
4517: default:
4518: $count = zp_apply_filter('checkPageValidity', NULL, $gallery_page, $page);
4519: break;
4520: }
4521: if ($page > $count) {
4522: $request = false;
4523: }
4524:
4525: return $request;
4526: }
4527:
4528: function print404status($album, $image, $obj) {
4529: global $_zp_page;
4530: echo "\n<strong>" . gettext("Zenphoto Error:</strong> the requested object was not found.");
4531: if (isset($album)) {
4532: echo '<br />' . sprintf(gettext('Album: %s'), html_encode($album));
4533:
4534: if (isset($image)) {
4535: echo '<br />' . sprintf(gettext('Image: %s'), html_encode($image));
4536: }
4537: } else {
4538: echo '<br />' . sprintf(gettext('Page: %s'), html_encode(substr(basename($obj), 0, -4)));
4539: }
4540: if (isset($_zp_page) && $_zp_page > 1) {
4541: echo '/' . $_zp_page;
4542: }
4543: }
4544:
4545: require_once(SERVERPATH . '/' . ZENFOLDER . '/template-filters.php');
4546: ?>
4547: