'photos_swfu_upload',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['photos_swfu/upload_node/%node'] = array(
'page callback' => 'photos_swfu_node',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function photos_swfu_form_alter(&$form, $form_state, $form_id) {
if ($form_id == "photos_upload_form") {
$form = photos_swfu_form();
}
}
function photos_swfu_form(){
global $user;
drupal_add_css(drupal_get_path('module', 'photos_swfu') .'/v102demo/swfupload.v102.theme.css');
drupal_add_js(drupal_get_path('module', 'photos_swfu') .'/v102demo/swfupload.js');
drupal_add_js(drupal_get_path('module', 'photos_swfu') .'/v102demo/swfupload.v102.js');
drupal_add_js(drupal_get_path('module', 'photos_swfu') .'/v102demo/swfupload.v102.callbacks.js', 'module');
if(variable_get('photos_upzip',0)){ $zip = ' zip';}
if(arg(0) == 'node' && is_numeric(arg(1))){
$type = db_result(db_query('SELECT type FROM {node} WHERE nid = %d', arg(1)));
if($type != 'photos'){
$form['new']['pid'] = array(
'#title' => t('Upload to album'),
'#type' => 'select',
'#options' => _photos_useralbum($user->uid),
'#default_value' => $_GET['pid'],
'#required' => TRUE,
'#description' => '
'.t('Allow the type:').' jpg gif png jpeg '.$zip.'
',
'#weight' => -5,
);
}
}
$form['new']['swfu'] = array(
'#value' => '',
'#weight' => -4
);
$op = array();
$op['query']['uid'] = session_id();
if(is_numeric($_GET['pid'])){
$op['query']['pid'] = $_GET['pid'];
}
if(arg(0) == 'node' && is_numeric(arg(1))){
$url = url('photos_swfu/upload_node/'.arg(1), $op);
}else{
$url = url('photos_swfu/upload', $op);
}
$swf = base_path() . drupal_get_path('module', 'photos_swfu') .'/v102demo/swfupload_f8.swf';
if(arg(1) == 'quote'){
$href = url($_GET['q'], array('query' => array('type' => 'upload')));
}else{
$href = url($_GET['q'], array('query' => array('type' => 'tx')));
}
drupal_add_js(<< $uid));
$limits = _upload_file_limits($user);
$path = _photos_check_path();
$files = new stdClass();
$ext = end(explode('.',$_FILES['Filedata']['name']));
$files->filesize = $_FILES['Filedata']['size'];
if(variable_get('photos_rname', 0)){
$name = round(rand(15770,967049700)).time().'.'.$ext;
}else{
$name = $_FILES['Filedata']['name'];
}
$files->filepath = file_destination(file_create_path($path .'/'.trim(basename($name))),FILE_EXISTS_RENAME);
$files->filename = end(explode('/',$files->filepath));
if(is_numeric($_GET['pid'])){
$node = node_load($_GET['pid']);
if(node_access('update', $node)){
$files->pid = $node->nid;
$files->title = $node->title;
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}else{
$node = db_fetch_object(db_query_range("SELECT nid, title FROM {node} WHERE uid = %d AND type = '%s'", $user->uid, 'photos', 0, 1));
if($node){
$files->pid = $node->nid;
$files->title = $node->title;
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}
if($ext == 'zip' || $ext == 'ZIP'){
if(!variable_get('photos_upzip',0)){
return header("HTTP/1.0 502 Internal Server Error");
}
if (file_move($_FILES['Filedata']['tmp_name'], $files->filepath)) {
if(!_photos_unzip($files->filepath, $path, $files)){
return header("HTTP/1.0 502 Internal Server Error");
}else {
return;
}
}else{
return header("HTTP/1.0 502 Internal Server Error");
}
}else{
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array($limits['resolution']),
'file_validate_size' => array($limits['file_size'], $limits['user_size'])
);
$_FILES['files']['name']['album'] = $name;
$_FILES['files']['tmp_name']['album'] = $_FILES['Filedata']['tmp_name'];
$_FILES['files']['size']['album'] = $_FILES['Filedata']['size'];
if ($file = file_save_upload('album', $validators, $path)) {
$title = urlencode($_FILES['Filedata']['name']);
$file->title = ($title ? urldecode($title):$files->title);
$file->pid = $files->pid;
$file->nid = $files->nid;
if(!_photos_image_date($file, $path)){
return header("HTTP/1.0 502 Internal Server Error");
}
}else {
return header("HTTP/1.0 502 Internal Server Error");
}
}
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}
function photos_swfu_node($node) {
global $user;
$session = $_GET['uid'];
$uid = db_result(db_query("SELECT uid FROM {sessions} WHERE sid = '%s' AND hostname = '%s'", $session, ip_address()));
if ($user = user_load(array('uid' => $uid))) {
if(node_access('update', $node) && is_uploaded_file($_FILES['Filedata']['tmp_name']) && !$_FILES['Filedata']['error']){
$limits = _upload_file_limits($user);
$path = _photos_check_path();
$files = new stdClass();
$ext = end(explode('.',$_FILES['Filedata']['name']));
$files->filesize = $_FILES['Filedata']['size'];
if(variable_get('photos_rname', 0)){
$name = round(rand(15770,967049700)).time().'.'.$ext;
}else{
$name = $_FILES['Filedata']['name'];
}
$files->filepath = file_destination(file_create_path($path .'/'.trim(basename($name))),FILE_EXISTS_RENAME);
$files->filename = end(explode('/',$files->filepath));
if($node->type == 'photos'){
$files->pid = $node->nid;
$files->title = $node->title;
}else{
$files->nid = $node->nid;
$files->title = $node->title;
if(is_numeric($_GET['pid'])){
$node = node_load($_GET['pid']);
if(node_access('update', $node)){
$files->pid = $node->nid;
$files->title = $node->title;
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}else{
$node = db_fetch_object(db_query_range("SELECT nid, title FROM {node} WHERE uid = %d AND type = '%s'", $user->uid, 'photos', 0, 1));
if($node){
$files->pid = $node->nid;
$files->title = $node->title;
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}
}
if($ext == 'zip' || $ext == 'ZIP'){
if(!variable_get('photos_upzip',0)){
return header("HTTP/1.0 502 Internal Server Error");
}
if (file_move($_FILES['Filedata']['tmp_name'], $files->filepath)) {
if(!_photos_unzip($files->filepath, $path, $files)){
return header("HTTP/1.0 502 Internal Server Error");
}else {
return;
}
}else{
return header("HTTP/1.0 502 Internal Server Error");
}
}else{
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array($limits['resolution']),
'file_validate_size' => array($limits['file_size'], $limits['user_size'])
);
$_FILES['files']['name']['album'] = $name;
$_FILES['files']['tmp_name']['album'] = $_FILES['Filedata']['tmp_name'];
$_FILES['files']['size']['album'] = $_FILES['Filedata']['size'];
if ($file = file_save_upload('album', $validators, $path)) {
$title = urlencode($_FILES['Filedata']['name']);
$file->title = ($title ? urldecode($title): $files->title);
$file->pid = $files->pid;
$file->nid = $files->nid;
if(!_photos_image_date($file, $path)){
return header("HTTP/1.0 502 Internal Server Error");
}
}else {
return header("HTTP/1.0 502 Internal Server Error");
}
}
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}else{
return header("HTTP/1.0 403 Internal Server Error");
}
}
//transliteration_init
function photos_swfu_init() {
if (module_exists('transliteration') && !empty($_FILES['Filedata'])) {
require_once(drupal_get_path('module', 'transliteration') .'/transliteration.inc');
$langcode = NULL;
if (!empty($_POST['language'])) {
$languages = language_list();
$langcode = isset($languages[$_POST['language']]) ? $_POST['language'] : NULL;
}
$_FILES['Filedata']['name'] = transliteration_clean_filename($_FILES['Filedata']['name'], $langcode);
}
}