use My class
parent
93ff904729
commit
956da8a211
|
@ -33,27 +33,9 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class Backend extends Process
|
class Backend extends Process
|
||||||
{
|
{
|
||||||
/** @var string Public packages folder */
|
|
||||||
public const TINYPACKER_DIR = 'packages';
|
|
||||||
|
|
||||||
/** @var array Excluded files and dirs */
|
|
||||||
public const TINYPACKER_EXCLUDE = [
|
|
||||||
'\.',
|
|
||||||
'\.\.',
|
|
||||||
'__MACOSX',
|
|
||||||
'\.svn',
|
|
||||||
'\.hg.*?',
|
|
||||||
'\.git.*?',
|
|
||||||
'CVS',
|
|
||||||
'\.directory',
|
|
||||||
'\.DS_Store',
|
|
||||||
'Thumbs\.db',
|
|
||||||
'_disabled',
|
|
||||||
];
|
|
||||||
|
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
{
|
{
|
||||||
return self::status(defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->isSuperAdmin());
|
return self::status(My::checkContext(My::BACKEND));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function process(): bool
|
public static function process(): bool
|
||||||
|
@ -67,18 +49,18 @@ class Backend extends Process
|
||||||
return in_array($list->getList(), [
|
return in_array($list->getList(), [
|
||||||
'plugin-activate',
|
'plugin-activate',
|
||||||
'theme-activate',
|
'theme-activate',
|
||||||
]) ? (new Submit([self::id() . '[' . Html::escapeHTML($id) . ']']))->value(__('Pack'))->render() : '';
|
]) ? (new Submit([My::id() . '[' . Html::escapeHTML($id) . ']']))->value(__('Pack'))->render() : '';
|
||||||
},
|
},
|
||||||
'adminModulesListDoActions' => function (ModulesList $list, array $modules, string $type): void {
|
'adminModulesListDoActions' => function (ModulesList $list, array $modules, string $type): void {
|
||||||
# Pack action
|
# Pack action
|
||||||
if (empty($_POST[self::id()])
|
if (empty($_POST[My::id()])
|
||||||
|| !is_array($_POST[self::id()])) {
|
|| !is_array($_POST[My::id()])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Repository directory
|
# Repository directory
|
||||||
$dir = (string) Path::real(
|
$dir = (string) Path::real(
|
||||||
dcCore::app()->blog->public_path . DIRECTORY_SEPARATOR . self::TINYPACKER_DIR,
|
dcCore::app()->blog->public_path . DIRECTORY_SEPARATOR . My::TINYPACKER_DIR,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (!empty($dir) && !is_dir($dir)) {
|
if (!empty($dir) && !is_dir($dir)) {
|
||||||
|
@ -89,7 +71,7 @@ class Backend extends Process
|
||||||
}
|
}
|
||||||
|
|
||||||
# Module to pack
|
# Module to pack
|
||||||
$modules = array_keys($_POST[self::id()]);
|
$modules = array_keys($_POST[My::id()]);
|
||||||
$id = $modules[0];
|
$id = $modules[0];
|
||||||
|
|
||||||
$module = $list->modules->getDefine($id);
|
$module = $list->modules->getDefine($id);
|
||||||
|
@ -109,7 +91,7 @@ class Backend extends Process
|
||||||
$fp = fopen($dir . DIRECTORY_SEPARATOR . $file, 'wb');
|
$fp = fopen($dir . DIRECTORY_SEPARATOR . $file, 'wb');
|
||||||
$zip = new Zip($fp);
|
$zip = new Zip($fp);
|
||||||
|
|
||||||
foreach (self::TINYPACKER_EXCLUDE as $e) {
|
foreach (My::TINYPACKER_EXCLUDE as $e) {
|
||||||
$zip->addExclusion(sprintf(
|
$zip->addExclusion(sprintf(
|
||||||
'#(^|/)(%s)(/|$)#',
|
'#(^|/)(%s)(/|$)#',
|
||||||
$e
|
$e
|
||||||
|
@ -131,9 +113,4 @@ class Backend extends Process
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function id(): string
|
|
||||||
{
|
|
||||||
return basename(dirname(__DIR__));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief tinyPacker, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dotclear\Plugin\tinyPacker;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
use Dotclear\Module\MyPlugin;
|
||||||
|
|
||||||
|
class My extends MyPlugin
|
||||||
|
{
|
||||||
|
/** @var string Public packages folder */
|
||||||
|
public const TINYPACKER_DIR = 'packages';
|
||||||
|
|
||||||
|
/** @var array Excluded files and dirs */
|
||||||
|
public const TINYPACKER_EXCLUDE = [
|
||||||
|
'\.',
|
||||||
|
'\.\.',
|
||||||
|
'__MACOSX',
|
||||||
|
'\.svn',
|
||||||
|
'\.hg.*?',
|
||||||
|
'\.git.*?',
|
||||||
|
'CVS',
|
||||||
|
'\.directory',
|
||||||
|
'\.DS_Store',
|
||||||
|
'Thumbs\.db',
|
||||||
|
'_disabled',
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function checkCustomContext(int $context): ?bool
|
||||||
|
{
|
||||||
|
return defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->isSuperAdmin();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue