A_NextGen_Basic_ImageBrowser_Controller

Provides rendering logic for the NextGen Basic ImageBrowser.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/package.module.nextgen_basic_imagebrowser.php  
  1. class A_NextGen_Basic_ImageBrowser_Controller extends Mixin 
  2. /** 
  3. * Renders the front-end display for the imagebrowser display type 
  4. * @param C_Displayed_Gallery $displayed_gallery 
  5. * @param bool $return 
  6. * @return string 
  7. */ 
  8. public function index_action($displayed_gallery, $return = FALSE) 
  9. $picture_list = array(); 
  10. foreach ($displayed_gallery->get_included_entities() as $image) { 
  11. $picture_list[$image->{$image->id_field}] = $image; 
  12. if ($picture_list) { 
  13. $retval = $this->render_image_browser($displayed_gallery, $picture_list); 
  14. if ($return) { 
  15. return $retval; 
  16. } else { 
  17. echo $retval; 
  18. } else { 
  19. return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); 
  20. /** 
  21. * Returns the rendered template of an image browser display 
  22. * @param C_Displayed_Gallery 
  23. * @param array $picture_list 
  24. * @return string Rendered HTML (probably) 
  25. */ 
  26. public function render_image_browser($displayed_gallery, $picture_list) 
  27. $display_settings = $displayed_gallery->display_settings; 
  28. $storage = C_Gallery_Storage::get_instance(); 
  29. $imap = C_Image_Mapper::get_instance(); 
  30. $application = C_Router::get_instance()->get_routed_app(); 
  31. // the pid may be a slug so we must track it & the slug target's database id 
  32. $pid = $this->object->param('pid'); 
  33. $numeric_pid = NULL; 
  34. // makes the upcoming which-image-am-I loop easier 
  35. $picture_array = array(); 
  36. foreach ($picture_list as $picture) { 
  37. $picture_array[] = $picture->{$imap->get_primary_key_column()}; 
  38. // Determine which image in the list we need to display 
  39. if (!empty($pid)) { 
  40. if (is_numeric($pid) && !empty($picture_list[$pid])) { 
  41. $numeric_pid = intval($pid); 
  42. } else { 
  43. // in the case it's a slug we need to search for the pid 
  44. foreach ($picture_list as $key => $picture) { 
  45. if ($picture->image_slug == $pid) { 
  46. $numeric_pid = $key; 
  47. break; 
  48. } else { 
  49. reset($picture_array); 
  50. $numeric_pid = current($picture_array); 
  51. // get ids to the next and previous images 
  52. $total = count($picture_array); 
  53. $key = array_search($numeric_pid, $picture_array); 
  54. if (!$key) { 
  55. $numeric_pid = reset($picture_array); 
  56. $key = key($picture_array); 
  57. // for "viewing image #13 of $total" 
  58. $picture_list_pos = $key + 1; 
  59. // our image to display 
  60. $picture = new C_Image_Wrapper($imap->find($numeric_pid), $displayed_gallery, TRUE); 
  61. $picture = apply_filters('ngg_image_object', $picture, $numeric_pid); 
  62. // determine URI to the next & previous images 
  63. $back_pid = $key >= 1 ? $picture_array[$key - 1] : end($picture_array); 
  64. // 'show' is set when using the imagebrowser as an alternate view to a thumbnail or slideshow 
  65. // for which the basic-gallery module will rewrite the show parameter into existence as long as 'image' 
  66. // is set. We remove 'show' here so navigation appears fluid. 
  67. $current_url = $application->get_routed_url(TRUE); 
  68. if ($this->object->param('ajax_pagination_referrer')) { 
  69. $current_url = $this->object->param('ajax_pagination_referrer'); 
  70. $prev_image_link = $this->object->set_param_for($current_url, 'pid', $picture_list[$back_pid]->image_slug); 
  71. $prev_image_link = $this->object->remove_param_for($prev_image_link, 'show', $displayed_gallery->id()); 
  72. $next_pid = $key < $total - 1 ? $picture_array[$key + 1] : reset($picture_array); 
  73. $next_image_link = $this->object->set_param_for($current_url, 'pid', $picture_list[$next_pid]->image_slug); 
  74. $next_image_link = $this->object->remove_param_for($next_image_link, 'show', $displayed_gallery->id()); 
  75. // css class 
  76. $anchor = 'ngg-imagebrowser-' . $displayed_gallery->id() . '-' . (get_the_ID() == false ? 0 : get_the_ID()); 
  77. // try to read EXIF data, but fallback to the db presets 
  78. $meta = new C_NextGen_Metadata($picture); 
  79. $meta->sanitize(); 
  80. $meta_results = array('exif' => $meta->get_EXIF(), 'iptc' => $meta->get_IPTC(), 'xmp' => $meta->get_XMP(), 'db' => $meta->get_saved_meta()); 
  81. $meta_results['exif'] = $meta_results['exif'] == false ? $meta_results['db'] : $meta_results['exif']; 
  82. // disable triggers IF we're rendering inside of an ajax-pagination request; var set in common.js 
  83. if (!empty($_POST['ajax_referrer'])) { 
  84. $displayed_gallery->display_settings['ngg_triggers_display'] = 'never'; 
  85. if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { 
  86. $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); 
  87. $picture->href_link = $picture->get_href_link(); 
  88. $picture->previous_image_link = $prev_image_link; 
  89. $picture->previous_pid = $back_pid; 
  90. $picture->next_image_link = $next_image_link; 
  91. $picture->next_pid = $next_pid; 
  92. $picture->number = $picture_list_pos; 
  93. $picture->total = $total; 
  94. $picture->anchor = $anchor; 
  95. 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'); 
  96. } else { 
  97. $params = $display_settings; 
  98. $params['anchor'] = $anchor; 
  99. $params['image'] = $picture; 
  100. $params['storage'] =& $storage; 
  101. $params['previous_pid'] = $back_pid; 
  102. $params['next_pid'] = $next_pid; 
  103. $params['number'] = $picture_list_pos; 
  104. $params['total'] = $total; 
  105. $params['previous_image_link'] = $prev_image_link; 
  106. $params['next_image_link'] = $next_image_link; 
  107. $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); 
  108. $params = $this->object->prepare_display_parameters($displayed_gallery, $params); 
  109. return $this->object->render_partial('photocrati-nextgen_basic_imagebrowser#nextgen_basic_imagebrowser', $params, TRUE); 
  110. /** 
  111. * Enqueues all static resources required by this display type 
  112. * @param C_Displayed_Gallery $displayed_gallery 
  113. */ 
  114. public function enqueue_frontend_resources($displayed_gallery) 
  115. $this->call_parent('enqueue_frontend_resources', $displayed_gallery); 
  116. wp_enqueue_style('nextgen_basic_imagebrowser_style', $this->get_static_url('photocrati-nextgen_basic_imagebrowser#style.css'), FALSE, NGG_SCRIPT_VERSION); 
  117. $this->enqueue_ngg_styles();