PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/products/photocrati_nextgen/modules/nextgen_basic_album/module.nextgen_basic_album.php

https://bitbucket.org/photocrati/nextgen-gallery
PHP | 231 lines | 169 code | 28 blank | 34 comment | 9 complexity | 79a0ba75cb88c91754d3120cbe51f6f7 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. /*
  3. {
  4. Module: photocrati-nextgen_basic_album,
  5. Depends: { photocrati-nextgen_gallery_display, photocrati-nextgen_basic_templates, photocrati-nextgen_pagination }
  6. }
  7. */
  8. define('NGG_BASIC_COMPACT_ALBUM', 'photocrati-nextgen_basic_compact_album');
  9. define('NGG_BASIC_EXTENDED_ALBUM', 'photocrati-nextgen_basic_extended_album');
  10. class M_NextGen_Basic_Album extends C_Base_Module
  11. {
  12. function define()
  13. {
  14. parent::define(
  15. 'photocrati-nextgen_basic_album',
  16. 'NextGEN Basic Album',
  17. "Provides support for NextGEN's Basic Album",
  18. '0.17',
  19. 'https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/',
  20. 'Photocrati Media',
  21. 'https://www.imagely.com'
  22. );
  23. C_Photocrati_Installer::add_handler($this->module_id, 'C_NextGen_Basic_Album_Installer');
  24. }
  25. function initialize()
  26. {
  27. parent::initialize();
  28. if (is_admin()) {
  29. $forms = C_Form_Manager::get_instance();
  30. $forms->add_form(
  31. NGG_DISPLAY_SETTINGS_SLUG,
  32. NGG_BASIC_COMPACT_ALBUM
  33. );
  34. $forms->add_form(
  35. NGG_DISPLAY_SETTINGS_SLUG,
  36. NGG_BASIC_EXTENDED_ALBUM
  37. );
  38. }
  39. }
  40. function _register_adapters()
  41. {
  42. // Add validation for album display settings
  43. $this->get_registry()->add_adapter(
  44. 'I_Display_Type',
  45. 'A_NextGen_Basic_Album'
  46. );
  47. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id))
  48. {
  49. // Add a controller for displaying albums on the front-end
  50. $this->get_registry()->add_adapter(
  51. 'I_Display_Type_Controller',
  52. 'A_NextGen_Basic_Album_Controller',
  53. array(
  54. NGG_BASIC_COMPACT_ALBUM,
  55. NGG_BASIC_EXTENDED_ALBUM,
  56. $this->module_id
  57. )
  58. );
  59. // Add a generic adapter for display types to do late url rewriting
  60. $this->get_registry()->add_adapter(
  61. 'I_Displayed_Gallery_Renderer',
  62. 'A_NextGen_Basic_Album_Routes'
  63. );
  64. $this->get_registry()->add_adapter('I_MVC_View', 'A_NextGen_Album_Breadcrumbs');
  65. $this->get_registry()->add_adapter('I_MVC_View', 'A_NextGen_Album_Descriptions');
  66. }
  67. // Add a mapper for setting the defaults for the album
  68. $this->get_registry()->add_adapter(
  69. 'I_Display_Type_Mapper',
  70. 'A_NextGen_Basic_Album_Mapper'
  71. );
  72. if (M_Attach_To_Post::is_atp_url() || is_admin())
  73. {
  74. // Add a display settings form for each display type
  75. $this->get_registry()->add_adapter(
  76. 'I_Form',
  77. 'A_NextGen_Basic_Compact_Album_Form',
  78. NGG_BASIC_COMPACT_ALBUM
  79. );
  80. $this->get_registry()->add_adapter(
  81. 'I_Form',
  82. 'A_NextGen_Basic_Extended_Album_Form',
  83. NGG_BASIC_EXTENDED_ALBUM
  84. );
  85. }
  86. // Creates special parameter segments
  87. $this->get_registry()->add_adapter(
  88. 'I_Routing_App',
  89. 'A_NextGen_Basic_Album_Urls'
  90. );
  91. }
  92. function _register_hooks()
  93. {
  94. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id)
  95. && (!defined('NGG_DISABLE_LEGACY_SHORTCODES') || !NGG_DISABLE_LEGACY_SHORTCODES))
  96. {
  97. C_NextGen_Shortcode_Manager::add('album', array(&$this, 'ngglegacy_shortcode'));
  98. C_NextGen_Shortcode_Manager::add('nggalbum', array(&$this, 'ngglegacy_shortcode'));
  99. }
  100. add_filter('ngg_atp_show_display_type', array($this, 'atp_show_basic_albums'), 10, 2);
  101. }
  102. /**
  103. * ATP filters display types by not displaying those whose name attribute isn't an active POPE module. This
  104. * is a workaround/hack to compensate for basic albums sharing a module.
  105. *
  106. * @param bool $available
  107. * @param C_Display_Type $display_type
  108. * @return bool
  109. */
  110. function atp_show_basic_albums($available, $display_type)
  111. {
  112. if (in_array($display_type->name, array(NGG_BASIC_COMPACT_ALBUM, NGG_BASIC_EXTENDED_ALBUM)))
  113. $available = TRUE;
  114. return $available;
  115. }
  116. /**
  117. * Gets a value from the parameter array, and if not available, uses the default value
  118. *
  119. * @param string $name
  120. * @param mixed $default
  121. * @param array $params
  122. * @return mixed
  123. */
  124. function _get_param($name, $default, $params)
  125. {
  126. return (isset($params[$name])) ? $params[$name] : $default;
  127. }
  128. /**
  129. * Renders the shortcode for rendering an album
  130. * @param array $params
  131. * @param null $inner_content
  132. * @return string
  133. */
  134. function ngglegacy_shortcode($params, $inner_content=NULL)
  135. {
  136. $params['source'] = $this->_get_param('source', 'albums', $params);
  137. $params['container_ids'] = $this->_get_param('id', NULL, $params);
  138. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_COMPACT_ALBUM, $params);
  139. unset($params['id']);
  140. $renderer = C_Displayed_Gallery_Renderer::get_instance();
  141. return $renderer->display_images($params, $inner_content);
  142. }
  143. function get_type_list()
  144. {
  145. return array(
  146. 'A_NextGen_Album_Breadcrumbs' => 'adapter.nextgen_album_breadcrumbs.php',
  147. 'A_NextGen_Album_Descriptions' => 'adapter.nextgen_album_descriptions.php',
  148. 'A_Nextgen_Basic_Album' => 'adapter.nextgen_basic_album.php',
  149. 'A_Nextgen_Basic_Album_Controller' => 'adapter.nextgen_basic_album_controller.php',
  150. 'A_Nextgen_Basic_Album_Mapper' => 'adapter.nextgen_basic_album_mapper.php',
  151. 'A_Nextgen_Basic_Album_Routes' => 'adapter.nextgen_basic_album_routes.php',
  152. 'A_Nextgen_Basic_Album_Urls' => 'adapter.nextgen_basic_album_urls.php',
  153. 'A_Nextgen_Basic_Compact_Album_Form' => 'adapter.nextgen_basic_compact_album_form.php',
  154. 'A_Nextgen_Basic_Extended_Album_Form' => 'adapter.nextgen_basic_extended_album_form.php',
  155. 'Mixin_Nextgen_Basic_Album_Form' => 'mixin.nextgen_basic_album_form.php'
  156. );
  157. }
  158. }
  159. class C_NextGen_Basic_Album_Installer extends C_Gallery_Display_Installer
  160. {
  161. function install()
  162. {
  163. $this->install_display_type(
  164. NGG_BASIC_COMPACT_ALBUM, array(
  165. 'title' => __('NextGEN Basic Compact Album', 'nggallery'),
  166. 'entity_types' => array('album', 'gallery'),
  167. 'preview_image_relpath' => 'photocrati-nextgen_basic_album#compact_preview.jpg',
  168. 'default_source' => 'albums',
  169. 'view_order' => NGG_DISPLAY_PRIORITY_BASE + 200,
  170. 'aliases' => array(
  171. 'basic_compact_album',
  172. 'nextgen_basic_album',
  173. 'basic_album_compact',
  174. 'compact_album'
  175. )
  176. ));
  177. $this->install_display_type(
  178. NGG_BASIC_EXTENDED_ALBUM, array(
  179. 'title' => __('NextGEN Basic Extended Album', 'nggallery'),
  180. 'entity_types' => array('album', 'gallery'),
  181. 'preview_image_relpath' => 'photocrati-nextgen_basic_album#extended_preview.jpg',
  182. 'default_source' => 'albums',
  183. 'view_order' => NGG_DISPLAY_PRIORITY_BASE + 210,
  184. 'aliases' => array(
  185. 'basic_extended_album',
  186. 'nextgen_basic_extended_album',
  187. 'extended_album'
  188. )
  189. ));
  190. }
  191. }
  192. function nggShowAlbum($albumID, $template = 'extend', $gallery_template = '')
  193. {
  194. $renderer = C_Displayed_Gallery_Renderer::get_instance();
  195. $retval = $renderer->display_images(array(
  196. 'album_ids' => array($albumID),
  197. 'display_type' => 'photocrati-nextgen_basic_extended_album',
  198. 'template' => $template,
  199. 'gallery_display_template' => $gallery_template
  200. ));
  201. return apply_filters('ngg_show_album_content', $retval, $albumID);
  202. }
  203. new M_NextGen_Basic_Album();