/** * Renders a displayed gallery on the frontend * @param C_Displayed_Gallery|stdClass $displayed_gallery */ function render($displayed_gallery, $return = FALSE, $mode = null) { $retval = ''; $lookup = TRUE; $cache = C_Photocrati_Cache::get_instance('displayed_gallery_rendering'); // Simply throwing our rendered gallery into a feed will most likely not work correctly. // The MediaRSS option in NextGEN is available as an alternative. if (!C_NextGen_Settings::get_instance()->galleries_in_feeds && is_feed()) { return ''; } if ($mode == null) { $mode = 'normal'; } // Save the displayed gallery as a transient if it hasn't already. Allows for ajax operations // to add or modify the gallery without losing a retrievable ID if (!$displayed_gallery->apply_transient()) { $displayed_gallery->to_transient(); } // Get the display type controller $controller = $this->get_registry()->get_utility('I_Display_Type_Controller', $displayed_gallery->display_type); // Get routing info $router = $url = C_Router::get_instance(); $url = $router->get_url($router->get_request_uri(), TRUE); // Should we lookup in cache? if (is_array($displayed_gallery->container_ids) && in_array('All', $displayed_gallery->container_ids)) { $lookup = FALSE; } elseif ($displayed_gallery->source == 'albums' && $controller->param('gallery') or $controller->param('album')) { $lookup = FALSE; } elseif ($controller->param('show')) { $lookup = FALSE; } elseif ($controller->cachable === FALSE) { $lookup = FALSE; } // Enqueue any necessary static resources if (!defined('NGG_SKIP_LOAD_SCRIPTS') || !NGG_SKIP_LOAD_SCRIPTS) { $controller->enqueue_frontend_resources($displayed_gallery); } // Try cache lookup, if we're to do so $key = null; $html = FALSE; if ($lookup) { // The display type may need to output some things // even when serving from the cache if ($controller->has_method('cache_action')) { $retval = $controller->cache_action($displayed_gallery); } // Output debug message $retval .= $this->debug_msg("Lookup!"); // Some settings affect display types $settings = C_NextGen_Settings::get_instance(); $key_params = apply_filters('ngg_displayed_gallery_cache_params', array($displayed_gallery->get_entity(), $url, $mode, $settings->activateTags, $settings->appendType, $settings->maxImages, $settings->thumbEffect, $settings->thumbCode, $settings->galSort, $settings->galSortDir)); // Any displayed gallery links on the home page will need to be regenerated if the permalink structure // changes if (is_home() or is_front_page()) { $key_params[] = get_option('permalink_structure'); } // Try getting the rendered HTML from the cache $key = $cache->generate_key($key_params); $html = $cache->lookup($key, FALSE); // Output debug messages if ($html) { $retval .= $this->debug_msg("HIT!"); } else { $retval .= $this->debug_msg("MISS!"); } // TODO: This is hack. We need to figure out a more uniform way of detecting dynamic image urls if (strpos($html, C_Photocrati_Settings_Manager::get_instance()->dynamic_thumbnail_slug . '/') !== FALSE) { $html = FALSE; // forces the cache to be re-generated } } else { $retval .= $this->debug_msg("Not looking up in cache as per rules"); } // If we're displaying a variant, I want to know it if (isset($displayed_gallery->variation) && is_numeric($displayed_gallery->variation) && $displayed_gallery->variation > 0) { $retval .= $this->debug_msg("Using variation #{$displayed_gallery->variation}!"); } // If a cached version doesn't exist, then create the cache if (!$html) { $retval .= $this->debug_msg("Rendering displayed gallery"); $current_mode = $controller->get_render_mode(); $controller->set_render_mode($mode); $html = $controller->index_action($displayed_gallery, TRUE); if ($key != null) { $cache->update($key, $html, NGG_RENDERING_CACHE_TTL); } $controller->set_render_mode($current_mode); } $retval .= $html; if (!$return) { echo $retval; } return $retval; }