/** * Provides a Galleria-formatted JSON array of get_included_entities() results */ function pro_lightbox_load_images_action() { $retval = array(); if ($id = $this->param('id')) { $displayed_gallery_mapper = C_Displayed_Gallery_Mapper::get_instance(); if ($this->param('lang', NULL, FALSE)) { if (class_exists('SitePress')) { global $sitepress; $sitepress->switch_lang($this->param('lang')); } } // Fetch ATP galleries or build our displayed gallery by parameters if (is_numeric($id)) { $displayed_gallery = $displayed_gallery_mapper->find($id, TRUE); } else { $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', $this->param('gallery'), $displayed_gallery_mapper); } if ($displayed_gallery) { $settings = C_NextGen_Settings::get_instance()->get('ngg_pro_lightbox'); $retval = M_NextGen_Pro_Lightbox_Legacy::parse_entities_for_galleria($displayed_gallery->get_entities(FALSE, $settings['localize_limit'])); } } return $retval; }
function _load_displayed_gallery() { $mapper = C_Displayed_Gallery_Mapper::get_instance(); if (!($this->object->_displayed_gallery = $mapper->find($this->object->param('id'), TRUE))) { $this->object->_displayed_gallery = $mapper->create(); } }
/** * Renders a feed for a displayed gallery */ public function render_displayed_gallery() { $displayed_gallery = NULL; $mapper = C_Displayed_Gallery_Mapper::get_instance(); $template = $this->object->param('template'); if (!in_array($template, array('mediarss_feed', 'playlist_feed'))) { $template = 'mediarss_feed'; } $template = 'photocrati-mediarss#' . $template; // Find the displayed gallery by it's database id if ($id = $this->object->param('id')) { $displayed_gallery = $mapper->find($id, TRUE); } elseif ($transient_id = $this->object->param('transient_id')) { // retrieve by transient id $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', NULL, $mapper); $displayed_gallery->apply_transient($transient_id); } elseif ($params = $this->object->param('params')) { // Create the displayed gallery based on the URL parameters $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', json_decode($params), $mapper); } // Assuming we have a displayed gallery, display it! if ($displayed_gallery) { $storage = C_Gallery_Storage::get_instance(); $this->render_view($template, array('storage' => $storage, 'images' => $displayed_gallery->get_included_entities(), 'feed_title' => $this->object->_get_feed_title($displayed_gallery), 'feed_description' => $this->object->_get_feed_description($displayed_gallery), 'feed_link' => $this->object->_get_feed_link($displayed_gallery), 'generator' => $this->object->_get_feed_generator($displayed_gallery), 'copyright' => $this->object->_get_feed_copyright($displayed_gallery))); } else { $this->object->http_error('Invalid ID', 404); } }
public function _load_displayed_gallery() { $mapper = C_Displayed_Gallery_Mapper::get_instance(); if (!($this->object->_displayed_gallery = $mapper->find($this->object->param('id'), TRUE))) { if (!empty($_REQUEST['id'])) { $this->object->_displayed_gallery = $mapper->find($_REQUEST['id'], TRUE); } if (empty($this->object->_displayed_gallery)) { $this->object->_displayed_gallery = $mapper->create(); } } }
/** * Provides a Galleria-formatted JSON array of get_included_entities() results */ function load_images_action() { // Prevent displaying any warnings or errors ob_start(); $this->set_content_type('json'); $retval = array(); if ($id = $this->param('id')) { $factory = C_Component_Factory::get_instance(); $storage = C_Gallery_Storage::get_instance(); $gallery_mapper = C_Displayed_Gallery_Mapper::get_instance(); if ($this->param('lang', NULL, FALSE)) { if (class_exists('SitePress')) { global $sitepress; $sitepress->switch_lang($this->param('lang')); } } $transient_id = $this->object->param('id'); $displayed_gallery = $factory->create('displayed_gallery', $gallery_mapper); if ($displayed_gallery->apply_transient($transient_id)) { $images = $displayed_gallery->get_included_entities(); if (!empty($images)) { foreach ($images as $image) { $retval[] = array('image' => $storage->get_image_url($image), 'title' => $image->alttext, 'description' => $image->description, 'image_id' => $image->{$image->id_field}, 'thumb' => $storage->get_image_url($image, 'thumb')); } } } } ob_end_clean(); print json_encode($retval); }
/** * Substitutes the gallery placeholder content with the gallery type frontend * view, returns a list of static resources that need to be loaded * @param string $content */ function substitute_placeholder_imgs($content) { $content = $this->fix_preview_images($content); // To match ATP entries we compare the stored url against a generic path; entries MUST have a gallery ID if (preg_match_all("#<img.*http(s)?://(.*)?" . NGG_ATTACH_TO_POST_SLUG . "(=|/)preview(/|&|&)id(=|--)(\\d+).*?>#mi", $content, $matches, PREG_SET_ORDER)) { $mapper = C_Displayed_Gallery_Mapper::get_instance(); foreach ($matches as $match) { // Find the displayed gallery $displayed_gallery_id = $match[6]; $displayed_gallery = $mapper->find($displayed_gallery_id, TRUE); // Get the content for the displayed gallery $retval = '<p>' . _('Invalid Displayed Gallery') . '</p>'; if ($displayed_gallery) { $retval = ''; $renderer = C_Displayed_Gallery_Renderer::get_instance(); if (defined('NGG_SHOW_DISPLAYED_GALLERY_ERRORS') && NGG_SHOW_DISPLAYED_GALLERY_ERRORS && $displayed_gallery->is_invalid()) { $retval .= var_export($displayed_gallery->get_errors(), TRUE); } if (self::$substitute_placeholders) { $retval .= $renderer->render($displayed_gallery, TRUE); } } $content = str_replace($match[0], $retval, $content); } } return $content; }
/** * Gets the url of a particular sized image * @param int|object $image * @param type $size * @return string */ public function get_image_url($image = FALSE, $size = 'full') { $retval = NULL; $image_key = C_Displayed_Gallery_Mapper::get_instance()->get_primary_key_column(); if ($image && ($image_id = $this->object->_get_image_id($image))) { $parts = wp_get_attachment_image_src($image->{$image_key}); if ($parts) { $retval = $parts['url']; } } return apply_filters('ngg_get_image_url', $retval, $image, $size); }
/** * Deletes all displayed galleries */ function uninstall_displayed_galleries() { $mapper = C_Displayed_Gallery_Mapper::get_instance(); $mapper->delete()->run_query(); }
/** * Displays a "displayed gallery" instance * * Alias Properties: * gallery_ids/album_ids/tag_ids == container_ids * image_ids/gallery_ids == entity_ids * * Default Behavior: * - if order_by and order_direction are missing, the default settings * are used from the "Other Options" page. The exception to this is * when entity_ids are selected, in which the order is custom unless * specified. * * How to use: * * To retrieve images from gallery 1 & 3, but exclude images 4 & 6: * [ngg_images gallery_ids="1,3" exclusions="4,6" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve images 1 & 2 from gallery 1: * [ngg_images gallery_ids="1" image_ids="1,2" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve images matching tags "landscapes" and "wedding shoots": * [ngg_images tag_ids="landscapes,wedding shoots" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve galleries from albums 1 & #, but exclude sub-album 1: * [ngg_images album_ids="1,2" exclusions="a1" display_type="photocrati-nextgen_basic_compact_album"] * * To retrieve galleries from albums 1 & 2, but exclude gallery 1: * [ngg_images album_ids="1,2" exclusions="1" display_type="photocrati-nextgen_basic_compact_album"] * * To retrieve image 2, 3, and 5 - independent of what container is used * [ngg_images image_ids="2,3,5" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve galleries 3 & 5, custom sorted, in album view * [ngg_images source="albums" gallery_ids="3,5" display_type="photocrati-nextgen_basic_compact_album"] * * To retrieve recent images, sorted by alt/title text * [ngg_images source="recent" order_by="alttext" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve random image * [ngg_images source="random" display_type="photocrati-nextgen_basic_thumbnails"] * * To retrieve a single image * [ngg_images image_ids='8' display_type='photocrati-nextgen_basic_singlepic'] * * To retrieve a tag cloud * [ngg_images tagcloud=yes display_type='photocrati-nextgen_basic_tagcloud'] */ public function display_images($params, $inner_content = NULL, $mode = NULL) { $retval = ''; $displayed_gallery = NULL; // Get the NextGEN settings to provide some defaults $settings = C_NextGen_Settings::get_instance(); // Configure the arguments $defaults = array('id' => NULL, 'source' => '', 'container_ids' => array(), 'gallery_ids' => array(), 'album_ids' => array(), 'tag_ids' => array(), 'display_type' => '', 'exclusions' => array(), 'order_by' => $settings->galSort, 'order_direction' => $settings->galSortOrder, 'image_ids' => array(), 'entity_ids' => array(), 'tagcloud' => FALSE, 'inner_content' => $inner_content, 'returns' => 'included', 'slug' => NULL); $args = shortcode_atts($defaults, $params); // Are we loading a specific displayed gallery that's persisted? $mapper = C_Displayed_Gallery_Mapper::get_instance(); if (!is_null($args['id'])) { $displayed_gallery = $mapper->find($args['id']); unset($mapper); } else { // Perform some conversions... // Galleries? if ($args['gallery_ids']) { if ($args['source'] != 'albums' and $args['source'] != 'album') { $args['source'] = 'galleries'; $args['container_ids'] = $args['gallery_ids']; if ($args['image_ids']) { $args['entity_ids'] = $args['image_ids']; } } elseif ($args['source'] == 'albums') { $args['entity_ids'] = $args['gallery_ids']; } unset($args['gallery_ids']); } elseif ($args['album_ids'] || $args['album_ids'] === '0') { $args['source'] = 'albums'; $args['container_ids'] = $args['album_ids']; unset($args['albums_ids']); } elseif ($args['tag_ids']) { $args['source'] = 'tags'; $args['container_ids'] = $args['tag_ids']; unset($args['tag_ids']); } elseif ($args['image_ids']) { $args['source'] = 'galleries'; $args['entity_ids'] = $args['image_ids']; unset($args['image_ids']); } elseif ($args['tagcloud']) { $args['source'] = 'tags'; } // Convert strings to arrays if (!is_array($args['container_ids'])) { $args['container_ids'] = preg_split('/,|\\|/', $args['container_ids']); } if (!is_array($args['exclusions'])) { $args['exclusions'] = preg_split('/,|\\|/', $args['exclusions']); } if (!is_array($args['entity_ids'])) { $args['entity_ids'] = preg_split('/,|\\|/', $args['entity_ids']); } // Get the display settings foreach (array_keys($defaults) as $key) { unset($params[$key]); } $args['display_settings'] = $params; // Create the displayed gallery $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', $args, $mapper); unset($factory); } // Validate the displayed gallery if ($displayed_gallery) { if ($displayed_gallery->validate()) { // Display! return $this->object->render($displayed_gallery, TRUE, $mode); } else { if (C_NextGEN_Bootstrap::$debug) { $retval = __('We cannot display this gallery', 'nggallery') . $this->debug_msg($displayed_gallery->get_errors()) . $this->debug_msg($displayed_gallery->get_entity()); } else { $retval = __('We cannot display this gallery', 'nggallery'); } } } else { $retval = __('We cannot display this gallery', 'nggallery'); } return $retval; }
/** * Substitutes the gallery placeholder content with the gallery type frontend * view, returns a list of static resources that need to be loaded * @param string $content */ function substitute_placeholder_imgs($content) { // The placeholder MUST have a gallery instance id if (preg_match_all("#<img.*http(s)?://(.*)/" . NGG_ATTACH_TO_POST_SLUG . "/preview/id--(\\d+).*>#mi", $content, $matches, PREG_SET_ORDER)) { $mapper = C_Displayed_Gallery_Mapper::get_instance(); foreach ($matches as $match) { // Find the displayed gallery $displayed_gallery_id = $match[3]; $displayed_gallery = $mapper->find($displayed_gallery_id, TRUE); // Get the content for the displayed gallery $retval = '<p>' . _('Invalid Displayed Gallery') . '</p>'; if ($displayed_gallery) { $renderer = $this->get_registry()->get_utility('I_Displayed_Gallery_Renderer'); $retval = $renderer->render($displayed_gallery, TRUE); } $content = str_replace($match[0], $retval, $content); } } return $content; }
/** * POST action for downloading a bunch of NextGEN gallery images as a ZIP archive */ public static function nggDownloadZip() { global $nggdb; // pick up gallery ID and array of image IDs from AJAX request $images = isset($_REQUEST['pid']) && is_array($_REQUEST['pid']) ? array_map('intval', $_REQUEST['pid']) : false; $gallery = isset($_REQUEST['gallery']) ? trim(wp_unslash($_REQUEST['gallery'])) : ''; // sanity check if (!is_object($nggdb)) { wp_die(__('NextGEN Download Gallery requires NextGEN Gallery or NextCellent Gallery', 'nextgen-download-gallery')); } // check for request to download everything if (!empty($_REQUEST['download-all']) && !empty($_REQUEST['all-id'])) { $allID = wp_unslash($_REQUEST['all-id']); if (defined('NEXTGEN_GALLERY_PLUGIN_VERSION')) { // decode NGG2 encoded query for virtual gallery $json = base64_decode($allID); $query = $json ? json_decode($json, true) : false; // reduce query to permitted fields $query = $query ? array_intersect_key($query, array_flip(self::getNgg2QueryFields())) : false; if (!empty($query)) { $mapper = C_Displayed_Gallery_Mapper::get_instance(); $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', $query, $mapper); $entities = $displayed_gallery->get_entities(false, false, true); $images = array(); foreach ($entities as $image) { $images[] = $image->pid; } if (empty($gallery)) { $gallery = self::getNgg2DownloadTitle($displayed_gallery); } } } else { $images = $nggdb->get_ids_from_gallery($allID); } } else { if (!empty($_REQUEST['all-tags'])) { $picturelist = nggTags::find_images_for_tags(wp_unslash($_REQUEST['all-tags']), 'ASC'); $images = array(); foreach ($picturelist as $image) { $images[] = $image->pid; } } } // if no gallery name, confect one if (empty($gallery)) { $gallery = md5(implode(',', $images)); } if (is_array($images) && count($images) > 0) { // allow a long script run for pulling together lots of images @set_time_limit(HOUR_IN_SECONDS); // stop/clear any output buffering while (ob_get_level()) { ob_end_clean(); } // turn off compression on the server if (function_exists('apache_setenv')) { @apache_setenv('no-gzip', 1); } @ini_set('zlib.output_compression', 'Off'); if (!class_exists('PclZip')) { require ABSPATH . 'wp-admin/includes/class-pclzip.php'; } $filename = tempnam(get_temp_dir(), 'zip'); $zip = new PclZip($filename); $files = array(); foreach ($images as $image) { $image = $nggdb->find_image($image); if ($image) { $files[] = apply_filters('ngg_dlgallery_image_path', $image->imagePath, $image); } } if (count($files) > 0) { // allow other plugins / themes to preprocess files added to the zip archive $preAddCallback = apply_filters('ngg_dlgallery_zip_pre_add', '__return_true'); // create the Zip archive, without paths or compression (images are generally already compressed) $properties = $zip->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_CB_PRE_ADD, $preAddCallback); if (!is_array($properties)) { wp_die($zip->errorInfo(true)); } unset($zip); // send the Zip archive to the browser $zipName = apply_filters('ngg_dlgallery_zip_filename', sanitize_file_name(strtr($gallery, ',', '-')) . '.zip', $gallery); do_action('ngg_dlgallery_zip_before_send', $zipName, $filename, $images); header('Content-Description: File Transfer'); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . $zipName); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); $chunksize = 512 * 1024; $file = @fopen($filename, 'rb'); while (!feof($file)) { echo @fread($file, $chunksize); flush(); } fclose($file); // check for bug in some old PHP versions, close a second time! if (is_resource($file)) { @fclose($file); } do_action('ngg_dlgallery_zip_after_send', $zipName, $filename, $images); // delete the temporary file @unlink($filename); exit; } // no files, report to user wp_die(__('No files found to download', 'nextgen-download-gallery')); } wp_die(__('No images selected for download', 'nextgen-download-gallery')); }
function wpml_set_gallery_language_on_save_post($post_id) { if (wp_is_post_revision($post_id)) { return; } if (isset($_POST['icl_ajx_action']) && $_POST['icl_ajx_action'] == 'make_duplicates') { return; } $post = get_post($post_id); if ($post->post_type == 'displayed_gallery') { return; } if (preg_match_all("#<img.*http(s)?://(.*)?" . NGG_ATTACH_TO_POST_SLUG . "(=|/)preview(/|&|&)id(=|--)(\\d+).*?>#mi", $post->post_content, $matches, PREG_SET_ORDER)) { $mapper = C_Displayed_Gallery_Mapper::get_instance(); foreach ($matches as $match) { // Find the displayed gallery $displayed_gallery_id = $match[6]; add_filter('wpml_suppress_filters', '__return_true', 10, 1); $displayed_gallery = $mapper->find($displayed_gallery_id, TRUE); add_filter('wpml_suppress_filters', '__return_false', 11, 1); if ($displayed_gallery) { $displayed_gallery_type = apply_filters('wpml_element_type', 'displayed_gallery'); // set language of this gallery $displayed_gallery_lang = apply_filters('wpml_post_language_details', null, $displayed_gallery->ID); $post_language = apply_filters('wpml_post_language_details', null, $post_id); if (!$displayed_gallery_lang || $displayed_gallery_lang['language_code'] != $post_language['language_code']) { if ($post_language) { $args = array('element_id' => $displayed_gallery->ID, 'element_type' => $displayed_gallery_type, 'language_code' => $post_language['language_code']); do_action('wpml_set_element_language_details', $args); } } // duplicate gallery to other languages $is_translated = apply_filters('wpml_element_has_translations', '', $displayed_gallery->ID, $displayed_gallery_type); if (!$is_translated) { do_action('wpml_admin_make_post_duplicates', $displayed_gallery->ID); } } } } }
function params_to_displayed_gallery($params) { $displayed_gallery = NULL; // Get the NextGEN settings to provide some defaults $settings = C_NextGen_Settings::get_instance(); // Configure the arguments $defaults = array('id' => NULL, 'source' => '', 'container_ids' => array(), 'gallery_ids' => array(), 'album_ids' => array(), 'tag_ids' => array(), 'display_type' => '', 'exclusions' => array(), 'order_by' => $settings->galSort, 'order_direction' => $settings->galSortOrder, 'image_ids' => array(), 'entity_ids' => array(), 'tagcloud' => FALSE, 'returns' => 'included', 'slug' => NULL, 'sortorder' => array()); $args = shortcode_atts($defaults, $params); // Are we loading a specific displayed gallery that's persisted? $mapper = C_Displayed_Gallery_Mapper::get_instance(); if (!is_null($args['id'])) { $displayed_gallery = $mapper->find($args['id'], TRUE); unset($mapper); // no longer needed } else { // Perform some conversions... // Galleries? if ($args['gallery_ids']) { if ($args['source'] != 'albums' and $args['source'] != 'album') { $args['source'] = 'galleries'; $args['container_ids'] = $args['gallery_ids']; if ($args['image_ids']) { $args['entity_ids'] = $args['image_ids']; } } elseif ($args['source'] == 'albums') { $args['entity_ids'] = $args['gallery_ids']; } unset($args['gallery_ids']); } elseif ($args['album_ids'] || $args['album_ids'] === '0') { $args['source'] = 'albums'; $args['container_ids'] = $args['album_ids']; unset($args['albums_ids']); } elseif ($args['tag_ids']) { $args['source'] = 'tags'; $args['container_ids'] = $args['tag_ids']; unset($args['tag_ids']); } elseif ($args['image_ids']) { $args['source'] = 'galleries'; $args['entity_ids'] = $args['image_ids']; unset($args['image_ids']); } elseif ($args['tagcloud']) { $args['source'] = 'tags'; } // Convert strings to arrays if (!is_array($args['container_ids'])) { $args['container_ids'] = preg_split("/,|\\|/", $args['container_ids']); } if (!is_array($args['exclusions'])) { $args['exclusions'] = preg_split("/,|\\|/", $args['exclusions']); } if (!is_array($args['entity_ids'])) { $args['entity_ids'] = preg_split("/,|\\|/", $args['entity_ids']); } if (!is_array($args['sortorder'])) { $args['sortorder'] = preg_split("/,|\\|/", $args['sortorder']); } // Get the display settings foreach (array_keys($defaults) as $key) { unset($params[$key]); } $args['display_settings'] = $params; // Create the displayed gallery $factory = C_Component_Factory::get_instance(); $displayed_gallery = $factory->create('displayed_gallery', $args, $mapper); unset($factory); } // Validate the displayed gallery if ($displayed_gallery) { $displayed_gallery->validate(); } return $displayed_gallery; }
function _load_displayed_gallery() { $mapper = C_Displayed_Gallery_Mapper::get_instance(); // Fetch the displayed gallery by ID if ($id = $this->object->param('id')) { $this->object->_displayed_gallery = $mapper->find($id, TRUE); } else { if (isset($_REQUEST['shortcode'])) { $params = str_replace('ngg_images', '', base64_decode($_REQUEST['shortcode'])); $params = stripslashes($params); $params = str_replace(array('[', ']'), array('[', ']'), $params); $params = shortcode_parse_atts($params); $this->object->_displayed_gallery = C_Displayed_Gallery_Renderer::get_instance()->params_to_displayed_gallery($params); } } // If all else fails, then create fresh with a new displayed gallery if (empty($this->object->_displayed_gallery)) { $this->object->_displayed_gallery = $mapper->create(); } }