1<?php
2
3/**
4 * e107 website system
5 *
6 * Copyright (C) 2008-2012 e107 Inc (e107.org)
7 * Released under the terms and conditions of the
8 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
9 *
10 * @file
11 * Helper functions for "gallery" plugin.
12 */
13
14/**
15 * Helper function to load prettyPhoto library's settings and files.
16 */
17function gallery_load_prettyphoto() // @lonalore FIXME Stop loading this on every page.
18{
19
20	// Re-use the statically cached value to save memory. Load settings and files only once!!!
21	static $gallery_load_prettyphoto;
22
23	if(!isset($gallery_load_prettyphoto['loaded']) || !$gallery_load_prettyphoto['loaded'])
24	{
25		$tp = e107::getParser();
26		$plugPref = e107::getPlugConfig('gallery')->getPref();
27		$template = e107::getTemplate('gallery');
28
29		// Load prettyPhoto library.
30		e107::library('load', 'jquery.prettyPhoto');
31
32		$settings = array(
33			'prettyphoto' => array(
34				'hook'                    => $tp->toText(varset($plugPref['pp_hook'], 'data-gal')),
35				'animation_speed'         => $tp->toText(varset($plugPref['pp_animation_speed'], 'fast')),
36				'slideshow'               => (int) varset($plugPref['pp_slideshow'], 5000),
37				'autoplay_slideshow'      => (bool) varset($plugPref['pp_autoplay_slideshow'], false),
38				'opacity'                 => (float) varset($plugPref['pp_opacity'], 0.80),
39				'show_title'              => (bool) varset($plugPref['pp_show_title'], true),
40				'allow_resize'            => (bool) varset($plugPref['pp_allow_resize'], true),
41				'default_width'           => (int) varset($plugPref['pp_default_width'], 500),
42				'default_height'          => (int) varset($plugPref['pp_default_height'], 344),
43				'counter_separator_label' => $tp->toText(varset($plugPref['pp_counter_separator_label'], '/')),
44				'theme'                   => $tp->toText(varset($plugPref['pp_theme'], 'pp_default')),
45				'horizontal_padding'      => (int) varset($plugPref['pp_horizontal_padding'], 20),
46				'hideflash'               => (bool) varset($plugPref['pp_hideflash'], false),
47				'wmode'                   => $tp->toText(varset($plugPref['pp_wmode'], 'opaque')),
48				'autoplay'                => (bool) varset($plugPref['pp_autoplay'], true),
49				'modal'                   => (bool) varset($plugPref['pp_modal'], false),
50				'deeplinking'             => (bool) varset($plugPref['pp_deeplinking'], false),
51				'overlay_gallery'         => (bool) varset($plugPref['pp_overlay_gallery'], true),
52				'keyboard_shortcuts'      => (bool) varset($plugPref['pp_keyboard_shortcuts'], true),
53				'ie6_fallback'            => (bool) varset($plugPref['pp_ie6_fallback'], true),
54				'markup'                  => $template['prettyphoto']['content'],
55				'gallery_markup'          => $template['prettyphoto']['gallery_item'],
56				'image_markup'            => $template['prettyphoto']['image_item'],
57				'flash_markup'            => $template['prettyphoto']['flash_item'],
58				'quicktime_markup'        => $template['prettyphoto']['quicktime_item'],
59				'iframe_markup'           => $template['prettyphoto']['iframe_item'],
60				'inline_markup'           => $template['prettyphoto']['inline_item'],
61				'custom_markup'           => $template['prettyphoto']['custom_item'],
62				'social_tools'            => $template['prettyphoto']['social_item'],
63			),
64		);
65
66		if(vartrue($plugPref['downloadable'], false))
67		{
68			$settings['prettyphoto']['image_markup'] .= '<span class="download-btn">';
69			$settings['prettyphoto']['image_markup'] .= '<a class="btn btn-default btn-secondary btn-xs" href="{path}">' . LAN_DOWNLOAD . '</a>';
70			$settings['prettyphoto']['image_markup'] .= '</span>';
71		}
72
73		e107::js('settings', array('gallery' => $settings));
74		e107::js('gallery', 'js/gallery.js');
75
76		$gallery_load_prettyphoto['loaded'] = true;
77	}
78}
79