X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js_upload%2Fjs_upload.php;h=89f62ea4dac04ef38714fc4e8ab8bf374d2baba4;hb=da159e9d2c95e341a39bdc845291ea97be0ca61f;hp=8810ec1123455a94ea2245376db43dc5eba81651;hpb=48fecb9a40d0a1bac959f239be1d937edd5b7f09;p=friendica-addons.git diff --git a/js_upload/js_upload.php b/js_upload/js_upload.php index 8810ec11..89f62ea4 100644 --- a/js_upload/js_upload.php +++ b/js_upload/js_upload.php @@ -1,19 +1,21 @@ * Maintainer: Hypolite Petovan */ use Friendica\App; -use Friendica\Core\Config; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; +use Friendica\Util\Strings; + +global $js_upload_jsonresponse; +global $js_upload_result; function js_upload_install() { @@ -37,24 +39,26 @@ function js_upload_form(App $a, array &$b) '$cancel' => DI::l10n()->t('Cancel'), '$failed' => DI::l10n()->t('Failed'), '$post_url' => $b['post_url'], - '$maximagesize' => intval(Config::get('system', 'maximagesize')), + '$maximagesize' => intval(DI::config()->get('system', 'maximagesize')), ]); } function js_upload_post_init(App $a, &$b) { + global $js_upload_result, $js_upload_jsonresponse; + // list of valid extensions $allowedExtensions = ['jpeg', 'gif', 'png', 'jpg']; // max file size in bytes - $sizeLimit = Config::get('system', 'maximagesize'); + $sizeLimit = DI::config()->get('system', 'maximagesize'); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $result = $uploader->handleUpload(); // to pass data through iframe you will need to encode all html tags - $a->data['upload_jsonresponse'] = htmlspecialchars(json_encode($result), ENT_NOQUOTES); + $js_upload_jsonresponse = htmlspecialchars(json_encode($result), ENT_NOQUOTES); if (isset($result['error'])) { Logger::log('mod/photos.php: photos_post(): error uploading photo: ' . $result['error'], Logger::DEBUG); @@ -62,12 +66,14 @@ function js_upload_post_init(App $a, &$b) exit(); } - $a->data['upload_result'] = $result; + $js_upload_result = $result; } function js_upload_post_file(App $a, &$b) { - $result = $a->data['upload_result']; + global $js_upload_result; + + $result = $js_upload_result; $b['src'] = $result['path']; $b['filename'] = $result['filename']; @@ -77,9 +83,11 @@ function js_upload_post_file(App $a, &$b) function js_upload_post_end(App $a, &$b) { + global $js_upload_jsonresponse; + Logger::log('upload_post_end'); - if (!empty($a->data['upload_jsonresponse'])) { - echo $a->data['upload_jsonresponse']; + if (!empty($js_upload_jsonresponse)) { + echo $js_upload_jsonresponse; exit(); } } @@ -100,7 +108,7 @@ class qqUploadedFileXhr { $input = fopen('php://input', 'r'); - $upload_dir = Config::get('system', 'tempdir'); + $upload_dir = DI::config()->get('system', 'tempdir'); if (!$upload_dir) $upload_dir = sys_get_temp_dir(); @@ -228,11 +236,10 @@ class qqFileUploader // } - $maximagesize = Config::get('system', 'maximagesize'); + $maximagesize = DI::config()->get('system', 'maximagesize'); if (($maximagesize) && ($size > $maximagesize)) { - return ['error' => DI::l10n()->t('Image exceeds size limit of ') . $maximagesize]; - + return ['error' => DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize))]; } $pathinfo = pathinfo($this->file->getName()); @@ -244,8 +251,7 @@ class qqFileUploader $ext = $pathinfo['extension'] ?? ''; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { - $these = implode(', ', $this->allowedExtensions); - return ['error' => DI::l10n()->t('File has an invalid extension, it should be one of ') . $these . '.']; + return ['error' => DI::l10n()->t('File has an invalid extension, it should be one of %s.', implode(', ', $this->allowedExtensions))]; } if ($this->file->save()) {