示例#1
0
// Query the pictures table for unique pids that only reside in the pictures table, but not in the cache table
$result = cpg_db_query("SELECT DISTINCT * FROM {$CONFIG['TABLE_PICTURES']} WHERE pid NOT IN (SELECT {$CONFIG['TABLE_PREFIX']}plugin_thumb_rotate.pid FROM {$CONFIG['TABLE_PREFIX']}plugin_thumb_rotate) LIMIT 1");
// Loop if there are still files to cache
$remaining_files = $image_files_total - $cached_files_total;
if ($remaining_files > 0) {
    $meta_refresh = '<meta http-equiv="refresh" content="' . $CONFIG['plugin_thumb_rotate_timelimit'] . '; URL=index.php?file=thumb_rotate/batch_fill" />';
} else {
    $message = cpgStoreTempMessage($lang_plugin_thumb_rotate['batch_fill'] . ': ' . $lang_common['done']);
    $meta_refresh = '<meta http-equiv="refresh" content="0; URL=index.php?file=thumb_rotate/index&message_id=' . $message . '&message_icon=success" />';
}
pageheader($lang_plugin_thumb_rotate['config_name'] . '-' . $lang_plugin_thumb_rotate['batch_fill'], $meta_refresh);
$CURRENT_PIC_DATA = mysql_fetch_assoc($result);
$CURRENT_PIC_DATA['extension'] = ltrim(substr($CURRENT_PIC_DATA['filename'], strrpos($CURRENT_PIC_DATA['filename'], '.')), '.');
$CURRENT_PIC_DATA['filename_without_extension'] = str_replace('.' . $CURRENT_PIC_DATA['extension'], '', $CURRENT_PIC_DATA['filename']);
if ($remaining_files > 0) {
    $created_image_array = thumb_rotate_image_create($CURRENT_PIC_DATA);
}
if ($created_image_array['path'] != '') {
    $result = cpg_db_query("INSERT IGNORE INTO {$CONFIG['TABLE_PREFIX']}plugin_thumb_rotate ( `pid` , `filepath`, `width`, `height` ) VALUES ('{$CURRENT_PIC_DATA['pid']}', '{$created_image_array['path']}', '{$created_image_array['width']}', '{$created_image_array['height']}');");
    $remaining_files--;
}
$remaining_output = theme_display_bar($remaining_files, $image_files_total, 600, '', '', sprintf($lang_plugin_thumb_rotate['x_files_remaining'], '/' . $image_files_total, 'red', 'green'));
// Display the rotated thumb we just created
starttable('100%', $thumb_rotate_icon_array['batch'] . $lang_plugin_thumb_rotate['batch_fill'], 3);
$max_dimension = max($CONFIG['thumb_width'], $CONFIG['thumb_height']) + 10;
$random = uniqid(rand());
if (defined('THEME_HAS_PROGRESS_GRAPHICS')) {
    $prefix = $THEME_DIR;
} else {
    $prefix = '';
}
示例#2
0
function thumb_rotate_thumb_display($params)
{
    global $CONFIG;
    if ($CONFIG['plugin_thumb_rotate_admin_only'] == 1 && !GALLERY_ADMIN_MODE) {
        return $params;
    }
    $gd_extension_array = array('jpg', 'jpeg', 'gif', 'png');
    // Create the super cage
    $superCage = Inspekt::makeSuperCage();
    // Extract the needed information from the thumbnail params array
    $link_target_array = parse_url(str_replace('&amp;', '&', $params['{LINK_TGT}']));
    parse_str($link_target_array['query'], $link_target_param_array);
    unset($link_target_array);
    $pid = $link_target_param_array['pid'];
    $pos = $link_target_param_array['pos'];
    $album = $link_target_param_array['album'];
    unset($link_target_param_array);
    if (!$album) {
        // Try to extract the album from the URL param
        if ($superCage->get->keyExists('album') == TRUE) {
            $album = $superCage->get->getAlnum('album');
        }
    }
    if (is_int($album) != TRUE) {
        unset($album);
    }
    // Extract the needed information about the individual pic using the built-in methods of coppermine (code taken from displayimage.php)
    if ($pos < 0 && !$pid) {
        $pid = -$pos;
    }
    if (!$album) {
        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE pid='{$pid}' {$FORBIDDEN_SET} LIMIT 1");
        if (mysql_num_rows($result) == 0) {
            cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
        }
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        $album = $row['aid'];
    }
    if (!$pos) {
        $pos = get_pic_pos($album, $pid);
    }
    $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
    $CURRENT_PIC_DATA = $pic_data[0];
    $CURRENT_PIC_DATA['extension'] = ltrim(substr($CURRENT_PIC_DATA['filename'], strrpos($CURRENT_PIC_DATA['filename'], '.')), '.');
    $CURRENT_PIC_DATA['filename_without_extension'] = str_replace('.' . $CURRENT_PIC_DATA['extension'], '', $CURRENT_PIC_DATA['filename']);
    if ($CONFIG['thumb_use'] == 'any' || $CONFIG['thumb_use'] == 'ex') {
        $CURRENT_PIC_DATA['maxthumb'] = max($CONFIG['thumb_width'], $CONFIG['thumb_height']);
    } elseif ($CONFIG['thumb_use'] == 'ht') {
        $CURRENT_PIC_DATA['maxthumb'] = $CONFIG['thumb_height'];
    } else {
        $CURRENT_PIC_DATA['maxthumb'] = $CONFIG['thumb_width'];
    }
    $thumb_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CURRENT_PIC_DATA['maxthumb']);
    $CURRENT_PIC_DATA['twidth'] = $thumb_size['width'];
    $CURRENT_PIC_DATA['theight'] = $thumb_size['height'];
    // End Extract - we now have all needed data concerning the individual pic
    // Let's determine if the file is cached already
    $rotate_image_create_file = 0;
    $rotate_image_create_dbrecord = 0;
    $result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PREFIX']}plugin_thumb_rotate WHERE pid = '{$pid}'");
    if (!mysql_num_rows($result)) {
        // There is NO cached record in the database --- start
        mysql_free_result($result);
        $rotate_image_create_file = 1;
        $rotate_image_create_dbrecord = 1;
        // There is NO cached record in the database --- end
    } else {
        // There IS a cached record in the database --- start
        $row = mysql_fetch_array($result);
        $rotate_image_create_dbrecord = 0;
        if (file_exists($CONFIG['fullpath'] . $row['filepath'])) {
            $rotate_image_create_file = 0;
        } else {
            $rotate_image_create_file = 1;
        }
        mysql_free_result($result);
        // There IS a cached record in the database --- end
    }
    // Apply the delay --- start
    if ($CONFIG['plugin_thumb_rotate_timelimit'] > 0) {
        if (time() - $CONFIG['plugin_thumb_rotate_timestamp'] > $CONFIG['plugin_thumb_rotate_timelimit']) {
            // The time stamp difference is greater than the set config parameter, so we can proceed with thumbnail creation
        } else {
            // The time stamp difference is smaller - don't process the thumb to save resources
            $rotate_image_create_file = 0;
            $rotate_image_create_dbrecord = 0;
        }
    }
    // Apply the delay --- end
    if ($rotate_image_create_file == 1) {
        $created_image_array = thumb_rotate_image_create($CURRENT_PIC_DATA);
        if ($CONFIG['plugin_thumb_rotate_timelimit'] > 0) {
            // Write the current time stamp to the db
            $time = time();
            cpg_db_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value='{$time}' WHERE name='plugin_thumb_rotate_timestamp'");
        }
    }
    if ($rotate_image_create_dbrecord == 1 && $created_image_array['path'] != '') {
        $result = cpg_db_query("INSERT IGNORE INTO {$CONFIG['TABLE_PREFIX']}plugin_thumb_rotate ( `pid` , `filepath`, `width`, `height` ) VALUES ('{$pid}', '{$created_image_array['path']}', '{$created_image_array['width']}', '{$created_image_array['height']}');");
    }
    if (!isset($created_image_array)) {
        $created_image_array['width'] = $row['width'];
        $created_image_array['height'] = $row['height'];
    }
    // Finally, let's manipulate the thumbnail HTML
    if (file_exists($CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CONFIG['plugin_thumb_rotate_thumb_pfx'] . $CURRENT_PIC_DATA['filename_without_extension'] . '.' . $CONFIG['plugin_thumb_rotate_filetype'])) {
        if (in_array(strtolower($CURRENT_PIC_DATA['extension']), $gd_extension_array)) {
            $params['{THUMB}'] = str_replace($CURRENT_PIC_DATA['filepath'] . $CONFIG['thumb_pfx'] . $CURRENT_PIC_DATA['filename'], $CURRENT_PIC_DATA['filepath'] . $CONFIG['plugin_thumb_rotate_thumb_pfx'] . $CURRENT_PIC_DATA['filename_without_extension'] . '.' . $CONFIG['plugin_thumb_rotate_filetype'], $params['{THUMB}']);
            $params['{THUMB}'] = str_replace('width="' . $thumb_size['width'] . '"', 'width="' . $created_image_array['width'] . '"', $params['{THUMB}']);
            // Replace the existing width attributes
            $params['{THUMB}'] = str_replace('height="' . $thumb_size['height'] . '"', 'height="' . $created_image_array['height'] . '"', $params['{THUMB}']);
            // Replace the existing height attributes
        } else {
            $params['{THUMB}'] = str_replace($THEME_DIR . 'images/thumbs/thumb_' . $CURRENT_PIC_DATA['extension'] . '.png', $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CONFIG['plugin_thumb_rotate_thumb_pfx'] . $CURRENT_PIC_DATA['filename_without_extension'] . '.' . $CONFIG['plugin_thumb_rotate_filetype'], $params['{THUMB}']);
            $params['{THUMB}'] = str_replace('images/thumbs/thumb_' . $CURRENT_PIC_DATA['extension'] . '.png', $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CONFIG['plugin_thumb_rotate_thumb_pfx'] . $CURRENT_PIC_DATA['filename_without_extension'] . '.' . $CONFIG['plugin_thumb_rotate_filetype'], $params['{THUMB}']);
        }
        $params['{THUMB}'] = str_replace('class="image"', 'class="image" style="border:none;"', $params['{THUMB}']);
        // Remove border CSS
    }
    //$params['{THUMB}'] .= $created_image_array['height'];
    return $params;
}