1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: $plugin_description = gettext("Adds a theme function to print an album menu either as a nested list or as a dropdown menu.");
21: $plugin_author = "Malte Müller (acrylian), Stephen Billard (sbillard)";
22:
23: $option_interface = 'print_album_menu';
24:
25: if (!defined('MENU_TRUNCATE_STRING'))
26: define('MENU_TRUNCATE_STRING', getOption('menu_truncate_string'));
27: if (!defined('MENU_TRUNCATE_INDICATOR'))
28: define('MENU_TRUNCATE_INDICATOR', getOption('menu_truncate_indicator'));
29: define('ALBUM_MENU_COUNT', getOption('print_album_menu_count'));
30: define('ALBUM_MENU_SHOWSUBS', getOption('print_album_menu_showsubs'));
31:
32: $_recursion_limiter = array();
33:
34: 35: 36: 37:
38: class print_album_menu {
39:
40: function __construct() {
41: setOptionDefault('print_album_menu_showsubs', 0);
42: setOptionDefault('print_album_menu_count', 1);
43: setOptionDefault('menu_truncate_string', 0);
44: setOptionDefault('menu_truncate_indicator', '');
45: }
46:
47: function getOptionsSupported() {
48: global $_common_truncate_handler;
49: $options = array(gettext('"List" subalbum level') => array('key' => 'print_album_menu_showsubs', 'type' => OPTION_TYPE_TEXTBOX,
50: 'order' => 0,
51: 'desc' => gettext('The depth of subalbum levels shown with the <code>printAlbumMenu</code> and <code>printAlbumMenuList</code> “List” option. Note: themes may override this default.')),
52: gettext('Show counts') => array('key' => 'print_album_menu_count', 'type' => OPTION_TYPE_CHECKBOX,
53: 'order' => 1,
54: 'desc' => gettext('If checked, image and album counts will be included in the list. Note: Themes may override this option.')),
55: gettext('Truncate titles*') => array('key' => 'menu_truncate_string', 'type' => OPTION_TYPE_TEXTBOX,
56: 'disabled' => $_common_truncate_handler,
57: 'order' => 6,
58: 'desc' => gettext('Limit titles to this many characters. Zero means no limit.')),
59: gettext('Truncate indicator*') => array('key' => 'menu_truncate_indicator', 'type' => OPTION_TYPE_TEXTBOX,
60: 'disabled' => $_common_truncate_handler,
61: 'order' => 7,
62: 'desc' => gettext('Append this string to truncated titles.'))
63: );
64: if ($_common_truncate_handler) {
65: $options['note'] = array('key' => 'menu_truncate_note', 'type' => OPTION_TYPE_NOTE,
66: 'order' => 8,
67: 'desc' => '<p class="notebox">' . $_common_truncate_handler . '</p>');
68: } else {
69: $_common_truncate_handler = gettext('* These options may be set via the <a href="javascript:gotoName(\'print_album_menu\');"><em>print_album_menu</em></a> plugin options.');
70: $options['note'] = array('key' => 'menu_truncate_note',
71: 'type' => OPTION_TYPE_NOTE,
72: 'order' => 8,
73: 'desc' => gettext('<p class="notebox">*<strong>Note:</strong> The setting of these options may be shared with other plugins.</p>'));
74: }
75: return $options;
76: }
77:
78: function handleOption($option, $currentValue) {
79:
80: }
81:
82: }
83:
84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112:
113: function printAlbumMenu($option, $showcount = NULL, $css_id = '', $css_class_topactive = '', $css_class = '', $css_class_active = '', $indexname = "Gallery Index", $showsubs = NULL, $firstimagelink = false, $keeptopactive = false) {
114: if ($option == "jump") {
115: printAlbumMenuJump($showcount, $indexname, $firstimagelink,$showsubs);
116: } else {
117: printAlbumMenuList($option, $showcount, $css_id, $css_class_topactive, $css_class, $css_class_active, $indexname, $showsubs, $firstimagelink, $keeptopactive);
118: }
119: }
120:
121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145:
146: function printAlbumMenuList($option, $showcount = NULL, $css_id = '', $css_class_topactive = '', $css_class = '', $css_class_active = '', $indexname = "Gallery Index", $showsubs = NULL, $firstimagelink = false, $keeptopactive = false, $startlist = true, $limit = NULL) {
147: global $_zp_gallery, $_zp_current_album, $_zp_gallery_page;
148:
149: if (in_context(ZP_SEARCH_LINKED)) {
150: $option = "list-top";
151: }
152:
153: $albumpath = rewrite_path("/", "/index.php?album=");
154: if (empty($_zp_current_album) || ($_zp_gallery_page != 'album.php' && $_zp_gallery_page != 'image.php')) {
155: $currentfolder = "";
156: } else {
157: $currentfolder = $_zp_current_album->name;
158: }
159:
160: if (is_null($css_id)) {
161: $css_id = 'menu_albums';
162: }
163: if (is_null($css_class_topactive)) {
164: $css_class_topactive = 'menu_topactive';
165: }
166: if (is_null($css_class)) {
167: $css_class = 'submenu';
168: }
169: if (is_null($css_class_active)) {
170: $css_class_active = 'menu-active';
171: }
172:
173: $startlist = $startlist && !($option == 'omit-top' || $option == 'list-sub');
174: if ($startlist)
175: echo '<ul id="'. $css_id . '">'."\n";
176:
177: if ($option === "list" OR $option === "list-top") {
178: if (!empty($indexname)) {
179: echo "<li><a href='" . html_encode(getGalleryIndexURL()) . "' title='" . html_encode($indexname) . "'>" . $indexname . "</a></li>";
180: }
181: }
182:
183: if ($option == 'list-sub' && in_context(ZP_ALBUM)) {
184: $albums = $_zp_current_album->getAlbums();
185: } else {
186: $albums = $_zp_gallery->getAlbums();
187: }
188:
189: printAlbumMenuListAlbum($albums, $currentfolder, $option, $showcount, $showsubs, $css_class, $css_class_topactive, $css_class_active, $firstimagelink, $keeptopactive, $limit);
190:
191: if ($startlist)
192: echo "</ul>\n";
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209:
210: function printAlbumMenuListAlbum($albums, $folder, $option, $showcount, $showsubs, $css_class, $css_class_topactive, $css_class_active, $firstimagelink, $keeptopactive, $limit = NULL) {
211: global $_zp_gallery, $_zp_current_album, $_zp_current_search, $_recursion_limiter;
212: if (is_null($limit)) {
213: $limit = MENU_TRUNCATE_STRING;
214: }
215: if (is_null($showcount)) {
216: $showcount = ALBUM_MENU_COUNT;
217: }
218: if (is_null($showsubs)) {
219: $showsubs = ALBUM_MENU_SHOWSUBS;
220: }
221: if ($showsubs && !is_numeric($showsubs)) {
222: $showsubs = 9999999999;
223: }
224: $pagelevel = count(explode('/', $folder));
225: $currenturalbumname = "";
226:
227: foreach ($albums as $album) {
228:
229: $level = count(explode('/', $album));
230: $process = (($level < $showsubs && $option == "list")
231: || ($option != 'list-top'
232: && strpos($folder, $album) === 0
233: && $level <= $pagelevel)
234: );
235:
236: if ($process && hasDynamicAlbumSuffix($album) && !is_dir(ALBUM_FOLDER_SERVERPATH . $album)) {
237: if (in_array($album, $_recursion_limiter))
238: $process = false;
239: }
240: $topalbum = '';
241: $albumobj = newAlbum($album, true);
242: $has_password = '';
243: if($albumobj->isProtected()) {
244: $has_password = ' has_password';
245: }
246: if ($level > 1 || ($option != 'omit-top')) {
247: if ($level == 1) {
248: $css_class_t = $css_class_topactive . $has_password;
249: } else {
250: $css_class_t = $css_class_active . $has_password;
251: }
252: if ($keeptopactive) {
253: if (isset($_zp_current_album) && is_object($_zp_current_album)) {
254: $currenturalbum = getUrAlbum($_zp_current_album);
255: $currenturalbumname = $currenturalbum->name;
256: }
257: }
258: $count = "";
259: if ($showcount) {
260: $toplevelsubalbums = $albumobj->getAlbums();
261: $toplevelsubalbums = count($toplevelsubalbums);
262: $topalbumnumimages = $albumobj->getNumImages();
263: if ($topalbumnumimages + $toplevelsubalbums > 0) {
264: $count = ' <span style="white-space:nowrap;"><small>(';
265: if ($toplevelsubalbums > 0) {
266: $count .= sprintf(ngettext('%u album', '%u albums', $toplevelsubalbums), $toplevelsubalbums);
267: }
268: if ($topalbumnumimages > 0) {
269: if ($toplevelsubalbums) {
270: $count .= ' ';
271: }
272: $count .= sprintf(ngettext('%u image', '%u images', $topalbumnumimages), $topalbumnumimages);
273: }
274: $count .= ')</small></span>';
275: }
276: }
277:
278: if ((in_context(ZP_ALBUM) && !in_context(ZP_SEARCH_LINKED) && (@$_zp_current_album->getID() == $albumobj->getID() ||
279: $albumobj->name == $currenturalbumname)) ||
280: (in_context(ZP_SEARCH_LINKED)) && ($a = $_zp_current_search->getDynamicAlbum()) && $a->name == $albumobj->name) {
281: $current = $css_class_t;
282: } else {
283: $current = "";
284: }
285: $title = $albumobj->getTitle();
286: if ($limit) {
287: $display = shortenContent($title, $limit, MENU_TRUNCATE_INDICATOR);
288: } else {
289: $display = $title;
290: }
291: if ($firstimagelink && $albumobj->getNumImages() != 0) {
292: $link = '<li><a class="' . $current . '" href="' . html_encode($albumobj->getImage(0)->getLink()) . '" title="' . html_encode($title) . '">' . html_encode($display) . '</a>' . $count;
293: } else {
294: $link = '<li><a class="' . $current . '" href="' . html_encode($albumobj->getLink(1)) . '" title="' . html_encode($title) . '">' . html_encode($display) . '</a>' . $count;
295: }
296: echo $link;
297: }
298: if ($process) {
299: $subalbums = $albumobj->getAlbums();
300: if (!empty($subalbums)) {
301: echo "\n".'<ul class="' . $css_class . '">'."\n";
302: array_push($_recursion_limiter, $album);
303: printAlbumMenuListAlbum($subalbums, $folder, $option, $showcount, $showsubs, $css_class, $css_class_topactive, $css_class_active, $firstimagelink, false, $limit);
304: array_pop($_recursion_limiter);
305: echo "\n</ul>\n";
306: }
307: }
308: if ($option == 'list' || $option == 'list-top' || $level > 1) {
309: echo "\n</li>\n";
310: }
311: }
312: }
313:
314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327:
328: function printAlbumMenuJump($option = "count", $indexname = "Gallery Index", $firstimagelink = false, $showsubs = NULL, $skipform = false) {
329: global $_zp_gallery, $_zp_current_album, $_zp_gallery_page;
330: if (!is_null($_zp_current_album) || $_zp_gallery_page == 'album.php') {
331: $currentfolder = $_zp_current_album->name;
332: }
333: if (is_null($showsubs)) {
334: $showsubs = ALBUM_MENU_SHOWSUBS;
335: }
336: if ($showsubs && !is_numeric($showsubs)) {
337: $showsubs = 9999999999;
338: }
339: if(!$skipform) {
340: ?>
341: <script type="text/javaScript">
342:
343: function gotoLink(form) {
344: var OptionIndex=form.ListBoxURL.selectedIndex;
345: parent.location = form.ListBoxURL.options[OptionIndex].value;
346: }
347:
348: </script>
349: <form name="AutoListBox" action="#">
350: <p>
351: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form);">
352: <?php
353: if (!empty($indexname)) {
354: $selected = checkSelectedAlbum("", "index");
355: ?>
356: <option <?php echo $selected; ?> value="<?php echo html_encode(getGalleryIndexURL()); ?>"><?php echo $indexname; ?></option>
357: <?php
358: }
359: }
360: $albums = getNestedAlbumList(null, $showsubs, false);
361: foreach($albums as $album) {
362: $albumobj = newAlbum($album['name'], true);
363: $count = '';
364: if ($option == "count") {
365: $numimages = $albumobj->getNumImages();
366: if($numimages != 0) {
367: $count = " (" . $numimages . ")";
368: }
369: }
370: $sortorder = count($album['sort_order']);
371: $arrow = '';
372: if($sortorder > 1) {
373: for($c = 1; $c != $sortorder; $c++) {
374: $arrow .= '» ';
375: }
376: }
377: $selected = checkSelectedAlbum($albumobj->name, "album");
378: if ($firstimagelink && $numimages != 0) {
379: $link = "<option $selected value='" . html_encode($albumobj->getImage(0)->getLink()) . "'>" . $arrow . getBare($albumobj->getTitle()) . $count . "</option>";
380: } else {
381: $link = "<option $selected value='" . html_encode($albumobj->getLink(1)) . "'>" . $arrow . getBare($albumobj->getTitle()) . $count . "</option>";
382: }
383: echo $link;
384: }
385: if(!$skipform) { ?>
386: </select>
387: </p>
388: </form>
389: <?php
390: }
391: }
392:
393: 394: 395: 396: 397: 398: 399: 400: 401:
402: function checkSelectedAlbum($checkalbum, $option) {
403: global $_zp_current_album, $_zp_gallery_page;
404: if (is_object($_zp_current_album)) {
405: $currentalbumname = $_zp_current_album->name;
406: } else {
407: $currentalbumname = "";
408: }
409: $selected = "";
410: switch ($option) {
411: case "index":
412: if ($_zp_gallery_page === "index.php") {
413: $selected = "selected";
414: }
415: break;
416: case "album":
417: if ($currentalbumname === $checkalbum) {
418: $selected = "selected";
419: }
420: break;
421: }
422: return $selected;
423: }
424: ?>