/**
  * 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);
     }
 }
 /**
  * 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;
 }
 /**
  * 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);
 }
 public function create_view($template, $params = array(), $context = NULL)
 {
     $factory = C_Component_Factory::get_instance();
     $view = $factory->create('mvc_view', $template, $params, NULL, $context);
     return $view;
 }
 static function update($reset = FALSE)
 {
     $local_settings = C_NextGen_Settings::get_instance();
     $global_settings = C_NextGen_Global_Settings::get_instance();
     // Somehow some installations are missing several default settings
     // Because gallerystorage_driver is essential to know we do a 'soft' reset here
     // by filling in any missing options from the default settings
     if (is_null($local_settings->gallerystorage_driver)) {
         $settings_installer = new C_NextGen_Settings_Installer();
         $local_settings->reset();
         $settings_installer->install_local_settings();
         $local_settings->save();
         $global_settings->reset();
         $settings_installer->install_global_settings();
         $global_settings->save();
     }
     // This is a specific hack/work-around/fix and can probably be removed sometime after 2.0.20's release
     //
     // NextGen 2x was not multisite compatible until 2.0.18. Users that upgraded before this
     // will have nearly all of their settings stored globally (network wide) in wp_sitemeta. If
     // pope_module_list (which should always be a local setting) exists site-wide we wipe the current
     // global ngg_options and restore from defaults. This should only ever run once.
     if (is_multisite() && isset($global_settings->pope_module_list)) {
         // Setting this to TRUE will wipe current settings for display types, but also
         // allows the display type installer to run correctly
         $reset = TRUE;
         $settings_installer = new C_NextGen_Settings_Installer();
         $global_defaults = $settings_installer->get_global_defaults();
         // Preserve the network options we honor by restoring them after calling $global_settings->reset()
         $global_settings_to_keep = array();
         foreach ($global_defaults as $key => $val) {
             $global_settings_to_keep[$key] = $global_settings->{$key};
         }
         // Resets internal options to an empty array
         $global_settings->reset();
         // Restore the defaults, then our saved values. This must be done again later because
         // we've set $reset to TRUE.
         $settings_installer->install_global_settings();
         foreach ($global_settings_to_keep as $key => $val) {
             $global_settings->{$key} = $val;
         }
     }
     // Get last module list and current module list. Compare...
     $last_module_list = self::_get_last_module_list($reset);
     $current_module_list = self::_generate_module_info();
     $diff = array_diff($current_module_list, $last_module_list);
     $do_upgrade = count($diff) > 0 || count($last_module_list) != count($current_module_list);
     $can_upgrade = $do_upgrade ? self::can_do_upgrade() : FALSE;
     if ($can_upgrade && !$diff) {
         $diff = $current_module_list;
     }
     if ($can_upgrade && $do_upgrade) {
         // Clear APC cache
         if (function_exists('apc_clear_cache')) {
             @apc_clear_cache('opcode');
             apc_clear_cache();
         }
         // We flush ALL transients
         wp_cache_flush();
         global $wpdb;
         $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient%'");
         // Remove all NGG created cron jobs
         self::refresh_cron();
         // Delete auto-update cache
         update_option('photocrati_auto_update_admin_update_list', null);
         update_option('photocrati_auto_update_admin_check_date', '');
         // Other Pope applications might be loaded, and therefore
         // all singletons should be destroyed, so that they can be
         // adapted as necessary. For now, we'll just assume that the factory
         // is the only singleton that will be used by other Pope applications
         C_Component_Factory::$_instances = array();
         foreach ($diff as $module_name) {
             $parts = explode('|', $module_name);
             if ($handler = self::get_handler_instance(array_shift($parts))) {
                 if (method_exists($handler, 'install')) {
                     $handler->install($reset);
                 }
             }
         }
         // NOTE & TODO: if the above section that declares $global_settings_to_keep is removed this should also
         // Since a hard-reset of the settings was forced we must again re-apply our previously saved values
         if (isset($global_settings_to_keep)) {
             foreach ($global_settings_to_keep as $key => $val) {
                 $global_settings->{$key} = $val;
             }
         }
         // Save any changes settings
         $global_settings->save();
         $local_settings->save();
     }
     // Another workaround to an issue caused by NextGen's lack of multisite compatibility. It's possible
     // the string substitation wasn't performed, so if a '%' symbol exists in gallerypath we reset it. It's
     // another db call, but again this should only ever run once.
     //
     // Remove this when removing the above reset-global-settings code
     if (strpos($local_settings->gallerypath, '%')) {
         $settings_installer = new C_NextGen_Settings_Installer();
         $local_settings->gallerypath = $settings_installer->gallerypath_replace($global_settings->gallerypath);
         $local_settings->save();
     }
     // Update the module list, and remove the update flag
     if ($can_upgrade) {
         update_option('pope_module_list', $current_module_list);
         self::done_upgrade();
     }
 }
 public function import_gallery_from_fs($abspath, $gallery_id = FALSE, $move_files = TRUE)
 {
     $retval = FALSE;
     if (@file_exists($abspath)) {
         // Ensure that this folder has images
         $files_all = scandir($abspath);
         $files = array();
         // first perform some filtering on file list
         foreach ($files_all as $file) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $files[] = $file;
         }
         if (!empty($files)) {
             // Get needed utilities
             $fs = C_Fs::get_instance();
             $gallery_mapper = C_Gallery_Mapper::get_instance();
             // Sometimes users try importing a directory, which actually has all images under another directory
             $first_file_abspath = $fs->join_paths($abspath, $files[0]);
             if (is_dir($first_file_abspath) && count($files) == 1) {
                 return $this->import_gallery_from_fs($first_file_abspath, $gallery_id, $move_files);
             }
             // If no gallery has been specified, then use the directory name as the gallery name
             if (!$gallery_id) {
                 // Create the gallery
                 $gallery = $gallery_mapper->create(array('title' => M_I18n::mb_basename($abspath)));
                 if (!$move_files) {
                     $gallery->path = str_ireplace(ABSPATH, '', $abspath);
                 }
                 // Save the gallery
                 if ($gallery->save()) {
                     $gallery_id = $gallery->id();
                 }
             }
             // Ensure that we have a gallery id
             if ($gallery_id) {
                 $retval = array('gallery_id' => $gallery_id, 'image_ids' => array());
                 foreach ($files as $file) {
                     if (!preg_match('/\\.(jpg|jpeg|gif|png)$/i', $file)) {
                         continue;
                     }
                     $file_abspath = $fs->join_paths($abspath, $file);
                     $image = null;
                     if ($move_files) {
                         $image = $this->object->upload_base64_image($gallery_id, file_get_contents($file_abspath), str_replace(' ', '_', $file));
                     } else {
                         // Create the database record ... TODO cleanup, some duplication here from upload_base64_image
                         $factory = C_Component_Factory::get_instance();
                         $image = $factory->create('image');
                         $image->alttext = sanitize_title_with_dashes(str_replace('.' . M_I18n::mb_pathinfo($file_abspath, PATHINFO_EXTENSION), '', M_I18n::mb_basename($file_abspath)));
                         $image->galleryid = $this->object->_get_gallery_id($gallery_id);
                         $image->filename = M_I18n::mb_basename($file_abspath);
                         $image->image_slug = nggdb::get_unique_slug(sanitize_title_with_dashes($image->alttext), 'image');
                         $image_key = $this->object->_image_mapper->get_primary_key_column();
                         $abs_filename = $file_abspath;
                         if ($image_id = $this->object->_image_mapper->save($image)) {
                             try {
                                 if (C_NextGen_settings::get_instance()->imgBackup) {
                                     $this->object->backup_image($image);
                                 }
                                 #															if ($settings->imgAutoResize)
                                 #															    $this->object->generate_image_clone(
                                 #															        $abs_filename,
                                 #															        $abs_filename,
                                 #															        $this->object->get_image_size_params($image_id, 'full')
                                 #															    );
                                 // Ensure that fullsize dimensions are added to metadata array
                                 $dimensions = getimagesize($abs_filename);
                                 $full_meta = array('width' => $dimensions[0], 'height' => $dimensions[1]);
                                 if (!isset($image->meta_data) or is_string($image->meta_data) && strlen($image->meta_data) == 0) {
                                     $image->meta_data = array();
                                 }
                                 $image->meta_data = array_merge($image->meta_data, $full_meta);
                                 $image->meta_data['full'] = $full_meta;
                                 // Generate a thumbnail for the image
                                 $this->object->generate_thumbnail($image);
                                 // Set gallery preview image if missing
                                 C_Gallery_Mapper::get_instance()->set_preview_image($gallery, $image_id, TRUE);
                                 // Notify other plugins that an image has been added
                                 do_action('ngg_added_new_image', $image);
                                 // delete dirsize after adding new images
                                 delete_transient('dirsize_cache');
                                 // Seems redundant to above hook. Maintaining for legacy purposes
                                 do_action('ngg_after_new_images_added', $gallery_id, array($image->{$image_key}));
                             } catch (Exception $ex) {
                                 throw new E_InsufficientWriteAccessException(FALSE, $abs_filename, FALSE, $ex);
                             }
                         } else {
                             throw new E_InvalidEntityException();
                         }
                     }
                     $retval['image_ids'][] = $image->{$image->id_field};
                 }
                 // Add the gallery name to the result
                 $gallery = $gallery_mapper->find($gallery_id);
                 $retval['gallery_name'] = $gallery->title;
                 unset($gallery);
             }
         }
     }
     return $retval;
 }
 public function &create_app($name = '/')
 {
     $factory = C_Component_Factory::get_instance();
     $app = $factory->create('routing_app', $name);
     $this->object->_apps[] = $app;
     return $app;
 }
 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 get_request_token($action_name, $args = null)
 {
     $factory = C_Component_Factory::get_instance();
     $token = $factory->create('wordpress_security_token');
     $token->init_token($action_name, $args);
     return $token;
 }
 function widget($args, $instance)
 {
     $router = C_Router::get_instance();
     wp_enqueue_style('nextgen_widgets_style', $router->get_static_url('photocrati-widget#widgets.css'), FALSE, NGG_SCRIPT_VERSION);
     wp_enqueue_style('nextgen_basic_thumbnails_style', $router->get_static_url('photocrati-nextgen_basic_gallery#thumbnails/nextgen_basic_thumbnails.css'), FALSE, NGG_SCRIPT_VERSION);
     // these are handled by extract() but I want to silence my IDE warnings that these vars don't exist
     $before_widget = NULL;
     $before_title = NULL;
     $after_widget = NULL;
     $after_title = NULL;
     $widget_id = NULL;
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base);
     $renderer = C_Displayed_Gallery_Renderer::get_instance();
     $factory = C_Component_Factory::get_instance();
     $view = $factory->create('mvc_view', '');
     // IE8 webslice support if needed
     if (!empty($instance['webslice'])) {
         $before_widget .= '<div class="hslice" id="ngg-webslice">';
         $before_title = str_replace('class="', 'class="entry-title ', $before_title);
         $after_widget = '</div>' . $after_widget;
     }
     $source = $instance['type'] == 'random' ? 'random_images' : 'recent';
     $template = !empty($instance['template']) ? $instance['template'] : $view->get_template_abspath('photocrati-widget#display_gallery');
     $params = array('slug' => 'widget-' . $args['widget_id'], 'source' => $source, 'display_type' => NGG_BASIC_THUMBNAILS, 'images_per_page' => $instance['items'], 'maximum_entity_count' => $instance['items'], 'template' => $template, 'image_type' => $instance['show'] == 'original' ? 'full' : 'thumb', 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'show_thumbnail_link' => FALSE, 'use_imagebrowser_effect' => FALSE, 'disable_pagination' => TRUE, 'image_width' => $instance['width'], 'image_height' => $instance['height'], 'ngg_triggers_display' => 'never', 'widget_setting_title' => $title, 'widget_setting_before_widget' => $before_widget, 'widget_setting_before_title' => $before_title, 'widget_setting_after_widget' => $after_widget, 'widget_setting_after_title' => $after_title, 'widget_setting_width' => $instance['width'], 'widget_setting_height' => $instance['height'], 'widget_setting_show_setting' => $instance['show'], 'widget_setting_widget_id' => $widget_id);
     switch ($instance['exclude']) {
         case 'all':
             break;
         case 'denied':
             $mapper = C_Gallery_Mapper::get_instance();
             $gallery_ids = array();
             $list = explode(',', $instance['list']);
             foreach ($mapper->find_all() as $gallery) {
                 if (!in_array($gallery->{$gallery->id_field}, $list)) {
                     $gallery_ids[] = $gallery->{$gallery->id_field};
                 }
             }
             $params['container_ids'] = implode(',', $gallery_ids);
             break;
         case 'allow':
             $params['container_ids'] = $instance['list'];
             break;
     }
     echo $renderer->display_images($params);
 }
 /**
  * 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;
 }
 static function update($reset = FALSE)
 {
     $local_settings = C_NextGen_Settings::get_instance();
     $global_settings = C_NextGen_Global_Settings::get_instance();
     // This is a specific hack/work-around/fix and can probably be removed sometime after 2.0.20's release
     //
     // NextGen 2x was not multisite compatible until 2.0.18. Users that upgraded before this
     // will have nearly all of their settings stored globally (network wide) in wp_sitemeta. If
     // pope_module_list (which should always be a local setting) exists site-wide we wipe the current
     // global ngg_options and restore from defaults. This should only ever run once.
     if (is_multisite() && isset($global_settings->pope_module_list)) {
         // Setting this to TRUE will wipe current settings for display types, but also
         // allows the display type installer to run correctly
         $reset = TRUE;
         $settings_installer = new C_NextGen_Settings_Installer();
         $global_defaults = $settings_installer->get_global_defaults();
         // Preserve the network options we honor by restoring them after calling $global_settings->reset()
         $global_settings_to_keep = array();
         foreach ($global_defaults as $key => $val) {
             $global_settings_to_keep[$key] = $global_settings->{$key};
         }
         // Resets internal options to an empty array
         $global_settings->reset();
         // Restore the defaults, then our saved values. This must be done again later because
         // we've set $reset to TRUE.
         $settings_installer->install_global_settings();
         foreach ($global_settings_to_keep as $key => $val) {
             $global_settings->{$key} = $val;
         }
     }
     $last_module_list = $reset ? array() : $local_settings->get('pope_module_list', array());
     $current_module_list = self::_generate_module_info();
     if (count($modules = array_diff($current_module_list, $last_module_list)) > 0) {
         // The cache should be flushed
         C_Photocrati_Cache::flush();
         // Remove all NGG created cron jobs
         self::refresh_cron();
         // Delete auto-update cache
         update_option('photocrati_auto_update_admin_update_list', null);
         update_option('photocrati_auto_update_admin_check_date', '');
         // Other Pope applications might be loaded, and therefore
         // all singletons should be destroyed, so that they can be
         // adapted as necessary. For now, we'll just assume that the factory
         // is the only singleton that will be used by other Pope applications
         C_Component_Factory::$_instances = array();
         foreach ($modules as $module_name) {
             if ($handler = self::get_handler_instance(array_shift(explode('|', $module_name)))) {
                 if (method_exists($handler, 'install')) {
                     $handler->install($reset);
                 }
             }
         }
         // Update the module list
         $local_settings->set('pope_module_list', $current_module_list);
         // NOTE & TODO: if the above section that declares $global_settings_to_keep is removed this should also
         // Since a hard-reset of the settings was forced we must again re-apply our previously saved values
         if (isset($global_settings_to_keep)) {
             foreach ($global_settings_to_keep as $key => $val) {
                 $global_settings->{$key} = $val;
             }
         }
         // Save any changes settings
         $global_settings->save();
         $local_settings->save();
     }
     // Another workaround to an issue caused by NextGen's lack of multisite compatibility. It's possible
     // the string substitation wasn't performed, so if a '%' symbol exists in gallerypath we reset it. It's
     // another db call, but again this should only ever run once.
     //
     // Remove this when removing the above reset-global-settings code
     if (strpos($local_settings->gallerypath, '%')) {
         $settings_installer = new C_NextGen_Settings_Installer();
         $local_settings->gallerypath = $settings_installer->gallerypath_replace($global_settings->gallerypath);
         $local_settings->save();
     }
 }
 /**
  * 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'));
 }
 /**
  * Saves the displayed gallery
  */
 public function save_displayed_gallery_action()
 {
     $response = array();
     $mapper = C_Displayed_Gallery_Mapper::get_instance();
     // Do we have fields to work with?
     if ($this->object->validate_ajax_request('nextgen_edit_displayed_gallery', true) && ($params = json_decode($this->object->param('displayed_gallery')))) {
         // Existing displayed gallery ?
         if ($id = $this->object->param('id')) {
             $displayed_gallery = $mapper->find($id, TRUE);
             if ($displayed_gallery) {
                 foreach ($params as $key => $value) {
                     $displayed_gallery->{$key} = $value;
                 }
             }
         } else {
             $factory = C_Component_Factory::get_instance();
             $displayed_gallery = $factory->create('displayed_gallery', $params, $mapper);
         }
         // Save the changes
         if ($displayed_gallery) {
             if ($displayed_gallery->save()) {
                 $response['displayed_gallery'] = $displayed_gallery->get_entity();
             } else {
                 $response['validation_errors'] = $this->get_attach_to_post()->show_errors_for($displayed_gallery, TRUE);
             }
         } else {
             $response['error'] = __('Displayed gallery does not exist', 'nggallery');
         }
     } else {
         $response['error'] = __('Invalid request', 'nggallery');
     }
     return $response;
 }
 static function _render_related_string($sluglist = array(), $maxImages = NULL, $type = NULL)
 {
     $settings = C_NextGen_Settings::get_instance();
     if (is_null($type)) {
         $type = $settings->appendType;
     }
     if (is_null($maxImages)) {
         $maxImages = $settings->maxImages;
     }
     if (!$sluglist) {
         switch ($type) {
             case 'tags':
                 if (function_exists('get_the_tags')) {
                     $taglist = get_the_tags();
                     if (is_array($taglist)) {
                         foreach ($taglist as $tag) {
                             $sluglist[] = $tag->slug;
                         }
                     }
                 }
                 break;
             case 'category':
                 $catlist = get_the_category();
                 if (is_array($catlist)) {
                     foreach ($catlist as $cat) {
                         $sluglist[] = $cat->category_nicename;
                     }
                 }
                 break;
         }
     }
     $taglist = implode(',', $sluglist);
     if ($taglist === 'uncategorized' || empty($taglist)) {
         return;
     }
     $renderer = C_Displayed_Gallery_Renderer::get_instance();
     $view = C_Component_Factory::get_instance()->create('mvc_view', '');
     $retval = $renderer->display_images(array('source' => 'tags', 'container_ids' => $taglist, 'display_type' => NGG_BASIC_THUMBNAILS, 'images_per_page' => $maxImages, 'maximum_entity_count' => $maxImages, 'template' => $view->get_template_abspath('photocrati-nextgen_gallery_display#related'), 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE, 'display_no_images_error' => FALSE));
     if ($retval) {
         wp_enqueue_style('nextgen_gallery_related_images');
     }
     return apply_filters('ngg_show_related_gallery_content', $retval, $taglist);
 }
 /**
  * Creates a new model
  * @param stdClass|array $properties
  * @return C_DataMapper_Model
  */
 function create($properties = array(), $context = FALSE)
 {
     $entity = $properties;
     $factory = C_Component_Factory::get_instance();
     if (!is_object($properties)) {
         $entity = new stdClass();
         foreach ($properties as $k => $v) {
             $entity->{$k} = $v;
         }
     }
     return $factory->create($this->object->get_model_factory_method(), $entity, $this->object, $context);
 }
 function admin_menu()
 {
     $list = $this->_get_update_list();
     if ($list != null) {
         $factory = C_Component_Factory::get_instance();
         $this->_controller = $factory->create('autoupdate_admin_controller');
         add_submenu_page('index.php', __('Photocrati Updates'), __('Photocrati') . ' <span class="update-plugins"><span class="update-count">' . count($list) . '</span></span>', 'update_plugins', $this->module_id, array($this->_controller, 'admin_page'));
     } else {
         if (isset($_GET['page']) && $_GET['page'] == $this->module_id) {
             wp_redirect(admin_url());
             exit;
         }
     }
 }