/**
  * Gets existing albums
  * @return array
  */
 public function get_existing_albums_action()
 {
     $response = array();
     if ($this->object->validate_ajax_request('nextgen_edit_displayed_gallery')) {
         $limit = $this->object->param('limit');
         $offset = $this->object->param('offset');
         // We return the total # of albums, so that the client can make pagination requests
         $mapper = C_Album_Mapper::get_instance();
         $response['total'] = $mapper->count();
         $response['limit'] = $limit = $limit ? $limit : 0;
         $response['offset'] = $offset = $offset ? $offset : 0;
         // Get the albums
         $mapper->select();
         if ($limit) {
             $mapper->limit($limit, $offset);
         }
         $response['items'] = $mapper->run_query();
     }
     return $response;
 }
 /**
  * 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);
     }
 }
 /**
  * Gets a single album
  * @param $args (blog_id, username, password, album_id)
  */
 function get_album($args, $return_model = FALSE)
 {
     $retval = new IXR_Error(403, 'Invalid username or password');
     $blog_id = intval($args[0]);
     $username = strval($args[1]);
     $password = strval($args[2]);
     $album_id = intval($args[3]);
     // Authenticate the user
     if ($this->_login($username, $password, $blog_id)) {
         // Are we allowed?
         $security = $this->get_registry()->get_utility('I_Security_Manager');
         if ($security->is_allowed('nextgen_edit_album')) {
             $mapper = C_Album_Mapper::get_instance();
             if ($album = $mapper->find($album_id, TRUE)) {
                 // Vladimir's Lightroom plugins requires the 'id' to be a string
                 // Ask if he can accept integers as well. Currently, integers break
                 // his plugin
                 $album->id = (string) $album->id;
                 $album->galleries = $album->sortorder;
                 $retval = $return_model ? $album : $album->get_entity();
             } else {
                 $retval = FALSE;
             }
         } else {
             $retval = new IXR_Error(403, "Sorry, you must be able to manage albums");
         }
     }
     return $retval;
 }
Exemple #4
0
 /**
  * Finds all albums
  *
  * @deprecated
  * @param string $order_by
  * @param string $order_dir
  * @param int $limit number of albums, 0 shows all albums
  * @param int $start the start index for paged albums
  * @return array $album
  */
 function find_all_album($order_by = 'id', $order_dir = 'ASC', $limit = '0', $start = '0')
 {
     $mapper = C_Album_Mapper::get_instance();
     $mapper->select();
     $mapper->where_and(array());
     $mapper->order_by($order_by, $order_dir);
     if ($limit > 0) {
         $mapper->limit($limit, $start);
     }
     return $mapper->run_query();
 }
 /**
  * Returns an instance of the album datamapper
  * @param bool|mixed $context
  * @return C_Album_Mapper
  */
 static function get_instance($context = FALSE)
 {
     if (is_null(self::$_instance)) {
         $klass = get_class();
         self::$_instance = new $klass($context);
     }
     return self::$_instance;
 }
 function index_action($displayed_gallery, $return = FALSE)
 {
     $retval = '';
     // Determine what to render:
     // 1) A gallery
     if ($this->param('gallery')) {
         $retval = $this->object->_render_gallery($displayed_gallery->display_settings['gallery_display_type'], $displayed_gallery->display_type, $displayed_gallery->display_settings, $displayed_gallery->get_albums(), TRUE);
     } else {
         if ($album_id = $this->param('album')) {
             if (!is_numeric($album_id)) {
                 $mapper = C_Album_Mapper::get_instance();
                 $result = array_pop($mapper->select()->where(array("slug = %s", $album_id))->limit(1)->run_query());
                 $album_id = $result->{$result->id_field};
             }
             $original_entities = $displayed_gallery->get_albums();
             $displayed_gallery->container_ids = array($album_id);
             $retval = $this->object->_render_album($displayed_gallery, $original_entities, $return);
         } else {
             $retval = $this->object->_render_album($displayed_gallery, NULL, $return);
         }
     }
     return $retval;
 }
 /**
  * Gets albums queried in this displayed gallery
  * @return array
  */
 public function get_albums()
 {
     $retval = array();
     if ($source = $this->object->get_source()) {
         if (in_array('album', $source->returns)) {
             $mapper = C_Album_Mapper::get_instance();
             $album_key = $mapper->get_primary_key_column();
             if ($this->object->container_ids) {
                 $mapper->select()->where(array("{$album_key} IN %s", $this->object->container_ids));
             }
             $retval = $mapper->run_query();
         }
     }
     return $retval;
 }
 function remove_folder($folderId)
 {
     global $wplr;
     $albumId = $wplr->get_meta('nextgen_album_id', $folderId);
     C_Album_Mapper::get_instance()->destroy($albumId, TRUE);
     $wplr->delete_meta("nextgen_album_id", $folderId);
 }
Exemple #9
0
 function update_album()
 {
     check_admin_referer('ngg_thickbox_form');
     if (!nggGallery::current_user_can('NextGEN Edit album settings')) {
         wp_die(__('Cheatin’ uh?'));
     }
     $this->currentID = $_REQUEST['act_album'];
     $album = $this->_get_album($this->currentID);
     $album->name = stripslashes($_POST['album_name']);
     $album->albumdesc = stripslashes($_POST['album_desc']);
     $album->previewpic = (int) $_POST['previewpic'];
     $album->pageid = (int) $_POST['pageid'];
     $result = C_Album_Mapper::get_instance()->save($album);
     //hook for other plugin to update the fields
     do_action('ngg_update_album', $this->currentID, $_POST);
     if ($result) {
         nggGallery::show_message(__('Update Successfully', '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)
 {
     // Ensure that the open_gallery_in_lightbox setting is present
     if (!array_key_exists('open_gallery_in_lightbox', $displayed_gallery->display_settings)) {
         $displayed_gallery->display_settings['open_gallery_in_lightbox'] = 0;
     }
     $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
     $parent_albums = $displayed_gallery->get_albums();
     // Are we to display a gallery? Ensure our 'gallery' isn't just a paginated album view
     $gallery = $gallery_slug = $this->param('gallery');
     if ($gallery && strpos($gallery, 'nggpage--') !== 0) {
         // 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();
         $tmp = $mapper->select()->where(array('slug = %s', $gallery))->limit(1)->run_query();
         $result = reset($tmp);
         unset($tmp);
         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, 'original_album_entities' => $parent_albums);
         if (!empty($display_settings['gallery_display_template'])) {
             $gallery_params['template'] = $display_settings['gallery_display_template'];
         }
         add_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates'), 8, 2);
         add_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates'), 9, 2);
         $output = $renderer->display_images($gallery_params, $return);
         remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates'));
         remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates'));
         return $output;
     } else {
         if ($album = $this->param('album')) {
             $mapper = C_Album_Mapper::get_instance();
             $result = $mapper->select()->where(array('slug = %s', $album))->limit(1)->run_query();
             $result = array_pop($result);
             $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);
             $displayed_gallery->display_settings['original_album_id'] = 'a' . $album_sub;
             $displayed_gallery->display_settings['original_album_entities'] = $parent_albums;
         }
     }
     // 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('page', $displayed_gallery->id(), 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) {
         $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')));
         if (!empty($display_settings['template']) && $display_settings['template'] != 'default') {
             // Add additional parameters
             $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'];
             // Legacy templates lack a good way of injecting content at the right time
             $this->object->add_mixin('A_NextGen_Album_Breadcrumbs');
             $this->object->add_mixin('A_NextGen_Album_Descriptions');
             $breadcrumbs = $this->object->render_legacy_template_breadcrumbs($displayed_gallery, $entities);
             $description = $this->object->render_legacy_template_description($displayed_gallery);
             // Render legacy template
             $this->object->add_mixin('Mixin_NextGen_Basic_Templates');
             $display_settings = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), $display_settings);
             $retval = $this->object->legacy_render($display_settings['template'], $display_settings, $return, 'album');
             if (!empty($description)) {
                 $retval = $description . $retval;
             }
             if (!empty($breadcrumbs)) {
                 $retval = $breadcrumbs . $retval;
             }
             return $retval;
         } else {
             $params = $display_settings;
             $albums = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), array('entities' => $entities));
             $params['pagination'] = $pagination_result['output'];
             $params['image_gen_params'] = $albums['image_gen_params'];
             $params['galleries'] = $albums['galleries'];
             foreach ($params['galleries'] as &$gallery) {
                 $gallery->entity_type = isset($gallery->is_gallery) && intval($gallery->is_gallery) ? 'gallery' : 'album';
                 // If we're to open a gallery in a lightbox, we need to expose it to the lightbox
                 // as a displayed gallery
                 if (isset($params['open_gallery_in_lightbox']) && $gallery->entity_type == 'gallery') {
                     $gallery->displayed_gallery = new C_Displayed_Gallery();
                     $gallery->displayed_gallery->container_ids = array($gallery->{$gallery->id_field});
                     $gallery->displayed_gallery->display_settings = $displayed_gallery->display_settings;
                     $gallery->displayed_gallery->returns = 'included';
                     $gallery->displayed_gallery->source = 'galleries';
                     $gallery->displayed_gallery->images_list_count = $gallery->displayed_gallery->get_entity_count();
                     $gallery->displayed_gallery->is_album_gallery = TRUE;
                     $gallery->displayed_gallery->to_transient();
                     if ($this->does_lightbox_support_displayed_gallery($displayed_gallery)) {
                         $gallery->displayed_gallery->effect_code = $this->object->get_effect_code($gallery->displayed_gallery);
                     }
                     // Add "galleries.gallery_1 = {};"
                     $this->object->_add_script_data('ngg_common', 'galleries.gallery_' . $gallery->displayed_gallery->id(), (array) $gallery->displayed_gallery->get_entity(), FALSE);
                     $this->object->_add_script_data('ngg_common', 'galleries.gallery_' . $gallery->displayed_gallery->id() . '.wordpress_page_root', get_permalink(), FALSE);
                 }
             }
             $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);
     }
 }