<?php
/**
* Name: JS Uploader
- * Description: JavaScript photo/image uploader. Uses Valum 'qq' Uploader.
+ * Description: JavaScript photo/image uploader. Helpful for uploading multiple files at once. Uses Valum 'qq' Uploader.
* Version: 1.1
* Author: Chris Case <http://friendika.openmindspace.org/profile/chris_case>
* Maintainer: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
*/
use Friendica\App;
-use Friendica\Core\Config;
use Friendica\Core\Hook;
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()
{
function js_upload_post_init(App $a, &$b)
{
+ global $js_upload_result, $js_upload_jsonresponse;
+
// list of valid extensions
$allowedExtensions = ['jpeg', 'gif', 'png', 'jpg'];
$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);
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'];
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();
}
}
$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());
$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()) {