rebuild structure (ns playground)

2.28
Jean-Christian Paul Denis 2022-12-19 00:21:11 +01:00
parent 337e9f4edd
commit 4357872eb2
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
15 changed files with 362 additions and 210 deletions

17
_admin.php 100644
View File

@ -0,0 +1,17 @@
<?php
/**
* @brief pacKman, 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);
if (Dotclear\Plugin\pacKman\Admin::init()) {
Dotclear\Plugin\pacKman\Admin::process();
}

22
_config.php 100644
View File

@ -0,0 +1,22 @@
<?php
/**
* @brief pacKman, 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);
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
if (Dotclear\Plugin\pacKman\Config::init()) {
Dotclear\Plugin\pacKman\Config::process();
Dotclear\Plugin\pacKman\Config::render();
}

19
_install.php 100644
View File

@ -0,0 +1,19 @@
<?php
/**
* @brief pacKman, 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);
if (Dotclear\Plugin\pacKman\Install::init()) {
return Dotclear\Plugin\pacKman\Install::process();
}
return null;

21
_prepend.php 100644
View File

@ -0,0 +1,21 @@
<?php
/**
* @brief pacKman, 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);
if (!class_exists('Dotclear\Plugin\pacKman\Prepend')) {
require __DIR__ . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'prepend.php';
if (Dotclear\Plugin\pacKman\Prepend::init()) {
Dotclear\Plugin\pacKman\Prepend::process();
}
}

17
_uninstall.php 100644
View File

@ -0,0 +1,17 @@
<?php
/**
* @brief pacKman, 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);
if (Dotclear\Plugin\pacKman\Uninstall::init()) {
Dotclear\Plugin\pacKman\Uninstall::process($this);
}

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcAdmin; use dcAdmin;
@ -26,32 +22,40 @@ use dcPage;
class Admin class Admin
{ {
public static function init() private static $init = false;
public static function init(): bool
{ {
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); if (defined('DC_CONTEXT_ADMIN')) {
dcCore::app()->blog->settings->addNamespace(Core::id());
self::$init = true;
}
return self::$init;
} }
public static function process() public static function process()
{ {
if (!self::$init) {
return false;
}
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(basename(__DIR__), [ $favs->register(Core::id(), [
'title' => __('Packages repository'), 'title' => __('Packages repository'),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), [], '#packman-repository-repository'), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), [], '#packman-repository-repository'),
'small-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], 'small-icon' => [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')],
'large-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], 'large-icon' => [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')],
//'permissions' => dcCore::app()->auth->isSuperAdmin(), //'permissions' => dcCore::app()->auth->isSuperAdmin(),
]); ]);
}); });
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Packages repository'), __('Packages repository'),
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '#packman-repository-repository', dcCore::app()->adminurl->get('admin.plugin.' . Core::id()) . '#packman-repository-repository',
[dcPage::getPF(basename(__DIR__) . '/icon.svg'), dcPage::getPF(basename(__DIR__) . '/icon-dark.svg')], [dcPage::getPF(Core::id() . '/icon.svg'), dcPage::getPF(Core::id() . '/icon-dark.svg')],
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . Core::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );
} }
} }
Admin::init();
Admin::process();

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;
@ -32,13 +28,24 @@ use Exception;
class Config class Config
{ {
public static function init(): void private static $init = false;
public static function init(): bool
{ {
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); if (defined('DC_CONTEXT_ADMIN')) {
dcCore::app()->blog->settings->addNamespace(Core::id());
self::$init = true;
}
return self::$init;
} }
public static function process(): void public static function process(): void
{ {
if (!self::$init) {
return;
}
if (empty($_POST['save'])) { if (empty($_POST['save'])) {
return; return;
} }
@ -60,7 +67,7 @@ class Config
); );
if ($check) { if ($check) {
$s = dcCore::app()->blog->settings->__get(basename(__DIR__)); $s = dcCore::app()->blog->settings->__get(Core::id());
$s->put('packman_pack_nocomment', $packman_pack_nocomment); $s->put('packman_pack_nocomment', $packman_pack_nocomment);
$s->put('packman_pack_fixnewline', $packman_pack_fixnewline); $s->put('packman_pack_fixnewline', $packman_pack_fixnewline);
$s->put('packman_pack_overwrite', $packman_pack_overwrite); $s->put('packman_pack_overwrite', $packman_pack_overwrite);
@ -73,7 +80,7 @@ class Config
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
); );
http::redirect( http::redirect(
dcCore::app()->admin->__get('list')->getURL('module=' . basename(__DIR__) . '&conf=1&redir=' . dcCore::app()->admin->__get('list')->getURL('module=' . Core::id() . '&conf=1&redir=' .
dcCore::app()->admin->__get('list')->getRedir()) dcCore::app()->admin->__get('list')->getRedir())
); );
} }
@ -82,18 +89,14 @@ class Config
} }
} }
public static function render(): void public static function render()
{ {
# -- Get settings -- if (!self::$init) {
$s = dcCore::app()->blog->settings->__get(basename(__DIR__)); return false;
}
$packman_pack_nocomment = $s->packman_pack_nocomment; # -- Get settings --
$packman_pack_fixnewline = $s->packman_pack_fixnewline; $s = dcCore::app()->blog->settings->__get(Core::id());
$packman_pack_overwrite = $s->packman_pack_overwrite;
$packman_pack_filename = $s->packman_pack_filename;
$packman_secondpack_filename = $s->packman_secondpack_filename;
$packman_pack_repository = $s->packman_pack_repository;
$packman_pack_excludefiles = $s->packman_pack_excludefiles;
# -- Display form -- # -- Display form --
echo ' echo '
@ -101,7 +104,7 @@ class Config
<h4>' . __('Root') . '</h4> <h4>' . __('Root') . '</h4>
<p><label for="packman_pack_repository">' . __('Path to repository:') . ' ' . <p><label for="packman_pack_repository">' . __('Path to repository:') . ' ' .
form::field('packman_pack_repository', 65, 255, $packman_pack_repository, 'maximal') . form::field('packman_pack_repository', 65, 255, (string) $s->get('packman_pack_repository'), 'maximal') .
'</label></p>' . '</label></p>' .
'<p class="form-note">' . sprintf( '<p class="form-note">' . sprintf(
__('Preconization: %s'), __('Preconization: %s'),
@ -114,17 +117,17 @@ class Config
<h4>' . __('Files') . '</h4> <h4>' . __('Files') . '</h4>
<p><label for="packman_pack_filename">' . __('Name of exported package:') . ' ' . <p><label for="packman_pack_filename">' . __('Name of exported package:') . ' ' .
form::field('packman_pack_filename', 65, 255, $packman_pack_filename, 'maximal') . form::field('packman_pack_filename', 65, 255, (string) $s->get('packman_pack_filename'), 'maximal') .
'</label></p> '</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p> <p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p>
<p><label for="packman_secondpack_filename">' . __('Name of second exported package:') . ' ' . <p><label for="packman_secondpack_filename">' . __('Name of second exported package:') . ' ' .
form::field('packman_secondpack_filename', 65, 255, $packman_secondpack_filename, 'maximal') . form::field('packman_secondpack_filename', 65, 255, (string) $s->get('packman_secondpack_filename'), 'maximal') .
'</label></p> '</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '</p> <p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '</p>
<p><label class="classic" for="packman_pack_overwrite">' . <p><label class="classic" for="packman_pack_overwrite">' .
form::checkbox('packman_pack_overwrite', 1, $packman_pack_overwrite) . ' ' . form::checkbox('packman_pack_overwrite', 1, (bool) $s->get('packman_pack_overwrite')) . ' ' .
__('Overwrite existing package') . '</label></p> __('Overwrite existing package') . '</label></p>
</div> </div>
@ -133,22 +136,18 @@ class Config
<h4>' . __('Content') . '</h4> <h4>' . __('Content') . '</h4>
<p><label for="packman_pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' . <p><label for="packman_pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' .
form::field('packman_pack_excludefiles', 65, 255, $packman_pack_excludefiles, 'maximal') . form::field('packman_pack_excludefiles', 65, 255, (string) $s->get('packman_pack_excludefiles'), 'maximal') .
'</label></p> '</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '</p> <p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '</p>
<p><label class="classic" for="packman_pack_nocomment">' . <p><label class="classic" for="packman_pack_nocomment">' .
form::checkbox('packman_pack_nocomment', 1, $packman_pack_nocomment) . ' ' . form::checkbox('packman_pack_nocomment', 1, (bool) $s->get('packman_pack_nocomment')) . ' ' .
__('Remove comments from files') . '</label></p> __('Remove comments from files') . '</label></p>
<p><label class="classic" for="packman_pack_fixnewline">' . <p><label class="classic" for="packman_pack_fixnewline">' .
form::checkbox('packman_pack_fixnewline', 1, $packman_pack_fixnewline) . ' ' . form::checkbox('packman_pack_fixnewline', 1, (bool) $s->get('packman_pack_fixnewline')) . ' ' .
__('Fix newline style from files content') . '</label></p> __('Fix newline style from files content') . '</label></p>
</div>'; </div>';
} }
} }
Config::init();
Config::process();
Config::render();

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcModules; use dcModules;
@ -34,6 +30,11 @@ use Exception;
class Core class Core
{ {
public static function id()
{
return basename(dirname(__DIR__));
}
/** @var array Excluded files */ /** @var array Excluded files */
public static $exclude = [ public static $exclude = [
'.', '.',
@ -147,12 +148,12 @@ class Core
$fp = fopen($dest, 'wb'); $fp = fopen($dest, 'wb');
if ($nocomment) { if ($nocomment) {
FileZip::$remove_comment = true; Filezip::$remove_comment = true;
} }
if ($fixnewline) { if ($fixnewline) {
FileZip::$fix_newline = true; Filezip::$fix_newline = true;
} }
$zip = new FileZip($fp); $zip = new Filezip($fp);
foreach ($exclude as $e) { foreach ($exclude as $e) {
$zip->addExclusion($e); $zip->addExclusion($e);

View File

@ -12,16 +12,12 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* clearbricks ns */ /* clearbricks ns */
//use fileZip; //use fileZip;
class FileZip extends \fileZip class Filezip extends \fileZip
{ {
/** @var boolean Remove comments from files content */ /** @var boolean Remove comments from files content */
public static $remove_comment = false; public static $remove_comment = false;

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;
@ -73,21 +69,26 @@ class Install
]; ];
# -- Nothing to change below -- # -- Nothing to change below --
public static function process() private static $init = false;
public static function init(): bool
{ {
try { self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version'));
# Check module version
if (!dcCore::app()->newVersion( return self::$init;
basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
)) {
return null;
} }
public static function process()
{
if (!self::$init) {
return false;
}
try {
# Set module settings # Set module settings
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(Core::id());
foreach (self::$mod_conf as $v) { foreach (self::$mod_conf as $v) {
dcCore::app()->blog->settings->__get(basename(__DIR__))->put( dcCore::app()->blog->settings->__get(Core::id())->put(
$v[0], $v[0],
$v[2], $v[2],
$v[3], $v[3],
@ -105,5 +106,3 @@ class Install
} }
} }
} }
return Install::process();

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;
@ -31,31 +27,41 @@ use path;
/* php ns */ /* php ns */
use Exception; use Exception;
class Index class Manage
{ {
private static $plugins_path = ''; private static $plugins_path = '';
private static $themes_path = ''; private static $themes_path = '';
private static $init = false;
public static function init() public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper(); dcPage::checkSuper();
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(Core::id());
# Paths # Paths
$e = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); $e = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT);
$p = array_pop($e); $p = array_pop($e);
self::$plugins_path = (string) path::real($p); self::$plugins_path = (string) path::real($p);
self::$themes_path = dcCore::app()->blog->themes_path; self::$themes_path = dcCore::app()->blog->themes_path;
self::$init = true;
} }
public static function process() return self::$init;
}
public static function process(): void
{ {
if (!self::$init) {
return;
}
# Queries # Queries
$action = $_POST['action'] ?? ''; $action = $_POST['action'] ?? '';
$type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : '';
# Settings # Settings
$s = dcCore::app()->blog->settings->__get(basename(__DIR__)); $s = dcCore::app()->blog->settings->get(Core::id());
# Modules # Modules
if (!(dcCore::app()->themes instanceof dcThemes)) { if (!(dcCore::app()->themes instanceof dcThemes)) {
@ -67,8 +73,8 @@ class Index
# Rights # Rights
$is_writable = Utils::is_writable( $is_writable = Utils::is_writable(
$s->packman_pack_repository, $s->get('packman_pack_repository'),
$s->packman_pack_filename $s->get('packman_pack_filename')
); );
$is_editable = !empty($type) $is_editable = !empty($type)
&& !empty($_POST['modules']) && !empty($_POST['modules'])
@ -85,8 +91,8 @@ class Index
$modules = Core::getPackages(self::$themes_path); $modules = Core::getPackages(self::$themes_path);
} else { } else {
$modules = array_merge( $modules = array_merge(
Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_pack_filename)), Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))),
Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_secondpack_filename)) Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename')))
); );
} }
@ -127,15 +133,15 @@ class Index
$module['id'] = $id; $module['id'] = $id;
$module['type'] = $type == 'themes' ? 'theme' : 'plugin'; $module['type'] = $type == 'themes' ? 'theme' : 'plugin';
$root = (string) $s->packman_pack_repository; $root = (string) $s->get('packman_pack_repository');
$files = [ $files = [
(string) $s->packman_pack_filename, (string) $s->get('packman_pack_filename'),
(string) $s->packman_secondpack_filename, (string) $s->get('packman_secondpack_filename'),
]; ];
$nocomment = (bool) $s->packman_pack_nocomment; $nocomment = (bool) $s->get('packman_pack_nocomment');
$fixnewline = (bool) $s->packman_pack_fixnewline; $fixnewline = (bool) $s->get('packman_pack_fixnewline');
$overwrite = (bool) $s->packman_pack_overwrite; $overwrite = (bool) $s->get('packman_pack_overwrite');
$exclude = explode(',', (string) $s->packman_pack_excludefiles); $exclude = explode(',', (string) $s->get('packman_pack_excludefiles'));
# --BEHAVIOR-- packmanBeforeCreatePackage # --BEHAVIOR-- packmanBeforeCreatePackage
dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module); dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module);
@ -153,7 +159,7 @@ class Index
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-' . $type);
} }
# Delete # Delete
@ -173,7 +179,7 @@ class Index
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type);
} }
# Install # Install
@ -200,12 +206,12 @@ class Index
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type);
} }
# Copy # Copy
} elseif (strpos($action, 'copy_to_') !== false) { } elseif (strpos($action, 'copy_to_') !== false) {
$dest = $s->packman_pack_repository; $dest = (string) $s->get('packman_pack_repository');
if ($action == 'copy_to_plugins') { if ($action == 'copy_to_plugins') {
$dest = self::$plugins_path; $dest = self::$plugins_path;
} elseif ($action == 'copy_to_themes') { } elseif ($action == 'copy_to_themes') {
@ -226,12 +232,12 @@ class Index
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type);
} }
# Move # Move
} elseif (strpos($action, 'move_to_') !== false) { } elseif (strpos($action, 'move_to_') !== false) {
$dest = $s->packman_pack_repository; $dest = (string) $s->get('packman_pack_repository');
if ($action == 'move_to_plugins') { if ($action == 'move_to_plugins') {
$dest = self::$plugins_path; $dest = self::$plugins_path;
} elseif ($action == 'move_to_themes') { } elseif ($action == 'move_to_themes') {
@ -253,7 +259,7 @@ class Index
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), [], '#packman-repository-' . $type); dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), [], '#packman-repository-' . $type);
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
@ -263,20 +269,24 @@ class Index
public static function render() public static function render()
{ {
if (!self::$init) {
return false;
}
# Settings # Settings
$s = dcCore::app()->blog->settings->__get(basename(__DIR__)); $s = dcCore::app()->blog->settings->get(Core::id());
$is_configured = Utils::is_configured( $is_configured = Utils::is_configured(
$s->packman_pack_repository, $s->get('packman_pack_repository'),
$s->packman_pack_filename, $s->get('packman_pack_filename'),
$s->packman_secondpack_filename $s->get('packman_secondpack_filename')
); );
# Display # Display
echo echo
'<html><head><title>' . __('pacKman') . '</title>' . '<html><head><title>' . __('pacKman') . '</title>' .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/packman.js')); dcPage::jsLoad(dcPage::getPF(Core::id() . '/js/packman.js'));
# --BEHAVIOR-- packmanAdminHeader # --BEHAVIOR-- packmanAdminHeader
dcCore::app()->callBehavior('packmanAdminHeader'); dcCore::app()->callBehavior('packmanAdminHeader');
@ -293,12 +303,12 @@ class Index
if (dcCore::app()->error->flag() || !$is_configured) { if (dcCore::app()->error->flag() || !$is_configured) {
echo echo
'<div class="warning">' . __('pacKman is not well configured.') . ' ' . '<div class="warning">' . __('pacKman is not well configured.') . ' ' .
'<a href="' . dcCore::app()->adminurl->get('admin.plugins', ['module' => basename(__DIR__), 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))]) . '">' . __('Configuration') . '</a>' . '<a href="' . dcCore::app()->adminurl->get('admin.plugins', ['module' => Core::id(), 'conf' => '1', 'redir' => dcCore::app()->adminurl->get('admin.plugin.' . Core::id())]) . '">' . __('Configuration') . '</a>' .
'</div>'; '</div>';
} else { } else {
$repo_path_modules = array_merge( $repo_path_modules = array_merge(
Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_pack_filename)), Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))),
Core::getPackages(dirname($s->packman_pack_repository . '/' . $s->packman_secondpack_filename)) Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename')))
); );
$plugins_path_modules = Core::getPackages(self::$plugins_path); $plugins_path_modules = Core::getPackages(self::$plugins_path);
$themes_path_modules = Core::getPackages(self::$themes_path); $themes_path_modules = Core::getPackages(self::$themes_path);
@ -343,7 +353,3 @@ class Index
'</body></html>'; '</body></html>';
} }
} }
Index::init();
Index::process();
Index::render();

View File

@ -12,25 +12,43 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_RC_PATH')) {
return null;
}
/* clearbricks ns */ /* clearbricks ns */
use Clearbricks; use Clearbricks;
class Prepend class Prepend
{ {
public static function init() private const LIBS = [
'Admin',
'Config',
'Core',
'Filezip',
'Install',
'Manage',
'Prepend',
'Uninstall',
'Utils',
];
private static $init = false;
public static function init(): bool
{ {
Clearbricks::lib()->autoload([ self::$init = defined('DC_RC_PATH');
'plugins\\pacKman\\Core' => __DIR__ . '/inc/class.core.php',
'plugins\\pacKman\\Utils' => __DIR__ . '/inc/class.utils.php', return self::$init;
'plugins\\pacKman\\FileZip' => __DIR__ . '/inc/class.filezip.php',
]);
}
} }
Prepend::init(); public static function process()
{
if (!self::$init) {
return false;
}
foreach (self::LIBS as $lib) {
Clearbricks::lib()->autoload(['Dotclear\\Plugin\\pacKman\\' . $lib => __DIR__ . DIRECTORY_SEPARATOR . $lib . '.php']);
}
return true;
}
}

View File

@ -10,72 +10,91 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
namespace Dotclear\Plugin\pacKman;
class Uninstall
{
private static $init = false;
public static function init(): bool
{
self::$init = defined('DC_RC_PATH');
return self::$init;
} }
$this->addUserAction( public static function process($uninstaller)
{
if (!self::$init) {
return false;
}
$uninstaller->addUserAction(
/* type */ /* type */
'settings', 'settings',
/* action */ /* action */
'delete_all', 'delete_all',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
__('delete all settings') __('delete all settings')
); );
$this->addUserAction( $uninstaller->addUserAction(
/* type */ /* type */
'plugins', 'plugins',
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
__('delete plugin files') __('delete plugin files')
); );
$this->addUserAction( $uninstaller->addUserAction(
/* type */ /* type */
'versions', 'versions',
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
__('delete the version number') __('delete the version number')
); );
$this->addDirectAction( $uninstaller->addDirectAction(
/* type */ /* type */
'settings', 'settings',
/* action */ /* action */
'delete_all', 'delete_all',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
sprintf(__('delete all %s settings'), basename(__DIR__)) sprintf(__('delete all %s settings'), Core::id())
); );
$this->addDirectAction( $uninstaller->addDirectAction(
/* type */ /* type */
'plugins', 'plugins',
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
sprintf(__('delete %s plugin files'), basename(__DIR__)) sprintf(__('delete %s plugin files'), Core::id())
); );
$this->addDirectAction( $uninstaller->addDirectAction(
/* type */ /* type */
'versions', 'versions',
/* action */ /* action */
'delete', 'delete',
/* ns */ /* ns */
basename(__DIR__), Core::id(),
/* desc */ /* desc */
sprintf(__('delete %s version number'), basename(__DIR__)) sprintf(__('delete %s version number'), Core::id())
); );
}
}

View File

@ -12,11 +12,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace plugins\pacKman; namespace Dotclear\Plugin\pacKman;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;

18
index.php 100644
View File

@ -0,0 +1,18 @@
<?php
/**
* @brief pacKman, 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);
if (Dotclear\Plugin\pacKman\Manage::init()) {
Dotclear\Plugin\pacKman\Manage::process();
Dotclear\Plugin\pacKman\Manage::render();
}