A_NextGen_Basic_Album_Controller

Class A_NextGen_Basic_Album_Controller.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_basic_album/package.module.nextgen_basic_album.php  
  1. class A_NextGen_Basic_Album_Controller extends Mixin_NextGen_Basic_Pagination 
  2. var $albums = array(); 
  3. /** 
  4. * Renders the front-end for the NextGen Basic Album display type 
  5. * @param $displayed_gallery 
  6. * @param bool $return 
  7. */ 
  8. function index_action($displayed_gallery, $return = FALSE) 
  9. $display_settings = $displayed_gallery->display_settings; 
  10. // We need to fetch the album containers selected in the Attach 
  11. // to Post interface. We need to do this, because once we fetch the 
  12. // included entities, we need to iterate over each entity and assign it 
  13. // a parent_id, which is the album that it belongs to. We need to do this 
  14. // because the link to the gallery, is not /nggallery/gallery--id, but 
  15. // /nggallery/album--id/gallery--id 
  16. $parent_albums = $displayed_gallery->get_albums(); 
  17. // Are we to display a gallery? Ensure our 'gallery' isn't just a paginated album view 
  18. $gallery = $gallery_slug = $this->param('gallery'); 
  19. if ($gallery && strpos($gallery, 'nggpage--') !== 0) { 
  20. // basic albums only support one per post 
  21. if (isset($GLOBALS['nggShowGallery'])) { 
  22. return; 
  23. $GLOBALS['nggShowGallery'] = TRUE; 
  24. // Try finding the gallery by slug first. If nothing is found, we assume that 
  25. // the user passed in a gallery id instead 
  26. $mapper = C_Gallery_Mapper::get_instance(); 
  27. $tmp = $mapper->select()->where(array('slug = %s', $gallery))->limit(1)->run_query(); 
  28. $result = reset($tmp); 
  29. unset($tmp); 
  30. if ($result) { 
  31. $gallery = $result->{$result->id_field}; 
  32. $renderer = C_Displayed_Gallery_Renderer::get_instance('inner'); 
  33. $gallery_params = array('source' => 'galleries', 'container_ids' => array($gallery), 'display_type' => $display_settings['gallery_display_type'], 'original_display_type' => $displayed_gallery->display_type, 'original_settings' => $display_settings, 'original_album_entities' => $parent_albums); 
  34. if (!empty($display_settings['gallery_display_template'])) { 
  35. $gallery_params['template'] = $display_settings['gallery_display_template']; 
  36. add_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates'), 8, 2); 
  37. add_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates'), 9, 2); 
  38. $output = $renderer->display_images($gallery_params, $return); 
  39. remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates')); 
  40. remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates')); 
  41. return $output; 
  42. } else { 
  43. if ($album = $this->param('album')) { 
  44. $mapper = C_Album_Mapper::get_instance(); 
  45. $result = $mapper->select()->where(array('slug = %s', $album))->limit(1)->run_query(); 
  46. $result = array_pop($result); 
  47. $album_sub = $result ? $result->{$result->id_field} : null; 
  48. if ($album_sub != null) { 
  49. $album = $album_sub; 
  50. $displayed_gallery->entity_ids = array(); 
  51. $displayed_gallery->sortorder = array(); 
  52. $displayed_gallery->container_ids = ($album === '0' or $album === 'all') ? array() : array($album); 
  53. $displayed_gallery->display_settings['original_album_id'] = 'a' . $album_sub; 
  54. $displayed_gallery->display_settings['original_album_entities'] = $parent_albums; 
  55. // Get the albums 
  56. // TODO: This should probably be moved to the elseif block above 
  57. $this->albums = $displayed_gallery->get_albums(); 
  58. // None of the above: Display the main album. Get the settings required for display 
  59. $current_page = (int) $this->param('page', $displayed_gallery->id(), 1); 
  60. $offset = $display_settings['galleries_per_page'] * ($current_page - 1); 
  61. $entities = $displayed_gallery->get_included_entities($display_settings['galleries_per_page'], $offset); 
  62. // If there are entities to be displayed 
  63. if ($entities) { 
  64. $pagination_result = $this->object->create_pagination($current_page, $displayed_gallery->get_entity_count(), $display_settings['galleries_per_page'], urldecode($this->object->param('ajax_pagination_referrer'))); 
  65. $display_settings['entities'] = $entities; 
  66. $display_settings['pagination'] = $pagination_result['output']; 
  67. $display_settings['displayed_gallery'] = $displayed_gallery; 
  68. $display_settings = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), $display_settings); 
  69. if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { 
  70. // Add additional parameters 
  71. $this->object->remove_param('ajax_pagination_referrer'); 
  72. $display_settings['current_page'] = $current_page; 
  73. $display_settings['pagination_prev'] = $pagination_result['prev']; 
  74. $display_settings['pagination_next'] = $pagination_result['next']; 
  75. // Legacy templates lack a good way of injecting content at the right time 
  76. $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); 
  77. $this->object->add_mixin('A_NextGen_Album_Breadcrumbs'); 
  78. $this->object->add_mixin('A_NextGen_Album_Descriptions'); 
  79. $breadcrumbs = $this->object->render_legacy_template_breadcrumbs($displayed_gallery, $entities); 
  80. $description = $this->object->render_legacy_template_description($displayed_gallery); 
  81. // If enabled enqueue the child entities as JSON for lightboxes to read 
  82. if (A_NextGen_Album_Child_Entities::are_child_entities_enabled($display_settings)) { 
  83. $script = A_NextGen_Album_Child_Entities::generate_script($entities); 
  84. $retval = $this->object->legacy_render($display_settings['template'], $display_settings, $return, 'album'); 
  85. if (!empty($description)) { 
  86. $retval = $description . $retval; 
  87. if (!empty($breadcrumbs)) { 
  88. $retval = $breadcrumbs . $retval; 
  89. if (!empty($script)) { 
  90. $retval = $retval . $script; 
  91. return $retval; 
  92. } else { 
  93. $params = $display_settings; 
  94. $params = $this->object->prepare_display_parameters($displayed_gallery, $params); 
  95. switch ($displayed_gallery->display_type) { 
  96. case NGG_BASIC_COMPACT_ALBUM: 
  97. $template = 'compact'; 
  98. break; 
  99. case NGG_BASIC_EXTENDED_ALBUM: 
  100. $template = 'extended'; 
  101. break; 
  102. return $this->object->render_view("photocrati-nextgen_basic_album#{$template}", $params, $return); 
  103. } else { 
  104. return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); 
  105. /** 
  106. * Creates a displayed gallery of a gallery belonging to an album. Shared by index_action() and cache_action() to 
  107. * allow lightboxes to open album children directly. 
  108. * @param $gallery 
  109. * @param $display_settings 
  110. * @return $gallery 
  111. */ 
  112. function make_child_displayed_gallery($gallery, $display_settings) 
  113. $gallery->displayed_gallery = new C_Displayed_Gallery(); 
  114. $gallery->displayed_gallery->container_ids = array($gallery->{$gallery->id_field}); 
  115. $gallery->displayed_gallery->display_settings = $display_settings; 
  116. $gallery->displayed_gallery->returns = 'included'; 
  117. $gallery->displayed_gallery->source = 'galleries'; 
  118. $gallery->displayed_gallery->images_list_count = $gallery->displayed_gallery->get_entity_count(); 
  119. $gallery->displayed_gallery->is_album_gallery = TRUE; 
  120. $gallery->displayed_gallery->to_transient(); 
  121. return $gallery; 
  122. function add_breadcrumbs_to_legacy_templates($html, $displayed_gallery) 
  123. $this->object->add_mixin('A_NextGen_Album_Breadcrumbs'); 
  124. $original_album_entities = array(); 
  125. if (isset($displayed_gallery->display_settings['original_album_entities'])) { 
  126. $original_album_entities = $displayed_gallery->display_settings['original_album_entities']; 
  127. } elseif (isset($displayed_gallery->display_settings['original_settings']) && isset($displayed_gallery->display_settings['original_settings']['original_album_entities'])) { 
  128. $original_album_entities = $displayed_gallery->display_settings['original_settings']['original_album_entities']; 
  129. $breadcrumbs = $this->object->render_legacy_template_breadcrumbs($displayed_gallery, $original_album_entities, $displayed_gallery->container_ids); 
  130. if (!empty($breadcrumbs)) { 
  131. $html = $breadcrumbs . $html; 
  132. return $html; 
  133. function add_description_to_legacy_templates($html, $displayed_gallery) 
  134. $this->object->add_mixin('A_NextGen_Album_Descriptions'); 
  135. $description = $this->object->render_legacy_template_description($displayed_gallery); 
  136. if (!empty($description)) { 
  137. $html = $description . $html; 
  138. return $html; 
  139. /** 
  140. * Gets the parent album for the entity being displayed 
  141. * @param int $entity_id 
  142. * @return stdClass (album) 
  143. */ 
  144. function get_parent_album_for($entity_id) 
  145. $retval = NULL; 
  146. foreach ($this->albums as $album) { 
  147. if (in_array($entity_id, $album->sortorder)) { 
  148. $retval = $album; 
  149. break; 
  150. return $retval; 
  151. function prepare_legacy_album_params($displayed_gallery, $params) 
  152. $image_mapper = C_Image_Mapper::get_instance(); 
  153. $storage = C_Gallery_Storage::get_instance(); 
  154. $image_gen = C_Dynamic_Thumbnails_Manager::get_instance(); 
  155. if (empty($displayed_gallery->display_settings['override_thumbnail_settings'])) { 
  156. // legacy templates expect these dimensions 
  157. $image_gen_params = array('width' => 91, 'height' => 68, 'crop' => TRUE); 
  158. } else { 
  159. // use settings requested by user 
  160. $image_gen_params = array('width' => $displayed_gallery->display_settings['thumbnail_width'], 'height' => $displayed_gallery->display_settings['thumbnail_height'], 'quality' => isset($displayed_gallery->display_settings['thumbnail_quality']) ? $displayed_gallery->display_settings['thumbnail_quality'] : 100, 'crop' => isset($displayed_gallery->display_settings['thumbnail_crop']) ? $displayed_gallery->display_settings['thumbnail_crop'] : NULL, 'watermark' => isset($displayed_gallery->display_settings['thumbnail_watermark']) ? $displayed_gallery->display_settings['thumbnail_watermark'] : NULL); 
  161. // so user templates can know how big the images are expected to be 
  162. $params['image_gen_params'] = $image_gen_params; 
  163. // Transform entities 
  164. $params['galleries'] = $params['entities']; 
  165. unset($params['entities']); 
  166. foreach ($params['galleries'] as &$gallery) { 
  167. // Get the preview image url 
  168. $gallery->previewurl = ''; 
  169. if ($gallery->previewpic && $gallery->previewpic > 0) { 
  170. if ($image = $image_mapper->find(intval($gallery->previewpic))) { 
  171. $gallery->previewpic_image = $image; 
  172. $gallery->previewpic_fullsized_url = $storage->get_image_url($image, 'full'); 
  173. $gallery->previewurl = $storage->get_image_url($image, $image_gen->get_size_name($image_gen_params), TRUE); 
  174. $gallery->previewname = $gallery->name; 
  175. // Get the page link. If the entity is an album, then the url will 
  176. // look like /nggallery/album--slug. 
  177. $id_field = $gallery->id_field; 
  178. if ($gallery->is_album) { 
  179. if ($gallery->pageid > 0) { 
  180. $gallery->pagelink = @get_page_link($gallery->pageid); 
  181. } else { 
  182. $pagelink = $this->object->get_routed_url(TRUE); 
  183. $pagelink = $this->object->remove_param_for($pagelink, 'album'); 
  184. $pagelink = $this->object->remove_param_for($pagelink, 'gallery'); 
  185. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  186. $pagelink = $this->object->set_param_for($pagelink, 'album', $gallery->slug); 
  187. $gallery->pagelink = $pagelink; 
  188. } else { 
  189. if ($gallery->pageid > 0) { 
  190. $gallery->pagelink = @get_page_link($gallery->pageid); 
  191. if (empty($gallery->pagelink)) { 
  192. $pagelink = $this->object->get_routed_url(TRUE); 
  193. $parent_album = $this->object->get_parent_album_for($gallery->{$id_field}); 
  194. if ($parent_album) { 
  195. $pagelink = $this->object->remove_param_for($pagelink, 'album'); 
  196. $pagelink = $this->object->remove_param_for($pagelink, 'gallery'); 
  197. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  198. $pagelink = $this->object->set_param_for($pagelink, 'album', $parent_album->slug); 
  199. } else { 
  200. if ($displayed_gallery->container_ids === array('0') || $displayed_gallery->container_ids === array('')) { 
  201. $pagelink = $this->object->set_param_for($pagelink, 'album', 'all'); 
  202. } else { 
  203. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  204. $pagelink = $this->object->set_param_for($pagelink, 'album', 'album'); 
  205. $gallery->pagelink = $this->object->set_param_for($pagelink, 'gallery', $gallery->slug); 
  206. // Mark the child type 
  207. $gallery->entity_type = isset($gallery->is_gallery) && intval($gallery->is_gallery) ? 'gallery' : 'album'; 
  208. // If this setting is on we need to inject an effect code 
  209. if (!empty($displayed_gallery->display_settings['open_gallery_in_lightbox']) && $gallery->entity_type == 'gallery') { 
  210. $gallery = $this->object->make_child_displayed_gallery($gallery, $displayed_gallery->display_settings); 
  211. if ($this->does_lightbox_support_displayed_gallery($displayed_gallery)) { 
  212. $gallery->displayed_gallery->effect_code = $this->object->get_effect_code($gallery->displayed_gallery); 
  213. // Let plugins modify the gallery 
  214. $gallery = apply_filters('ngg_album_galleryobject', $gallery); 
  215. $params['galleries'] = apply_filters('ngg_album_prepared_child_entity', $params['galleries'], $params['displayed_gallery']); 
  216. $params['album'] = reset($this->albums); 
  217. $params['albums'] = $this->albums; 
  218. // Clean up 
  219. unset($storage); 
  220. unset($image_mapper); 
  221. unset($image_gen); 
  222. unset($image_gen_params); 
  223. return $params; 
  224. function _get_js_lib_url() 
  225. return $this->object->get_static_url('photocrati-nextgen_basic_album#init.js'); 
  226. /** 
  227. * Enqueues all static resources required by this display type 
  228. * @param C_Displayed_Gallery $displayed_gallery 
  229. */ 
  230. function enqueue_frontend_resources($displayed_gallery) 
  231. $this->call_parent('enqueue_frontend_resources', $displayed_gallery); 
  232. wp_enqueue_style('nextgen_basic_album_style', $this->object->get_static_url('photocrati-nextgen_basic_album#nextgen_basic_album.css'), FALSE, NGG_SCRIPT_VERSION); 
  233. wp_enqueue_style('nextgen_pagination_style', $this->get_static_url('photocrati-nextgen_pagination#style.css'), FALSE, NGG_SCRIPT_VERSION); 
  234. wp_enqueue_script('jquery.dotdotdot', $this->object->get_static_url('photocrati-nextgen_basic_album#jquery.dotdotdot-1.5.7-packed.js'), array('jquery'), NGG_SCRIPT_VERSION); 
  235. $ds = $displayed_gallery->display_settings; 
  236. if (!empty($ds['enable_breadcrumbs']) && $ds['enable_breadcrumbs'] || !empty($ds['original_settings']['enable_breadcrumbs']) && $ds['original_settings']['enable_breadcrumbs']) { 
  237. wp_enqueue_style('nextgen_basic_album_breadcrumbs_style', $this->object->get_static_url('photocrati-nextgen_basic_album#breadcrumbs.css'), FALSE, NGG_SCRIPT_VERSION); 
  238. $this->enqueue_ngg_styles();