function register_translation_hooks()
 {
     $fs = C_Fs::get_instance();
     $dir = str_replace($fs->get_document_root('plugins'), '', $fs->get_abspath('lang', 'photocrati-nextgen_pro_i18n'));
     // Load text domain
     load_plugin_textdomain('nextgen-gallery-pro', false, $dir);
 }
 function comments_template($template)
 {
     $fs = C_Fs::get_instance();
     if (strpos($template, 'ngg_comments') !== FALSE) {
         $template = $fs->find_abspath('photocrati-comments#templates/comments.php');
     }
     return $template;
 }
 public function register_defaults()
 {
     $settings = C_NextGen_Settings::get_instance();
     $fs = C_Fs::get_instance();
     $router = C_Router::get_instance();
     // Add none as an option
     $none = new stdClass();
     $none->title = __('None', 'nggallery');
     $this->register('none', $none);
     // Add Fancybox
     $fancybox = new stdClass();
     $fancybox->title = __('Fancybox', 'nggallery');
     $fancybox->code = 'class="ngg-fancybox" rel="%GALLERY_NAME%"';
     $fancybox->styles = array('photocrati-lightbox#fancybox/jquery.fancybox-1.3.4.css');
     $fancybox->scripts = array('photocrati-lightbox#fancybox/jquery.easing-1.3.pack.js', 'photocrati-lightbox#fancybox/jquery.fancybox-1.3.4.pack.js', 'photocrati-lightbox#fancybox/nextgen_fancybox_init.js');
     $this->register('fancybox', $fancybox);
     // Add Shutter
     $shutter = new stdClass();
     $shutter->title = __('Shutter', 'nggallery');
     $shutter->code = 'class="shutterset_%GALLERY_NAME%"';
     $shutter->styles = array('photocrati-lightbox#shutter/shutter.css');
     $shutter->scripts = array('photocrati-lightbox#shutter/shutter.js', 'photocrati-lightbox#shutter/nextgen_shutter.js');
     $shutter->values = array('nextgen_shutter_i18n' => array('msgLoading' => __('L O A D I N G', 'nggallery'), 'msgClose' => __('Click to Close', 'nggallery')));
     $this->register('shutter', $shutter);
     // Add shutter reloaded
     $shutter2 = new stdClass();
     $shutter2->title = __('Shutter Reloaded', 'nggallery');
     $shutter2->code = 'class="shutterset_%GALLERY_NAME%"';
     $shutter2->styles = array('photocrati-lightbox#shutter_reloaded/shutter.css');
     $shutter2->scripts = array('photocrati-lightbox#shutter_reloaded/shutter.js', 'photocrati-lightbox#shutter_reloaded/nextgen_shutter_reloaded.js');
     $shutter2->values = array('nextgen_shutter2_i18n' => array(__('Previous', 'nggallery'), __('Next', 'nggallery'), __('Close', 'nggallery'), __('Full Size', 'nggallery'), __('Fit to Screen', 'nggallery'), __('Image', 'nggallery'), __('of', 'nggallery'), __('Loading...', 'nggallery')));
     $this->register('shutter2', $shutter2);
     // Add Thickbox
     $thickbox = new stdClass();
     $thickbox->title = __('Thickbox', 'nggallery');
     $thickbox->code = 'class=\'thickbox\' rel=\'%GALLERY_NAME%\'';
     $thickbox->styles = array('wordpress#thickbox');
     $thickbox->scripts = array('photocrati-lightbox#thickbox/nextgen_thickbox_init.js', 'wordpress#thickbox');
     $thickbox->values = array('nextgen_thickbox_i18n' => array('next' => __('Next >', 'nggallery'), 'prev' => __('< Prev', 'nggallery'), 'image' => __('Image', 'nggallery'), 'of' => __('of', 'nggallery'), 'close' => __('Close', 'nggallery'), 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.', 'nggallery')));
     $this->register('thickbox', $thickbox);
     // Allow third parties to integrate
     do_action('ngg_registered_default_lightboxes');
     // Add custom option
     $custom = new stdClass();
     $custom->title = __('Custom', 'nggallery');
     $custom->code = $settings->thumbEffectCode;
     $custom->styles = $settings->thumbEffectStyles;
     $custom->scripts = $settings->thumbEffectScripts;
     $this->register('custom_lightbox', $custom);
     $this->_registered_defaults = TRUE;
 }
 /**
  * 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;
 }
Exemplo n.º 5
0
 function _register_hooks()
 {
     $dir = str_replace(WP_PLUGIN_DIR, '', C_Fs::get_instance()->get_abspath('lang', 'photocrati-i18n'));
     // Load text domain
     load_plugin_textdomain('nggallery', false, $dir);
     // Hooks to register image, gallery, and album name & description with WPML
     add_action('ngg_image_updated', array(&$this, 'register_image_strings'));
     add_action('ngg_album_updated', array(&$this, 'register_album_strings'));
     add_action('ngg_created_new_gallery', array(&$this, 'register_gallery_strings'));
     // do not let WPML translate posts we use as a document store
     add_filter('get_translatable_documents', array(&$this, 'wpml_translatable_documents'));
     // see function comments
     add_filter('ngg_displayed_gallery_cache_params', array(&$this, 'set_qtranslate_cache_parameters'));
     add_filter('ngg_displayed_gallery_cache_params', array(&$this, 'set_wpml_cache_parameters'));
 }
Exemplo n.º 6
0
 function register_translation_hooks()
 {
     $fs = C_Fs::get_instance();
     $dir = str_replace($fs->get_document_root('plugins'), '', $fs->get_abspath('lang', 'photocrati-i18n'));
     // Load text domain
     load_plugin_textdomain('nggallery', false, $dir);
     // Hooks to register image, gallery, and album name & description with WPML
     add_action('ngg_image_updated', array($this, 'register_image_strings'));
     add_action('ngg_album_updated', array($this, 'register_album_strings'));
     add_action('ngg_created_new_gallery', array($this, 'register_gallery_strings'));
     // do not let WPML translate posts we use as a document store
     add_filter('get_translatable_documents', array($this, 'wpml_translatable_documents'));
     if (class_exists('SitePress')) {
         // Copy AttachToPost entries when duplicating posts to another language
         add_action('icl_make_duplicate', array($this, 'wpml_adjust_gallery_id'), 10, 4);
         add_action('save_post', array($this, 'wpml_set_gallery_language_on_save_post'), 101, 1);
     }
     // see function comments
     add_filter('ngg_displayed_gallery_cache_params', array($this, 'set_qtranslate_cache_parameters'));
     add_filter('ngg_displayed_gallery_cache_params', array($this, 'set_wpml_cache_parameters'));
 }
 public function get_url($uri = '/', $with_qs = TRUE, $site_url = FALSE)
 {
     static $cache = array();
     $key = implode('|', array($uri, $with_qs, $site_url));
     if (isset($cache[$key])) {
         return $cache[$key];
     } else {
         $retval = $this->call_parent('get_url', $uri, $with_qs, $site_url);
         // Determine whether the url is a directory or file on the filesystem
         // If so, then we do NOT need /index.php as part of the url
         $base_url = $this->object->get_base_url();
         $filename = str_replace($base_url, C_Fs::get_instance()->get_document_root(), $retval);
         if ($retval && @file_exists($filename) && $retval != $base_url) {
             // Remove index.php from the url
             $retval = $this->object->remove_url_segment('/index.php', $retval);
             // Static urls don't end with a slash
             $retval = untrailingslashit($retval);
         }
         $cache[$key] = $retval;
         return $retval;
     }
 }
 function import_folder_action()
 {
     $retval = array();
     if ($this->validate_ajax_request('nextgen_upload_image')) {
         if ($folder = $this->param('folder')) {
             $storage = C_Gallery_Storage::get_instance();
             $fs = C_Fs::get_instance();
             try {
                 $keep_files = $this->param('keep_location') == 'on';
                 $retval = $storage->import_gallery_from_fs($fs->join_paths(NEXTGEN_GALLERY_IMPORT_ROOT, $folder), false, !$keep_files);
                 if (!$retval) {
                     $retval = array('error' => "Could not import folder. No images found.");
                 }
             } catch (E_NggErrorException $ex) {
                 $retval['error'] = $ex->getMessage();
             } catch (Exception $ex) {
                 $retval['error'] = "An unexpected error occured.";
                 $retval['error_details'] = $ex->getMessage();
             }
         } else {
             $retval['error'] = "No folder specified";
         }
     } else {
         $retval['error'] = "No permissions to import folders. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.";
     }
     return $retval;
 }
 /**
  * Modfied Watermark function by Steve Peart 
  * http://parasitehosting.com/
  *
  * @param string $relPOS
  * @param int $xPOS
  * @param int $yPOS
  */
 public function watermarkImage($relPOS = 'botRight', $xPOS = 0, $yPOS = 0)
 {
     // if it's a resource ID take it as watermark text image
     if (is_resource($this->watermarkImgPath)) {
         $this->workingImage = $this->watermarkImgPath;
     } else {
         // (possibly) search for the file from the document root
         if (!is_file($this->watermarkImgPath)) {
             $fs = C_Fs::get_instance();
             if (is_file($fs->join_paths($fs->get_document_root('content'), $this->watermarkImgPath))) {
                 $this->watermarkImgPath = $fs->get_document_root('content') . $this->watermarkImgPath;
             }
         }
         // Would you really want to use anything other than a png?
         $this->workingImage = @imagecreatefrompng($this->watermarkImgPath);
         // if it's not a valid file die...
         if (empty($this->workingImage) or !$this->workingImage) {
             return;
         }
     }
     imagealphablending($this->workingImage, false);
     imagesavealpha($this->workingImage, true);
     $sourcefile_width = imageSX($this->oldImage);
     $sourcefile_height = imageSY($this->oldImage);
     $watermarkfile_width = imageSX($this->workingImage);
     $watermarkfile_height = imageSY($this->workingImage);
     switch (substr($relPOS, 0, 3)) {
         case 'top':
             $dest_y = 0 + $yPOS;
             break;
         case 'mid':
             $dest_y = $sourcefile_height / 2 - $watermarkfile_height / 2;
             break;
         case 'bot':
             $dest_y = $sourcefile_height - $watermarkfile_height - $yPOS;
             break;
         default:
             $dest_y = 0;
             break;
     }
     switch (substr($relPOS, 3)) {
         case 'Left':
             $dest_x = 0 + $xPOS;
             break;
         case 'Center':
             $dest_x = $sourcefile_width / 2 - $watermarkfile_width / 2;
             break;
         case 'Right':
             $dest_x = $sourcefile_width - $watermarkfile_width - $xPOS;
             break;
         default:
             $dest_x = 0;
             break;
     }
     // debug
     // $this->errmsg = 'X '.$dest_x.' Y '.$dest_y;
     // $this->showErrorImage();
     // if a gif, we have to upsample it to a truecolor image
     if ($this->format == 'GIF') {
         $tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
         imagecopy($tempimage, $this->oldImage, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);
         $this->newImage = $tempimage;
     }
     $this->imagecopymerge_alpha($this->newImage, $this->workingImage, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height, 100);
 }
Exemplo n.º 10
0
 function post_processor_galleries()
 {
     global $wpdb, $ngg, $nggdb;
     // bulk update in a single gallery
     if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) {
         check_admin_referer('ngg_bulkgallery');
         switch ($_POST['bulkaction']) {
             case 'no_action':
                 // No action
                 break;
             case 'recover_images':
                 // Recover images from backup
                 // A prefix 'gallery_' will first fetch all ids from the selected galleries
                 nggAdmin::do_ajax_operation('gallery_recover_image', $_POST['doaction'], __('Recover from backup', 'nggallery'));
                 break;
             case 'set_watermark':
                 // Set watermark
                 // A prefix 'gallery_' will first fetch all ids from the selected galleries
                 nggAdmin::do_ajax_operation('gallery_set_watermark', $_POST['doaction'], __('Set watermark', 'nggallery'));
                 break;
             case 'import_meta':
                 // Import Metadata
                 // A prefix 'gallery_' will first fetch all ids from the selected galleries
                 nggAdmin::do_ajax_operation('gallery_import_metadata', $_POST['doaction'], __('Import metadata', 'nggallery'));
                 break;
             case 'delete_gallery':
                 // Delete gallery
                 if (is_array($_POST['doaction'])) {
                     $deleted = false;
                     foreach ($_POST['doaction'] as $id) {
                         // get the path to the gallery
                         $gallery = nggdb::find_gallery($id);
                         if ($gallery) {
                             //TODO:Remove also Tag reference, look here for ids instead filename
                             $imagelist = $wpdb->get_col("SELECT pid FROM {$wpdb->nggpictures} WHERE galleryid = '{$gallery->gid}' ");
                             if ($ngg->options['deleteImg']) {
                                 $storage = C_Component_Registry::get_instance()->get_utility('I_Gallery_Storage');
                                 if (is_array($imagelist)) {
                                     foreach ($imagelist as $pid) {
                                         $storage->delete_image($pid);
                                     }
                                 }
                                 // delete folder. abspath provided by nggdb::find_gallery()
                                 $fs = C_Fs::get_instance();
                                 @rmdir($fs->join_paths($gallery->abspath, 'thumbs'));
                                 @rmdir($fs->join_paths($gallery->abspath, 'dynamic'));
                                 @rmdir($gallery->abspath);
                             }
                         }
                         do_action('ngg_delete_gallery', $id);
                         $deleted = nggdb::delete_gallery($id);
                     }
                     if ($deleted) {
                         nggGallery::show_message(__('Gallery deleted successfully ', 'nggallery'));
                     }
                 }
                 break;
         }
     }
     if (isset($_POST['addgallery']) && isset($_POST['galleryname'])) {
         check_admin_referer('ngg_addgallery');
         if (!nggGallery::current_user_can('NextGEN Add new gallery')) {
             wp_die(__('Cheatin&#8217; uh?', 'nggallery'));
         }
         // get the default path for a new gallery
         $defaultpath = $ngg->options['gallerypath'];
         $newgallery = $_POST['galleryname'];
         if (!empty($newgallery)) {
             nggAdmin::create_gallery($newgallery, $defaultpath);
         }
         do_action('ngg_update_addgallery_page');
     }
     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'];
         // What is in the case the user has no if cap 'NextGEN Change options' ? Check feedback
         update_option('ngg_options', $ngg->options);
         $gallery_ids = explode(',', $_POST['TB_imagelist']);
         // A prefix 'gallery_' will first fetch all ids from the selected galleries
         nggAdmin::do_ajax_operation('gallery_resize_image', $gallery_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();
         // What is in the case the user has no if cap 'NextGEN Change options' ? Check feedback
         $gallery_ids = explode(',', $_POST['TB_imagelist']);
         // A prefix 'gallery_' will first fetch all ids from the selected galleries
         nggAdmin::do_ajax_operation('gallery_create_thumbnail', $gallery_ids, __('Create new thumbnails', 'nggallery'));
     }
 }
 /**
  * Returns the url to the selected stylesheet
  * @return mixed
  */
 function get_selected_stylesheet_url($selected = FALSE)
 {
     if (!$selected) {
         $selected = $this->get_selected_stylesheet();
     }
     $abspath = $this->find_selected_stylesheet_abspath($selected);
     // default_dir is the only resource loaded from inside the plugin directory
     $type = 'content';
     $url = content_url();
     if (0 === strpos($abspath, $this->default_dir)) {
         $type = 'plugins';
         $url = plugins_url();
     }
     $retval = str_replace(C_Fs::get_instance()->get_document_root($type), $url, $this->find_selected_stylesheet_abspath($selected));
     return rtrim(str_replace('\\', '/', $retval), "/");
 }
Exemplo n.º 12
0
 /**
  * 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&#96;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;
 }
Exemplo n.º 13
0
 /**
  * Returns the url to the selected stylesheet
  * @return mixed
  */
 function get_selected_stylesheet_url($selected = FALSE)
 {
     if (!$selected) {
         $selected = $this->get_selected_stylesheet();
     }
     $retval = str_replace(C_Fs::get_instance()->get_document_root('content'), content_url(), $this->find_selected_stylesheet_abspath($selected));
     return rtrim(str_replace('\\', '/', $retval), "/");
 }
 /**
  * Gets the absolute path where the image is stored
  * Can optionally return the path for a particular sized image
  */
 function get_image_abspath($image, $size = 'full', $check_existance = FALSE)
 {
     $retval = NULL;
     $fs = C_Fs::get_instance();
     // Ensure that we have a size
     if (!$size) {
         $size = 'full';
     }
     // If we have the id, get the actual image entity
     if (is_numeric($image)) {
         $image = $this->object->_image_mapper->find($image);
     }
     // Ensure we have the image entity - user could have passed in an
     // incorrect id
     if (is_object($image)) {
         if ($gallery_path = $this->object->get_gallery_abspath($image->galleryid)) {
             $folder = $prefix = $size;
             switch ($size) {
                 # Images are stored in the associated gallery folder
                 case 'full':
                 case 'original':
                 case 'image':
                     $retval = $fs->join_paths($gallery_path, $image->filename);
                     break;
                 case 'backup':
                     $retval = $fs->join_paths($gallery_path, $image->filename . '_backup');
                     if (!@file_exists($retval)) {
                         $retval = $fs->join_paths($gallery_path, $image->filename);
                     }
                     break;
                 case 'thumbnails':
                 case 'thumbnail':
                 case 'thumb':
                 case 'thumbs':
                     $size = 'thumbnail';
                     $folder = 'thumbs';
                     $prefix = 'thumbs';
                     // deliberately no break here
                     // We assume any other size of image is stored in the a
                     //subdirectory of the same name within the gallery folder
                     // gallery folder, but with the size appended to the filename
                 // deliberately no break here
                 // We assume any other size of image is stored in the a
                 //subdirectory of the same name within the gallery folder
                 // gallery folder, but with the size appended to the filename
                 default:
                     $image_path = $fs->join_paths($gallery_path, $folder);
                     // NGG 2.0 stores relative filenames in the meta data of
                     // an image. It does this because it uses filenames
                     // that follow conventional WordPress naming scheme.
                     if (isset($image->meta_data) && isset($image->meta_data[$size]) && isset($image->meta_data[$size]['filename'])) {
                         $image_path = $fs->join_paths($image_path, $image->meta_data[$size]['filename']);
                     } else {
                         $image_path = $fs->join_paths($image_path, "{$prefix}_{$image->filename}");
                     }
                     $retval = $image_path;
                     break;
             }
         }
     }
     // Check the existance of the file
     if ($retval && $check_existance) {
         if (!file_exists($retval)) {
             $retval = NULL;
         }
     }
     return $retval ? rtrim($retval, "/\\") : $retval;
 }
 public function save_action($image_options)
 {
     $save = TRUE;
     if ($image_options) {
         // Update the gallery path. Moves all images to the new location
         if (isset($image_options['gallerypath']) && (!is_multisite() || get_current_blog_id() == 1)) {
             $fs = C_Fs::get_instance();
             $original_dir = $fs->get_abspath($this->object->get_model()->get('gallerypath'));
             $new_dir = $fs->get_abspath($image_options['gallerypath']);
             $image_options['gallerypath'] = $fs->add_trailing_slash($image_options['gallerypath']);
         } elseif (isset($image_options['gallerypath'])) {
             unset($image_options['gallerypath']);
         }
         // Update image options
         if ($save) {
             $this->object->get_model()->set($image_options)->save();
         }
     }
 }
Exemplo n.º 16
0
 function load_styles()
 {
     global $ngg;
     // load the icon for the navigation menu
     wp_enqueue_style('nggmenu', NGGALLERY_URLPATH . 'admin/css/menu.css', false, NGG_SCRIPT_VERSION);
     wp_register_style('nggadmin', NGGALLERY_URLPATH . 'admin/css/nggadmin.css', false, NGG_SCRIPT_VERSION, 'screen');
     wp_register_style('ngg-jqueryui', NGGALLERY_URLPATH . 'admin/css/jquery.ui.css', false, NGG_SCRIPT_VERSION, 'screen');
     // no need to go on if it's not a plugin page
     if (!isset($_GET['page'])) {
         return;
     }
     // used to retrieve the uri of some module resources
     $router = C_Router::get_instance();
     switch ($_GET['page']) {
         case NGGFOLDER:
             wp_add_inline_style('nggadmin', file_get_contents(C_Fs::get_instance()->find_static_abspath('photocrati-nextgen-legacy#overview.css')));
         case "nggallery-about":
             wp_enqueue_style('nggadmin');
             //TODO:Remove after WP 3.3 release
             if (!defined('IS_WP_3_3')) {
                 wp_admin_css('css/dashboard');
             }
             break;
         case "nggallery-manage-gallery":
             wp_enqueue_script('jquery-ui-tooltip');
             wp_enqueue_style('shutter', $router->get_static_url('photocrati-lightbox#shutter/shutter.css'), false, NGG_SCRIPT_VERSION, 'screen');
         case "nggallery-roles":
         case "nggallery-manage-album":
             $this->enqueue_jquery_ui_theme();
             wp_enqueue_style('nggadmin');
             break;
         case "nggallery-tags":
             wp_enqueue_style('nggtags', NGGALLERY_URLPATH . 'admin/css/tags-admin.css', false, NGG_SCRIPT_VERSION, 'screen');
             break;
     }
 }
 /**
  * Renders the underscore template used by TinyMCE for IGW placeholders
  */
 function print_tinymce_placeholder_template()
 {
     readfile(C_Fs::get_instance()->join_paths($this->get_registry()->get_module_dir('photocrati-attach_to_post'), 'templates', 'tinymce_placeholder.php'));
 }
Exemplo n.º 18
0
    function dashboard_quota()
    {
        if (get_site_option('upload_space_check_disabled')) {
            return;
        }
        if (!wpmu_enable_function('wpmuQuotaCheck')) {
            return;
        }
        $settings = C_NextGen_Settings::get_instance();
        $fs = C_Fs::get_instance();
        $dir = $fs->join_paths($fs->get_document_root('content'), $settings->gallerypath);
        $quota = get_space_allowed();
        $used = get_dirsize($dir) / 1024 / 1024;
        if ($used > $quota) {
            $percentused = '100';
        } else {
            $percentused = $used / $quota * 100;
        }
        $used_color = $percentused < 70 ? $percentused >= 40 ? 'yellow' : 'green' : 'red';
        $used = round($used, 2);
        $percentused = number_format($percentused);
        ?>
        <p><?php 
        print __('Storage Space');
        ?>
</p>
        <ul>
            <li><?php 
        printf(__('%1$sMB Allowed', 'nggallery'), $quota);
        ?>
</li>
            <li class="<?php 
        print $used_color;
        ?>
"><?php 
        printf(__('%1$sMB (%2$s%%) Used', 'nggallery'), $used, $percentused);
        ?>
</li>
        </ul>
        <?php 
    }
Exemplo n.º 19
0
function ngg_dashboard_quota()
{
    if (get_site_option('upload_space_check_disabled')) {
        return;
    }
    if (!wpmu_enable_function('wpmuQuotaCheck')) {
        return;
    }
    $settings = C_NextGen_Settings::get_instance();
    $fs = C_Fs::get_instance();
    $dir = $fs->join_paths($fs->get_document_root('content'), $settings->gallerypath);
    $quota = get_space_allowed();
    $used = get_dirsize($dir) / 1024 / 1024;
    if ($used > $quota) {
        $percentused = '100';
    } else {
        $percentused = $used / $quota * 100;
    }
    $used_color = $percentused < 70 ? $percentused >= 40 ? 'waiting' : 'approved' : 'spam';
    $used = round($used, 2);
    $percentused = number_format($percentused);
    ?>
	<p class="sub musub" style="position:static" ><?php 
    _e('Storage Space');
    ?>
</p>
	<div class="table table_content musubtable">
	<table>
		<tr class="first">
			<td class="first b b-posts"><?php 
    printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>'), nextgen_esc_url(admin_url('admin.php?page=nggallery-manage-gallery')), $quota);
    ?>
</td>
			<td class="t posts"><?php 
    _e('Space Allowed');
    ?>
</td>
		</tr>
	</table>
	</div>
	<div class="table table_discussion musubtable">
	<table>
		<tr class="first">
			<td class="b b-comments"><?php 
    printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>'), nextgen_esc_url(admin_url('admin.php?page=nggallery-manage-gallery')), $used, $percentused);
    ?>
</td>
			<td class="last t comments <?php 
    echo $used_color;
    ?>
"><?php 
    _e('Space Used');
    ?>
</td>
		</tr>
	</table>
	</div>
	<br class="clear" />
	<?php 
}
 function save_action($image_options)
 {
     $save = TRUE;
     if ($image_options) {
         // Update the gallery path. Moves all images to the new location
         if (isset($image_options['gallerypath']) && (!is_multisite() || get_current_blog_id() == 1)) {
             $fs = C_Fs::get_instance();
             $original_dir = $fs->get_abspath($this->object->get_model()->get('gallerypath'));
             $new_dir = $fs->get_abspath($image_options['gallerypath']);
             $image_options['gallerypath'] = $fs->add_trailing_slash($image_options['gallerypath']);
             // Note: the below file move is disabled because it's quite unreliable as it doesn't perform any checks
             //       For instance changing gallery path from /wp-content to /wp-content/gallery would attempt a recursive copy and then delete ALL files under wp-content, which would be disastreus
             #				// If the gallery path has changed...
             #				if ($original_dir != $new_dir) {
             #                    // Try creating the new directory
             #                    if ($this->object->_create_gallery_storage_dir($new_dir) AND is_writable($new_dir)) {
             #					    // Try moving files
             #						$this->object->recursive_copy($original_dir, $new_dir);
             #						$this->object->recursive_delete($original_dir);
             #						// Update gallery paths
             #						$mapper = $this->get_registry()->get_utility('I_Gallery_Mapper');
             #						foreach ($mapper->find_all() as $gallery) {
             #							$gallery->path = $image_options['gallerypath'] . $gallery->name;
             #							$mapper->save($gallery);
             #						}
             #					}
             #					else {
             #						$this->get_model()->add_error("Unable to change gallery path. Insufficient filesystem permissions");
             #						$save = FALSE;
             #					}
             #				}
         } elseif (isset($image_options['gallerypath'])) {
             unset($image_options['gallerypath']);
         }
         // Update image options
         if ($save) {
             $this->object->get_model()->set($image_options)->save();
         }
     }
 }
 /**
  * Installs a display type
  * @param string $name
  * @param array $properties
  */
 function install_display_type($name, $properties = array())
 {
     // Try to find the existing entity. If it doesn't exist, we'll create
     $fs = C_Fs::get_instance();
     $mapper = C_Display_Type_Mapper::get_instance();
     $display_type = $mapper->find_by_name($name);
     if (!$display_type) {
         $display_type = new stdClass();
     }
     // Update the properties of the display type
     $properties['name'] = $name;
     $properties['installed_at_version'] = NGG_PLUGIN_VERSION;
     foreach ($properties as $key => $val) {
         if ($key == 'preview_image_relpath') {
             $val = $fs->find_static_abspath($val, FALSE, TRUE);
         }
         $display_type->{$key} = $val;
     }
     // Save the entity
     $retval = $mapper->save($display_type);
     return $retval;
 }
 public function get_template_override_abspath($module, $filename)
 {
     $fs = C_Fs::get_instance();
     $retval = NULL;
     $abspath = $fs->join_paths($this->object->get_template_override_dir($module), $filename);
     if (@file_exists($abspath)) {
         $retval = $abspath;
     }
     return $retval;
 }
Exemplo n.º 23
0
 /**
  * Gets the absolute path of an MVC template file
  *
  * @param string $path
  * @param string $module
  * @return string
  */
 public function find_template_abspath($path, $module = FALSE)
 {
     $fs = C_Fs::get_instance();
     $settings = C_NextGen_Settings::get_instance();
     // We also accept module_name#path, which needs parsing.
     if (!$module) {
         list($path, $module) = $fs->parse_formatted_path($path);
     }
     // Append the suffix
     $path = $path . '.php';
     $retval = $fs->join_paths($this->object->get_registry()->get_module_dir($module), $settings->mvc_template_dirname, $path);
     if (!@file_exists($retval)) {
         throw new RuntimeException("{$retval} is not a valid MVC template");
     }
     return $retval;
 }
 /**
  * Plupload stores its i18n JS *mostly* as "en.js" or "ar.js" - but some as zh_CN.js so we must check both if the
  * first does not match.
  *
  * @return bool|string
  */
 public function _find_plupload_i18n()
 {
     $fs = C_Fs::get_instance();
     $router = C_Router::get_instance();
     $locale = get_locale();
     $dir = $fs->find_static_abspath('photocrati-nextgen_addgallery_page#plupload-2.1.1/i18n') . DIRECTORY_SEPARATOR;
     $tmp = explode('_', $locale, 2);
     $retval = FALSE;
     if (file_exists($dir . $tmp[0] . '.js')) {
         $retval = $tmp[0];
     } else {
         if (file_exists($dir . $locale . '.js')) {
             $retval = $locale;
         }
     }
     if ($retval) {
         $retval = $router->get_static_url('photocrati-nextgen_addgallery_page#plupload-2.1.1/i18n/' . $retval . '.js');
     }
     return $retval;
 }
 /**
  * Gets the upload path, optionally for a particular gallery
  * @param int|C_Gallery|stdClass $gallery
  */
 function get_upload_relpath($gallery = FALSE)
 {
     $fs = C_Fs::get_instance();
     $retval = str_replace($fs->get_document_root('gallery'), '', $this->object->get_upload_abspath($gallery));
     return DIRECTORY_SEPARATOR . ltrim($retval, "/\\");
 }
 /**
  * Returns a static url
  * @param string $path
  * @param string $module
  * @return string
  */
 public function get_static_url($path, $module = FALSE)
 {
     $fs = C_Fs::get_instance();
     $path = $fs->find_abspath($path, $module);
     $base_url = $this->object->get_base_url(TRUE);
     $base_url = $this->object->remove_url_segment('/index.php', $base_url);
     $path = str_replace($fs->get_document_root('plugins'), $base_url, $path);
     // adjust for possible windows hosts
     return str_replace('\\', '/', $path);
 }
Exemplo n.º 27
0
 /**
  * Copy images to another gallery
  *
  * @class nggAdmin
  * @param array|int $pic_ids ID's of the images
  * @param int $dest_gid destination gallery
  * @return void
  */
 function copy_images($pic_ids, $dest_gid)
 {
     require_once NGGALLERY_ABSPATH . '/lib/meta.php';
     $errors = $messages = '';
     if (!is_array($pic_ids)) {
         $pic_ids = array($pic_ids);
     }
     // Get destination gallery
     $destination = nggdb::find_gallery($dest_gid);
     if ($destination == null) {
         nggGallery::show_error(__('The destination gallery does not exist', 'nggallery'));
         return;
     }
     // The gallery path should be relative, but in the past on IIS we were storing this incorrectly
     // as the absolute path. So, we need to normalize the path
     $destination_path = str_replace('/', DIRECTORY_SEPARATOR, $destination->path);
     $fs = C_Fs::get_instance();
     if (strpos($destination_path, $fs->get_document_root()) !== 0) {
         $destination_path = $fs->join_paths($fs->get_document_root(), $destination->path);
     }
     // Check for folder permission
     if (!is_writeable($destination_path)) {
         $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), esc_html($destination_path));
         nggGallery::show_error($message);
         return;
     }
     // Get pictures
     $images = nggdb::find_images_in_list($pic_ids);
     foreach ($images as $image) {
         // WPMU action
         if (nggWPMU::check_quota()) {
             return;
         }
         $i = 0;
         $tmp_prefix = '';
         $destination_file_name = $image->filename;
         while (file_exists($destination_path . '/' . $destination_file_name)) {
             $tmp_prefix = 'copy_' . $i++ . '_';
             $destination_file_name = $tmp_prefix . $image->filename;
         }
         $destination_file_path = $destination_path . '/' . $destination_file_name;
         $destination_thumb_file_path = $destination_path . '/' . $image->thumbFolder . $image->thumbPrefix . $destination_file_name;
         // Copy files
         if (!@copy($image->imagePath, $destination_file_path)) {
             $errors .= sprintf(__('Failed to copy image %1$s to %2$s', 'nggallery'), esc_html($image->filename), esc_html($destination_file_path)) . '<br />';
             continue;
         }
         // Copy backup file, if possible
         @copy($image->imagePath . '_backup', $destination_file_path . '_backup');
         // Copy the thumbnail if possible
         @copy($image->thumbPath, $destination_thumb_file_path);
         // Create new database entry for the image
         $new_pid = nggdb::insert_image($destination->gid, $destination_file_name, $image->alttext, $image->description, $image->exclude);
         if (!isset($new_pid)) {
             $errors .= sprintf(__('Failed to copy database row for picture %s', 'nggallery'), $image->pid) . '<br />';
             continue;
         }
         // Copy tags
         nggTags::copy_tags($image->pid, $new_pid);
         // Copy meta information
         $meta = new nggMeta($image->pid);
         nggdb::update_image_meta($new_pid, $meta->image->meta_data);
         if ($tmp_prefix != '') {
             $messages .= sprintf(__('Image %1$s (%2$s) copied as image %3$s (%4$s) &raquo; The file already existed in the destination gallery.', 'nggallery'), $image->pid, esc_html($image->filename), $new_pid, esc_html($destination_file_name)) . '<br />';
         } else {
             $messages .= sprintf(__('Image %1$s (%2$s) copied as image %3$s (%4$s)', 'nggallery'), $image->pid, esc_html($image->filename), $new_pid, esc_html($destination_file_name)) . '<br />';
         }
     }
     // Finish by showing errors or success
     if ($errors == '') {
         $link = '<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $destination->gid . '" >' . esc_html($destination->title) . '</a>';
         $messages .= '<hr />' . sprintf(__('Copied %1$s picture(s) to gallery: %2$s .', 'nggallery'), count($images), $link);
     }
     if ($messages != '') {
         nggGallery::show_message($messages);
     }
     if ($errors != '') {
         nggGallery::show_error($errors);
     }
     return;
 }