PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_album/adapter.nextgen_basic_album_controller.php

https://github.com/Fishgate/privatecollectionswp
PHP | 286 lines | 201 code | 40 blank | 45 comment | 29 complexity | 857b043c58335beb5cc40b4e224ecd6e MD5 | raw file
  1. <?php
  2. class A_NextGen_Basic_Album_Controller extends Mixin
  3. {
  4. function initialize()
  5. {
  6. $this->albums = array();
  7. $this->object->add_mixin('Mixin_NextGen_Basic_Pagination');
  8. }
  9. /**
  10. * Renders the front-end for the NextGen Basic Album display type
  11. *
  12. * @param $displayed_gallery
  13. * @param bool $return
  14. */
  15. function index_action($displayed_gallery, $return = FALSE)
  16. {
  17. $display_settings = $displayed_gallery->display_settings;
  18. // We need to fetch the album containers selected in the Attach
  19. // to Post interface. We need to do this, because once we fetch the
  20. // included entities, we need to iterate over each entity and assign it
  21. // a parent_id, which is the album that it belongs to. We need to do this
  22. // because the link to the gallery, is not /nggallery/gallery--id, but
  23. // /nggallery/album--id/gallery--id
  24. // Are we to display a gallery?
  25. if (($gallery = $gallery_slug = $this->param('gallery')))
  26. {
  27. // basic albums only support one per post
  28. if (isset($GLOBALS['nggShowGallery']))
  29. return;
  30. $GLOBALS['nggShowGallery'] = TRUE;
  31. // Try finding the gallery by slug first. If nothing is found, we assume that
  32. // the user passed in a gallery id instead
  33. $mapper = $this->object->get_registry()->get_utility('I_Gallery_Mapper');
  34. $result = reset($mapper->select()->where(array('slug = %s', $gallery))->limit(1)->run_query());
  35. if ($result) {
  36. $gallery = $result->{$result->id_field};
  37. }
  38. $renderer = $this->object->get_registry()->get_utility('I_Displayed_Gallery_Renderer');
  39. return $renderer->display_images(
  40. array(
  41. 'source' => 'galleries',
  42. 'container_ids' => array($gallery),
  43. 'display_type' => $display_settings['gallery_display_type'],
  44. 'original_display_type' => $displayed_gallery->display_type,
  45. 'original_settings' => $display_settings
  46. ),
  47. $return
  48. );
  49. }
  50. // If we're viewing a sub-album, then we use that album as a container instead
  51. else if (($album = $this->param('album'))) {
  52. // Are we to display a sub-album?
  53. {
  54. $mapper = $this->object->get_registry()->get_utility('I_Album_Mapper');
  55. $result = array_pop($mapper->select()->where(array('slug = %s', $album))->limit(1)->run_query());
  56. $album_sub = $result ? $result->{$result->id_field} : null;
  57. if ($album_sub != null) {
  58. $album = $album_sub;
  59. }
  60. }
  61. $displayed_gallery->entity_ids = array();
  62. $displayed_gallery->sortorder = array();
  63. $displayed_gallery->container_ids = ($album === '0' OR $album === 'all') ? array() : array($album);
  64. }
  65. // Get the albums
  66. $this->albums = $displayed_gallery->get_albums();
  67. // None of the above: Display the main album. Get the settings required for display
  68. $current_page = (int)$this->param('nggpage', 1);
  69. $offset = $display_settings['galleries_per_page'] * ($current_page - 1);
  70. $entities = $displayed_gallery->get_included_entities($display_settings['galleries_per_page'], $offset);
  71. // If there are entities to be displayed
  72. if ($entities)
  73. {
  74. if (!empty($display_settings['template']))
  75. {
  76. // Add additional parameters
  77. $pagination_result = $this->object->create_pagination(
  78. $current_page,
  79. $displayed_gallery->get_entity_count(),
  80. $display_settings['galleries_per_page'],
  81. urldecode($this->object->param('ajax_pagination_referrer'))
  82. );
  83. $this->object->remove_param('ajax_pagination_referrer');
  84. $display_settings['current_page'] = $current_page;
  85. $display_settings['entities'] = &$entities;
  86. $display_settings['pagination_prev'] = $pagination_result['prev'];
  87. $display_settings['pagination_next'] = $pagination_result['next'];
  88. $display_settings['pagination'] = $pagination_result['output'];
  89. // Render legacy template
  90. $this->object->add_mixin('Mixin_NextGen_Basic_Templates');
  91. $display_settings = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), $display_settings);
  92. return $this->object->legacy_render($display_settings['template'], $display_settings, $return, 'album');
  93. }
  94. else {
  95. $params = $display_settings;
  96. $albums = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), array('entities' => $entities));;
  97. $params['image_gen_params'] = $albums['image_gen_params'];
  98. $params['galleries'] = $albums['galleries'];
  99. $params['displayed_gallery'] = $displayed_gallery;
  100. $params = $this->object->prepare_display_parameters($displayed_gallery, $params);
  101. switch ($displayed_gallery->display_type) {
  102. case NGG_BASIC_COMPACT_ALBUM:
  103. $template = 'compact';
  104. break;
  105. case NGG_BASIC_EXTENDED_ALBUM:
  106. $template = 'extended';
  107. break;
  108. }
  109. return $this->object->render_view("photocrati-nextgen_basic_album#{$template}", $params, $return);
  110. }
  111. }
  112. else {
  113. return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return);
  114. }
  115. }
  116. /**
  117. * Gets the parent album for the entity being displayed
  118. * @param int $entity_id
  119. * @return stdClass (album)
  120. */
  121. function get_parent_album_for($entity_id)
  122. {
  123. $retval = NULL;
  124. foreach ($this->albums as $album) {
  125. if (in_array($entity_id, $album->sortorder)) {
  126. $retval = $album;
  127. break;
  128. }
  129. }
  130. return $retval;
  131. }
  132. function prepare_legacy_album_params($displayed_gallery, $params)
  133. {
  134. $image_mapper = $this->object->get_registry()->get_utility('I_Image_Mapper');
  135. $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage');
  136. $image_gen = $this->object->get_registry()->get_utility('I_Dynamic_Thumbnails_Manager');
  137. if (empty($displayed_gallery->display_settings['override_thumbnail_settings']))
  138. {
  139. // legacy templates expect these dimensions
  140. $image_gen_params = array(
  141. 'width' => 91,
  142. 'height' => 68,
  143. 'crop' => TRUE
  144. );
  145. }
  146. else {
  147. // use settings requested by user
  148. $image_gen_params = array(
  149. 'width' => $displayed_gallery->display_settings['thumbnail_width'],
  150. 'height' => $displayed_gallery->display_settings['thumbnail_height'],
  151. 'quality' => isset($displayed_gallery->display_settings['thumbnail_quality']) ? $displayed_gallery->display_settings['thumbnail_quality'] : 100,
  152. 'crop' => isset($displayed_gallery->display_settings['thumbnail_crop']) ? $displayed_gallery->display_settings['thumbnail_crop'] : NULL,
  153. 'watermark' => isset($displayed_gallery->display_settings['thumbnail_watermark']) ? $displayed_gallery->display_settings['thumbnail_watermark'] : NULL
  154. );
  155. }
  156. // so user templates can know how big the images are expected to be
  157. $params['image_gen_params'] = $image_gen_params;
  158. // Transform entities
  159. $params['galleries'] = $params['entities'];
  160. unset($params['entities']);
  161. foreach ($params['galleries'] as &$gallery) {
  162. // Get the preview image url
  163. $gallery->previewurl = '';
  164. if ($gallery->previewpic && $gallery->previewpic > 0)
  165. {
  166. if (($image = $image_mapper->find(intval($gallery->previewpic))))
  167. {
  168. $gallery->previewurl = $storage->get_image_url($image, $image_gen->get_size_name($image_gen_params), TRUE);
  169. $gallery->previewname = $gallery->name;
  170. }
  171. }
  172. // Get the page link. If the entity is an album, then the url will
  173. // look like /nggallery/album--slug.
  174. $id_field = $gallery->id_field;
  175. if ($gallery->is_album)
  176. {
  177. if ($gallery->pageid > 0)
  178. $gallery->pagelink = @get_page_link($gallery->pageid);
  179. else {
  180. $gallery->pagelink = $this->object->set_param_for(
  181. $this->object->get_routed_url(TRUE),
  182. 'album',
  183. $gallery->slug
  184. );
  185. }
  186. }
  187. // Otherwise, if it's a gallery then it will look like
  188. // /nggallery/album--slug/gallery--slug
  189. else {
  190. if ($gallery->pageid > 0) {
  191. $gallery->pagelink = @get_page_link($gallery->pageid);
  192. }
  193. if (empty($gallery->pagelink)) {
  194. $pagelink = $this->object->get_routed_url(TRUE);
  195. $parent_album = $this->object->get_parent_album_for($gallery->$id_field);
  196. if ($parent_album) {
  197. $pagelink = $this->object->set_param_for(
  198. $pagelink,
  199. 'album',
  200. $parent_album->slug
  201. );
  202. }
  203. // Legacy compat: use an album slug of 'all' if we're missing a container_id
  204. else if($displayed_gallery->container_ids === array('0')
  205. || $displayed_gallery->container_ids === array('')) {
  206. $pagelink = $this->object->set_param_for($pagelink, 'album', 'all');
  207. }
  208. else {
  209. $pagelink = $this->object->set_param_for($pagelink, 'album', 'album');
  210. }
  211. $gallery->pagelink = $this->object->set_param_for(
  212. $pagelink,
  213. 'gallery',
  214. $gallery->slug
  215. );
  216. }
  217. }
  218. // Let plugins modify the gallery
  219. $gallery = apply_filters('ngg_album_galleryobject', $gallery);
  220. }
  221. $params['album'] = reset($this->albums);
  222. $params['albums'] = $this->albums;
  223. // Clean up
  224. unset($storage);
  225. unset($image_mapper);
  226. unset($image_gen);
  227. unset($image_gen_params);
  228. return $params;
  229. }
  230. function _get_js_lib_url()
  231. {
  232. return $this->object->get_static_url('photocrati-nextgen_basic_album#init.js');
  233. }
  234. /**
  235. * Enqueues all static resources required by this display type
  236. *
  237. * @param C_Displayed_Gallery $displayed_gallery
  238. */
  239. function enqueue_frontend_resources($displayed_gallery)
  240. {
  241. $this->call_parent('enqueue_frontend_resources', $displayed_gallery);
  242. wp_enqueue_style('nextgen_basic_album_style', $this->object->get_static_url('photocrati-nextgen_basic_album#nextgen_basic_album.css'));
  243. wp_enqueue_script('jquery.dotdotdot', $this->object->get_static_url('photocrati-nextgen_basic_album#jquery.dotdotdot-1.5.7-packed.js'), array('jquery'));
  244. $this->enqueue_ngg_styles();
  245. }
  246. }