Ejemplo n.º 1
0
 /**
  *
  * @param $pic_id
  * @param bool $onlyEXIF parse only exif if needed
  */
 function __construct($pic_id, $onlyEXIF = false)
 {
     //get the path and other data about the image
     $this->image = flagdb::find_image($pic_id);
     $this->image = apply_filters('flag_find_image_meta', $this->image);
     if (!file_exists($this->image->imagePath)) {
         return false;
     }
     $this->size = @getimagesize($this->image->imagePath, $metadata);
     if ($this->size && is_array($metadata)) {
         // get exif - data
         if (is_callable('exif_read_data')) {
             $this->exif_data = @exif_read_data($this->image->imagePath, 0, true);
         }
         // stop here if we didn't need other meta data
         if ($onlyEXIF) {
             return true;
         }
         // get the iptc data - should be in APP13
         if (is_callable('iptcparse')) {
             $this->iptc_data = @iptcparse($metadata["APP13"]);
         }
         // get the xmp data in a XML format
         if (is_callable('xml_parser_create')) {
             $this->xmp_data = $this->extract_XMP($this->image->imagePath);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Get the XML <rss> node corresponding to a gallery
  *
  * @param $gallery object The gallery to include in RSS
  * @param $prev_gallery object The previous gallery to link in RSS (null if none)
  * @param $next_gallery object The next gallery to link in RSS (null if none)
  * @return string
  */
 function get_gallery_mrss($gallery, $prev_gallery = null, $next_gallery = null)
 {
     global $flag;
     $flag_options = get_option('flag_options');
     //Set sort order value, if not used (upgrade issue)
     $flag_options['galSort'] = $flag_options['galSort'] ? $flag_options['galSort'] : 'pid';
     $flag_options['galSortDir'] = $flag_options['galSortDir'] == 'DESC' ? 'DESC' : 'ASC';
     $title = stripslashes(flagGallery::i18n($gallery->title));
     $description = stripslashes(flagGallery::i18n($gallery->galdesc));
     $link = get_option('siteurl');
     $prev_link = $prev_gallery != null ? flagMediaRss::get_gallery_mrss_url($prev_gallery->gid, true) : '';
     $next_link = $next_gallery != null ? flagMediaRss::get_gallery_mrss_url($next_gallery->gid, true) : '';
     $images = flagdb::get_gallery($gallery->gid, $flag_options['galSort'], $flag_options['galSortDir']);
     return flagMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images);
 }
Ejemplo n.º 3
0
function flagCreateNewThumb()
{
    global $wpdb;
    // check for correct capability
    if (!is_user_logged_in()) {
        die('-1');
    }
    // check for correct FlAG capability
    if (!current_user_can('FlAG Manage gallery')) {
        die('-1');
    }
    require_once dirname(dirname(__FILE__)) . '/flag-config.php';
    include_once flagGallery::graphic_library();
    $flag_options = get_option('flag_options');
    $id = (int) $_POST['id'];
    $picture = flagdb::find_image($id);
    $x = round($_POST['x'] * $_POST['rr'], 0);
    $y = round($_POST['y'] * $_POST['rr'], 0);
    $w = round($_POST['w'] * $_POST['rr'], 0);
    $h = round($_POST['h'] * $_POST['rr'], 0);
    $thumb = new flag_Thumbnail($picture->imagePath, TRUE);
    $thumb->crop($x, $y, $w, $h);
    if ($flag_options['thumbFix']) {
        if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) {
            $thumb->resize($flag_options['thumbWidth'], 0);
        } else {
            $thumb->resize(0, $flag_options['thumbHeight']);
        }
    } else {
        $thumb->resize($flag_options['thumbWidth'], $flag_options['thumbHeight']);
    }
    if ($thumb->save($picture->thumbPath, 100)) {
        //read the new sizes
        $new_size = @getimagesize($picture->thumbPath);
        $size['width'] = $new_size[0];
        $size['height'] = $new_size[1];
        // add them to the database
        flagdb::update_image_meta($picture->pid, array('thumbnail' => $size));
        echo "OK";
    } else {
        header('HTTP/1.1 500 Internal Server Error');
        echo "KO";
    }
    exit;
}
 function ewww_flag_bulk_loop()
 {
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
         wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
     }
     if (!empty($_REQUEST['sleep'])) {
         sleep($_REQUEST['sleep']);
     }
     // need this file to work with flag meta
     require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
     // record the starting time for the current image (in microseconds)
     $started = microtime(true);
     $id = $_POST['attachment'];
     // get the image meta for the current ID
     $meta = new flagMeta($id);
     $file_path = $meta->image->imagePath;
     // optimize the full-size version
     $fres = ewww_image_optimizer($file_path, 3, false, false, ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full'));
     $meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
     // let the user know what happened
     printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
     printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]);
     $thumb_path = $meta->image->thumbPath;
     // optimize the thumbnail
     $tres = ewww_image_optimizer($thumb_path, 3, false, true);
     $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
     // and let the user know the results
     printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]);
     flagdb::update_image_meta($id, $meta->image->meta_data);
     // determine how much time the image took to process
     $elapsed = microtime(true) - $started;
     // and output it to the user
     printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
     // retrieve the list of attachments left to work on
     $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
     // take the first image off the list
     if (!empty($attachments)) {
         array_shift($attachments);
     }
     // and send the list back to the db
     update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
     die;
 }
Ejemplo n.º 5
0
 function ewww_flag_bulk_loop()
 {
     global $ewww_defer;
     $ewww_defer = false;
     $output = array();
     $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
     if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
         $output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
         echo json_encode($output);
         die;
     }
     session_write_close();
     // find out if our nonce is on it's last leg/tick
     $tick = wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk');
     if ($tick === 2) {
         $output['new_nonce'] = wp_create_nonce('ewww-image-optimizer-bulk');
     } else {
         $output['new_nonce'] = '';
     }
     // need this file to work with flag meta
     require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
     // record the starting time for the current image (in microseconds)
     $started = microtime(true);
     // retrieve the list of attachments left to work on
     $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
     $id = array_shift($attachments);
     // get the image meta for the current ID
     $meta = new flagMeta($id);
     $file_path = $meta->image->imagePath;
     // optimize the full-size version
     $fres = ewww_image_optimizer($file_path, 3, false, false, true);
     $ewww_status = get_transient('ewww_image_optimizer_cloud_status');
     if (!empty($ewww_status) && preg_match('/exceeded/', $ewww_status)) {
         $output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN);
         echo json_encode($output);
         die;
     }
     $meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
     // let the user know what happened
     $output['results'] = sprintf("<p>" . esc_html__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
     $output['results'] .= sprintf(esc_html__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($fres[1]));
     if (!empty($meta->image->meta_data['webview'])) {
         // determine path of the webview
         $web_path = $meta->image->webimagePath;
         $wres = ewww_image_optimizer($web_path, 3, false, true);
         $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
         $output['results'] .= sprintf(esc_html__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($wres[1]));
     }
     $thumb_path = $meta->image->thumbPath;
     // optimize the thumbnail
     $tres = ewww_image_optimizer($thumb_path, 3, false, true);
     $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
     // and let the user know the results
     $output['results'] .= sprintf(esc_html__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($tres[1]));
     flagdb::update_image_meta($id, $meta->image->meta_data);
     // determine how much time the image took to process
     $elapsed = microtime(true) - $started;
     // and output it to the user
     $output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
     // send the list back to the db
     update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments, false);
     if (!empty($attachments)) {
         $next_attachment = array_shift($attachments);
         $next_file = $this->ewww_flag_bulk_filename($next_attachment);
         $loading_image = plugins_url('/images/wpspin.gif', __FILE__);
         if ($next_file) {
             $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b>&nbsp;<img src='{$loading_image}' alt='loading'/></p>";
         } else {
             $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&nbsp;<img src='{$loading_image}' alt='loading'/></p>";
         }
     }
     echo json_encode($output);
     die;
 }
Ejemplo n.º 6
0
function ewww_image_optimizer_defer()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_defer;
    $ewww_defer = false;
    $deferred_attachments = get_option('ewww_image_optimizer_defer_attachments');
    if (empty($deferred_attachments)) {
        return;
    }
    $start_time = time();
    $delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay');
    foreach ($deferred_attachments as $image) {
        list($type, $id) = explode(',', $image, 2);
        switch ($type) {
            case 'media':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $meta = wp_get_attachment_metadata($id, true);
                // do the optimization for the current attachment (including resizes)
                $meta = ewww_image_optimizer_resize_from_meta_data($meta, $id, false);
                // update the metadata for the current attachment
                wp_update_attachment_metadata($id, $meta);
                break;
            case 'nextgen2':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                // creating the 'registry' object for working with nextgen
                $registry = C_Component_Registry::get_instance();
                // creating a database storage object from the 'registry' object
                $storage = $registry->get_utility('I_Gallery_Storage');
                // get an image object
                $ngg_image = $storage->object->_image_mapper->find($id);
                ewwwngg::ewww_added_new_image($ngg_image, $storage);
                break;
            case 'nextcellent':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewwwngg::ewww_ngg_optimize($id);
                break;
            case 'flag':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $flag_image = flagdb::find_image($id);
                ewwwflag::ewww_added_new_image($flag_image);
                break;
            case 'file':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewww_image_optimizer($id);
                break;
            default:
                ewwwio_debug_message("unknown type in deferrred queue: {$type}, {$id}");
        }
        ewww_image_optimizer_remove_deferred_attachment($image);
        $elapsed_time = time() - $start_time;
        ewwwio_debug_message("time elapsed during deferred opt: {$elapsed_time}");
        global $ewww_exceed;
        if (!empty($ewww_exceed)) {
            ewwwio_debug_message('Deferred opt aborted, license exceeded');
            die;
        }
        ewww_image_optimizer_debug_log();
        if (!empty($delay)) {
            sleep($delay);
        }
        // prevent running longer than an hour
        if ($elapsed_time > 3600) {
            return;
        }
    }
    ewwwio_memory(__FUNCTION__);
    return;
}
Ejemplo n.º 7
0
 /**
  * Return a JSON coded array of Image ids for a requested gallery
  * 
  * @param int $galleryID
  * @return array (JSON)
  */
 static function get_image_ids($galleryID)
 {
     if (!function_exists('json_encode')) {
         return -2;
     }
     $gallery = flagdb::get_ids_from_gallery($galleryID, 'pid', 'ASC', false);
     header('Content-Type: text/plain; charset=' . get_option('blog_charset'), true);
     $output = json_encode($gallery);
     return $output;
 }
Ejemplo n.º 8
0
function ewww_image_optimizer_import_loop()
{
    // verify that an authorized user has started the optimizer
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk')) {
        wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    global $wpdb;
    global $ewww_debug;
    //	echo "starting usage: " . memory_get_usage() . "<br>";
    // retrieve the time when the optimizer starts
    //	$started = microtime(true);
    $import_finished = false;
    $import_status = get_option('ewww_image_optimizer_import_status');
    $attachments = $wpdb->get_results("SELECT posts.ID,metas.meta_value FROM {$wpdb->postmeta} metas INNER JOIN {$wpdb->posts} posts ON posts.ID = metas.post_id WHERE posts.post_mime_type LIKE '%image%' AND metas.meta_key = '_wp_attachment_metadata' AND metas.meta_value LIKE '%ewww_image_optimizer%' LIMIT {$import_status['media']}, 100", ARRAY_N);
    //	echo "after loading metadata: " . memory_get_usage() . "<br>";
    if (count($attachments) === 0) {
        $import_finished = true;
    } else {
        $import_status['media'] += count($attachments);
    }
    $already_optimized = array();
    //	echo "after loading already optimized: " . memory_get_usage() . "<br>";
    $ewww_debug .= "importing " . count($attachments) . " attachments<br>";
    $insert_query = "INSERT INTO {$wpdb->ewwwio_images} (path, image_size, orig_size, results, temp) VALUES ";
    $rows = array();
    foreach ($attachments as $attachment) {
        $record = array();
        $gallery_type = 0;
        $id = $attachment[0];
        $meta = unserialize($attachment[1]);
        if (empty($attachment) || empty($attachment[1])) {
            continue;
        }
        list($attachment, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id);
        if ('ims_image' == get_post_type($id)) {
            $gallery_type = 6;
        }
        // make sure the meta actually contains data for ewww_image_optimizer
        if (empty($meta['ewww_image_optimizer'])) {
            $prev_results = '';
        } else {
            $prev_results = $meta['ewww_image_optimizer'];
        }
        $record = ewww_image_optimizer_import_file($attachment, $prev_results, $already_optimized);
        if (!empty($record)) {
            $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
        }
        // resized versions, so we can continue
        if (isset($meta['sizes'])) {
            $record = array();
            $ewww_debug .= "processing resizes<br>";
            // meta sizes don't contain a path, so we calculate one
            if ($gallery_type === 6) {
                $base_dir = dirname($attachment) . '/_resized/';
            } else {
                $base_dir = dirname($attachment) . '/';
            }
            foreach ($meta['sizes'] as $size => $data) {
                $resize_path = $base_dir . $data['file'];
                $ewww_debug .= "current resize: {$resize_path}<br>";
                // make sure the meta actually contains data for ewww_image_optimizer
                if (empty($data['ewww_image_optimizer'])) {
                    $prev_results = '';
                } else {
                    $prev_results = $data['ewww_image_optimizer'];
                }
                $record = ewww_image_optimizer_import_file($resize_path, $prev_results, $already_optimized);
                if (!empty($record)) {
                    $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
                }
            }
        }
        ewww_image_optimizer_debug_log();
    }
    $import_count = $import_status['media'];
    //nextgen import
    if ($import_finished && isset($import_status['nextgen'])) {
        $import_finished = false;
        $images = $wpdb->get_results("SELECT pid,meta_data,filename,galleryid FROM {$wpdb->nggpictures} WHERE meta_data LIKE '%ewww_image_optimizer%' LIMIT {$import_status['nextgen']}, 100", ARRAY_N);
        if (count($images) === 0) {
            $import_finished = true;
        } else {
            $import_status['nextgen'] += count($images);
        }
        $galleries = $wpdb->get_results("SELECT gid,path FROM {$wpdb->nggallery}", ARRAY_N);
        // creating the 'registry' object for working with nextgen
        $registry = C_Component_Registry::get_instance();
        // creating a database storage object from the 'registry' object
        $storage = $registry->get_utility('I_Gallery_Storage');
        $sizes = $storage->get_image_sizes();
        foreach ($images as $image) {
            $record = array();
            $gallery_path = '';
            foreach ($galleries as $gallery) {
                if ($gallery[0] == $image[3]) {
                    $gallery_path = trailingslashit($gallery[1]);
                }
            }
            $meta = unserialize($image[1]);
            // get an array of sizes available for the $image
            foreach ($sizes as $size) {
                // get the absolute path
                if ($size === 'full' || $size === 'original' || $size === 'image') {
                    if (!empty($meta['ewww_image_optimizer'])) {
                        $file_path = ABSPATH . $gallery_path . $image[2];
                        $ewww_debug .= "nextgen path generated: {$file_path}<br>";
                        $record = ewww_image_optimizer_import_file($file_path, $meta['ewww_image_optimizer'], $already_optimized);
                    }
                } elseif (!empty($meta[$size]['ewww_image_optimizer'])) {
                    if (isset($meta[$size]['filename'])) {
                        $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . $meta[$size]['filename'];
                    } else {
                        $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . 'thumbs_' . $image[2];
                    }
                    $ewww_debug .= "nextgen path generated: {$file_path}<br>";
                    $record = ewww_image_optimizer_import_file($file_path, $meta[$size]['ewww_image_optimizer'], $already_optimized);
                } elseif (!empty($meta['ewww_image_optimizer'])) {
                    if (isset($meta[$size]['filename'])) {
                        $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . $meta[$size]['filename'];
                    } else {
                        $file_path = ABSPATH . $gallery_path . trailingslashit('thumbs') . 'thumbs_' . $image[2];
                    }
                    $ewww_debug .= "nextgen path generated: {$file_path}<br>";
                    $meta[$size]['ewww_image_optimizer'] = __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    nggdb::update_image_meta($image[0], $meta);
                    $record = ewww_image_optimizer_import_file($file_path, $meta[$size]['ewww_image_optimizer'], $already_optimized);
                }
                if (!empty($record)) {
                    $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
                }
            }
            ewww_image_optimizer_debug_log();
        }
        $import_count += $import_status['nextgen'];
    }
    // fla gallery import
    if ($import_finished && isset($import_status['flag'])) {
        $import_finished = false;
        $images = $wpdb->get_results("SELECT pid,meta_data,filename,galleryid FROM {$wpdb->flagpictures} WHERE meta_data LIKE '%ewww_image_optimizer%' LIMIT {$import_status['flag']}, 100", ARRAY_N);
        $galleries = $wpdb->get_results("SELECT gid,path FROM {$wpdb->flaggallery}", ARRAY_N);
        if (count($images) === 0) {
            $import_finished = true;
        } else {
            $import_status['flag'] += count($images);
        }
        // need this file to work with flag meta
        foreach ($images as $image) {
            $record = array();
            $gallery_path = '';
            foreach ($galleries as $gallery) {
                if ($gallery[0] == $image[3]) {
                    $gallery_path = trailingslashit($gallery[1]);
                }
            }
            // get the image meta for the current ID
            $meta = unserialize($image[1]);
            $file_path = ABSPATH . $gallery_path . $image[2];
            $ewww_debug .= "flagallery path generated: {$file_path}<br>";
            if (!empty($meta['ewww_image_optimizer'])) {
                $record = ewww_image_optimizer_import_file($file_path, $meta['ewww_image_optimizer']);
                if (!empty($record)) {
                    $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
                }
                $thumb_path = ABSPATH . $gallery_path . 'thumbs/thumbs_' . $image[2];
                if (empty($meta['thumbnail']['ewww_image_optimizer'])) {
                    $meta['thumbnail']['ewww_image_optimizer'] = __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    // update the image metadata in the db
                    flagdb::update_image_meta($id, $meta);
                    $record = ewww_image_optimizer_import_file($thumb_path, __('Unknown Savings', EWWW_IMAGE_OPTIMIZER_DOMAIN));
                } else {
                    $record = ewww_image_optimizer_import_file($thumb_path, $meta['thumbnail']['ewww_image_optimizer']);
                }
                if (!empty($record)) {
                    $rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
                }
            }
            ewww_image_optimizer_debug_log();
        }
        $import_count += $import_status['flag'];
    }
    if (!empty($rows)) {
        $wpdb->query($insert_query . implode(', ', $rows));
        $rows = array();
    }
    //	echo "after we are done: " . memory_get_usage() . "<br>";
    if ($import_finished) {
        update_option('ewww_image_optimizer_imported', true);
        update_option('ewww_image_optimizer_import_status', '');
        $wpdb->query("ALTER TABLE {$wpdb->ewwwio_images} DROP temp");
        echo "<b>" . __('Finished importing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b>";
    } else {
        update_option('ewww_image_optimizer_import_status', $import_status);
        echo $import_count;
    }
    //	$elapsed = microtime(true) - $started;
    //	echo "<br>importing images took $elapsed seconds<br>";
    die;
}
 function ewww_flag_bulk_loop()
 {
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
         wp_die(__('Cheatin&#8217; eh?'));
     }
     // need this file to work with flag meta
     require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
     // record the starting time for the current image (in microseconds)
     $started = microtime(true);
     $id = $_POST['attachment'];
     // get the image meta for the current ID
     $meta = new flagMeta($id);
     $file_path = $meta->image->imagePath;
     // optimize the full-size version
     $fres = ewww_image_optimizer($file_path, 3, false, false);
     // and store the results in the metadata
     flagdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
     // let the user know what happened
     printf("<p>Optimized image: <strong>%s</strong><br>", esc_html($meta->image->filename));
     printf("Full size – %s<br>", $fres[1]);
     $thumb_path = $meta->image->thumbPath;
     // optimize the thumbnail
     $tres = ewww_image_optimizer($thumb_path, 3, false, true);
     // and let the user know the results
     printf("Thumbnail – %s<br>", $tres[1]);
     // determine how much time the image took to process
     $elapsed = microtime(true) - $started;
     // and output it to the user
     echo "Elapsed: " . round($elapsed, 3) . " seconds</p>";
     // retrieve the list of attachments left to work on
     $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
     // take the first image off the list
     array_shift($attachments);
     // and send the list back to the db
     update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
     die;
 }
Ejemplo n.º 10
0
Credits:
 jCrop : Kelly Hallman <*****@*****.**> | http://deepliquid.com/content/Jcrop.html
 
**/
require_once dirname(dirname(__FILE__)) . '/flag-config.php';
require_once FLAG_ABSPATH . '/lib/image.php';
if (!is_user_logged_in()) {
    die(__('Cheatin&#8217; uh?'));
}
if (!current_user_can('FlAG Manage gallery')) {
    die(__('Cheatin&#8217; uh?'));
}
global $wpdb;
$id = (int) $_GET['id'];
// let's get the image data
$picture = flagdb::find_image($id);
include_once flagGallery::graphic_library();
$flag_options = get_option('flag_options');
$thumb = new flag_Thumbnail($picture->imagePath, TRUE);
$thumb->resize(350, 350);
// we need the new dimension
$resizedPreviewInfo = $thumb->newDimensions;
$thumb->destruct();
$preview_image = FLAG_URLPATH . 'flagshow.php?pid=' . $picture->pid . '&amp;width=350&amp;height=350';
$imageInfo = @getimagesize($picture->imagePath);
$rr = round($imageInfo[0] / $resizedPreviewInfo['newWidth'], 2);
$WidthHtmlPrev = $flag_options['thumbWidth'];
$HeightHtmlPrev = $flag_options['thumbHeight'];
if ($flag_options['thumbFix'] == 1) {
    $WidthHtmlPrev = $flag_options['thumbWidth'];
    $HeightHtmlPrev = $flag_options['thumbHeight'];
Ejemplo n.º 11
0
// Load wp-config
if (!defined('ABSPATH')) {
    require_once dirname(__FILE__) . '/flag-config.php';
}
// reference thumbnail class
include_once flagGallery::graphic_library();
include_once 'lib/core.php';
// get the plugin options
$flag_options = get_option('flag_options');
// Some parameters from the URL
if (!isset($_GET['pid'])) {
    exit;
}
$pictureID = intval($_GET['pid']);
if (!$pictureID) {
    exit;
}
// let's get the image data
$picture = flagdb::find_image($pictureID);
if (!is_object($picture)) {
    exit;
}
$thumb = new flag_Thumbnail($picture->imagePath);
// Resize if necessary
if (!empty($_GET['width']) || !empty($_GET['height'])) {
    $thumb->resize(intval($_GET['width']), intval($_GET['height']));
}
// Show thumbnail
$thumb->show();
$thumb->destruct();
exit;
Ejemplo n.º 12
0
function media_upload_flag_form()
{
    global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $flag;
    media_upload_header();
    $post_id = intval($_REQUEST['post_id']);
    $galleryID = 0;
    $total = 1;
    $picarray = false;
    $form_action_url = site_url("wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=flag&post_id={$post_id}", 'admin');
    // Get number of images in gallery
    if (isset($_REQUEST['select_gal']) && $_REQUEST['select_gal']) {
        $galleryID = (int) $_REQUEST['select_gal'];
        $total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}'");
    }
    // Build navigation
    $_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 1;
    if ($_GET['paged'] < 1) {
        $_GET['paged'] = 1;
    }
    $start = ($_GET['paged'] - 1) * 10;
    if ($start < 1) {
        $start = 0;
    }
    // Get the images
    if ($galleryID != 0) {
        $picarray = $wpdb->get_col("SELECT pid FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}' AND exclude != 1 ORDER BY {$flag->options['galSort']} {$flag->options['galSortDir']} LIMIT {$start}, 10 ");
    }
    ?>

<form id="filter" action="" method="get">
<input type="hidden" name="type" value="<?php 
    echo esc_attr($GLOBALS['type']);
    ?>
" />
<input type="hidden" name="tab" value="<?php 
    echo esc_attr($GLOBALS['tab']);
    ?>
" />
<input type="hidden" name="post_id" value="<?php 
    echo (int) $post_id;
    ?>
" />

<div class="tablenav">
	<?php 
    $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'total' => ceil($total / 10), 'current' => $_GET['paged']));
    if ($page_links) {
        echo "<div class='tablenav-pages'>{$page_links}</div>";
    }
    ?>
	
	<div class="alignleft actions">
		<select id="select_gal" name="select_gal" style="width:200px;">;
			<option value="0" <?php 
    selected('0', $galleryID);
    ?>
 ><?php 
    _e('No gallery', "flag");
    ?>
</option>
			<?php 
    // Show gallery selection
    $gallerylist = $wpdb->get_results("SELECT * FROM {$wpdb->flaggallery} ORDER BY gid ASC");
    if (is_array($gallerylist)) {
        foreach ($gallerylist as $gallery) {
            $selected = $gallery->gid == $galleryID ? ' selected="selected"' : "";
            echo '<option value="' . $gallery->gid . '"' . $selected . ' >' . $gallery->title . '</option>' . "\n";
        }
    }
    ?>
		</select>
		<input type="submit" id="show-gallery" value="<?php 
    _e('Select &#187;', 'flag');
    ?>
" class="button-secondary" />
	</div>
	<br style="clear:both;" />
</div>
</form>

<form enctype="multipart/form-data" method="post" action="<?php 
    echo esc_attr($form_action_url);
    ?>
" class="media-upload-form" id="library-form">

	<?php 
    wp_nonce_field('flag-media-form');
    ?>

	<script type="text/javascript">
	<!--
	jQuery(function($){
		var preloaded = $(".media-item.preloaded");
		if ( preloaded.length > 0 ) {
			preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
			updateMediaForm();
		}
	});
	-->
	</script>
	
	<div id="media-items">
	<?php 
    if (is_array($picarray)) {
        foreach ($picarray as $picid) {
            //TODO:Reduce SQL Queries
            $picture = flagdb::find_image($picid);
            ?>
			<div id='media-item-<?php 
            echo $picid;
            ?>
' class='media-item preloaded'>
			  <div class='filename'></div>
			  <a class='toggle describe-toggle-on' href='#'><?php 
            _e('Show', "flag");
            ?>
</a>
			  <a class='toggle describe-toggle-off' href='#'><?php 
            _e('Hide', "flag");
            ?>
</a>
			  <div class='filename new'><?php 
            echo empty($picture->alttext) ? wp_html_excerpt($picture->filename, 60) : stripslashes(wp_html_excerpt($picture->alttext, 60));
            ?>
</div>
			  <table class='slidetoggle describe startclosed'><tbody>
				  <tr>
					<td rowspan='4'><img class='thumbnail' alt='<?php 
            echo esc_attr($picture->alttext);
            ?>
' src='<?php 
            echo esc_attr($picture->thumbURL);
            ?>
'/></td>
					<td><?php 
            _e('Image ID:', "flag");
            echo $picid;
            ?>
</td>
				  </tr>
				  <tr><td><?php 
            echo esc_attr($picture->filename);
            ?>
</td></tr>
				  <tr><td><?php 
            echo esc_html(stripslashes($picture->alttext));
            ?>
</td></tr>
				  <tr><td>&nbsp;</td></tr>
				  <tr>
					<td class="label"><label for="image[<?php 
            echo $picid;
            ?>
][alttext]"><?php 
            _e('Alt/Title text', "flag");
            ?>
</label></td>
					<td class="field"><input id="image[<?php 
            echo $picid;
            ?>
][alttext]" name="image[<?php 
            echo $picid;
            ?>
][alttext]" value="<?php 
            echo esc_html(stripslashes($picture->alttext));
            ?>
" type="text"/></td>
				  </tr>	
				  <tr>
					<td class="label"><label for="image[<?php 
            echo $picid;
            ?>
][description]"><?php 
            _e("Description", "flag");
            ?>
</label></td>
						<td class="field"><textarea name="image[<?php 
            echo $picid;
            ?>
][description]" id="image[<?php 
            echo $picid;
            ?>
][description]"><?php 
            echo esc_html(stripslashes($picture->description));
            ?>
</textarea></td>
				  </tr>
					<tr class="align">
						<td class="label"><label for="image[<?php 
            echo $picid;
            ?>
][align]"><?php 
            _e("Alignment");
            ?>
</label></td>
						<td class="field">
							<input name="image[<?php 
            echo $picid;
            ?>
][align]" id="image-align-none-<?php 
            echo $picid;
            ?>
" checked="checked" value="none" type="radio" />
							<label for="image-align-none-<?php 
            echo $picid;
            ?>
" class="align image-align-none-label"><?php 
            _e("None");
            ?>
</label>
							<input name="image[<?php 
            echo $picid;
            ?>
][align]" id="image-align-left-<?php 
            echo $picid;
            ?>
" value="left" type="radio" />
							<label for="image-align-left-<?php 
            echo $picid;
            ?>
" class="align image-align-left-label"><?php 
            _e("Left");
            ?>
</label>
							<input name="image[<?php 
            echo $picid;
            ?>
][align]" id="image-align-center-<?php 
            echo $picid;
            ?>
" value="center" type="radio" />
							<label for="image-align-center-<?php 
            echo $picid;
            ?>
" class="align image-align-center-label"><?php 
            _e("Center");
            ?>
</label>
							<input name="image[<?php 
            echo $picid;
            ?>
][align]" id="image-align-right-<?php 
            echo $picid;
            ?>
" value="right" type="radio" />
							<label for="image-align-right-<?php 
            echo $picid;
            ?>
" class="align image-align-right-label"><?php 
            _e("Right");
            ?>
</label>
						</td>
					</tr>
					<tr class="image-size">
						<th class="label"><label for="image[<?php 
            echo $picid;
            ?>
][size]"><span class="alignleft"><?php 
            _e("Size");
            ?>
</span></label>
						</th>
						<td class="field">
							<input name="image[<?php 
            echo $picid;
            ?>
][size]" id="image-size-thumb-<?php 
            echo $picid;
            ?>
" type="radio" checked="checked" value="thumbnail" />
							<label for="image-size-thumb-<?php 
            echo $picid;
            ?>
"><?php 
            _e("Thumbnail");
            ?>
</label>
							<input name="image[<?php 
            echo $picid;
            ?>
][size]" id="image-size-full-<?php 
            echo $picid;
            ?>
" type="radio" value="full" />
							<label for="image-size-full-<?php 
            echo $picid;
            ?>
"><?php 
            _e("Full size");
            ?>
</label>
						</td>
					</tr>
				   <tr class="submit">
						<td>
							<input type="hidden"  name="image[<?php 
            echo $picid;
            ?>
][thumb]" value="<?php 
            echo $picture->thumbURL;
            ?>
" />
							<input type="hidden"  name="image[<?php 
            echo $picid;
            ?>
][url]" value="<?php 
            echo $picture->imageURL;
            ?>
" />
						</td>
						<td class="savesend"><button type="submit" class="button" value="1" name="send[<?php 
            echo $picid;
            ?>
]"><?php 
            echo esc_attr(__('Insert into Post'));
            ?>
</button></td>
				   </tr>
			  </tbody></table>
			</div>
		<?php 
        }
    }
    ?>
	</div>
	<p class="ml-submit">
		<input type="submit" class="button savebutton" name="save" value="<?php 
    _e('Save all changes', 'flag');
    ?>
" />
	</p>
	<input type="hidden" name="post_id" id="post_id" value="<?php 
    echo (int) $post_id;
    ?>
" />
	<input type="hidden" name="select_gal" id="select_gal" value="<?php 
    echo (int) $galleryID;
    ?>
" />
</form>

<?php 
}
Ejemplo n.º 13
0
 /**
  * Get the last images registered in the database with a maximum number of $limit results
  *
  * @param integer $page
  * @param integer $limit
  * @param int $exclude
  * @param int $galleryId Only look for images with this gallery id, or in all galleries if id is 0
  * @param string $orderby
  * @param string $orderby is one of "id" (default, order by pid), "date" (order by exif date), sort (order by user sort order)
  * @return array
  */
 function find_last_images($page = 0, $limit = 30, $exclude = 0, $galleryId = 0, $orderby = "id")
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     // Check for the exclude setting
     $exclude_clause = $exclude ? ' AND exclude<>1 ' : '';
     $offset = (int) $page * $limit;
     $galleryId = (int) $galleryId;
     $gallery_clause = $galleryId === 0 ? '' : ' AND galleryid = ' . $galleryId . ' ';
     // default order by pid
     $order = 'pid DESC';
     switch ($orderby) {
         case 'date':
             $order = 'imagedate DESC';
             break;
         case 'sort':
             $order = 'sortorder ASC';
             break;
     }
     $result = array();
     $gallery_cache = array();
     // Query database
     $images = $wpdb->get_results("SELECT * FROM {$wpdb->flagpictures} WHERE 1=1 {$exclude_clause} {$gallery_clause} ORDER BY {$order} LIMIT {$offset}, {$limit}");
     // Build the object from the query result
     if ($images) {
         foreach ($images as $key => $image) {
             // cache a gallery , so we didn't need to lookup twice
             if (!array_key_exists($image->galleryid, $gallery_cache)) {
                 $gallery_cache[$image->galleryid] = flagdb::find_gallery($image->galleryid);
             }
             // Join gallery information with picture information
             foreach ($gallery_cache[$image->galleryid] as $index => $value) {
                 $image->{$index} = $value;
             }
             // Now get the complete image data
             $result[$key] = new flagImage($image);
         }
     }
     return $result;
 }
Ejemplo n.º 14
0
function ewww_image_optimizer_bulk_flag($delay = 0)
{
    $ids = null;
    // if there is an operation to resume, get those IDs from the db
    if (get_option('ewww_image_optimizer_bulk_flag_resume')) {
        $ids = get_option('ewww_image_optimizer_bulk_flag_attachments');
        // otherwise, if we are on the main bulk optimize page, just get all the IDs available
    } else {
        global $wpdb;
        $ids = $wpdb->get_col("SELECT pid FROM {$wpdb->flagpictures} ORDER BY sortorder ASC");
        // store the IDs to optimize in the options table of the db
        update_option('ewww_image_optimizer_bulk_flag_attachments', $ids, false);
    }
    // set the resume flag to indicate the bulk operation is in progress
    update_option('ewww_image_optimizer_bulk_flag_resume', 'true');
    // need this file to work with flag meta
    require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
    if (!ewww_image_optimizer_iterable($ids)) {
        WP_CLI::line(__('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
        return;
    }
    foreach ($ids as $id) {
        sleep($delay);
        // record the starting time for the current image (in microseconds)
        $started = microtime(true);
        // retrieve the meta for the current ID
        $meta = new flagMeta($id);
        $file_path = $meta->image->imagePath;
        // optimize the full-size version
        $fres = ewww_image_optimizer($file_path, 3, false, false, true);
        $meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
        // let the user know what happened
        WP_CLI::line(__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " " . esc_html($meta->image->filename));
        WP_CLI::line(sprintf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($fres[1])));
        if (!empty($meta->image->meta_data['webview'])) {
            // determine path of the webview
            $web_path = $meta->image->webimagePath;
            $wres = ewww_image_optimizer($web_path, 3, false, true);
            $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
            WP_CLI::line(sprintf(__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($wres[1])));
        }
        $thumb_path = $meta->image->thumbPath;
        // optimize the thumbnail
        $tres = ewww_image_optimizer($thumb_path, 3, false, true);
        $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
        // and let the user know the results
        WP_CLI::line(sprintf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($tres[1])));
        flagdb::update_image_meta($id, $meta->image->meta_data);
        // determine how much time the image took to process
        $elapsed = microtime(true) - $started;
        // and output it to the user
        WP_CLI::line(sprintf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN), $elapsed));
        // retrieve the list of attachments left to work on
        $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
        // take the first image off the list
        if (!empty($attachments)) {
            array_shift($attachments);
        }
        // and send the list back to the db
        update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments, false);
    }
    // reset the bulk flags in the db
    update_option('ewww_image_optimizer_bulk_flag_resume', '');
    update_option('ewww_image_optimizer_bulk_flag_attachments', '', false);
    // and let the user know we are done
    WP_CLI::success(__('Finished Optimization!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
Ejemplo n.º 15
0
 function ewww_flag_bulk_loop()
 {
     global $ewww_defer;
     $ewww_defer = false;
     $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
     if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
         wp_die(__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
     }
     if (!empty($_REQUEST['ewww_sleep'])) {
         sleep($_REQUEST['ewww_sleep']);
     }
     // need this file to work with flag meta
     require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
     // record the starting time for the current image (in microseconds)
     $started = microtime(true);
     $id = $_POST['ewww_attachment'];
     // get the image meta for the current ID
     $meta = new flagMeta($id);
     $file_path = $meta->image->imagePath;
     // optimize the full-size version
     $fres = ewww_image_optimizer($file_path, 3, false, false, true);
     global $ewww_exceed;
     if (!empty($ewww_exceed)) {
         echo '-9exceeded';
         die;
     }
     $meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
     // let the user know what happened
     printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
     printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]);
     if (!empty($meta->image->meta_data['webview'])) {
         // determine path of the webview
         $web_path = $meta->image->webimagePath;
         $wres = ewww_image_optimizer($web_path, 3, false, true);
         $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
         printf(__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $wres[1]);
     }
     $thumb_path = $meta->image->thumbPath;
     // optimize the thumbnail
     $tres = ewww_image_optimizer($thumb_path, 3, false, true);
     $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
     // and let the user know the results
     printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]);
     flagdb::update_image_meta($id, $meta->image->meta_data);
     // determine how much time the image took to process
     $elapsed = microtime(true) - $started;
     // and output it to the user
     printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
     // retrieve the list of attachments left to work on
     $attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
     // take the first image off the list
     if (!empty($attachments)) {
         array_shift($attachments);
     }
     // and send the list back to the db
     update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
     die;
 }
Ejemplo n.º 16
0
 function post_processor_images()
 {
     global $wpdb, $flag, $flagdb;
     do_action('flag_manage_post_processor_images');
     // bulk update in a single gallery
     if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) {
         check_admin_referer('flag_updategallery');
         switch ($_POST['bulkaction']) {
             case 'no_action':
                 break;
             case 'delete_images':
                 if (is_array($_POST['doaction'])) {
                     $delete_pic = false;
                     foreach ($_POST['doaction'] as $imageID) {
                         $image = $flagdb->find_image($imageID);
                         if ($image) {
                             if ($flag->options['deleteImg']) {
                                 @unlink($image->imagePath);
                                 @unlink($image->webimagePath);
                                 @unlink($image->thumbPath);
                             }
                             $delete_pic = flagdb::delete_image($image->pid);
                         }
                     }
                     if ($delete_pic) {
                         flagGallery::show_message(__('Pictures deleted successfully ', 'flash-album-gallery'));
                     }
                 }
                 break;
             case 'import_meta':
                 flagAdmin::do_ajax_operation('import_metadata', $_POST['doaction'], __('Import metadata', 'flash-album-gallery'));
                 break;
             case 'copy_meta':
                 flagAdmin::do_ajax_operation('copy_metadata', $_POST['doaction'], __('Copy metadata to image Description', 'flash-album-gallery'));
                 break;
             case 'webview_images':
                 flagAdmin::do_ajax_operation('webview_image', $_POST['doaction'], __('Creating images optimized for web', 'flash-album-gallery'));
                 break;
             case 'reset_counters':
                 if (is_array($_POST['doaction'])) {
                     $images = $flagdb->find_images_in_list($_POST['doaction']);
                     foreach ($images as $image) {
                         $img_id = $image->pid;
                         $wpdb->query("UPDATE {$wpdb->flagpictures} SET hitcounter = '0', total_votes = '0' WHERE pid = {$img_id}");
                     }
                 }
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_ResizeImages'])) {
         check_admin_referer('flag_thickbox_form');
         //save the new values for the next operation
         $flag->options['imgWidth'] = (int) $_POST['imgWidth'];
         $flag->options['imgHeight'] = (int) $_POST['imgHeight'];
         update_option('flag_options', $flag->options);
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         flagAdmin::do_ajax_operation('resize_image', $pic_ids, __('Resize images', 'flash-album-gallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_NewThumbnail'])) {
         check_admin_referer('flag_thickbox_form');
         //save the new values for the next operation
         $flag->options['thumbWidth'] = (int) $_POST['thumbWidth'];
         $flag->options['thumbHeight'] = (int) $_POST['thumbHeight'];
         $flag->options['thumbFix'] = (bool) $_POST['thumbFix'];
         update_option('flag_options', $flag->options);
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         flagAdmin::do_ajax_operation('create_thumbnail', $pic_ids, __('Create new thumbnails', 'flash-album-gallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_SelectGallery'])) {
         check_admin_referer('flag_thickbox_form');
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         $pic_ids = array_filter($pic_ids, 'intval');
         $dest_gid = (int) $_POST['dest_gid'];
         switch ($_POST['TB_bulkaction']) {
             case 'copy_to':
                 // Copy images
                 flagAdmin::copy_images($pic_ids, $dest_gid);
                 break;
             case 'move_to':
                 // Move images
                 flagAdmin::move_images($pic_ids, $dest_gid);
                 break;
         }
     }
     if (isset($_POST['updatepictures'])) {
         // Update pictures
         check_admin_referer('flag_updategallery');
         $gallery_title = esc_html($_POST['title']);
         $gallery_path = esc_attr(str_replace('..', '', $_POST['path']));
         $gallery_desc = esc_html($_POST['gallerydesc']);
         $gallery_preview = (int) $_POST['previewpic'];
         $wpdb->query("UPDATE {$wpdb->flaggallery} SET title= '{$gallery_title}', path= '{$gallery_path}', galdesc = '{$gallery_desc}', previewpic = '{$gallery_preview}' WHERE gid = '{$this->gid}'");
         if (isset($_POST['author'])) {
             $gallery_author = (int) $_POST['author'];
             $wpdb->query("UPDATE {$wpdb->flaggallery} SET author = '{$gallery_author}' WHERE gid = '{$this->gid}'");
         }
         $this->update_pictures();
         //hook for other plugin to update the fields
         do_action('flag_update_gallery', $this->gid, $_POST);
         flagGallery::show_message(__('Update successful', "flash-album-gallery"));
     }
     if (isset($_POST['scanfolder'])) {
         // Rescan folder
         check_admin_referer('flag_updategallery');
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->flaggallery} WHERE gid = '{$this->gid}' ");
         flagAdmin::import_gallery($gallerypath);
     }
 }
Ejemplo n.º 17
0
function ewww_image_optimizer_defer()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_defer;
    $ewww_defer = false;
    $deferred_attachments = get_option('ewww_image_optimizer_defer_attachments');
    foreach ($deferred_attachments as $image) {
        list($type, $id) = explode(',', $image, 2);
        switch ($type) {
            case 'media':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $meta = wp_get_attachment_metadata($id, true);
                // do the optimization for the current attachment (including resizes)
                $meta = ewww_image_optimizer_resize_from_meta_data($meta, $id, false);
                // update the metadata for the current attachment
                wp_update_attachment_metadata($id, $meta);
                break;
            case 'nextgen2':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                // creating the 'registry' object for working with nextgen
                $registry = C_Component_Registry::get_instance();
                // creating a database storage object from the 'registry' object
                $storage = $registry->get_utility('I_Gallery_Storage');
                // get an image object
                $ngg_image = $storage->object->_image_mapper->find($id);
                ewwwngg::ewww_added_new_image($ngg_image, $storage);
                break;
                //			case 'nextgen1':
                //				ewwwio_debug_message( "processing deferred $type: $id" );
                //				break;
            //			case 'nextgen1':
            //				ewwwio_debug_message( "processing deferred $type: $id" );
            //				break;
            case 'nextcellent':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewwwngg::ewww_ngg_optimize($id);
                break;
            case 'flag':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $flag_image = flagdb::find_image($id);
                ewwwflag::ewww_added_new_image($flag_image);
                break;
            case 'file':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewww_image_optimizer($id);
                break;
            default:
                ewwwio_debug_message("unknown type in deferrred queue: {$type}, {$id}");
        }
        ewww_image_optimizer_remove_deferred_attachment($image);
        ewww_image_optimizer_debug_log();
    }
    ewwwio_memory(__FUNCTION__);
    return;
}