Example #1
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;
}
Example #2
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;
}