Mixin_Attach_To_Post_Display_Tab

Provides the "Display Tab" for the Attach To Post interface/controller.

Defined (1)

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

/products/photocrati_nextgen/modules/attach_to_post/package.module.attach_to_post.php  
  1. class Mixin_Attach_To_Post_Display_Tab extends Mixin 
  2. /** 
  3. * Renders the JS required for the Backbone-based Display Tab 
  4. */ 
  5. public function display_tab_js_action($return = FALSE) 
  6. // Cache appropriately 
  7. $this->object->do_not_cache(); 
  8. // Ensure that JS is returned 
  9. $this->object->set_content_type('javascript'); 
  10. $buffer_limit = 0; 
  11. $zlib = ini_get('zlib.output_compression'); 
  12. if (!is_numeric($zlib) && $zlib == 'On') { 
  13. $buffer_limit = 1; 
  14. } else { 
  15. if (is_numeric($zlib) && $zlib > 0) { 
  16. $buffer_limit = 1; 
  17. while (ob_get_level() != $buffer_limit) { 
  18. ob_end_clean(); 
  19. // Get all entities used by the display tab 
  20. $context = 'attach_to_post'; 
  21. $gallery_mapper = $this->get_registry()->get_utility('I_Gallery_Mapper', $context); 
  22. $album_mapper = $this->get_registry()->get_utility('I_Album_Mapper', $context); 
  23. $image_mapper = $this->get_registry()->get_utility('I_Image_Mapper', $context); 
  24. $display_type_mapper = $this->get_registry()->get_utility('I_Display_Type_Mapper', $context); 
  25. $sources = C_Displayed_Gallery_Source_Manager::get_instance(); 
  26. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  27. // Get the nextgen tags 
  28. global $wpdb; 
  29. $tags = $wpdb->get_results("SELECT DISTINCT name AS 'id', name FROM {$wpdb->terms}\n WHERE term_id IN (\n SELECT term_id FROM {$wpdb->term_taxonomy}\n WHERE taxonomy = 'ngg_tag'\n )"); 
  30. $all_tags = new stdClass(); 
  31. $all_tags->name = 'All'; 
  32. $all_tags->id = 'All'; 
  33. array_unshift($tags, $all_tags); 
  34. $display_types = array(); 
  35. $registry = C_Component_Registry::get_instance(); 
  36. foreach ($display_type_mapper->find_all() as $display_type) { 
  37. if (isset($display_type->hidden_from_ui) && $display_type->hidden_from_ui) { 
  38. continue; 
  39. $available = $registry->is_module_loaded($display_type->name); 
  40. if (!apply_filters('ngg_atp_show_display_type', $available, $display_type)) { 
  41. continue; 
  42. $display_types[] = $display_type; 
  43. usort($display_types, array($this->object, '_display_type_list_sort')); 
  44. $output = $this->object->render_view('photocrati-attach_to_post#display_tab_js', array('displayed_gallery' => json_encode($this->object->_displayed_gallery->get_entity()), 'sources' => json_encode($sources->get_all()), 'gallery_primary_key' => $gallery_mapper->get_primary_key_column(), 'galleries' => json_encode($gallery_mapper->find_all()), 'albums' => json_encode($album_mapper->find_all()), 'tags' => json_encode($tags), 'display_types' => json_encode($display_types), 'sec_token' => $security->get_request_token('nextgen_edit_displayed_gallery')->get_json(), 'image_primary_key' => $image_mapper->get_primary_key_column()), $return); 
  45. return $output; 
  46. public function _display_type_list_sort($type_1, $type_2) 
  47. $order_1 = $type_1->view_order; 
  48. $order_2 = $type_2->view_order; 
  49. if ($order_1 == null) { 
  50. $order_1 = NGG_DISPLAY_PRIORITY_BASE; 
  51. if ($order_2 == null) { 
  52. $order_2 = NGG_DISPLAY_PRIORITY_BASE; 
  53. if ($order_1 > $order_2) { 
  54. return 1; 
  55. if ($order_1 < $order_2) { 
  56. return -1; 
  57. return 0; 
  58. /** 
  59. * Gets a list of tabs to render for the "Display" tab 
  60. */ 
  61. public function _get_display_tabs() 
  62. // The ATP requires more memmory than some applications, somewhere around 60MB. 
  63. // Because it's such an important feature of NextGEN Gallery, we temporarily disable 
  64. // any memory limits 
  65. if (!extension_loaded('suhosin')) { 
  66. @ini_set('memory_limit', -1); 
  67. return array($this->object->_render_display_types_tab(), $this->object->_render_display_source_tab(), $this->object->_render_display_settings_tab(), $this->object->_render_preview_tab()); 
  68. /** 
  69. * Renders the accordion tab, "What would you like to display?" 
  70. */ 
  71. public function _render_display_source_tab() 
  72. return $this->object->render_partial('photocrati-attach_to_post#accordion_tab', array('id' => 'source_tab', 'title' => __('What would you like to display?', 'nggallery'), 'content' => $this->object->_render_display_source_tab_contents()), TRUE); 
  73. /** 
  74. * Renders the contents of the source tab 
  75. * @return string 
  76. */ 
  77. public function _render_display_source_tab_contents() 
  78. return $this->object->render_partial('photocrati-attach_to_post#display_tab_source', array(), TRUE); 
  79. /** 
  80. * Renders the accordion tab for selecting a display type 
  81. * @return string 
  82. */ 
  83. public function _render_display_types_tab() 
  84. return $this->object->render_partial('photocrati-attach_to_post#accordion_tab', array('id' => 'display_type_tab', 'title' => __('Select a display type', 'nggallery'), 'content' => $this->object->_render_display_type_tab_contents()), TRUE); 
  85. /** 
  86. * Renders the contents of the display type tab 
  87. */ 
  88. public function _render_display_type_tab_contents() 
  89. return $this->object->render_partial('photocrati-attach_to_post#display_tab_type', array(), TRUE); 
  90. /** 
  91. * Renders the display settings tab for the Attach to Post interface 
  92. * @return type 
  93. */ 
  94. public function _render_display_settings_tab() 
  95. return $this->object->render_partial('photocrati-attach_to_post#accordion_tab', array('id' => 'display_settings_tab', 'title' => __('Customize the display settings', 'nggallery'), 'content' => $this->object->_render_display_settings_contents()), TRUE); 
  96. /** 
  97. * If editing an existing displayed gallery, retrieves the name 
  98. * of the display type 
  99. * @return string 
  100. */ 
  101. public function _get_selected_display_type_name() 
  102. $retval = ''; 
  103. if ($this->object->_displayed_gallery) { 
  104. $retval = $this->object->_displayed_gallery->display_type; 
  105. return $retval; 
  106. /** 
  107. * Is the displayed gallery that's being edited using the specified display 
  108. * type? 
  109. * @param string $name name of the display type 
  110. * @return bool 
  111. */ 
  112. public function is_displayed_gallery_using_display_type($name) 
  113. $retval = FALSE; 
  114. if ($this->object->_displayed_gallery) { 
  115. $retval = $this->object->_displayed_gallery->display_type == $name; 
  116. return $retval; 
  117. /** 
  118. * Renders the contents of the display settings tab 
  119. * @return string 
  120. */ 
  121. public function _render_display_settings_contents() 
  122. $retval = array(); 
  123. // Get all display setting forms 
  124. $form_manager = C_Form_Manager::get_instance(); 
  125. $forms = $form_manager->get_forms(NGG_DISPLAY_SETTINGS_SLUG, TRUE); 
  126. // Display each form 
  127. foreach ($forms as $form) { 
  128. // Enqueue the form's static resources 
  129. $form->enqueue_static_resources(); 
  130. // Determine which classes to use for the form's "class" attribute 
  131. $model = $form->get_model(); 
  132. $current = $this->object->is_displayed_gallery_using_display_type($model->name); 
  133. $css_class = $current ? 'display_settings_form' : 'display_settings_form hidden'; 
  134. // If this form is used to provide the display settings for the current 
  135. // displayed gallery, then we need to override the forms settings 
  136. // with the displayed gallery settings 
  137. if ($current) { 
  138. $settings = $this->array_merge_assoc($model->settings, $this->object->_displayed_gallery->display_settings, TRUE); 
  139. $model->settings = $settings; 
  140. // Output the display settings form 
  141. $retval[] = $this->object->render_partial('photocrati-attach_to_post#display_settings_form', array('settings' => $form->render(), 'display_type_name' => $model->name, 'css_class' => $css_class), TRUE); 
  142. // In addition, we'll render a form that will be displayed when no 
  143. // display type has been selected in the Attach to Post interface 
  144. // Render the default "no display type selected" view 
  145. $css_class = $this->object->_get_selected_display_type_name() ? 'display_settings_form hidden' : 'display_settings_form'; 
  146. $retval[] = $this->object->render_partial('photocrati-attach_to_post#no_display_type_selected', array('no_display_type_selected' => __('No display type selected', 'nggallery'), 'css_class' => $css_class), TRUE); 
  147. // Return all display setting forms 
  148. return implode(' 
  149. ', $retval); 
  150. /** 
  151. * Renders the tab used to preview included images 
  152. * @return string 
  153. */ 
  154. public function _render_preview_tab() 
  155. return $this->object->render_partial('photocrati-attach_to_post#accordion_tab', array('id' => 'preview_tab', 'title' => __('Sort or Exclude Images', 'nggallery'), 'content' => $this->object->_render_preview_tab_contents()), TRUE); 
  156. /** 
  157. * Renders the contents of the "Preview" tab. 
  158. * @return string 
  159. */ 
  160. public function _render_preview_tab_contents() 
  161. return $this->object->render_partial('photocrati-attach_to_post#preview_tab', array(), TRUE);