2021-08-26 22:38:34 +00:00
|
|
|
<?php
|
2021-09-27 22:46:41 +00:00
|
|
|
/**
|
|
|
|
* @brief tweakStores, a plugin for Dotclear 2
|
2021-11-04 23:43:37 +00:00
|
|
|
*
|
2021-09-27 22:46:41 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-04 23:43:37 +00:00
|
|
|
*
|
2021-09-27 22:46:41 +00:00
|
|
|
* @author Jean-Christian Denis and Contributors
|
2021-11-04 23:43:37 +00:00
|
|
|
*
|
2021-09-27 22:46:41 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-01-06 08:31:44 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\tweakStores;
|
|
|
|
|
|
|
|
/* dotclear ns */
|
|
|
|
use dcCore;
|
|
|
|
use dcPage;
|
|
|
|
|
|
|
|
/* clearbricks ns */
|
|
|
|
use form;
|
|
|
|
use http;
|
|
|
|
|
|
|
|
/* php ns */
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class Config
|
|
|
|
{
|
2023-01-07 14:52:02 +00:00
|
|
|
private static $pid = '';
|
2023-01-06 08:31:44 +00:00
|
|
|
protected static $init = false;
|
2021-08-26 22:38:34 +00:00
|
|
|
|
2023-01-06 08:31:44 +00:00
|
|
|
public static function init(): bool
|
|
|
|
{
|
|
|
|
if (defined('DC_CONTEXT_ADMIN') && defined('DC_CONTEXT_MODULE')) {
|
|
|
|
dcPage::checkSuper();
|
2023-01-07 14:52:02 +00:00
|
|
|
self::$pid = basename(dirname(__DIR__));
|
2023-01-06 08:31:44 +00:00
|
|
|
self::$init = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$init;
|
2021-08-26 22:38:34 +00:00
|
|
|
}
|
|
|
|
|
2023-01-06 08:31:44 +00:00
|
|
|
public static function process(): ?bool
|
|
|
|
{
|
|
|
|
if (!self::$init) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($_POST['save'])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-01-07 14:52:02 +00:00
|
|
|
$s = dcCore::app()->blog->settings->get(self::$pid);
|
2023-01-06 08:31:44 +00:00
|
|
|
$s->put('active', !empty($_POST['s_active']));
|
|
|
|
$s->put('packman', !empty($_POST['s_packman']));
|
|
|
|
$s->put('file_pattern', $_POST['s_file_pattern']);
|
|
|
|
|
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Configuration successfully updated')
|
|
|
|
);
|
|
|
|
http::redirect(
|
2023-01-07 14:52:02 +00:00
|
|
|
dcCore::app()->admin->__get('list')->getURL('module=' . self::$pid . '&conf=1&redir=' . dcCore::app()->admin->__get('list')->getRedir())
|
2023-01-06 08:31:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function render(): void
|
|
|
|
{
|
2023-01-07 14:52:02 +00:00
|
|
|
$s = dcCore::app()->blog->settings->get(self::$pid);
|
2023-01-06 08:31:44 +00:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="fieldset">
|
2023-01-07 14:52:02 +00:00
|
|
|
<h4>' . dcCore::app()->plugins->moduleInfo(self::$pid, 'name') . '</h4>
|
2023-01-06 08:31:44 +00:00
|
|
|
|
|
|
|
<p><label class="classic" for="s_active">' .
|
|
|
|
form::checkbox('s_active', 1, (bool) $s->get('active')) . ' ' .
|
|
|
|
__('Enable plugin') . '</label></p>
|
|
|
|
<p class="form-note">' . __('If enabled, new tab "Tweak stores" allows your to perfom actions relative to third-party repositories.') . '</p>
|
|
|
|
|
|
|
|
<p><label class="classic" for="s_packman">' .
|
|
|
|
form::checkbox('s_packman', 1, (bool) $s->get('packman')) . ' ' .
|
|
|
|
__('Enable packman behaviors') . '</label></p>
|
|
|
|
<p class="form-note">' . __('If enabled, plugin pacKman will (re)generate on the fly dcstore.xml file at root directory of the module.') . '</p>
|
|
|
|
|
|
|
|
<p><label class="classic" for="s_file_pattern">' . __('Predictable URL to zip file on the external repository') .
|
|
|
|
form::field('s_file_pattern', 65, 255, (string) $s->get('file_pattern'), 'maximal') . '
|
|
|
|
</label></p>
|
|
|
|
<p class="form-note">' .
|
|
|
|
__('You can use widcard like %author%, %type%, %id%, %version%.') . '<br /> ' .
|
|
|
|
__('For example on github https://github.com/MyGitName/%id%/releases/download/v%version%/%type%-%id%.zip') . '<br />' .
|
|
|
|
__('Note: on github, you must create a release and join to it the module zip file.') . '
|
|
|
|
</p>
|
|
|
|
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|