Beispiel #1
0
function flag_ajax_operation()
{
    global $wpdb;
    // if nonce is not correct it returns -1
    check_ajax_referer("flag-ajax");
    // check for correct capability
    if (!is_user_logged_in()) {
        die('-1');
    }
    // check for correct FlAG capability
    if (!current_user_can('FlAG Upload images') || !current_user_can('FlAG Manage gallery')) {
        die('-1');
    }
    // include the flag function
    include_once dirname(__FILE__) . '/functions.php';
    // Get the image id
    if (isset($_POST['image'])) {
        $id = (int) $_POST['image'];
        // let's get the image data
        $picture = flagdb::find_image($id);
        // what do you want to do ?
        switch ($_POST['operation']) {
            case 'create_thumbnail':
                $result = flagAdmin::create_thumbnail($picture);
                break;
            case 'resize_image':
                $result = flagAdmin::resize_image($picture);
                break;
            case 'webview_image':
                $result = flagAdmin::webview_image($picture);
                break;
            case 'import_metadata':
                $result = flagAdmin::import_MetaData($id);
                break;
            case 'copy_metadata':
                $result = flagAdmin::copy_MetaData($id);
                break;
            case 'get_image_ids':
                $result = flagAdmin::get_image_ids($id);
                break;
            default:
                do_action('flag_ajax_' . sanitize_key($_POST['operation']));
                die('-1');
                break;
        }
        // A success should return a '1'
        die($result);
    }
    // The script should never stop here
    die('0');
}
Beispiel #2
0
 /**
  * flagAdmin::createThumbnail() - function to create or recreate a thumbnail
  * 
  * @param object | int $image contain all information about the image or the id
  * @return string result code
  */
 public static function create_thumbnail($image)
 {
     global $flag;
     if (is_numeric($image)) {
         $image = flagdb::find_image($image);
     }
     if (!is_object($image)) {
         return __('Object didn\'t contain correct data', 'flag');
     }
     $dest_path = dirname($image->webimagePath);
     if (!is_dir($dest_path)) {
         flagGallery::create_webview_folder(dirname($image->imagePath));
         @chmod($dest_path, 0755);
     }
     if (!class_exists('flag_Thumbnail')) {
         require_once flagGallery::graphic_library();
     }
     // check for existing thumbnail
     if (file_exists($image->thumbPath)) {
         if (!is_writable($image->thumbPath)) {
             return $image->filename . __(' is not writeable ', 'flag');
         }
     }
     $thumb = new flag_Thumbnail($image->imagePath, TRUE);
     $img_size = @getimagesize($image->imagePath);
     // skip if file is not there
     if (!$thumb->error) {
         if ($flag->options['thumbFix']) {
             // check for portrait format
             if ($flag->options['thumbWidth'] / $flag->options['thumbHeight'] > $img_size[0] / $img_size[1]) {
                 // first resize to the wanted width
                 $thumb->resize($flag->options['thumbWidth'], 0);
                 // get optimal y startpos
                 $ypos = ($thumb->currentDimensions['height'] - $flag->options['thumbHeight']) / 2;
                 $thumb->crop(0, $ypos, $flag->options['thumbWidth'], $flag->options['thumbHeight']);
             } else {
                 // first resize to the wanted height
                 $thumb->resize(0, $flag->options['thumbHeight']);
                 // get optimal x startpos
                 $xpos = ($thumb->currentDimensions['width'] - $flag->options['thumbWidth']) / 2;
                 $thumb->crop($xpos, 0, $flag->options['thumbWidth'], $flag->options['thumbHeight']);
             }
             //this create a thumbnail but keep ratio settings
         } else {
             $thumb->resize($flag->options['thumbWidth'], $flag->options['thumbHeight']);
         }
         // save the new thumbnail
         $thumb->save($image->thumbPath, $flag->options['thumbQuality']);
         flagAdmin::chmod($image->thumbPath);
         //read the new sizes
         $new_size = @getimagesize($image->thumbPath);
         $size['width'] = $new_size[0];
         $size['height'] = $new_size[1];
         // add them to the database
         flagdb::update_image_meta($image->pid, array('thumbnail' => $size));
     }
     $thumb->destruct();
     if (!empty($thumb->errmsg)) {
         return $image->filename . ' (Error : ' . $thumb->errmsg . ')';
     }
     do_action('flag_thumbnail_created', $image);
     flagAdmin::webview_image($image);
     // success
     return '1';
 }