static function get_instance() { if (!isset(self::$_instance)) { $klass = get_class(); self::$_instance = new $klass(); } return self::$_instance; }
/** * Renders the JS required for the Backbone-based Display Tab */ public function display_tab_js_action($return = FALSE) { // Cache appropriately $this->object->do_not_cache(); // Ensure that JS is returned $this->object->set_content_type('javascript'); $buffer_limit = 0; $zlib = ini_get('zlib.output_compression'); if (!is_numeric($zlib) && $zlib == 'On') { $buffer_limit = 1; } else { if (is_numeric($zlib) && $zlib > 0) { $buffer_limit = 1; } } while (ob_get_level() != $buffer_limit) { ob_end_clean(); } // Get all entities used by the display tab $context = 'attach_to_post'; $gallery_mapper = $this->get_registry()->get_utility('I_Gallery_Mapper', $context); $album_mapper = $this->get_registry()->get_utility('I_Album_Mapper', $context); $image_mapper = $this->get_registry()->get_utility('I_Image_Mapper', $context); $display_type_mapper = $this->get_registry()->get_utility('I_Display_Type_Mapper', $context); $sources = C_Displayed_Gallery_Source_Manager::get_instance(); $security = $this->get_registry()->get_utility('I_Security_Manager'); // Get the nextgen tags global $wpdb; $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 )"); $all_tags = new stdClass(); $all_tags->name = 'All'; $all_tags->id = 'All'; array_unshift($tags, $all_tags); $display_types = array(); $registry = C_Component_Registry::get_instance(); foreach ($display_type_mapper->find_all() as $display_type) { if (isset($display_type->hidden_from_ui) && $display_type->hidden_from_ui) { continue; } $available = $registry->is_module_loaded($display_type->name); if (!apply_filters('ngg_atp_show_display_type', $available, $display_type)) { continue; } $display_types[] = $display_type; } usort($display_types, array($this->object, '_display_type_list_sort')); $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); return $output; }
function enqueue_display_tab_js() { // Enqueue backbone.js library, required by the Attach to Post display tab wp_enqueue_script('backbone'); // provided by WP $this->object->mark_script('backbone'); // Ensure underscore sting, a helper utility wp_enqueue_script('underscore.string', $this->get_static_url('photocrati-attach_to_post#underscore.string.js'), array('underscore'), NGG_SCRIPT_VERSION); $this->object->mark_script('underscore.string'); // Enqueue the backbone app for the display tab // Get all entities used by the display tab $context = 'attach_to_post'; $gallery_mapper = $this->get_registry()->get_utility('I_Gallery_Mapper', $context); $album_mapper = $this->get_registry()->get_utility('I_Album_Mapper', $context); $image_mapper = $this->get_registry()->get_utility('I_Image_Mapper', $context); $display_type_mapper = $this->get_registry()->get_utility('I_Display_Type_Mapper', $context); $sources = C_Displayed_Gallery_Source_Manager::get_instance(); $security = $this->get_registry()->get_utility('I_Security_Manager'); $settings = C_NextGen_Settings::get_instance(); // Get the nextgen tags global $wpdb; $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 )"); $all_tags = new stdClass(); $all_tags->name = "All"; $all_tags->id = "All"; array_unshift($tags, $all_tags); $display_types = array(); $registry = C_Component_Registry::get_instance(); foreach ($display_type_mapper->find_all() as $display_type) { if (isset($display_type->hidden_from_igw) && $display_type->hidden_from_igw || isset($display_type->hidden_from_ui) && $display_type->hidden_from_ui) { continue; } $available = $registry->is_module_loaded($display_type->name); if (!apply_filters('ngg_atp_show_display_type', $available, $display_type)) { continue; } $display_types[] = $display_type; } usort($display_types, array($this->object, '_display_type_list_sort')); wp_enqueue_script('ngg_display_tab', $this->get_static_url('photocrati-attach_to_post#display_tab.js'), array('jquery', 'backbone', 'underscore.string', 'photocrati_ajax')); $this->object->mark_script('ngg_display_tab'); wp_localize_script('ngg_display_tab', 'igw_data', array('displayed_gallery_preview_url' => $settings->gallery_preview_url, 'displayed_gallery' => $this->object->_displayed_gallery->get_entity(), 'sources' => $sources->get_all(), 'gallery_primary_key' => $gallery_mapper->get_primary_key_column(), 'galleries' => $gallery_mapper->find_all(), 'albums' => $album_mapper->find_all(), 'tags' => $tags, 'display_types' => $display_types, 'sec_token' => $security->get_request_token('nextgen_edit_displayed_gallery')->get_json(), 'image_primary_key' => $image_mapper->get_primary_key_column(), 'display_type_priority_base' => NGG_DISPLAY_PRIORITY_BASE, 'display_type_priority_step' => NGG_DISPLAY_PRIORITY_STEP, 'shortcode_ref' => isset($_REQUEST['ref']) ? doubleval($_REQUEST['ref']) : null, 'i18n' => array('sources' => __('Sources', 'nggallery'), 'optional' => __('(optional)', 'nggallery'), 'slug_tooltip' => __('Sets an SEO-friendly name to this gallery for URLs. Currently only in use by the Pro Lightbox', 'nggallery'), 'slug_label' => __('Slug', 'nggallery'), 'no_entities' => __('No entities to display for this source', 'nggallery'), 'exclude_question' => __('Exlude?', 'nggallery'), 'select_gallery' => __('Select a gallery', 'nggallery'), 'galleries' => __('Galleries', 'nggallery'), 'albums' => __('Albums', 'nggallery')))); }