/** * Returns a url to view the displayed gallery using an alternate display * type * @param C_Displayed_Gallery $displayed_gallery * @param string $display_type * @return string */ function get_url_for_alternate_display_type($displayed_gallery, $display_type) { $url = $this->object->get_routed_url(TRUE); $url = $this->object->remove_param_for($url, 'show', $displayed_gallery->id()); $url = $this->object->set_param_for($url, 'show', $display_type, $displayed_gallery->id()); return $url; }
/** * Displays the 'tagcloud' display type * * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { $display_settings = $displayed_gallery->display_settings; $application = $this->object->get_registry()->get_utility('I_Router')->get_routed_app(); $tag = $this->param('gallerytag'); // we're looking at a tag, so show images w/that tag as a thumbnail gallery if (!is_home() && !empty($tag)) { return $this->object->get_registry()->get_utility('I_Displayed_Gallery_Renderer')->display_images(array('source' => 'tags', 'container_ids' => array(esc_attr($tag)), 'display_type' => $display_settings['display_type'], 'original_display_type' => $displayed_gallery->display_type, 'original_settings' => $display_settings)); } $defaults = array('exclude' => '', 'format' => 'list', 'include' => $displayed_gallery->get_term_ids_for_tags(), 'largest' => 22, 'link' => 'view', 'number' => $display_settings['number'], 'order' => 'ASC', 'orderby' => 'name', 'smallest' => 8, 'taxonomy' => 'ngg_tag', 'unit' => 'pt'); $args = wp_parse_args('', $defaults); // Always query top tags $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); foreach ($tags as $key => $tag) { $tags[$key]->link = $this->object->set_param_for($application->get_routed_url(TRUE), 'gallerytag', $tag->slug); $tags[$key]->id = $tag->term_id; } $params = $display_settings; $params['inner_content'] = $displayed_gallery->inner_content; $params['storage'] =& $storage; $params['tagcloud'] = wp_generate_tag_cloud($tags, $args); $params['displayed_gallery_id'] = $displayed_gallery->id(); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_partial('photocrati-nextgen_basic_tagcloud#nextgen_basic_tagcloud', $params, $return); }
/** * Displays the ngglegacy thumbnail gallery. * This method deprecates the use of the nggShowGallery() function. * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { // Get the images to be displayed $current_page = (int) $this->param('nggpage', 1); if ($images = $displayed_gallery->get_included_entities()) { // Get the gallery storage component $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); // Create parameter list for the view $params = $displayed_gallery->display_settings; $params['storage'] =& $storage; $params['images'] =& $images; $params['displayed_gallery_id'] = $displayed_gallery->id(); $params['current_page'] = $current_page; $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['anchor'] = 'ngg-slideshow-' . $displayed_gallery->id() . '-' . rand(1, getrandmax()) . $current_page; $gallery_width = $displayed_gallery->display_settings['gallery_width']; $gallery_height = $displayed_gallery->display_settings['gallery_height']; $params['aspect_ratio'] = $gallery_width / $gallery_height; $params['placeholder'] = $this->object->get_static_url('photocrati-nextgen_basic_gallery#slideshow/placeholder.gif'); // Are we to generate a thumbnail link? if ($displayed_gallery->display_settings['show_thumbnail_link']) { $params['thumbnail_link'] = $this->object->get_url_for_alternate_display_type($displayed_gallery, NGG_BASIC_THUMBNAILS); } $params = $this->object->prepare_display_parameters($displayed_gallery, $params); $retval = $this->object->render_partial('photocrati-nextgen_basic_gallery#slideshow/index', $params, $return); } else { $retval = $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); } return $retval; }
function render_displayed_gallery_action() { $retval = array(); // this must run ONLY twice if (isset($_POST['ajax_referrer']) && $this->_run_count <= 1) { // set the router & routed app to use the uri provided in ajax_referrer $parsed_url = parse_url($_POST['ajax_referrer']); $url = $parsed_url['path']; if (!empty($parsed_url['query'])) { $url .= '?' . $parsed_url['query']; } $_SERVER['REQUEST_URI'] = $url; $_SERVER['PATH_INFO'] = $parsed_url['path']; $this->_run_count++; C_Router::$_instances = array(); $router = C_Router::get_instance(); $router->serve_request(); } if (isset($_POST['displayed_gallery_id'])) { $displayed_gallery = new C_Displayed_Gallery(); $displayed_gallery->apply_transient($_POST['displayed_gallery_id']); $renderer = C_Displayed_Gallery_Renderer::get_instance(); $retval['html'] = $renderer->render($displayed_gallery, TRUE); } return $retval; }
function render_displayed_gallery_action() { $retval = array(); if (isset($_POST['ajax_referrer'])) { $_SERVER['REQUEST_URI'] = $_POST['ajax_referrer']; C_Router::get_instance()->serve_request(); } if (isset($_POST['displayed_gallery_id'])) { $displayed_gallery = new C_Displayed_Gallery(); $displayed_gallery->apply_transient($_POST['displayed_gallery_id']); $renderer = C_Displayed_Gallery_Renderer::get_instance(); $retval['html'] = $renderer->render($displayed_gallery, TRUE); } return $retval; }
/** * Renders the front-end display for the masonry display type * * @param C_Displayed_Gallery $displayed_gallery * @param bool $return * @return string */ function index_action($displayed_gallery, $return = FALSE) { $images = $displayed_gallery->get_included_entities(); if (!$images) { return $this->object->render_partial("photocrati-nextgen_gallery_display#no_images_found", array(), $return); } else { $params = $displayed_gallery->display_settings; $params['images'] = $images; $params['storage'] = C_Gallery_Storage::get_instance(); $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['displayed_gallery_id'] = $displayed_gallery->id(); $params['thumbnail_size_name'] = C_Dynamic_Thumbnails_Manager::get_instance()->get_size_name(array('width' => $params['size'], 'crop' => FALSE)); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_view('photocrati-nextgen_pro_masonry#index', $params, $return); } }
/** * Renders the front-end display for the imagebrowser display type * * @param C_Displayed_Gallery $displayed_gallery * @param bool $return * @return string */ function index_action($displayed_gallery, $return = FALSE) { $picture_list = array(); foreach ($displayed_gallery->get_included_entities() as $image) { $picture_list[$image->{$image->id_field}] = $image; } if ($picture_list) { $retval = $this->render_image_browser($displayed_gallery, $picture_list); if ($return) { return $retval; } else { echo $retval; } } else { return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); } }
/** * Displays the ngglegacy thumbnail gallery. * This method deprecates the use of the nggShowGallery() function. * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { // Get the images to be displayed $current_page = (int) $this->param('page', 1); // TODO: Shouldn't we be using maximum_entity_count instead? $limit = FALSE; if (in_array($displayed_gallery->source, array('random_images', 'recent_images'))) { $limit = $displayed_gallery->display_settings['images_per_page']; } if ($images = $displayed_gallery->get_included_entities($limit)) { // Get the gallery storage component $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); // Create parameter list for the view $params = $displayed_gallery->display_settings; $params['storage'] =& $storage; $params['images'] =& $images; $params['displayed_gallery_id'] = $displayed_gallery->id(); $params['current_page'] = $current_page; $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['anchor'] = 'ngg-slideshow-' . $displayed_gallery->id() . '-' . rand(1, getrandmax()) . $current_page; $gallery_width = $displayed_gallery->display_settings['gallery_width']; $gallery_height = $displayed_gallery->display_settings['gallery_height']; $params['aspect_ratio'] = $gallery_width / $gallery_height; $params['flash_path'] = $this->object->get_static_url('photocrati-nextgen_basic_gallery#slideshow/imagerotator.swf'); $params['placeholder'] = $this->object->get_static_url('photocrati-nextgen_basic_gallery#slideshow/placeholder.gif'); // Are we displayed a flash slideshow? if ($displayed_gallery->display_settings['flash_enabled']) { include_once path_join(NGGALLERY_ABSPATH, implode(DIRECTORY_SEPARATOR, array('lib', 'swfobject.php'))); $transient_id = $displayed_gallery->transient_id; $params['mediarss_link'] = $this->get_router()->get_url('/nextgen-mediarss?template=playlist_feed&source=displayed_gallery&transient_id=' . $transient_id, false); } // Are we to generate a thumbnail link? if ($displayed_gallery->display_settings['show_thumbnail_link']) { $params['thumbnail_link'] = $this->object->get_url_for_alternate_display_type($displayed_gallery, NEXTGEN_GALLERY_BASIC_THUMBNAILS); } $params = $this->object->prepare_display_parameters($displayed_gallery, $params); $retval = $this->object->render_partial('photocrati-nextgen_basic_gallery#slideshow/index', $params, $return); } else { $retval = $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); } return $retval; }
/** * Displays the ngglegacy thumbnail gallery. * This method deprecates the use of the nggShowGallery() function. * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { $display_settings = $displayed_gallery->display_settings; $gallery_id = $displayed_gallery->id(); $transient_id = $displayed_gallery->transient_id; // If these options are on we must use the transient_id to identify the gallery if ($display_settings['show_piclens_link'] || $display_settings['ajax_pagination']) { $gallery_id = $transient_id; } if (!$display_settings['disable_pagination']) { $current_page = (int) $this->param('page', $gallery_id, 1); } else { $current_page = 1; } $offset = $display_settings['images_per_page'] * ($current_page - 1); $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); $total = $displayed_gallery->get_entity_count(); // Get the images to be displayed if ($display_settings['images_per_page'] > 0 && $display_settings['show_all_in_lightbox']) { // the "Add Hidden Images" feature works by loading ALL images and then marking the ones not on this page // as hidden (style="display: none") $images = $displayed_gallery->get_included_entities(); $i = 0; foreach ($images as &$image) { if ($i < $display_settings['images_per_page'] * ($current_page - 1)) { $image->hidden = TRUE; } elseif ($i >= $display_settings['images_per_page'] * $current_page) { $image->hidden = TRUE; } $i++; } } else { // just display the images for this page, as normal $images = $displayed_gallery->get_included_entities($display_settings['images_per_page'], $offset); } if (in_array($displayed_gallery->source, array('random_images', 'recent_images'))) { $display_settings['disable_pagination'] = TRUE; } // Are there images to display? if ($images) { // Create pagination if ($display_settings['images_per_page'] && !$display_settings['disable_pagination']) { $pagination_result = $this->object->create_pagination($current_page, $total, $display_settings['images_per_page'], urldecode($this->object->param('ajax_pagination_referrer'))); $this->object->remove_param('ajax_pagination_referrer'); $pagination_prev = $pagination_result['prev']; $pagination_next = $pagination_result['next']; $pagination = $pagination_result['output']; } else { list($pagination_prev, $pagination_next, $pagination) = array(NULL, NULL, NULL); } $thumbnail_size_name = 'thumbnail'; if ($display_settings['override_thumbnail_settings']) { $dynthumbs = $this->object->get_registry()->get_utility('I_Dynamic_Thumbnails_Manager'); if ($dynthumbs != null) { $dyn_params = array('width' => $display_settings['thumbnail_width'], 'height' => $display_settings['thumbnail_height']); if ($display_settings['thumbnail_quality']) { $dyn_params['quality'] = $display_settings['thumbnail_quality']; } if ($display_settings['thumbnail_crop']) { $dyn_params['crop'] = true; } if ($display_settings['thumbnail_watermark']) { $dyn_params['watermark'] = true; } $thumbnail_size_name = $dynthumbs->get_size_name($dyn_params); } } // Determine what the piclens link would be $piclens_link = ''; if ($display_settings['show_piclens_link']) { $mediarss_link = $this->object->get_router()->get_url('/nextgen-mediarss?source=displayed_gallery&transient_id=' . $gallery_id, FALSE); $piclens_link = "javascript:PicLensLite.start({feedUrl:'{$mediarss_link}'});"; } // Generate a slideshow link $slideshow_link = ''; if ($display_settings['show_slideshow_link']) { // origin_url is necessary for ajax operations. slideshow_link_origin will NOT always exist. $origin_url = $this->object->param('ajax_pagination_referrer'); $slideshow_link = $this->object->get_url_for_alternate_display_type($displayed_gallery, NEXTGEN_GALLERY_BASIC_SLIDESHOW, $origin_url); } // This setting 1) points all images to an imagebrowser display & 2) disables the lightbox effect if ($display_settings['use_imagebrowser_effect']) { // this hook *MUST* be removed later; it should not apply to galleries that may come after this one! $storage->add_post_hook('get_image_url', 'imagebrowser alternate url replacer', 'Hook_NextGen_Basic_Imagebrowser_Alt_URLs', 'get_image_url'); $effect_code = ''; } else { $effect_code = $this->object->get_effect_code($displayed_gallery); } // The render functions require different processing if (!empty($display_settings['template'])) { $this->object->add_mixin('A_NextGen_Basic_Template_Form'); $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); $params = $this->object->prepare_legacy_parameters($images, $displayed_gallery, array('next' => empty($pagination_next) ? FALSE : $pagination_next, 'prev' => empty($pagination_prev) ? FALSE : $pagination_prev, 'pagination' => $pagination, 'piclens_link' => $piclens_link, 'slideshow_link' => $slideshow_link)); $output = $this->object->legacy_render($display_settings['template'], $params, $return, 'gallery'); } else { $params = $display_settings; $params['storage'] =& $storage; $params['images'] =& $images; $params['displayed_gallery_id'] = $gallery_id; $params['transient_id'] = $displayed_gallery->transient_id; $params['current_page'] = $current_page; $params['piclens_link'] = $piclens_link; $params['effect_code'] = $effect_code; $params['pagination'] = $pagination; $params['thumbnail_size_name'] = $thumbnail_size_name; $params['slideshow_link'] = $slideshow_link; $params = $this->object->prepare_display_parameters($displayed_gallery, $params); $output = $this->object->render_view('photocrati-nextgen_basic_gallery#thumbnails/index', $params, $return); } if ($display_settings['use_imagebrowser_effect']) { $storage->del_post_hook('get_image_url', 'imagebrowser alternate url replacer'); } return $output; } else { if ($display_settings['display_no_images_error']) { return $this->object->render_partial("photocrati-nextgen_gallery_display#no_images_found", array(), $return); } } }
/** * Gets a title for the feed * @param C_Displayed_Gallery $displayed_gallery * @return string */ function _get_feed_title($displayed_gallery) { // Get gallery titles $gallery_titles = array(); foreach ($displayed_gallery->get_galleries() as $gallery) { $gallery_titles[] = $gallery->title; } return "Images from: " . implode(', ', $gallery_titles); }
/** * 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; }
/** * Displays the 'singlepic' display type * * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ public function index_action($displayed_gallery, $return = FALSE) { $storage = C_Gallery_Storage::get_instance(); $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $display_settings = $displayed_gallery->display_settings; // use this over get_included_entities() so we can display images marked 'excluded' $displayed_gallery->skip_excluding_globally_excluded_images = TRUE; $image = array_shift($displayed_gallery->get_entities(1, FALSE, FALSE, 'included')); if (!$image) { return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); } switch ($display_settings['float']) { case 'left': $display_settings['float'] = 'ngg-left'; break; case 'right': $display_settings['float'] = 'ngg-right'; break; case 'center': $display_settings['float'] = 'ngg-center'; break; default: $display_settings['float'] = ''; break; } $params = array(); if (!empty($display_settings['link'])) { $target = $display_settings['link_target']; $effect_code = ''; } else { $display_settings['link'] = $storage->get_image_url($image, 'full', TRUE); $target = '_self'; $effect_code = $this->object->get_effect_code($displayed_gallery); } $params['target'] = $target; // mode is a legacy parameter if (!is_array($display_settings['mode'])) { $display_settings['mode'] = explode(',', $display_settings['mode']); } if (in_array('web20', $display_settings['mode'])) { $display_settings['display_reflection'] = TRUE; } if (in_array('watermark', $display_settings['mode'])) { $display_settings['display_watermark'] = TRUE; } if (isset($display_settings['w'])) { $display_settings['width'] = $display_settings['w']; } elseif (isset($display_settings['h'])) { unset($display_settings['width']); } if (isset($display_settings['h'])) { $display_settings['height'] = $display_settings['h']; } elseif (isset($display_settings['w'])) { unset($display_settings['height']); } // legacy assumed no width/height meant full size unlike generate_thumbnail: force a full resolution if (!isset($display_settings['width']) && !isset($display_settings['height'])) { $display_settings['width'] = $image->meta_data['width']; } if (isset($display_settings['width'])) { $params['width'] = $display_settings['width']; } if (isset($display_settings['height'])) { $params['height'] = $display_settings['height']; } $params['quality'] = $display_settings['quality']; $params['crop'] = $display_settings['crop']; $params['watermark'] = $display_settings['display_watermark']; $params['reflection'] = $display_settings['display_reflection']; // Fall back to full in case dynamic images aren't available $size = 'full'; if ($dynthumbs != null) { $size = $dynthumbs->get_size_name($params); } $thumbnail_url = $storage->get_image_url($image, $size); if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { $this->object->add_mixin('A_NextGen_Basic_Template_Form'); $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); $params = $this->object->prepare_legacy_parameters(array($image), $displayed_gallery, array('single_image' => TRUE)); // the wrapper is a lazy-loader that calculates variables when requested. We here override those to always // return the same precalculated settings provided $params['image']->container[0]->_cache_overrides['caption'] = $displayed_gallery->inner_content; $params['image']->container[0]->_cache_overrides['classname'] = 'ngg-singlepic ' . $display_settings['float']; $params['image']->container[0]->_cache_overrides['imageURL'] = $display_settings['link']; $params['image']->container[0]->_cache_overrides['thumbnailURL'] = $thumbnail_url; $params['target'] = $target; // if a link is present we temporarily must filter out the effect code if (empty($effect_code)) { add_filter('ngg_get_thumbcode', array(&$this, 'strip_thumbcode'), 10); } $retval = $this->object->legacy_render($display_settings['template'], $params, $return, 'singlepic'); if (empty($effect_code)) { remove_filter('ngg_get_thumbcode', array(&$this, 'strip_thumbcode'), 10); } return $retval; } else { $params = $display_settings; $params['storage'] =& $storage; $params['image'] =& $image; $params['effect_code'] = $effect_code; $params['inner_content'] = $displayed_gallery->inner_content; $params['settings'] = $display_settings; $params['thumbnail_url'] = $thumbnail_url; $params['target'] = $target; $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic', $params, $return); } }
/** * Displays the 'singlepic' display type * * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); $dynthumbs = $this->object->get_registry()->get_utility('I_Dynamic_Thumbnails_Manager'); $display_settings = $displayed_gallery->display_settings; $image = array_shift($displayed_gallery->get_included_entities(1)); if (!$image) { return $this->object->render_partial("photocrati-nextgen_gallery_display#no_images_found", array(), $return); } switch ($display_settings['float']) { case 'left': $display_settings['float'] = 'ngg-left'; break; case 'right': $display_settings['float'] = 'ngg-right'; break; case 'center': $display_settings['float'] = 'ngg-center'; break; default: $display_settings['float'] = ''; break; } // validate and/or clean our passed settings $display_settings['link'] = !empty($display_settings['link']) ? $display_settings['link'] : $storage->get_image_url($image); // mode is a legacy parameter if (!is_array($display_settings['mode'])) { $display_settings['mode'] = explode(',', $display_settings['mode']); } if (in_array('web20', $display_settings['mode'])) { $display_settings['display_reflection'] = TRUE; } if (in_array('watermark', $display_settings['mode'])) { $display_settings['display_watermark'] = TRUE; } if (isset($display_settings['w'])) { $display_settings['width'] = $display_settings['w']; } elseif (isset($display_settings['h'])) { unset($display_settings['width']); } if (isset($display_settings['h'])) { $display_settings['height'] = $display_settings['h']; } elseif (isset($display_settings['w'])) { unset($display_settings['height']); } // legacy assumed no width/height meant full size unlike generate_thumbnail: force a full resolution if (!isset($display_settings['width']) && !isset($display_settings['height'])) { $display_settings['width'] = $image->meta_data['width']; } if (isset($display_settings['width'])) { $params['width'] = $display_settings['width']; } if (isset($display_settings['height'])) { $params['height'] = $display_settings['height']; } $params['quality'] = $display_settings['quality']; $params['crop'] = $display_settings['crop']; $params['watermark'] = $display_settings['display_watermark']; $params['reflection'] = $display_settings['display_reflection']; // Fall back to full in case dynamic images aren't available $size = 'full'; if ($dynthumbs != null) { $size = $dynthumbs->get_size_name($params); } $thumbnail_url = $storage->get_image_url($image, $size); if (!empty($display_settings['template'])) { $this->object->add_mixin('A_NextGen_Basic_Template_Form'); $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); $params = $this->object->prepare_legacy_parameters(array($image), $displayed_gallery, array('single_image' => TRUE)); // the wrapper is a lazy-loader that calculates variables when requested. We here override those to always // return the same precalculated settings provided $params['image']->container[0]->_cache_overrides['caption'] = $displayed_gallery->inner_content; $params['image']->container[0]->_cache_overrides['classname'] = 'ngg-singlepic ' . $display_settings['float']; $params['image']->container[0]->_cache_overrides['imageURL'] = $display_settings['link']; $params['image']->container[0]->_cache_overrides['thumbnailURL'] = $thumbnail_url; return $this->object->legacy_render($display_settings['template'], $params, $return, 'singlepic'); } else { $params = $display_settings; $params['storage'] =& $storage; $params['image'] =& $image; $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['inner_content'] = $displayed_gallery->inner_content; $params['settings'] = $display_settings; $params['thumbnail_url'] = $thumbnail_url; $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_partial('photocrati-nextgen_basic_singlepic#nextgen_basic_singlepic', $params, $return); } }
/** * 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; }