/**
* Flushes cache from all available galleries
*
* @param array $galleries When provided only the requested galleries' cache is flushed
*/
public function flush_galleries($galleries = array())
{
if (empty($galleries)) {
$galleries = C_Gallery_Mapper::get_instance()->find_all();
}
foreach ($galleries as $gallery) {
C_Gallery_Storage::get_instance()->flush_cache($gallery);
}
}
/**
* Flushes cache from all available galleries
*
* @param array $galleries When provided only the requested galleries' cache is flushed
*/
public function flush_galleries($galleries = array())
{
global $wpdb;
if (empty($galleries)) {
$galleries = C_Gallery_Mapper::get_instance()->find_all();
}
foreach ($galleries as $gallery) {
C_Gallery_Storage::get_instance()->flush_cache($gallery);
}
// Remove images still in the DB whose gallery no longer exists
$wpdb->query("DELETE FROM `{$wpdb->nggpictures}` WHERE `galleryid` NOT IN (SELECT `gid` FROM `{$wpdb->nggallery}`)");
}
/**
* Renders the front-end for the NextGen Basic Album display type
*
* @param $displayed_gallery
* @param bool $return
*/
public function index_action($displayed_gallery, $return = FALSE)
{
$display_settings = $displayed_gallery->display_settings;
// We need to fetch the album containers selected in the Attach
// to Post interface. We need to do this, because once we fetch the
// included entities, we need to iterate over each entity and assign it
// a parent_id, which is the album that it belongs to. We need to do this
// because the link to the gallery, is not /nggallery/gallery--id, but
// /nggallery/album--id/gallery--id
// Are we to display a gallery?
if ($gallery = $gallery_slug = $this->param('gallery')) {
// basic albums only support one per post
if (isset($GLOBALS['nggShowGallery'])) {
return;
}
$GLOBALS['nggShowGallery'] = TRUE;
// Try finding the gallery by slug first. If nothing is found, we assume that
// the user passed in a gallery id instead
$mapper = C_Gallery_Mapper::get_instance();
$result = reset($mapper->select()->where(array('slug = %s', $gallery))->limit(1)->run_query());
if ($result) {
$gallery = $result->{$result->id_field};
}
$renderer = C_Displayed_Gallery_Renderer::get_instance('inner');
$gallery_params = array('source' => 'galleries', 'container_ids' => array($gallery), 'display_type' => $display_settings['gallery_display_type'], 'original_display_type' => $displayed_gallery->display_type, 'original_settings' => $display_settings);
if (!empty($display_settings['gallery_display_template'])) {
$gallery_params['template'] = $display_settings['gallery_display_template'];
}
return $renderer->display_images($gallery_params, $return);
} else {
if ($album = $this->param('album')) {
$mapper = C_Album_Mapper::get_instance();
$result = array_pop($mapper->select()->where(array('slug = %s', $album))->limit(1)->run_query());
$album_sub = $result ? $result->{$result->id_field} : null;
if ($album_sub != null) {
$album = $album_sub;
}
$displayed_gallery->entity_ids = array();
$displayed_gallery->sortorder = array();
$displayed_gallery->container_ids = ($album === '0' or $album === 'all') ? array() : array($album);
}
}
// Get the albums
// TODO: This should probably be moved to the elseif block above
$this->albums = $displayed_gallery->get_albums();
// None of the above: Display the main album. Get the settings required for display
$current_page = (int) $this->param('nggpage', 1);
$offset = $display_settings['galleries_per_page'] * ($current_page - 1);
$entities = $displayed_gallery->get_included_entities($display_settings['galleries_per_page'], $offset);
// If there are entities to be displayed
if ($entities) {
if (!empty($display_settings['template'])) {
// Add additional parameters
$pagination_result = $this->object->create_pagination($current_page, $displayed_gallery->get_entity_count(), $display_settings['galleries_per_page'], urldecode($this->object->param('ajax_pagination_referrer')));
$this->object->remove_param('ajax_pagination_referrer');
$display_settings['current_page'] = $current_page;
$display_settings['entities'] =& $entities;
$display_settings['pagination_prev'] = $pagination_result['prev'];
$display_settings['pagination_next'] = $pagination_result['next'];
$display_settings['pagination'] = $pagination_result['output'];
// Render legacy template
$this->object->add_mixin('Mixin_NextGen_Basic_Templates');
$display_settings = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), $display_settings);
return $this->object->legacy_render($display_settings['template'], $display_settings, $return, 'album');
} else {
$params = $display_settings;
$albums = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), array('entities' => $entities));
$params['image_gen_params'] = $albums['image_gen_params'];
$params['galleries'] = $albums['galleries'];
$params['displayed_gallery'] = $displayed_gallery;
$params = $this->object->prepare_display_parameters($displayed_gallery, $params);
switch ($displayed_gallery->display_type) {
case NGG_BASIC_COMPACT_ALBUM:
$template = 'compact';
break;
case NGG_BASIC_EXTENDED_ALBUM:
$template = 'extended';
break;
}
return $this->object->render_view("photocrati-nextgen_basic_album#{$template}", $params, $return);
}
} else {
return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return);
}
}
function index_action()
{
$factory = C_Component_Factory::get_instance();
$router = C_Router::get_instance();
$gallery_mapper = C_Gallery_Mapper::get_instance();
$lightbox_mapper = $this->object->get_registry()->get_utility('I_Lightbox_Library_Mapper');
// retrieve by transient id
$transient_id = $this->object->param('id');
// ! denotes a non-nextgen gallery -- skip processing them
if ($transient_id !== '!') {
$displayed_gallery = $factory->create('displayed_gallery', array(), $gallery_mapper);
if (!$displayed_gallery->apply_transient($transient_id)) {
$response = array();
// if the transient does not exist we make an HTTP request to the referer to rebuild the transient
if (!empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], home_url()) !== FALSE) {
$referrer = $_SERVER['HTTP_REFERER'];
if (strpos($referrer, '?') === FALSE) {
$referrer .= '?ngg_no_resources=1';
} else {
$referrer .= '&ngg_no_resources=1';
}
$response = wp_remote_get($referrer);
}
// WP has cached the results of our last get_transient() calls and must be flushed
global $wp_object_cache;
$wp_object_cache->flush();
// and try again to retrieve the transient
if (!$displayed_gallery->apply_transient($transient_id)) {
$displayed_gallery->id($transient_id);
}
}
$displayed_gallery_id = $displayed_gallery->id();
} else {
$displayed_gallery_id = '!';
}
// TODO: (possibly?) find a better solution, This feels too hackish.
// Remove all currently enqueued CSS & JS. Resources needed by the pro-lightbox incidentally happen
// to be enqueued after this particular code is run anyway.
global $wp_styles;
global $wp_scripts;
$wp_styles->queue = array();
$wp_scripts->queue = array();
// our only necessary script
wp_enqueue_script('galleria', $this->object->get_static_url('photocrati-galleria#galleria-1.2.9.min.js'), array('jquery'), FALSE, FALSE);
wp_enqueue_script('pro-lightbox-galleria-init', $this->object->get_static_url('photocrati-nextgen_pro_lightbox_legacy#galleria_init.js'), array('galleria'), FALSE, FALSE);
if (!wp_style_is('fontawesome', 'registered')) {
C_Display_Type_Controller::get_instance()->enqueue_displayed_gallery_trigger_buttons_resources();
}
wp_enqueue_style('fontawesome');
wp_enqueue_script('velocity', $this->object->get_static_url('photocrati-nextgen_pro_lightbox_legacy#jquery.velocity.min.js'));
// retrieve and add some fields to the lightbox settings
$library = $lightbox_mapper->find_by_name(NGG_PRO_LIGHTBOX, TRUE);
$ls =& $library->display_settings;
$ls['theme'] = $this->object->get_static_url('photocrati-nextgen_pro_lightbox_legacy#theme/galleria.nextgen_pro_lightbox.js');
$ls['load_images_url'] = $router->get_url('/nextgen-pro-lightbox-load-images/' . $transient_id, TRUE, 'root');
$ls['gallery_url'] = $router->get_url('/nextgen-pro-lightbox-gallery/{gallery_id}/', TRUE, 'root');
$ls['share_url'] = $router->get_url('/nextgen-share/{gallery_id}/{image_id}/{named_size}', TRUE, 'root');
$ls['wp_site_url'] = $router->get_base_url();
$ls['image_protect'] = !empty(C_NextGen_Settings::get_instance()->protect_images) ? TRUE : FALSE;
if (!empty($ls['style'])) {
wp_enqueue_style('nextgen_pro_lightbox_user_style', $router->get_static_url('photocrati-nextgen_pro_lightbox_legacy#styles/' . $ls['style']));
}
// this should come after all other enqueue'ings
$settings = C_NextGen_Settings::get_instance();
if ((!is_multisite() || is_multisite() && $settings->wpmuStyle) && $settings->activateCSS) {
wp_enqueue_style('nggallery', C_NextGen_Style_Manager::get_instance()->get_selected_stylesheet_url());
}
// The Pro Lightbox can be extended with components that enqueue their own resources
// and render some markup
$component_markup = array();
foreach ($this->object->_components as $name => $handler) {
$handler = new $handler();
$handler->name = $name;
if (!empty($displayed_gallery)) {
$handler->displayed_gallery = $displayed_gallery;
}
$handler->lightbox_library = $library;
$handler->enqueue_static_resources();
$component_markup[] = $handler->render();
}
$params = array('displayed_gallery_id' => $displayed_gallery_id, 'lightbox_settings' => $library->display_settings, 'component_markup' => implode("\n", $component_markup));
return $this->object->render_view('photocrati-nextgen_pro_lightbox_legacy#index', $params, FALSE);
}
请发表评论