/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/module.nextgen_basic_imagebrowser.php

  1. <?php 
  2. /*** 
  3. { 
  4. Module: photocrati-nextgen_basic_imagebrowser,  
  5. Depends: { photocrati-nextgen_gallery_display } 
  6. } 
  7. ***/ 
  8.  
  9. define( 
  10. 'NGG_BASIC_IMAGEBROWSER',  
  11. 'photocrati-nextgen_basic_imagebrowser' 
  12. ); 
  13.  
  14. class M_NextGen_Basic_ImageBrowser extends C_Base_Module 
  15. function define($id = 'pope-module',  
  16. $name = 'Pope Module',  
  17. $description = '',  
  18. $version = '',  
  19. $uri = '',  
  20. $author = '',  
  21. $author_uri = '',  
  22. $context = FALSE) 
  23. parent::define( 
  24. 'photocrati-nextgen_basic_imagebrowser',  
  25. 'NextGEN Basic ImageBrowser',  
  26. 'Provides the NextGEN Basic ImageBrowser Display Type',  
  27. '0.14',  
  28. 'https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/',  
  29. 'Imagely',  
  30. 'https://www.imagely.com' 
  31. ); 
  32.  
  33. C_Photocrati_Installer::add_handler($this->module_id, 'C_NextGen_Basic_ImageBrowser_Installer'); 
  34.  
  35. function initialize() 
  36. parent::initialize(); 
  37. if (is_admin()) { 
  38. $forms = C_Form_Manager::get_instance(); 
  39. $forms->add_form( 
  40. NGG_DISPLAY_SETTINGS_SLUG, NGG_BASIC_IMAGEBROWSER 
  41. ); 
  42.  
  43. /** 
  44. * Register adapters required for the NextGen Basic ImageBrowser 
  45. */ 
  46. function _register_adapters() 
  47. $this->get_registry()->add_adapter( 
  48. 'I_Display_Type_Mapper', 'A_NextGen_Basic_ImageBrowser_Mapper' 
  49. ); 
  50.  
  51. // Add validation for the display type 
  52. $this->get_registry()->add_adapter( 
  53. 'I_Display_Type', 'A_NextGen_Basic_ImageBrowser' 
  54. ); 
  55.  
  56. // Add imagebrowser ngglegacy-compatible urls 
  57. $this->get_registry()->add_adapter( 
  58. 'I_Routing_App', 'A_NextGen_Basic_ImageBrowser_Urls' 
  59. ); 
  60.  
  61. if (M_Attach_To_Post::is_atp_url() || is_admin()) 
  62. // Provide the imagebrowser form 
  63. $this->get_registry()->add_adapter( 
  64. 'I_Form',  
  65. 'A_NextGen_Basic_ImageBrowser_Form',  
  66. $this->module_id 
  67. ); 
  68.  
  69. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id)) 
  70. // Add rendering logic 
  71. $this->get_registry()->add_adapter( 
  72. 'I_Display_Type_Controller',  
  73. 'A_NextGen_Basic_ImageBrowser_Controller',  
  74. $this->module_id 
  75. ); 
  76.  
  77. function _register_hooks() 
  78. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id) 
  79. && (!defined('NGG_DISABLE_LEGACY_SHORTCODES') || !NGG_DISABLE_LEGACY_SHORTCODES)) 
  80. C_NextGen_Shortcode_Manager::add('imagebrowser', array(&$this, 'render_shortcode')); 
  81. C_NextGen_Shortcode_Manager::add('nggimagebrowser', array(&$this, 'render_shortcode')); 
  82.  
  83. add_action('ngg_routes', array(&$this, 'define_routes')); 
  84.  
  85. function define_routes($router) 
  86. $slug = '/'.C_NextGen_Settings::get_instance()->router_param_slug; 
  87. $router->rewrite("{*}{$slug}{*}/image/{\\w}", "{1}{$slug}{2}/pid--{3}"); 
  88.  
  89. /** 
  90. * Gets a value from the parameter array, and if not available, uses the default value 
  91. * 
  92. * @param string $name 
  93. * @param mixed $default 
  94. * @param array $params 
  95. * @return mixed 
  96. */ 
  97. function _get_param($name, $default, $params) 
  98. return (isset($params[$name])) ? $params[$name] : $default; 
  99.  
  100. function render_shortcode($params, $inner_content=NULL) 
  101. $params['gallery_ids'] = $this->_get_param('id', NULL, $params); 
  102. $params['source'] = $this->_get_param('source', 'galleries', $params); 
  103. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_IMAGEBROWSER, $params); 
  104.  
  105. unset($params['id']); 
  106.  
  107. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  108. return $renderer->display_images($params, $inner_content); 
  109.  
  110. function get_type_list() 
  111. return array( 
  112. 'A_Nextgen_Basic_Imagebrowser' => 'adapter.nextgen_basic_imagebrowser.php',  
  113. 'A_Nextgen_Basic_Imagebrowser_Controller' => 'adapter.nextgen_basic_imagebrowser_controller.php',  
  114. 'A_Nextgen_Basic_Imagebrowser_Form' => 'adapter.nextgen_basic_imagebrowser_form.php',  
  115. 'C_Nextgen_Basic_Imagebrowser_Installer' => 'class.nextgen_basic_imagebrowser_installer.php',  
  116. 'A_Nextgen_Basic_Imagebrowser_Mapper' => 'adapter.nextgen_basic_imagebrowser_mapper.php',  
  117. 'A_Nextgen_Basic_Imagebrowser_Urls' => 'adapter.nextgen_basic_imagebrowser_urls.php',  
  118. ); 
  119.  
  120. /** 
  121. * Show an image browser. Ngglegacy function 
  122. * @param $galleryID 
  123. * @param string $template 
  124. */ 
  125. function nggShowImageBrowser($galleryID, $template = '') 
  126. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  127. $retval = $renderer->display_images(array( 
  128. 'gallery_ids' => array($galleryID),  
  129. 'display_type' => 'photocrati-nextgen_basic_imagebrowser',  
  130. 'template' => $template 
  131. )); 
  132.  
  133. return apply_filters('ngg_show_imagebrowser_content', $retval, $galleryID); 
  134.  
  135. /** 
  136. * Create an image browser from a list of image objects. Ngglegacy function 
  137. * @param $picturelist 
  138. * @param string $template 
  139. */ 
  140. function nggCreateImageBrowser($picturelist, $template = '') 
  141. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  142. $image_ids = array(); 
  143. foreach ($picturelist as $image) $image_ids[] = $image->pid; 
  144. return $renderer->display_images(array( 
  145. 'image_ids' => $image_ids,  
  146. 'display_type' => 'photocrati-nextgen_basic_imagebrowser',  
  147. 'template' => $template 
  148. )); 
  149.  
  150. class C_NextGen_Basic_ImageBrowser_Installer extends C_Gallery_Display_Installer 
  151. function install($reset = FALSE) 
  152. $this->install_display_type( 
  153. NGG_BASIC_IMAGEBROWSER, array( 
  154. 'title' => __('NextGEN Basic ImageBrowser', 'nggallery'),  
  155. 'entity_types' => array('image'),  
  156. 'preview_image_relpath' => 'photocrati-nextgen_basic_imagebrowser#preview.jpg',  
  157. 'default_source' => 'galleries',  
  158. 'view_order' => NGG_DISPLAY_PRIORITY_BASE + 20,  
  159. 'aliases' => array( 
  160. 'basic_imagebrowser',  
  161. 'imagebrowser',  
  162. 'nextgen_basic_imagebrowser' 
  163. ); 
  164.  
  165. new M_NextGen_Basic_ImageBrowser(); 
.