C_Lightbox_Library_Manager

The NextGEN Gallery C Lightbox Library Manager class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/lightbox/package.module.lightbox.php  
  1. class C_Lightbox_Library_Manager 
  2. private $_lightboxes = array(); 
  3. private $_registered_defaults = FALSE; 
  4. /** 
  5. * @var C_Lightbox_Library_Manager 
  6. */ 
  7. static $_instance = NULL; 
  8. static function get_instance() 
  9. if (!isset(self::$_instance)) { 
  10. $klass = get_class(); 
  11. self::$_instance = new $klass(); 
  12. return self::$_instance; 
  13. function register_defaults() 
  14. $settings = C_NextGen_Settings::get_instance(); 
  15. $fs = C_Fs::get_instance(); 
  16. $router = C_Router::get_instance(); 
  17. // Add none as an option 
  18. $none = new C_NGG_Lightbox('none'); 
  19. $none->title = __('None', 'nggallery'); 
  20. $this->register('none', $none); 
  21. // Add Fancybox 
  22. $fancybox = new C_NGG_Lightbox('fancybox'); 
  23. $fancybox->title = __('Fancybox', 'nggallery'); 
  24. $fancybox->code = 'class="ngg-fancybox" rel="%GALLERY_NAME%"'; 
  25. $fancybox->styles = array('photocrati-lightbox#fancybox/jquery.fancybox-1.3.4.css'); 
  26. $fancybox->scripts = array('photocrati-lightbox#fancybox/jquery.easing-1.3.pack.js', 'photocrati-lightbox#fancybox/jquery.fancybox-1.3.4.pack.js', 'photocrati-lightbox#fancybox/nextgen_fancybox_init.js'); 
  27. $this->register('fancybox', $fancybox); 
  28. // Add Shutter 
  29. $shutter = new C_NGG_Lightbox('shutter'); 
  30. $shutter->title = __('Shutter', 'nggallery'); 
  31. $shutter->code = 'class="shutterset_%GALLERY_NAME%"'; 
  32. $shutter->styles = array('photocrati-lightbox#shutter/shutter.css'); 
  33. $shutter->scripts = array('photocrati-lightbox#shutter/shutter.js', 'photocrati-lightbox#shutter/nextgen_shutter.js'); 
  34. $shutter->values = array('nextgen_shutter_i18n' => array('msgLoading' => __('L O A D I N G', 'nggallery'), 'msgClose' => __('Click to Close', 'nggallery'))); 
  35. $this->register('shutter', $shutter); 
  36. // Add shutter reloaded 
  37. $shutter2 = new C_NGG_Lightbox('shutter2'); 
  38. $shutter2->title = __('Shutter Reloaded', 'nggallery'); 
  39. $shutter2->code = 'class="shutterset_%GALLERY_NAME%"'; 
  40. $shutter2->styles = array('photocrati-lightbox#shutter_reloaded/shutter.css'); 
  41. $shutter2->scripts = array('photocrati-lightbox#shutter_reloaded/shutter.js', 'photocrati-lightbox#shutter_reloaded/nextgen_shutter_reloaded.js'); 
  42. $shutter2->values = array('nextgen_shutter2_i18n' => array(__('Previous', 'nggallery'), __('Next', 'nggallery'), __('Close', 'nggallery'), __('Full Size', 'nggallery'), __('Fit to Screen', 'nggallery'), __('Image', 'nggallery'), __('of', 'nggallery'), __('Loading...', 'nggallery'))); 
  43. $this->register('shutter2', $shutter2); 
  44. // Add Thickbox 
  45. $thickbox = new C_NGG_Lightbox('thickbox'); 
  46. $thickbox->title = __('Thickbox', 'nggallery'); 
  47. $thickbox->code = "class='thickbox' rel='%GALLERY_NAME%'"; 
  48. $thickbox->styles = array('wordpress#thickbox'); 
  49. $thickbox->scripts = array('photocrati-lightbox#thickbox/nextgen_thickbox_init.js', 'wordpress#thickbox'); 
  50. $thickbox->values = array('nextgen_thickbox_i18n' => array('next' => __('Next >', 'nggallery'), 'prev' => __('< Prev', 'nggallery'), 'image' => __('Image', 'nggallery'), 'of' => __('of', 'nggallery'), 'close' => __('Close', 'nggallery'), 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.', 'nggallery'))); 
  51. $this->register('thickbox', $thickbox); 
  52. // Allow third parties to integrate 
  53. do_action('ngg_registered_default_lightboxes'); 
  54. // Add custom option 
  55. $custom = new C_NGG_Lightbox('custom'); 
  56. $custom->title = __('Custom', 'nggallery'); 
  57. $custom->code = $settings->thumbEffectCode; 
  58. $custom->styles = $settings->thumbEffectStyles; 
  59. $custom->scripts = $settings->thumbEffectScripts; 
  60. $this->register('custom_lightbox', $custom); 
  61. $this->_registered_defaults = TRUE; 
  62. function register($name, $properties) 
  63. // We'll use an object to represent the lightbox 
  64. $object = $properties; 
  65. if (!is_object($properties)) { 
  66. $object = new stdClass(); 
  67. foreach ($properties as $k => $v) { 
  68. $object->{$k} = $v; 
  69. // Set default properties 
  70. $object->name = $name; 
  71. if (!isset($object->title)) { 
  72. $object->title = $name; 
  73. if (!isset($object->code)) { 
  74. $object->code = ''; 
  75. if (!isset($object->scripts)) { 
  76. $object->scripts = array(); 
  77. if (!isset($object->styles)) { 
  78. $object->styles = array(); 
  79. if (!isset($object->values)) { 
  80. $object->values = array(); 
  81. $this->_lightboxes[$name] = $object; 
  82. function deregister($name) 
  83. unset($this->_lightboxes[$name]); 
  84. function get($name) 
  85. if (!$this->_registered_defaults) { 
  86. $this->register_defaults(); 
  87. $retval = NULL; 
  88. if (isset($this->_lightboxes[$name])) { 
  89. $retval = $this->_lightboxes[$name]; 
  90. return $retval; 
  91. /** 
  92. * Returns which lightbox effect has been chosen 
  93. * Highslide and jQuery.Lightbox were removed in 2.0.73 due to licensing. If a user has selected 
  94. * either of those options we silently make their selection fallback to Fancybox 
  95. * @return null|string 
  96. */ 
  97. function get_selected() 
  98. $settings = C_NextGen_Settings::get_instance(); 
  99. if (in_array($settings->thumbEffect, array('highslide', 'lightbox'))) { 
  100. $settings->thumbEffect = 'fancybox'; 
  101. return $this->get($settings->thumbEffect); 
  102. function get_selected_context() 
  103. return C_NextGen_Settings::get_instance()->thumbEffectContext; 
  104. function get_all() 
  105. if (!$this->_registered_defaults) { 
  106. $this->register_defaults(); 
  107. return array_values($this->_lightboxes); 
  108. function is_registered($name) 
  109. return !is_null($this->get($name)); 
  110. function maybe_enqueue() 
  111. $settings = C_NextGen_Settings::get_instance(); 
  112. $thumbEffectContext = isset($settings->thumbEffectContext) ? $settings->thumbEffectContext : ''; 
  113. if ($thumbEffectContext != 'nextgen_images') { 
  114. $this->enqueue(); 
  115. function enqueue($lightbox = NULL) 
  116. $router = C_Router::get_instance(); 
  117. $settings = C_NextGen_Settings::get_instance(); 
  118. $thumbEffectContext = isset($settings->thumbEffectContext) ? $settings->thumbEffectContext : ''; 
  119. // If no lightbox has been provided, get the selected lightbox 
  120. if (!$lightbox) { 
  121. $lightbox = $this->get_selected(); 
  122. } else { 
  123. $lightbox = $this->get($lightbox); 
  124. if (!wp_script_is('ngg_lightbox_context')) { 
  125. wp_enqueue_script('ngg_lightbox_context', $router->get_static_url('photocrati-lightbox#lightbox_context.js'), array('ngg_common', 'photocrati_ajax'), NGG_SCRIPT_VERSION, TRUE); 
  126. // Make the path to the static resources available for libraries 
  127. // Shutter-Reloaded in particular depends on this 
  128. $this->_add_script_data('ngg_common', 'nextgen_lightbox_settings', array('static_path' => $router->get_static_url('', 'photocrati-lightbox'), 'context' => $thumbEffectContext), TRUE, TRUE); 
  129. // Enqueue lightbox resources, only if we have a configured lightbox 
  130. if ($lightbox) { 
  131. // Add lightbox script data 
  132. if (isset($lightbox->values)) { 
  133. foreach ($lightbox->values as $name => $value) { 
  134. if (empty($value)) { 
  135. continue; 
  136. $this->_add_script_data('ngg_lightbox_context', $name, $value, TRUE); 
  137. // Enqueue stylesheets 
  138. for ($i = 0; $i < count($lightbox->styles); $i++) { 
  139. $src = $lightbox->styles[$i]; 
  140. if (strpos($src, 'wordpress#') === 0) { 
  141. $parts = explode('wordpress#', $src); 
  142. wp_enqueue_style(array_pop($parts)); 
  143. } else { 
  144. if (!empty($src)) { 
  145. wp_enqueue_style($lightbox->name . "-{$i}", $this->_handle_url($src), FALSE, NGG_SCRIPT_VERSION); 
  146. // Enqueue scripts 
  147. for ($i = 0; $i < count($lightbox->scripts); $i++) { 
  148. $src = $lightbox->scripts[$i]; 
  149. $handle = $lightbox->name . "-{$i}"; 
  150. if (strpos($src, 'wordpress#') === 0) { 
  151. $parts = explode('wordpress#', $src); 
  152. wp_enqueue_script(array_pop($parts)); 
  153. } else { 
  154. if (!empty($src)) { 
  155. wp_enqueue_script($handle, $this->_handle_url($src), array('ngg_lightbox_context'), NGG_SCRIPT_VERSION, TRUE); 
  156. /** 
  157. * Parses certain paths through get_static_url 
  158. * @param string $url 
  159. * @return string Resulting URL 
  160. */ 
  161. static function _handle_url($url, $type = 'script') 
  162. $router = C_Router::get_instance(); 
  163. if (0 !== strpos($url, '/') && 0 !== strpos($url, 'wordpress#') && 0 !== strpos($url, 'http://') && 0 !== strpos($url, 'https://')) { 
  164. $url = $router->get_static_url($url); 
  165. } elseif (strpos($url, '/') === 0) { 
  166. $url = home_url($url); 
  167. return $url; 
  168. /** 
  169. * Adds data to the DOM which is then accessible by a script -- borrowed from display type controller class 
  170. * @param string $handle 
  171. * @param string $object_name 
  172. * @param mixed $object_value 
  173. * @param bool $define 
  174. */ 
  175. function _add_script_data($handle, $object_name, $object_value, $define = TRUE, $override = FALSE) 
  176. $retval = FALSE; 
  177. // wp_localize_script allows you to add data to the DOM, associated 
  178. // with a particular script. You can even call wp_localize_script 
  179. // multiple times to add multiple objects to the DOM. However, there 
  180. // are a few problems with wp_localize_script: 
  181. // 
  182. // - If you call it with the same object_name more than once, you're 
  183. // overwritting the first call. 
  184. // - You cannot namespace your objects due to the "var" keyword always 
  185. // - being used. 
  186. // 
  187. // To circumvent the above issues, we're going to use the WP_Scripts 
  188. // object to workaround the above issues 
  189. global $wp_scripts; 
  190. // Has the script been registered or enqueued yet? 
  191. if (isset($wp_scripts->registered[$handle])) { 
  192. // Get the associated data with this script 
  193. $script =& $wp_scripts->registered[$handle]; 
  194. $data = isset($script->extra['data']) ? $script->extra['data'] : ''; 
  195. // Construct the addition 
  196. $addition = $define ? "\nvar {$object_name} = " . json_encode($object_value) . ';' : "\n{$object_name} = " . json_encode($object_value) . ';'; 
  197. // Add the addition 
  198. if ($override) { 
  199. $data .= $addition; 
  200. $retval = TRUE; 
  201. } else { 
  202. if (strpos($data, $object_name) === FALSE) { 
  203. $data .= $addition; 
  204. $retval = TRUE; 
  205. $script->extra['data'] = $data; 
  206. unset($script); 
  207. return $retval; 
  208. function deregister_all() 
  209. $this->_lightboxes = array(); 
  210. $this->_registered_defaults = FALSE;