Exemple #1
0
/**
 * Image edit functions via AJAX
 * 
 * @author Alex Rabe
 * @copyright 2008 - 2010
 * 
 * @return void
 */
function ngg_ajax_operation()
{
    global $wpdb;
    // if nonce is not correct it returns -1
    check_ajax_referer("ngg-ajax");
    // check for correct capability
    if (!is_user_logged_in()) {
        die('-1');
    }
    // check for correct NextGEN capability
    if (!current_user_can('NextGEN Upload images') && !current_user_can('NextGEN Manage gallery')) {
        die('-1');
    }
    // include the ngg 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 = nggdb::find_image($id);
        // what do you want to do ?
        switch ($_POST['operation']) {
            case 'create_thumbnail':
                $result = nggAdmin::create_thumbnail($picture);
                break;
            case 'resize_image':
                $result = nggAdmin::resize_image($picture);
                break;
            case 'rotate_cw':
                $result = nggAdmin::rotate_image($picture, 'CW');
                nggAdmin::create_thumbnail($picture);
                break;
            case 'rotate_ccw':
                $result = nggAdmin::rotate_image($picture, 'CCW');
                nggAdmin::create_thumbnail($picture);
                break;
            case 'set_watermark':
                $result = nggAdmin::set_watermark($picture);
                break;
            case 'recover_image':
                $result = nggAdmin::recover_image($picture);
                break;
            case 'import_metadata':
                $result = nggAdmin::import_MetaData($id);
                break;
            case 'get_image_ids':
                $result = nggAdmin::get_image_ids($id);
                break;
            default:
                do_action('ngg_ajax_' . $_POST['operation']);
                die('-1');
                break;
        }
        // A success should return a '1'
        die($result);
    }
    // The script should never stop here
    die('0');
}
Exemple #2
0
 /**
  * Add images to database
  * 
  * @class nggAdmin
  * @param int $galleryID
  * @param array $imageslist
  * @return array $image_ids Id's which are sucessful added
  */
 function add_Images($galleryID, $imageslist)
 {
     global $wpdb, $ngg;
     $image_ids = array();
     if (is_array($imageslist)) {
         foreach ($imageslist as $picture) {
             // strip off the extension of the filename
             $path_parts = pathinfo($picture);
             $alttext = !isset($path_parts['filename']) ? substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')) : $path_parts['filename'];
             // save it to the database
             $pic_id = nggdb::add_image($galleryID, $picture, '', $alttext);
             if (!empty($pic_id)) {
                 $image_ids[] = $pic_id;
             }
             // add the metadata
             nggAdmin::import_MetaData($pic_id);
             // auto rotate
             nggAdmin::rotate_image($pic_id);
             // Autoresize image if required
             if ($ngg->options['imgAutoResize']) {
                 $imagetmp = nggdb::find_image($pic_id);
                 $sizetmp = @getimagesize($imagetmp->imagePath);
                 $widthtmp = $ngg->options['imgWidth'];
                 $heighttmp = $ngg->options['imgHeight'];
                 if ($sizetmp[0] > $widthtmp && $widthtmp || $sizetmp[1] > $heighttmp && $heighttmp) {
                     nggAdmin::resize_image($pic_id);
                 }
             }
             // action hook for post process after the image is added to the database
             $image = array('id' => $pic_id, 'filename' => $picture, 'galleryID' => $galleryID);
             do_action('ngg_added_new_image', $image);
         }
     }
     // is_array
     // delete dirsize after adding new images
     delete_transient('dirsize_cache');
     do_action('ngg_after_new_images_added', $galleryID, $image_ids);
     return $image_ids;
 }