/products/photocrati_nextgen/modules/nextgen_basic_gallery/module.nextgen_basic_gallery.php

  1. <?php 
  2. /** 
  3. { 
  4. Module: photocrati-nextgen_basic_gallery,  
  5. Depends: { photocrati-nextgen_pagination } 
  6. } 
  7. */ 
  8.  
  9. define( 
  10. 'NGG_BASIC_THUMBNAILS',  
  11. 'photocrati-nextgen_basic_thumbnails' 
  12. ); 
  13.  
  14. define( 
  15. 'NGG_BASIC_SLIDESHOW',  
  16. 'photocrati-nextgen_basic_slideshow' 
  17. ); 
  18.  
  19.  
  20. class M_NextGen_Basic_Gallery extends C_Base_Module 
  21. function define($id = 'pope-module',  
  22. $name = 'Pope Module',  
  23. $description = '',  
  24. $version = '',  
  25. $uri = '',  
  26. $author = '',  
  27. $author_uri = '',  
  28. $context = FALSE) 
  29. parent::define( 
  30. 'photocrati-nextgen_basic_gallery',  
  31. 'NextGEN Basic Gallery',  
  32. "Provides NextGEN Gallery's basic thumbnail/slideshow integrated gallery",  
  33. '0.16',  
  34. 'https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/',  
  35. 'Imagely',  
  36. 'https://www.imagely.com' 
  37. ); 
  38.  
  39. C_Photocrati_Installer::add_handler($this->module_id, 'C_NextGen_Basic_Gallery_Installer'); 
  40.  
  41. function initialize() 
  42. parent::initialize(); 
  43. if (is_admin()) { 
  44. $forms = C_Form_Manager::get_instance(); 
  45. $forms->add_form(NGG_DISPLAY_SETTINGS_SLUG, NGG_BASIC_THUMBNAILS); 
  46. $forms->add_form(NGG_DISPLAY_SETTINGS_SLUG, NGG_BASIC_SLIDESHOW); 
  47.  
  48.  
  49. function get_type_list() 
  50. return array( 
  51. 'C_Nextgen_Basic_Gallery_Installer' => 'class.nextgen_basic_gallery_installer.php',  
  52. 'A_Nextgen_Basic_Gallery_Mapper' => 'adapter.nextgen_basic_gallery_mapper.php',  
  53. 'A_Nextgen_Basic_Gallery_Urls' => 'adapter.nextgen_basic_gallery_urls.php',  
  54. 'A_Nextgen_Basic_Gallery_Validation' => 'adapter.nextgen_basic_gallery_validation.php',  
  55. 'A_Nextgen_Basic_Slideshow_Controller' => 'adapter.nextgen_basic_slideshow_controller.php',  
  56. 'A_Nextgen_Basic_Slideshow_Form' => 'adapter.nextgen_basic_slideshow_form.php',  
  57. 'A_Nextgen_Basic_Thumbnail_Form' => 'adapter.nextgen_basic_thumbnail_form.php',  
  58. 'A_Nextgen_Basic_Thumbnails_Controller' => 'adapter.nextgen_basic_thumbnails_controller.php',  
  59. 'Mixin_Nextgen_Basic_Gallery_Controller' => 'mixin.nextgen_basic_gallery_controller.php',  
  60. 'A_NextGen_Basic_Gallery_Controller' => 'adapter.nextgen_basic_gallery_controller.php' 
  61. ); 
  62.  
  63.  
  64. function _register_adapters() 
  65. if (M_Attach_To_Post::is_atp_url() || is_admin()) 
  66. // Provides the display type forms 
  67. $this->get_registry()->add_adapter( 
  68. 'I_Form',  
  69. 'A_NextGen_Basic_Slideshow_Form',  
  70. NGG_BASIC_SLIDESHOW 
  71. ); 
  72. $this->get_registry()->add_adapter( 
  73. 'I_Form',  
  74. 'A_NextGen_Basic_Thumbnail_Form',  
  75. NGG_BASIC_THUMBNAILS 
  76. ); 
  77.  
  78. // Frontend-only components 
  79. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id)) 
  80. // Provides the controllers for the display types 
  81. $this->get_registry()->add_adapter( 
  82. 'I_Display_Type_Controller',  
  83. 'A_NextGen_Basic_Slideshow_Controller',  
  84. NGG_BASIC_SLIDESHOW 
  85. ); 
  86. $this->get_registry()->add_adapter( 
  87. 'I_Display_Type_Controller',  
  88. 'A_NextGen_Basic_Thumbnails_Controller',  
  89. NGG_BASIC_THUMBNAILS 
  90. ); 
  91.  
  92. $this->get_registry()->add_adapter( 
  93. 'I_Display_Type_Controller',  
  94. 'A_NextGen_Basic_Gallery_Controller',  
  95. NGG_BASIC_SLIDESHOW 
  96. ); 
  97. $this->get_registry()->add_adapter( 
  98. 'I_Display_Type_Controller',  
  99. 'A_NextGen_Basic_Gallery_Controller',  
  100. NGG_BASIC_THUMBNAILS 
  101. ); 
  102.  
  103. // Provide defaults for the display types 
  104. $this->get_registry()->add_adapter( 
  105. 'I_Display_Type_Mapper',  
  106. 'A_NextGen_Basic_Gallery_Mapper' 
  107. ); 
  108.  
  109. // Provides validation for the display types 
  110. $this->get_registry()->add_adapter( 
  111. 'I_Display_Type',  
  112. 'A_NextGen_Basic_Gallery_Validation' 
  113. ); 
  114.  
  115. // Provides url generation support for the display types 
  116. $this->get_registry()->add_adapter( 
  117. 'I_Routing_App',  
  118. 'A_NextGen_Basic_Gallery_Urls' 
  119. ); 
  120.  
  121. function _register_hooks() 
  122. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id) 
  123. && (!defined('NGG_DISABLE_LEGACY_SHORTCODES') || !NGG_DISABLE_LEGACY_SHORTCODES)) 
  124. C_NextGen_Shortcode_Manager::add('random', array(&$this, 'render_random_images')); 
  125. C_NextGen_Shortcode_Manager::add('recent', array(&$this, 'render_recent_images')); 
  126. C_NextGen_Shortcode_Manager::add('thumb', array(&$this, 'render_thumb_shortcode')); 
  127. C_NextGen_Shortcode_Manager::add('slideshow', array(&$this, 'render_slideshow')); 
  128. C_NextGen_Shortcode_Manager::add('nggallery', array(&$this, 'render')); 
  129. C_NextGen_Shortcode_Manager::add('nggtags', array(&$this, 'render_based_on_tags')); 
  130. C_NextGen_Shortcode_Manager::add('nggslideshow', array(&$this, 'render_slideshow')); 
  131. C_NextGen_Shortcode_Manager::add('nggrandom', array(&$this, 'render_random_images')); 
  132. C_NextGen_Shortcode_Manager::add('nggrecent', array(&$this, 'render_recent_images')); 
  133. C_NextGen_Shortcode_Manager::add('nggthumb', array(&$this, 'render_thumb_shortcode')); 
  134.  
  135. add_action('ngg_routes', array(&$this, 'define_routes')); 
  136.  
  137. add_filter('ngg_atp_show_display_type', array($this, 'atp_show_basic_galleries'), 10, 2); 
  138.  
  139. function define_routes($router) 
  140. $slug = '/'.C_NextGen_Settings::get_instance()->router_param_slug; 
  141. $router->rewrite("{*}{$slug}{*}/image/{*}", "{1}{$slug}{2}/pid--{3}"); 
  142. $router->rewrite("{*}{$slug}{*}/slideshow/{*}", "{1}{$slug}{2}/show--" . NGG_BASIC_SLIDESHOW . "/{3}"); 
  143. $router->rewrite("{*}{$slug}{*}/thumbnails/{*}", "{1}{$slug}{2}/show--". NGG_BASIC_THUMBNAILS . "/{3}"); 
  144. $router->rewrite("{*}{$slug}{*}/show--slide/{*}", "{1}{$slug}{2}/show--" . NGG_BASIC_SLIDESHOW . "/{3}"); 
  145. $router->rewrite("{*}{$slug}{*}/show--gallery/{*}", "{1}{$slug}{2}/show--" . NGG_BASIC_THUMBNAILS . "/{3}"); 
  146. $router->rewrite("{*}{$slug}{*}/page/{\\d}{*}", "{1}{$slug}{2}/nggpage--{3}{4}"); 
  147.  
  148. /** 
  149. * ATP filters display types by not displaying those whose name attribute isn't an active POPE module. This 
  150. * is a workaround/hack to compensate for basic slideshow & thumbnails sharing a module. 
  151. * 
  152. * @param bool $available 
  153. * @param C_Display_Type $display_type 
  154. * @return bool 
  155. */ 
  156. function atp_show_basic_galleries($available, $display_type) 
  157. if (in_array($display_type->name, array(NGG_BASIC_THUMBNAILS, NGG_BASIC_SLIDESHOW))) 
  158. $available = TRUE; 
  159. return $available; 
  160.  
  161. /** 
  162. * Gets a value from the parameter array, and if not available, uses the default value 
  163. * 
  164. * @param string $name 
  165. * @param mixed $default 
  166. * @param array $params 
  167. * @return mixed 
  168. */ 
  169. function _get_param($name, $default, $params) 
  170. return (isset($params[$name])) ? $params[$name] : $default; 
  171.  
  172. /** 
  173. * Short-cut for rendering an thumbnail gallery 
  174. * @param array $params 
  175. * @param null $inner_content 
  176. * @return string 
  177. */ 
  178. function render($params, $inner_content=NULL) 
  179. $params['gallery_ids'] = $this->_get_param('id', NULL, $params); 
  180. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params); 
  181. if (isset($params['images'])) 
  182. $params['images_per_page'] = $this->_get_param('images', NULL, $params); 
  183. unset($params['id']); 
  184. unset($params['images']); 
  185.  
  186. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  187. return $renderer->display_images($params, $inner_content); 
  188.  
  189. function render_based_on_tags($params, $inner_content=NULL) 
  190. $params['tag_ids'] = $this->_get_param('gallery', $this->_get_param('album', array(), $params), $params); 
  191. $params['source'] = $this->_get_param('source', 'tags', $params); 
  192. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params); 
  193. unset($params['gallery']); 
  194.  
  195. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  196. return $renderer->display_images($params, $inner_content); 
  197.  
  198. function render_random_images($params, $inner_content=NULL) 
  199. $params['source'] = $this->_get_param('source', 'random', $params); 
  200. $params['images_per_page'] = $this->_get_param('max', NULL, $params); 
  201. $params['disable_pagination'] = $this->_get_param('disable_pagination', TRUE, $params); 
  202. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params); 
  203.  
  204. // inside if because Mixin_Displayed_Gallery_Instance_Methods->get_entities() doesn't handle NULL container_ids 
  205. // correctly 
  206. if (isset($params['id'])) 
  207. $params['container_ids'] = $this->_get_param('id', NULL, $params); 
  208.  
  209. unset($params['max']); 
  210. unset($params['id']); 
  211.  
  212. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  213. return $renderer->display_images($params, $inner_content); 
  214.  
  215. function render_recent_images($params, $inner_content=NULL) 
  216. $params['source'] = $this->_get_param('source', 'recent', $params); 
  217. $params['images_per_page'] = $this->_get_param('max', NULL, $params); 
  218. $params['disable_pagination'] = $this->_get_param('disable_pagination', TRUE, $params); 
  219. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params); 
  220.  
  221. if (isset($params['id'])) 
  222. $params['container_ids'] = $this->_get_param('id', NULL, $params); 
  223.  
  224. unset($params['max']); 
  225. unset($params['id']); 
  226.  
  227. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  228. return $renderer->display_images($params, $inner_content); 
  229.  
  230. function render_thumb_shortcode($params, $inner_content=NULL) 
  231. $params['entity_ids'] = $this->_get_param('id', NULL, $params); 
  232. $params['source'] = $this->_get_param('source', 'galleries', $params); 
  233. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params); 
  234. unset($params['id']); 
  235.  
  236. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  237. return $renderer->display_images($params, $inner_content); 
  238.  
  239. function render_slideshow($params, $inner_content=NULL) 
  240. $params['gallery_ids'] = $this->_get_param('id', NULL, $params); 
  241. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_SLIDESHOW, $params); 
  242. $params['gallery_width'] = $this->_get_param('w', NULL, $params); 
  243. $params['gallery_height'] = $this->_get_param('h', NULL, $params); 
  244. unset($params['id'], $params['w'], $params['h']); 
  245.  
  246. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  247. return $renderer->display_images($params, $inner_content); 
  248. }  
  249.  
  250. /** 
  251. * Wrapper to I_Displayed_Gallery_Renderer->display_images(); this will display 
  252. * a basic thumbnails gallery 
  253. * 
  254. * @param int $galleryID Gallery ID 
  255. * @param string $template Path to template file 
  256. * @param bool $images_per_page Basic thumbnails setting 
  257. */ 
  258. function nggShowGallery($galleryID, $template = '', $images_per_page = FALSE) 
  259. $args = array( 
  260. 'source' => 'galleries',  
  261. 'container_ids' => $galleryID 
  262. ); 
  263.  
  264. if (apply_filters('ngg_show_imagebrowser_first', FALSE, $galleryID)) 
  265. $args['display_type'] = NGG_BASIC_IMAGEBROWSER; 
  266. else 
  267. $args['display_type'] = NGG_BASIC_THUMBNAILS; 
  268.  
  269. if (!empty($template)) 
  270. $args['template'] = $template; 
  271. if (!empty($images_per_page)) 
  272. $args['images_per_page'] = $images_per_page; 
  273.  
  274. echo C_Displayed_Gallery_Renderer::get_instance()->display_images($args); 
  275.  
  276.  
  277. /** 
  278. * Wrapper to I_Displayed_Gallery_Renderer->display_images(); this will display 
  279. * a basic slideshow gallery 
  280. * 
  281. * @param int $galleryID Gallery ID 
  282. * @param int $width Gallery width 
  283. * @param int $height Gallery height 
  284. */ 
  285. function nggShowSlideshow($galleryID, $width, $height) 
  286. $args = array( 
  287. 'source' => 'galleries',  
  288. 'container_ids' => $galleryID,  
  289. 'gallery_width' => $width,  
  290. 'gallery_height' => $height,  
  291. 'display_type' => NGG_BASIC_SLIDESHOW 
  292. ); 
  293.  
  294. echo C_Displayed_Gallery_Renderer::get_instance()->display_images($args); 
  295.  
  296. class C_NextGen_Basic_Gallery_Installer extends C_Gallery_Display_Installer 
  297. function install($reset = FALSE) 
  298. $this->install_display_type(NGG_BASIC_THUMBNAILS,  
  299. array( 
  300. 'title' => __('NextGEN Basic Thumbnails', 'nggallery'),  
  301. 'entity_types' => array('image'),  
  302. 'preview_image_relpath' => 'photocrati-nextgen_basic_gallery#thumb_preview.jpg',  
  303. 'default_source' => 'galleries',  
  304. 'view_order' => NGG_DISPLAY_PRIORITY_BASE,  
  305. 'aliases' => array( 
  306. 'basic_thumbnail',  
  307. 'basic_thumbnails',  
  308. 'nextgen_basic_thumbnails',  
  309. ); 
  310.  
  311. $this->install_display_type(NGG_BASIC_SLIDESHOW,  
  312. array( 
  313. 'title' => __('NextGEN Basic Slideshow', 'nggallery'),  
  314. 'entity_types' => array('image'),  
  315. 'preview_image_relpath' => 'photocrati-nextgen_basic_gallery#slideshow_preview.jpg',  
  316. 'default_source' => 'galleries',  
  317. 'view_order' => NGG_DISPLAY_PRIORITY_BASE + 10,  
  318. 'aliases' => array( 
  319. 'basic_slideshow',  
  320. 'nextgen_basic_slideshow' 
  321. ); 
  322.  
  323. new M_NextGen_Basic_Gallery; 
.