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

  1. <?php 
  2. /** 
  3. * Adds validation for the NextGen Basic ImageBrowser display type 
  4. * @mixin C_Display_Type 
  5. * @adapts I_Display_Type 
  6. */ 
  7. class A_NextGen_Basic_ImageBrowser extends Mixin 
  8. function validation() 
  9. return $this->call_parent('validation'); 
  10. /** 
  11. * Provides rendering logic for the NextGen Basic ImageBrowser 
  12. * @mixin C_Display_Type_Controller 
  13. * @adapts I_Display_Type_Controller for "photocrati-nextgen_basic_imagebrowser" context 
  14. */ 
  15. class A_NextGen_Basic_ImageBrowser_Controller extends Mixin 
  16. /** 
  17. * Renders the front-end display for the imagebrowser display type 
  18. * 
  19. * @param C_Displayed_Gallery $displayed_gallery 
  20. * @param bool $return 
  21. * @return string 
  22. */ 
  23. function index_action($displayed_gallery, $return = FALSE) 
  24. $picture_list = array(); 
  25. foreach ($displayed_gallery->get_included_entities() as $image) { 
  26. $picture_list[$image->{$image->id_field}] = $image; 
  27. if ($picture_list) { 
  28. $retval = $this->render_image_browser($displayed_gallery, $picture_list); 
  29. if ($return) { 
  30. return $retval; 
  31. } else { 
  32. echo $retval; 
  33. } else { 
  34. return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); 
  35. /** 
  36. * Returns the rendered template of an image browser display 
  37. * 
  38. * @param C_Displayed_Gallery 
  39. * @param array $picture_list 
  40. * @return string Rendered HTML (probably) 
  41. */ 
  42. function render_image_browser($displayed_gallery, $picture_list) 
  43. $display_settings = $displayed_gallery->display_settings; 
  44. $storage = C_Gallery_Storage::get_instance(); 
  45. $imap = C_Image_Mapper::get_instance(); 
  46. $application = C_Router::get_instance()->get_routed_app(); 
  47. // the pid may be a slug so we must track it & the slug target's database id 
  48. $pid = $this->object->param('pid'); 
  49. $numeric_pid = NULL; 
  50. // makes the upcoming which-image-am-I loop easier 
  51. $picture_array = array(); 
  52. foreach ($picture_list as $picture) { 
  53. $picture_array[] = $picture->{$imap->get_primary_key_column()}; 
  54. // Determine which image in the list we need to display 
  55. if (!empty($pid)) { 
  56. if (is_numeric($pid) && !empty($picture_list[$pid])) { 
  57. $numeric_pid = intval($pid); 
  58. } else { 
  59. // in the case it's a slug we need to search for the pid 
  60. foreach ($picture_list as $key => $picture) { 
  61. if ($picture->image_slug == $pid) { 
  62. $numeric_pid = $key; 
  63. break; 
  64. } else { 
  65. reset($picture_array); 
  66. $numeric_pid = current($picture_array); 
  67. // get ids to the next and previous images 
  68. $total = count($picture_array); 
  69. $key = array_search($numeric_pid, $picture_array); 
  70. if (!$key) { 
  71. $numeric_pid = reset($picture_array); 
  72. $key = key($picture_array); 
  73. // for "viewing image #13 of $total" 
  74. $picture_list_pos = $key + 1; 
  75. // our image to display 
  76. $picture = new C_Image_Wrapper($imap->find($numeric_pid), $displayed_gallery, TRUE); 
  77. $picture = apply_filters('ngg_image_object', $picture, $numeric_pid); 
  78. // determine URI to the next & previous images 
  79. $back_pid = $key >= 1 ? $picture_array[$key - 1] : end($picture_array); 
  80. // 'show' is set when using the imagebrowser as an alternate view to a thumbnail or slideshow 
  81. // for which the basic-gallery module will rewrite the show parameter into existence as long as 'image' 
  82. // is set. We remove 'show' here so navigation appears fluid. 
  83. $current_url = $application->get_routed_url(TRUE); 
  84. if ($this->object->param('ajax_pagination_referrer')) { 
  85. $current_url = $this->object->param('ajax_pagination_referrer'); 
  86. $prev_image_link = $this->object->set_param_for($current_url, 'pid', $picture_list[$back_pid]->image_slug); 
  87. $prev_image_link = $this->object->remove_param_for($prev_image_link, 'show', $displayed_gallery->id()); 
  88. $next_pid = $key < $total - 1 ? $picture_array[$key + 1] : reset($picture_array); 
  89. $next_image_link = $this->object->set_param_for($current_url, 'pid', $picture_list[$next_pid]->image_slug); 
  90. $next_image_link = $this->object->remove_param_for($next_image_link, 'show', $displayed_gallery->id()); 
  91. // css class 
  92. $anchor = 'ngg-imagebrowser-' . $displayed_gallery->id() . '-' . (get_the_ID() == false ? 0 : get_the_ID()); 
  93. // try to read EXIF data, but fallback to the db presets 
  94. $meta = new C_NextGen_Metadata($picture); 
  95. $meta->sanitize(); 
  96. $meta_results = array('exif' => $meta->get_EXIF(), 'iptc' => $meta->get_IPTC(), 'xmp' => $meta->get_XMP(), 'db' => $meta->get_saved_meta()); 
  97. $meta_results['exif'] = $meta_results['exif'] == false ? $meta_results['db'] : $meta_results['exif']; 
  98. // disable triggers IF we're rendering inside of an ajax-pagination request; var set in common.js 
  99. if (!empty($_POST['ajax_referrer'])) { 
  100. $displayed_gallery->display_settings['ngg_triggers_display'] = 'never'; 
  101. if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { 
  102. $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); 
  103. $picture->href_link = $picture->get_href_link(); 
  104. $picture->previous_image_link = $prev_image_link; 
  105. $picture->previous_pid = $back_pid; 
  106. $picture->next_image_link = $next_image_link; 
  107. $picture->next_pid = $next_pid; 
  108. $picture->number = $picture_list_pos; 
  109. $picture->total = $total; 
  110. $picture->anchor = $anchor; 
  111. return $this->object->legacy_render($display_settings['template'], array('image' => $picture, 'meta' => $meta, 'exif' => $meta_results['exif'], 'iptc' => $meta_results['iptc'], 'xmp' => $meta_results['xmp'], 'db' => $meta_results['db'], 'displayed_gallery' => $displayed_gallery), TRUE, 'imagebrowser'); 
  112. } else { 
  113. $params = $display_settings; 
  114. $params['anchor'] = $anchor; 
  115. $params['image'] = $picture; 
  116. $params['storage'] =& $storage; 
  117. $params['previous_pid'] = $back_pid; 
  118. $params['next_pid'] = $next_pid; 
  119. $params['number'] = $picture_list_pos; 
  120. $params['total'] = $total; 
  121. $params['previous_image_link'] = $prev_image_link; 
  122. $params['next_image_link'] = $next_image_link; 
  123. $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); 
  124. $params = $this->object->prepare_display_parameters($displayed_gallery, $params); 
  125. return $this->object->render_partial('photocrati-nextgen_basic_imagebrowser#nextgen_basic_imagebrowser', $params, TRUE); 
  126. /** 
  127. * Enqueues all static resources required by this display type 
  128. * 
  129. * @param C_Displayed_Gallery $displayed_gallery 
  130. */ 
  131. function enqueue_frontend_resources($displayed_gallery) 
  132. $this->call_parent('enqueue_frontend_resources', $displayed_gallery); 
  133. wp_enqueue_style('nextgen_basic_imagebrowser_style', $this->get_static_url('photocrati-nextgen_basic_imagebrowser#style.css'), FALSE, NGG_SCRIPT_VERSION); 
  134. $this->enqueue_ngg_styles(); 
  135. /** 
  136. * Class A_NextGen_Basic_ImageBrowser_Form 
  137. * @mixin C_Form 
  138. * @adapts I_Form for "photocrati-nextgen_basic_imagebrowser" context 
  139. */ 
  140. class A_NextGen_Basic_ImageBrowser_Form extends Mixin_Display_Type_Form 
  141. function get_display_type_name() 
  142. return NGG_BASIC_IMAGEBROWSER; 
  143. /** 
  144. * Returns a list of fields to render on the settings page 
  145. */ 
  146. function _get_field_names() 
  147. return array('ajax_pagination', 'nextgen_basic_templates_template'); 
  148. /** 
  149. * Class A_NextGen_Basic_ImageBrowser_Mapper 
  150. * @mixin C_Display_Type_Mapper 
  151. * @adapts I_Display_Type_Mapper 
  152. */ 
  153. class A_NextGen_Basic_ImageBrowser_Mapper extends Mixin 
  154. function set_defaults($entity) 
  155. $this->call_parent('set_defaults', $entity); 
  156. if (isset($entity->name) && $entity->name == NGG_BASIC_IMAGEBROWSER) { 
  157. $this->object->_set_default_value($entity, 'settings', 'template', ''); 
  158. // Part of the pro-modules 
  159. $this->object->_set_default_value($entity, 'settings', 'ngg_triggers_display', 'never'); 
  160. /** 
  161. * Class A_NextGen_Basic_ImageBrowser_Urls 
  162. * @mixin C_Routing_App 
  163. * @adapts I_Routing_App 
  164. */ 
  165. class A_NextGen_Basic_ImageBrowser_Urls extends Mixin 
  166. function create_parameter_segment($key, $value, $id = NULL, $use_prefix = FALSE) 
  167. if ($key == 'pid') { 
  168. return "image/{$value}"; 
  169. } else { 
  170. return $this->call_parent('create_parameter_segment', $key, $value, $id, $use_prefix); 
.