1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: $plugin_description = gettext("jQuery jCarousel thumb nav plugin with dynamic loading of thumbs on request via JavaScript.");
13: $plugin_author = "Malte Müller (acrylian) based on a jCarousel example";
14: $plugin_disable = (extensionEnabled('bxslider_thumb_nav')) ? sprintf(gettext('Only one Carousel plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), 'bxslider_thumb_nav') : '';
15:
16: $option_interface = 'jcarousel';
17:
18: 19: 20: 21:
22: class jcarousel {
23:
24: function __construct() {
25: if (OFFSET_PATH == 2) {
26: setOptionDefault('jcarousel_scroll', '3');
27: setOptionDefault('jcarousel_width', '50');
28: setOptionDefault('jcarousel_height', '50');
29: setOptionDefault('jcarousel_croph', '50');
30: setOptionDefault('jcarousel_cropw', '50');
31: setOptionDefault('jcarousel_fullimagelink', '');
32: setOptionDefault('jcarousel_vertical', 0);
33: if (class_exists('cacheManager')) {
34: cacheManager::deleteThemeCacheSizes('jcarousel_thumb_nav');
35: cacheManager::addThemeCacheSize('jcarousel_thumb_nav', NULL, getOption('jcarousel_width'), getOption('jcarousel_height'), getOption('jcarousel_cropw'), getOption('jcarousel_croph'), NULL, NULL, true, NULL, NULL, NULL);
36: }
37: }
38: }
39:
40: function getOptionsSupported() {
41: global $_zp_gallery;
42: $options = array(gettext('Thumbs number') => array('key' => 'jcarousel_scroll', 'type' => OPTION_TYPE_TEXTBOX,
43: 'desc' => gettext("The number of thumbs to scroll by. Note that the CSS might need to be adjusted.")),
44: gettext('width') => array('key' => 'jcarousel_width', 'type' => OPTION_TYPE_TEXTBOX,
45: 'desc' => gettext("Width of the carousel. Note that the CSS might need to be adjusted.")),
46: gettext('height') => array('key' => 'jcarousel_height', 'type' => OPTION_TYPE_TEXTBOX,
47: 'desc' => gettext("Height of the carousel. Note that the CSS might need to be adjusted.")),
48: gettext('Crop width') => array('key' => 'jcarousel_cropw', 'type' => OPTION_TYPE_TEXTBOX,
49: 'desc' => ""),
50: gettext('Crop height') => array('key' => 'jcarousel_croph', 'type' => OPTION_TYPE_TEXTBOX,
51: 'desc' => ""),
52: gettext('Full image link') => array('key' => 'jcarousel_fullimagelink', 'type' => OPTION_TYPE_CHECKBOX,
53: 'desc' => gettext("If checked the thumbs link to the full image instead of the image page.")),
54: gettext('Vertical') => array('key' => 'jcarousel_vertical', 'type' => OPTION_TYPE_CHECKBOX,
55: 'desc' => gettext("If checked the carousel will flow vertically instead of the default horizontal. Changing this may require theme changes!"))
56: );
57: foreach (getThemeFiles(array('404.php', 'themeoptions.php', 'theme_description.php', 'functions.php', 'password.php', 'sidebar.php', 'register.php', 'contact.php')) as $theme => $scripts) {
58: $list = array();
59: foreach ($scripts as $script) {
60: $list[$script] = 'jcarousel_' . $theme . '_' . stripSuffix($script);
61: }
62: $options[$theme] = array('key' => 'jcarousel_' . $theme . '_scripts', 'type' => OPTION_TYPE_CHECKBOX_ARRAY,
63: 'checkboxes' => $list,
64: 'desc' => gettext('The scripts for which jCarousel is enabled. {If themes require it they might set this, otherwise you need to do it manually!}')
65: );
66: }
67: return $options;
68: }
69:
70: static function themeJS() {
71: $theme = getCurrentTheme();
72: $css = SERVERPATH . '/' . THEMEFOLDER . '/' . internalToFilesystem($theme) . '/jcarousel.css';
73: if (file_exists($css)) {
74: $css = WEBPATH . '/' . THEMEFOLDER . '/' . $theme . '/jcarousel.css';
75: } else {
76: $css = WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/jcarousel_thumb_nav/jcarousel.css';
77: }
78: ?>
79: <script>
80: (function($) {
81: var userAgent = navigator.userAgent.toLowerCase();
82:
83: $.browser = {
84: version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
85: safari: /webkit/.test(userAgent),
86: opera: /opera/.test(userAgent),
87: msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
88: mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
89: };
90:
91: })(jQuery);
92: </script>
93: <script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/jcarousel_thumb_nav/jquery.jcarousel.pack.js"></script>
94: <link rel="stylesheet" type="text/css" href="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/jcarousel_thumb_nav/jquery.jcarousel.css" />
95: <link rel="stylesheet" type="text/css" href="<?php echo html_encode($css); ?>" />
96: <?php
97: }
98:
99: }
100:
101: if (!$plugin_disable && !OFFSET_PATH && getOption('jcarousel_' . $_zp_gallery->getCurrentTheme() . '_' . stripSuffix($_zp_gallery_page))) {
102: zp_register_filter('theme_head', 'jcarousel::themeJS');
103:
104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116:
117: function printThumbNav($minitems = NULL, $maxitems = NULL, $width = NULL, $height = NULL, $cropw = NULL, $croph = NULL, $fullimagelink = NULL, $vertical = NULL, $speed = NULL, $thumbscroll = NULL) {
118: global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_search, $_zp_gallery_page;
119:
120: setOptionDefault('slideshow_' . $_zp_gallery->getCurrentTheme() . '_' . stripSuffix($_zp_gallery_page), 1);
121: $items = "";
122: if (is_object($_zp_current_album) && $_zp_current_album->getNumImages() >= 2) {
123: if (is_null($thumbscroll)) {
124: $thumbscroll = getOption('jcarousel_scroll');
125: } else {
126: $thumbscroll = sanitize_numeric($thumbscroll);
127: }
128: if (is_null($width)) {
129: $width = getOption('jcarousel_width');
130: } else {
131: $width = sanitize_numeric($width);
132: }
133: if (is_null($height)) {
134: $height = getOption('jcarousel_height');
135: } else {
136: $height = sanitize_numeric($height);
137: }
138: if (is_null($cropw)) {
139: $cropw = getOption('jcarousel_cropw');
140: } else {
141: $cropw = sanitize_numeric($cropw);
142: }
143: if (is_null($croph)) {
144: $croph = getOption('jcarousel_croph');
145: } else {
146: $croph = sanitize_numeric($croph);
147: }
148: if (is_null($fullimagelink)) {
149: $fullimagelink = getOption('jcarousel_fullimagelink');
150: } else {
151: $fullimagelink = sanitize($fullimagelink);
152: }
153: if (is_null($vertical)) {
154: $vertical = getOption('jcarousel_vertical');
155: } else {
156: $vertical = sanitize($vertical);
157: }
158: if ($vertical) {
159: $vertical = 'true';
160: } else {
161: $vertical = 'false';
162: }
163: if (in_context(ZP_SEARCH_LINKED)) {
164: if ($_zp_current_search->getNumImages() === 0) {
165: $searchimages = false;
166: } else {
167: $searchimages = true;
168: }
169: } else {
170: $searchimages = false;
171: }
172: if (in_context(ZP_SEARCH_LINKED) && $searchimages) {
173: $jcarousel_items = $_zp_current_search->getImages();
174: } else {
175: $jcarousel_items = $_zp_current_album->getImages();
176: }
177: if (count($jcarousel_items) >= 2) {
178: foreach ($jcarousel_items as $item) {
179: if (is_array($item)) {
180: $imgobj = newImage($_zp_current_album, $item['filename']);
181: } else {
182: $imgobj = newImage($_zp_current_album, $item);
183: }
184: if ($fullimagelink) {
185: $link = $imgobj->getFullImageURL();
186: } else {
187: $link = $imgobj->getLink();
188: }
189: if (!is_null($_zp_current_image)) {
190: if ($_zp_current_album->isDynamic()) {
191: if ($_zp_current_image->filename == $imgobj->filename && $_zp_current_image->getAlbum()->name == $imgobj->getAlbum()->name) {
192: $active = 'active';
193: } else {
194: $active = '';
195: }
196: } else {
197: if ($_zp_current_image->filename == $imgobj->filename) {
198: $active = 'active';
199: } else {
200: $active = '';
201: }
202: }
203: } else {
204: $active = '';
205: }
206: $imageurl = $imgobj->getCustomImage(NULL, $width, $height, $cropw, $croph, NULL, NULL, true);
207: $items .= ' {url: "' . html_encode($imageurl) . '", title: "' . html_encode($imgobj->getTitle()) . '", link: "' . html_encode($link) . '", active: "' . $active . '"},';
208: $items .= "\n";
209: }
210: }
211: $items = substr($items, 0, -2);
212: $numimages = getNumImages();
213: if (!is_null($_zp_current_image)) {
214: $imgnumber = imageNumber();
215: } else {
216: $imgnumber = 1;
217: }
218: ?>
219: <script type="text/javascript">
220:
221: var mycarousel_itemList = [
222: <?php echo $items; ?>
223: ];
224:
225: function mycarousel_itemLoadCallback(carousel, state) {
226: for (var i = carousel.first; i <= carousel.last; i++) {
227: if (carousel.has(i)) {
228: continue;
229: }
230: if (i > mycarousel_itemList.length) {
231: break;
232: }
233: carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i - 1]));
234: }
235: }
236:
237: function mycarousel_getItemHTML(item) {
238: if (item.active === "") {
239: html = '<a href="' + item.link + '" title="' + item.title + '"><img src="' + item.url + '" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="' + item.url + '" /></a>';
240: } else {
241: html = '<a href="' + item.link + '" title="' + item.title + '"><img class="activecarouselimage" src="' + item.url + '" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="' + item.url + '" /></a>';
242: }
243: return html;
244: }
245:
246: jQuery(document).ready(function() {
247: jQuery("#mycarousel").jcarousel({
248: vertical: <?php echo $vertical; ?>,
249: size: mycarousel_itemList.length,
250: start: <?php echo $imgnumber; ?>,
251: scroll: <?php echo $thumbscroll; ?>,
252: itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
253: });
254: });
255:
256: </script>
257: <ul id="mycarousel">
258: <!-- The content will be dynamically loaded in here -->
259: </ul>
260: <?php
261: }
262: }
263:
264: }
265: ?>