Added : Remote URL Support

Update : File uploader
Added : Remoet Upload form
Added : new ajax loader
This commit is contained in:
Arslan Hassan 2010-12-24 14:22:47 +00:00
parent 65bf47b8bb
commit 4c1e63e46a
12 changed files with 321 additions and 194 deletions

View file

@ -39,11 +39,12 @@ if($_POST['del_log'])
$use_crons = config('use_crons');
if($quick_conv=='yes' || $use_crons=='no')
{
$targetFileName = $details['file_name'];
//exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &");
if (stristr(PHP_OS, 'WIN')) {
exec(php_path()." -q ".BASEDIR."/actions/video_convert.php");
} else {
exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &");
exec(php_path()." -q ".BASEDIR."/actions/video_convert.php $targetFileName");
} else {
exec(php_path()." -q ".BASEDIR."/actions/video_convert.php $targetFileName &> /dev/null &");
}
}

View file

@ -0,0 +1,130 @@
<?php
function RandomString($length)
{
// Generate random 32 charecter string
$string = md5(microtime());
// Position Limiting
$highest_startpoint = 32-$length;
// Take a random starting point in the randomly
// Generated String, not going any higher then $highest_startpoint
$randomString = substr($string,rand(0,$highest_startpoint),$length);
return $randomString;
}
function formatfilesize( $data ) {
// bytes
if( $data < 1024 ) {
return $data . " bytes";
}
// kilobytes
else if( $data < 1024000 ) {
return round( ( $data / 1024 ), 1 ) . "KB";
}
// megabytes
else if($data < 1024000000){
return round( ( $data / 1024000 ), 1 ) . " MB";
}else{
return round( ( $data / 1024000000 ), 1 ) . " GB";
}
}
/**
* Function used to get file name
*/
function GetName($file)
{
if(!is_string($file))
return false;
$path = explode('/',$file);
if(is_array($path))
$file = $path[count($path)-1];
$new_name = substr($file, 0, strrpos($file, '.'));
return $new_name;
}
function get_elapsed_time($ts,$datetime=1)
{
if($datetime == 1)
{
$ts = date('U',strtotime($ts));
}
$mins = floor((time() - $ts) / 60);
$hours = floor($mins / 60);
$mins -= $hours * 60;
$days = floor($hours / 24);
$hours -= $days * 24;
$weeks = floor($days / 7);
$days -= $weeks * 7;
$t = "";
if ($weeks > 0)
return "$weeks week" . ($weeks > 1 ? "s" : "");
if ($days > 0)
return "$days day" . ($days > 1 ? "s" : "");
if ($hours > 0)
return "$hours hour" . ($hours > 1 ? "s" : "");
if ($mins > 0)
return "$mins min" . ($mins > 1 ? "s" : "");
return "< 1 min";
}
//Function Used TO Get Extensio Of File
function GetExt($file){
return substr($file, strrpos($file,'.') + 1);
}
function old_set_time($temps)
{
round($temps);
$heures = floor($temps / 3600);
$minutes = round(floor(($temps - ($heures * 3600)) / 60));
if ($minutes < 10)
$minutes = "0" . round($minutes);
$secondes = round($temps - ($heures * 3600) - ($minutes * 60));
if ($secondes < 10)
$secondes = "0" . round($secondes);
return $minutes . ':' . $secondes;
}
function SetTime($sec, $padHours = true) {
if($sec < 3600)
return old_set_time($sec);
$hms = "";
// there are 3600 seconds in an hour, so if we
// divide total seconds by 3600 and throw away
// the remainder, we've got the number of hours
$hours = intval(intval($sec) / 3600);
// add to $hms, with a leading 0 if asked for
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';
// dividing the total seconds by 60 will give us
// the number of minutes, but we're interested in
// minutes past the hour: to get that, we need to
// divide by 60 again and keep the remainder
$minutes = intval(($sec / 60) % 60);
// then add to $hms (with a leading 0 if needed)
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
// seconds are simple - just divide the total
// seconds by 60 and keep the remainder
$seconds = intval($sec % 60);
// add to $hms, again with a leading 0 if needed
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}

View file

@ -17,24 +17,28 @@
global $file_name;
if($params['class'])
$class = ' '.$params['class'];
echo '<div class="upload_form_div clearfix'.$class.'">';
echo '<label for="check_url" class="label">Please enter remote file url</label>';
echo '<input type="textfield" id="remote_file_url" name="remote_file_url" class="upload_input"/>';
echo '<input name="submit_upload" type="hidden" value="Upload Data Now!">';
echo '<div id="remote_upload_result_cont"></div>';
echo '
<div id="loading" align="center" style="width:400px"></div>
<div class="remote_main_bar" id="main_bar">
<div id="prog_bar" class="remote_prog_bar"></div>
</div>
<div id="dspeed" align="center" style="width:400px"></div>
<div id="eta" align="center" style="width:400px"></div>
<div id="status" align="center" style="width:400px"></div>
<div id="time_took" align="center" style="width:400px"></div>
<div id="results" align="center" style="width:400px"></div>
';
echo '<div align="right"><input type="button" name="check_url" id="check_url" value="Upload" onClick="check_remote_url()" class="'.$params['button_class'].'"></div>';
echo '</div>';
echo
'<div class="upload_form_div clearfix'.$class.'" id="rempteUploadFormDiv">
<label for="remote_file_url" class="label">'.lang('please_enter_remote_file_url').'</label>
<input name="remote_file_url" type="textfield" class="remoteUrlInput"
id="remote_file_url" value="e.g http://clipbucket.com/sample.flv"
onclick="if($(this).val()==\'e.g http://clipbucket.com/sample.flv\') $(this).val(\'\')"/>
<input name="submit_upload" type="hidden" value="Upload Data Now!">
<div id="remote_upload_result_cont"></div>
<div class="remote_main_bar" id="main_bar">
<div id="prog_bar" class="remote_prog_bar"></div>
</div>
<div align="center" id="loading" style="height:16px; margin:5px 0px"></div>
<div>
'.lang('remoteDownloadStatusDiv').'
</div>
<div align="right">
<input type="button" name="remoteUploadBttn" id="remoteUploadBttn" value="Upload" onClick="check_remote_url()" class="cbSubmitUpload">
<input type="button" name="remoteUploadBttnStop" id="remoteUploadBttnStop" value="Cancel" class="cbSubmitUpload" style="display:none"/>
</div>
</div>
<div id="remoteForm"></div> ';
}
?>

View file

@ -97,6 +97,21 @@ var loading = loading_img+" Loading...";
// -->
function randomString()
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
var download = 0;
var total_size = 0;
var cur_speed = 0;
@ -108,14 +123,19 @@ var loading = loading_img+" Loading...";
var force_stop = false;
var remoteObjID = randomString();
function check_remote_url()
{
$('#remoteUploadBttn').attr("disabled","disabled").hide();
$('#remoteUploadBttnStop').show();
var file = $("#remote_file_url").val();
force_stop = false;
if(!file || file=='undefined')
{
alert("Please enter file url");
$('#remoteUploadBttn').attr('disabled','').show();
$('#remoteUploadBttnStop').attr("disabled","disabled").hide();
return false;
}
var ajaxCall = $.ajax({
@ -125,8 +145,11 @@ var loading = loading_img+" Loading...";
dataType : 'json',
beforeSend : function()
{
status_update();
$("#loading").html(loading_img+" uploading file, please wait...");
var remoteFileName = getName(file);
$("#loading").html('<div style="float: left; display: inline-block;"><img src="'+imageurl+'/ajax-loader.gif"></div><div style="float: left; line-height: 16px; padding-left:5px">'+lang.remoteUploadFile+'</div><div class="clear"></div>');
$('#remoteFileName').replaceWith('"'+remoteFileName+'"');
},
success: function(data)
{
@ -134,6 +157,7 @@ var loading = loading_img+" Loading...";
if(data.error)
{
force_stop = true;
$('#remoteUploadBttn').attr('disabled','');
alert(data.error);
}
$("#loading").html('');
@ -141,10 +165,15 @@ var loading = loading_img+" Loading...";
}
);
$('#remoteUploadBttnStop').click(function() {
ajaxCall.abort(); force_stop=true; $("#loading").html('');$('#remoteDownloadStatus').hide(); $(this).hide();$('#remoteUploadBttn').attr('disabled','').show(); });
}
var hasLoaded = false;
var perc_download = 0;
function status_update()
{
@ -175,34 +204,61 @@ var loading = loading_img+" Loading...";
var theSpeed = Math.round(speed/ 1024 ) + " Kbps";
perc_download = Math.round(download/total*100);
$('#prog_bar').width(perc_download+'%');
$('#remoteDownloadStatus').show();
//$('#prog_bar').width(perc_download+'%');
$('#prog_bar').animate({width:perc_download+'%'},1000);
$('#prog_bar').html(perc_download+'%');
$('#dspeed').html(theSpeed);
$('#eta').html('Time Left '+eta_fm);
$('#eta').html(eta_fm);
$('#status').html(download_fm+' of '+total_fm);
}
var intval = status_refesh*1000;
if(perc_download<100 && !force_stop)
setTimeout(function(){status_update()},intval);
else if(perc_download==100 && total>1)
{
$('#time_took').html('Time Took : '+time_took_fm);
//Del the log file
$.ajax({
url: result_page,
type: "POST",
data: ({del_log:'yes',file_name:file_name}),
success:function(data)
{
submit_upload_form();
}
var intval = status_refesh*1000;
if(perc_download<100 && !force_stop)
setTimeout(function(){status_update()},intval);
else if(perc_download==100 && total>1)
{
$('#time_took').html('Time Took : '+time_took_fm);
//Del the log file
$.ajax({
url: result_page,
type: "POST",
data: ({del_log:'yes',file_name:file_name}),
success:function(data)
{
$('#remoteUploadBttnStop').hide();
});
}
$.post(baseurl+'/actions/file_uploader.php',
{"getForm":"get_form","title":$("#remote_file_url").val(),"objId":remoteObjID},
function(data)
{
$('#remoteForm').append(data);
},'text');
$.ajax({
url: baseurl+'/actions/file_uploader.php',
type: "POST",
data:({"insertVideo":"yes","title":$("#remote_file_url").val(),"file_name":file_name}),
dataType: "json",
success: function(data)
{
vid = data;
$('#cbSubmitUpload'+remoteObjID)
.before('<span id="updateVideoDataLoading" style="margin-right:5px"></span>')
.attr("disabled","")
.attr("value",lang.saveData)
.attr("onClick","doUpdateVideo('#uploadForm"+remoteObjID+"','"+remoteObjID+"')")
.after('<input type="hidden" name="videoid" value="'+vid+'" id="videoid" />')
.after('<input type="hidden" name="updateVideo" value="yes" id="updateVideo" />');
}
});
}
});
}
}
}
);
@ -955,11 +1011,8 @@ function collection_actions(form,mode,objID,result_con,type,cid)
}
// Simple function to open url with javascript
function openURL(url,newWindow) {
if(newWindow == 'new')
window.open(url,'mywindow');
else
document.location = url;
function openURL(url) {
document.location = url;
}
@ -967,7 +1020,7 @@ function openURL(url,newWindow) {
function get_item(obj,ci_id,cid,type,direction)
{
var btn_text = $(obj).text();
$(obj).html(loading);
$(obj).text('Working');
$.post(page,
{
@ -982,7 +1035,7 @@ function get_item(obj,ci_id,cid,type,direction)
if(!data)
{
alert('No '+type+' returned');
$(obj).html(btn_text);
$(obj).text(btn_text);
} else {
var jsArray = new Array(type,data['cid'],data['key']);
construct_url(jsArray);
@ -1031,7 +1084,7 @@ function onReload_item()
function pagination(object,cid,type,pageNumber)
{
var obj = $(object), objID = obj.id, parent = obj.parent(), parentID;
obj = $(object); objID = obj.id; parent = obj.parent();
if(parent.attr('id'))
parentID = parent.attr('id')
@ -1094,101 +1147,73 @@ function ajax_add_collection(obj)
Child = $("#"+ID).children().filter('div'),
total = Child.length, eachObj, AjaxCall;
}*/
var AjaxIteration = 0;
var InputIteration = 0;
function callAjax(obj)
{
var getArray = getDetails(obj),
TotalItems = getArray.length, AjaxCall,
inputs = getInputs(obj,true),
element = inputs[InputIteration++];
if(AjaxIteration == getArray.length)
var getArray = updatePhotos(obj),
TotalItems = getArray.length;
alert(TotalItems);
$.each(getArray,function(i,v) { alert(i+" "+v) })
}
function updatePhotos(obj)
{
var ID = obj.form.id,
Child = $("#"+ID).children().filter('div'),
eachObj, AjaxCall, i = 0, ParamArray = new Array(Child.length);
var err_count = 0;
$.each(Child,function(index,elem){
eachObj = $(elem);
var inputs = $("#"+elem.id+" :input"),
query = '';
inputs.each(function(ind, input)
{
$(obj).html(TotalItems+" Photos Saved. Continue").removeAttr('disabled');
return;
}
else
{
AjaxCall =
$.ajax
({
url: page,
type: "post",
dataType: "json",
data: getArray[AjaxIteration++],
cache: false,
beforeSend: function() { $(obj).html(loading_img+" Saving "+AjaxIteration+" of out "+TotalItems); $(obj).attr('disabled','disabled') },
success: function(data) {
$('#'+element.id+" div:first-child > div").slideUp('normal');
$('#'+element.id+" div:first-child").css('padding','10px').html(
"<div style='font:bold 11px Tahoma;'>"+data.photo_title+" is now saved.</div>"
).fadeIn(350,function() { callAjax(obj); });
}
});
}
}
function getInputs(obj,return_array)
{
var Child = $(obj).parent().children().filter('form'), InputArray = [];
if(return_array == true)
{
$.each(Child,function(index,element){
InputArray[index] = element;
if(input.type == "text" || input.type == "textarea" || input.type == "hidden")
{
if(input.value == null || input.value == '')
{
err_count++;
input.style.border = '2px solid #ed0000';
//ShouldContinue = false;
} else {
query += input.id+"="+input.value+"&";
err_count = 0;
//ShouldContinue = true;
}
}
if(input.type == "select-one" && input.selected)
query += input.id+"="+input.value+"&";
if(input.type == "radio" && input.checked)
query += input.id+"="+input.value+"&";
})
return InputArray;
} else
return Child;
}
function getDetails(obj)
{
var forms = getInputs(obj), ParamArray = new Array(forms.length);
$.each(forms,function(index,form) {
query = $("#"+form.id+" *").serialize();
query += "&mode=ajaxPhotos";
ParamArray[index] = query;
query += "mode=ajaxPhotos";
ParamArray[index] = query;
/* AjaxCall =
$.ajax
({
url: page,
type: "post",
dataType: "text",
data: query,
cache: false,
beforeSend: function() { $(obj).html(loading_img+" Saving"); $(obj).attr('disabled','disabled') },
complete : function() { $(obj).html(Child.length+" photos saved") },
success: function(data) { $("#"+eachObj.attr('id')).hide() }
});
saving++;
*/
})
return ParamArray;
}
function viewRatings(object,pid)
function getName(File)
{
var obj = $(object), innerHTML = obj.html();
if(document.getElementById('RatingStatContainer'))
$("#RatingStatContainer").toggle();
else
{
loadAjax =
$.ajax
({
url:page,
type: "post",
dataType: "text",
data: { mode:"viewPhotoRating", photoid:pid },
beforeSend: function() { obj.html(loading); },
success:function(data) {
obj.html(innerHTML);
if(data)
{
$("<div />").attr('id','RatingStatContainer')
.addClass('clearfix')
.css({
"padding" : "8px",
"font" : "normal 11px Tahoma",
"border" : "1px solid #ccc"
}).html(data).fadeIn(350).insertAfter(obj);
} else {
obj.removeAttr('onclick');
alert("Photo has not recieved any rating yet.");
}
}
});
}
var url = File;
var filename = url.substring(url.lastIndexOf('/')+1);
return filename;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 B

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,9 +1,3 @@
{assign var='requiredFields' value=$Upload->loadRequiredFields()}
{assign var='optionFields' value=$Upload->loadOptionFields()}
{assign var='locationFields' value=$Upload->loadLocationFields()}
{assign var='cust_fields' value=$Upload->custom_form_fields}
{lang code='vdo_upload_step2' assign='vdo_upload_step'}
<div class="upload_left">
@ -17,8 +11,7 @@
$(document).ready(function() { show_menu('file_upload_div') })
</script>
{/literal}
<form action="{$upload_link}" method="post" enctype="multipart/form-data" name="{$upload_form_name}" id="{$upload_form_name}" >
<input name="file_name" type="hidden" value="{$file_name}">
{assign var=opt_list value=$Upload->load_upload_options()}
<ul class="upload_opts clearfix">
{foreach from=$opt_list item=opt key=divid}
@ -28,14 +21,9 @@
<div class="clear"></div>
{foreach from=$opt_list item=opt key=divid}
<div class="upload_opt" id="{$divid}">
</div> <!--upload_opt-->
{load_form name=$opt.load_func button_class='cb_button_2' class='upload_form'}
</div>
{/foreach}
</form>
<input id="file_uploads" name="file_uploads" type="file" />
<a href="javascript:$('#file_uploads').uploadifyUpload();">Upload Files</a>
{/if}
@ -43,36 +31,6 @@
<!-- STEP 1 ENDS HERE -->
<!-- STEP 2 - UPLOADING VIDEO FILES -->
{if $step =="2"}
<h2>{$vdo_upload_step|sprintf:2}</h2>
{literal}
<script type="text/javascript">
$(document).ready(function() { show_menu('file_upload_div') })
</script>
{/literal}
<form action="{$upload_link}" method="post" enctype="multipart/form-data" name="{$upload_form_name}" id="{$upload_form_name}" >
{$Upload->load_post_fields()}
<input name="file_name" type="hidden" value="{$file_name}">
{assign var=opt_list value=$Upload->load_upload_options()}
<ul class="upload_opts clearfix">
{foreach from=$opt_list item=opt key=divid}
<li class="upload_opt_head moveL {$divid}" onclick="show_menu('{$divid}')">{$opt.title}</li>
{/foreach}
</ul>
<div class="clear"></div>
{foreach from=$opt_list item=opt key=divid}
<div class="upload_opt" id="{$divid}">
{load_form name=$opt.load_func button_class='cb_button_2' class='upload_form'}
</div> <!--upload_opt-->
{/foreach}
</form>
{/if}
<!-- STEP 2 ENDS HERE -->
<!-- STEP 3 - VIEWING SUCCESSFULL PAGE -->
{if $step==3}
<div class="upload_info">

View file

@ -374,7 +374,7 @@ span.remember { font-size:10px; }
.cbSubmitUpload:hover,.cb_button:hover,.cb_button_2:hover{background-position:-0px -31px}
.cbSubmitUpload,.cb_button_2{font-size:12px}
input[disabled=disabled].cbSubmitUpload{ background:#f2f2f2; cursor:default; color:#999; border:1px solid #ccc; font:normal 11px Tahoma;}
input[disabled].cbSubmitUpload{ background:#f2f2f2; cursor:default; color:#999; border:1px solid #ccc; font:normal 11px Tahoma;}
@ -779,19 +779,27 @@ ul.upload_opts li.selected { cursor:pointer; background:none; border:1px solid;
.remote_main_bar
{
width:400px;
height:30px;
border:1px solid #666;
width:100%;
height:20px;
background-image:url(../images/uploading_bar.png);
border-width:0px 1px 0px 1px; border-color:#dedede; border-style:solid;
}
#rempteUploadFormDiv{padding-right:10px;}
.remote_prog_bar
{
height:30px;
background-color:#53baff;
height:20px;
background-image:url(../images/uploading_bar.png);
background-position:-0px -20px;
text-align:center;
line-height:30px;
font:normal 13px "Arial Black", Gadget, sans-serif;
color:#fff;
line-height:20px;
width:0px
}
.remoteDownloadStatus{ font-weight:bold; display:none }
#remote_upload_div .remoteUrlInput {width:100%; border-style:solid; border-color:#dedede; border-width:1px 1px 0px 1px; height:20px; color:#999999 }
/* COLLECTION */
.collect_grid { position:relative; }
.obj_title { width:110px; display:inline-block; }

View file

@ -11,6 +11,7 @@ var file_name = '{$file_name}';
var lang = new Array();
lang['saveData'] = 'Save Data';
lang['savingData'] = 'Saving...';
lang['remoteUploadFile'] = '{lang code="remote_upload_file"}';
var fileExt = '{$Cbucket->list_extensions()|replace:",":";"}';
{literal}
@ -21,8 +22,8 @@ var fileExt = '{$Cbucket->list_extensions()|replace:",":";"}';
}
function show_message(msg,ID,fade)
{ $('#file_uploads'+ID+' .percentage')
.after('<div class=\"uploadSuccessDiv\"><div class=\"uploadSuccessMsg\">'+msg+'<\/div><\/div>');
{ $('#uploadForm'+ID)
.prepend('<div class=\"uploadSuccessDiv\"><div class=\"uploadSuccessMsg\">'+msg+'<\/div><\/div>');
if(fade){$('.uploadSuccessDiv').delay(3000).fadeOut('slow');}
}