View source
<?php
define('IMAGE_UNMACHINED', 'image_raw');
define('IMAGE_HALFPROCESSED', 'image_halfwork');
define('IMAGE_PROCESSED', 'image_processed');
function image_fupload_help($path, $arg) {
switch ($path) {
case 'admin/help#image_fupload':
$output = '<p>' . t("The Image FUpload module is used to provide an alternate upload form to image module itself.") . '</p>';
$output .= '<p>' . t("This is a great advantage because multiple images can be selected with one click which are automatically uploaded and processed without any further user interaction. Additionally, this module fully integrates in image module. Consequently, all settings made by image module are observed (thumb creation, file size limit etc.).") . '</p>';
$output .= '<p>' . t("Image FUpload administration allows to define some characters which are replaced in the node title by a whitespace. In addition to that, the option can be selected to show a link to the original upload form to those users whose browser doesn't support this Flash / JS solution.") . '</p>';
$output .= t('<p>You can</p>
<ul>
<li>create images using F(lash)Upload at <a href="!node-create-image">node >> create >> image</a>.</li>
<li>configure Image FUpload settings at <a href="!admin-settings-image-fupload">administer >> settings >> image >> image_fupload</a>.</li>
', array(
'!node-create-image' => url('node/add/image'),
'!admin-image-galleries' => url('admin/image/galleries'),
'!admin-settings-image-fupload' => url('admin/settings/image/image_fupload'),
)) . '</ul>';
$output .= '<p>' . t('For more information please read the configuration and customization handbook <a href="!image">Image FUpload page</a>.', array(
'!image' => 'http://www.drupal.org/handbook/modules/image/',
)) . '</p>';
return $output;
}
}
function image_fupload_theme() {
return array(
'swfupload_settings' => array(
'template' => 'swfupload-settings',
'arguments' => array(
'modulepath' => NULL,
'uploadpath' => NULL,
'maxfilesize' => NULL,
'sessionid' => NULL,
'uploadlimit' => NULL,
),
),
'fupload_create_filename' => array(
'arguments' => array(
'image' => NULL,
),
),
);
}
function fupload_filetransfer() {
global $user;
$sid = $_POST['PHPSESSID'];
$result = db_query("SELECT * FROM {sessions} WHERE sid = '%s' AND hostname = '%s' LIMIT 0 , 1", $sid, ip_address());
$upload_user = db_fetch_object($result);
if (!empty($upload_user)) {
$user = user_load(array(
'uid' => $upload_user->uid,
));
$_FILES['files']['name']['image'] = $_FILES['Filedata']['name'];
$_FILES['files']['type']['image'] = $_FILES['Filedata']['type'];
$_FILES['files']['tmp_name']['image'] = $_FILES['Filedata']['tmp_name'];
$_FILES['files']['error']['image'] = $_FILES['Filedata']['error'];
$_FILES['files']['size']['image'] = $_FILES['Filedata']['size'];
$validators = array(
'file_validate_is_image' => array(),
'file_validate_size' => array(
variable_get('image_max_upload_size', 800) * 1024,
),
);
if ($file = file_save_upload('image', $validators)) {
$image = image_get_info($file->filepath);
if (!db_query("UPDATE {files} SET filename = '%s', filemime = '%s' WHERE fid = %d LIMIT 1", IMAGE_UNMACHINED, $image['mime_type'], $file->fid)) {
drupal_set_header('HTTP/1.1 405 Upload Error');
}
print 'READY';
}
else {
drupal_set_header('HTTP/1.1 408 Image Error');
}
}
else {
drupal_access_denied();
}
}
function fupload_empty_queue() {
global $user;
db_query("UPDATE {files} SET filename = '%s' WHERE uid = %d AND status = %d AND filename = '%s' LIMIT 100", IMAGE_PROCESSED, $user->uid, FILE_STATUS_TEMPORARY, IMAGE_UNMACHINED);
drupal_set_message(t('All queued images were deleted.'), 'warning');
drupal_json(array(
'status' => TRUE,
'data' => theme('status_messages'),
));
}
function theme_fupload_create_filename($image) {
$filename = trim(basename($image->filepath), ' ');
$length1 = strlen(strrchr($filename, '.'));
$length2 = strlen($filename);
$image_name = ucfirst(substr($filename, 0, $length2 - $length1));
$replacements = explode(';', variable_get('fupload_title_replacements', '_;{;}'));
$image_name = str_replace($replacements, ' ', $image_name);
return $image_name;
}