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