Mixin_Display_Type_Controller

Provides instance methods for the C_Display_Type_Controller class.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_gallery_display/package.module.nextgen_gallery_display.php  
  1. class Mixin_Display_Type_Controller extends Mixin 
  2. var $_render_mode; 
  3. /** 
  4. * Enqueues static resources required for lightbox effects 
  5. * @param type $displayed_gallery 
  6. */ 
  7. function enqueue_lightbox_resources($displayed_gallery) 
  8. C_Lightbox_Library_Manager::get_instance()->enqueue(); 
  9. function is_cachable() 
  10. return TRUE; 
  11. /** 
  12. * This method should be overwritten by other adapters/mixins, and call 
  13. * wp_enqueue_script() / wp_enqueue_style() 
  14. */ 
  15. function enqueue_frontend_resources($displayed_gallery) 
  16. // This script provides common JavaScript among all display types 
  17. wp_enqueue_script('ngg_common'); 
  18. // Enqueue the display type library 
  19. wp_enqueue_script($displayed_gallery->display_type, $this->object->_get_js_lib_url($displayed_gallery), FALSE, NGG_SCRIPT_VERSION); 
  20. // Add "galleries = {};" 
  21. $this->object->_add_script_data('ngg_common', 'galleries', new stdClass(), TRUE, FALSE); 
  22. // Add "galleries.gallery_1 = {};" 
  23. $this->object->_add_script_data('ngg_common', 'galleries.gallery_' . $displayed_gallery->id(), (array) $displayed_gallery->get_entity(), FALSE); 
  24. $this->object->_add_script_data('ngg_common', 'galleries.gallery_' . $displayed_gallery->id() . '.wordpress_page_root', get_permalink(), FALSE); 
  25. // Enqueue trigger button resources 
  26. C_Displayed_Gallery_Trigger_Manager::get_instance()->enqueue_resources($displayed_gallery); 
  27. // Enqueue lightbox library 
  28. $this->object->enqueue_lightbox_resources($displayed_gallery); 
  29. function enqueue_ngg_styles() 
  30. $settings = C_NextGen_Settings::get_instance(); 
  31. if ((!is_multisite() || is_multisite() && $settings->wpmuStyle) && $settings->activateCSS) { 
  32. wp_enqueue_style('nggallery', C_NextGen_Style_Manager::get_instance()->get_selected_stylesheet_url(), FALSE, NGG_SCRIPT_VERSION); 
  33. function get_render_mode() 
  34. return $this->object->_render_mode; 
  35. function set_render_mode($mode) 
  36. $this->object->_render_mode = $mode; 
  37. /** 
  38. * Ensures that the minimum configuration of parameters are sent to a view 
  39. * @param $displayed_gallery 
  40. * @param null $params 
  41. * @return array|null 
  42. */ 
  43. function prepare_display_parameters($displayed_gallery, $params = null) 
  44. if ($params == null) { 
  45. $params = array(); 
  46. $params['display_type_rendering'] = true; 
  47. $params['displayed_gallery'] = $displayed_gallery; 
  48. $params['render_mode'] = $this->object->get_render_mode(); 
  49. return $params; 
  50. /** 
  51. * Renders the frontend display of the display type 
  52. */ 
  53. function index_action($displayed_gallery, $return = FALSE) 
  54. return $this->object->render_partial('photocrati-nextgen_gallery_display#index', array(), $return); 
  55. /** 
  56. * Returns the url for the JavaScript library required 
  57. * @return null|string 
  58. */ 
  59. function _get_js_lib_url() 
  60. return NULL; 
  61. function does_lightbox_support_displayed_gallery($displayed_gallery, $lightbox = NULL) 
  62. if (!$lightbox) { 
  63. $lightbox = C_Lightbox_Library_Manager::get_instance()->get_selected(); 
  64. $retval = FALSE; 
  65. if ($lightbox) { 
  66. // HANDLE COMPATIBILITY BREAK 
  67. // In NGG 2.1.48 and earlier, lightboxes were stdClass objects, and it was assumed 
  68. // that they only supported galleries that contained images, not albums that contained galleries. 
  69. // After NGG 2.1.48, lightboxes are now C_NGG_Lightbox instances which have a 'is_supported()' method 
  70. // to test if the lightbox can work with the displayed gallery settings 
  71. if (get_class($lightbox) == 'stdClass') { 
  72. $retval = !in_array($displayed_gallery->source, array('album', 'albums')); 
  73. } else { 
  74. $retval = $lightbox->is_supported($displayed_gallery); 
  75. return $retval; 
  76. /** 
  77. * Returns the effect HTML code for the displayed gallery 
  78. * @param type $displayed_gallery 
  79. */ 
  80. function get_effect_code($displayed_gallery) 
  81. $retval = ''; 
  82. if ($lightbox = C_Lightbox_Library_Manager::get_instance()->get_selected()) { 
  83. if ($this->does_lightbox_support_displayed_gallery($displayed_gallery, $lightbox)) { 
  84. $retval = $lightbox->code; 
  85. $retval = str_replace('%GALLERY_ID%', $displayed_gallery->id(), $retval); 
  86. $retval = str_replace('%GALLERY_NAME%', $displayed_gallery->id(), $retval); 
  87. global $post; 
  88. if ($post && isset($post->ID) && $post->ID) { 
  89. $retval = str_replace('%PAGE_ID%', $post->ID, $retval); 
  90. // allow for customization 
  91. $retval = apply_filters('ngg_effect_code', $retval, $displayed_gallery); 
  92. return $retval; 
  93. /** 
  94. * Adds data to the DOM which is then accessible by a script 
  95. * @param string $handle 
  96. * @param string $object_name 
  97. * @param mixed $object_value 
  98. * @param bool $define 
  99. */ 
  100. function _add_script_data($handle, $object_name, $object_value, $define = TRUE, $override = FALSE) 
  101. $retval = FALSE; 
  102. // wp_localize_script allows you to add data to the DOM, associated 
  103. // with a particular script. You can even call wp_localize_script 
  104. // multiple times to add multiple objects to the DOM. However, there 
  105. // are a few problems with wp_localize_script: 
  106. // 
  107. // - If you call it with the same object_name more than once, you're 
  108. // overwritting the first call. 
  109. // - You cannot namespace your objects due to the "var" keyword always 
  110. // - being used. 
  111. // 
  112. // To circumvent the above issues, we're going to use the WP_Scripts 
  113. // object to workaround the above issues 
  114. global $wp_scripts; 
  115. // Has the script been registered or enqueued yet? 
  116. if (isset($wp_scripts->registered[$handle])) { 
  117. // Get the associated data with this script 
  118. $script =& $wp_scripts->registered[$handle]; 
  119. $data = isset($script->extra['data']) ? $script->extra['data'] : ''; 
  120. // Construct the addition 
  121. $addition = $define ? "\nvar {$object_name} = " . json_encode($object_value) . ';' : "\n{$object_name} = " . json_encode($object_value) . ';'; 
  122. // Add the addition 
  123. if ($override) { 
  124. $data .= $addition; 
  125. $retval = TRUE; 
  126. } else { 
  127. if (strpos($data, $object_name) === FALSE) { 
  128. $data .= $addition; 
  129. $retval = TRUE; 
  130. $script->extra['data'] = $data; 
  131. unset($script); 
  132. return $retval; 
  133. // Returns the longest and widest dimensions from a list of entities 
  134. function get_entity_statistics($entities, $named_size, $style_images = FALSE) 
  135. $longest = $widest = 0; 
  136. $storage = C_Gallery_Storage::get_instance(); 
  137. $image_mapper = FALSE; 
  138. // we'll fetch this if needed 
  139. // Calculate longest and 
  140. foreach ($entities as $entity) { 
  141. // Get the image 
  142. $image = FALSE; 
  143. if (isset($entity->pid)) { 
  144. $image = $entity; 
  145. } elseif (isset($entity->previewpic)) { 
  146. if (!$image_mapper) { 
  147. $image_mapper = C_Image_Mapper::get_instance(); 
  148. $image = $image_mapper->find($entity->previewpic); 
  149. // Once we have the image, get it's dimensions 
  150. if ($image) { 
  151. $dimensions = $storage->get_image_dimensions($image, $named_size); 
  152. if ($dimensions['width'] > $widest) { 
  153. $widest = $dimensions['width']; 
  154. if ($dimensions['height'] > $longest) { 
  155. $longest = $dimensions['height']; 
  156. // Second loop to style images 
  157. if ($style_images) { 
  158. foreach ($entities as &$entity) { 
  159. // Get the image 
  160. $image = FALSE; 
  161. if (isset($entity->pid)) { 
  162. $image = $entity; 
  163. } elseif (isset($entity->previewpic)) { 
  164. if (!$image_mapper) { 
  165. $image_mapper = C_Image_Mapper::get_instance(); 
  166. $image = $image_mapper->find($entity->previewpic); 
  167. // Once we have the image, get it's dimension and calculate margins 
  168. if ($image) { 
  169. $dimensions = $storage->get_image_dimensions($image, $named_size); 
  170. return array('entities' => $entities, 'longest' => $longest, 'widest' => $widest); 
  171. /** 
  172. * Renders a view after checking for templates 
  173. */ 
  174. function create_view($template, $params = array(), $context = NULL) 
  175. if (isset($params['displayed_gallery'])) { 
  176. if (isset($params['displayed_gallery']->display_settings)) { 
  177. if (isset($params['displayed_gallery']->display_settings['display_type_view'])) { 
  178. if ('default' !== $params['displayed_gallery']->display_settings['display_type_view']) { 
  179. $template = $this->get_display_type_view_abspath($template, $params); 
  180. return $this->call_parent('create_view', $template, $params, $context); 
  181. /** 
  182. * Finds the abs path of template given file name and list of posssible directories 
  183. * @param string $template 
  184. * @param array $params 
  185. * @return string $template  
  186. */ 
  187. function get_display_type_view_abspath($template, $params) 
  188. /** Identify display type and display_type_view */ 
  189. $display_type_name = $params['displayed_gallery']->display_type; 
  190. $display_type_view = $params['displayed_gallery']->display_settings['display_type_view']; 
  191. /** Fetch array of template directories */ 
  192. $dirs = M_Gallery_Display::get_display_type_view_dirs($display_type_name); 
  193. /** Set abspath for template based on directory placeholder in display_type_view */ 
  194. $path = pathinfo($display_type_view); 
  195. if ($path['dirname'] == ".") { 
  196. $template = $dirs['default'] . DIRECTORY_SEPARATOR . $path['basename']; 
  197. } else { 
  198. foreach ($dirs as $dir_name => $dir) { 
  199. if ($path['dirname'] == $dir_name) { 
  200. $template = $dir . DIRECTORY_SEPARATOR . $path['basename']; 
  201. /** Return template. If no match is found, returns the original template */ 
  202. return $template;