mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-22 05:03:42 +00:00
Fix wrong intends in js_upload
This commit is contained in:
parent
47b2326dff
commit
dcf4b5695d
1 changed files with 123 additions and 123 deletions
|
@ -62,38 +62,38 @@ function js_upload_form(&$a,&$b) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var uploader = null;
|
var uploader = null;
|
||||||
function getSelected(opt) {
|
function getSelected(opt) {
|
||||||
var selected = new Array();
|
var selected = new Array();
|
||||||
var index = 0;
|
var index = 0;
|
||||||
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
|
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
|
||||||
if ((opt[intLoop].selected) ||
|
if ((opt[intLoop].selected) ||
|
||||||
(opt[intLoop].checked)) {
|
(opt[intLoop].checked)) {
|
||||||
index = selected.length;
|
index = selected.length;
|
||||||
//selected[index] = new Object;
|
//selected[index] = new Object;
|
||||||
selected[index] = opt[intLoop].value;
|
selected[index] = opt[intLoop].value;
|
||||||
//selected[index] = intLoop;
|
//selected[index] = intLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
function createUploader() {
|
function createUploader() {
|
||||||
uploader = new qq.FileUploader({
|
uploader = new qq.FileUploader({
|
||||||
element: document.getElementById('file-uploader-demo1'),
|
element: document.getElementById('file-uploader-demo1'),
|
||||||
action: '{$b['post_url']}',
|
action: '{$b['post_url']}',
|
||||||
|
|
||||||
template: '<div class="qq-uploader">' +
|
template: '<div class="qq-uploader">' +
|
||||||
'<div class="qq-upload-drop-area"><span>$drop_msg</span></div>' +
|
'<div class="qq-upload-drop-area"><span>$drop_msg</span></div>' +
|
||||||
'<div class="qq-upload-button">$upload_msg</div>' +
|
'<div class="qq-upload-button">$upload_msg</div>' +
|
||||||
'<ul class="qq-upload-list"></ul>' +
|
'<ul class="qq-upload-list"></ul>' +
|
||||||
'</div>',
|
'</div>',
|
||||||
|
|
||||||
// template for one item in file list
|
// template for one item in file list
|
||||||
fileTemplate: '<li>' +
|
fileTemplate: '<li>' +
|
||||||
'<span class="qq-upload-file"></span>' +
|
'<span class="qq-upload-file"></span>' +
|
||||||
'<span class="qq-upload-spinner"></span>' +
|
'<span class="qq-upload-spinner"></span>' +
|
||||||
'<span class="qq-upload-size"></span>' +
|
'<span class="qq-upload-size"></span>' +
|
||||||
'<a class="qq-upload-cancel" href="#">$cancel</a>' +
|
'<a class="qq-upload-cancel" href="#">$cancel</a>' +
|
||||||
'<span class="qq-upload-failed-text">$failed</span>' +
|
'<span class="qq-upload-failed-text">$failed</span>' +
|
||||||
'</li>',
|
'</li>',
|
||||||
|
|
||||||
debug: true,
|
debug: true,
|
||||||
sizeLimit: $maximagesize,
|
sizeLimit: $maximagesize,
|
||||||
|
@ -106,22 +106,22 @@ function createUploader() {
|
||||||
|
|
||||||
if (typeof acl != "undefined"){
|
if (typeof acl != "undefined"){
|
||||||
uploader.setParams( {
|
uploader.setParams( {
|
||||||
newalbum : newalbum,
|
newalbum : newalbum,
|
||||||
album : album,
|
album : album,
|
||||||
not_visible : document.getElementById('photos-upload-noshare').checked,
|
not_visible : document.getElementById('photos-upload-noshare').checked,
|
||||||
group_allow : acl.allow_gid.join(','),
|
group_allow : acl.allow_gid.join(','),
|
||||||
contact_allow : acl.allow_cid.join(','),
|
contact_allow : acl.allow_cid.join(','),
|
||||||
group_deny : acl.deny_gid.join(','),
|
group_deny : acl.deny_gid.join(','),
|
||||||
contact_deny : acl.deny_cid.join(',')
|
contact_deny : acl.deny_cid.join(',')
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uploader.setParams( {
|
uploader.setParams( {
|
||||||
newalbum : newalbum,
|
newalbum : newalbum,
|
||||||
album : album,
|
album : album,
|
||||||
not_visible : document.getElementById('photos-upload-noshare').checked,
|
not_visible : document.getElementById('photos-upload-noshare').checked,
|
||||||
group_allow : getSelected(document.getElementById('group_allow')).join(','),
|
group_allow : getSelected(document.getElementById('group_allow')).join(','),
|
||||||
contact_allow : getSelected(document.getElementById('contact_allow')).join(','),
|
contact_allow : getSelected(document.getElementById('contact_allow')).join(','),
|
||||||
group_deny : getSelected(document.getElementById('group_deny')).join(','),
|
group_deny : getSelected(document.getElementById('group_deny')).join(','),
|
||||||
contact_deny : getSelected(document.getElementById('contact_deny')).join(',')
|
contact_deny : getSelected(document.getElementById('contact_deny')).join(',')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -199,46 +199,46 @@ class qqUploadedFileXhr {
|
||||||
|
|
||||||
private $pathnm = '';
|
private $pathnm = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the file in the temp dir.
|
* Save the file in the temp dir.
|
||||||
* @return boolean TRUE on success
|
* @return boolean TRUE on success
|
||||||
*/
|
*/
|
||||||
function save() {
|
function save() {
|
||||||
$input = fopen("php://input", "r");
|
$input = fopen("php://input", "r");
|
||||||
|
|
||||||
$upload_dir = Config::get('system','tempdir');
|
$upload_dir = Config::get('system','tempdir');
|
||||||
if(! $upload_dir)
|
if(! $upload_dir)
|
||||||
$upload_dir = sys_get_temp_dir();
|
$upload_dir = sys_get_temp_dir();
|
||||||
|
|
||||||
$this->pathnm = tempnam($upload_dir,'frn');
|
$this->pathnm = tempnam($upload_dir,'frn');
|
||||||
|
|
||||||
$temp = fopen($this->pathnm,"w");
|
$temp = fopen($this->pathnm,"w");
|
||||||
$realSize = stream_copy_to_stream($input, $temp);
|
$realSize = stream_copy_to_stream($input, $temp);
|
||||||
|
|
||||||
fclose($input);
|
fclose($input);
|
||||||
fclose($temp);
|
fclose($temp);
|
||||||
|
|
||||||
if ($realSize != $this->getSize()){
|
if ($realSize != $this->getSize()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPath() {
|
function getPath() {
|
||||||
return $this->pathnm;
|
return $this->pathnm;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName() {
|
function getName() {
|
||||||
return $_GET['qqfile'];
|
return $_GET['qqfile'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSize() {
|
function getSize() {
|
||||||
if (isset($_SERVER["CONTENT_LENGTH"])){
|
if (isset($_SERVER["CONTENT_LENGTH"])){
|
||||||
return (int)$_SERVER["CONTENT_LENGTH"];
|
return (int)$_SERVER["CONTENT_LENGTH"];
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('Getting content length is not supported.');
|
throw new Exception('Getting content length is not supported.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,80 +248,80 @@ class qqUploadedFileXhr {
|
||||||
class qqUploadedFileForm {
|
class qqUploadedFileForm {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the file to the specified path
|
* Save the file to the specified path
|
||||||
* @return boolean TRUE on success
|
* @return boolean TRUE on success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPath() {
|
function getPath() {
|
||||||
return $_FILES['qqfile']['tmp_name'];
|
return $_FILES['qqfile']['tmp_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName() {
|
function getName() {
|
||||||
return $_FILES['qqfile']['name'];
|
return $_FILES['qqfile']['name'];
|
||||||
}
|
}
|
||||||
function getSize() {
|
function getSize() {
|
||||||
return $_FILES['qqfile']['size'];
|
return $_FILES['qqfile']['size'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class qqFileUploader {
|
class qqFileUploader {
|
||||||
private $allowedExtensions = [];
|
private $allowedExtensions = [];
|
||||||
private $sizeLimit = 10485760;
|
private $sizeLimit = 10485760;
|
||||||
private $file;
|
private $file;
|
||||||
|
|
||||||
function __construct(array $allowedExtensions = [], $sizeLimit = 10485760){
|
function __construct(array $allowedExtensions = [], $sizeLimit = 10485760){
|
||||||
$allowedExtensions = array_map("strtolower", $allowedExtensions);
|
$allowedExtensions = array_map("strtolower", $allowedExtensions);
|
||||||
|
|
||||||
$this->allowedExtensions = $allowedExtensions;
|
$this->allowedExtensions = $allowedExtensions;
|
||||||
$this->sizeLimit = $sizeLimit;
|
$this->sizeLimit = $sizeLimit;
|
||||||
|
|
||||||
if (isset($_GET['qqfile'])) {
|
if (isset($_GET['qqfile'])) {
|
||||||
$this->file = new qqUploadedFileXhr();
|
$this->file = new qqUploadedFileXhr();
|
||||||
} elseif (isset($_FILES['qqfile'])) {
|
} elseif (isset($_FILES['qqfile'])) {
|
||||||
$this->file = new qqUploadedFileForm();
|
$this->file = new qqUploadedFileForm();
|
||||||
} else {
|
} else {
|
||||||
$this->file = false;
|
$this->file = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function toBytes($str){
|
private function toBytes($str){
|
||||||
$val = trim($str);
|
$val = trim($str);
|
||||||
$last = strtolower($str[strlen($str)-1]);
|
$last = strtolower($str[strlen($str)-1]);
|
||||||
switch($last) {
|
switch($last) {
|
||||||
case 'g': $val *= 1024;
|
case 'g': $val *= 1024;
|
||||||
case 'm': $val *= 1024;
|
case 'm': $val *= 1024;
|
||||||
case 'k': $val *= 1024;
|
case 'k': $val *= 1024;
|
||||||
}
|
}
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns array('success'=>true) or array('error'=>'error message')
|
* Returns array('success'=>true) or array('error'=>'error message')
|
||||||
*/
|
*/
|
||||||
function handleUpload(){
|
function handleUpload(){
|
||||||
|
|
||||||
if (!$this->file){
|
if (!$this->file){
|
||||||
return ['error' => L10n::t('No files were uploaded.')];
|
return ['error' => L10n::t('No files were uploaded.')];
|
||||||
}
|
}
|
||||||
|
|
||||||
$size = $this->file->getSize();
|
$size = $this->file->getSize();
|
||||||
|
|
||||||
if ($size == 0) {
|
if ($size == 0) {
|
||||||
return ['error' => L10n::t('Uploaded file is empty')];
|
return ['error' => L10n::t('Uploaded file is empty')];
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ($size > $this->sizeLimit) {
|
// if ($size > $this->sizeLimit) {
|
||||||
|
|
||||||
// return array('error' => L10n::t('Uploaded file is too large'));
|
// return array('error' => L10n::t('Uploaded file is too large'));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
$maximagesize = Config::get('system','maximagesize');
|
$maximagesize = Config::get('system','maximagesize');
|
||||||
|
@ -331,32 +331,32 @@ class qqFileUploader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pathinfo = pathinfo($this->file->getName());
|
$pathinfo = pathinfo($this->file->getName());
|
||||||
$filename = $pathinfo['filename'];
|
$filename = $pathinfo['filename'];
|
||||||
|
|
||||||
if (!isset($pathinfo['extension'])) {
|
if (!isset($pathinfo['extension'])) {
|
||||||
Logger::warning('extension isn\'t set.', ['filename' => $filename]);
|
Logger::warning('extension isn\'t set.', ['filename' => $filename]);
|
||||||
}
|
}
|
||||||
$ext = defaults($pathinfo, 'extension', '');
|
$ext = defaults($pathinfo, 'extension', '');
|
||||||
|
|
||||||
if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){
|
if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){
|
||||||
$these = implode(', ', $this->allowedExtensions);
|
$these = implode(', ', $this->allowedExtensions);
|
||||||
return ['error' => L10n::t('File has an invalid extension, it should be one of ') . $these . '.'];
|
return ['error' => L10n::t('File has an invalid extension, it should be one of ') . $these . '.'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->file->save()){
|
if ($this->file->save()){
|
||||||
return [
|
return [
|
||||||
'success'=>true,
|
'success'=>true,
|
||||||
'path' => $this->file->getPath(),
|
'path' => $this->file->getPath(),
|
||||||
'filename' => $filename . '.' . $ext
|
'filename' => $filename . '.' . $ext
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
'error'=> L10n::t('Upload was cancelled, or server error encountered'),
|
'error'=> L10n::t('Upload was cancelled, or server error encountered'),
|
||||||
'path' => $this->file->getPath(),
|
'path' => $this->file->getPath(),
|
||||||
'filename' => $filename . '.' . $ext
|
'filename' => $filename . '.' . $ext
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue