/products/photocrati_nextgen/modules/nextgen_basic_singlepic/module.nextgen_basic_singlepic.php

  1. <?php 
  2.  
  3. /*** 
  4. { 
  5. Module: photocrati-nextgen_basic_singlepic,  
  6. Depends: { photocrati-nextgen_gallery_display } 
  7. } 
  8. ***/ 
  9.  
  10. define('NGG_BASIC_SINGLEPIC', 'photocrati-nextgen_basic_singlepic'); 
  11.  
  12. class M_NextGen_Basic_Singlepic extends C_Base_Module 
  13. function define($id = 'pope-module',  
  14. $name = 'Pope Module',  
  15. $description = '',  
  16. $version = '',  
  17. $uri = '',  
  18. $author = '',  
  19. $author_uri = '',  
  20. $context = FALSE) 
  21. parent::define( 
  22. NGG_BASIC_SINGLEPIC,  
  23. 'NextGen Basic Singlepic',  
  24. 'Provides a singlepic gallery for NextGEN Gallery',  
  25. '0.14',  
  26. 'https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/',  
  27. 'Imagely',  
  28. 'https://www.imagely.com' 
  29. ); 
  30.  
  31. C_Photocrati_Installer::add_handler($this->module_id, 'C_NextGen_Basic_SinglePic_Installer'); 
  32.  
  33. function initialize() 
  34. parent::initialize(); 
  35. if (is_admin()) { 
  36. $forms = C_Form_Manager::get_instance(); 
  37. $forms->add_form( 
  38. NGG_DISPLAY_SETTINGS_SLUG, NGG_BASIC_SINGLEPIC 
  39. ); 
  40.  
  41.  
  42. function _register_adapters() 
  43. // Provides default values for the display type 
  44. $this->get_registry()->add_adapter( 
  45. 'I_Display_Type_Mapper',  
  46. 'A_NextGen_Basic_Singlepic_Mapper' 
  47. ); 
  48.  
  49. if (M_Attach_To_Post::is_atp_url() || is_admin()) 
  50. // Provides the display settings form for the SinglePic display type 
  51. $this->get_registry()->add_adapter( 
  52. 'I_Form',  
  53. 'A_NextGen_Basic_SinglePic_Form',  
  54. $this->module_id 
  55. ); 
  56.  
  57. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id)) 
  58. // Provides settings fields and frontend rendering 
  59. $this->get_registry()->add_adapter( 
  60. 'I_Display_Type_Controller',  
  61. 'A_NextGen_Basic_Singlepic_Controller',  
  62. $this->module_id 
  63. ); 
  64.  
  65. function _register_hooks() 
  66. if (apply_filters('ngg_load_frontend_logic', TRUE, $this->module_id) 
  67. && (!defined('NGG_DISABLE_LEGACY_SHORTCODES') || !NGG_DISABLE_LEGACY_SHORTCODES)) 
  68. C_NextGen_Shortcode_Manager::add('singlepic', array(&$this, 'render_singlepic')); 
  69. C_NextGen_Shortcode_Manager::add('nggsinglepic', array(&$this, 'render_singlepic')); 
  70.  
  71. // enqueue the singlepic CSS if an inline image has the ngg-singlepic class 
  72. add_filter('the_content', array(&$this, 'enqueue_singlepic_css'), PHP_INT_MAX, 1); 
  73.  
  74. /** 
  75. * Examines 'the_content' string for img.ngg-singlepic and enqueues styling when found 
  76. * 
  77. * @param string $content 
  78. * @return string $content 
  79. */ 
  80. function enqueue_singlepic_css($content) 
  81. if (preg_match("#<img.*ngg-singlepic.*>#", $content, $matches)) { 
  82. $router = C_Router::get_instance(); 
  83. wp_enqueue_style( 
  84. 'nextgen_basic_singlepic_style',  
  85. $router->get_static_url(NGG_BASIC_SINGLEPIC . '#nextgen_basic_singlepic.css'),  
  86. FALSE,  
  87. NGG_SCRIPT_VERSION 
  88. ); 
  89.  
  90. return $content; 
  91.  
  92. /** 
  93. * Gets a value from the parameter array, and if not available, uses the default value 
  94. * 
  95. * @param string $name 
  96. * @param mixed $default 
  97. * @param array $params 
  98. * @return mixed 
  99. */ 
  100. function _get_param($name, $default, $params) 
  101. return (isset($params[$name])) ? $params[$name] : $default; 
  102.  
  103. function render_singlepic($params, $inner_content=NULL) 
  104. $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_SINGLEPIC, $params); 
  105. $params['image_ids'] = $this->_get_param('id', NULL, $params); 
  106. unset($params['id']); 
  107.  
  108. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  109. return $renderer->display_images($params, $inner_content); 
  110.  
  111. function get_type_list() 
  112. return array( 
  113. 'A_Nextgen_Basic_Singlepic' => 'adapter.nextgen_basic_singlepic.php',  
  114. 'A_Nextgen_Basic_Singlepic_Controller' => 'adapter.nextgen_basic_singlepic_controller.php',  
  115. 'A_Nextgen_Basic_Singlepic_Form' => 'adapter.nextgen_basic_singlepic_form.php',  
  116. 'C_NextGen_Basic_SinglePic_Installer' => 'class.nextgen_basic_singlepic_installer.php',  
  117. 'A_Nextgen_Basic_Singlepic_Mapper' => 'adapter.nextgen_basic_singlepic_mapper.php' 
  118. ); 
  119.  
  120. class C_NextGen_Basic_SinglePic_Installer extends C_Gallery_Display_Installer 
  121. function install($reset = FALSE) 
  122. $this->install_display_type( 
  123. NGG_BASIC_SINGLEPIC, array( 
  124. 'title' => __('NextGEN Basic SinglePic', 'nggallery'),  
  125. 'entity_types' => array('image'),  
  126. 'preview_image_relpath' => 'photocrati-nextgen_basic_singlepic#preview.gif',  
  127. 'default_source' => 'galleries',  
  128. 'view_order' => NGG_DISPLAY_PRIORITY_BASE + 60,  
  129. 'hidden_from_ui' => TRUE, // todo remove this, use hidden_from_igw instead 
  130. 'hidden_from_igw' => TRUE,  
  131. 'aliases' => array( 
  132. 'basic_singlepic',  
  133. 'singlepic',  
  134. 'nextgen_basic_singlepic' 
  135. )); 
  136.  
  137. new M_NextGen_Basic_Singlepic(); 
.