upgrade to dotclear 2.28

This commit is contained in:
Jean-Christian Denis 2023-10-20 22:33:40 +02:00
parent 38b7d54089
commit d3bf04228d
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
16 changed files with 254 additions and 326 deletions

View file

@ -1,3 +1,9 @@
templator 1.7 - 2023.10.20
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Upgrade to Dotclear 2.28
templator 1.6 - 2023.08.15
===========================================================
* Require Dotclear 2.27

View file

@ -1,28 +1,25 @@
# README
[![Release](https://img.shields.io/badge/release-1.6-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
[![Date](https://img.shields.io/badge/date-2023.08.15-c44d58.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download)
[![Release](https://img.shields.io/badge/release-1.7-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
![Date](https://img.shields.io/badge/date-2023.10.20-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/templator)
[![License](https://img.shields.io/github/license/JcDenis/templator)](https://git.dotclear.watch/JcDenis/templator/blob/master/LICENSE)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE)
## WHAT IS TEMPLATOR ?
## ABOUT
_templator_ is a plugin for the open-source
web publishing software called Dotclear.
_templator_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
It help you to manage additonnal tempaltes for your blog.
> Help you to manage additonnal tempaltes for your blog.
You can copy existing templates, then edit them.
You can attribute a template to a post or a category.
## REQUIREMENTS
_templator_ requires:
* content admin or templator
* Dotclear 2.27
* Dotclear 2.28
* PHP 8.1+
* A writable directory on public path to store tempaltes
* System writable directory on public path to store tempaltes
* Dotclear content admin or templator
## USAGE
@ -34,14 +31,15 @@ You can manage your additional templates from menu
## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/templator) or [GitHub Page](https://github.com/JcDenis/templator)
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/templator/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/templator)
* Discuss and help : [Dotclear Forum](http://forum.dotclear.net/viewtopic.php?id=42059)
* [License](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE)
* [Packages & details](https://git.dotclear.watch/JcDenis/templator/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/templator))
* [Sources & contributions](https://git.dotclear.watch/JcDenis/templator) (or on [GitHub](https://github.com/JcDenis/templator))
* [Issues & security](https://git.dotclear.watch/JcDenis/templator/issues) (or on [GitHub](https://github.com/JcDenis/templator/issues))
* [Discuss & help](http://forum.dotclear.net/viewtopic.php?id=42059)
## CONTRIBUTORS
* Osku (author)
* Jean-Christian Denis
* Jean-Christian Denis (latest)
You are welcome to contribute to this code.

View file

@ -1,36 +1,30 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
* @file
* @brief The plugin templator definition
* @ingroup templator
*
* @package Dotclear
* @subpackage Plugin
* @defgroup templator Plugin templator.
*
* @author Osku and contributors
* Create and select more templates for your posts.
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
$this->registerModule(
'Templates engine',
'Create and select more templates for your posts',
'Osku and contributors',
'1.6',
'1.7',
[
'requires' => [
['php', '8.1'],
['core', '2.27'],
],
'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]),
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
'requires' => [['core', '2.28']],
'permissions' => 'My',
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
]
);

View file

@ -1,20 +0,0 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initTemplator
{
public const PERMISSION_TEMPLATOR = 'templator';
}

View file

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="templator">
<name>Templates engine</name>
<version>1.6</version>
<version>1.7</version>
<author>Osku and contributors</author>
<desc>Create and select more templates for your posts</desc>
<file>https://git.dotclear.watch/JcDenis/templator/releases/download/v1.6/plugin-templator.zip</file>
<da:dcmin>2.27</da:dcmin>
<file>https://git.dotclear.watch/JcDenis/templator/releases/download/v1.7/plugin-templator.zip</file>
<da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/templator/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/templator/issues</da:support>
</module>

View file

@ -1,22 +1,20 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
/**
* @brief templator backend class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Backend extends Process
{
public static function init(): bool
@ -32,19 +30,19 @@ class Backend extends Process
My::addBackendMenuItem();
dcCore::app()->addBehaviors([
'adminPostHeaders' => [BackendBehaviors::class,'adminPostHeaders'],
'adminPostFormItems' => [BackendBehaviors::class,'adminPostFormItems'],
'adminPageHeaders' => [BackendBehaviors::class,'adminPostHeaders'],
'adminPageFormItems' => [BackendBehaviors::class,'adminPostFormItems'],
'adminAfterPostCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
'adminBeforePostUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
'adminAfterPageCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
'adminBeforePageUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
'adminPostsActions' => [BackendBehaviors::class,'adminPostsActions'],
'adminPagesActions' => [BackendBehaviors::class,'adminPostsActions'],
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
'initWidgets' => [Widgets::class, 'initWidgets'],
App::behavior()->addBehaviors([
'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminAfterPostCreate' => BackendBehaviors::adminBeforePostUpdate(...),
'adminBeforePostUpdate' => BackendBehaviors::adminBeforePostUpdate(...),
'adminAfterPageCreate' => BackendBehaviors::adminBeforePostUpdate(...),
'adminBeforePageUpdate' => BackendBehaviors::adminBeforePostUpdate(...),
'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
'adminPagesActions' => BackendBehaviors::adminPostsActions(...),
'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
'initWidgets' => Widgets::initWidgets(...),
]);
return true;

View file

@ -1,21 +1,11 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use ArrayObject;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Backend\Action\ActionsPosts;
use Dotclear\Core\Backend\{
Notices,
@ -30,6 +20,14 @@ use Exception;
use form;
/**
* @brief templator backend behaviors.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class BackendBehaviors
{
public static function adminPostHeaders(): string
@ -42,7 +40,7 @@ class BackendBehaviors
$selected = '';
if (!is_null($post)) {
$post_meta = dcCore::app()->meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->f('post_id')]);
$post_meta = App::meta()->getMetadata(['meta_type' => 'template', 'post_id' => $post->f('post_id')]);
$selected = $post_meta->isEmpty() ? '' : $post_meta->f('meta_id');
}
@ -58,9 +56,9 @@ class BackendBehaviors
$post_id = (int) $post_id;
if (isset($_POST['post_tpl'])) {
dcCore::app()->meta->delPostMeta($post_id, 'template');
App::meta()->delPostMeta($post_id, 'template');
if (!empty($_POST['post_tpl'])) {
dcCore::app()->meta->setPostMeta($post_id, 'template', $_POST['post_tpl']);
App::meta()->setPostMeta($post_id, 'template', $_POST['post_tpl']);
}
}
}
@ -73,7 +71,7 @@ class BackendBehaviors
__('Select the template') => 'tpl',
],
],
[self::class, 'adminPostsActionsCallback']
self::adminPostsActionsCallback(...)
);
}
@ -90,24 +88,24 @@ class BackendBehaviors
if (isset($post['post_tpl']) && is_string($post['post_tpl'])) {
try {
foreach ($posts_ids as $post_id) {
dcCore::app()->meta->delPostMeta($post_id, 'template');
App::meta()->delPostMeta($post_id, 'template');
if (!empty($post['post_tpl'])) {
dcCore::app()->meta->setPostMeta($post_id, 'template', $post['post_tpl']);
App::meta()->setPostMeta($post_id, 'template', $post['post_tpl']);
}
}
Notices::addSuccessNotice(__('Entries template updated.'));
$pa->redirect(true);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
$pa->beginPage(
Page::breadcrumb([
Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Entry template') => '',
Html::escapeHTML(App::blog()->name()) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Entry template') => '',
])
);
@ -120,7 +118,7 @@ class BackendBehaviors
'<p>' .
$pa->getHiddenFields() .
dcCore::app()->formNonce() .
App::nonce()->getFormNonce() .
form::hidden(['action'], 'tpl') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';

View file

@ -1,25 +1,20 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
use Dotclear\Database\MetaRecord;
/**
* Frontend prepend.
* @brief templator frontend class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Frontend extends Process
{
@ -34,41 +29,37 @@ class Frontend extends Process
return false;
}
dcCore::app()->tpl->setPath(
dcCore::app()->tpl->getPath(),
App::frontend()->template()->setPath(
App::frontend()->template()->getPath(),
Templator::instance()->getPath()
);
dcCore::app()->addBehaviors([
App::behavior()->addBehaviors([
'urlHandlerBeforeGetData' => function ($_): void {
if (is_null(dcCore::app()->ctx)) {
return;
}
if ((dcCore::app()->ctx->__get('posts') instanceof MetaRecord)
&& (array_key_exists(dcCore::app()->url->type, dcCore::app()->getPostTypes()) || dcCore::app()->url->type == 'pages')) {
if ((App::frontend()->context()->__get('posts') instanceof MetaRecord)
&& (array_key_exists(App::url()->type, App::postTypes()->getPostTypes()) || App::url()->type == 'pages')) {
$params = [];
$params['meta_type'] = 'template';
$params['post_id'] = dcCore::app()->ctx->__get('posts')->f('post_id');
$post_meta = dcCore::app()->meta->getMetadata($params);
$params['post_id'] = App::frontend()->context()->__get('posts')->f('post_id');
$post_meta = App::meta()->getMetadata($params);
if (!$post_meta->isEmpty() && is_string($post_meta->f('meta_id')) && dcCore::app()->tpl->getFilePath($post_meta->f('meta_id'))) {
dcCore::app()->ctx->__set('current_tpl', $post_meta->f('meta_id'));
if (!$post_meta->isEmpty() && is_string($post_meta->f('meta_id')) && App::frontend()->template()->getFilePath($post_meta->f('meta_id'))) {
App::frontend()->context()->__set('current_tpl', $post_meta->f('meta_id'));
}
}
if (dcCore::app()->ctx->__get('current_tpl') == 'category.html'
&& (dcCore::app()->ctx->__get('categories') instanceof MetaRecord)
&& is_string(dcCore::app()->ctx->__get('categories')->f('cat_id'))
&& preg_match('/^[0-9]{1,}/', dcCore::app()->ctx->__get('categories')->f('cat_id'), $cat_id)
if (App::frontend()->context()->__get('current_tpl') == 'category.html'
&& (App::frontend()->context()->__get('categories') instanceof MetaRecord)
&& is_string(App::frontend()->context()->__get('categories')->f('cat_id'))
&& preg_match('/^[0-9]{1,}/', App::frontend()->context()->__get('categories')->f('cat_id'), $cat_id)
) {
$tpl = 'category-' . $cat_id[0] . '.html';
if (dcCore::app()->tpl->getFilePath($tpl)) {
dcCore::app()->ctx->__set('current_tpl', $tpl);
if (App::frontend()->template()->getFilePath($tpl)) {
App::frontend()->context()->__set('current_tpl', $tpl);
}
}
},
'initWidgets' => [Widgets::class, 'initWidgets'],
'initWidgets' => Widgets::initWidgets(...),
]);
return true;

View file

@ -1,20 +1,10 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Backend\Filter\{
Filters,
FiltersLibrary
@ -32,6 +22,14 @@ use Exception;
use form;
/**
* @brief templator manage class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Manage extends Process
{
public static function init(): bool
@ -63,12 +61,12 @@ class Manage extends Process
}
$t->initializeTpl($name, $_POST['filesource']);
if (!dcCore::app()->error->flag()) {
if (!App::error()->flag()) {
Notices::addSuccessNotice(__('The new template has been successfully created.'));
My::redirect();
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -82,12 +80,12 @@ class Manage extends Process
rawurldecode($_POST['file'])
);
if (!dcCore::app()->error->flag()) {
if (!App::error()->flag()) {
Notices::addSuccessNotice(__('The template has been successfully copied.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -101,12 +99,12 @@ class Manage extends Process
rawurldecode($_POST['file'])
);
if (!dcCore::app()->error->flag()) {
if (!App::error()->flag()) {
Notices::addSuccessNotice(__('The template has been successfully copied.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -117,14 +115,14 @@ class Manage extends Process
try {
$file = rawurldecode($_POST['file']);
$v->media->removeItem($file);
dcCore::app()->meta->delMeta($file, 'template');
App::meta()->delMeta($file, 'template');
if (!dcCore::app()->error->flag()) {
Notices::addSuccessNotice(__('The template has been successfully removed.'));
My::redirect(['part' => 'files']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -133,12 +131,9 @@ class Manage extends Process
public static function render(): void
{
if (!self::status()) {
return;
}
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!self::status()
|| !App::blog()->isDefined()
) {
return;
}
@ -151,7 +146,7 @@ class Manage extends Process
*/
if (!$t->canUseRessources(true)) {
dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
App::error()->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
Page::openModule(My::name());
echo
Page::breadcrumb([
@ -226,12 +221,12 @@ class Manage extends Process
*/
} elseif ('copycat' == $v->part && !empty($_REQUEST['file'])) {
$category_id = (int) str_replace(['category-','.html'], '', $_REQUEST['file']);
$cat_parents = dcCore::app()->blog->getCategoryParents($category_id);
$cat_parents = App::blog()->getCategoryParents($category_id);
$full_name = '';
while ($cat_parents->fetch()) {
$full_name = $cat_parents->f('cat_title') . ' &rsaquo; ';
};
$name = $full_name . dcCore::app()->blog->getCategory($category_id)->f('cat_title');
$name = $full_name . App::blog()->getCategory($category_id)->f('cat_title');
Page::openModule(My::name());
echo
@ -322,8 +317,8 @@ class Manage extends Process
* List Used templator template
*/
} elseif ('used' == $v->part) {
$tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']);
$tags = dcCore::app()->meta->computeMetaStats($tags);
$tags = App::meta()->getMetadata(['meta_type' => 'template']);
$tags = App::meta()->computeMetaStats($tags);
$tags->sort('meta_id_lower', 'asc');
$last_letter = null;
@ -403,9 +398,9 @@ class Manage extends Process
$name = $file['f'];
if (preg_match('/^category-(.+).html$/', $name, $cat_id)) {
$category = dcCore::app()->blog->getCategory((int) $cat_id[1]);
$category = App::blog()->getCategory((int) $cat_id[1]);
$full_name = '';
$cat_parents = dcCore::app()->blog->getCategoryParents((int) $cat_id[1]);
$cat_parents = App::blog()->getCategoryParents((int) $cat_id[1]);
while ($cat_parents->fetch()) {
$full_name = $cat_parents->f('cat_title') . ' &rsaquo; ';
};
@ -422,16 +417,16 @@ class Manage extends Process
$t->writeTpl($file['f'], $file['c']);
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
$ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
$ict = App::auth()->prefs()->get('interface')->get('colorsyntax_theme');
Page::openModule(
My::name(),
(
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) : ''
App::auth()->prefs()->get('interface')->get('colorsyntax') ?
Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => App::auth()->prefs()->get('interface')->get('colorsyntax')]) : ''
) .
Page::jsJson('theme_editor_msg', [
'saving_document' => __('Saving document...'),
@ -442,7 +437,7 @@ class Manage extends Process
Page::jsModuleLoad('themeEditor/js/script.js') .
Page::jsConfirmClose('file-form') .
(
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
App::auth()->prefs()->get('interface')->get('colorsyntax') ?
Page::jsLoadCodeMirror(is_string($ict) ? $ict : '') : ''
) .
Page::cssModuleLoad('themeEditor/style.css')
@ -478,8 +473,8 @@ class Manage extends Process
echo
'</div></form>';
if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) {
$ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
if (App::auth()->prefs()->get('interface')->get('colorsyntax')) {
$ict = App::auth()->prefs()->get('interface')->get('colorsyntax_theme');
echo
Page::jsJson('theme_editor_mode', ['mode' => 'html']) .
Page::jsModuleLoad('themeEditor/js/mode.js') .
@ -495,15 +490,15 @@ class Manage extends Process
$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([
dcCore::app()->auth::PERMISSION_PUBLISH,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && App::auth()->check(App::auth()->makePermissions([
App::auth()::PERMISSION_PUBLISH,
App::auth()::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id())) {
try {
dcCore::app()->meta->delMeta($file, 'template');
App::meta()->delMeta($file, 'template');
My::redirect(['part' => 'posts', 'file' => $file]);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -520,15 +515,15 @@ class Manage extends Process
# Get posts
try {
$posts = dcCore::app()->meta->getPostsByMeta($params);
$posts = App::meta()->getPostsByMeta($params);
if (is_null($posts)) {
throw new Exception(__('Failed to get posts meta'));
}
$counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0);
$counter = App::meta()->getPostsByMeta($params, true)?->f(0);
$counter = is_numeric($counter) ? (int) $counter : 0;
$post_list = new ListingPosts($posts, $counter);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
Page::openModule(
@ -549,7 +544,7 @@ class Manage extends Process
'<h3>' . sprintf(__('Unselect template "%s"'), '<strong>' . $file . '</strong>') . '</h3>' .
'<p><a class ="back" href="' . $redir . '">' . __('Back') . '</a></p>';
if (!dcCore::app()->error->flag() && isset($posts)) {
if (!App::error()->flag() && isset($posts)) {
if ($posts->isEmpty() && !$filter->show()) {
echo '<p>' . __('There is no entries') . '</p>';
} else {
@ -573,9 +568,9 @@ class Manage extends Process
'<p class="col right">' .
'<input type="submit" value="' . __('Unselect template for selected entries') . '" /></p>' .
form::hidden('action', 'unselecttpl') .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), $filter->values()) .
App::backend()->url()->getHiddenFormFields('admin.plugin.' . My::id(), $filter->values()) .
form::hidden('redir', $redir) .
dcCore::app()->formNonce() .
App::nonce()->getFormNonce() .
'</div>' .
'</form>',
$filter->show()

View file

@ -1,25 +1,24 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Helper\File\File;
use Dotclear\Helper\Html\Html;
use Dotclear\Interface\Core\MediaInterface;
use Dotclear\Plugin\pages\Pages;
use Exception;
use initPages;
/**
* @brief templator vars class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ManageVars
{
/** @var ManageVars $container Self instance */
@ -31,8 +30,8 @@ class ManageVars
/** @var string $part The requested manage part */
public readonly string $part;
/** @var Media $media The limited media instance */
public readonly Media $media;
/** @var MediaInterface $media The limited media instance */
public readonly MediaInterface $media;
/** @var array<int,File> $items The media items */
public readonly array $items;
@ -57,10 +56,11 @@ class ManageVars
$this->part = empty($name) ? '' : $_REQUEST['part'];
// Extend dcMedia to change settings to allow .html vs media_exclusion
$this->media = new Media();
$this->media = clone App::media();
$this->media->setExcludePattern('/^(.html)$/i');
$this->media->chdir(Templator::MY_TPL_DIR);
// For users with only templator permission, we use sudo.
dcCore::app()->auth?->sudo([$this->media,'getDir']);
App::auth()->sudo($this->media->getDir(...));
$dir = $this->media->dir;
$this->items = array_values($dir['files']);
@ -69,7 +69,7 @@ class ManageVars
$has_categories = false;
try {
$categories = dcCore::app()->blog?->getCategories(['post_type' => 'post']);
$categories = App::blog()->getCategories(['post_type' => 'post']);
if (!is_null($categories)) {
$l = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
$full_name = [is_string($categories->f('cat_title')) ? $categories->f('cat_title') : ''];
@ -103,8 +103,8 @@ class ManageVars
'post.html' => 'post',
];
if (dcCore::app()->plugins->moduleExists('pages')
&& dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([initPages::PERMISSION_PAGES]), dcCore::app()->blog?->id)
if (App::plugins()->moduleExists('pages')
&& App::auth()->check(App::auth()->makePermissions([Pages::PERMISSION_PAGES]), App::blog()->id())
) {
$sources_combo['page.html'] = 'page';
}

View file

@ -1,26 +0,0 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcMedia;
class Media extends dcMedia
{
// limit to html files
protected function isFileExclude(string $file): bool
{
return !preg_match('/\.html$/i', $file);
}
}

View file

@ -1,41 +1,39 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Module\MyPlugin;
/**
* This module definitions.
* @brief templator My helper.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class My extends MyPlugin
{
/** @var string This module permission */
/**
* The module permission.
*
* @var string PERMISSION_TEMPLATOR
*/
public const PERMISSION_TEMPLATOR = 'templator';
public static function checkCustomContext(int $context): ?bool
{
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);
}
return match ($context) {
self::BACKEND, self::MENU, self::MANAGE => App::task()->checkContext('BACKEND')
&& App::auth()->check(App::auth()->makePermissions([
self::PERMISSION_TEMPLATOR,
App::auth()::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id()),
return null;
default => null,
};
}
}

View file

@ -1,33 +1,31 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Helper\File\File;
use Dotclear\Helper\File\Files;
use Exception;
/**
* @brief templator backend pager class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Pager
{
public static function line(File $f, int $i): string
{
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
return '';
}
$p_url = dcCore::app()->admin->getPageURL();
$p_url = App::backend()->getPageURL();
$fname = $f->basename;
$count = '';
$params = [];
@ -41,9 +39,9 @@ class Pager
if (preg_match('/^category-(.+).html$/', $f->basename, $cat_id)) {
$cat_id = (int) $cat_id[1];
$category = dcCore::app()->blog->getCategory($cat_id);
$category = App::blog()->getCategory($cat_id);
$full_name = '';
$cat_parents = dcCore::app()->blog->getCategoryParents($cat_id);
$cat_parents = App::blog()->getCategoryParents($cat_id);
while ($cat_parents->fetch()) {
$full_name = $cat_parents->f('cat_title') . ' &rsaquo; ';
};
@ -54,7 +52,7 @@ class Pager
$part = 'copycat';
try {
$counter = dcCore::app()->blog->getPosts($params, true);
$counter = App::blog()->getPosts($params, true);
if ($counter->f(0) == 0) {
$count = __('No entry');
} elseif ($counter->f(0) == 1) {
@ -63,7 +61,7 @@ class Pager
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entries') . '</a>';
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
$count = '&nbsp;';
@ -75,7 +73,7 @@ class Pager
$params['post_type'] = '';
try {
$counter = dcCore::app()->meta->getPostsByMeta($params, true)?->f(0);
$counter = App::meta()->getPostsByMeta($params, true)?->f(0);
$counter = is_numeric($counter) ? (int) $counter : 0;
$url = My::manageUrl([
'part' => 'posts',
@ -90,7 +88,7 @@ class Pager
$count = '<strong>' . $counter . '</strong> <a href="' . $url . '">' . __('entries') . '</a>';
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -99,10 +97,10 @@ class Pager
'<ul>' .
'<li><a class="media-link" href="' . $link_edit . '"><img src="images/edit-mini.png" alt="' . __('edit') . '" title="' . __('edit the template') . '" /> ' . $fname . '</a> ' . $special . '</li>';
/*
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id)) {
if (App::auth()->check(App::auth()->makePermissions([
App::auth()::PERMISSION_CONTENT_ADMIN,
My::PERMISSION_TEMPLATOR,
]), App::blog()->id())) {
$details = ' - <a href="' . $link . '">' . __('details') . '</a>';
}
*/

View file

@ -1,22 +1,20 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
/**
* @brief templator perpend class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Prepend extends Process
{
public static function init(): bool
@ -30,7 +28,7 @@ class Prepend extends Process
return false;
}
dcCore::app()->auth?->setPermissionType(
App::auth()->setPermissionType(
My::PERMISSION_TEMPLATOR,
__('manage templates')
);

View file

@ -14,14 +14,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Helper\File\Files;
use Dotclear\Helper\File\Path;
use Dotclear\Helper\Html\Html;
use Exception;
/**
* Templator main class.
* @brief templator main class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Templator
{
@ -69,20 +74,20 @@ class Templator
*/
public function __construct()
{
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
throw new Exception(__('Blog is not set'));
}
$page_root = dcCore::app()->plugins->getDefine('pages')->get('root');
$page_root = App::plugins()->getDefine('pages')->get('root');
// Initial templates
$this->path = implode(DIRECTORY_SEPARATOR, [dcCore::app()->blog->public_path, self::MY_TPL_DIR]);
$this->file_tpl_post = implode(DIRECTORY_SEPARATOR, [DC_ROOT, 'inc', 'public', self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_POST]);
$this->file_tpl_category = implode(DIRECTORY_SEPARATOR, [DC_ROOT, 'inc', 'public', self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_CATEGORY]);
$this->path = implode(DIRECTORY_SEPARATOR, [App::blog()->publicPath(), self::MY_TPL_DIR]);
$this->file_tpl_post = implode(DIRECTORY_SEPARATOR, [App::config()->dotclearRoot(), 'inc', 'public', self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_POST]);
$this->file_tpl_category = implode(DIRECTORY_SEPARATOR, [App::config()->dotclearRoot(), 'inc', 'public', self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_CATEGORY]);
$this->file_tpl_page = Path::real(implode(DIRECTORY_SEPARATOR, [$page_root, self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_PAGE])) ?: '';
// user templates
$this->user_path_theme = dcCore::app()->blog->themes_path . DIRECTORY_SEPARATOR . dcCore::app()->blog->settings->get('system')->get('theme');
$this->user_path_theme = App::blog()->themesPath() . DIRECTORY_SEPARATOR . App::blog()->settings()->get('system')->get('theme');
$this->user_tpl_post = Path::real(implode(DIRECTORY_SEPARATOR, [$this->user_path_theme, self::THEME_TPL_DIR, self::DEFAULT_TPL_POST])) ?: '';
$this->user_tpl_category = Path::real(implode(DIRECTORY_SEPARATOR, [$this->user_path_theme, self::THEME_TPL_DIR, self::DEFAULT_TPL_CATEGORY])) ?: '';
$this->user_tpl_page = Path::real(implode(DIRECTORY_SEPARATOR, [$this->user_path_theme, self::THEME_TPL_DIR, self::DEFAULT_TPL_PAGE])) ?: '';

View file

@ -1,25 +1,20 @@
<?php
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\templator;
use dcCore;
use Dotclear\App;
use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement;
/**
* Widgets.
* @brief templator widgets class.
* @ingroup templator
*
* @author Osku (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Widgets
{
@ -40,7 +35,7 @@ class Widgets
->create(
'templatorWidget',
__('Templator Rendering'),
[self::class, 'getDataTpl']
self::getDataTpl(...)
)
->setting(
'template',
@ -53,7 +48,7 @@ class Widgets
public static function getDataTpl(WidgetsElement $w): string
{
return is_string($w->__get('template')) && dcCore::app()->tpl->getFilePath($w->__get('template')) ?
dcCore::app()->tpl->getData($w->__get('template')) : '';
return is_string($w->__get('template')) && App::frontend()->template()->getFilePath($w->__get('template')) ?
App::frontend()->template()->getData($w->__get('template')) : '';
}
}