Skip to content
Code-Schnipsel Gruppen Projekte
Commit 9691543b erstellt von Florian Bogner's avatar Florian Bogner
Dateien durchsuchen

feat: Added upload capacility

Übergeordneter 0bcf2ee9
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
<?php
QUI::$Ajax->registerFunction(
'package_quiqqer_ckeditor4_ajax_uploadComplete',
function ($File) {
$filePath = $File->getAttribute('filepath');
$Manager = new \QUI\Ckeditor\Plugins\Manager();
try {
$Manager->installPlugin($filePath);
} catch (\Exception $Exception) {
QUI::getMessagesHandler()->addError($Exception->getMessage());
}
},
array('File')
);
\ No newline at end of file
......@@ -64,6 +64,15 @@ define('package/quiqqer/ckeditor4/bin/controls/settings/Plugins', [
events : {
onClick: this.$toggleState
}
}, {
name : 'upload',
text : QUILocale.get(
"quiqqer/ckeditor4",
"editors.settings.plugins.table.button.upload"
),
events: {
onClick: this.$displayUpload
}
}],
height : "500",
columnModel: [
......@@ -99,6 +108,8 @@ define('package/quiqqer/ckeditor4/bin/controls/settings/Plugins', [
var StateBtn = TableButtons.state;
console.log(TableButtons);
var data = self.$Grid.getSelectedData()[0];
if (!data) {
......@@ -271,8 +282,16 @@ define('package/quiqqer/ckeditor4/bin/controls/settings/Plugins', [
onError : reject
});
});
}
},
$displayUpload: function () {
var self = this;
require(['package/quiqqer/ckeditor4/bin/windows/Upload'], function (Window) {
new Window({}).open();
});
}
}
);
});
\ No newline at end of file
define('package/quiqqer/ckeditor4/bin/windows/Upload', [
'qui/QUI',
'qui/controls/windows/Confirm',
'Locale',
'controls/upload/Form'
], function (QUI, QUIConfirm, QUILocale, UploadForm) {
"use strict";
return new Class({
Extends: QUIConfirm,
Type : 'package/quiqqer/ckeditor4/bin/windows/Upload',
Binds: [
'$onSubmit',
'$onOpen',
'$onComplete'
],
initialize: function (options) {
this.setAttributes({
title : QUILocale.get("quiqqer/ckeditor4", "window.upload.title"),
icon : 'fa fa-upload',
maxWidth : 400,
maxHeight : 600,
autoclose : false,
texticon : false,
cancel_button: {
text : false,
textimage: 'icon-remove fa fa-remove'
},
ok_button : {
text : QUILocale.get("quiqqer/ckeditor4", "window.upload.button.upload"),
textimage: 'fa fa-upload'
}
});
this.$Upload = null;
this.parent(options);
this.addEvents({
onOpen: this.$onOpen,
submit: this.$onSubmit
});
},
/**
* Calls the ajax function to get the labels from gitlab and sets up its controls.
*/
$onOpen: function () {
var self = this;
var Content = this.getContent();
this.$Upload = new UploadForm({
multible : false,
sendbutton : false,
cancelbutton: false,
events : {
onComplete: self.$onComplete
},
styles : {
height: '95%'
}
});
this.$Upload.setParam('onfinish', 'package_quiqqer_ckeditor4_ajax_uploadComplete');
this.$Upload.setParam('extract', 0);
this.$Upload.inject(Content);
},
$onSubmit: function () {
this.$Upload.submit();
},
$onComplete: function (Form, File, result) {
QUI.MessageHandler.addSuccess(
QUILocale.get("quiqqer/ckeditor4", "message.window.upload.complete")
);
this.close();
}
});
});
......@@ -23,6 +23,39 @@
<en><![CDATA[The given plugin is not active]]></en>
</locale>
<!--Upload-->
<locale name="window.upload.title">
<de><![CDATA[Plugin hochladen]]></de>
<en><![CDATA[Upload plugin]]></en>
</locale>
<locale name="window.upload.button.upload">
<de><![CDATA[Hochladen]]></de>
<en><![CDATA[Upload]]></en>
</locale>
<locale name="message.window.upload.complete">
<de><![CDATA[Der Upload ist beendet und das Plugin wird nun installiert]]></de>
<en><![CDATA[The upload is complete and the plugin will now get installed]]></en>
</locale>
<locale name="exception.install.file.invalid.format">
<de>
<![CDATA[Die hochegaldene Datei hat das falsche Format oder ist beschädigt. Bitte laden Sie ein intaktes Ziparchiv hoch.]]></de>
<en>
<![CDATA[The uploaded file is either corrupted or does not have the correct format. Please upload a zip file.]]></en>
</locale>
<locale name="exception.install.file.extract.failed">
<de>
<![CDATA[Während des Entpackens des Archivs ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.]]></de>
<en><![CDATA[An error occured while extracteing the archive. Please try again]]></en>
</locale>
<locale name="message.plugin.install.success">
<de><![CDATA[Das Plugin wurde erfolgreich installiert]]></de>
<en><![CDATA[The plugin has been installed successfully]]></en>
</locale>
<locale name="exception.install.file.exists">
<de><![CDATA[Ein Plugin mit diesem Namen existiert bereits!]]></de>
<en><![CDATA[A plugin with the same name is installed already]]></en>
</locale>
<!--Settings -->
<locale name="editors.settings.plugins.table.header.state">
<de><![CDATA[Status]]></de>
......@@ -40,6 +73,10 @@
<de><![CDATA[Deaktivieren]]></de>
<en><![CDATA[Deactivate]]></en>
</locale>
<locale name="editors.settings.plugins.table.button.upload">
<de><![CDATA[Hochladen]]></de>
<en><![CDATA[Upload]]></en>
</locale>
<locale name="message.settings.plugins.activation.success">
<de><![CDATA[Plugin erfolgreich aktiviert]]></de>
<en><![CDATA[Plugin enabled successfully]]></en>
......
......@@ -3,6 +3,7 @@
namespace QUI\Ckeditor\Plugins;
use QUI\Archiver\Zip;
use QUI\Exception;
use QUI\System\Log;
use QUI\Utils\Security\Orthos;
......@@ -23,6 +24,7 @@ class Manager
/**
* List of plugins which should be installed
*
* @var array
*/
protected $blacklist = array(
......@@ -187,6 +189,67 @@ class Manager
return $result;
}
/**
* Installs a plugin zip file from the given path
*
* @param $pluginpath
*
* @throws Exception
*/
public function installPlugin($pluginpath)
{
# Check if file exists
if (!file_exists($pluginpath)) {
throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.not.found"));
}
$tmpDir = \QUI::getTemp()->createFolder();
copy(
$pluginpath,
$tmpDir . "/archive.zip"
);
$Zip = new \ZipArchive();
if ($Zip->open($tmpDir . "/archive.zip") === false) {
throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.invalid.format"));
}
if ($Zip->extractTo($tmpDir . "/content") === false) {
throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.extract.failed"));
}
foreach (scandir($tmpDir . "/content") as $entry) {
if ($entry == "." || $entry == "..") {
continue;
}
if (is_dir($this->installedPluginDir . "/" . $entry)) {
throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists"));
}
if (is_dir($this->activePluginDir . "/" . $entry)) {
throw new Exception(array("quiqqer/ckeditor4", "exception.install.file.exists"));
}
rename(
$tmpDir . "/content/" . $entry,
$this->installedPluginDir . "/" . $entry
);
}
File::deleteDir($tmpDir);
\QUI::getMessagesHandler()->addSuccess(
\QUI::getLocale()->get(
"quiqqer/ckeditor4",
"message.plugin.install.success"
)
);
}
#########################################
# Enable/Disable #
#########################################
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren