2009-02-14 23:03:09 +00:00
< ? php defined ( " SYSPATH " ) or die ( " No direct script access. " ) ?>
2009-03-17 05:20:37 +00:00
< script type = " text/javascript " src = " <?= url::file( " lib / swfupload / swfupload . js " ) ?> " ></ script >
< script type = " text/javascript " src = " <?= url::file( " lib / swfupload / swfupload . queue . js " ) ?> " ></ script >
2009-06-28 17:07:41 -07:00
< script type = " text/javascript " src = " <?= url::file( " lib / jquery . scrollTo . js " ) ?> " ></ script >
2009-03-17 05:20:37 +00:00
<!-- hack to set the title for the dialog -->
2009-10-04 00:27:22 -06:00
< form id = " g-add-photos-form " action = " <?= url::site( " simple_uploader / finish ? csrf = $csrf " ) ?> " >
2009-02-18 07:33:38 +00:00
< fieldset >
2009-08-29 22:54:20 -07:00
< legend > < ? = t ( " Add photos to %album_title " , array ( " album_title " => html :: purify ( $item -> title ))) ?> </legend>
2009-02-18 07:33:38 +00:00
</ fieldset >
</ form >
2009-03-17 05:20:37 +00:00
2009-10-04 00:27:22 -06:00
< div id = " g-add-photos " >
2009-05-10 20:54:15 +00:00
< ? if ( ini_get ( " suhosin.session.encrypt " )) : ?>
2009-10-07 00:21:23 -06:00
< ul id = " g-action-status " class = " g-message-block " >
2009-10-04 00:27:22 -06:00
< li class = " g-error " >
2009-05-10 21:32:27 +00:00
< ? = t ( " Error: your server is configured to use the <a href= \" %encrypt_url \" ><code>suhosin.session.encrypt</code></a> setting from <a href= \" %suhosin_url \" >Suhosin</a>. You must disable this setting to upload photos. " ,
array ( " encrypt_url " => " http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.encrypt " ,
" suhosin_url " => " http://www.hardened-php.net/suhosin/ " )) ?>
</ li >
</ ul >
2009-05-10 20:54:15 +00:00
< ? endif ?>
2009-03-17 05:20:37 +00:00
< p >
< ? = t ( " Photos will be uploaded to album: " ) ?>
</ p >
2009-10-04 00:27:22 -06:00
< ul class = " g-breadcrumbs " >
2009-03-17 05:20:37 +00:00
< ? foreach ( $item -> parents () as $parent ) : ?>
2009-08-29 22:54:20 -07:00
< li > < ? = html :: clean ( $parent -> title ) ?> </li>
2009-03-17 05:20:37 +00:00
< ? endforeach ?>
2009-08-29 22:54:20 -07:00
< li class = " active " > < ? = html :: purify ( $item -> title ) ?> </li>
2009-03-17 05:20:37 +00:00
</ ul >
2009-09-26 13:28:10 -04:00
< div id = " g-uploadqueue-infobar " >
2009-09-27 11:35:03 -07:00
< ? = t ( " Upload Queue " ) ?>
2009-09-26 13:28:10 -04:00
< span id = " g-uploadstatus " ></ span >
< a id = " g-cancelupload " title = " <?= t( " Cancel all the pending uploads " )->for_html_attr() ?> " onclick = " swfu.cancelQueue(); " >< ? = t ( " cancel " ) ?> </a>
</ div >
2009-10-04 00:27:22 -06:00
< div id = " g-add-photos-canvas " style = " text-align: center; " >
< div id = " g-add-photos-queue " ></ div >
< div id = " g-edit-photos-queue " ></ div >
2009-03-17 05:20:37 +00:00
</ div >
2009-10-04 00:27:22 -06:00
< span id = " g-choose-files-placeholder " ></ span >
2009-03-17 05:20:37 +00:00
<!-- Proxy the done request back to our form , since its been ajaxified -->
2009-10-04 00:27:22 -06:00
< button class = " ui-state-default ui-corner-all " onclick = " $ ('#g-add-photos-form').submit() " >
2009-09-26 11:27:07 -04:00
< ? = t ( " Done " ) ?>
2009-03-17 05:20:37 +00:00
</ button >
</ div >
< script type = " text/javascript " >
var swfu = new SWFUpload ({
2009-08-30 15:34:46 -07:00
flash_url : < ? = html :: js_string ( url :: file ( " lib/swfupload/swfupload.swf " )) ?> ,
upload_url : < ? = html :: js_string ( url :: site ( " simple_uploader/add_photo/ $item->id " )) ?> ,
2009-08-29 13:41:18 -07:00
post_params : < ? = json_encode ( array (
" g3sid " => Session :: instance () -> id (),
" user_agent " => Input :: instance () -> server ( " HTTP_USER_AGENT " ),
" csrf " => $csrf )) ?> ,
2009-08-30 15:34:46 -07:00
file_size_limit : < ? = html :: js_string ( ini_get ( " upload_max_filesize " ) ? num :: convert_to_bytes ( ini_get ( " upload_max_filesize " )) . " B " : " 100MB " ) ?> ,
2009-06-29 16:02:11 -04:00
file_types : " *.gif;*.jpg;*.jpeg;*.png;*.flv;*.mp4;*.GIF;*.JPG;*.JPEG;*.PNG;*.FLV;*.MP4 " ,
2009-08-30 15:34:46 -07:00
file_types_description : < ? = t ( " Photos and Movies " ) -> for_js () ?> ,
2009-06-29 16:02:11 -04:00
file_upload_limit : 1000 ,
file_queue_limit : 0 ,
custom_settings : { },
2009-03-17 05:20:37 +00:00
debug : false ,
// Button settings
2009-09-26 13:28:10 -04:00
button_image_url : < ? = html :: js_string ( url :: file ( gallery :: find_file ( " images " , " select-photos-backg.png " ))) ?> ,
2009-03-20 17:22:12 +00:00
button_width : " 202 " ,
button_height : " 45 " ,
2009-10-04 00:27:22 -06:00
button_placeholder_id : " g-choose-files-placeholder " ,
2009-08-29 13:41:18 -07:00
button_text : < ? = json_encode ( '<span class="swfUploadFont">' . t ( " Select photos... " ) . '</span>' ) ?> ,
2009-03-20 17:22:12 +00:00
button_text_style : " .swfUploadFont { color: #2E6E9E; font-size: 16px; font-family: Lucida Grande,Lucida Sans,Arial,sans-serif; font-weight: bold; } " ,
button_text_left_padding : 30 ,
2009-09-27 11:35:03 -07:00
button_text_right_padding : 30 ,
2009-03-20 17:22:12 +00:00
button_text_top_padding : 10 ,
2009-03-17 05:20:37 +00:00
// The event handler functions are defined in handlers.js
2009-06-29 16:02:11 -04:00
file_queued_handler : file_queued ,
file_queue_error_handler : file_queue_error ,
file_dialog_complete_handler : file_dialog_complete ,
upload_start_handler : upload_start ,
upload_progress_handler : upload_progress ,
upload_error_handler : upload_error ,
upload_success_handler : upload_success ,
upload_complete_handler : upload_complete ,
queue_complete_handler : queue_complete
2009-03-17 05:20:37 +00:00
});
// @todo add support for cancelling individual uploads
function File_Progress ( file ) {
this . box = $ ( " # " + file . id );
if ( ! this . box . length ) {
2009-10-04 00:27:22 -06:00
$ ( " #g-add-photos-queue " ) . append (
2009-03-17 05:20:37 +00:00
" <div class= \" box \" id= \" " + file . id + " \" > " +
" <div class= \" title \" ></div> " +
" <div class= \" status \" ></div> " +
2009-06-29 16:02:11 -04:00
" <div class= \" progressbar \" ></div> " +
" </div> " );
2009-03-17 05:20:37 +00:00
this . box = $ ( " # " + file . id );
}
this . title = this . box . find ( " .title " );
this . status = this . box . find ( " .status " );
this . progress_bar = this . box . find ( " .progressbar " );
this . progress_bar . progressbar ();
this . progress_bar . css ( " visibility " , " hidden " );
}
File_Progress . prototype . set_status = function ( status_class , msg ) {
this . box . removeClass ( " pending error uploading complete " ) . addClass ( status_class );
this . status . html ( msg );
}
function file_queued ( file ) {
var fp = new File_Progress ( file );
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " pending " , < ? = t ( " Pending... " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
// @todo add cancel button to call this.cancelUpload(file.id)
}
function file_queue_error ( file , error_code , message ) {
if ( error_code === SWFUpload . QUEUE_ERROR . QUEUE_LIMIT_EXCEEDED ) {
2009-08-30 15:34:46 -07:00
alert ( < ? = t ( " You have attempted to queue too many files. " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
return ;
}
var fp = new File_Progress ( file );
switch ( error_code ) {
case SWFUpload . QUEUE_ERROR . FILE_EXCEEDS_SIZE_LIMIT :
2009-06-04 21:05:33 -04:00
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " <strong>File is too big.</strong> A likely error source is a too low value for <em>upload_max_filesize</em> (%upload_max_filesize) in your <em>php.ini</em>. " , array ( " upload_max_filesize " => ini_get ( " upload_max_filesize " ))) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . QUEUE_ERROR . ZERO_BYTE_FILE :
2009-06-04 21:05:33 -04:00
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Cannot upload empty files. " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . QUEUE_ERROR . INVALID_FILETYPE :
2009-06-04 21:05:33 -04:00
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Invalid file type. " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
default :
if ( file !== null ) {
2009-06-04 21:05:33 -04:00
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Unknown error " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
}
break ;
}
}
function file_dialog_complete ( num_files_selected , num_files_queued ) {
if ( num_files_selected > 0 ) {
2009-09-26 13:28:10 -04:00
$ ( " #g-cancelupload " ) . show ();
$ ( " #g-uploadstatus " ) . text ( get_completed_status_msg ( this . getStats ()));
2009-03-17 05:20:37 +00:00
}
2009-07-03 21:44:10 -07:00
2009-03-17 05:20:37 +00:00
// Auto start the upload
this . startUpload ();
}
function upload_start ( file ) {
// Do all file validation on the server side. Update the UI here because in Linux
// no uploadProgress events are called (limitation in the Linux Flash VM).
var fp = new File_Progress ( file );
fp . title . html ( file . name );
2009-08-30 15:34:46 -07:00
fp . set_status ( " uploading " , < ? = t ( " Uploading... " ) -> for_js () ?> );
2009-10-04 00:27:22 -06:00
$ ( " #g-add-photos-canvas " ) . scrollTo ( fp . box , 1000 );
2009-09-27 11:35:03 -07:00
// move file select button
$ ( " #SWFUpload_0 " ) . css ({ 'left' : '0' , 'top' : '0' });
swfu . setButtonText ( < ? = json_encode ( '<span class="swfUploadFont">' . t ( " Select more photos... " ) . '</span>' ) ?> );
2009-03-17 05:20:37 +00:00
return true ;
// @todo add cancel button to call this.cancelUpload(file.id)
}
function upload_progress ( file , bytes_loaded , bytes_total ) {
var percent = Math . ceil (( bytes_loaded / bytes_total ) * 100 );
var fp = new File_Progress ( file );
2009-08-30 15:34:46 -07:00
fp . set_status ( " uploading " , < ? = t ( " Uploading... " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
fp . progress_bar . css ( " visibility " , " visible " );
fp . progress_bar . progressbar ( " value " , percent );
}
function upload_success ( file , serverData ) {
var fp = new File_Progress ( file );
fp . progress_bar . progressbar ( " value " , 100 );
2009-08-30 15:34:46 -07:00
fp . set_status ( " complete " , < ? = t ( " Complete. " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
}
function upload_error ( file , error_code , message ) {
var fp = new File_Progress ( file );
switch ( error_code ) {
case SWFUpload . UPLOAD_ERROR . HTTP_ERROR :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Upload error: bad image file " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . UPLOAD_FAILED :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Upload failed " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . IO_ERROR :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Server error " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . SECURITY_ERROR :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Security error " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . UPLOAD_LIMIT_EXCEEDED :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Upload limit exceeded " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . FILE_VALIDATION_FAILED :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Failed validation. File skipped " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . FILE_CANCELLED :
// If there aren't any files left (they were all cancelled) disable the cancel button
if ( this . getStats () . files_queued === 0 ) {
2009-09-26 13:28:10 -04:00
$ ( " #g-cancelupload " ) . hide ();
2009-03-17 05:20:37 +00:00
}
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Cancelled " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
case SWFUpload . UPLOAD_ERROR . UPLOAD_STOPPED :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Stopped " ) -> for_js () ?> );
2009-03-17 05:20:37 +00:00
break ;
default :
2009-08-30 15:34:46 -07:00
fp . set_status ( " error " , < ? = t ( " Unknown error: " ) -> for_js () ?> + error_code);
2009-03-17 05:20:37 +00:00
break ;
}
}
function upload_complete ( file ) {
2009-06-29 16:02:11 -04:00
var stats = this . getStats ();
2009-09-26 13:28:10 -04:00
$ ( " #g-uploadstatus " ) . text ( get_completed_status_msg ( stats ));
2009-06-29 16:02:11 -04:00
if ( stats . files_queued === 0 ) {
2009-09-26 13:28:10 -04:00
$ ( " #g-cancelupload " ) . hide ();
2009-03-17 05:20:37 +00:00
}
}
2009-07-14 12:36:57 -07:00
function get_completed_status_msg ( stats ) {
2009-09-26 13:28:10 -04:00
var msg = < ? = t ( " (completed %completed of %total) " , array ( " completed " => " __COMPLETED__ " , " total " => " __TOTAL__ " )) -> for_js () ?> ;
2009-07-14 12:36:57 -07:00
msg = msg . replace ( " __COMPLETED__ " , stats . successful_uploads );
msg = msg . replace ( " __TOTAL__ " , stats . files_queued + stats . successful_uploads +
stats . upload_errors + stats . upload_cancelled + stats . queue_errors );
return msg ;
}
2009-03-17 05:20:37 +00:00
// This event comes from the Queue Plugin
function queue_complete ( num_files_uploaded ) {
2009-08-30 15:34:46 -07:00
var status_msg = < ? = t ( " Uploaded: __COUNT__ " ) -> for_js () ?> ;
2009-10-04 00:27:22 -06:00
$ ( " #g-upload-status " ) . html ( status_msg . replace ( " __COUNT__ " , num_files_uploaded ));
2009-03-17 05:20:37 +00:00
}
</ script >