upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian Denis 2023-08-15 21:52:21 +02:00
parent b3edda6cc8
commit 73f9b6f83a
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
8 changed files with 155 additions and 204 deletions

View file

@ -2,6 +2,6 @@ $(function(){
/* toogle admin form sidebar */
$('#templator h5').toggleWithLegend(
$('#templator').children().not('h5'),
{cookie:'dcx_templator_admin_form_sidebar',legend_click:true}
{user_pref:'dcx_templator_admin_form_sidebar',legend_click:true}
);
});

View file

@ -14,50 +14,23 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcAdmin;
use dcCore;
use dcMenu;
use dcNsProcess;
use dcPage;
use Dotclear\Core\Process;
class Backend extends dcNsProcess
class Backend extends Process
{
public static function init(): bool
{
static::$init == defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
My::PERMISSION_TEMPLATOR,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
return self::status(My::checkContext(My::BACKEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->blog)) {
return false;
}
//backend sidebar menu icon
if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) {
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
urldecode(dcPage::getPF(My::id() . '/icon.svg')),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
My::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id)
);
}
My::addBackendMenuItem();
dcCore::app()->addBehaviors([
'adminPostHeaders' => [BackendBehaviors::class,'adminPostHeaders'],

View file

@ -16,10 +16,15 @@ namespace Dotclear\Plugin\templator;
use ArrayObject;
use dcCore;
use dcPage;
use dcPostsActions;
use Dotclear\Database\Cursor;
use Dotclear\Database\MetaRecord;
use Dotclear\Core\Backend\Action\ActionsPosts;
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Database\{
Cursor,
MetaRecord
};
use Dotclear\Helper\Html\Html;
use Exception;
@ -29,7 +34,7 @@ class BackendBehaviors
{
public static function adminPostHeaders(): string
{
return dcPage::jsModuleLoad(My::id() . '/js/admin.js');
return My::jsLoad('admin');
}
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
@ -60,7 +65,7 @@ class BackendBehaviors
}
}
public static function adminPostsActions(dcPostsActions $pa): void
public static function adminPostsActions(ActionsPosts $pa): void
{
$pa->addAction(
[
@ -72,7 +77,7 @@ class BackendBehaviors
);
}
public static function adminPostsActionsCallback(dcPostsActions $pa, ArrayObject $post): void
public static function adminPostsActionsCallback(ActionsPosts $pa, ArrayObject $post): void
{
# No entry
$posts_ids = $pa->getIDs();
@ -91,7 +96,7 @@ class BackendBehaviors
}
}
dcPage::addSuccessNotice(__('Entries template updated.'));
Notices::addSuccessNotice(__('Entries template updated.'));
$pa->redirect(true);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@ -99,7 +104,7 @@ class BackendBehaviors
}
$pa->beginPage(
dcPage::breadcrumb([
Page::breadcrumb([
Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Entry template') => '',

View file

@ -15,24 +15,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
use Dotclear\Database\MetaRecord;
/**
* Frontend prepend.
*/
class Frontend extends dcNsProcess
class Frontend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
return self::status(My::checkContext(My::FRONTEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View file

@ -14,41 +14,34 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use adminGenericFilterV2;
use adminPostList;
use dcAdminFilters;
use dcCore;
use dcNsProcess;
use dcPage;
use dcPager;
use Dotclear\Core\Backend\Filter\{
Filters,
FiltersLibrary
};
use Dotclear\Core\Backend\Listing\ListingPosts;
use Dotclear\Core\Backend\Listing\Pager as corePager;
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\File\Files;
use Dotclear\Helper\Html\Html;
use Exception;
use form;
class Manage extends dcNsProcess
class Manage extends Process
{
public static function init(): bool
{
static::$init == defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
My::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id);
return static::$init;
return self::status(My::checkContext(My::MANAGE));
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!self::status()) {
return false;
}
@ -71,8 +64,8 @@ class Manage extends dcNsProcess
$t->initializeTpl($name, $_POST['filesource']);
if (!dcCore::app()->error->flag()) {
dcPage::addSuccessNotice(__('The new template has been successfully created.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
Notices::addSuccessNotice(__('The new template has been successfully created.'));
My::redirect();
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@ -90,8 +83,8 @@ class Manage extends dcNsProcess
);
if (!dcCore::app()->error->flag()) {
dcPage::addSuccessNotice(__('The template has been successfully copied.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']);
Notices::addSuccessNotice(__('The template has been successfully copied.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@ -109,8 +102,8 @@ class Manage extends dcNsProcess
);
if (!dcCore::app()->error->flag()) {
dcPage::addSuccessNotice(__('The template has been successfully copied.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']);
Notices::addSuccessNotice(__('The template has been successfully copied.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@ -127,8 +120,8 @@ class Manage extends dcNsProcess
dcCore::app()->meta->delMeta($file, 'template');
if (!dcCore::app()->error->flag()) {
dcPage::addSuccessNotice(__('The template has been successfully removed.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'files']);
Notices::addSuccessNotice(__('The template has been successfully removed.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
@ -140,7 +133,7 @@ class Manage extends dcNsProcess
public static function render(): void
{
if (!static::$init) {
if (!self::status()) {
return;
}
@ -159,28 +152,28 @@ class Manage extends dcNsProcess
if (!$t->canUseRessources(true)) {
dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
]) .
dcPage::notices();
Notices::getNotices();
/*
* Duplicate dotclear template
*/
} elseif ('new' == $v->part) {
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'new']) . '" method="post" id="add-template">' .
'<form action="' . My::manageUrl(['part' => 'new']) . '" method="post" id="add-template">' .
'<h3>' . $v->name . '</h3>' .
'<p><label for="filesource" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Template source:') . '</label> ' .
form::combo('filesource', $v->sources) . '</p>' .
@ -197,7 +190,7 @@ class Manage extends dcNsProcess
echo
'<p>' .
dcCore::app()->formNonce() .
My::parsedHiddenFields() .
'<input type="submit" value="' . __('Create') . '" /></p>' .
'</form>';
@ -205,16 +198,16 @@ class Manage extends dcNsProcess
* Copy templator template
*/
} elseif ('copy' == $v->part && !empty($_REQUEST['file'])) {
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'copy']) . '" method="post">' .
'<form action="' . My::manageUrl(['part' => 'copy']) . '" method="post">' .
'<h3>' . $v->name . '</h3>' .
'<p><label for="filename" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('New filename:') . '</label> ' .
form::field('filename', 25, 255) . '<code>' . Html::escapeHTML('.html') . '</code></p> ' .
@ -224,9 +217,8 @@ class Manage extends dcNsProcess
) . '</p>' .
'<p>' .
'<input type="submit" name="submit" value="' . __('Copy') . '" /> ' .
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
dcCore::app()->formNonce() .
form::hidden('file', Html::escapeHTML($_REQUEST['file'])) . '</p>' .
'<a class="button" href="' . My::manageUrl(['part' => 'files']) . '">' . __('Cancel') . '</a>' .
My::parsedHiddenFields(['file' => Html::escapeHTML($_REQUEST['file'])]) . '</p>' .
'</form>';
/*
@ -241,16 +233,16 @@ class Manage extends dcNsProcess
};
$name = $full_name . dcCore::app()->blog->getCategory($category_id)->f('cat_title');
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'copycat']) . '" method="post">' .
'<form action="' . My::manageUrl(['part' => 'copycat']) . '" method="post">' .
'<h3>' . $v->name . '</h3>' .
'<p><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Target category:') . '</label> ' .
form::combo('filecat', $v->categories, '') . '</p>' .
@ -260,60 +252,58 @@ class Manage extends dcNsProcess
$name
) . '</p>' .
'<input type="submit" name="submit" value="' . __('Copy') . '" /> ' .
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
dcCore::app()->formNonce() .
form::hidden('file', Html::escapeHTML($_REQUEST['file'])) . '</p>' .
'<a class="button" href="' . My::manageUrl(['part' => 'files']) . '">' . __('Cancel') . '</a>' .
My::parsedHiddenFields(['file' => Html::escapeHTML($_REQUEST['file'])]) . '</p>' .
'</form>';
/*
* Delete templator template
*/
} elseif ('delete' == $v->part && !empty($_REQUEST['file'])) {
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'delete']) . '" method="post">' .
'<form action="' . My::manageUrl(['part' => 'delete']) . '" method="post">' .
'<h3>' . $v->name . '</h3>' .
'<p>' . sprintf(
__('Are you sure you want to remove the template "%s"?'),
Html::escapeHTML($_GET['file'])
) . '</p>' .
'<p><input type="submit" class="delete" value="' . __('Delete') . '" /> ' .
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
dcCore::app()->formNonce() .
form::hidden('file', Html::escapeHTML($_GET['file'])) . '</p>' .
'<a class="button" href="' . My::manageUrl(['part' => 'files']) . '">' . __('Cancel') . '</a>' .
My::parsedHiddenFields(['file' => Html::escapeHTML($_GET['file'])]) . '</p>' .
'</form>';
/*
* List templator templates
*/
} elseif ('files' == $v->part) {
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<h3>' . $v->name . '</h3>';
if (count($v->items) == 0) {
echo '<p><strong>' . __('No template.') . '</strong></p>';
} else {
// reuse "used templatro template" filter settings
$filter = new adminGenericFilterV2(My::id());
$filter->add(dcAdminFilters::getPageFilter());
$filter = new Filters(My::id());
$filter->add(FiltersLibrary::getPageFilter());
$page = is_numeric($filter->value('page')) ? (int) $filter->value('page') : 1;
$nb = is_numeric($filter->value('nb')) ? (int) $filter->value('nb') : 1;
$pager = new dcPager($page, count($v->items), $nb, 10);
$pager = new corePager($page, count($v->items), $nb, 10);
echo
'<div class="media-list">' .
@ -361,11 +351,11 @@ class Manage extends dcNsProcess
$cols[$col] .= '<tr class="line">' .
'<td class="maximal"><a href="' .
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), [
My::manageUrl([
'part' => 'posts',
'file' => $meta_id,
'redir' => dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'used']),
]) . '">' . $meta_id . '</a> ' . $img_status . '</td>' .
'redir' => My::manageUrl(['part' => 'used'], '&amp;'),
], '&') . '">' . $meta_id . '</a> ' . $img_status . '</td>' .
'<td class="nowrap"><strong>' . $count . '</strong> ' .
(($count == 1) ? __('entry') : __('entries')) . '</td>' .
'</tr>';
@ -375,17 +365,17 @@ class Manage extends dcNsProcess
$table = '<div class="col"><table class="tags">%s</table></div>';
dcPage::openModule(
Page::openModule(
My::name(),
dcPage::cssModuleLoad('tags/style.css')
Page::cssModuleLoad('tags/style.css')
);
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<h3>' . $v->name . '</h3>';
if ($cols[0]) {
@ -437,38 +427,38 @@ class Manage extends dcNsProcess
$ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
dcPage::openModule(
Page::openModule(
My::name(),
(
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) : ''
Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) : ''
) .
dcPage::jsJson('theme_editor_msg', [
Page::jsJson('theme_editor_msg', [
'saving_document' => __('Saving document...'),
'document_saved' => __('Document saved'),
'error_occurred' => __('An error occurred:'),
'confirm_reset_file' => __('Are you sure you want to reset this file?'),
]) .
dcPage::jsModuleLoad('themeEditor/js/script.js') .
dcPage::jsConfirmClose('file-form') .
Page::jsModuleLoad('themeEditor/js/script.js') .
Page::jsConfirmClose('file-form') .
(
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
dcPage::jsLoadCodeMirror(is_string($ict) ? $ict : '') : ''
Page::jsLoadCodeMirror(is_string($ict) ? $ict : '') : ''
) .
dcPage::cssModuleLoad('themeEditor/style.css')
Page::cssModuleLoad('themeEditor/style.css')
);
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices();
Notices::getNotices();
if (($file['c'] !== null)) {
echo
'<form id="file-form" action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'edit', 'file' => $name]) . '" method="post">' .
'<form id="file-form" action="' . My::manageUrl(['part' => 'edit', 'file' => $name]) . '" method="post">' .
'<div><h3><label for="file_content">' . sprintf(__('Editing file %s'), '<strong>' . $name) . '</strong></label></h3>' .
'<p>' . form::textarea('file_content', 72, 25, [
'default' => Html::escapeHTML($file['c']),
@ -479,9 +469,8 @@ class Manage extends dcNsProcess
if ($file['w']) {
echo
'<p><input type="submit" name="write" value="' . __('Save') . '" accesskey="s" /> ' .
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
dcCore::app()->formNonce() .
form::hidden(['file_id'], Html::escapeHTML($file['f'])) .
'<a class="button" href="' . My::manageUrl(['part' => 'files']) . '">' . __('Cancel') . '</a>' .
My::parsedHiddenFields(['file_id' => Html::escapeHTML($file['f'])]) .
'</p>';
} else {
echo '<p>' . __('This file is not writable. Please check your files permissions.') . '</p>';
@ -492,9 +481,9 @@ class Manage extends dcNsProcess
if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) {
$ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
echo
dcPage::jsJson('theme_editor_mode', ['mode' => 'html']) .
dcPage::jsModuleLoad('themeEditor/js/mode.js') .
dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', is_string($ict) ? $ict : '');
Page::jsJson('theme_editor_mode', ['mode' => 'html']) .
Page::jsModuleLoad('themeEditor/js/mode.js') .
Page::jsRunCodeMirror('editor', 'file_content', 'dotclear', is_string($ict) ? $ict : '');
}
}
@ -503,7 +492,7 @@ class Manage extends dcNsProcess
*/
} elseif ('posts' == $v->part && (!empty($_REQUEST['file']) || $_REQUEST['file'] == '0')) {
$file = $_REQUEST['file'];
$redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'used']);
$redir = $_REQUEST['redir'] ?? My::manageUrl(['part' => 'used']);
# Unselect the template
if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
@ -512,14 +501,14 @@ class Manage extends dcNsProcess
]), dcCore::app()->blog->id)) {
try {
dcCore::app()->meta->delMeta($file, 'template');
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'posts', 'file' => $file]);
My::redirect(['part' => 'posts', 'file' => $file]);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
$filter = new adminGenericFilterV2('templator');
$filter->add(dcAdminFilters::getPageFilter());
$filter = new Filters('templator');
$filter->add(FiltersLibrary::getPageFilter());
$filter->add('part', 'posts');
$filter->add('file', $file);
$filter->add('post_type', '');
@ -537,25 +526,25 @@ class Manage extends dcNsProcess
}
$counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0);
$counter = is_numeric($counter) ? (int) $counter : 0;
$post_list = new adminPostList($posts, $counter);
$post_list = new ListingPosts($posts, $counter);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
dcPage::openModule(
Page::openModule(
My::name(),
dcPage::jsFilterControl($filter->show()) .
dcPage::jsModuleLoad(My::id() . '/js/posts.js') .
$filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'posts', 'file' => $file]))
Page::jsFilterControl($filter->show()) .
My::jsLoad('posts') .
$filter->js(My::manageUrl(['part' => 'posts', 'file' => $file]))
);
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
$v->name => '',
]) .
dcPage::notices() .
Notices::getNotices() .
'<h3>' . sprintf(__('Unselect template "%s"'), '<strong>' . $file . '</strong>') . '</h3>' .
'<p><a class ="back" href="' . $redir . '">' . __('Back') . '</a></p>';
@ -574,7 +563,7 @@ class Manage extends dcNsProcess
$post_list->display(
$page,
$nb,
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
'<form action="' . My::manageUrl() . '" method="post" id="form-entries">' .
'%s' .
@ -598,13 +587,13 @@ class Manage extends dcNsProcess
* Default page
*/
} else {
dcPage::openModule(My::name());
Page::openModule(My::name());
echo
dcPage::breadcrumb([
Page::breadcrumb([
__('Plugins') => '',
My::name() => '',
]) .
dcPage::notices();
Notices::getNotices();
$line = '<li><a href="%s">%s</a></li>';
echo '
@ -613,24 +602,24 @@ class Manage extends dcNsProcess
'<h3><ul class="nice">%s</ul></h3>',
sprintf(
$line,
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'files']),
My::manageUrl(['part' => 'files']),
__('Available templates')
) .
sprintf(
$line,
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'used']),
My::manageUrl(['part' => 'used']),
__('Used templates')
) .
sprintf(
$line,
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'new']),
My::manageUrl(['part' => 'new']),
__('New template')
)
);
}
dcPage::helpBlock('templator');
Page::helpBlock('templator');
dcPage::closeModule();
Page::closeModule();
}
}

View file

@ -15,38 +15,27 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\Module\MyPlugin;
/**
* This module definitions.
*/
class My
class My extends MyPlugin
{
/** @var string This module permission */
public const PERMISSION_TEMPLATOR = 'templator';
/**
* This module id.
*/
public static function id(): string
public static function checkCustomContext(int $context): ?bool
{
return basename(dirname(__DIR__));
}
if (in_array($context, [My::BACKEND, My::MENU, My::MANAGE])) {
return defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
My::PERMISSION_TEMPLATOR,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
}
/**
* This module name.
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
return null;
}
}

View file

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use dcPage;
use Dotclear\Helper\File\File;
use Dotclear\Helper\File\Files;
use Exception;
@ -33,8 +32,8 @@ class Pager
$count = '';
$params = [];
$link = 'media_item.php?id=' . $f->media_id;
$link_edit = dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'edit', 'file' => $f->basename]);
$icon = dcPage::getPF('templator/img/template.png');
$link_edit = My::manageUrl(['part' => 'edit', 'file' => $f->basename]);
$icon = My::fileURL('img/template.png');
$class = 'media-item media-col-' . ($i % 2);
$details = $special = '';
$widget_icon = '<span class="widget" title="' . __('Template widget') . '">&diams;</span>';
@ -51,7 +50,7 @@ class Pager
$fname = '<strong>' . __('Category') . '</strong> :&nbsp;' . $full_name . $category->f('cat_title');
$params['cat_id'] = $cat_id;
$params['post_type'] = '';
$icon = dcPage::getPF('templator/img/template-alt.png');
$icon = My::fileURL('img/template-alt.png');
$part = 'copycat';
try {
@ -68,7 +67,7 @@ class Pager
}
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
$count = '&nbsp;';
$icon = dcPage::getPF('templator/img/template-widget.png');
$icon = My::fileURL('img/template-widget.png');
$special = $widget_icon;
} else {
$params['meta_id'] = $f->basename;
@ -78,11 +77,11 @@ class Pager
try {
$counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0);
$counter = is_numeric($counter) ? (int) $counter : 0;
$url = dcCore::app()->adminurl->get('admin.plugin.templator', [
$url = My::manageUrl([
'part' => 'posts',
'file' => $fname,
'redir' => dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']),
]);
'redir' => My::manageUrl(['part' => 'files'], '&amp;'),
], '&');
if ($counter == 0) {
$count = __('No entry');
} elseif ($counter == 1) {
@ -119,12 +118,12 @@ class Pager
$res .= '<li class="media-action">&nbsp;';
$res .= '<a class="media-remove" href="' .
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => $part, 'file' => $f->basename]) . '">' .
My::manageUrl(['part' => $part, 'file' => $f->basename]) . '">' .
'<img src="images/plus.png" alt="' . __('copy') . '" title="' . __('copy the template') . '" /></a>&nbsp;';
if ($f->del) {
$res .= '<a class="media-remove" href="' .
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'delete', 'file' => $f->basename]) . '">' .
My::manageUrl(['part' => 'delete', 'file' => $f->basename]) . '">' .
'<img src="images/trash.png" alt="' . __('delete') . '" title="' . __('delete the template') . '" /></a>';
}

View file

@ -15,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
class Prepend extends dcNsProcess
class Prepend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
return self::status(My::checkContext(My::PREPEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}