function index_action() { $key = C_Photocrati_Cache::generate_key('nextgen_pro_upgrade_page'); if ($html = C_Photocrati_Cache::get('nextgen_pro_upgrade_page', FALSE)) { echo $html; } else { // Get page content $template = 'photocrati-nextgen_pro_upgrade#plus'; if (defined('NGG_PLUS_PLUGIN_BASENAME')) { $template = 'photocrati-nextgen_pro_upgrade#pro'; } $description = 'Extend NextGEN Gallery with 8 new pro gallery displays, a full screen responsive pro lightbox, commenting / social sharing / deep linking for individual images, ecommerce, digital downloads, and pro email support.'; $headline = 'Upgrade to NextGEN Plus or NextGEN Pro'; if (defined('NGG_PLUS_PLUGIN_BASENAME')) { $description = 'NextGEN Pro now offers ecommerce! Extend NextGEN Gallery and NextGEN Plus with a complete solution for selling prints and digital downloads, including unlimited pricelists, PayPal and Stripe integration, and more.'; $headline = 'Upgrade to NextGEN Pro with Ecommerce'; } $params = array('description' => $description, 'headline' => $headline); $html = $this->render_view($template, $params, TRUE); // Cache it C_Photocrati_Cache::set($key, $html); // Render it echo $html; } }
function display_tab_js_action() { $url = C_Router::get_instance()->get_routed_app()->get_routed_url(TRUE); $key = C_Photocrati_Cache::generate_key($url); // Try fetching the contents from the cache if ($html = C_Photocrati_Cache::get($key, FALSE)) { echo $html; } else { $html = C_Attach_Controller::get_instance(FALSE)->display_tab_js_action(TRUE); C_Photocrati_Cache::set($key, $html); echo $html; } }
function index_action() { $key = C_Photocrati_Cache::generate_key('nextgen_pro_upgrade_page'); if ($html = C_Photocrati_Cache::get('nextgen_pro_upgrade_page', FALSE)) { echo $html; } else { // Get page content $params = array('btn_url' => $this->object->get_router()->get_static_url('photocrati-nextgen_pro_upgrade#button.png'), 'img_url' => $this->object->get_router()->get_static_url('photocrati-nextgen_pro_upgrade#proupgrade.gif')); $html = $this->render_view('photocrati-nextgen_pro_upgrade#index', $params, TRUE); // Cache it C_Photocrati_Cache::set($key, $html); // Render it echo $html; } }
/** * Returns a transient for the displayed gallery * @return string */ function to_transient() { $group = 'displayed_galleries'; $key = C_Photocrati_Cache::generate_key($this->object->get_entity(), $group); if (is_null(C_Photocrati_Cache::get($key, NULL, $group))) { C_Photocrati_Cache::set($key, $this->object->get_entity(), $group, NGG_DISPLAYED_GALLERY_CACHE_TTL); } $this->object->transient_id = $key; if (!$this->object->id()) { $this->object->id($key); } return $key; }
/** * Returns a transient for the displayed gallery * @return string */ function to_transient() { // TODO: put this someplace more appropriate // If the source is random do a separate image id lookup and fill those values into the gallery entity_ids // This is necessary for compat w/Pro Lightbox so it can retrieve (through it's iframe request) the same images // the viewer was previously looking at. if (in_array($this->object->source, array('random', 'random_images')) && empty($this->object->entity_ids)) { global $wpdb; $image_ids = array(); $limit = !empty($this->object->display_settings['images_per_page']) ? $this->object->display_settings['images_per_page'] : $this->object->maximum_entity_count; $sql = "SELECT `pid` FROM `{$wpdb->nggpictures}` WHERE `exclude` = 0"; if (!empty($this->object->exclusions)) { $sql .= sprintf(" AND `pid` NOT IN (%s)", implode(',', $this->object->exclusions)); } $sql .= " ORDER BY RAND() LIMIT {$limit}"; foreach ($wpdb->get_results($sql, ARRAY_N) as $res) { $image_ids[] = reset($res); } $this->object->entity_ids = $image_ids; } $group = 'displayed_galleries'; $key = C_Photocrati_Cache::generate_key($this->object->get_entity(), $group); if (is_null(C_Photocrati_Cache::get($key, NULL, $group))) { C_Photocrati_Cache::set($key, $this->object->get_entity(), $group, 1800); } return $key; }
/** * Renders a displayed gallery on the frontend * @param C_Displayed_Gallery|stdClass $displayed_gallery */ function render($displayed_gallery, $return = FALSE, $mode = null) { // 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 (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 (empty($displayed_gallery->transient_id)) { $displayed_gallery->transient_id = $displayed_gallery->to_transient(); } // Get the display type controller $controller = $this->get_registry()->get_utility('I_Display_Type_Controller', $displayed_gallery->display_type); // Enqueue any necessary static resources $controller->enqueue_frontend_resources($displayed_gallery); // Get routing info $router = $url = C_Router::get_instance(); $url = $router->get_url($router->get_request_uri(), TRUE); // Should we lookup in cache? $lookup = TRUE; if ($displayed_gallery->source == 'random_images') { $lookup = FALSE; } elseif (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->cachable) { $lookup = FALSE; } // Try cache lookup, if we're to do so $key = null; $html = FALSE; if ($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)); // Try getting the rendered HTML from the cache $key = C_Photocrati_Cache::generate_key($key_params); $html = C_Photocrati_Cache::get($key, FALSE); // 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 } } // If a cached version doesn't exist, then create the cache if (!$html) { $current_mode = $controller->get_render_mode(); $controller->set_render_mode($mode); $html = $controller->index_action($displayed_gallery, TRUE); if ($key != null) { C_Photocrati_Cache::set($key, $html); } $controller->set_render_mode($current_mode); // Compress the html to avoid wpautop problems $html = $this->compress_html($html); } if (!$return) { echo $html; } return $html; }
public function cache_lookups() { C_Photocrati_Cache::set('get_static_url', self::$_lookups, 'MVC'); }