mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
Improved example plugin to test for admin section
This commit is contained in:
parent
603d48f739
commit
c1017499e4
3 changed files with 48 additions and 5 deletions
|
|
@ -17,12 +17,17 @@ class BackupPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
{
|
||||
// Admin Settings tab
|
||||
$this->addJs('js/BackupAdminSettings.js', true); // add js file
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
|
||||
$this->addJsonHook('JsonAdminGetData');
|
||||
$this->addJsonHook('JsonAdminRestoreData');
|
||||
$this->addTemplate('templates/BackupAdminSettingsTab.html', true);
|
||||
}
|
||||
|
||||
public function JsonAdminGetData()
|
||||
{
|
||||
if (!($this->Manager()->Actions() instanceof \RainLoop\ActionsAdmin)) {
|
||||
return $this->jsonResponse(__FUNCTION__, false);
|
||||
}
|
||||
|
||||
$sZipHash = \MailSo\Base\Utils::Sha1Rand();
|
||||
$sZipFileName = APP_PRIVATE_DATA . $sZipHash . '.zip';
|
||||
|
||||
|
|
@ -39,10 +44,39 @@ class BackupPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$oZip->addRecursive(APP_PRIVATE_DATA.'configs', 'configs');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'domains', 'domains');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'plugins', 'plugins');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'storage', 'storage');
|
||||
$oZip->close();
|
||||
|
||||
$data = \base64_encode(\file_get_contents($sZipFileName));
|
||||
\unlink($sZipFileName);
|
||||
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'zip' => \base64_encode(\file_get_contents($sZipFileName))
|
||||
'zip' => $data
|
||||
));
|
||||
}
|
||||
|
||||
public function JsonAdminRestoreData()
|
||||
{
|
||||
if (!($this->Manager()->Actions() instanceof \RainLoop\ActionsAdmin)
|
||||
|| empty($_FILES['backup'])
|
||||
|| 'application/zip' !== $_FILES['backup']['type']
|
||||
|| !\is_uploaded_file($_FILES['backup']['tmp_name'])
|
||||
) {
|
||||
return $this->jsonResponse(__FUNCTION__, false);
|
||||
}
|
||||
|
||||
if (\class_exists('ZipArchive')) {
|
||||
$oArchive = new \ZipArchive();
|
||||
$oArchive->open($_FILES['backup']['tmp_name'], \ZIPARCHIVE::CREATE);
|
||||
$oArchive->extractTo(APP_PRIVATE_DATA);
|
||||
} else if (\class_exists('PharData')) {
|
||||
$oArchive = new \PharData($sTmp, 0, null, \Phar::GZ);
|
||||
$oArchive->extractTo(APP_PRIVATE_DATA);
|
||||
}
|
||||
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'$_FILES' => $_FILES
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
});
|
||||
} else {
|
||||
var link = document.createElement("a");
|
||||
link.download = 'backup.zip';
|
||||
link.download = 'backup-' + Date.now() + '.zip';
|
||||
link.href = 'data:application/zip;base64,' + oData.Result.zip;
|
||||
link.textContent = 'backup.zip';
|
||||
this.viewModelDom.append(link);
|
||||
|
|
@ -32,6 +32,13 @@
|
|||
|
||||
}, 'JsonAdminGetData');
|
||||
}
|
||||
|
||||
submitForm(form) {
|
||||
form.reportValidity()
|
||||
&& rl.pluginRemoteRequest((iError, oData) => {
|
||||
console.dir(oData);
|
||||
}, 'JsonAdminRestoreData', new FormData(form));
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModelForAdmin(BackupAdminSettings, 'BackupAdminSettingsTab',
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
// Admin Settings tab
|
||||
$this->addJs('js/ExampleAdminSettings.js', true); // add js file
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData', true);
|
||||
$this->addTemplate('templates/ExampleAdminSettingsTab.html', true);
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +82,9 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
public function JsonAdminGetData()
|
||||
{
|
||||
if ($this->Manager()->Actions() instanceof \RainLoop\ActionsAdmin) {
|
||||
return $this->jsonResponse(__FUNCTION__, false);
|
||||
}
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'PHP' => \phpversion()
|
||||
));
|
||||
|
|
@ -172,7 +175,6 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
protected function configMapping() : array
|
||||
protected function jsonResponse(string $sFunctionName, $mData)
|
||||
protected function replaceTemplate(string $sFile, bool $bAdminScope = false) : self
|
||||
|
||||
$this->Manager()
|
||||
$this->Manager()->Actions()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue