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

  1. <?php 
  2. /** 
  3. * Class A_NextGen_Basic_Singlepic 
  4. * @mixin C_Display_Type 
  5. * @adapts I_Display_Type 
  6. */ 
  7. class A_NextGen_Basic_Singlepic extends Mixin 
  8. function validation() 
  9. if ($this->object->name == NGG_BASIC_SINGLEPIC) { 
  10. return $this->call_parent('validation'); 
  11. /** 
  12. * Class A_NextGen_Basic_Singlepic_Controller 
  13. * @mixin C_Display_Type_Controller 
  14. * @adapts I_Display_Type_Controller for "photocrati-nextgen_basic_singlepic" context 
  15. */ 
  16. class A_NextGen_Basic_Singlepic_Controller extends Mixin 
  17. /** 
  18. * Displays the 'singlepic' display type 
  19. * 
  20. * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery 
  21. */ 
  22. function index_action($displayed_gallery, $return = FALSE) 
  23. $storage = C_Gallery_Storage::get_instance(); 
  24. $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); 
  25. $display_settings = $displayed_gallery->display_settings; 
  26. // use this over get_included_entities() so we can display images marked 'excluded' 
  27. $displayed_gallery->skip_excluding_globally_excluded_images = TRUE; 
  28. $image = array_shift($displayed_gallery->get_entities(1, FALSE, FALSE, 'included')); 
  29. if (!$image) { 
  30. return $this->object->render_partial("photocrati-nextgen_gallery_display#no_images_found", array(), $return); 
  31. switch ($display_settings['float']) { 
  32. case 'left': 
  33. $display_settings['float'] = 'ngg-left'; 
  34. break; 
  35. case 'right': 
  36. $display_settings['float'] = 'ngg-right'; 
  37. break; 
  38. case 'center': 
  39. $display_settings['float'] = 'ngg-center'; 
  40. break; 
  41. default: 
  42. $display_settings['float'] = ''; 
  43. break; 
  44. $params = array(); 
  45. if (!empty($display_settings['link'])) { 
  46. $target = $display_settings['link_target']; 
  47. $effect_code = ''; 
  48. } else { 
  49. $display_settings['link'] = $storage->get_image_url($image, 'full', TRUE); 
  50. $target = '_self'; 
  51. $effect_code = $this->object->get_effect_code($displayed_gallery); 
  52. $params['target'] = $target; 
  53. // mode is a legacy parameter 
  54. if (!is_array($display_settings['mode'])) { 
  55. $display_settings['mode'] = explode(', ', $display_settings['mode']); 
  56. if (in_array('web20', $display_settings['mode'])) { 
  57. $display_settings['display_reflection'] = TRUE; 
  58. if (in_array('watermark', $display_settings['mode'])) { 
  59. $display_settings['display_watermark'] = TRUE; 
  60. if (isset($display_settings['w'])) { 
  61. $display_settings['width'] = $display_settings['w']; 
  62. } elseif (isset($display_settings['h'])) { 
  63. unset($display_settings['width']); 
  64. if (isset($display_settings['h'])) { 
  65. $display_settings['height'] = $display_settings['h']; 
  66. } elseif (isset($display_settings['w'])) { 
  67. unset($display_settings['height']); 
  68. // legacy assumed no width/height meant full size unlike generate_thumbnail: force a full resolution 
  69. if (!isset($display_settings['width']) && !isset($display_settings['height'])) { 
  70. $display_settings['width'] = $image->meta_data['width']; 
  71. if (isset($display_settings['width'])) { 
  72. $params['width'] = $display_settings['width']; 
  73. if (isset($display_settings['height'])) { 
  74. $params['height'] = $display_settings['height']; 
  75. $params['quality'] = $display_settings['quality']; 
  76. $params['crop'] = $display_settings['crop']; 
  77. $params['watermark'] = $display_settings['display_watermark']; 
  78. $params['reflection'] = $display_settings['display_reflection']; 
  79. // Fall back to full in case dynamic images aren't available 
  80. $size = 'full'; 
  81. if ($dynthumbs != null) { 
  82. $size = $dynthumbs->get_size_name($params); 
  83. $thumbnail_url = $storage->get_image_url($image, $size); 
  84. if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { 
  85. $this->object->add_mixin('A_NextGen_Basic_Template_Form'); 
  86. $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); 
  87. $params = $this->object->prepare_legacy_parameters(array($image), $displayed_gallery, array('single_image' => TRUE)); 
  88. // the wrapper is a lazy-loader that calculates variables when requested. We here override those to always 
  89. // return the same precalculated settings provided 
  90. $params['image']->container[0]->_cache_overrides['caption'] = $displayed_gallery->inner_content; 
  91. $params['image']->container[0]->_cache_overrides['classname'] = 'ngg-singlepic ' . $display_settings['float']; 
  92. $params['image']->container[0]->_cache_overrides['imageURL'] = $display_settings['link']; 
  93. $params['image']->container[0]->_cache_overrides['thumbnailURL'] = $thumbnail_url; 
  94. $params['target'] = $target; 
  95. // if a link is present we temporarily must filter out the effect code 
  96. if (empty($effect_code)) { 
  97. add_filter('ngg_get_thumbcode', array(&$this, 'strip_thumbcode'), 10); 
  98. $retval = $this->object->legacy_render($display_settings['template'], $params, $return, 'singlepic'); 
  99. if (empty($effect_code)) { 
  100. remove_filter('ngg_get_thumbcode', array(&$this, 'strip_thumbcode'), 10); 
  101. return $retval; 
  102. } else { 
  103. $params = $display_settings; 
  104. $params['storage'] =& $storage; 
  105. $params['image'] =& $image; 
  106. $params['effect_code'] = $effect_code; 
  107. $params['inner_content'] = $displayed_gallery->inner_content; 
  108. $params['settings'] = $display_settings; 
  109. $params['thumbnail_url'] = $thumbnail_url; 
  110. $params['target'] = $target; 
  111. $params = $this->object->prepare_display_parameters($displayed_gallery, $params); 
  112. return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic', $params, $return); 
  113. /** 
  114. * Intentionally disable the application of the effect code 
  115. */ 
  116. function strip_thumbcode($thumbcode) 
  117. return ''; 
  118. /** 
  119. * Enqueues all static resources required by this display type 
  120. * 
  121. * @param C_Displayed_Gallery $displayed_gallery 
  122. */ 
  123. function enqueue_frontend_resources($displayed_gallery) 
  124. $this->call_parent('enqueue_frontend_resources', $displayed_gallery); 
  125. wp_enqueue_style('nextgen_basic_singlepic_style', $this->get_static_url('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic.css'), FALSE, NGG_SCRIPT_VERSION); 
  126. $this->enqueue_ngg_styles(); 
  127. /** 
  128. * Class A_NextGen_Basic_SinglePic_Form 
  129. * @mixin C_Form 
  130. * @adapts I_Form for "photocrati-nextgen_basic_singlepic" context 
  131. */ 
  132. class A_NextGen_Basic_SinglePic_Form extends Mixin_Display_Type_Form 
  133. /** 
  134. * Returns the name of the display type 
  135. * @return string 
  136. */ 
  137. function get_display_type_name() 
  138. return NGG_BASIC_SINGLEPIC; 
  139. /** 
  140. * Returns the name of the fields to render for the SinglePic 
  141. */ 
  142. function _get_field_names() 
  143. return array('nextgen_basic_singlepic_dimensions', 'nextgen_basic_singlepic_link', 'nextgen_basic_singlepic_link_target', 'nextgen_basic_singlepic_float', 'nextgen_basic_singlepic_quality', 'nextgen_basic_singlepic_crop', 'nextgen_basic_singlepic_display_watermark', 'nextgen_basic_singlepic_display_reflection', 'nextgen_basic_templates_template'); 
  144. function _render_nextgen_basic_singlepic_dimensions_field($display_type) 
  145. return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic_settings_dimensions', array('display_type_name' => $display_type->name, 'dimensions_label' => __('Thumbnail dimensions', 'nggallery'), 'width_label' => __('Width'), 'width' => $display_type->settings['width'], 'height_label' => __('Height'), 'height' => $display_type->settings['height']), True); 
  146. function _render_nextgen_basic_singlepic_link_field($display_type) 
  147. return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic_settings_link', array('display_type_name' => $display_type->name, 'link_label' => __('Link'), 'link' => $display_type->settings['link']), True); 
  148. function _render_nextgen_basic_singlepic_link_target_field($display_type) 
  149. return $this->_render_select_field($display_type, 'link_target', __('Link target', 'nggallery'), array('_self' => __('Self', 'nggallery'), '_blank' => __('Blank', 'nggallery'), '_parent' => __('Parent', 'nggallery'), '_top' => __('Top', 'nggallery')), $display_type->settings['link_target']); 
  150. function _render_nextgen_basic_singlepic_quality_field($display_type) 
  151. return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic_settings_quality', array('display_type_name' => $display_type->name, 'quality_label' => __('Image quality', 'nggallery'), 'quality' => $display_type->settings['quality']), True); 
  152. function _render_nextgen_basic_singlepic_display_watermark_field($display_type) 
  153. return $this->_render_radio_field($display_type, 'display_watermark', __('Display watermark', 'nggallery'), $display_type->settings['display_watermark']); 
  154. function _render_nextgen_basic_singlepic_display_reflection_field($display_type) 
  155. return $this->_render_radio_field($display_type, 'display_reflection', __('Display reflection', 'nggallery'), $display_type->settings['display_reflection']); 
  156. function _render_nextgen_basic_singlepic_crop_field($display_type) 
  157. return $this->_render_radio_field($display_type, 'crop', __('Crop thumbnail', 'nggallery'), $display_type->settings['crop']); 
  158. function _render_nextgen_basic_singlepic_float_field($display_type) 
  159. return $this->_render_select_field($display_type, 'float', __('Float', 'nggallery'), array('' => __('None', 'nggallery'), 'left' => __('Left', 'nggallery'), 'right' => __('Right', 'nggallery')), $display_type->settings['float']); 
  160. /** 
  161. * Class A_NextGen_Basic_SinglePic_Mapper 
  162. * @mixin C_Display_Type_Mapper 
  163. * @adapts I_Display_Type_Mapper 
  164. */ 
  165. class A_NextGen_Basic_SinglePic_Mapper extends Mixin 
  166. /** 
  167. * Sets default values for SinglePic settings 
  168. * @param stdClass|C_DataMapper_Model $entity 
  169. */ 
  170. function set_defaults($entity) 
  171. $this->call_parent('set_defaults', $entity); 
  172. if (isset($entity->name) && $entity->name == NGG_BASIC_SINGLEPIC) { 
  173. $this->object->_set_default_value($entity, 'settings', 'width', ''); 
  174. $this->object->_set_default_value($entity, 'settings', 'height', ''); 
  175. $this->object->_set_default_value($entity, 'settings', 'mode', ''); 
  176. $this->object->_set_default_value($entity, 'settings', 'display_watermark', 0); 
  177. $this->object->_set_default_value($entity, 'settings', 'display_reflection', 0); 
  178. $this->object->_set_default_value($entity, 'settings', 'float', ''); 
  179. $this->object->_set_default_value($entity, 'settings', 'link', ''); 
  180. $this->object->_set_default_value($entity, 'settings', 'link_target', '_blank'); 
  181. $this->object->_set_default_value($entity, 'settings', 'quality', 100); 
  182. $this->object->_set_default_value($entity, 'settings', 'crop', 0); 
  183. $this->object->_set_default_value($entity, 'settings', 'template', ''); 
  184. // Part of the pro-modules 
  185. $this->object->_set_default_value($entity, 'settings', 'ngg_triggers_display', 'never'); 
.