use namespace
This commit is contained in:
parent
e1e6023990
commit
90905e5024
48
src/Backend.php
Normal file
48
src/Backend.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief fac, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis 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\fac;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
|
||||||
|
class Backend extends dcNsProcess
|
||||||
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||||
|
|
||||||
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!static::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->addBehaviors([
|
||||||
|
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
|
||||||
|
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
|
||||||
|
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
|
||||||
|
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
|
||||||
|
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
||||||
|
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
||||||
|
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
|
||||||
|
'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -10,35 +10,47 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @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_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
namespace Dotclear\Plugin\fac;
|
||||||
|
|
||||||
# Admin behaviors
|
use cursor;
|
||||||
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesFormV2']);
|
use ArrayObject;
|
||||||
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']);
|
use dcAuth;
|
||||||
dcCore::app()->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']);
|
use dcCore;
|
||||||
dcCore::app()->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']);
|
use dcPage;
|
||||||
dcCore::app()->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']);
|
use dcPostsActions;
|
||||||
dcCore::app()->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']);
|
use dcRecord;
|
||||||
dcCore::app()->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']);
|
use dcSettings;
|
||||||
dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActions']);
|
use Dotclear\Helper\Html\Html;
|
||||||
|
use Dotclear\Helper\Html\Form\{
|
||||||
|
Checkbox,
|
||||||
|
Div,
|
||||||
|
Form,
|
||||||
|
Hidden,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Note,
|
||||||
|
Para,
|
||||||
|
Select,
|
||||||
|
Submit,
|
||||||
|
Text
|
||||||
|
};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_FAC
|
* @ingroup DC_PLUGIN_FAC
|
||||||
* @brief Linked feed to entries - admin methods.
|
* @brief Linked feed to entries - admin methods.
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
class facAdmin
|
class BackendBehaviors
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get combos of types of supported public pages
|
* Get combos of types of supported public pages
|
||||||
*
|
*
|
||||||
* @return array List of post type and name
|
* @return array List of post type and name
|
||||||
*/
|
*/
|
||||||
public static function getPostsTypes()
|
public static function getPostsTypes(): array
|
||||||
{
|
{
|
||||||
$types = [
|
$types = [
|
||||||
__('home page') => 'default',
|
__('home page') => 'default',
|
||||||
@ -48,8 +60,8 @@ class facAdmin
|
|||||||
__('category pages') => 'category',
|
__('category pages') => 'category',
|
||||||
__('entries feed') => 'feed',
|
__('entries feed') => 'feed',
|
||||||
];
|
];
|
||||||
if (dcCore::app()->plugins->moduleExists('muppet')) {
|
if (dcCore::app()->plugins->moduleExists('muppet') && class_exists('\muppet')) {
|
||||||
foreach (muppet::getPostTypes() as $k => $v) {
|
foreach (\muppet::getPostTypes() as $k => $v) {
|
||||||
$types[sprintf(
|
$types[sprintf(
|
||||||
__('"%s" pages from extension muppet'),
|
__('"%s" pages from extension muppet'),
|
||||||
$v['name']
|
$v['name']
|
||||||
@ -65,8 +77,20 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param dcSettings $blog_settings dcSettings instance
|
* @param dcSettings $blog_settings dcSettings instance
|
||||||
*/
|
*/
|
||||||
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings)
|
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void
|
||||||
{
|
{
|
||||||
|
$lines = '';
|
||||||
|
$fac_public_tpltypes = json_decode($blog_settings->get(My::id())->get('public_tpltypes'), true);
|
||||||
|
if (!is_array($fac_public_tpltypes)) {
|
||||||
|
$fac_public_tpltypes = [];
|
||||||
|
}
|
||||||
|
foreach (self::getPostsTypes() as $k => $v) {
|
||||||
|
$lines .= (new Para())->items([
|
||||||
|
(new Checkbox(['fac_public_tpltypes[]', 'fac_public_tpltypes' . $k], in_array($v, $fac_public_tpltypes)))->value($v),
|
||||||
|
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('fac_public_tpltypes' . $k)->class('classic'),
|
||||||
|
])->render();
|
||||||
|
}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
|
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
|
||||||
'<p class="form-note">' .
|
'<p class="form-note">' .
|
||||||
@ -74,49 +98,40 @@ class facAdmin
|
|||||||
'</p>';
|
'</p>';
|
||||||
if (dcCore::app()->auth->isSuperAdmin()) {
|
if (dcCore::app()->auth->isSuperAdmin()) {
|
||||||
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
|
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
|
||||||
'module' => basename(__DIR__),
|
'module' => My::id(),
|
||||||
'conf' => 1,
|
'conf' => 1,
|
||||||
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
|
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
|
||||||
]) . '">' . __('Configure formats') . '</a></p>';
|
]) . '">' . __('Configure formats') . '</a></p>';
|
||||||
}
|
}
|
||||||
echo
|
|
||||||
'<div class="two-cols">' .
|
|
||||||
'<div class="col">' .
|
|
||||||
'<h5>' . __('Activation') . '</h5>' .
|
|
||||||
'<p><label class="classic">' .
|
|
||||||
form::checkbox('fac_active', '1', (bool) $blog_settings->get(basename(__DIR__))->get('active')) .
|
|
||||||
__('Enable "fac" extension') . '</label></p>' .
|
|
||||||
'<p class="form-note">' .
|
|
||||||
__('You can manage related feed to display for each post with a predefined format.') .
|
|
||||||
'</p>' .
|
|
||||||
'<h5>' . __('Feed') . '</h5>' .
|
|
||||||
'<p><label for="fac_defaultfeedtitle">' . __('Default title') . '</label>' .
|
|
||||||
form::field('fac_defaultfeedtitle', 65, 255, (string) $blog_settings->get(basename(__DIR__))->get('defaultfeedtitle')) . '</p>' .
|
|
||||||
'<p class="form-note">' . __('Use %T to insert title of feed.') . '</p>' .
|
|
||||||
'<p><label class="classic" for="fac_showfeeddesc">' .
|
|
||||||
form::checkbox('fac_showfeeddesc', 1, (bool) $blog_settings->get(basename(__DIR__))->get('showfeeddesc')) .
|
|
||||||
__('Show description of feed') . '</label></p>' .
|
|
||||||
'</div>' .
|
|
||||||
'<div class="col">' .
|
|
||||||
'<h5>' . __('Show feed after content on:') . '</h5>';
|
|
||||||
|
|
||||||
$fac_public_tpltypes = json_decode($blog_settings->get(basename(__DIR__))->get('public_tpltypes'), true);
|
|
||||||
if (!is_array($fac_public_tpltypes)) {
|
|
||||||
$fac_public_tpltypes = [];
|
|
||||||
}
|
|
||||||
foreach (self::getPostsTypes() as $k => $v) {
|
|
||||||
echo '
|
|
||||||
<p><label class="classic" for="fac_public_tpltypes' . $k . '">' .
|
|
||||||
form::checkbox(
|
|
||||||
['fac_public_tpltypes[]', 'fac_public_tpltypes' . $k],
|
|
||||||
$v,
|
|
||||||
in_array($v, $fac_public_tpltypes)
|
|
||||||
) . __($k) . '</label></p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'</div>' .
|
(new Div())->class('two-cols')->items([
|
||||||
'</div>' .
|
(new Div())->class('col')->items([
|
||||||
|
(new Text('h5', Html::escapeHTML(__('Activation')))),
|
||||||
|
// active
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox('fac_active', (bool) $blog_settings->get(My::id())->get('active')))->value(1),
|
||||||
|
(new Label(__('Enable "fac" extension'), Label::OUTSIDE_LABEL_AFTER))->for('fac_active')->class('classic'),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('You can manage related feed to display for each post with a predefined format.'))->class('form-note'),
|
||||||
|
(new Text('h5', Html::escapeHTML(__('Feed')))),
|
||||||
|
// defaultfeedtitle
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Default title')))->for('fac_defaultfeedtitle'),
|
||||||
|
(new Input('fac_defaultfeedtitle'))->size(70)->maxlenght(255)->value((string) $blog_settings->get(My::id())->get('defaultfeedtitle')),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('Use %T to insert title of feed.'))->class('form-note'),
|
||||||
|
// showfeeddesc
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox('fac_showfeeddesc', (bool) $blog_settings->get(My::id())->get('showfeeddesc')))->value(1),
|
||||||
|
(new Label(__('Show description of feed'), Label::OUTSIDE_LABEL_AFTER))->for('fac_showfeeddesc')->class('classic'),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
(new Div())->class('col')->items([
|
||||||
|
(new Text('h5', Html::escapeHTML(__('Show feed after content on:')))),
|
||||||
|
(new Text('', $lines)),
|
||||||
|
]),
|
||||||
|
])->render() .
|
||||||
'<br class="clear" />' .
|
'<br class="clear" />' .
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
@ -126,12 +141,12 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param dcSettings $blog_settings dcSettings instance
|
* @param dcSettings $blog_settings dcSettings instance
|
||||||
*/
|
*/
|
||||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void
|
||||||
{
|
{
|
||||||
$blog_settings->get(basename(__DIR__))->put('active', !empty($_POST['fac_active']));
|
$blog_settings->get(My::id())->put('active', !empty($_POST['fac_active']));
|
||||||
$blog_settings->get(basename(__DIR__))->put('public_tpltypes', json_encode($_POST['fac_public_tpltypes']));
|
$blog_settings->get(My::id())->put('public_tpltypes', json_encode($_POST['fac_public_tpltypes']));
|
||||||
$blog_settings->get(basename(__DIR__))->put('defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']);
|
$blog_settings->get(My::id())->put('defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']);
|
||||||
$blog_settings->get(basename(__DIR__))->put('showfeeddesc', !empty($_POST['fac_showfeeddesc']));
|
$blog_settings->get(My::id())->put('showfeeddesc', !empty($_POST['fac_showfeeddesc']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,9 +154,9 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @return string HTML head
|
* @return string HTML head
|
||||||
*/
|
*/
|
||||||
public static function adminPostHeaders()
|
public static function adminPostHeaders(): string
|
||||||
{
|
{
|
||||||
return dcPage::jsModuleLoad(basename(__DIR__) . '/js/admin.js');
|
return dcPage::jsModuleLoad(My::id() . '/js/backend.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,12 +164,12 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param ArrayObject $main_items Main items
|
* @param ArrayObject $main_items Main items
|
||||||
* @param ArrayObject $sidebar_items Sidebar items
|
* @param ArrayObject $sidebar_items Sidebar items
|
||||||
* @param record $post Post record or null
|
* @param null|dcRecord $post Post record or null
|
||||||
*/
|
*/
|
||||||
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
|
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?dcRecord $post): void
|
||||||
{
|
{
|
||||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) {
|
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get existing linked feed
|
# Get existing linked feed
|
||||||
@ -162,17 +177,17 @@ class facAdmin
|
|||||||
if ($post) {
|
if ($post) {
|
||||||
$rs = dcCore::app()->meta->getMetadata([
|
$rs = dcCore::app()->meta->getMetadata([
|
||||||
'meta_type' => 'fac',
|
'meta_type' => 'fac',
|
||||||
'post_id' => $post->post_id,
|
'post_id' => $post->f('post_id'),
|
||||||
'limit' => 1,
|
'limit' => 1,
|
||||||
]);
|
]);
|
||||||
$fac_url = $rs->isEmpty() ? '' : $rs->meta_id;
|
$fac_url = $rs->isEmpty() ? '' : $rs->f('meta_id');
|
||||||
|
|
||||||
$rs = dcCore::app()->meta->getMetadata([
|
$rs = dcCore::app()->meta->getMetadata([
|
||||||
'meta_type' => 'facformat',
|
'meta_type' => 'facformat',
|
||||||
'post_id' => $post->post_id,
|
'post_id' => $post->f('post_id'),
|
||||||
'limit' => 1,
|
'limit' => 1,
|
||||||
]);
|
]);
|
||||||
$fac_format = $rs->isEmpty() ? '' : $rs->meta_id;
|
$fac_format = $rs->isEmpty() ? '' : $rs->f('meta_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set linked feed form items
|
# Set linked feed form items
|
||||||
@ -185,11 +200,11 @@ class facAdmin
|
|||||||
* @param cursor $cur Current post cursor
|
* @param cursor $cur Current post cursor
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
*/
|
*/
|
||||||
public static function adminAfterPostSave(cursor $cur, $post_id)
|
public static function adminAfterPostSave(cursor $cur, int $post_id): void
|
||||||
{
|
{
|
||||||
if (!isset($_POST['fac_url'])
|
if (!isset($_POST['fac_url'])
|
||||||
|| !isset($_POST['fac_format'])) {
|
|| !isset($_POST['fac_format'])) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete old linked feed
|
# Delete old linked feed
|
||||||
@ -204,7 +219,7 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
*/
|
*/
|
||||||
public static function adminBeforePostDelete($post_id)
|
public static function adminBeforePostDelete(int $post_id): void
|
||||||
{
|
{
|
||||||
self::delFeed($post_id);
|
self::delFeed($post_id);
|
||||||
}
|
}
|
||||||
@ -214,26 +229,26 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param dcPostsActions $pa dcPostsActionsPage instance
|
* @param dcPostsActions $pa dcPostsActionsPage instance
|
||||||
*/
|
*/
|
||||||
public static function adminPostsActions(dcPostsActions $pa)
|
public static function adminPostsActions(dcPostsActions $pa): void
|
||||||
{
|
{
|
||||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) {
|
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pa->addAction(
|
$pa->addAction(
|
||||||
[__('Linked feed') => [__('Add feed') => 'fac_add']],
|
[__('Linked feed') => [__('Add feed') => 'fac_add']],
|
||||||
['facAdmin', 'callbackAdd']
|
[self::class, 'callbackAdd']
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||||
dcAuth::PERMISSION_DELETE,
|
dcAuth::PERMISSION_DELETE,
|
||||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||||
]), dcCore::app()->blog->id)) {
|
]), dcCore::app()->blog->id)) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
$pa->addAction(
|
$pa->addAction(
|
||||||
[__('Linked feed') => [__('Remove feed') => 'fac_remove']],
|
[__('Linked feed') => [__('Remove feed') => 'fac_remove']],
|
||||||
['facAdmin', 'callbackRemove']
|
[self::class, 'callbackRemove']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +258,7 @@ class facAdmin
|
|||||||
* @param dcPostsActions $pa dcPostsActions instance
|
* @param dcPostsActions $pa dcPostsActions instance
|
||||||
* @param ArrayObject $post _POST actions
|
* @param ArrayObject $post _POST actions
|
||||||
*/
|
*/
|
||||||
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post)
|
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void
|
||||||
{
|
{
|
||||||
# No entry
|
# No entry
|
||||||
$posts_ids = $pa->getIDs();
|
$posts_ids = $pa->getIDs();
|
||||||
@ -274,7 +289,7 @@ class facAdmin
|
|||||||
* @param dcPostsActions $pa dcPostsActions instance
|
* @param dcPostsActions $pa dcPostsActions instance
|
||||||
* @param ArrayObject $post _POST actions
|
* @param ArrayObject $post _POST actions
|
||||||
*/
|
*/
|
||||||
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post)
|
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void
|
||||||
{
|
{
|
||||||
# No entry
|
# No entry
|
||||||
$posts_ids = $pa->getIDs();
|
$posts_ids = $pa->getIDs();
|
||||||
@ -297,24 +312,21 @@ class facAdmin
|
|||||||
} else {
|
} else {
|
||||||
$pa->beginPage(
|
$pa->beginPage(
|
||||||
dcPage::breadcrumb([
|
dcPage::breadcrumb([
|
||||||
html::escapeHTML(dcCore::app()->blog->name) => '',
|
Html::escapeHTML(dcCore::app()->blog->name) => '',
|
||||||
$pa->getCallerTitle() => $pa->getRedirection(true),
|
$pa->getCallerTitle() => $pa->getRedirection(true),
|
||||||
__('Linked feed to this selection') => '',
|
__('Linked feed to this selection') => '',
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'<form action="' . $pa->getURI() . '" method="post">' .
|
(new Form('fac_form'))->action($pa->getURI())->method('post')->fields([
|
||||||
$pa->getCheckboxes() .
|
(new Text('', $pa->getCheckboxes() . self::formFeed())),
|
||||||
|
(new Para())->items([
|
||||||
self::formFeed() .
|
(new Text('', dcCore::app()->formNonce() . $pa->getHiddenFields())),
|
||||||
|
(new Hidden(['action'], 'fac_add')),
|
||||||
'<p>' .
|
(new Submit(['save']))->value(__('Save')),
|
||||||
dcCore::app()->formNonce() .
|
]),
|
||||||
$pa->getHiddenFields() .
|
])->render();
|
||||||
form::hidden(['action'], 'fac_add') .
|
|
||||||
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
|
||||||
'</form>';
|
|
||||||
|
|
||||||
$pa->endPage();
|
$pa->endPage();
|
||||||
}
|
}
|
||||||
@ -325,36 +337,29 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param string $url Feed URL
|
* @param string $url Feed URL
|
||||||
* @param string $format Feed format
|
* @param string $format Feed format
|
||||||
* @return null|string Feed form content
|
* @return string Feed form content
|
||||||
*/
|
*/
|
||||||
protected static function formFeed($url = '', $format = '')
|
protected static function formFeed(string $url = '', string $format = ''): string
|
||||||
{
|
{
|
||||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) {
|
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
'<div id="fac">' .
|
(new Div('fac'))->items([
|
||||||
'<h5>' . __('Linked feed') . '</h5>' .
|
(new Text('h5', __('Linked feed'))),
|
||||||
'<p><label for="fac_url">' .
|
// fac_url
|
||||||
__('Feed URL:') . '</label>' .
|
(new Para())->items([
|
||||||
form::field(
|
(new Label(__('Feed URL:')))->for('fac_url')->class('required'),
|
||||||
'fac_url',
|
(new Input('fac_url'))->size(60)->maxlenght(255)->value($url),
|
||||||
60,
|
]),
|
||||||
255,
|
// fac_format
|
||||||
$url,
|
(new Para())->items([
|
||||||
'maximal'
|
(new Label(__('Format:')))->for('fac_format'),
|
||||||
) . '</p>' .
|
(new Select('fac_format'))->default($format)->items(self::comboFac()),
|
||||||
'<p><label for="fac_format">' .
|
]),
|
||||||
__('Format:') . '</label>' .
|
(new Text('', $url ? '<p><a href="' . $url . '" title="' . $url . '">' . __('view feed') . '</a></p>' : '')),
|
||||||
form::combo(
|
])->render();
|
||||||
'fac_format',
|
|
||||||
self::comboFac(),
|
|
||||||
$format,
|
|
||||||
'maximal'
|
|
||||||
) . '</p>' .
|
|
||||||
($url ? '<p><a href="' . $url . '" title="' . $url . '">' . __('view feed') . '</a></p>' : '') .
|
|
||||||
'</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -362,9 +367,9 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @return array List of fac formats
|
* @return array List of fac formats
|
||||||
*/
|
*/
|
||||||
protected static function comboFac()
|
protected static function comboFac(): array
|
||||||
{
|
{
|
||||||
$formats = json_decode(dcCore::app()->blog->settings->get(basename(__DIR__))->get('formats'), true);
|
$formats = json_decode(dcCore::app()->blog->settings->get(My::id())->get('formats'), true);
|
||||||
if (!is_array($formats) || empty($formats)) {
|
if (!is_array($formats) || empty($formats)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -382,7 +387,7 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
*/
|
*/
|
||||||
protected static function delFeed($post_id)
|
protected static function delFeed(int $post_id): void
|
||||||
{
|
{
|
||||||
$post_id = (int) $post_id;
|
$post_id = (int) $post_id;
|
||||||
dcCore::app()->meta->delPostMeta($post_id, 'fac');
|
dcCore::app()->meta->delPostMeta($post_id, 'fac');
|
||||||
@ -395,11 +400,11 @@ class facAdmin
|
|||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
* @param array|ArrayObject $options Feed options
|
* @param array|ArrayObject $options Feed options
|
||||||
*/
|
*/
|
||||||
protected static function addFeed($post_id, $options)
|
protected static function addFeed(int $post_id, array|ArrayObject $options): void
|
||||||
{
|
{
|
||||||
if (empty($options['fac_url'])
|
if (empty($options['fac_url'])
|
||||||
|| empty($options['fac_format'])) {
|
|| empty($options['fac_format'])) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_id = (int) $post_id;
|
$post_id = (int) $post_id;
|
||||||
|
732
src/Config.php
732
src/Config.php
@ -10,496 +10,298 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @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_CONTEXT_MODULE')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dcCore::app()->auth->isSuperAdmin()) {
|
namespace Dotclear\Plugin\fac;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$redir = empty($_REQUEST['redir']) ?
|
use dcCore;
|
||||||
dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
|
use dcPage;
|
||||||
|
use dcNsProcess;
|
||||||
|
use Dotclear\Helper\Html\Html;
|
||||||
|
use Dotclear\Helper\Html\Form\{
|
||||||
|
Checkbox,
|
||||||
|
Div,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Note,
|
||||||
|
Number,
|
||||||
|
Para,
|
||||||
|
Text
|
||||||
|
};
|
||||||
|
use Exception;
|
||||||
|
|
||||||
# -- Get settings --
|
class Config extends dcNsProcess
|
||||||
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init == defined('DC_CONTEXT_ADMIN')
|
||||||
|
&& dcCore::app()->auth?->isSuperAdmin();
|
||||||
|
|
||||||
$fac_formats = json_decode($s->get('formats'), true);
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($fac_formats)) {
|
public static function process(): bool
|
||||||
$fac_formats = [];
|
{
|
||||||
}
|
if (!static::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
# -- Set settings --
|
$redir = empty($_REQUEST['redir']) ?
|
||||||
if (!empty($_POST['save'])) {
|
dcCore::app()->admin->__get('list')->getURL() . '#plugins' : $_REQUEST['redir'];
|
||||||
try {
|
|
||||||
$fac_formats = [];
|
|
||||||
|
|
||||||
foreach ($_POST['fac_formats'] as $uid => $f) {
|
# -- Get settings --
|
||||||
if (!empty($f['name'])) {
|
$s = dcCore::app()->blog->settings->get(My::id());
|
||||||
$fac_formats[$uid] = $f;
|
|
||||||
|
$fac_formats = json_decode($s->get('formats'), true);
|
||||||
|
|
||||||
|
if (!is_array($fac_formats)) {
|
||||||
|
$fac_formats = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
# -- Set settings --
|
||||||
|
if (!empty($_POST['save'])) {
|
||||||
|
try {
|
||||||
|
$fac_formats = [];
|
||||||
|
|
||||||
|
foreach ($_POST['fac_formats'] as $uid => $f) {
|
||||||
|
if (!empty($f['name'])) {
|
||||||
|
$fac_formats[$uid] = $f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix 2021.08.21 : formats are now global
|
||||||
|
$s->drop('formats');
|
||||||
|
$s->put(
|
||||||
|
'formats',
|
||||||
|
json_encode($fac_formats),
|
||||||
|
'string',
|
||||||
|
'Formats of feeds contents',
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
dcCore::app()->blog->triggerBlog();
|
||||||
|
|
||||||
|
dcPage::addSuccessNotice(
|
||||||
|
__('Configuration successfully updated.')
|
||||||
|
);
|
||||||
|
dcCore::app()->adminurl?->redirect(
|
||||||
|
'admin.plugins',
|
||||||
|
['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix 2021.08.21 : formats are now global
|
return true;
|
||||||
$s->drop('formats');
|
|
||||||
$s->put(
|
|
||||||
'formats',
|
|
||||||
json_encode($fac_formats),
|
|
||||||
'string',
|
|
||||||
'Formats of feeds contents',
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
dcCore::app()->blog->triggerBlog();
|
|
||||||
|
|
||||||
dcAdminNotices::addSuccessNotice(
|
|
||||||
__('Configuration successfully updated.')
|
|
||||||
);
|
|
||||||
http::redirect(
|
|
||||||
dcCore::app()->admin->list->getURL('module=' . basename(__DIR__) . '&conf=1&redir=' . dcCore::app()->admin->list->getRedir())
|
|
||||||
);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# -- Display form --
|
|
||||||
|
|
||||||
$i = 1;
|
|
||||||
foreach ($fac_formats as $uid => $f) {
|
|
||||||
if (empty($f['name'])) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
public static function render(): void
|
||||||
<div class="fieldset">
|
{
|
||||||
<h4>' . sprintf(__('Format %s'), $i) . '</h4>
|
if (!static::$init) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$s = dcCore::app()->blog->settings->get(My::id());
|
||||||
|
|
||||||
<div class="two-boxes"><h5>' . __('General') . '</h5>
|
$fac_formats = json_decode($s->get('formats'), true);
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_name">' .
|
$i = 1;
|
||||||
__('Name:') . '</label>' .
|
foreach ($fac_formats as $uid => $format) {
|
||||||
form::field(
|
if (empty($format['name'])) {
|
||||||
[
|
continue;
|
||||||
'fac_formats[' . $uid . '][name]',
|
}
|
||||||
'fac_formats_' . $uid . '_name',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
empty($f['name']) ? '' : $f['name'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('In order to remove a format, leave its name empty.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_dateformat">' .
|
self::displayFacFormat(sprintf(__('Format %s'), $i), $uid, $format);
|
||||||
__('Date format:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][dateformat]',
|
|
||||||
'fac_formats_' . $uid . '_dateformat',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
empty($f['dateformat']) ? '' : $f['dateformat'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Use date format of Dotclear or leave empty to use default date format of blog.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_lineslimit">' .
|
$i++;
|
||||||
__('Entries limit:') . '</label>' .
|
}
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][lineslimit]',
|
|
||||||
'fac_formats_' . $uid . '_lineslimit',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
empty($f['lineslimit']) ? '' : $f['lineslimit'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Title') . '</h5>
|
$new_format = [
|
||||||
|
'name' => '',
|
||||||
|
'dateformat' => '',
|
||||||
|
'lineslimit' => '5',
|
||||||
|
'linestitletext' => '%T',
|
||||||
|
'linestitleover' => '%D',
|
||||||
|
'linestitlelength' => '150',
|
||||||
|
'showlinesdescription' => '0',
|
||||||
|
'linesdescriptionlength' => '350',
|
||||||
|
'linesdescriptionnohtml' => '1',
|
||||||
|
'showlinescontent' => '0',
|
||||||
|
'linescontentlength' => '350',
|
||||||
|
'linescontentnohtml' => '1',
|
||||||
|
];
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitletext">' .
|
self::displayFacFormat(__('New format'), uniqid(), $new_format);
|
||||||
__('Title format:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitletext]',
|
|
||||||
'fac_formats_' . $uid . '_linestitletext',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
empty($f['linestitletext']) ? '' : $f['linestitletext'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Format can be:') .
|
|
||||||
'%D : ' . __('Date') .
|
|
||||||
', %T : ' . __('Title') .
|
|
||||||
', %A : ' . __('Author') .
|
|
||||||
', %E : ' . __('Description') .
|
|
||||||
', %C : ' . __('Content') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitleover">' .
|
echo '
|
||||||
__('Over title format:') . '</label>' .
|
<div class="fieldset">
|
||||||
form::field(
|
<h4>' . __('Informations') . '</h4>
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitleover]',
|
|
||||||
'fac_formats_' . $uid . '_linestitleover',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
empty($f['linestitleover']) ? '' : $f['linestitleover'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Format can be:') .
|
|
||||||
'%D : ' . __('Date') .
|
|
||||||
', %T : ' . __('Title') .
|
|
||||||
', %A : ' . __('Author') .
|
|
||||||
', %E : ' . __('Description') .
|
|
||||||
', %C : ' . __('Content') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitlelength">' .
|
<div class="two-boxes">
|
||||||
__('Maximum length of title:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitlelength]',
|
|
||||||
'fac_formats_' . $uid . '_linestitlelength',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
empty($f['linestitlelength']) ? '' : $f['linestitlelength'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Description') . '</h5>
|
<h5>' . __('Theme') . '</h5>
|
||||||
|
<p>' .
|
||||||
|
__('Theme must have behavoir publicEntryAfterContent.') . ' ' .
|
||||||
|
__('To add feed to an entry edit this entry and put in sidebar the url of the feed and select a format.') .
|
||||||
|
'</p>
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_showlinesdescription">' .
|
</div><div class="two-boxes">
|
||||||
form::checkbox(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][showlinesdescription]',
|
|
||||||
'fac_formats_' . $uid . '_showlinesdescription',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
!empty($f['showlinesdescription'])
|
|
||||||
) .
|
|
||||||
__('Show description of entries') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linesdescriptionnohtml">' .
|
<h5>' . __('Structure') . '</h5>
|
||||||
form::checkbox(
|
<pre>' . Html::escapeHTML('
|
||||||
[
|
<div class="post-fac">
|
||||||
'fac_formats[' . $uid . '][linesdescriptionnohtml]',
|
<h3>' . __('Title of feed') . '</h3>
|
||||||
'fac_formats_' . $uid . '_linesdescriptionnohtml',
|
<p>' . __('Description of feed') . '</p>
|
||||||
],
|
<dl>
|
||||||
1,
|
<dt>' . __('Title of entry') . '</dt>
|
||||||
!empty($f['linesdescriptionnohtml'])
|
<dd>' . __('Description of entry') . '</dd>
|
||||||
) .
|
</dl>
|
||||||
__('Remove html of description') . '</label></p>
|
</div>
|
||||||
|
') . '</pre>
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linesdescriptionlength">' .
|
</div>
|
||||||
__('Maximum length of description:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linesdescriptionlength]',
|
|
||||||
'fac_formats_' . $uid . '_linesdescriptionlength',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
empty($f['linesdescriptionlength']) ? '' : $f['linesdescriptionlength'],
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Content') . '</h5>
|
</div>';
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_showlinescontent">' .
|
dcPage::helpBlock('fac');
|
||||||
form::checkbox(
|
}
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][showlinescontent]',
|
|
||||||
'fac_formats_' . $uid . '_showlinescontent',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
!empty($f['showlinescontent'])
|
|
||||||
) .
|
|
||||||
__('Show content of entries') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linescontentnohtml">' .
|
private static function displayFacFormat(string $title, string $uid, array $format): void
|
||||||
form::checkbox(
|
{
|
||||||
[
|
echo
|
||||||
'fac_formats[' . $uid . '][linescontentnohtml]',
|
(new Div())->class('fieldset')->separator('')->items([
|
||||||
'fac_formats_' . $uid . '_linescontentnohtml',
|
(new Text('h4', $title)),
|
||||||
],
|
(new Div())->class('two-boxes even')->items([
|
||||||
1,
|
(new Text('h5', __('General'))),
|
||||||
!empty($f['linescontentnohtml'])
|
// name
|
||||||
) .
|
(new Para())->items([
|
||||||
__('Remove html of content') . '</label></p>
|
(new Label(__('Name:')))->for('fac_formats_' . $uid . '_name'),
|
||||||
|
(new Input([
|
||||||
<p><label for="fac_formats_' . $uid . '_linescontentlength">' .
|
'fac_formats[' . $uid . '][name]',
|
||||||
__('Maximum length of content:') . '</label>' .
|
'fac_formats_' . $uid . '_name',
|
||||||
form::field(
|
]))->value(empty($format['name']) ? '' : $format['name'])->size(20)->maxlenght(255)->class('maximal'),
|
||||||
[
|
]),
|
||||||
'fac_formats[' . $uid . '][linescontentlength]',
|
(new Note())->text(__('In order to remove a format, leave its name empty.'))->class('form-note'),
|
||||||
'fac_formats_' . $uid . '_linescontentlength',
|
// dateformat
|
||||||
],
|
(new Para())->items([
|
||||||
5,
|
(new Label(__('Date format:')))->for('fac_formats_' . $uid . '_dateformat'),
|
||||||
4,
|
(new Input([
|
||||||
empty($f['linescontentlength']) ? '' : $f['linescontentlength'],
|
'fac_formats[' . $uid . '][dateformat]',
|
||||||
'maximal'
|
'fac_formats_' . $uid . '_dateformat',
|
||||||
) . '</p>
|
]))->value(empty($format['dateformat']) ? '' : $format['dateformat'])->size(20)->maxlenght(255)->class('maximal'),
|
||||||
<p class="form-note">' .
|
]),
|
||||||
__('Leave lengh empty for no limit.') .
|
(new Note())->text(__('Use date format of Dotclear or leave empty to use default date format of blog.'))->class('form-note'),
|
||||||
'</p>
|
// dateformat //todo: use Number
|
||||||
|
(new Para())->items([
|
||||||
</div>
|
(new Label(__('Entries limit:')))->for('fac_formats_' . $uid . '_lineslimit'),
|
||||||
|
(new Input([
|
||||||
</div>';
|
'fac_formats[' . $uid . '][lineslimit]',
|
||||||
|
'fac_formats_' . $uid . '_lineslimit',
|
||||||
$i++;
|
]))->value(empty($format['lineslimit']) ? '' : $format['lineslimit'])->size(4)->maxlenght(5),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('Leave lengh empty for no limit.'))->class('form-note'),
|
||||||
|
]),
|
||||||
|
(new Div())->class('two-boxes odd')->items([
|
||||||
|
(new Text('h5', __('Title'))),
|
||||||
|
// linestitletext
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Title format:')))->for('fac_formats_' . $uid . '_linestitletext'),
|
||||||
|
(new Input([
|
||||||
|
'fac_formats[' . $uid . '][linestitletext]',
|
||||||
|
'fac_formats_' . $uid . '_linestitletext',
|
||||||
|
]))->value(empty($format['linestitletext']) ? '' : $format['linestitletext'])->size(20)->maxlenght(255)->class('maximal'),
|
||||||
|
]),
|
||||||
|
(new Note())->text(
|
||||||
|
__('Format can be:') .
|
||||||
|
'%D : ' . __('Date') .
|
||||||
|
', %T : ' . __('Title') .
|
||||||
|
', %A : ' . __('Author') .
|
||||||
|
', %E : ' . __('Description') .
|
||||||
|
', %C : ' . __('Content')
|
||||||
|
)->class('form-note'),
|
||||||
|
// linestitleover
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Over title format:')))->for('fac_formats_' . $uid . '_linestitleover'),
|
||||||
|
(new Input([
|
||||||
|
'fac_formats[' . $uid . '][linestitleover]',
|
||||||
|
'fac_formats_' . $uid . '_linestitleover',
|
||||||
|
]))->value(empty($format['linestitleover']) ? '' : $format['linestitleover'])->size(20)->maxlenght(255)->class('maximal'),
|
||||||
|
]),
|
||||||
|
(new Note())->text(
|
||||||
|
__('Format can be:') .
|
||||||
|
'%D : ' . __('Date') .
|
||||||
|
', %T : ' . __('Title') .
|
||||||
|
', %A : ' . __('Author') .
|
||||||
|
', %E : ' . __('Description') .
|
||||||
|
', %C : ' . __('Content')
|
||||||
|
)->class('form-note'),
|
||||||
|
// linestitlelength //todo: use Number
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Maximum length of title:')))->for('fac_formats_' . $uid . '_linestitlelength'),
|
||||||
|
(new Input([
|
||||||
|
'fac_formats[' . $uid . '][linestitlelength]',
|
||||||
|
'fac_formats_' . $uid . '_linestitlelength',
|
||||||
|
]))->value(empty($format['linestitlelength']) ? '' : $format['linestitlelength'])->size(4)->maxlenght(5),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('Leave lengh empty for no limit.'))->class('form-note'),
|
||||||
|
]),
|
||||||
|
(new Div())->class('two-boxes even')->items([
|
||||||
|
(new Text('h5', __('Description'))),
|
||||||
|
// showlinesdescription
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox([
|
||||||
|
'fac_formats[' . $uid . '][showlinesdescription]',
|
||||||
|
'fac_formats_' . $uid . '_showlinesdescription',
|
||||||
|
], !empty($format['showlinesdescription'])))->value(1),
|
||||||
|
(new Label(__('Show description of entries'), Label::OUTSIDE_LABEL_AFTER))->for('fac_formats_' . $uid . '_showlinesdescription')->class('classic'),
|
||||||
|
]),
|
||||||
|
// linesdescriptionnohtml
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox([
|
||||||
|
'fac_formats[' . $uid . '][linesdescriptionnohtml]',
|
||||||
|
'fac_formats_' . $uid . '_linesdescriptionnohtml',
|
||||||
|
], !empty($format['linesdescriptionnohtml'])))->value(1),
|
||||||
|
(new Label(__('Remove html of description'), Label::OUTSIDE_LABEL_AFTER))->for('fac_formats_' . $uid . '_linesdescriptionnohtml')->class('classic'),
|
||||||
|
]),
|
||||||
|
// linesdescriptionlength //todo: use Number
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Maximum length of description:')))->for('fac_formats_' . $uid . '_linesdescriptionlength'),
|
||||||
|
(new Input([
|
||||||
|
'fac_formats[' . $uid . '][linesdescriptionlength]',
|
||||||
|
'fac_formats_' . $uid . '_linesdescriptionlength',
|
||||||
|
]))->value(empty($format['linesdescriptionlength']) ? '' : $format['linesdescriptionlength'])->size(4)->maxlenght(5),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('Leave lengh empty for no limit.'))->class('form-note'),
|
||||||
|
]),
|
||||||
|
(new Div())->class('two-boxes odd')->items([
|
||||||
|
(new Text('h5', __('Content'))),
|
||||||
|
// showlinescontent
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox([
|
||||||
|
'fac_formats[' . $uid . '][showlinescontent]',
|
||||||
|
'fac_formats_' . $uid . '_showlinescontent',
|
||||||
|
], !empty($format['showlinescontent'])))->value(1),
|
||||||
|
(new Label(__('Show content of entries'), Label::OUTSIDE_LABEL_AFTER))->for('fac_formats_' . $uid . '_showlinescontent')->class('classic'),
|
||||||
|
]),
|
||||||
|
// linescontentnohtml
|
||||||
|
(new Para())->items([
|
||||||
|
(new Checkbox([
|
||||||
|
'fac_formats[' . $uid . '][linescontentnohtml]',
|
||||||
|
'fac_formats_' . $uid . '_linescontentnohtml',
|
||||||
|
], !empty($format['linescontentnohtml'])))->value(1),
|
||||||
|
(new Label(__('Remove html of content'), Label::OUTSIDE_LABEL_AFTER))->for('fac_formats_' . $uid . '_linescontentnohtml')->class('classic'),
|
||||||
|
]),
|
||||||
|
// linescontentlength //todo: use Number
|
||||||
|
(new Para())->items([
|
||||||
|
(new Label(__('Maximum length of content:')))->for('fac_formats_' . $uid . '_linescontentlength'),
|
||||||
|
(new Input([
|
||||||
|
'fac_formats[' . $uid . '][linescontentlength]',
|
||||||
|
'fac_formats_' . $uid . '_linescontentlength',
|
||||||
|
]))->value(empty($format['linescontentlength']) ? '' : $format['linescontentlength'])->size(4)->maxlenght(5),
|
||||||
|
]),
|
||||||
|
(new Note())->text(__('Leave lengh empty for no limit.'))->class('form-note'),
|
||||||
|
]),
|
||||||
|
])->render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = uniqid();
|
|
||||||
echo '
|
|
||||||
<div class="fieldset">
|
|
||||||
<h4>' . __('New format') . '</h4>
|
|
||||||
|
|
||||||
<div class="two-boxes"><h5>' . __('General') . '</h5>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_name">' .
|
|
||||||
__('Name:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][name]',
|
|
||||||
'fac_formats_' . $uid . '_name',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
'',
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('In order to remove a format, leave its name empty.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_dateformat">' .
|
|
||||||
__('Date format:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][dateformat]',
|
|
||||||
'fac_formats_' . $uid . '_dateformat',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
'',
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Use date format of Dotclear or leave empty to use default date format of blog.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_lineslimit">' .
|
|
||||||
__('Entries limit:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][lineslimit]',
|
|
||||||
'fac_formats_' . $uid . '_lineslimit',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Title') . '</h5>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitletext">' .
|
|
||||||
__('Title format:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitletext]',
|
|
||||||
'fac_formats_' . $uid . '_linestitletext',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
'%T',
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Format can be:') .
|
|
||||||
'%D : ' . __('Date') .
|
|
||||||
', %T : ' . __('Title') .
|
|
||||||
', %A : ' . __('Author') .
|
|
||||||
', %E : ' . __('Description') .
|
|
||||||
', %C : ' . __('Content') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitleover">' .
|
|
||||||
__('Over title format:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitleover]',
|
|
||||||
'fac_formats_' . $uid . '_linestitleover',
|
|
||||||
],
|
|
||||||
20,
|
|
||||||
255,
|
|
||||||
'%D',
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Format can be:') .
|
|
||||||
'%D : ' . __('Date') .
|
|
||||||
', %T : ' . __('Title') .
|
|
||||||
', %A : ' . __('Author') .
|
|
||||||
', %E : ' . __('Description') .
|
|
||||||
', %C : ' . __('Content') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linestitlelength">' .
|
|
||||||
__('Maximum length of title:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linestitlelength]',
|
|
||||||
'fac_formats_' . $uid . '_linestitlelength',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
150,
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Description') . '</h5>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_showlinesdescription">' .
|
|
||||||
form::checkbox(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][showlinesdescription]',
|
|
||||||
'fac_formats_' . $uid . '_showlinesdescription',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
0
|
|
||||||
) .
|
|
||||||
__('Show description of entries') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linesdescriptionnohtml">' .
|
|
||||||
form::checkbox(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linesdescriptionnohtml]',
|
|
||||||
'fac_formats_' . $uid . '_linesdescriptionnohtml',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
) .
|
|
||||||
__('Remove html of description') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linesdescriptionlength">' .
|
|
||||||
__('Maximum length of description:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linesdescriptionlength]',
|
|
||||||
'fac_formats_' . $uid . '_linesdescriptionlength',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
350,
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes"><h5>' . __('Content') . '</h5>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_showlinescontent">' .
|
|
||||||
form::checkbox(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][showlinescontent]',
|
|
||||||
'fac_formats_' . $uid . '_showlinescontent',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
0
|
|
||||||
) .
|
|
||||||
__('Show content of entries') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linescontentnohtml">' .
|
|
||||||
form::checkbox(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linescontentnohtml]',
|
|
||||||
'fac_formats_' . $uid . '_linescontentnohtml',
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
) .
|
|
||||||
__('Remove html of content') . '</label></p>
|
|
||||||
|
|
||||||
<p><label for="fac_formats_' . $uid . '_linescontentlength">' .
|
|
||||||
__('Maximum length of content:') . '</label>' .
|
|
||||||
form::field(
|
|
||||||
[
|
|
||||||
'fac_formats[' . $uid . '][linescontentlength]',
|
|
||||||
'fac_formats_' . $uid . '_linescontentlength',
|
|
||||||
],
|
|
||||||
5,
|
|
||||||
4,
|
|
||||||
350,
|
|
||||||
'maximal'
|
|
||||||
) . '</p>
|
|
||||||
<p class="form-note">' .
|
|
||||||
__('Leave lengh empty for no limit.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fieldset">
|
|
||||||
<h4>' . __('Informations') . '</h4>
|
|
||||||
|
|
||||||
<div class="two-boxes">
|
|
||||||
|
|
||||||
<h5>' . __('Theme') . '</h5>
|
|
||||||
<p>' .
|
|
||||||
__('Theme must have behavoir publicEntryAfterContent.') . ' ' .
|
|
||||||
__('To add feed to an entry edit this entry and put in sidebar the url of the feed and select a format.') .
|
|
||||||
'</p>
|
|
||||||
|
|
||||||
</div><div class="two-boxes">
|
|
||||||
|
|
||||||
<h5>' . __('Structure') . '</h5>
|
|
||||||
<pre>' . html::escapeHTML('
|
|
||||||
<div class="post-fac">
|
|
||||||
<h3>' . __('Title of feed') . '</h3>
|
|
||||||
<p>' . __('Description of feed') . '</p>
|
|
||||||
<dl>
|
|
||||||
<dt>' . __('Title of entry') . '</dt>
|
|
||||||
<dd>' . __('Description of entry') . '</dd>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
') . '</pre>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
dcPage::helpBlock('fac');
|
|
||||||
|
436
src/Frontend.php
436
src/Frontend.php
@ -10,210 +10,234 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @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;
|
|
||||||
|
namespace Dotclear\Plugin\fac;
|
||||||
|
|
||||||
|
use context;
|
||||||
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
use Dotclear\Helper\Html\Html;
|
||||||
|
use Exception;
|
||||||
|
use dt;
|
||||||
|
use feedReader;
|
||||||
|
|
||||||
|
class Frontend extends dcNsProcess
|
||||||
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init = defined('DC_RC_PATH');
|
||||||
|
|
||||||
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!static::$init || !dcCore::app()->blog->settings->get(My::id())->get('active')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, context $_ctx): void {
|
||||||
|
# Not a post
|
||||||
|
if (!dcCore::app()->ctx->exists('posts')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Not in page to show
|
||||||
|
$types = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get('public_tpltypes'), true);
|
||||||
|
if (!is_array($types)
|
||||||
|
|| !in_array(dcCore::app()->url->type, $types)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get related feed
|
||||||
|
$fac_url = dcCore::app()->meta->getMetadata([
|
||||||
|
'meta_type' => 'fac',
|
||||||
|
'post_id' => dcCore::app()->ctx->__get('posts')->f('post_id'),
|
||||||
|
'limit' => 1,
|
||||||
|
]);
|
||||||
|
if ($fac_url->isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get related format
|
||||||
|
$fac_format = dcCore::app()->meta->getMetadata([
|
||||||
|
'meta_type' => 'facformat',
|
||||||
|
'post_id' => dcCore::app()->ctx->__get('posts')->f('post_id'),
|
||||||
|
'limit' => 1,
|
||||||
|
]);
|
||||||
|
if ($fac_format->isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get format info
|
||||||
|
$default_format = [
|
||||||
|
'name' => 'default',
|
||||||
|
'dateformat' => '',
|
||||||
|
'lineslimit' => '5',
|
||||||
|
'linestitletext' => '%T',
|
||||||
|
'linestitleover' => '%D',
|
||||||
|
'linestitlelength' => '150',
|
||||||
|
'showlinesdescription' => '0',
|
||||||
|
'linesdescriptionlength' => '350',
|
||||||
|
'linesdescriptionnohtml' => '1',
|
||||||
|
'showlinescontent' => '0',
|
||||||
|
'linescontentlength' => '350',
|
||||||
|
'linescontentnohtml' => '1',
|
||||||
|
];
|
||||||
|
|
||||||
|
$formats = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get('formats'), true);
|
||||||
|
if (empty($formats)
|
||||||
|
|| !is_array($formats)
|
||||||
|
|| !isset($formats[$fac_format->f('meta_id')])) {
|
||||||
|
$format = $default_format;
|
||||||
|
} else {
|
||||||
|
$format = array_merge(
|
||||||
|
$default_format,
|
||||||
|
$formats[$fac_format->f('meta_id')]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Read feed url
|
||||||
|
$cache = is_dir(DC_TPL_CACHE . '/fac') ? DC_TPL_CACHE . '/fac' : null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$feed = feedReader::quickParse($fac_url->f('meta_id'), $cache);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$feed = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
# No entries
|
||||||
|
if (!$feed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Feed title
|
||||||
|
$feedtitle = '';
|
||||||
|
if ('' != dcCore::app()->blog->settings->get(My::id())->get('defaultfeedtitle')) {
|
||||||
|
$feedtitle = '<h3>' . Html::escapeHTML(
|
||||||
|
empty($feed->title) ?
|
||||||
|
str_replace(
|
||||||
|
'%T',
|
||||||
|
__('a related feed'),
|
||||||
|
dcCore::app()->blog->settings->get(My::id())->get('defaultfeedtitle')
|
||||||
|
) :
|
||||||
|
str_replace(
|
||||||
|
'%T',
|
||||||
|
$feed->title,
|
||||||
|
dcCore::app()->blog->settings->get(My::id())->get('defaultfeedtitle')
|
||||||
|
)
|
||||||
|
) . '</h3>';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Feed desc
|
||||||
|
$feeddesc = '';
|
||||||
|
if (dcCore::app()->blog->settings->get(My::id())->get('showfeeddesc')
|
||||||
|
&& '' != $feed->description) {
|
||||||
|
$feeddesc = '<p>' . context::global_filters(
|
||||||
|
$feed->description,
|
||||||
|
['encode_xml', 'remove_html']
|
||||||
|
) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Date format
|
||||||
|
$dateformat = '' != $format['dateformat'] ?
|
||||||
|
$format['dateformat'] :
|
||||||
|
dcCore::app()->blog->settings->get('system')->get('date_format') . ',' . dcCore::app()->blog->settings->get('system')->get('time_format');
|
||||||
|
|
||||||
|
# Enrties limit
|
||||||
|
$entrieslimit = abs((int) $format['lineslimit']);
|
||||||
|
$uselimit = $entrieslimit > 0 ? true : false;
|
||||||
|
|
||||||
|
echo
|
||||||
|
'<div class="post-fac">' .
|
||||||
|
$feedtitle . $feeddesc .
|
||||||
|
'<dl>';
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
foreach ($feed->items as $item) {
|
||||||
|
# Format date
|
||||||
|
$date = dt::dt2str($dateformat, $item->pubdate);
|
||||||
|
|
||||||
|
# Entries title
|
||||||
|
$title = context::global_filters(
|
||||||
|
str_replace(
|
||||||
|
[
|
||||||
|
'%D',
|
||||||
|
'%T',
|
||||||
|
'%A',
|
||||||
|
'%E',
|
||||||
|
'%C',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
$date,
|
||||||
|
$item->title,
|
||||||
|
$item->creator,
|
||||||
|
$item->description,
|
||||||
|
$item->content,
|
||||||
|
],
|
||||||
|
$format['linestitletext']
|
||||||
|
),
|
||||||
|
['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])],
|
||||||
|
);
|
||||||
|
|
||||||
|
# Entries over title
|
||||||
|
$overtitle = context::global_filters(
|
||||||
|
str_replace(
|
||||||
|
[
|
||||||
|
'%D',
|
||||||
|
'%T',
|
||||||
|
'%A',
|
||||||
|
'%E',
|
||||||
|
'%C',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
$date,
|
||||||
|
$item->title,
|
||||||
|
$item->creator,
|
||||||
|
$item->description,
|
||||||
|
$item->content,
|
||||||
|
],
|
||||||
|
$format['linestitleover']
|
||||||
|
),
|
||||||
|
['remove_html', 'cut_string' => 350],
|
||||||
|
);
|
||||||
|
|
||||||
|
# Entries description
|
||||||
|
$description = '';
|
||||||
|
if ($format['showlinesdescription']
|
||||||
|
&& '' != $item->description) {
|
||||||
|
$description = '<dd>' .
|
||||||
|
context::global_filters(
|
||||||
|
$item->description,
|
||||||
|
['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])]
|
||||||
|
) . '</dd>';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Entries content
|
||||||
|
$content = '';
|
||||||
|
if ($format['showlinescontent']
|
||||||
|
&& '' != $item->content) {
|
||||||
|
$content = '<dd>' .
|
||||||
|
context::global_filters(
|
||||||
|
$item->content,
|
||||||
|
['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])]
|
||||||
|
) . '</dd>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
'<dt><a href="' . $item->link . '" ' .
|
||||||
|
'title="' . $overtitle . '">' . $title . '</a></dt>' .
|
||||||
|
$description . $content;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
if ($uselimit && $i == $entrieslimit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo '</dl></div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, context $_ctx) {
|
|
||||||
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
|
||||||
|
|
||||||
# Not active or not a post
|
|
||||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')
|
|
||||||
|| !dcCore::app()->ctx->exists('posts')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Not in page to show
|
|
||||||
$types = json_decode((string) dcCore::app()->blog->settings->get(basename(__DIR__))->get('public_tpltypes'), true);
|
|
||||||
if (!is_array($types)
|
|
||||||
|| !in_array(dcCore::app()->url->type, $types)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get related feed
|
|
||||||
$fac_url = dcCore::app()->meta->getMetadata([
|
|
||||||
'meta_type' => 'fac',
|
|
||||||
'post_id' => dcCore::app()->ctx->posts->post_id,
|
|
||||||
'limit' => 1,
|
|
||||||
]);
|
|
||||||
if ($fac_url->isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get related format
|
|
||||||
$fac_format = dcCore::app()->meta->getMetadata([
|
|
||||||
'meta_type' => 'facformat',
|
|
||||||
'post_id' => dcCore::app()->ctx->posts->post_id,
|
|
||||||
'limit' => 1,
|
|
||||||
]);
|
|
||||||
if ($fac_format->isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get format info
|
|
||||||
$default_format = [
|
|
||||||
'name' => 'default',
|
|
||||||
'dateformat' => '',
|
|
||||||
'lineslimit' => '5',
|
|
||||||
'linestitletext' => '%T',
|
|
||||||
'linestitleover' => '%D',
|
|
||||||
'linestitlelength' => '150',
|
|
||||||
'showlinesdescription' => '0',
|
|
||||||
'linesdescriptionlength' => '350',
|
|
||||||
'linesdescriptionnohtml' => '1',
|
|
||||||
'showlinescontent' => '0',
|
|
||||||
'linescontentlength' => '350',
|
|
||||||
'linescontentnohtml' => '1',
|
|
||||||
];
|
|
||||||
|
|
||||||
$formats = json_decode((string) dcCore::app()->blog->settings->get(basename(__DIR__))->get('formats'), true);
|
|
||||||
if (empty($formats)
|
|
||||||
|| !is_array($formats)
|
|
||||||
|| !isset($formats[$fac_format->meta_id])) {
|
|
||||||
$format = $default_format;
|
|
||||||
} else {
|
|
||||||
$format = array_merge(
|
|
||||||
$default_format,
|
|
||||||
$formats[$fac_format->meta_id]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read feed url
|
|
||||||
$cache = is_dir(DC_TPL_CACHE . '/fac') ? DC_TPL_CACHE . '/fac' : null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$feed = feedReader::quickParse($fac_url->meta_id, $cache);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$feed = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# No entries
|
|
||||||
if (!$feed) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Feed title
|
|
||||||
$feedtitle = '';
|
|
||||||
if ('' != dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')) {
|
|
||||||
$feedtitle = '<h3>' . html::escapeHTML(
|
|
||||||
empty($feed->title) ?
|
|
||||||
str_replace(
|
|
||||||
'%T',
|
|
||||||
__('a related feed'),
|
|
||||||
dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')
|
|
||||||
) :
|
|
||||||
str_replace(
|
|
||||||
'%T',
|
|
||||||
$feed->title,
|
|
||||||
dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')
|
|
||||||
)
|
|
||||||
) . '</h3>';
|
|
||||||
}
|
|
||||||
|
|
||||||
# Feed desc
|
|
||||||
$feeddesc = '';
|
|
||||||
if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('showfeeddesc')
|
|
||||||
&& '' != $feed->description) {
|
|
||||||
$feeddesc = '<p>' . context::global_filters(
|
|
||||||
$feed->description,
|
|
||||||
['encode_xml', 'remove_html']
|
|
||||||
) . '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
# Date format
|
|
||||||
$dateformat = '' != $format['dateformat'] ?
|
|
||||||
$format['dateformat'] :
|
|
||||||
dcCore::app()->blog->settings->get('system')->get('date_format') . ',' . dcCore::app()->blog->settings->get('system')->get('time_format');
|
|
||||||
|
|
||||||
# Enrties limit
|
|
||||||
$entrieslimit = abs((int) $format['lineslimit']);
|
|
||||||
$uselimit = $entrieslimit > 0 ? true : false;
|
|
||||||
|
|
||||||
echo
|
|
||||||
'<div class="post-fac">' .
|
|
||||||
$feedtitle . $feeddesc .
|
|
||||||
'<dl>';
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($feed->items as $item) {
|
|
||||||
# Format date
|
|
||||||
$date = dt::dt2str($dateformat, $item->pubdate);
|
|
||||||
|
|
||||||
# Entries title
|
|
||||||
$title = context::global_filters(
|
|
||||||
str_replace(
|
|
||||||
[
|
|
||||||
'%D',
|
|
||||||
'%T',
|
|
||||||
'%A',
|
|
||||||
'%E',
|
|
||||||
'%C',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
$date,
|
|
||||||
$item->title,
|
|
||||||
$item->creator,
|
|
||||||
$item->description,
|
|
||||||
$item->content,
|
|
||||||
],
|
|
||||||
$format['linestitletext']
|
|
||||||
),
|
|
||||||
['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])],
|
|
||||||
);
|
|
||||||
|
|
||||||
# Entries over title
|
|
||||||
$overtitle = context::global_filters(
|
|
||||||
str_replace(
|
|
||||||
[
|
|
||||||
'%D',
|
|
||||||
'%T',
|
|
||||||
'%A',
|
|
||||||
'%E',
|
|
||||||
'%C',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
$date,
|
|
||||||
$item->title,
|
|
||||||
$item->creator,
|
|
||||||
$item->description,
|
|
||||||
$item->content,
|
|
||||||
],
|
|
||||||
$format['linestitleover']
|
|
||||||
),
|
|
||||||
['remove_html', 'cut_string' => 350],
|
|
||||||
);
|
|
||||||
|
|
||||||
# Entries description
|
|
||||||
$description = '';
|
|
||||||
if ($format['showlinesdescription']
|
|
||||||
&& '' != $item->description) {
|
|
||||||
$description = '<dd>' .
|
|
||||||
context::global_filters(
|
|
||||||
$item->description,
|
|
||||||
['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])]
|
|
||||||
) . '</dd>';
|
|
||||||
}
|
|
||||||
|
|
||||||
# Entries content
|
|
||||||
$content = '';
|
|
||||||
if ($format['showlinescontent']
|
|
||||||
&& '' != $item->content) {
|
|
||||||
$content = '<dd>' .
|
|
||||||
context::global_filters(
|
|
||||||
$item->content,
|
|
||||||
['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])]
|
|
||||||
) . '</dd>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'<dt><a href="' . $item->link . '" ' .
|
|
||||||
'title="' . $overtitle . '">' . $title . '</a></dt>' .
|
|
||||||
$description . $content;
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
if ($uselimit && $i == $entrieslimit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo '</dl></div>';
|
|
||||||
});
|
|
||||||
|
241
src/Install.php
241
src/Install.php
@ -10,124 +10,141 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @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_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Module specs
|
namespace Dotclear\Plugin\fac;
|
||||||
$mod_conf = [
|
|
||||||
[
|
|
||||||
'active',
|
|
||||||
'Enabled fac plugin',
|
|
||||||
false,
|
|
||||||
'boolean',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'public_tpltypes',
|
|
||||||
'List of templates types which used fac',
|
|
||||||
json_encode(['post', 'tag', 'archive']),
|
|
||||||
'string',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'formats',
|
|
||||||
'Formats of feeds contents',
|
|
||||||
json_encode([
|
|
||||||
uniqid() => [
|
|
||||||
'name' => 'default',
|
|
||||||
'dateformat' => '',
|
|
||||||
'lineslimit' => '5',
|
|
||||||
'linestitletext' => '%T',
|
|
||||||
'linestitleover' => '%D',
|
|
||||||
'linestitlelength' => '150',
|
|
||||||
'showlinesdescription' => '0',
|
|
||||||
'linesdescriptionlength' => '350',
|
|
||||||
'linesdescriptionnohtml' => '1',
|
|
||||||
'showlinescontent' => '0',
|
|
||||||
'linescontentlength' => '350',
|
|
||||||
'linescontentnohtml' => '1',
|
|
||||||
],
|
|
||||||
uniqid() => [
|
|
||||||
'name' => 'full',
|
|
||||||
'dateformat' => '',
|
|
||||||
'lineslimit' => '20',
|
|
||||||
'linestitletext' => '%T',
|
|
||||||
'linestitleover' => '%D - %E',
|
|
||||||
'linestitlelength' => '',
|
|
||||||
'showlinesdescription' => '1',
|
|
||||||
'linesdescriptionlength' => '',
|
|
||||||
'linesdescriptionnohtml' => '1',
|
|
||||||
'showlinescontent' => '1',
|
|
||||||
'linescontentlength' => '',
|
|
||||||
'linescontentnohtml' => '1',
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
'string',
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'defaultfeedtitle',
|
|
||||||
'Default title of feed',
|
|
||||||
'%T',
|
|
||||||
'string',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'showfeeddesc',
|
|
||||||
'Show description of feed',
|
|
||||||
1,
|
|
||||||
'boolean',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// Nothing to change below
|
use dcCore;
|
||||||
try {
|
use dcNamespace;
|
||||||
// Check module version
|
use dcNsProcess;
|
||||||
if (!dcCore::app()->newVersion(
|
use Exception;
|
||||||
basename(__DIR__),
|
|
||||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
class Install extends dcNsProcess
|
||||||
)) {
|
{
|
||||||
return null;
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||||
|
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||||
|
|
||||||
|
return static::$init;
|
||||||
}
|
}
|
||||||
|
|
||||||
// version < 1.0 : upgrade settings id and ns and array
|
public static function process(): bool
|
||||||
$current = dcCore::app()->getVersion(basename(__DIR__));
|
{
|
||||||
if ($current && version_compare($current, '1.0', '<')) {
|
if (!static::$init) {
|
||||||
$record = dcCore::app()->con->select(
|
return false;
|
||||||
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
}
|
||||||
"WHERE setting_ns = 'fac' "
|
|
||||||
);
|
// Module specs
|
||||||
while ($record->fetch()) {
|
$mod_conf = [
|
||||||
if (preg_match('/^fac_(.*?)$/', $record->setting_id, $match)) {
|
[
|
||||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
'active',
|
||||||
if (in_array($record->setting_id, ['fac_public_tpltypes', 'fac_formats'])) {
|
'Enabled fac plugin',
|
||||||
$cur->setting_value = json_encode(@unserialize($record->setting_value));
|
false,
|
||||||
}
|
'boolean',
|
||||||
$cur->setting_id = $match[1];
|
],
|
||||||
$cur->setting_ns = basename(__DIR__);
|
[
|
||||||
$cur->update(
|
'public_tpltypes',
|
||||||
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'fac' " .
|
'List of templates types which used fac',
|
||||||
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
json_encode(['post', 'tag', 'archive']),
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'formats',
|
||||||
|
'Formats of feeds contents',
|
||||||
|
json_encode([
|
||||||
|
uniqid() => [
|
||||||
|
'name' => 'default',
|
||||||
|
'dateformat' => '',
|
||||||
|
'lineslimit' => '5',
|
||||||
|
'linestitletext' => '%T',
|
||||||
|
'linestitleover' => '%D',
|
||||||
|
'linestitlelength' => '150',
|
||||||
|
'showlinesdescription' => '0',
|
||||||
|
'linesdescriptionlength' => '350',
|
||||||
|
'linesdescriptionnohtml' => '1',
|
||||||
|
'showlinescontent' => '0',
|
||||||
|
'linescontentlength' => '350',
|
||||||
|
'linescontentnohtml' => '1',
|
||||||
|
],
|
||||||
|
uniqid() => [
|
||||||
|
'name' => 'full',
|
||||||
|
'dateformat' => '',
|
||||||
|
'lineslimit' => '20',
|
||||||
|
'linestitletext' => '%T',
|
||||||
|
'linestitleover' => '%D - %E',
|
||||||
|
'linestitlelength' => '',
|
||||||
|
'showlinesdescription' => '1',
|
||||||
|
'linesdescriptionlength' => '',
|
||||||
|
'linesdescriptionnohtml' => '1',
|
||||||
|
'showlinescontent' => '1',
|
||||||
|
'linescontentlength' => '',
|
||||||
|
'linescontentnohtml' => '1',
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
'string',
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'defaultfeedtitle',
|
||||||
|
'Default title of feed',
|
||||||
|
'%T',
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'showfeeddesc',
|
||||||
|
'Show description of feed',
|
||||||
|
1,
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Nothing to change below
|
||||||
|
try {
|
||||||
|
self::growUp();
|
||||||
|
|
||||||
|
// Set module settings
|
||||||
|
foreach ($mod_conf as $v) {
|
||||||
|
dcCore::app()->blog->settings->get(My::id())->put(
|
||||||
|
$v[0],
|
||||||
|
$v[2],
|
||||||
|
$v[3],
|
||||||
|
$v[1],
|
||||||
|
false,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function growUp(): void
|
||||||
|
{
|
||||||
|
// version < 1.0 : upgrade settings id and ns and array
|
||||||
|
$current = dcCore::app()->getVersion(My::id());
|
||||||
|
if ($current && version_compare($current, '1.0', '<')) {
|
||||||
|
$record = dcCore::app()->con->select(
|
||||||
|
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
||||||
|
"WHERE setting_ns = 'fac' "
|
||||||
|
);
|
||||||
|
while ($record->fetch()) {
|
||||||
|
if (preg_match('/^fac_(.*?)$/', $record->f('setting_id'), $match)) {
|
||||||
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
|
if (in_array($record->f('setting_id'), ['fac_public_tpltypes', 'fac_formats'])) {
|
||||||
|
$cur->setField('setting_value', json_encode(@unserialize($record->f('setting_value'))));
|
||||||
|
}
|
||||||
|
$cur->setField('setting_id', $match[1]);
|
||||||
|
$cur->SetField('setting_ns', My::id());
|
||||||
|
$cur->update(
|
||||||
|
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'fac' " .
|
||||||
|
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr($record->f('blog_id')) . "' "))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set module settings
|
|
||||||
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
|
||||||
foreach ($mod_conf as $v) {
|
|
||||||
dcCore::app()->blog->settings->get(basename(__DIR__))->put(
|
|
||||||
$v[0],
|
|
||||||
$v[2],
|
|
||||||
$v[3],
|
|
||||||
$v[1],
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
36
src/My.php
Normal file
36
src/My.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief fac, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis 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\fac;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
|
||||||
|
class My
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This module id
|
||||||
|
*/
|
||||||
|
public static function id(): string
|
||||||
|
{
|
||||||
|
return basename(dirname(__DIR__));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module name
|
||||||
|
*/
|
||||||
|
public static function name(): string
|
||||||
|
{
|
||||||
|
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user