upgrade to dotclear 2.28
This commit is contained in:
parent
38b7d54089
commit
d3bf04228d
@ -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
|
templator 1.6 - 2023.08.15
|
||||||
===========================================================
|
===========================================================
|
||||||
* Require Dotclear 2.27
|
* Require Dotclear 2.27
|
||||||
|
34
README.md
34
README.md
@ -1,28 +1,25 @@
|
|||||||
# README
|
# README
|
||||||
|
|
||||||
[![Release](https://img.shields.io/badge/release-1.6-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
|
[![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.08.15-c44d58.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.27-137bbb.svg)](https://fr.dotclear.org/download)
|
[![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)
|
[![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
|
_templator_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
|
||||||
web publishing software called Dotclear.
|
|
||||||
|
|
||||||
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 copy existing templates, then edit them.
|
||||||
You can attribute a template to a post or a category.
|
You can attribute a template to a post or a category.
|
||||||
|
|
||||||
## REQUIREMENTS
|
## REQUIREMENTS
|
||||||
|
|
||||||
_templator_ requires:
|
* Dotclear 2.28
|
||||||
|
|
||||||
* content admin or templator
|
|
||||||
* Dotclear 2.27
|
|
||||||
* PHP 8.1+
|
* 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
|
## USAGE
|
||||||
|
|
||||||
@ -34,14 +31,15 @@ You can manage your additional templates from menu
|
|||||||
|
|
||||||
## LINKS
|
## LINKS
|
||||||
|
|
||||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
* [License](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE)
|
||||||
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/templator) or [GitHub Page](https://github.com/JcDenis/templator)
|
* [Packages & details](https://git.dotclear.watch/JcDenis/templator/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/templator))
|
||||||
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/templator/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/templator)
|
* [Sources & contributions](https://git.dotclear.watch/JcDenis/templator) (or on [GitHub](https://github.com/JcDenis/templator))
|
||||||
* Discuss and help : [Dotclear Forum](http://forum.dotclear.net/viewtopic.php?id=42059)
|
* [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
|
## CONTRIBUTORS
|
||||||
|
|
||||||
* Osku (author)
|
* Osku (author)
|
||||||
* Jean-Christian Denis
|
* Jean-Christian Denis (latest)
|
||||||
|
|
||||||
You are welcome to contribute to this code.
|
You are welcome to contribute to this code.
|
||||||
|
28
_define.php
28
_define.php
@ -1,33 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @brief templator, a plugin for Dotclear 2
|
* @file
|
||||||
|
* @brief The plugin templator definition
|
||||||
|
* @ingroup templator
|
||||||
*
|
*
|
||||||
* @package Dotclear
|
* @defgroup templator Plugin templator.
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
*
|
||||||
* @author Osku and contributors
|
* Create and select more templates for your posts.
|
||||||
*
|
*
|
||||||
* @copyright Jean-Christian Denis
|
* @author Osku (author)
|
||||||
|
* @author Jean-Christian Denis (latest)
|
||||||
* @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_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->registerModule(
|
$this->registerModule(
|
||||||
'Templates engine',
|
'Templates engine',
|
||||||
'Create and select more templates for your posts',
|
'Create and select more templates for your posts',
|
||||||
'Osku and contributors',
|
'Osku and contributors',
|
||||||
'1.6',
|
'1.7',
|
||||||
[
|
[
|
||||||
'requires' => [
|
'requires' => [['core', '2.28']],
|
||||||
['php', '8.1'],
|
'permissions' => 'My',
|
||||||
['core', '2.27'],
|
|
||||||
],
|
|
||||||
'permissions' => dcCore::app()->auth->makePermissions([
|
|
||||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
|
||||||
initTemplator::PERMISSION_TEMPLATOR,
|
|
||||||
]),
|
|
||||||
'type' => 'plugin',
|
'type' => 'plugin',
|
||||||
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
|
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
|
||||||
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
|
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
|
||||||
|
20
_init.php
20
_init.php
@ -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';
|
|
||||||
}
|
|
@ -2,11 +2,11 @@
|
|||||||
<modules xmlns:da="http://dotaddict.org/da/">
|
<modules xmlns:da="http://dotaddict.org/da/">
|
||||||
<module id="templator">
|
<module id="templator">
|
||||||
<name>Templates engine</name>
|
<name>Templates engine</name>
|
||||||
<version>1.6</version>
|
<version>1.7</version>
|
||||||
<author>Osku and contributors</author>
|
<author>Osku and contributors</author>
|
||||||
<desc>Create and select more templates for your posts</desc>
|
<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>
|
<file>https://git.dotclear.watch/JcDenis/templator/releases/download/v1.7/plugin-templator.zip</file>
|
||||||
<da:dcmin>2.27</da:dcmin>
|
<da:dcmin>2.28</da:dcmin>
|
||||||
<da:details>https://git.dotclear.watch/JcDenis/templator/src/branch/master/README.md</da:details>
|
<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>
|
<da:support>https://git.dotclear.watch/JcDenis/templator/issues</da:support>
|
||||||
</module>
|
</module>
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Process;
|
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
|
class Backend extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
@ -32,19 +30,19 @@ class Backend extends Process
|
|||||||
|
|
||||||
My::addBackendMenuItem();
|
My::addBackendMenuItem();
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
App::behavior()->addBehaviors([
|
||||||
'adminPostHeaders' => [BackendBehaviors::class,'adminPostHeaders'],
|
'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
|
||||||
'adminPostFormItems' => [BackendBehaviors::class,'adminPostFormItems'],
|
'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
|
||||||
'adminPageHeaders' => [BackendBehaviors::class,'adminPostHeaders'],
|
'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...),
|
||||||
'adminPageFormItems' => [BackendBehaviors::class,'adminPostFormItems'],
|
'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...),
|
||||||
'adminAfterPostCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
|
'adminAfterPostCreate' => BackendBehaviors::adminBeforePostUpdate(...),
|
||||||
'adminBeforePostUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
|
'adminBeforePostUpdate' => BackendBehaviors::adminBeforePostUpdate(...),
|
||||||
'adminAfterPageCreate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
|
'adminAfterPageCreate' => BackendBehaviors::adminBeforePostUpdate(...),
|
||||||
'adminBeforePageUpdate' => [BackendBehaviors::class,'adminBeforePostUpdate'],
|
'adminBeforePageUpdate' => BackendBehaviors::adminBeforePostUpdate(...),
|
||||||
'adminPostsActions' => [BackendBehaviors::class,'adminPostsActions'],
|
'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
|
||||||
'adminPagesActions' => [BackendBehaviors::class,'adminPostsActions'],
|
'adminPagesActions' => BackendBehaviors::adminPostsActions(...),
|
||||||
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
|
'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
|
||||||
'initWidgets' => [Widgets::class, 'initWidgets'],
|
'initWidgets' => Widgets::initWidgets(...),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Backend\Action\ActionsPosts;
|
use Dotclear\Core\Backend\Action\ActionsPosts;
|
||||||
use Dotclear\Core\Backend\{
|
use Dotclear\Core\Backend\{
|
||||||
Notices,
|
Notices,
|
||||||
@ -30,6 +20,14 @@ use Exception;
|
|||||||
|
|
||||||
use form;
|
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
|
class BackendBehaviors
|
||||||
{
|
{
|
||||||
public static function adminPostHeaders(): string
|
public static function adminPostHeaders(): string
|
||||||
@ -42,7 +40,7 @@ class BackendBehaviors
|
|||||||
$selected = '';
|
$selected = '';
|
||||||
|
|
||||||
if (!is_null($post)) {
|
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');
|
$selected = $post_meta->isEmpty() ? '' : $post_meta->f('meta_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,9 +56,9 @@ class BackendBehaviors
|
|||||||
$post_id = (int) $post_id;
|
$post_id = (int) $post_id;
|
||||||
|
|
||||||
if (isset($_POST['post_tpl'])) {
|
if (isset($_POST['post_tpl'])) {
|
||||||
dcCore::app()->meta->delPostMeta($post_id, 'template');
|
App::meta()->delPostMeta($post_id, 'template');
|
||||||
if (!empty($_POST['post_tpl'])) {
|
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',
|
__('Select the template') => 'tpl',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[self::class, 'adminPostsActionsCallback']
|
self::adminPostsActionsCallback(...)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,22 +88,22 @@ class BackendBehaviors
|
|||||||
if (isset($post['post_tpl']) && is_string($post['post_tpl'])) {
|
if (isset($post['post_tpl']) && is_string($post['post_tpl'])) {
|
||||||
try {
|
try {
|
||||||
foreach ($posts_ids as $post_id) {
|
foreach ($posts_ids as $post_id) {
|
||||||
dcCore::app()->meta->delPostMeta($post_id, 'template');
|
App::meta()->delPostMeta($post_id, 'template');
|
||||||
if (!empty($post['post_tpl'])) {
|
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.'));
|
Notices::addSuccessNotice(__('Entries template updated.'));
|
||||||
$pa->redirect(true);
|
$pa->redirect(true);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pa->beginPage(
|
$pa->beginPage(
|
||||||
Page::breadcrumb([
|
Page::breadcrumb([
|
||||||
Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
|
Html::escapeHTML(App::blog()->name()) => '',
|
||||||
$pa->getCallerTitle() => $pa->getRedirection(true),
|
$pa->getCallerTitle() => $pa->getRedirection(true),
|
||||||
__('Entry template') => '',
|
__('Entry template') => '',
|
||||||
])
|
])
|
||||||
@ -120,7 +118,7 @@ class BackendBehaviors
|
|||||||
|
|
||||||
'<p>' .
|
'<p>' .
|
||||||
$pa->getHiddenFields() .
|
$pa->getHiddenFields() .
|
||||||
dcCore::app()->formNonce() .
|
App::nonce()->getFormNonce() .
|
||||||
form::hidden(['action'], 'tpl') .
|
form::hidden(['action'], 'tpl') .
|
||||||
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
||||||
'</form>';
|
'</form>';
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Process;
|
use Dotclear\Core\Process;
|
||||||
use Dotclear\Database\MetaRecord;
|
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
|
class Frontend extends Process
|
||||||
{
|
{
|
||||||
@ -34,41 +29,37 @@ class Frontend extends Process
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->tpl->setPath(
|
App::frontend()->template()->setPath(
|
||||||
dcCore::app()->tpl->getPath(),
|
App::frontend()->template()->getPath(),
|
||||||
Templator::instance()->getPath()
|
Templator::instance()->getPath()
|
||||||
);
|
);
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
App::behavior()->addBehaviors([
|
||||||
'urlHandlerBeforeGetData' => function ($_): void {
|
'urlHandlerBeforeGetData' => function ($_): void {
|
||||||
if (is_null(dcCore::app()->ctx)) {
|
if ((App::frontend()->context()->__get('posts') instanceof MetaRecord)
|
||||||
return;
|
&& (array_key_exists(App::url()->type, App::postTypes()->getPostTypes()) || App::url()->type == 'pages')) {
|
||||||
}
|
|
||||||
|
|
||||||
if ((dcCore::app()->ctx->__get('posts') instanceof MetaRecord)
|
|
||||||
&& (array_key_exists(dcCore::app()->url->type, dcCore::app()->getPostTypes()) || dcCore::app()->url->type == 'pages')) {
|
|
||||||
$params = [];
|
$params = [];
|
||||||
$params['meta_type'] = 'template';
|
$params['meta_type'] = 'template';
|
||||||
$params['post_id'] = dcCore::app()->ctx->__get('posts')->f('post_id');
|
$params['post_id'] = App::frontend()->context()->__get('posts')->f('post_id');
|
||||||
$post_meta = dcCore::app()->meta->getMetadata($params);
|
$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'))) {
|
if (!$post_meta->isEmpty() && is_string($post_meta->f('meta_id')) && App::frontend()->template()->getFilePath($post_meta->f('meta_id'))) {
|
||||||
dcCore::app()->ctx->__set('current_tpl', $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'
|
if (App::frontend()->context()->__get('current_tpl') == 'category.html'
|
||||||
&& (dcCore::app()->ctx->__get('categories') instanceof MetaRecord)
|
&& (App::frontend()->context()->__get('categories') instanceof MetaRecord)
|
||||||
&& is_string(dcCore::app()->ctx->__get('categories')->f('cat_id'))
|
&& is_string(App::frontend()->context()->__get('categories')->f('cat_id'))
|
||||||
&& preg_match('/^[0-9]{1,}/', dcCore::app()->ctx->__get('categories')->f('cat_id'), $cat_id)
|
&& preg_match('/^[0-9]{1,}/', App::frontend()->context()->__get('categories')->f('cat_id'), $cat_id)
|
||||||
) {
|
) {
|
||||||
$tpl = 'category-' . $cat_id[0] . '.html';
|
$tpl = 'category-' . $cat_id[0] . '.html';
|
||||||
if (dcCore::app()->tpl->getFilePath($tpl)) {
|
if (App::frontend()->template()->getFilePath($tpl)) {
|
||||||
dcCore::app()->ctx->__set('current_tpl', $tpl);
|
App::frontend()->context()->__set('current_tpl', $tpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'initWidgets' => [Widgets::class, 'initWidgets'],
|
'initWidgets' => Widgets::initWidgets(...),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,20 +1,10 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Backend\Filter\{
|
use Dotclear\Core\Backend\Filter\{
|
||||||
Filters,
|
Filters,
|
||||||
FiltersLibrary
|
FiltersLibrary
|
||||||
@ -32,6 +22,14 @@ use Exception;
|
|||||||
|
|
||||||
use form;
|
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
|
class Manage extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
@ -63,12 +61,12 @@ class Manage extends Process
|
|||||||
}
|
}
|
||||||
$t->initializeTpl($name, $_POST['filesource']);
|
$t->initializeTpl($name, $_POST['filesource']);
|
||||||
|
|
||||||
if (!dcCore::app()->error->flag()) {
|
if (!App::error()->flag()) {
|
||||||
Notices::addSuccessNotice(__('The new template has been successfully created.'));
|
Notices::addSuccessNotice(__('The new template has been successfully created.'));
|
||||||
My::redirect();
|
My::redirect();
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} 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'])
|
rawurldecode($_POST['file'])
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!dcCore::app()->error->flag()) {
|
if (!App::error()->flag()) {
|
||||||
Notices::addSuccessNotice(__('The template has been successfully copied.'));
|
Notices::addSuccessNotice(__('The template has been successfully copied.'));
|
||||||
My::redirect(['part' => 'files']);
|
My::redirect(['part' => 'files']);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} 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'])
|
rawurldecode($_POST['file'])
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!dcCore::app()->error->flag()) {
|
if (!App::error()->flag()) {
|
||||||
Notices::addSuccessNotice(__('The template has been successfully copied.'));
|
Notices::addSuccessNotice(__('The template has been successfully copied.'));
|
||||||
My::redirect(['part' => 'files']);
|
My::redirect(['part' => 'files']);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,14 +115,14 @@ class Manage extends Process
|
|||||||
try {
|
try {
|
||||||
$file = rawurldecode($_POST['file']);
|
$file = rawurldecode($_POST['file']);
|
||||||
$v->media->removeItem($file);
|
$v->media->removeItem($file);
|
||||||
dcCore::app()->meta->delMeta($file, 'template');
|
App::meta()->delMeta($file, 'template');
|
||||||
|
|
||||||
if (!dcCore::app()->error->flag()) {
|
if (!dcCore::app()->error->flag()) {
|
||||||
Notices::addSuccessNotice(__('The template has been successfully removed.'));
|
Notices::addSuccessNotice(__('The template has been successfully removed.'));
|
||||||
My::redirect(['part' => 'files']);
|
My::redirect(['part' => 'files']);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} 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
|
public static function render(): void
|
||||||
{
|
{
|
||||||
if (!self::status()) {
|
if (!self::status()
|
||||||
return;
|
|| !App::blog()->isDefined()
|
||||||
}
|
) {
|
||||||
|
|
||||||
// nullsafe
|
|
||||||
if (is_null(dcCore::app()->blog)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +146,7 @@ class Manage extends Process
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!$t->canUseRessources(true)) {
|
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());
|
Page::openModule(My::name());
|
||||||
echo
|
echo
|
||||||
Page::breadcrumb([
|
Page::breadcrumb([
|
||||||
@ -226,12 +221,12 @@ class Manage extends Process
|
|||||||
*/
|
*/
|
||||||
} elseif ('copycat' == $v->part && !empty($_REQUEST['file'])) {
|
} elseif ('copycat' == $v->part && !empty($_REQUEST['file'])) {
|
||||||
$category_id = (int) str_replace(['category-','.html'], '', $_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 = '';
|
$full_name = '';
|
||||||
while ($cat_parents->fetch()) {
|
while ($cat_parents->fetch()) {
|
||||||
$full_name = $cat_parents->f('cat_title') . ' › ';
|
$full_name = $cat_parents->f('cat_title') . ' › ';
|
||||||
};
|
};
|
||||||
$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());
|
Page::openModule(My::name());
|
||||||
echo
|
echo
|
||||||
@ -322,8 +317,8 @@ class Manage extends Process
|
|||||||
* List Used templator template
|
* List Used templator template
|
||||||
*/
|
*/
|
||||||
} elseif ('used' == $v->part) {
|
} elseif ('used' == $v->part) {
|
||||||
$tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']);
|
$tags = App::meta()->getMetadata(['meta_type' => 'template']);
|
||||||
$tags = dcCore::app()->meta->computeMetaStats($tags);
|
$tags = App::meta()->computeMetaStats($tags);
|
||||||
$tags->sort('meta_id_lower', 'asc');
|
$tags->sort('meta_id_lower', 'asc');
|
||||||
|
|
||||||
$last_letter = null;
|
$last_letter = null;
|
||||||
@ -403,9 +398,9 @@ class Manage extends Process
|
|||||||
$name = $file['f'];
|
$name = $file['f'];
|
||||||
|
|
||||||
if (preg_match('/^category-(.+).html$/', $name, $cat_id)) {
|
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 = '';
|
$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()) {
|
while ($cat_parents->fetch()) {
|
||||||
$full_name = $cat_parents->f('cat_title') . ' › ';
|
$full_name = $cat_parents->f('cat_title') . ' › ';
|
||||||
};
|
};
|
||||||
@ -422,16 +417,16 @@ class Manage extends Process
|
|||||||
$t->writeTpl($file['f'], $file['c']);
|
$t->writeTpl($file['f'], $file['c']);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} 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(
|
Page::openModule(
|
||||||
My::name(),
|
My::name(),
|
||||||
(
|
(
|
||||||
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
|
App::auth()->prefs()->get('interface')->get('colorsyntax') ?
|
||||||
Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) : ''
|
Page::jsJson('dotclear_colorsyntax', ['colorsyntax' => App::auth()->prefs()->get('interface')->get('colorsyntax')]) : ''
|
||||||
) .
|
) .
|
||||||
Page::jsJson('theme_editor_msg', [
|
Page::jsJson('theme_editor_msg', [
|
||||||
'saving_document' => __('Saving document...'),
|
'saving_document' => __('Saving document...'),
|
||||||
@ -442,7 +437,7 @@ class Manage extends Process
|
|||||||
Page::jsModuleLoad('themeEditor/js/script.js') .
|
Page::jsModuleLoad('themeEditor/js/script.js') .
|
||||||
Page::jsConfirmClose('file-form') .
|
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::jsLoadCodeMirror(is_string($ict) ? $ict : '') : ''
|
||||||
) .
|
) .
|
||||||
Page::cssModuleLoad('themeEditor/style.css')
|
Page::cssModuleLoad('themeEditor/style.css')
|
||||||
@ -478,8 +473,8 @@ class Manage extends Process
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
'</div></form>';
|
'</div></form>';
|
||||||
if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) {
|
if (App::auth()->prefs()->get('interface')->get('colorsyntax')) {
|
||||||
$ict = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
|
$ict = App::auth()->prefs()->get('interface')->get('colorsyntax_theme');
|
||||||
echo
|
echo
|
||||||
Page::jsJson('theme_editor_mode', ['mode' => 'html']) .
|
Page::jsJson('theme_editor_mode', ['mode' => 'html']) .
|
||||||
Page::jsModuleLoad('themeEditor/js/mode.js') .
|
Page::jsModuleLoad('themeEditor/js/mode.js') .
|
||||||
@ -495,15 +490,15 @@ class Manage extends Process
|
|||||||
$redir = $_REQUEST['redir'] ?? My::manageUrl(['part' => 'used']);
|
$redir = $_REQUEST['redir'] ?? My::manageUrl(['part' => 'used']);
|
||||||
|
|
||||||
# Unselect the template
|
# Unselect the template
|
||||||
if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && App::auth()->check(App::auth()->makePermissions([
|
||||||
dcCore::app()->auth::PERMISSION_PUBLISH,
|
App::auth()::PERMISSION_PUBLISH,
|
||||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
App::auth()::PERMISSION_CONTENT_ADMIN,
|
||||||
]), dcCore::app()->blog->id)) {
|
]), App::blog()->id())) {
|
||||||
try {
|
try {
|
||||||
dcCore::app()->meta->delMeta($file, 'template');
|
App::meta()->delMeta($file, 'template');
|
||||||
My::redirect(['part' => 'posts', 'file' => $file]);
|
My::redirect(['part' => 'posts', 'file' => $file]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,15 +515,15 @@ class Manage extends Process
|
|||||||
|
|
||||||
# Get posts
|
# Get posts
|
||||||
try {
|
try {
|
||||||
$posts = dcCore::app()->meta->getPostsByMeta($params);
|
$posts = App::meta()->getPostsByMeta($params);
|
||||||
if (is_null($posts)) {
|
if (is_null($posts)) {
|
||||||
throw new Exception(__('Failed to get posts meta'));
|
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;
|
$counter = is_numeric($counter) ? (int) $counter : 0;
|
||||||
$post_list = new ListingPosts($posts, $counter);
|
$post_list = new ListingPosts($posts, $counter);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
Page::openModule(
|
Page::openModule(
|
||||||
@ -549,7 +544,7 @@ class Manage extends Process
|
|||||||
'<h3>' . sprintf(__('Unselect template "%s"'), '<strong>' . $file . '</strong>') . '</h3>' .
|
'<h3>' . sprintf(__('Unselect template "%s"'), '<strong>' . $file . '</strong>') . '</h3>' .
|
||||||
'<p><a class ="back" href="' . $redir . '">' . __('Back') . '</a></p>';
|
'<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()) {
|
if ($posts->isEmpty() && !$filter->show()) {
|
||||||
echo '<p>' . __('There is no entries') . '</p>';
|
echo '<p>' . __('There is no entries') . '</p>';
|
||||||
} else {
|
} else {
|
||||||
@ -573,9 +568,9 @@ class Manage extends Process
|
|||||||
'<p class="col right">' .
|
'<p class="col right">' .
|
||||||
'<input type="submit" value="' . __('Unselect template for selected entries') . '" /></p>' .
|
'<input type="submit" value="' . __('Unselect template for selected entries') . '" /></p>' .
|
||||||
form::hidden('action', 'unselecttpl') .
|
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) .
|
form::hidden('redir', $redir) .
|
||||||
dcCore::app()->formNonce() .
|
App::nonce()->getFormNonce() .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'</form>',
|
'</form>',
|
||||||
$filter->show()
|
$filter->show()
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Helper\File\File;
|
use Dotclear\Helper\File\File;
|
||||||
use Dotclear\Helper\Html\Html;
|
use Dotclear\Helper\Html\Html;
|
||||||
|
use Dotclear\Interface\Core\MediaInterface;
|
||||||
|
use Dotclear\Plugin\pages\Pages;
|
||||||
use Exception;
|
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
|
class ManageVars
|
||||||
{
|
{
|
||||||
/** @var ManageVars $container Self instance */
|
/** @var ManageVars $container Self instance */
|
||||||
@ -31,8 +30,8 @@ class ManageVars
|
|||||||
/** @var string $part The requested manage part */
|
/** @var string $part The requested manage part */
|
||||||
public readonly string $part;
|
public readonly string $part;
|
||||||
|
|
||||||
/** @var Media $media The limited media instance */
|
/** @var MediaInterface $media The limited media instance */
|
||||||
public readonly Media $media;
|
public readonly MediaInterface $media;
|
||||||
|
|
||||||
/** @var array<int,File> $items The media items */
|
/** @var array<int,File> $items The media items */
|
||||||
public readonly array $items;
|
public readonly array $items;
|
||||||
@ -57,10 +56,11 @@ class ManageVars
|
|||||||
$this->part = empty($name) ? '' : $_REQUEST['part'];
|
$this->part = empty($name) ? '' : $_REQUEST['part'];
|
||||||
|
|
||||||
// Extend dcMedia to change settings to allow .html vs media_exclusion
|
// 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);
|
$this->media->chdir(Templator::MY_TPL_DIR);
|
||||||
// For users with only templator permission, we use sudo.
|
// 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;
|
$dir = $this->media->dir;
|
||||||
$this->items = array_values($dir['files']);
|
$this->items = array_values($dir['files']);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class ManageVars
|
|||||||
$has_categories = false;
|
$has_categories = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$categories = dcCore::app()->blog?->getCategories(['post_type' => 'post']);
|
$categories = App::blog()->getCategories(['post_type' => 'post']);
|
||||||
if (!is_null($categories)) {
|
if (!is_null($categories)) {
|
||||||
$l = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
|
$l = is_numeric($categories->f('level')) ? (int) $categories->f('level') : 1;
|
||||||
$full_name = [is_string($categories->f('cat_title')) ? $categories->f('cat_title') : ''];
|
$full_name = [is_string($categories->f('cat_title')) ? $categories->f('cat_title') : ''];
|
||||||
@ -103,8 +103,8 @@ class ManageVars
|
|||||||
'post.html' => 'post',
|
'post.html' => 'post',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (dcCore::app()->plugins->moduleExists('pages')
|
if (App::plugins()->moduleExists('pages')
|
||||||
&& dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([initPages::PERMISSION_PAGES]), dcCore::app()->blog?->id)
|
&& App::auth()->check(App::auth()->makePermissions([Pages::PERMISSION_PAGES]), App::blog()->id())
|
||||||
) {
|
) {
|
||||||
$sources_combo['page.html'] = 'page';
|
$sources_combo['page.html'] = 'page';
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
44
src/My.php
44
src/My.php
@ -1,41 +1,39 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Module\MyPlugin;
|
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
|
class My extends MyPlugin
|
||||||
{
|
{
|
||||||
/** @var string This module permission */
|
/**
|
||||||
|
* The module permission.
|
||||||
|
*
|
||||||
|
* @var string PERMISSION_TEMPLATOR
|
||||||
|
*/
|
||||||
public const PERMISSION_TEMPLATOR = 'templator';
|
public const PERMISSION_TEMPLATOR = 'templator';
|
||||||
|
|
||||||
public static function checkCustomContext(int $context): ?bool
|
public static function checkCustomContext(int $context): ?bool
|
||||||
{
|
{
|
||||||
if (in_array($context, [My::BACKEND, My::MENU, My::MANAGE])) {
|
return match ($context) {
|
||||||
return defined('DC_CONTEXT_ADMIN')
|
self::BACKEND, self::MENU, self::MANAGE => App::task()->checkContext('BACKEND')
|
||||||
&& !is_null(dcCore::app()->blog)
|
&& App::auth()->check(App::auth()->makePermissions([
|
||||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
self::PERMISSION_TEMPLATOR,
|
||||||
My::PERMISSION_TEMPLATOR,
|
App::auth()::PERMISSION_CONTENT_ADMIN,
|
||||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
]), App::blog()->id()),
|
||||||
]), dcCore::app()->blog->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
default => null,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,31 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Helper\File\File;
|
use Dotclear\Helper\File\File;
|
||||||
use Dotclear\Helper\File\Files;
|
use Dotclear\Helper\File\Files;
|
||||||
use Exception;
|
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
|
class Pager
|
||||||
{
|
{
|
||||||
public static function line(File $f, int $i): string
|
public static function line(File $f, int $i): string
|
||||||
{
|
{
|
||||||
if (is_null(dcCore::app()->blog)) {
|
if (!App::blog()->isDefined()) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$p_url = dcCore::app()->admin->getPageURL();
|
$p_url = App::backend()->getPageURL();
|
||||||
$fname = $f->basename;
|
$fname = $f->basename;
|
||||||
$count = '';
|
$count = '';
|
||||||
$params = [];
|
$params = [];
|
||||||
@ -41,9 +39,9 @@ class Pager
|
|||||||
|
|
||||||
if (preg_match('/^category-(.+).html$/', $f->basename, $cat_id)) {
|
if (preg_match('/^category-(.+).html$/', $f->basename, $cat_id)) {
|
||||||
$cat_id = (int) $cat_id[1];
|
$cat_id = (int) $cat_id[1];
|
||||||
$category = dcCore::app()->blog->getCategory($cat_id);
|
$category = App::blog()->getCategory($cat_id);
|
||||||
$full_name = '';
|
$full_name = '';
|
||||||
$cat_parents = dcCore::app()->blog->getCategoryParents($cat_id);
|
$cat_parents = App::blog()->getCategoryParents($cat_id);
|
||||||
while ($cat_parents->fetch()) {
|
while ($cat_parents->fetch()) {
|
||||||
$full_name = $cat_parents->f('cat_title') . ' › ';
|
$full_name = $cat_parents->f('cat_title') . ' › ';
|
||||||
};
|
};
|
||||||
@ -54,7 +52,7 @@ class Pager
|
|||||||
$part = 'copycat';
|
$part = 'copycat';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$counter = dcCore::app()->blog->getPosts($params, true);
|
$counter = App::blog()->getPosts($params, true);
|
||||||
if ($counter->f(0) == 0) {
|
if ($counter->f(0) == 0) {
|
||||||
$count = __('No entry');
|
$count = __('No entry');
|
||||||
} elseif ($counter->f(0) == 1) {
|
} 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>';
|
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entries') . '</a>';
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
|
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
|
||||||
$count = ' ';
|
$count = ' ';
|
||||||
@ -75,7 +73,7 @@ class Pager
|
|||||||
$params['post_type'] = '';
|
$params['post_type'] = '';
|
||||||
|
|
||||||
try {
|
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;
|
$counter = is_numeric($counter) ? (int) $counter : 0;
|
||||||
$url = My::manageUrl([
|
$url = My::manageUrl([
|
||||||
'part' => 'posts',
|
'part' => 'posts',
|
||||||
@ -90,7 +88,7 @@ class Pager
|
|||||||
$count = '<strong>' . $counter . '</strong> <a href="' . $url . '">' . __('entries') . '</a>';
|
$count = '<strong>' . $counter . '</strong> <a href="' . $url . '">' . __('entries') . '</a>';
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
App::error()->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,10 +97,10 @@ class Pager
|
|||||||
'<ul>' .
|
'<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>';
|
'<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([
|
if (App::auth()->check(App::auth()->makePermissions([
|
||||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
App::auth()::PERMISSION_CONTENT_ADMIN,
|
||||||
initTemplator::PERMISSION_TEMPLATOR,
|
My::PERMISSION_TEMPLATOR,
|
||||||
]), dcCore::app()->blog->id)) {
|
]), App::blog()->id())) {
|
||||||
$details = ' - <a href="' . $link . '">' . __('details') . '</a>';
|
$details = ' - <a href="' . $link . '">' . __('details') . '</a>';
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Process;
|
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
|
class Prepend extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
@ -30,7 +28,7 @@ class Prepend extends Process
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->auth?->setPermissionType(
|
App::auth()->setPermissionType(
|
||||||
My::PERMISSION_TEMPLATOR,
|
My::PERMISSION_TEMPLATOR,
|
||||||
__('manage templates')
|
__('manage templates')
|
||||||
);
|
);
|
||||||
|
@ -14,14 +14,19 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Helper\File\Files;
|
use Dotclear\Helper\File\Files;
|
||||||
use Dotclear\Helper\File\Path;
|
use Dotclear\Helper\File\Path;
|
||||||
use Dotclear\Helper\Html\Html;
|
use Dotclear\Helper\Html\Html;
|
||||||
use Exception;
|
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
|
class Templator
|
||||||
{
|
{
|
||||||
@ -69,20 +74,20 @@ class Templator
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if (is_null(dcCore::app()->blog)) {
|
if (!App::blog()->isDefined()) {
|
||||||
throw new Exception(__('Blog is not set'));
|
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
|
// Initial templates
|
||||||
$this->path = implode(DIRECTORY_SEPARATOR, [dcCore::app()->blog->public_path, self::MY_TPL_DIR]);
|
$this->path = implode(DIRECTORY_SEPARATOR, [App::blog()->publicPath(), 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_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, [DC_ROOT, 'inc', 'public', self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_CATEGORY]);
|
$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])) ?: '';
|
$this->file_tpl_page = Path::real(implode(DIRECTORY_SEPARATOR, [$page_root, self::DC_TPL_DIR, self::DEFAULT_TPLSET, self::DEFAULT_TPL_PAGE])) ?: '';
|
||||||
|
|
||||||
// user templates
|
// 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_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_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])) ?: '';
|
$this->user_tpl_page = Path::real(implode(DIRECTORY_SEPARATOR, [$this->user_path_theme, self::THEME_TPL_DIR, self::DEFAULT_TPL_PAGE])) ?: '';
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
<?php
|
<?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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\templator;
|
namespace Dotclear\Plugin\templator;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Plugin\widgets\WidgetsStack;
|
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
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
|
class Widgets
|
||||||
{
|
{
|
||||||
@ -40,7 +35,7 @@ class Widgets
|
|||||||
->create(
|
->create(
|
||||||
'templatorWidget',
|
'templatorWidget',
|
||||||
__('Templator › Rendering'),
|
__('Templator › Rendering'),
|
||||||
[self::class, 'getDataTpl']
|
self::getDataTpl(...)
|
||||||
)
|
)
|
||||||
->setting(
|
->setting(
|
||||||
'template',
|
'template',
|
||||||
@ -53,7 +48,7 @@ class Widgets
|
|||||||
|
|
||||||
public static function getDataTpl(WidgetsElement $w): string
|
public static function getDataTpl(WidgetsElement $w): string
|
||||||
{
|
{
|
||||||
return is_string($w->__get('template')) && dcCore::app()->tpl->getFilePath($w->__get('template')) ?
|
return is_string($w->__get('template')) && App::frontend()->template()->getFilePath($w->__get('template')) ?
|
||||||
dcCore::app()->tpl->getData($w->__get('template')) : '';
|
App::frontend()->template()->getData($w->__get('template')) : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user