/** * Gets all digital downloads for the pricelist * @param null $image_id * @return mixed */ function get_digital_downloads($image_id = NULL) { // Find digital download items $mapper = C_Pricelist_Item_Mapper::get_instance(); $conditions = array(array("pricelist_id = %d", $this->object->id()), array("source IN %s", array(NGG_PRO_DIGITAL_DOWNLOADS_SOURCE))); $items = $mapper->select()->where($conditions)->order_by('ID', 'ASC')->run_query(); // Filter by image resolutions if ($image_id) { $image = is_object($image_id) ? $image_id : C_Image_Mapper::get_instance()->find($image_id); if ($image) { $retval = array(); $storage = C_Gallery_Storage::get_instance(); foreach ($items as $item) { $source_width = $image->meta_data['width']; $source_height = $image->meta_data['height']; // the downloads themselves come from the backup as source so if possible only filter images // whose backup file doesn't have sufficient dimensions $backup_abspath = $storage->get_backup_abspath($image); if (@file_exists($backup_abspath)) { $dimensions = @getimagesize($backup_abspath); $source_width = $dimensions[0]; $source_height = $dimensions[1]; } if (isset($item->resolution) && $item->resolution >= 0 && ($source_height >= $item->resolution or $source_width >= $item->resolution)) { $retval[] = $item; } } $items = $retval; } } return $items; }
function protect_gallery($gallery, $force = false) { $retval = $this->object->is_gallery_protected($gallery); if ($force || !$retval) { $storage = C_Gallery_Storage::get_instance(); $gallery_path = $storage->get_gallery_abspath($gallery); if ($gallery_path != null && file_exists($gallery_path)) { $protector_files = $this->_get_protector_list(); foreach ($protector_files as $name => $protector) { $path = $protector['path']; $full_path = path_join($gallery_path, $path); $full = null; if (file_exists($full_path)) { $full = file_get_contents($full_path); $result = $this->_find_protector_content($full, $protector); if ($result != null) { $full = substr_replace($full, $protector['content'], $result['start'], $result['size']); } } else { $full = $protector['tag-start'] . $protector['content'] . $protector['tag-end']; } file_put_contents($full_path, $full); $retval = true; } } } return $retval; }
function add_image($image_id, $image_props) { // Get the items associated with the image $items = array(); if (is_array($image_props)) { unset($image_props['item_ids']); if (isset($image_props['items'])) { $items = $image_props['items']; } } else { unset($image_props->item_ids); if (isset($image_props->items)) { $items = $image_props->items; } } // Does the image exist? if ($image = C_Image_Mapper::get_instance()->find($image_id)) { $storage = C_Gallery_Storage::get_instance(); $image->thumbnail_url = $storage->get_thumbnail_url($image); $image->dimensions = $storage->get_thumbnail_dimensions($image); $image->width = $image->dimensions['width']; $image->height = $image->dimensions['height']; $this->_state[$image_id] = $image; foreach ($items as $item_id => $item_props) { if (is_numeric($item_id)) { $this->add_item($image_id, $item_id, $item_props); } } } }
function index_action() { $this->enqueue_static_resources(); $settings = C_NextGen_Settings::get_instance(); $retval = $settings->proofing_user_confirmation_not_found; if ($proof = C_NextGen_Pro_Proofing_Mapper::get_instance()->find_by_hash($this->param('proof'), TRUE)) { $image_mapper = C_Image_Mapper::get_instance(); $images = array(); foreach ($proof->proofed_gallery['image_list'] as $image_id) { $images[] = $image_mapper->find($image_id); } $message = $settings->proofing_user_confirmation_template; if (preg_match_all('/%%(\\w+)%%/', $settings->proofing_user_confirmation_template, $matches, PREG_SET_ORDER) > 0) { foreach ($matches as $match) { switch ($match[1]) { case 'user_name': $message = str_replace('%%user_name%%', $proof->customer_name, $message); break; case 'user_email': $message = str_replace('%%user_email%%', $proof->email, $message); break; case 'proof_link': $message = str_replace('%%proof_link%%', $proof->referer, $message); break; case 'proof_details': $imagehtml = $this->object->render_partial('photocrati-nextgen_pro_proofing#confirmation', array('images' => $images, 'storage' => C_Gallery_Storage::get_instance()), TRUE); $message = str_replace('%%proof_details%%', $imagehtml, $message); break; } } $retval = $message; } } return $retval; }
function index_action($displayed_gallery, $return = FALSE) { // The HTML id of the gallery $id = 'displayed_gallery_' . $displayed_gallery->id(); $image_size_name = 'full'; $display_settings = $displayed_gallery->display_settings; if ($display_settings['override_image_settings']) { $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $dyn_params = array(); if ($display_settings['image_quality']) { $dyn_params['quality'] = $display_settings['image_quality']; } if ($display_settings['image_crop']) { $dyn_params['crop'] = true; } if ($display_settings['image_watermark']) { $dyn_params['watermark'] = true; } $image_size_name = $dynthumbs->get_size_name($dyn_params); } $params = array('images' => $displayed_gallery->get_included_entities(), 'storage' => C_Gallery_Storage::get_instance(), 'effect_code' => $this->object->get_effect_code($displayed_gallery), 'id' => $id, 'image_size_name' => $image_size_name, 'image_display_size' => $displayed_gallery->display_settings['image_display_size'], 'border_size' => $displayed_gallery->display_settings['border_size']); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); // Render view/template return $this->render_view('photocrati-nextgen_pro_blog_gallery#nextgen_pro_blog', $params, $return); }
/** * 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); } }
function get_storage() { if (!$this->storage) { $this->storage = C_Gallery_Storage::get_instance(); } return $this->storage; }
/** * 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); } }
function index_action() { wp_dequeue_script('photocrati_ajax'); wp_dequeue_script('frame_event_publisher'); wp_dequeue_script('jquery'); wp_dequeue_style('nextgen_gallery_related_images'); $img_mapper = C_Image_Mapper::get_instance(); $image_id = $this->param('image_id'); if ($image = $img_mapper->find($image_id)) { $displayed_gallery_id = $this->param('displayed_gallery_id'); // Template parameters $params = array('img' => $image); // Get the url & dimensions $named_size = $this->param('named_size'); $storage = C_Gallery_Storage::get_instance(); $dimensions = $storage->get_image_dimensions($image, $named_size); $image->url = $storage->get_image_url($image, $named_size, TRUE); $image->width = $dimensions['width']; $image->height = $dimensions['height']; // Generate the lightbox url $router = $this->get_router(); $lightboxes = C_Lightbox_Library_Manager::get_instance(); $lightbox = $lightboxes->get(NGG_PRO_LIGHTBOX); $uri = urldecode($this->param('uri')); $lightbox_slug = $lightbox->values['nplModalSettings']['router_slug']; $qs = $this->get_querystring(); if ($qs) { $lightbox_url = $router->get_url('/', FALSE, 'root'); $lightbox_url .= "?" . $qs; } else { $lightbox_url = $router->get_url($uri, FALSE, 'root'); $lightbox_url .= '/'; } // widget galleries shouldn't have a url specific to one image if (FALSE !== strpos($displayed_gallery_id, 'widget-ngg-images-')) { $image_id = '!'; } $params['lightbox_url'] = "{$lightbox_url}#{$lightbox_slug}/{$displayed_gallery_id}/{$image_id}"; // Add the blog name $params['blog_name'] = get_bloginfo('name'); if ($lightbox->values['nplModalSettings']['enable_twitter_cards']) { $params['enable_twitter_cards'] = $lightbox->values['nplModalSettings']['enable_twitter_cards']; $params['twitter_username'] = $lightbox->values['nplModalSettings']['twitter_username']; } // Add routed url $protocol = $router->is_https() ? 'https://' : 'http://'; $params['routed_url'] = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Render the opengraph metadata $this->expires('+1 day'); $this->render_view("photocrati-nextgen_pro_lightbox#opengraph", $params); } else { header(__('Status: 404 Image not found', 'nextgen-gallery-pro')); echo __('Image not found', 'nextgen-gallery-pro'); } }
/** * 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}`)"); }
/** * Read an image file into memory and display it * * This is necessary for htaccess or server-side protection that blocks access to filenames ending with "_backup" * At the moment it only supports the backup or full size image. */ function get_image_file_action() { $order_id = $this->param('order_id', FALSE); $image_id = $this->param('image_id', FALSE); $bail = FALSE; if (!$order_id || !$image_id) { $bail = TRUE; } $order = C_Order_Mapper::get_instance()->find_by_hash($order_id); if (!in_array($image_id, $order->cart['image_ids'])) { $bail = TRUE; } if ($order->status != 'verified') { $bail = TRUE; } if ($bail) { header('HTTP/1.1 404 Not found'); exit; } $storage = C_Gallery_Storage::get_instance(); if (version_compare(NGG_PLUGIN_VERSION, '2.0.66.99') <= 0) { // Pre 2.0.67 didn't fallback to the original path if the backup file didn't exist $imagemapper = C_Image_Mapper::get_instance(); $fs = C_Fs::get_instance(); $image = $imagemapper->find($image_id); $gallery_path = $storage->get_gallery_abspath($image->galleryid); $abspath = $fs->join_paths($gallery_path, $image->filename . '_backup'); if (!@file_exists($abspath)) { $abspath = $storage->get_image_abspath($image_id, 'full'); } } else { $abspath = $storage->get_image_abspath($image_id, 'backup'); } $mimetype = 'application/octet'; if (function_exists('finfo_buffer')) { $finfo = new finfo(FILEINFO_MIME); $mimetype = @$finfo->file($abspath); } elseif (function_exists('mime_content_type')) { $mimetype = @mime_content_type($abspath); } header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . basename($storage->get_image_abspath($image_id, 'full'))); header("Content-type: " . $mimetype); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . @filesize($abspath)); readfile($abspath); exit; }
function upload_images() { $storage = C_Gallery_Storage::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); $gallery_mapper = C_Gallery_Mapper::get_instance(); // Get Gallery ID $galleryID = absint($_POST['galleryselect']); if (0 == $galleryID) { $galleryID = get_option('npu_default_gallery'); if (empty($galleryID)) { self::show_error(__('No gallery selected.', 'nextgen-public-uploader')); return; } } // Get the Gallery $gallery = $gallery_mapper->find($galleryID); if (!$gallery->path) { self::show_error(__('Failure in database, no gallery path set.', 'nextgen-public-uploader')); return; } // Read Image List foreach ($_FILES as $key => $value) { if (0 == $_FILES[$key]['error']) { try { if ($storage->is_image_file($_FILES[$key]['tmp_name'])) { $image = $storage->object->upload_base64_image($gallery, file_get_contents($_FILES[$key]['tmp_name']), $_FILES[$key]['name']); if (get_option('npu_exclude_select')) { $image->exclude = 1; $image_mapper->save($image); } // Add to Image and Dir List $this->arrImgNames[] = $image->filename; $this->arrImageIds[] = $image->id(); $this->strGalleryPath = $gallery->path; } else { unlink($_FILES[$key]['tmp_name']); $error_msg = sprintf(__('<strong>%s</strong> is not a valid file.', 'nextgen-public-uploader'), $_FILES[$key]['name']); self::show_error($error_msg); continue; } } catch (E_NggErrorException $ex) { self::show_error('<strong>' . $ex->getMessage() . '</strong>'); continue; } catch (Exception $ex) { self::show_error('<strong>' . $ex->getMessage() . '</strong>'); continue; } } } }
function index_action($displayed_gallery, $return = FALSE) { $id = $displayed_gallery->id(); $display_settings = $displayed_gallery->display_settings; $current_page = (int) $this->param('nggpage', $displayed_gallery->id(), 1); if (!isset($display_settings['images_per_page'])) { $display_settings['images_per_page'] = C_NextGen_Settings::get_instance()->images_per_page; } $offset = $display_settings['images_per_page'] * ($current_page - 1); $total = $displayed_gallery->get_entity_count(); $images = $displayed_gallery->get_included_entities($display_settings['images_per_page'], $offset); if (in_array($displayed_gallery->source, array('random', 'recent'))) { $display_settings['disable_pagination'] = TRUE; } if ($images) { if ($display_settings['images_per_page'] && !$display_settings['disable_pagination']) { $pagination_result = $this->object->create_pagination($current_page, $total, $display_settings['images_per_page']); } } $pagination = !empty($pagination_result['output']) ? $pagination_result['output'] : NULL; // Get named size of thumbnail images $thumbnail_size_name = 'thumbnail'; if ($display_settings['override_thumbnail_settings']) { $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $dyn_params = array('width' => $display_settings['thumbnail_width'], 'height' => $display_settings['thumbnail_height']); if ($display_settings['thumbnail_quality']) { $dyn_params['quality'] = $display_settings['thumbnail_quality']; } if ($display_settings['thumbnail_crop']) { $dyn_params['crop'] = true; } if ($display_settings['thumbnail_watermark']) { $dyn_params['watermark'] = true; } $thumbnail_size_name = $dynthumbs->get_size_name($dyn_params); } // Calculate image statistics $stats = $this->object->get_entity_statistics($images, $thumbnail_size_name, TRUE); $images = $stats['entities']; $display_settings['longest'] = $stats['longest']; $display_settings['widest'] = $stats['widest']; // Enqueue dynamic stylesheet $dyn_styles = C_Dynamic_Stylesheet_Controller::get_instance('all'); $dyn_styles->enqueue('nextgen_pro_film', $this->array_merge_assoc($display_settings, array('id' => $id))); $params = array('images' => $images, 'storage' => C_Gallery_Storage::get_instance(), 'thumbnail_size_name' => $thumbnail_size_name, 'effect_code' => $this->object->get_effect_code($displayed_gallery), 'id' => $id, 'pagination' => $pagination); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); // Render view/template return preg_replace('~>\\s*\\n\\s*<~', '><', $this->render_view('photocrati-nextgen_pro_film#nextgen_pro_film', $params, $return)); }
function index_action($displayed_gallery, $return = FALSE) { $storage = C_Gallery_Storage::get_instance(); $list = $displayed_gallery->get_included_entities(); $thumbnail_size_name = 'thumbnail'; $ds = $displayed_gallery->display_settings; if (!empty($ds['override_thumbnail_settings']) && $ds['override_thumbnail_settings']) { $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $dyn_params = array('width' => $ds['thumbnail_width'], 'height' => $ds['thumbnail_height'], 'crop' => true); $thumbnail_size_name = $dynthumbs->get_size_name($dyn_params); } $params = array('images' => $list, 'displayed_gallery_id' => $displayed_gallery->id(), 'storage' => $storage, 'custom_css_rules' => $this->object->get_custom_css_rules($displayed_gallery), 'thumbnail_size_name' => $thumbnail_size_name); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_view('photocrati-galleria#galleria', $params, $return); }
/** * Renders the front-end display for the masonry display type * * @param C_Displayed_Gallery $displayed_gallery * @param bool $return * @return string */ function index_action($displayed_gallery, $return = FALSE) { $images = $displayed_gallery->get_included_entities(); if (!$images) { return $this->object->render_partial("photocrati-nextgen_gallery_display#no_images_found", array(), $return); } else { $params = $displayed_gallery->display_settings; $params['images'] = $images; $params['storage'] = C_Gallery_Storage::get_instance(); $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['displayed_gallery_id'] = $displayed_gallery->id(); $params['thumbnail_size_name'] = C_Dynamic_Thumbnails_Manager::get_instance()->get_size_name(array('width' => $params['size'], 'crop' => FALSE)); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); return $this->object->render_view('photocrati-nextgen_pro_masonry#index', $params, $return); } }
/** * Parse the gallery/imagebrowser/slideshow shortcode and return all images into an array * * @param string $atts * @return */ function add_gallery($atts) { global $wpdb; extract(shortcode_atts(array('id' => 0), $atts)); $gallery_mapper = C_Gallery_Mapper::get_instance(); if (!is_numeric($id)) { if ($gallery = array_shift($gallery_mapper->select()->where(array('name = %s', $id))->limit(1)->run_query())) { $id = $gallery->{$gallery->id_field}; } else { $id = NULL; } } if ($id) { $gallery_storage = C_Gallery_Storage::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); foreach ($image_mapper->find_all_for_gallery($id) as $image) { $this->images[] = array('src' => $gallery_storage->get_image_url($image), 'title' => $image->title, 'alt' => $image->alttext); } } return ''; }
/** * Import an image from the filesystem into NextGen * * @synopsis --filename=<absolute-path> --gallery=<gallery-id> */ function import_image($args, $assoc_args) { $mapper = C_Gallery_Mapper::get_instance(); $storage = C_Gallery_Storage::get_instance(); if ($gallery = $mapper->find($assoc_args['gallery'], TRUE)) { $file_data = @file_get_contents($assoc_args['filename']); $file_name = M_I18n::mb_basename($assoc_args['filename']); if (empty($file_data)) { WP_CLI::error('Could not load file'); } $image = $storage->upload_base64_image($gallery, $file_data, $file_name); $image_id = $image->{$image->id_field}; if (!$image) { WP_CLI::error('Could not import image'); } else { WP_CLI::success("Imported image with id #{$image_id}"); } } else { WP_CLI::error("Gallery not found (with id #{$assoc_args['gallery']}"); } }
function index_action($displayed_gallery, $return = FALSE) { // The HTML id of the gallery $id = 'displayed_gallery_' . $displayed_gallery->id(); // Get named size of thumbnail images $thumbnail_size_name = 'thumbnail'; $display_settings = $displayed_gallery->display_settings; if ($display_settings['override_thumbnail_settings']) { $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $dyn_params = array('width' => $display_settings['thumbnail_width'], 'height' => $display_settings['thumbnail_height']); if ($display_settings['thumbnail_quality']) { $dyn_params['quality'] = $display_settings['thumbnail_quality']; } if ($display_settings['thumbnail_crop']) { $dyn_params['crop'] = true; } if ($display_settings['thumbnail_watermark']) { $dyn_params['watermark'] = true; } $thumbnail_size_name = $dynthumbs->get_size_name($dyn_params); } $current_page = (int) $this->param('nggpage', $displayed_gallery->id(), 1); $offset = $display_settings['images_per_page'] * ($current_page - 1); $total = $displayed_gallery->get_entity_count(); $images = $displayed_gallery->get_included_entities($display_settings['images_per_page'], $offset); if (in_array($displayed_gallery->source, array('random', 'recent'))) { $display_settings['disable_pagination'] = TRUE; } if ($images) { if ($display_settings['images_per_page'] && !$display_settings['disable_pagination']) { $pagination_result = $this->object->create_pagination($current_page, $total, $display_settings['images_per_page']); } } $pagination = !empty($pagination_result['output']) ? $pagination_result['output'] : NULL; $params = array('images' => $images, 'storage' => C_Gallery_Storage::get_instance(), 'thumbnail_size_name' => $thumbnail_size_name, 'effect_code' => $this->object->get_effect_code($displayed_gallery), 'id' => $id, 'pagination' => $pagination); $params = $this->object->prepare_display_parameters($displayed_gallery, $params); // Render view/template. We remove whitespace from between HTML elements lest the browser think we want // a space character ( ) between each image-causing columns to appear between images return preg_replace('~>\\s*\\n\\s*<~', '><', $this->render_view('photocrati-nextgen_pro_thumbnail_grid#nextgen_pro_thumbnail_grid', $params, $return)); }
function _prepare_entities($displayed_gallery, $thumbnail_size_name) { $current_url = $this->object->get_routed_url(TRUE); $storage = C_Gallery_Storage::get_instance(); $mapper = C_Image_Mapper::get_instance(); $entities = $displayed_gallery->get_included_entities(); foreach ($entities as &$entity) { $entity_type = intval($entity->is_gallery) ? 'gallery' : 'album'; // Is the gallery actually a link to a page? Stupid feature... if (isset($entity->pageid) && $entity->pageid > 0) { $entity->link = get_page_link($entity->pageid); } else { $page_url = $current_url; if (intval($entity->is_gallery) && !$this->param('album')) { $page_url = $this->object->set_param_for($page_url, 'album', 'galleries'); } $entity->link = $this->object->set_param_for($page_url, $entity_type, $entity->slug); } $preview_img = $mapper->find($entity->previewpic); $entity->thumb_size = $storage->get_image_dimensions($preview_img, $thumbnail_size_name); $entity->url = $storage->get_image_url($preview_img, $thumbnail_size_name, TRUE); } return $entities; }
/** * Sets the post thumbnail for a post to a NextGEN Gallery image * @param $args (blog_id, username, password, post_id, image_id) * * @return IXR_Error|int attachment id */ function set_post_thumbnail($args) { $retval = new IXR_Error(403, 'Invalid username or password'); $blog_id = intval($args[0]); $username = strval($args[1]); $password = strval($args[2]); $post_ID = intval($args[3]); $image_id = intval($args[4]); // Authenticate the user if ($this->_login($username, $password, $blog_id)) { if (current_user_can('edit_post', $post_ID)) { $retval = C_Gallery_Storage::get_instance()->set_post_thumbnail($post_ID, $image_id); } else { $retval = new IXR_Error(403, "Sorry but you need permission to do this"); } } return $retval; }
} else { //Initialize stats array $stats = array("stats" => array_merge($WpSmush->_get_size_signature(), array('api_version' => -1, 'lossy' => -1, 'keep_exif' => false)), 'sizes' => array()); $stats['bytes'] = $response['data']->bytes_saved; $stats['percent'] = $response['data']->compression; $stats['size_after'] = $response['data']->after_size; $stats['size_before'] = $response['data']->before_size; $stats['time'] = $response['data']->time; } $stats['sizes'][$size] = (object) $WpSmush->_array_fill_placeholders($WpSmush->_get_size_signature(), (array) $response['data']); if (isset($image->metadata)) { $image->meta_data['wp_smush'] = $stats; nggdb::update_image_meta($image->pid, $image->meta_data); } //Allows To get the stats for each image, after the image is smushed do_action('wp_smush_nextgen_image_stats', $image_id, $stats); } } } return $success; } } } } if (class_exists('WpSmushNextGenDynamicThumbs')) { if (!get_option('ngg_options')) { return; } $storage = C_Gallery_Storage::get_instance(); $storage->get_wrapped_instance()->add_mixin('WpSmushNextGenDynamicThumbs'); }
public function prepare_legacy_album_params($displayed_gallery, $params) { $image_mapper = C_Image_Mapper::get_instance(); $storage = C_Gallery_Storage::get_instance(); $image_gen = C_Dynamic_Thumbnails_Manager::get_instance(); if (empty($displayed_gallery->display_settings['override_thumbnail_settings'])) { // legacy templates expect these dimensions $image_gen_params = array('width' => 91, 'height' => 68, 'crop' => TRUE); } else { // use settings requested by user $image_gen_params = array('width' => $displayed_gallery->display_settings['thumbnail_width'], 'height' => $displayed_gallery->display_settings['thumbnail_height'], 'quality' => isset($displayed_gallery->display_settings['thumbnail_quality']) ? $displayed_gallery->display_settings['thumbnail_quality'] : 100, 'crop' => isset($displayed_gallery->display_settings['thumbnail_crop']) ? $displayed_gallery->display_settings['thumbnail_crop'] : NULL, 'watermark' => isset($displayed_gallery->display_settings['thumbnail_watermark']) ? $displayed_gallery->display_settings['thumbnail_watermark'] : NULL); } // so user templates can know how big the images are expected to be $params['image_gen_params'] = $image_gen_params; // Transform entities $params['galleries'] = $params['entities']; unset($params['entities']); foreach ($params['galleries'] as &$gallery) { // Get the preview image url $gallery->previewurl = ''; if ($gallery->previewpic && $gallery->previewpic > 0) { if ($image = $image_mapper->find(intval($gallery->previewpic))) { $gallery->previewurl = $storage->get_image_url($image, $image_gen->get_size_name($image_gen_params), TRUE); $gallery->previewname = $gallery->name; } } // Get the page link. If the entity is an album, then the url will // look like /nggallery/album--slug. $id_field = $gallery->id_field; if ($gallery->is_album) { if ($gallery->pageid > 0) { $gallery->pagelink = @get_page_link($gallery->pageid); } else { $gallery->pagelink = $this->object->set_param_for($this->object->get_routed_url(TRUE), 'album', $gallery->slug); } } else { if ($gallery->pageid > 0) { $gallery->pagelink = @get_page_link($gallery->pageid); } if (empty($gallery->pagelink)) { $pagelink = $this->object->get_routed_url(TRUE); $parent_album = $this->object->get_parent_album_for($gallery->{$id_field}); if ($parent_album) { $pagelink = $this->object->set_param_for($pagelink, 'album', $parent_album->slug); } else { if ($displayed_gallery->container_ids === array('0') || $displayed_gallery->container_ids === array('')) { $pagelink = $this->object->set_param_for($pagelink, 'album', 'all'); } else { $pagelink = $this->object->set_param_for($pagelink, 'album', 'album'); } } $gallery->pagelink = $this->object->set_param_for($pagelink, 'gallery', $gallery->slug); } } // Let plugins modify the gallery $gallery = apply_filters('ngg_album_galleryobject', $gallery); } $params['album'] = reset($this->albums); $params['albums'] = $this->albums; // Clean up unset($storage); unset($image_mapper); unset($image_gen); unset($image_gen_params); return $params; }
static function parse_entities_for_galleria($entities = array()) { $retval = array(); if (!empty($entities)) { $storage = C_Gallery_Storage::get_instance(); foreach ($entities as $entity) { if (isset($entity->is_gallery) && !$entity->is_gallery) { continue; } if (isset($entity->is_album) && !$entity->is_album) { continue; } $retval[] = array('image' => $storage->get_image_url($entity), 'title' => $entity->alttext, 'description' => $entity->description, 'image_id' => $entity->{$entity->id_field}, 'thumb' => $storage->get_image_url($entity, 'thumb')); } } return apply_filters('ngg_pro_lightbox_images_queue', $retval); }
/** * nggPostThumbnail::ajax_set_post_thumbnail() * * @return void */ function ajax_set_post_thumbnail() { // This function does the following: // 1) Check if the user is logged in and has permission to edit the post // 2) Get the thumbnail id from the POST request. The thumbnail id is actually the NGG image id // 3)] global $post_ID; // check for correct capability if (!is_user_logged_in()) { die('-1'); } // get the post id as global variable, otherwise the ajax_nonce failed later $post_ID = intval($_POST['post_id']); if (!current_user_can('edit_post', $post_ID)) { die('-1'); } $thumbnail_id = intval($_POST['thumbnail_id']); // delete the image if ($thumbnail_id == '-1') { delete_post_meta($post_ID, '_thumbnail_id'); die('0'); } die(strval(C_Gallery_Storage::get_instance()->set_post_thumbnail($post_ID, $thumbnail_id))); }
function nggallery_picturelist($controller) { // *** show picture list global $wpdb, $nggdb, $user_ID, $ngg; // Look if its a search result $is_search = isset($_GET['s']) ? true : false; $counter = 0; $wp_list_table = new _NGG_Images_List_Table('nggallery-manage-images'); if ($is_search) { // fetch the imagelist $picturelist = $ngg->manage_page->search_result; // we didn't set a gallery or a pagination $act_gid = 0; $_GET['paged'] = 1; $page_links = false; } else { // GET variables $act_gid = $ngg->manage_page->gid; // Load the gallery metadata $mapper = C_Gallery_Mapper::get_instance(); $gallery = $mapper->find($act_gid); if (!$gallery) { nggGallery::show_error(__('Gallery not found.', 'nggallery')); return; } // Check if you have the correct capability if (!nggAdmin::can_manage_this_gallery($gallery->author)) { nggGallery::show_error(__('Sorry, you have no access here', 'nggallery')); return; } // look for pagination $_GET['paged'] = isset($_GET['paged']) && $_GET['paged'] > 0 ? absint($_GET['paged']) : 1; $items_per_page = 50; $start = ($_GET['paged'] - 1) * $items_per_page; // get picture values $image_mapper = C_Image_Mapper::get_instance(); $total_number_of_images = count($image_mapper->select($image_mapper->get_primary_key_column())->where(array("galleryid = %d", $act_gid))->run_query(FALSE, TRUE)); $picturelist = $image_mapper->select()->where(array("galleryid = %d", $act_gid))->order_by($ngg->options['galSort'], $ngg->options['galSortDir'])->limit($items_per_page, $start)->run_query(); // get the current author $act_author_user = get_userdata((int) $gallery->author); } // list all galleries $gallerylist = $nggdb->find_all_galleries(); //get the columns $image_columns = $wp_list_table->get_columns(); $hidden_columns = get_hidden_columns('nggallery-manage-images'); $num_columns = count($image_columns) - count($hidden_columns); $attr = nggGallery::current_user_can('NextGEN Edit gallery options') ? '' : 'disabled="disabled"'; ?> <script type="text/javascript"> <!-- function showDialog( windowId, title ) { var form = document.getElementById('updategallery'); var elementlist = ""; for (i = 0, n = form.elements.length; i < n; i++) { if(form.elements[i].type == "checkbox") { if(form.elements[i].name == "doaction[]") if(form.elements[i].checked == true) if (elementlist == "") elementlist = form.elements[i].value; else elementlist += "," + form.elements[i].value ; } } jQuery("#" + windowId + "_bulkaction").val(jQuery("#bulkaction").val()); jQuery("#" + windowId + "_imagelist").val(elementlist); // now show the dialog jQuery( "#" + windowId ).dialog({ width: 640, resizable : false, modal: true, title: title, position: { my: 'center', at: 'center', of: window.parent } }); jQuery("#" + windowId + ' .dialog-cancel').click(function() { jQuery( "#" + windowId ).dialog("close"); }); } jQuery(function (){ jQuery('span.tooltip, label.tooltip').tooltip(); // load a content via ajax jQuery('a.ngg-dialog').click(function() { var dialogs = jQuery('.ngg-overlay-dialog:visible'); if (dialogs.size() > 0) { return false; } if ( jQuery( "#spinner" ).length == 0) { jQuery("body").append('<div id="spinner"></div>'); } var $this = jQuery(this); var results = new RegExp('[\\?&]w=([^&#]*)').exec(this.href); var width = ( results ) ? results[1] : 600; var results = new RegExp('[\\?&]h=([^&#]*)').exec(this.href); var height = ( results ) ? results[1] : 440; var container = window; if (window.parent) { container = window.parent; } jQuery('#spinner').fadeIn(); jQuery('#spinner').position({ my: "center", at: "center", of: container }); var dialog = jQuery('<div class="ngg-overlay-dialog" style="display:hidden"></div>').appendTo('body'); // load the remote content dialog.load( this.href, {}, function () { jQuery('#spinner').hide(); dialog.dialog({ title: ($this.attr('title')) ? $this.attr('title') : '', position: { my: "center", at: "center", of: container }, width: width, height: height, modal: true, resizable: false, close: function() { dialog.remove(); } }).width(width - 30).height(height - 30); } ); //prevent the browser to follow the link return false; }); }); function checkAll(form) { for (i = 0, n = form.elements.length; i < n; i++) { if(form.elements[i].type == "checkbox") { if(form.elements[i].name == "doaction[]") { if(form.elements[i].checked == true) form.elements[i].checked = false; else form.elements[i].checked = true; } } } } function getNumChecked(form) { var num = 0; for (i = 0, n = form.elements.length; i < n; i++) { if(form.elements[i].type == "checkbox") { if(form.elements[i].name == "doaction[]") if(form.elements[i].checked == true) num++; } } return num; } // this function check for a the number of selected images, sumbmit false when no one selected function checkSelected() { var numchecked = getNumChecked(document.getElementById('updategallery')); if (typeof document.activeElement == "undefined" && document.addEventListener) { document.addEventListener("focus", function (e) { document.activeElement = e.target; }, true); } if ( document.activeElement.name == 'post_paged' ) return true; if(numchecked < 1) { alert('<?php echo esc_js(__('No images selected', 'nggallery')); ?> '); return false; } actionId = jQuery('#bulkaction').val(); switch (actionId) { case "copy_to": showDialog('selectgallery', '<?php echo esc_js(__('Copy image to...', 'nggallery')); ?> '); return false; break; case "move_to": showDialog('selectgallery', '<?php echo esc_js(__('Move image to...', 'nggallery')); ?> '); return false; break; case "add_tags": showDialog('entertags', '<?php echo esc_js(__('Add new tags', 'nggallery')); ?> '); return false; break; case "delete_tags": showDialog('entertags', '<?php echo esc_js(__('Delete tags', 'nggallery')); ?> '); return false; break; case "overwrite_tags": showDialog('entertags', '<?php echo esc_js(__('Overwrite', 'nggallery')); ?> '); return false; break; case "resize_images": showDialog('resize_images', '<?php echo esc_js(__('Resize images', 'nggallery')); ?> '); return false; break; case "new_thumbnail": showDialog('new_thumbnail', '<?php echo esc_js(__('Create new thumbnails', 'nggallery')); ?> '); return false; break; } return confirm('<?php echo sprintf(esc_js(__("You are about to start the bulk edit for %s images \n \n 'Cancel' to stop, 'OK' to proceed.", 'nggallery')), "' + numchecked + '"); ?> '); } jQuery(document).ready( function($) { if ($(this).data('ready')) return; // close postboxes that should be closed jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed'); postboxes.add_postbox_toggles('ngg-manage-gallery'); jQuery('.iedit').mouseover( function(e){ jQuery(this).parent().find('.row-actions').css('visibility', 'hidden'); jQuery(this).next('.row_actions:first').find('.row-actions:first').css('visibility', 'visible'); } ); $(this).data('ready', true); }); //--> </script> <div class="wrap"> <?php //include('templates/social_media_buttons.php'); screen_icon('nextgen-gallery'); if ($is_search) { ?> <h2><?php printf(__('Search results for “%s”', 'nggallery'), esc_html(get_search_query())); ?> </h2> <form class="search-form" action="" method="get"> <p class="search-box"> <label class="hidden" for="media-search-input"><?php _e('Search Images', 'nggallery'); ?> :</label> <input type="hidden" id="page-name" name="page" value="nggallery-manage-gallery" /> <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?> " /> <input type="submit" value="<?php _e('Search Images', 'nggallery'); ?> " class="button" /> </p> </form> <br style="clear: both;" /> <form id="updategallery" class="nggform" method="POST" action="<?php echo $ngg->manage_page->base_page . '&mode=edit&s=' . get_search_query(); ?> " accept-charset="utf-8"> <?php wp_nonce_field('ngg_updategallery'); ?> <input type="hidden" name="page" value="manage-images" /> <?php } else { ?> <h2><?php echo _n('Gallery', 'Galleries', 1, 'nggallery'); ?> : <?php echo esc_html(nggGallery::i18n($gallery->title)); ?> </h2> <br style="clear: both;" /> <form id="updategallery" class="nggform" method="POST" action="<?php echo $ngg->manage_page->base_page . '&mode=edit&gid=' . $act_gid . '&paged=' . esc_attr($_GET['paged']); ?> " accept-charset="utf-8"> <?php wp_nonce_field('ngg_updategallery'); ?> <input type="hidden" name="page" value="manage-images" /> <?php if (nggGallery::current_user_can('NextGEN Edit gallery options')) { ?> <div id="poststuff"> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> <div id="gallerydiv" class="postbox <?php echo postbox_classes('gallerydiv', 'ngg-manage-gallery'); ?> " > <h3><?php _e('Gallery settings', 'nggallery'); ?> <small> (<?php _e('Click here for more settings', 'nggallery'); ?> )</small></h3> <div class="inside"> <?php $controller->render_gallery_fields(); ?> <div class="submit"> <?php if (wpmu_enable_function('wpmuImportFolder') && nggGallery::current_user_can('NextGEN Import image folder')) { ?> <input type="submit" class="button-secondary" name="scanfolder" value="<?php _e("Scan Folder for new images", 'nggallery'); ?> " /> <?php } ?> <input type="submit" class="button-primary action" name="updatepictures" value="<?php _e("Save Changes", 'nggallery'); ?> " /> </div> </div> </div> </div> <!-- poststuff --> <?php } ?> <?php } ?> <div class="tablenav top ngg-tablenav"> <?php $ngg->manage_page->pagination('top', $_GET['paged'], $total_number_of_images, $items_per_page); ?> <div class="alignleft actions"> <select id="bulkaction" name="bulkaction"> <option value="no_action" ><?php _e("Bulk actions", 'nggallery'); ?> </option> <option value="set_watermark" ><?php _e("Set watermark", 'nggallery'); ?> </option> <option value="new_thumbnail" ><?php _e("Create new thumbnails", 'nggallery'); ?> </option> <option value="resize_images" ><?php _e("Resize images", 'nggallery'); ?> </option> <option value="recover_images" ><?php _e("Recover from backup", 'nggallery'); ?> </option> <option value="delete_images" ><?php _e("Delete images", 'nggallery'); ?> </option> <option value="import_meta" ><?php _e("Import metadata", 'nggallery'); ?> </option> <option value="rotate_cw" ><?php _e("Rotate images clockwise", 'nggallery'); ?> </option> <option value="rotate_ccw" ><?php _e("Rotate images counter-clockwise", 'nggallery'); ?> </option> <option value="copy_to" ><?php _e("Copy to...", 'nggallery'); ?> </option> <option value="move_to"><?php _e("Move to...", 'nggallery'); ?> </option> <option value="add_tags" ><?php _e("Add tags", 'nggallery'); ?> </option> <option value="delete_tags" ><?php _e("Delete tags", 'nggallery'); ?> </option> <option value="overwrite_tags" ><?php _e("Overwrite tags", 'nggallery'); ?> </option> </select> <input class="button-secondary" type="submit" name="showThickbox" value="<?php _e('Apply', 'nggallery'); ?> " onclick="if ( !checkSelected() ) return false;" /> <?php if ($ngg->options['galSort'] == "sortorder" && !$is_search) { ?> <input class="button-secondary" type="submit" name="sortGallery" value="<?php _e('Sort gallery', 'nggallery'); ?> " /> <?php } ?> <input type="submit" name="updatepictures" class="button-primary action" value="<?php _e('Save Changes', 'nggallery'); ?> " /> </div> </div> <table id="ngg-listimages" class="widefat fixed" cellspacing="0" > <thead> <?php $controller->render_image_row_header(); ?> </thead> <tfoot> <?php $controller->render_image_row_header(); ?> </tfoot> <tbody id="the-list"> <?php if ($picturelist) { $thumbsize = ''; $storage = C_Gallery_Storage::get_instance(); if ($ngg->options['thumbfix']) { $thumbsize = 'width="' . $ngg->options['thumbwidth'] . '" height="' . $ngg->options['thumbheight'] . '"'; } foreach ($picturelist as $picture) { //for search result we need to check the capatibiliy if (!nggAdmin::can_manage_this_gallery($gallery->author) && $is_search) { continue; } $counter++; $picture->imageURL = $storage->get_image_url($picture); $picture->thumbURL = $storage->get_thumb_url($picture); $picture->imagePath = $storage->get_image_abspath($picture); $picture->thumbPath = $storage->get_thumb_abspath($picture); echo apply_filters('ngg_manage_images_row', $picture, $counter); } } // In the case you have no capaptibility to see the search result if ($counter == 0) { echo '<tr><td colspan="' . $num_columns . '" align="center"><strong>' . __('No entries found', 'nggallery') . '</strong></td></tr>'; } ?> </tbody> </table> <div class="tablenav bottom"> <input type="submit" class="button-primary action" name="updatepictures" value="<?php _e('Save Changes', 'nggallery'); ?> " /> <?php $ngg->manage_page->pagination('bottom', $_GET['paged'], $total_number_of_images, $items_per_page); ?> </div> </form> <br class="clear"/> </div><!-- /#wrap --> <!-- #entertags --> <div id="entertags" style="display: none;" > <form id="form-tags" method="POST" accept-charset="utf-8"> <?php wp_nonce_field('ngg_thickbox_form'); ?> <input type="hidden" id="entertags_imagelist" name="TB_imagelist" value="" /> <input type="hidden" id="entertags_bulkaction" name="TB_bulkaction" value="" /> <input type="hidden" name="page" value="manage-images" /> <table width="100%" border="0" cellspacing="3" cellpadding="3" > <tr> <th><?php _e("Enter the tags", 'nggallery'); ?> : <input name="taglist" type="text" style="width:90%" value="" /></th> </tr> <tr align="right"> <td class="submit"> <input class="button-primary" type="submit" name="TB_EditTags" value="<?php _e("OK", 'nggallery'); ?> " /> <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e("Cancel", 'nggallery'); ?> " /> </td> </tr> </table> </form> </div> <!-- /#entertags --> <!-- #selectgallery --> <div id="selectgallery" style="display: none;" > <form id="form-select-gallery" method="POST" accept-charset="utf-8"> <?php wp_nonce_field('ngg_thickbox_form'); ?> <input type="hidden" id="selectgallery_imagelist" name="TB_imagelist" value="" /> <input type="hidden" id="selectgallery_bulkaction" name="TB_bulkaction" value="" /> <input type="hidden" name="page" value="manage-images" /> <table width="100%" border="0" cellspacing="3" cellpadding="3" > <tr> <th> <?php _e('Select the destination gallery:', 'nggallery'); ?> <select name="dest_gid" style="width:90%" > <?php foreach ($gallerylist as $gallery) { if ($gallery->gid != $act_gid) { ?> <option value="<?php echo $gallery->gid; ?> " ><?php echo $gallery->gid; ?> - <?php echo esc_attr(stripslashes($gallery->title)); ?> </option> <?php } } ?> </select> </th> </tr> <tr align="right"> <td class="submit"> <input type="submit" class="button-primary" name="TB_SelectGallery" value="<?php _e("OK", 'nggallery'); ?> " /> <input class="button-secondary dialog-cancel" type="reset" value="<?php _e("Cancel", 'nggallery'); ?> " /> </td> </tr> </table> </form> </div> <!-- /#selectgallery --> <!-- #resize_images --> <div id="resize_images" style="display: none;" > <form id="form-resize-images" method="POST" accept-charset="utf-8"> <?php wp_nonce_field('ngg_thickbox_form'); ?> <input type="hidden" id="resize_images_imagelist" name="TB_imagelist" value="" /> <input type="hidden" id="resize_images_bulkaction" name="TB_bulkaction" value="" /> <input type="hidden" name="page" value="manage-images" /> <table width="100%" border="0" cellspacing="3" cellpadding="3" > <tr valign="top"> <td> <strong><?php _e('Resize Images to', 'nggallery'); ?> :</strong> </td> <td> <input type="text" size="5" name="imgWidth" value="<?php echo $ngg->options['imgWidth']; ?> " /> x <input type="text" size="5" name="imgHeight" value="<?php echo $ngg->options['imgHeight']; ?> " /> <br /><small><?php _e('Width x height (in pixel). NextGEN Gallery will keep ratio size', 'nggallery'); ?> </small> </td> </tr> <tr align="right"> <td colspan="2" class="submit"> <input class="button-primary" type="submit" name="TB_ResizeImages" value="<?php _e('OK', 'nggallery'); ?> " /> <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e('Cancel', 'nggallery'); ?> " /> </td> </tr> </table> </form> </div> <!-- /#resize_images --> <!-- #new_thumbnail --> <div id="new_thumbnail" style="display: none;" > <form id="form-new-thumbnail" method="POST" accept-charset="utf-8"> <?php wp_nonce_field('ngg_thickbox_form'); ?> <input type="hidden" id="new_thumbnail_imagelist" name="TB_imagelist" value="" /> <input type="hidden" id="new_thumbnail_bulkaction" name="TB_bulkaction" value="" /> <input type="hidden" name="page" value="manage-images" /> <table width="100%" border="0" cellspacing="3" cellpadding="3" > <tr valign="top"> <th align="left"><?php _e('Width x height (in pixel)', 'nggallery'); ?> </th> <td> <?php include dirname(__FILE__) . '/thumbnails-template.php'; ?> </td> </tr> <tr valign="top"> <th align="left"><?php _e('Set fix dimension', 'nggallery'); ?> </th> <td><input type="checkbox" name="thumbfix" value="1" <?php checked('1', $ngg->options['thumbfix']); ?> /> <br /><small><?php _e('Ignore the aspect ratio, no portrait thumbnails', 'nggallery'); ?> </small></td> </tr> <tr align="right"> <td colspan="2" class="submit"> <input class="button-primary" type="submit" name="TB_NewThumbnail" value="<?php _e('OK', 'nggallery'); ?> " /> <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e('Cancel', 'nggallery'); ?> " /> </td> </tr> </table> </form> </div> <!-- /#new_thumbnail --> <script type="text/javascript"> /* <![CDATA[ */ jQuery(document).ready(function(){columns.init('nggallery-manage-images');}); /* ]]> */ </script> <?php }
/** * nggAdmin::import_gallery() * TODO: Check permission of existing thumb folder & images * * @class nggAdmin * @param string $galleryfolder contains relative path to the gallery itself * @return void */ static function import_gallery($galleryfolder, $gallery_id = NULL) { global $wpdb, $user_ID; // get the current user ID wp_get_current_user(); $created_msg = ''; // remove trailing slash at the end, if somebody use it $galleryfolder = untrailingslashit($galleryfolder); $fs = C_Fs::get_instance(); if (is_null($gallery_id)) { $gallerypath = $fs->join_paths($fs->get_document_root('content'), $galleryfolder); } else { $storage = C_Gallery_Storage::get_instance(); $gallerypath = $storage->get_gallery_abspath($gallery_id); } if (!is_dir($gallerypath)) { nggGallery::show_error(sprintf(__("Directory <strong>%s</strong> doesn`t exist!", 'nggallery'), esc_html($gallerypath))); return; } // read list of images $new_imageslist = nggAdmin::scandir($gallerypath); if (empty($new_imageslist)) { nggGallery::show_message(sprintf(__("Directory <strong>%s</strong> contains no pictures", 'nggallery'), esc_html($gallerypath))); return; } // take folder name as gallery name $galleryname = basename($galleryfolder); $galleryname = apply_filters('ngg_gallery_name', $galleryname); // check for existing gallery folder if (is_null($gallery_id)) { $gallery_id = $wpdb->get_var("SELECT gid FROM {$wpdb->nggallery} WHERE path = '{$galleryfolder}' "); } if (!$gallery_id) { // now add the gallery to the database $gallery_id = nggdb::add_gallery($galleryname, $galleryfolder, '', 0, 0, $user_ID); if (!$gallery_id) { nggGallery::show_error(__('Database error. Could not add gallery!', 'nggallery')); return; } else { do_action('ngg_created_new_gallery', $gallery_id); } $created_msg = sprintf(_n("Gallery <strong>%s</strong> successfully created!", 'Galleries <strong>%s</strong> successfully created!', 1, 'nggallery'), esc_html($galleryname)); } // Look for existing image list $old_imageslist = $wpdb->get_col("SELECT filename FROM {$wpdb->nggpictures} WHERE galleryid = '{$gallery_id}' "); // if no images are there, create empty array if ($old_imageslist == NULL) { $old_imageslist = array(); } // check difference $new_images = array_diff($new_imageslist, $old_imageslist); // all images must be valid files foreach ($new_images as $key => $picture) { // filter function to rename/change/modify image before $picture = apply_filters('ngg_pre_add_new_image', $picture, $gallery_id); $new_images[$key] = $picture; if (!@getimagesize($gallerypath . '/' . $picture)) { unset($new_images[$key]); @unlink($gallerypath . '/' . $picture); } } // add images to database $image_ids = nggAdmin::add_Images($gallery_id, $new_images); do_action('ngg_after_new_images_added', $gallery_id, $image_ids); //add the preview image if needed nggAdmin::set_gallery_preview($gallery_id); // now create thumbnails nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery')); //TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX $message = $created_msg . sprintf(_n('%s picture successfully added', '%s pictures successfully added', count($image_ids), 'nggallery'), count($image_ids)); $message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $gallery_id . '" >'; $message .= __('Edit gallery', 'nggallery'); $message .= '</a>]'; nggGallery::show_message($message); return; }
public function import_media_library_action() { $retval = array(); $created_gallery = FALSE; $gallery_id = intval($this->param('gallery_id')); $gallery_name = urldecode($this->param('gallery_name')); $gallery_mapper = C_Gallery_Mapper::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); $attachment_ids = $this->param('attachment_ids'); if ($this->validate_ajax_request('nextgen_upload_image', TRUE)) { if (empty($attachment_ids) || !is_array($attachment_ids)) { $retval['error'] = __('An unexpected error occured.', 'nggallery'); } if (empty($retval['error']) && $gallery_id == 0) { if (strlen($gallery_name) > 0) { $gallery = $gallery_mapper->create(array('title' => $gallery_name)); if (!$gallery->save()) { $retval['error'] = $gallery->get_errors(); } else { $created_gallery = TRUE; $gallery_id = $gallery->id(); } } else { $retval['error'] = __('No gallery name specified', 'nggallery'); } } if (empty($retval['error'])) { $retval['gallery_id'] = $gallery_id; $storage = C_Gallery_Storage::get_instance(); foreach ($attachment_ids as $id) { try { $abspath = get_attached_file($id); $file_data = @file_get_contents($abspath); $file_name = M_I18n::mb_basename($abspath); $attachment = get_post($id); if (empty($file_data)) { $retval['error'] = __('Image generation failed', 'nggallery'); break; } $image = $storage->upload_base64_image($gallery_id, $file_data, $file_name); if ($image) { // Potentially import metadata from WordPress $image = $image_mapper->find($image->id()); if (!empty($attachment->post_excerpt)) { $image->alttext = $attachment->post_excerpt; } if (!empty($attachment->post_content)) { $image->description = $attachment->post_content; } $image = apply_filters('ngg_medialibrary_imported_image', $image, $attachment); $image_mapper->save($image); } else { $retval['error'] = __('Image generation failed', 'nggallery'); break; } $retval['image_ids'][] = $image->{$image->id_field}; } catch (E_NggErrorException $ex) { $retval['error'] = $ex->getMessage(); if ($created_gallery) { $gallery_mapper->destroy($gallery_id); } } catch (Exception $ex) { $retval['error'] = __('An unexpected error occured.', 'nggallery'); $retval['error_details'] = $ex->getMessage(); } } } } else { $retval['error'] = __('No permissions to upload images. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.', 'nggallery'); } if (!empty($retval['error'])) { return $retval; } else { $retval['gallery_name'] = esc_html($gallery_name); } return $retval; }
function post_processor_images() { global $wpdb, $ngg, $nggdb; // bulk update in a single gallery if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) { check_admin_referer('ngg_updategallery'); switch ($_POST['bulkaction']) { case 'no_action': break; case 'rotate_cw': nggAdmin::do_ajax_operation('rotate_cw', $_POST['doaction'], __('Rotate images', 'nggallery')); break; case 'rotate_ccw': nggAdmin::do_ajax_operation('rotate_ccw', $_POST['doaction'], __('Rotate images', 'nggallery')); break; case 'recover_images': nggAdmin::do_ajax_operation('recover_image', $_POST['doaction'], __('Recover from backup', 'nggallery')); break; case 'set_watermark': nggAdmin::do_ajax_operation('set_watermark', $_POST['doaction'], __('Set watermark', 'nggallery')); break; case 'delete_images': if (is_array($_POST['doaction'])) { foreach ($_POST['doaction'] as $imageID) { $image = $nggdb->find_image($imageID); if ($image) { if ($ngg->options['deleteImg']) { $storage = C_Gallery_Storage::get_instance(); $storage->delete_image($image->pid); } do_action('ngg_delete_picture', $image->pid); $delete_pic = C_Image_Mapper::get_instance()->destroy($image->pid); } } if ($delete_pic) { nggGallery::show_message(__('Pictures deleted successfully ', 'nggallery')); } } break; case 'import_meta': nggAdmin::do_ajax_operation('import_metadata', $_POST['doaction'], __('Import metadata', 'nggallery')); break; } } if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_ResizeImages'])) { check_admin_referer('ngg_thickbox_form'); //save the new values for the next operation $ngg->options['imgWidth'] = (int) $_POST['imgWidth']; $ngg->options['imgHeight'] = (int) $_POST['imgHeight']; update_option('ngg_options', $ngg->options); $pic_ids = explode(',', $_POST['TB_imagelist']); nggAdmin::do_ajax_operation('resize_image', $pic_ids, __('Resize images', 'nggallery')); } if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_NewThumbnail'])) { check_admin_referer('ngg_thickbox_form'); // save the new values for the next operation $settings = C_NextGen_Settings::get_instance(); $settings->thumbwidth = (int) $_POST['thumbwidth']; $settings->thumbheight = (int) $_POST['thumbheight']; $settings->thumbfix = isset($_POST['thumbfix']) ? TRUE : FALSE; $settings->save(); ngg_refreshSavedSettings(); $pic_ids = explode(',', $_POST['TB_imagelist']); nggAdmin::do_ajax_operation('create_thumbnail', $pic_ids, __('Create new thumbnails', 'nggallery')); } if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_SelectGallery'])) { check_admin_referer('ngg_thickbox_form'); $pic_ids = explode(',', $_POST['TB_imagelist']); $dest_gid = (int) $_POST['dest_gid']; switch ($_POST['TB_bulkaction']) { case 'copy_to': C_Gallery_Storage::get_instance()->copy_images($pic_ids, $dest_gid); break; case 'move_to': C_Gallery_Storage::get_instance()->move_images($pic_ids, $dest_gid); break; } } if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_EditTags'])) { // do tags update check_admin_referer('ngg_thickbox_form'); // get the images list $pic_ids = explode(',', $_POST['TB_imagelist']); $taglist = explode(',', $_POST['taglist']); $taglist = array_map('trim', $taglist); if (is_array($pic_ids)) { foreach ($pic_ids as $pic_id) { // which action should be performed ? switch ($_POST['TB_bulkaction']) { case 'no_action': // No action break; case 'overwrite_tags': // Overwrite tags wp_set_object_terms($pic_id, $taglist, 'ngg_tag'); break; case 'add_tags': // Add / append tags wp_set_object_terms($pic_id, $taglist, 'ngg_tag', TRUE); break; case 'delete_tags': // Delete tags $oldtags = wp_get_object_terms($pic_id, 'ngg_tag', 'fields=names'); // get the slugs, to vaoid case sensitive problems $slugarray = array_map('sanitize_title', $taglist); $oldtags = array_map('sanitize_title', $oldtags); // compare them and return the diff $newtags = array_diff($oldtags, $slugarray); wp_set_object_terms($pic_id, $newtags, 'ngg_tag'); break; } } nggGallery::show_message(__('Tags changed', 'nggallery')); } } if (isset($_POST['updatepictures'])) { // Update pictures check_admin_referer('ngg_updategallery'); if (nggGallery::current_user_can('NextGEN Edit gallery options') && !isset($_GET['s'])) { $tags = array('<a>', '<abbr>', '<acronym>', '<address>', '<b>', '<base>', '<basefont>', '<big>', '<blockquote>', '<br>', '<br/>', '<caption>', '<center>', '<cite>', '<code>', '<col>', '<colgroup>', '<dd>', '<del>', '<dfn>', '<dir>', '<div>', '<dl>', '<dt>', '<em>', '<fieldset>', '<font>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<hr>', '<i>', '<ins>', '<label>', '<legend>', '<li>', '<menu>', '<noframes>', '<noscript>', '<ol>', '<optgroup>', '<option>', '<p>', '<pre>', '<q>', '<s>', '<samp>', '<select>', '<small>', '<span>', '<strike>', '<strong>', '<sub>', '<sup>', '<table>', '<tbody>', '<td>', '<tfoot>', '<th>', '<thead>', '<tr>', '<tt>', '<u>', '<ul>'); $fields = array('title', 'galdesc'); // Sanitize fields foreach ($fields as $field) { $html = $_POST[$field]; $html = preg_replace('/\\s+on\\w+=(["\']).*?\\1/i', '', $html); $html = preg_replace('/(<\\/[^>]+?>)(<[^>\\/][^>]*?>)/', '$1 $2', $html); $html = strip_tags($html, implode('', $tags)); $_POST[$field] = $html; } // Update the gallery $mapper = C_Gallery_Mapper::get_instance(); if ($entity = $mapper->find($this->gid)) { foreach ($_POST as $key => $value) { $entity->{$key} = $value; } $mapper->save($entity); } wp_cache_delete($this->gid, 'ngg_gallery'); } $this->update_pictures(); //hook for other plugin to update the fields do_action('ngg_update_gallery', $this->gid, $_POST); nggGallery::show_message(__('Update successful', 'nggallery')); } if (isset($_POST['scanfolder'])) { // Rescan folder check_admin_referer('ngg_updategallery'); $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' "); nggAdmin::import_gallery($gallerypath, $this->gid); } // Add a new page if (isset($_POST['addnewpage'])) { check_admin_referer('ngg_updategallery'); $parent_id = esc_attr($_POST['parent_id']); $gallery_title = esc_attr($_POST['title']); $mapper = C_Gallery_Mapper::get_instance(); $gallery = $mapper->find($this->gid); $gallery_name = $gallery->name; // Create a WP page global $user_ID; $page['post_type'] = 'page'; $page['post_content'] = apply_filters('ngg_add_page_shortcode', '[nggallery id="' . $this->gid . '"]'); $page['post_parent'] = $parent_id; $page['post_author'] = $user_ID; $page['post_status'] = 'publish'; $page['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title; $page = apply_filters('ngg_add_new_page', $page, $this->gid); $gallery_pageid = wp_insert_post($page); if ($gallery_pageid != 0) { $gallery->pageid = $gallery_pageid; $mapper->save($gallery); nggGallery::show_message(__('New gallery page ID', 'nggallery') . ' ' . $gallery_pageid . ' -> <strong>' . $gallery_title . '</strong> ' . __('created', 'nggallery')); } do_action('ngg_gallery_addnewpage', $this->gid); } }
/** * Displays a preview image for the displayed gallery */ public function preview_action() { $found_preview_pic = FALSE; $dyn_thumbs = C_Dynamic_Thumbnails_Manager::get_instance(); $storage = C_Gallery_Storage::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); // Get the first entity from the displayed gallery. We will use this // for a preview pic $entity = array_pop($this->object->_displayed_gallery->get_included_entities(1)); $image = FALSE; if ($entity) { // This is an album or gallery if (isset($entity->previewpic)) { $image = (int) $entity->previewpic; if ($image = $image_mapper->find($image)) { $found_preview_pic = TRUE; } } else { if (isset($entity->galleryid)) { $image = $entity; $found_preview_pic = TRUE; } } } // Were we able to find a preview pic? If so, then render it $image_size = $dyn_thumbs->get_size_name(array('width' => 200, 'height' => 200, 'quality' => 90, 'type' => 'jpg')); $found_preview_pic = $storage->render_image($image, $image_size, TRUE); // Render invalid image if no preview pic is found if (!$found_preview_pic) { $filename = $this->object->get_static_abspath('photocrati-attach_to_post#invalid_image.png'); $this->set_content_type('image/png'); readfile($filename); $this->render(); } }
/** * 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); }