Commit bea12522 authored by Henning Leutz's avatar Henning Leutz 🥋

fix: merge conflict solved

parents b0723fb3 f30d13d4
<?php
/**
* Upload callback if a file is finished uploaded
*/
QUI::$Ajax->registerFunction(
'ajax_uploads_callback',
function ($File, $callable) {
if (!isset($callable)) {
return;
}
if (!\class_exists($callable)) {
return;
}
QUI\Permissions\Permission::checkPermission('quiqqer.frontend.upload');
$Callable = new $callable();
if ($Callable instanceof QUI\Upload\Form) {
/* @var $File \QUI\QDOM */
$Callable->onFileFinish(
$File->getAttribute('filepath'),
$File->getAttributes()
);
}
},
['File', 'callable']
);
......@@ -419,7 +419,7 @@
<option value="404">404 - Not Found</option>
</select>
<input type="hidden" conf="globals.nonce" label="false" />
<input type="hidden" conf="globals.nonce" label="false"/>
</settings>
<settings title="templateengine" name="templateengine">
......
......@@ -13,8 +13,7 @@ define('controls/permissions/Panel', [
], function (QUI, QUIPanel, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -323,7 +322,6 @@ define('controls/permissions/Panel', [
});
});
});
}).catch(function () {
self.openWelcomeMessage();
});
......
......@@ -133,4 +133,8 @@
text-overflow: ellipsis;
width: calc(100% - 20px);
white-space: nowrap;
}
\ No newline at end of file
}
.qui-permission-entry input[type="text"] {
width: 100%;
}
......@@ -98,11 +98,11 @@ define('controls/upload/File', [
this.$is_paused = false;
this.$file_size = this.$File.size;
this.$chunk_size = (1024 * 100);
this.$chunk_size = (1024 * 256); // 256kb
this.$range_start = 0;
this.$range_end = this.$chunk_size;
this.$upload_time = null;
this.$execute = true; // false if no excute of the update routine
this.$execute = true; // false if no execute of the update routine
this.$result = null;
this.$error = false;
......
......@@ -96,4 +96,109 @@
.controls-upload-form-fileinfo:hover {
background-color: #2F8FC6;
color: #fff;
}
\ No newline at end of file
}
/** icon design
================================== */
.controls-upload-form--icon {
border: 1px solid #dedede;
display: inline-block;
width: initial;
}
.controls-upload-form--icon form {
border: none;
padding: 0;
}
.controls-upload-form--icon form input {
display: none;
}
.controls-upload-form--icon .controls-upload-icon {
cursor: pointer;
font-size: 24px;
padding: 20px;
text-align: center;
width: 100%;
}
.controls-upload-form-submit {
cursor: pointer;
font-size: 12px;
text-align: center;
width: 100%;
}
.controls-upload-form-submit span {
padding: 0 5px;
}
/** single design
================================== */
.controls-upload-form--single {
max-width: 400px;
width: 100%;
}
.controls-upload-form--single form {
border: none;
padding: 0;
}
.controls-upload-form-single {
display: flex;
}
.controls-upload-form-single input {
display: none;
}
.controls-upload-form-single-container {
display: flex;
width: calc(100% - 130px);
}
.controls-upload-form-single-container-preview {
background-color: rgba(0, 0, 0, 0.2);
background-position: center;
background-size: cover;
display: inline-block;
height: 30px;
overflow: hidden;
width: 30px;
}
.controls-upload-form-single-container-preview img {
max-width: 100%;
}
.controls-upload-form-single-container-select-placeholder {
color: #bebebe;
}
.controls-upload-form-single-container-select {
border: 1px solid rgba(0, 0, 0, 0.2);
cursor: pointer;
display: inline-block;
height: 30px;
line-height: 30px;
overflow: hidden;
padding: 0 10px;
text-overflow: ellipsis;
white-space: nowrap;
width: calc(100% - 30px);
}
.controls-upload-form-single-container-select:hover {
background: rgba(0, 0, 0, 0.05);
}
.controls-upload-form--single .controls-upload-form-submit {
display: inline-block;
width: 130px;
}
This diff is collapsed.
......@@ -304,6 +304,8 @@ class Manager
* defaultvalue =>
* src =>
* )
*
* @throws QUI\Database\Exception
*/
public function addPermission($params)
{
......@@ -430,7 +432,11 @@ class Manager
$permission['defaultvalue'] = $permission['default'];
}
$this->addPermission($permission);
try {
$this->addPermission($permission);
} catch (QUI\Exception $Exception) {
QUI\System\Log::addError($Exception->getMessage());
}
}
}
......@@ -527,7 +533,7 @@ class Manager
* Return the current permissions from a group, user, site, project or media
* Returns the set permissions
*
* @param QUI\Groups\Group|QUI\Users\User|QUI\Projects\Project|QUI\Projects\Site $Obj
* @param QUI\Groups\Group|QUI\Interfaces\Users\User|QUI\Projects\Project|QUI\Projects\Site $Obj
*
* @return array
*/
......@@ -1517,7 +1523,6 @@ class Manager
break;
case 'string':
$val = Orthos::clearMySQL($val);
break;
default:
......
......@@ -718,6 +718,32 @@ class Permission
return isset($permissions[$perm]) ? $permissions[$perm] : false;
}
/**
* Return a permission of the user
* - can be user for string permissions
*
* @param string $perm
* @param QUI\Interfaces\Users\User|null $User
*
* @return mixed|boolean
*/
public static function getPermission($perm, $User = null)
{
if ($User === null) {
$User = self::getUser();
}
$Manager = QUI::getPermissionManager();
$permissions = $Manager->getPermissions($User);
// first check user permission
if (isset($permissions[$perm]) && !empty($permissions[$perm])) {
return $permissions[$perm];
}
return isset($permissions[$perm]) ? $permissions[$perm] : false;
}
/**
* has the User the permission at the site?
*
......
......@@ -37,6 +37,16 @@ class Media extends QUI\QDOM
*/
protected static $mediaPermissions = null;
/**
* This flag indicates if the creation of media item/folder cache is disabled
* when createCache() is called.
*
* This should only be set to true if a lot of media items are created (e.g. in a mass import).
*
* @var bool
*/
public static $globalDisableMediaCacheCreation = false;
/**
* constructor
*
......@@ -308,7 +318,7 @@ class Media extends QUI\QDOM
$DataBase->table()->setIndex($table, 'pathHash');
try {
$DataBase->fetchSQL('UPDATE '.$table.' SET pathHash = MD5(file)');
$DataBase->execSQL('UPDATE '.$table.' SET pathHash = MD5(file)');
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
......
......@@ -7,6 +7,7 @@
namespace QUI\Projects\Media;
use QUI;
use QUI\Projects\Media;
/**
* Class ExternalImage
......@@ -147,6 +148,10 @@ class ExternalImage implements QUI\Interfaces\Projects\Media\File
*/
public function createCache()
{
if (Media::$globalDisableMediaCacheCreation) {
return false;
}
return $this->createSizeCache();
}
......
......@@ -7,6 +7,7 @@
namespace QUI\Projects\Media;
use QUI;
use QUI\Projects\Media;
use QUI\Utils\System\File as QUIFile;
/**
......@@ -28,6 +29,10 @@ class File extends Item implements QUI\Interfaces\Projects\Media\File
*/
public function createCache()
{
if (Media::$globalDisableMediaCacheCreation) {
return false;
}
if (!$this->getAttribute('active')) {
return false;
}
......
......@@ -1204,6 +1204,10 @@ class Folder extends Item implements QUI\Interfaces\Projects\Media\File
*/
public function createCache()
{
if (Media::$globalDisableMediaCacheCreation) {
return false;
}
if (!$this->getAttribute('active')) {
return true;
}
......
......@@ -109,6 +109,10 @@ class Image extends Item implements QUI\Interfaces\Projects\Media\File
*/
public function createCache()
{
if (Media::$globalDisableMediaCacheCreation) {
return false;
}
return $this->createSizeCache();
}
......
......@@ -268,7 +268,7 @@ abstract class Item extends QUI\QDOM
* Return the alt text
*
* @param null|QUI\Locale $Locale
* @return mixed
* @return string
*/
public function getAlt($Locale = null)
{
......@@ -286,7 +286,14 @@ abstract class Item extends QUI\QDOM
return $this->alt[$current];
}
return \reset($this->alt);
\reset($this->alt);
$result = \current($this->alt);
if (empty($result)) {
return '';
}
return $result;
}
//endregion
......
......@@ -387,19 +387,27 @@ class Utils
$imageWidth = $Image->getWidth();
$maxWidth = false;
$maxHeight = false;
if (isset($attributes['width'])) {
$maxWidth = (int)$attributes['width'];
}
if (isset($attributes['style']) && \strpos($attributes['style'], 'width') !== false) {
if (isset($attributes['height'])) {
$maxHeight = (int)$attributes['height'];
}
if (isset($attributes['style'])) {
$style = StringUtils::splitStyleAttributes($attributes['style']);
if (isset($style['width']) && \strpos($style['width'], '%') === false) {
$maxWidth = (int)$style['width'];
}
}
if (isset($style['height']) && \strpos($style['height'], '%') === false) {
$maxHeight = (int)$style['height'];
}
}
if ($imageWidth) {
$end = $maxWidth && $imageWidth > $maxWidth ? $maxWidth : $imageWidth;
......@@ -410,17 +418,32 @@ class Utils
// @todo setting
$batchSize = 200;
$duplicate = [];
for (; $start < $end + $batchSize; $start += $batchSize) {
$media = '(max-width: '.$start.'px)';
if ($maxHeight) {
$media = '(max-width: '.$start.'px; max-height: '.$maxHeight.'px)';
}
$imageUrl = $Image->getSizeCacheUrl($start, $maxHeight);
if (isset($duplicate[$imageUrl])) {
continue;
}
$duplicate[$imageUrl] = true;
$sets[] = [
'src' => \htmlspecialchars($Image->getSizeCacheUrl($start)),
'media' => '(max-width: '.$start.'px)',
'src' => \htmlspecialchars($imageUrl),
'media' => $media,
'type' => $Image->getAttribute('mime_type')
];
}
// last one is the original
if ($maxWidth) {
if ($maxWidth || $maxHeight) {
$sets[\array_key_last($sets)]['media'] = '';
} else {
$sets[] = [
......@@ -450,6 +473,12 @@ class Utils
$img = '<img ';
foreach ($attributes as $key => $value) {
if (is_array($value) && $key === 'alt') {
$value = $Image->getAlt();
} elseif (!is_string($value)) {
continue;
}
$value = \htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
$value = \htmlentities($value);
......
......@@ -89,10 +89,6 @@ class Setup
// workspaces
Workspace\Manager::setup();
// Upload Manager
$UploadManager = new Upload\Manager();
$UploadManager->setup();
QUI::getEvents()->fireEvent('setupMainSystemEnd');
}
......
<div class="form-upload-{$id}"></div>
<script>
(function () {
require(['qui/QUI', 'controls/upload/Form'], function (QUI, UploadForm) {
var maxFileSize = {$maxFileSize};
var allowedFileTypes = {$allowedFileTypes};
var Form = new UploadForm({
name : '{$name}',
contextMenu: {$contextMenu},
multiple : {$multiple},
sendbutton : {$sendbutton},
maxuploads : {$uploads},
Drops : [],
hasFile : {$hasFile},
deleteFile : {$deleteFile},
typeOfLook : "{$typeOfLook}",
events : {
onFinished: function (Form) {
console.log('done', arguments);
},
onError: function (Form, Message) {
QUI.getMessageHandler().then(function (MH) {
MH.addError(Message.getMessage());
});
},
onAdd: function (Control, File) {
if (typeof FileReader === 'undefined') {
return;
}
if (!maxFileSize === false && File.size > maxFileSize) {
return false;
}
var isAllowed = function (type) {
if (!allowedFileTypes.length) {
return true;
}
for (var i = 0; i < allowedFileTypes.length; i++) {
if (type === allowedFileTypes[i]) {
return true;
}
}
return false;
};
if (!isAllowed(File.type)) {
var files = Control.getElm().getElements(
'.controls-upload-form-fileinfo'
);
files = files.filter(function (F) {
return F.get('text').trim() === File.name;
});
files[0].getParent().getElement('button').click();
}
}
}
});
Form.setParam('onfinish', 'ajax_uploads_callback');
Form.setParam('package', 'quiqqer/quiqqer');
Form.setParam('callable', '{$callable}');
Form.inject(document.getElement('.form-upload-{$id}'));
});
})();
</script>
<?php
namespace QUI\Upload;
use QUI;
use QUI\Permissions\Permission;
/**
* Class Form
*
* @package QUI\Upload
*/
class Form extends QUI\QDOM
{
/**
* Form constructor.
*
* @param array $params
*/
public function __construct($params = [])
{
// defaults
$this->setAttributes([
'name' => 'test-upload',
'contextMenu' => true,
'multiple' => true,
'sendbutton' => true,
'uploads' => 1,
'hasFile' => false,
'deleteFile' => true,
'allowedFileTypes' => false, // eq: ['image/jpeg', 'image/png']
'allowedFileEnding' => false, // eq: ['.gif', '.jpg']
'maxFileSize' => false, // eq: 20000000 = 20mb
'typeOfLook' => 'DragDrop', // DragDrop, Icon, Single
'typeOfLookIcon' => 'fa fa-upload'
]);
// set default allowed file types
if (!isset($params['allowedFileTypes'])) {
$allowedTypes = Permission::getPermission(
'quiqqer.upload.allowedTypes'
);
$this->setAttribute('allowedFileTypes', $allowedTypes);
}
// set default allowed file endings
if (!isset($params['allowedFileEnding'])) {
$allowedEndings = Permission::getPermission(
'quiqqer.upload.allowedEndings'
);
$this->setAttribute('allowedFileEnding', $allowedEndings);
}
parent::setAttributes($params);
}
/**
* Return the generated JS control
*/
public function create()
{
$Engine = QUI::getTemplateManager()->getEngine();
switch ($this->getAttribute('typeOfLook')) {
case 'DragDrop':
case 'Icon':
case 'Single':
$typeOfLook = $this->getAttribute('typeOfLook');
break;
default:
$typeOfLook = 'DragDrop';
break;
}
$Engine->assign([
'this' => $this,
'name' => $this->getAttribute('name'),
'id' => QUI\Utils\Uuid::get(),
'uploads' => \intval($this->getAttribute('uploads')),
'contextMenu' => $this->phpBool2JsBool(\boolval($this->getAttribute('contextMenu'))),
'multiple' => $this->phpBool2JsBool(\boolval($this->getAttribute('multiple'))),
'sendbutton' => $this->phpBool2JsBool(\boolval($this->getAttribute('sendbutton'))),
'hasFile' => $this->phpBool2JsBool(\boolval($this->getAttribute('hasFile'))),
'deleteFile' => $this->phpBool2JsBool(\boolval($this->getAttribute('deleteFile'))),
'callable' => \str_replace('\\', '\\\\', $this->getType()),
'typeOfLook' => $typeOfLook
]);
$maxFileSize = $this->getAttribute('maxFileSize');
$allowedFileTypes = $this->getAttribute('allowedFileTypes');
if (!$maxFileSize) {
$Engine->assign('maxFileSize', $this->phpBool2JsBool($maxFileSize));
} else {
$Engine->assign('maxFileSize', (int)$maxFileSize);
}
if (!$allowedFileTypes) {
$Engine->assign('allowedFileTypes', '[]');
} else {
$Engine->assign('allowedFileTypes', \json_encode($allowedFileTypes));
}
return $Engine->fetch(\dirname(__FILE__).'/Form.html');
}
/**
* Return a php bool var for js bool
*
* @param $var
* @return string
*/
public function phpBool2JsBool($var)
{
return $var ? 'true' : 'false';
}
//region API Events
/**
* Can be overwritten - will be called if the upload is finished
*
* @param $file
* @param $params
*/
public function onFileFinish($file, $params)
{
}
//endregion
}
This diff is collapsed.
......@@ -12,6 +12,8 @@ $dir = \str_replace('quiqqer/quiqqer/lib/QUI/Upload/bin', '', \dirname(__FILE__)
require_once $dir.'header.php';
try {
QUI\Permissions\Permission::checkPermission('quiqqer.frontend.upload');
$QUM = new QUI\Upload\Manager();
QUI::getAjax();
......
......@@ -277,6 +277,12 @@
<locale name="permission.quiqqer.editors.toolbar.delete">
<de><![CDATA[Darf Editor Toolbars löschen]]></de>
</locale>
<locale name="permission.quiqqer.frontend._header">
<de><![CDATA[Frontend]]></de>
</locale>
<locale name="permission.quiqqer.frontend.upload">
<de><![CDATA[Darf Dateien im Frontend hochladen.]]></de>
</locale>
<locale name="projects.project.settings.panel.placeholder">
<de><![CDATA[Platzhalterbild]]></de>
</locale>
......@@ -609,7 +615,14 @@
<de><![CDATA[Sie besitzen nicht die nötigen Rechte um die Konfiguration zu speichern.]]></de>
</locale>
<locale name="exception.media.upload.fileSize.is.to.big">
<de><![CDATA[Die Datei ist leider zu gross. Die maximale Uploadgröße ist einer Datei beträgt [size]]]></de>
<de>
<![CDATA[Die Datei [file] ist leider zu gross. Die maximale Uploadgröße einer Datei beträgt [size]]]></de>
</locale>
<locale name="exception.media.upload.fileType.not.allowed">
<de><![CDATA[
Der Dateityp der Datei [file] ist leider nicht erlaubt.
Bitte nutze nur folgende Dateitypen: [filetypes]
]]></de>
</locale>
<locale name="exception.media.move.is.no.folder">
<de><![CDATA[Bitte wählen Sie einen Ordner aus um die Dateien zu verschieben.]]></de>
......@@ -1478,6 +1491,9 @@
<locale name="permissions.panel.btn.select.project">
<de><![CDATA[Für ein Projekt]]></de>
</locale>
<locale name="permissions.panel.btn.select.media">
<de><![CDATA[Für den Mediabereich]]></de>
</locale>
<locale name="permissions.panel.btn.select.manage">