code review
This commit is contained in:
parent
d3bf04228d
commit
a77741d890
10 changed files with 87 additions and 46 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
templator 1.7.1 - 2023.11.04
|
||||||
|
===========================================================
|
||||||
|
* Require Dotclear 2.28
|
||||||
|
* Require PHP 8.1
|
||||||
|
* Code review (phpstan)
|
||||||
|
|
||||||
templator 1.7 - 2023.10.20
|
templator 1.7 - 2023.10.20
|
||||||
===========================================================
|
===========================================================
|
||||||
* Require Dotclear 2.28
|
* Require Dotclear 2.28
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# README
|
# README
|
||||||
|
|
||||||
[![Release](https://img.shields.io/badge/release-1.7-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
|
[![Release](https://img.shields.io/badge/release-1.7.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/templator/releases)
|
||||||
![Date](https://img.shields.io/badge/date-2023.10.20-c44d58.svg)
|
![Date](https://img.shields.io/badge/date-2023.11.04-c44d58.svg)
|
||||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-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/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE)
|
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/templator/src/branch/master/LICENSE)
|
||||||
|
|
|
@ -18,7 +18,7 @@ $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.7',
|
'1.7.1',
|
||||||
[
|
[
|
||||||
'requires' => [['core', '2.28']],
|
'requires' => [['core', '2.28']],
|
||||||
'permissions' => 'My',
|
'permissions' => 'My',
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
<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.7</version>
|
<version>1.7.1</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.7/plugin-templator.zip</file>
|
<file>https://git.dotclear.watch/JcDenis/templator/releases/download/v1.7.1/plugin-templator.zip</file>
|
||||||
<da:dcmin>2.28</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>
|
||||||
|
|
|
@ -35,6 +35,10 @@ class BackendBehaviors
|
||||||
return My::jsLoad('admin');
|
return My::jsLoad('admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ArrayObject<string, mixed> $main_items
|
||||||
|
* @param ArrayObject<string, mixed> $sidebar_items
|
||||||
|
*/
|
||||||
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
|
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
|
||||||
{
|
{
|
||||||
$selected = '';
|
$selected = '';
|
||||||
|
@ -75,6 +79,9 @@ class BackendBehaviors
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ArrayObject<string, mixed> $post
|
||||||
|
*/
|
||||||
public static function adminPostsActionsCallback(ActionsPosts $pa, ArrayObject $post): void
|
public static function adminPostsActionsCallback(ActionsPosts $pa, ArrayObject $post): void
|
||||||
{
|
{
|
||||||
# No entry
|
# No entry
|
||||||
|
@ -126,6 +133,9 @@ class BackendBehaviors
|
||||||
$pa->endPage();
|
$pa->endPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ArrayObject<string, mixed> $sorts
|
||||||
|
*/
|
||||||
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
||||||
{
|
{
|
||||||
$sorts[My::id()] = [
|
$sorts[My::id()] = [
|
||||||
|
|
|
@ -29,10 +29,7 @@ class Frontend extends Process
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
App::frontend()->template()->setPath(
|
App::frontend()->template()->appendPath(Templator::instance()->getPath());
|
||||||
App::frontend()->template()->getPath(),
|
|
||||||
Templator::instance()->getPath()
|
|
||||||
);
|
|
||||||
|
|
||||||
App::behavior()->addBehaviors([
|
App::behavior()->addBehaviors([
|
||||||
'urlHandlerBeforeGetData' => function ($_): void {
|
'urlHandlerBeforeGetData' => function ($_): void {
|
||||||
|
|
|
@ -117,7 +117,7 @@ class Manage extends Process
|
||||||
$v->media->removeItem($file);
|
$v->media->removeItem($file);
|
||||||
App::meta()->delMeta($file, 'template');
|
App::meta()->delMeta($file, 'template');
|
||||||
|
|
||||||
if (!dcCore::app()->error->flag()) {
|
if (!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']);
|
||||||
}
|
}
|
||||||
|
@ -516,10 +516,7 @@ class Manage extends Process
|
||||||
# Get posts
|
# Get posts
|
||||||
try {
|
try {
|
||||||
$posts = App::meta()->getPostsByMeta($params);
|
$posts = App::meta()->getPostsByMeta($params);
|
||||||
if (is_null($posts)) {
|
$counter = App::meta()->getPostsByMeta($params, true)->f(0);
|
||||||
throw new Exception(__('Failed to get posts meta'));
|
|
||||||
}
|
|
||||||
$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) {
|
||||||
|
@ -544,7 +541,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 (!App::error()->flag() && isset($posts)) {
|
if (!App::error()->flag() && isset($posts) && isset($post_list)) {
|
||||||
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 {
|
||||||
|
|
|
@ -21,32 +21,64 @@ use Exception;
|
||||||
*/
|
*/
|
||||||
class ManageVars
|
class ManageVars
|
||||||
{
|
{
|
||||||
/** @var ManageVars $container Self instance */
|
/**
|
||||||
|
* Self instance.
|
||||||
|
*
|
||||||
|
* @var ManageVars $container
|
||||||
|
*/
|
||||||
private static $container;
|
private static $container;
|
||||||
|
|
||||||
/** @var string $name The requested manage part name*/
|
/**
|
||||||
|
* The requested manage part name.
|
||||||
|
*
|
||||||
|
* @var string $name
|
||||||
|
*/
|
||||||
public readonly string $name;
|
public readonly string $name;
|
||||||
|
|
||||||
/** @var string $part The requested manage part */
|
/**
|
||||||
|
* The requested manage part.
|
||||||
|
*
|
||||||
|
* @var string $part
|
||||||
|
*/
|
||||||
public readonly string $part;
|
public readonly string $part;
|
||||||
|
|
||||||
/** @var MediaInterface $media The limited media instance */
|
/**
|
||||||
|
* The limited media instance.
|
||||||
|
*
|
||||||
|
* @var MediaInterface $media
|
||||||
|
*/
|
||||||
public readonly MediaInterface $media;
|
public readonly MediaInterface $media;
|
||||||
|
|
||||||
/** @var array<int,File> $items The media items */
|
/**
|
||||||
|
* The media items.
|
||||||
|
*
|
||||||
|
* @var array<int, File> $items
|
||||||
|
*/
|
||||||
public readonly array $items;
|
public readonly array $items;
|
||||||
|
|
||||||
/** @var array<string,int> $categories The blog categories list */
|
/**
|
||||||
|
* The blog categories list.
|
||||||
|
*
|
||||||
|
* @var array<string, int> $categories
|
||||||
|
*/
|
||||||
public readonly array $categories;
|
public readonly array $categories;
|
||||||
|
|
||||||
/** @var bool $has_categories Blog has categories */
|
/**
|
||||||
|
* Blog has categories.
|
||||||
|
*
|
||||||
|
* @var bool $has_categories
|
||||||
|
*/
|
||||||
public readonly bool $has_categories;
|
public readonly bool $has_categories;
|
||||||
|
|
||||||
/** @var array<string,string> $sources The templates list */
|
/**
|
||||||
|
* The templates list.
|
||||||
|
*
|
||||||
|
* @var array<string, string> $sources
|
||||||
|
*/
|
||||||
public readonly array $sources;
|
public readonly array $sources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructo sets properties.
|
* Constructor sets properties.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -61,8 +93,7 @@ class ManageVars
|
||||||
$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.
|
||||||
App::auth()->sudo($this->media->getDir(...));
|
App::auth()->sudo($this->media->getDir(...));
|
||||||
$dir = $this->media->dir;
|
$this->items = array_values($this->media->getFiles());
|
||||||
$this->items = array_values($dir['files']);
|
|
||||||
|
|
||||||
// categories
|
// categories
|
||||||
$categories_combo = [];
|
$categories_combo = [];
|
||||||
|
@ -70,7 +101,7 @@ class ManageVars
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$categories = 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;
|
$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') : ''];
|
||||||
|
|
||||||
|
@ -91,7 +122,6 @@ class ManageVars
|
||||||
$l = $level;
|
$l = $level;
|
||||||
}
|
}
|
||||||
$has_categories = !$categories->isEmpty();
|
$has_categories = !$categories->isEmpty();
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
$this->categories = $categories_combo;
|
$this->categories = $categories_combo;
|
||||||
|
|
|
@ -27,6 +27,7 @@ class My extends MyPlugin
|
||||||
public static function checkCustomContext(int $context): ?bool
|
public static function checkCustomContext(int $context): ?bool
|
||||||
{
|
{
|
||||||
return match ($context) {
|
return match ($context) {
|
||||||
|
// Add templator perm to backend
|
||||||
self::BACKEND, self::MENU, self::MANAGE => App::task()->checkContext('BACKEND')
|
self::BACKEND, self::MENU, self::MANAGE => App::task()->checkContext('BACKEND')
|
||||||
&& App::auth()->check(App::auth()->makePermissions([
|
&& App::auth()->check(App::auth()->makePermissions([
|
||||||
self::PERMISSION_TEMPLATOR,
|
self::PERMISSION_TEMPLATOR,
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Pager
|
||||||
$params['post_type'] = '';
|
$params['post_type'] = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$counter = 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',
|
||||||
|
|
Loading…
Reference in a new issue