release 0.10

This commit is contained in:
Jean-Christian Denis 2022-11-20 21:13:56 +01:00
parent b4485bebd0
commit 807214f658
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
10 changed files with 327 additions and 318 deletions

View file

@ -1,5 +1,5 @@
0.9.3
- [ ] ?
0.10 2022.11.20
- fix compatibility with Dotclear 2.24 (required)
0.9.2 - 2021.09.02
- update license bloc to phpdoc

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/fac)](https://github.com/JcDenis/fac/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/fac)](https://github.com/JcDenis/fac/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/fac)](https://github.com/JcDenis/fac/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.19-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/fac)
[![License](https://img.shields.io/github/license/JcDenis/fac)](https://github.com/JcDenis/fac/blob/master/LICENSE)
@ -22,7 +22,7 @@ to link en extenal feed to the bottom of an entry.
* superadmin to configure feeds formats
* admin permissions to configure plugin
* usage,contentadmin permissions to link feeds
* Dotclear 2.19
* Dotclear 2.24
* A theme that contents behavior publicEntryAfterContent
## USAGE
@ -39,8 +39,14 @@ to link a feed to this post.
You can also add or remove feed to multiple post from posts actions page.
This plugins also supports pages from plugin "muppet".
## MORE
## LINKS
* License : GNU GPL v2
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* Source & contribution : [GitHub Page](https://github.com/JcDenis/fac)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/fac)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/fac)
## CONTRIBUTORS
* Jean-Christian Denis
You are welcome to contribute to this code.

View file

@ -1,31 +1,30 @@
<?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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$core->blog->settings->addNamespace('fac');
dcCore::app()->blog->settings->addNamespace('fac');
# Admin behaviors
$core->addBehavior('adminBlogPreferencesForm', ['facAdmin', 'adminBlogPreferencesForm']);
$core->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']);
$core->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']);
$core->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']);
$core->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']);
$core->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']);
$core->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']);
$core->addBehavior('adminPostsActionsPage', ['facAdmin', 'adminPostsActionsPage']);
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesForm']);
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']);
dcCore::app()->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']);
dcCore::app()->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']);
dcCore::app()->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']);
dcCore::app()->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']);
dcCore::app()->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']);
dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActionsPage']);
/**
* @ingroup DC_PLUGIN_FAC
@ -36,67 +35,66 @@ class facAdmin
{
/**
* Get combos of types of supported public pages
*
* @param dcCore $core dcCore instance
*
* @return array List of post type and name
*/
public static function getPostsTypes(dcCore $core)
public static function getPostsTypes()
{
$types = [
__('home page') => 'default',
__('post pages') => 'post',
__('tags pages') => 'tag',
__('archives pages') => 'archive',
__('category pages') => 'category',
__('entries feed') => 'feed'
__('home page') => 'default',
__('post pages') => 'post',
__('tags pages') => 'tag',
__('archives pages') => 'archive',
__('category pages') => 'category',
__('entries feed') => 'feed',
];
if ($core->plugins->moduleExists('muppet')) {
foreach(muppet::getPostTypes() as $k => $v) {
if (dcCore::app()->plugins->moduleExists('muppet')) {
foreach (muppet::getPostTypes() as $k => $v) {
$types[sprintf(
__('"%s" pages from extension muppet'),
$v['name']
)] = $k;
}
}
return $types;
}
/**
* Add settings to blog preference
*
* @param dcCore $core dcCore instance
*
* @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
public static function adminBlogPreferencesForm(dcSettings $blog_settings)
{
echo
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
'<p class="form-note">' .
'<p class="form-note">' .
__('To add feed to an entry edit this entry and put in sidebar the url of the feed and select a format.') .
'</p>';
if ($core->auth->isSuperAdmin()) {
echo '<p><a href="' . $core->adminurl->get('admin.plugins', [
'module' => 'fac',
'conf' => 1,
'redir' => $core->adminurl->get('admin.blog.pref') . '#fac_params'
if (dcCore::app()->auth->isSuperAdmin()) {
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
'module' => 'fac',
'conf' => 1,
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
]) . '">' . __('Configure formats') . '</a></p>';
}
echo
echo
'<div class="two-cols">' .
'<div class="col">' .
'<h5>' . __('Activation') . '</h5>' .
'<p><label class="classic">' .
form::checkbox('fac_active', '1', (boolean) $blog_settings->fac->fac_active) .
form::checkbox('fac_active', '1', (bool) $blog_settings->fac->fac_active) .
__('Enable "fac" extension') . '</label></p>' .
'<p class="form-note">' .
__("You can manage related feed to display for each post with a predefined format.") .
__('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->fac->fac_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, (boolean) $blog_settings->fac->fac_showfeeddesc) .
form::checkbox('fac_showfeeddesc', 1, (bool) $blog_settings->fac->fac_showfeeddesc) .
__('Show description of feed') . '</label></p>' .
'</div>' .
'<div class="col">' .
@ -106,7 +104,7 @@ class facAdmin
if (!is_array($fac_public_tpltypes)) {
$fac_public_tpltypes = [];
}
foreach(self::getPostsTypes($core) as $k => $v) {
foreach (self::getPostsTypes() as $k => $v) {
echo '
<p><label class="classic" for="fac_public_tpltypes' . $k . '">' .
form::checkbox(
@ -116,16 +114,16 @@ class facAdmin
) . __($k) . '</label></p>';
}
echo
echo
'</div>' .
'</div>' .
'<br class="clear" />' .
'<br class="clear" />' .
'</div>';
}
/**
* Save blog settings
*
*
* @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
@ -138,7 +136,7 @@ class facAdmin
/**
* Add javascript (toggle)
*
*
* @return string HTML head
*/
public static function adminPostHeaders()
@ -148,84 +146,77 @@ class facAdmin
/**
* Add form to post sidebar
*
*
* @param ArrayObject $main_items Main items
* @param ArrayObject $sidebar_items Sidebar items
* @param record $post Post record or null
*/
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
global $core;
if (!$core->blog->settings->fac->fac_active) {
if (!dcCore::app()->blog->settings->fac->fac_active) {
return null;
}
# Get existing linked feed
$fac_url = $fac_format = '';
if ($post) {
$rs = $core->meta->getMetadata([
$rs = dcCore::app()->meta->getMetadata([
'meta_type' => 'fac',
'post_id' => $post->post_id,
'limit' => 1
'post_id' => $post->post_id,
'limit' => 1,
]);
$fac_url = $rs->isEmpty() ? '' : $rs->meta_id;
$rs = $core->meta->getMetadata([
$rs = dcCore::app()->meta->getMetadata([
'meta_type' => 'facformat',
'post_id' => $post->post_id,
'limit' => 1
'post_id' => $post->post_id,
'limit' => 1,
]);
$fac_format = $rs->isEmpty() ? '' : $rs->meta_id;
}
# Set linked feed form items
$sidebar_items['options-box']['items']['fac'] =
self::formFeed($core, $fac_url, $fac_format);
$sidebar_items['options-box']['items']['fac'] = self::formFeed($fac_url, $fac_format);
}
/**
* Save linked feed
*
*
* @param cursor $cur Current post cursor
* @param integer $post_id Post id
*/
public static function adminAfterPostSave(cursor $cur, $post_id)
{
global $core;
if (!isset($_POST['fac_url'])
if (!isset($_POST['fac_url'])
|| !isset($_POST['fac_format'])) {
return null;
}
# Delete old linked feed
self::delFeed($core, $post_id);
self::delFeed($post_id);
# Add new linked feed
self::addFeed($core, $post_id, $_POST);
self::addFeed($post_id, $_POST);
}
/**
* Delete linked feed on post edition
*
*
* @param integer $post_id Post id
*/
public static function adminBeforePostDelete($post_id)
{
self::delFeed($GLOBALS['core'], $post_id);
self::delFeed($post_id);
}
/**
* Add actions to posts page combo
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $ap dcPostsActionsPage instance
*
* @param dcPostsActions $pa dcPostsActionsPage instance
*/
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa)
public static function adminPostsActionsPage(dcPostsActions $pa)
{
if (!$core->blog->settings->fac->fac_active) {
if (!dcCore::app()->blog->settings->fac->fac_active) {
return null;
}
@ -234,7 +225,10 @@ class facAdmin
['facAdmin', 'callbackAdd']
);
if (!$core->auth->check('delete,contentadmin', $core->blog->id)) {
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
return null;
}
$pa->addAction(
@ -245,12 +239,11 @@ class facAdmin
/**
* Posts actions callback to remove linked feed
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
*
* @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions
*/
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
@ -259,13 +252,16 @@ class facAdmin
}
# No right
if (!$core->auth->check('delete,contentadmin',$core->blog->id)) {
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
throw new Exception(__('No enough right'));
}
# Delete unused feed
foreach($posts_ids as $post_id) {
self::delFeed($core, $post_id);
foreach ($posts_ids as $post_id) {
self::delFeed($post_id);
}
dcPage::addSuccessNotice(__('Linked feed deleted.'));
@ -274,14 +270,13 @@ class facAdmin
/**
* Posts actions callback to add linked feed
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
*
* @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions
*/
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post)
{
# No entry
# No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
@ -290,9 +285,9 @@ class facAdmin
# Save action
if (!empty($post['fac_url'])
&& !empty($post['fac_format'])) {
foreach($posts_ids as $post_id) {
self::delFeed($core, $post_id);
self::addFeed($core, $post_id, $post);
foreach ($posts_ids as $post_id) {
self::delFeed($post_id);
self::addFeed($post_id, $post);
}
dcPage::addSuccessNotice(__('Linked feed added.'));
@ -302,9 +297,9 @@ class facAdmin
} else {
$pa->beginPage(
dcPage::breadcrumb([
html::escapeHTML($core->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Linked feed to this selection') => ''
html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Linked feed to this selection') => '',
])
);
@ -312,10 +307,10 @@ class facAdmin
'<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes() .
self::formFeed($core) .
self::formFeed() .
'<p>' .
$core->formNonce() .
dcCore::app()->formNonce() .
$pa->getHiddenFields() .
form::hidden(['action'], 'fac_add') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
@ -327,20 +322,19 @@ class facAdmin
/**
* Linked feed form field
*
* @param dcCore $core dcCore instance
*
* @param string $url Feed URL
* @param string $format Feed format
* @return string Feed form content
* @return null|string Feed form content
*/
protected static function formFeed(dcCore $core, $url = '', $format = '')
protected static function formFeed($url = '', $format = '')
{
if (!$core->blog->settings->fac->fac_active) {
if (!dcCore::app()->blog->settings->fac->fac_active) {
return null;
}
return
'<div id="fac">' .
return
'<div id="fac">' .
'<h5>' . __('Linked feed') . '</h5>' .
'<p><label for="fac_url">' .
__('Feed URL:') . '</label>' .
@ -355,7 +349,7 @@ class facAdmin
__('Format:') . '</label>' .
form::combo(
'fac_format',
self::comboFac($core),
self::comboFac(),
$format,
'maximal'
) . '</p>' .
@ -365,19 +359,18 @@ class facAdmin
/**
* List of fac formats
*
* @param dcCore $core dcCore instance
*
* @return array List of fac formats
*/
protected static function comboFac(dcCore $core)
protected static function comboFac()
{
$formats = @unserialize($core->blog->settings->fac->fac_formats);
$formats = @unserialize(dcCore::app()->blog->settings->fac->fac_formats);
if (!is_array($formats) || empty($formats)) {
return [];
}
$res = [];
foreach($formats as $uid => $f) {
foreach ($formats as $uid => $f) {
$res[$f['name']] = $uid;
}
@ -386,42 +379,40 @@ class facAdmin
/**
* Delete linked feed
*
* @param dcCore $core dcCore instance
*
* @param integer $post_id Post id
*/
protected static function delFeed(dcCore $core, $post_id)
protected static function delFeed($post_id)
{
$post_id = (integer) $post_id;
$core->meta->delPostMeta($post_id, 'fac');
$core->meta->delPostMeta($post_id, 'facformat');
$post_id = (int) $post_id;
dcCore::app()->meta->delPostMeta($post_id, 'fac');
dcCore::app()->meta->delPostMeta($post_id, 'facformat');
}
/**
* Add linked feed
*
* @param dcCore $core dcCore instance
*
* @param integer $post_id Post id
* @param array $options Feed options
* @param array|ArrayObject $options Feed options
*/
protected static function addFeed($core, $post_id, $options)
protected static function addFeed($post_id, $options)
{
if (empty($options['fac_url'])
if (empty($options['fac_url'])
|| empty($options['fac_format'])) {
return null;
}
$post_id = (integer) $post_id;
$post_id = (int) $post_id;
$core->meta->setPostMeta(
dcCore::app()->meta->setPostMeta(
$post_id,
'fac',
$options['fac_url']
);
$core->meta->setPostMeta(
dcCore::app()->meta->setPostMeta(
$post_id,
'facformat',
$options['fac_format']
);
}
}
}

View file

@ -1,30 +1,29 @@
<?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
*/
if (!defined('DC_CONTEXT_MODULE')) {
return null;
}
if (!$core->auth->isSuperAdmin()) {
if (!dcCore::app()->auth->isSuperAdmin()) {
return null;
}
$redir = empty($_REQUEST['redir']) ?
$list->getURL() . '#plugins' : $_REQUEST['redir'];
$redir = empty($_REQUEST['redir']) ?
dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
# -- Get settings --
$core->blog->settings->addNamespace('fac');
$s = $core->blog->settings->fac;
dcCore::app()->blog->settings->addNamespace('fac');
$s = dcCore::app()->blog->settings->fac;
$fac_formats = @unserialize($s->fac_formats);
@ -37,7 +36,7 @@ if (!empty($_POST['save'])) {
try {
$fac_formats = [];
foreach($_POST['fac_formats'] as $uid => $f) {
foreach ($_POST['fac_formats'] as $uid => $f) {
if (!empty($f['name'])) {
$fac_formats[$uid] = $f;
}
@ -46,31 +45,31 @@ if (!empty($_POST['save'])) {
// fix 2021.08.21 : formats are now global
$s->drop('fac_formats');
$s->put(
'fac_formats',
serialize($fac_formats),
'string',
'Formats of feeds contents',
true,
'fac_formats',
serialize($fac_formats),
'string',
'Formats of feeds contents',
true,
true
);
$core->blog->triggerBlog();
dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice(
dcAdminNotices::addSuccessNotice(
__('Configuration successfully updated.')
);
http::redirect(
$list->getURL('module=fac&conf=1&redir=' . $list->getRedir())
dcCore::app()->admin->list->getURL('module=fac&conf=1&redir=' . dcCore::app()->admin->list->getRedir())
);
} catch (Exception $e) {
$core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
}
# -- Display form --
$i = 1;
foreach($fac_formats as $uid => $f) {
foreach ($fac_formats as $uid => $f) {
if (empty($f['name'])) {
continue;
}
@ -86,7 +85,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][name]',
'fac_formats_' . $uid . '_name'
'fac_formats_' . $uid . '_name',
],
20,
255,
@ -102,7 +101,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][dateformat]',
'fac_formats_' . $uid . '_dateformat'
'fac_formats_' . $uid . '_dateformat',
],
20,
255,
@ -118,7 +117,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][lineslimit]',
'fac_formats_' . $uid . '_lineslimit'
'fac_formats_' . $uid . '_lineslimit',
],
5,
4,
@ -136,7 +135,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][linestitletext]',
'fac_formats_' . $uid . '_linestitletext'
'fac_formats_' . $uid . '_linestitletext',
],
20,
255,
@ -157,7 +156,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][linestitleover]',
'fac_formats_' . $uid . '_linestitleover'
'fac_formats_' . $uid . '_linestitleover',
],
20,
255,
@ -178,7 +177,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][linestitlelength]',
'fac_formats_' . $uid . '_linestitlelength'
'fac_formats_' . $uid . '_linestitlelength',
],
5,
4,
@ -195,7 +194,7 @@ foreach($fac_formats as $uid => $f) {
form::checkbox(
[
'fac_formats[' . $uid . '][showlinesdescription]',
'fac_formats_' . $uid . '_showlinesdescription'
'fac_formats_' . $uid . '_showlinesdescription',
],
1,
!empty($f['showlinesdescription'])
@ -206,11 +205,11 @@ foreach($fac_formats as $uid => $f) {
form::checkbox(
[
'fac_formats[' . $uid . '][linesdescriptionnohtml]',
'fac_formats_' . $uid . '_linesdescriptionnohtml'
'fac_formats_' . $uid . '_linesdescriptionnohtml',
],
1,
!empty($f['linesdescriptionnohtml'])
).
) .
__('Remove html of description') . '</label></p>
<p><label for="fac_formats_' . $uid . '_linesdescriptionlength">' .
@ -218,7 +217,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][linesdescriptionlength]',
'fac_formats_' . $uid . '_linesdescriptionlength'
'fac_formats_' . $uid . '_linesdescriptionlength',
],
5,
4,
@ -235,7 +234,7 @@ foreach($fac_formats as $uid => $f) {
form::checkbox(
[
'fac_formats[' . $uid . '][showlinescontent]',
'fac_formats_' . $uid . '_showlinescontent'
'fac_formats_' . $uid . '_showlinescontent',
],
1,
!empty($f['showlinescontent'])
@ -246,7 +245,7 @@ foreach($fac_formats as $uid => $f) {
form::checkbox(
[
'fac_formats[' . $uid . '][linescontentnohtml]',
'fac_formats_' . $uid . '_linescontentnohtml'
'fac_formats_' . $uid . '_linescontentnohtml',
],
1,
!empty($f['linescontentnohtml'])
@ -258,7 +257,7 @@ foreach($fac_formats as $uid => $f) {
form::field(
[
'fac_formats[' . $uid . '][linescontentlength]',
'fac_formats_' . $uid . '_linescontentlength'
'fac_formats_' . $uid . '_linescontentlength',
],
5,
4,
@ -288,14 +287,14 @@ __('Name:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][name]',
'fac_formats_' . $uid . '_name'
'fac_formats_' . $uid . '_name',
],
20,
255,
'',
'maximal'
) . '</p>
<p class="form-note">'.
<p class="form-note">' .
__('In order to remove a format, leave its name empty.') .
'</p>
@ -304,7 +303,7 @@ __('Date format:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][dateformat]',
'fac_formats_' . $uid . '_dateformat'
'fac_formats_' . $uid . '_dateformat',
],
20,
255,
@ -320,7 +319,7 @@ __('Entries limit:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][lineslimit]',
'fac_formats_' . $uid . '_lineslimit'
'fac_formats_' . $uid . '_lineslimit',
],
5,
4,
@ -338,7 +337,7 @@ __('Title format:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][linestitletext]',
'fac_formats_' . $uid . '_linestitletext'
'fac_formats_' . $uid . '_linestitletext',
],
20,
255,
@ -355,11 +354,11 @@ __('Format can be:') .
'</p>
<p><label for="fac_formats_' . $uid . '_linestitleover">' .
__('Over title format:') . '</label>' .
__('Over title format:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][linestitleover]',
'fac_formats_' . $uid . '_linestitleover'
'fac_formats_' . $uid . '_linestitleover',
],
20,
255,
@ -380,14 +379,14 @@ __('Maximum length of title:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][linestitlelength]',
'fac_formats_' . $uid . '_linestitlelength'
'fac_formats_' . $uid . '_linestitlelength',
],
5,
4,
150,
'maximal'
) . '</p>
<p class="form-note">' .
<p class="form-note">' .
__('Leave lengh empty for no limit.') .
'</p>
@ -397,7 +396,7 @@ __('Leave lengh empty for no limit.') .
form::checkbox(
[
'fac_formats[' . $uid . '][showlinesdescription]',
'fac_formats_' . $uid . '_showlinesdescription'
'fac_formats_' . $uid . '_showlinesdescription',
],
1,
0
@ -408,7 +407,7 @@ __('Show description of entries') . '</label></p>
form::checkbox(
[
'fac_formats[' . $uid . '][linesdescriptionnohtml]',
'fac_formats_' . $uid . '_linesdescriptionnohtml'
'fac_formats_' . $uid . '_linesdescriptionnohtml',
],
1,
1
@ -420,7 +419,7 @@ __('Maximum length of description:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][linesdescriptionlength]',
'fac_formats_' . $uid . '_linesdescriptionlength'
'fac_formats_' . $uid . '_linesdescriptionlength',
],
5,
4,
@ -437,7 +436,7 @@ __('Leave lengh empty for no limit.') .
form::checkbox(
[
'fac_formats[' . $uid . '][showlinescontent]',
'fac_formats_' . $uid . '_showlinescontent'
'fac_formats_' . $uid . '_showlinescontent',
],
1,
0
@ -448,7 +447,7 @@ __('Show content of entries') . '</label></p>
form::checkbox(
[
'fac_formats[' . $uid . '][linescontentnohtml]',
'fac_formats_' . $uid . '_linescontentnohtml'
'fac_formats_' . $uid . '_linescontentnohtml',
],
1,
1
@ -460,7 +459,7 @@ __('Maximum length of content:') . '</label>' .
form::field(
[
'fac_formats[' . $uid . '][linescontentlength]',
'fac_formats_' . $uid . '_linescontentlength'
'fac_formats_' . $uid . '_linescontentlength',
],
5,
4,
@ -504,4 +503,4 @@ __('To add feed to an entry edit this entry and put in sidebar the url of the fe
</div>';
dcPage::helpBlock('fac');
dcPage::helpBlock('fac');

View file

@ -1,16 +1,15 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
@ -19,16 +18,19 @@ $this->registerModule(
'Feed after content',
'Add RSS/Atom feeds after entries content',
'Jean-Christian Denis and Contributors',
'0.9.3',
'0.10',
[
'requires' => [['core', '2.19']],
'permissions' => 'usage,contentadmin',
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/fac',
'details' => 'https://plugins.dotaddict.org/dc2/details/fac',
'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/fac',
'details' => 'https://plugins.dotaddict.org/dc2/details/fac',
'repository' => 'https://raw.githubusercontent.com/JcDenis/fac/master/repository.xml',
'settings' => [
'blog' => '#params.fac_params'
]
'settings' => [
'blog' => '#params.fac_params',
],
]
);
);

View file

@ -1,117 +1,126 @@
<?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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# -- Module specs --
$dc_min = '2.19';
$mod_id = 'fac';
$dc_min = '2.24';
$mod_id = 'fac';
$mod_conf = [
[
'fac_active',
'Enabled fac plugin',
false,
'boolean'
'boolean',
],
[
'fac_public_tpltypes',
'List of templates types which used fac',
serialize(['post', 'tag', 'archive']),
'string'
'string',
],
[
'fac_formats',
'Formats of feeds contents',
serialize([
uniqid() => [
'name' => 'default',
'dateformat' => '',
'lineslimit' => '5',
'linestitletext' => '%T',
'linestitleover' => '%D',
'linestitlelength' => '150',
'showlinesdescription' => '0',
'linesdescriptionlength' => '350',
'linesdescriptionnohtml' => '1',
'showlinescontent' => '0',
'linescontentlength' => '350',
'linescontentnohtml' => '1'
'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'
]
'name' => 'full',
'dateformat' => '',
'lineslimit' => '20',
'linestitletext' => '%T',
'linestitleover' => '%D - %E',
'linestitlelength' => '',
'showlinesdescription' => '1',
'linesdescriptionlength' => '',
'linesdescriptionnohtml' => '1',
'showlinescontent' => '1',
'linescontentlength' => '',
'linescontentnohtml' => '1',
],
]),
'string',
false,
true
true,
],
[
'fac_defaultfeedtitle',
'Default title of feed',
'%T',
'string'
'string',
],
[
'fac_showfeeddesc',
'Show description of feed',
1,
'boolean'
]
'boolean',
],
];
# -- Nothing to change below --
try {
# Check module version
if (version_compare(
$core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'),
'>=')) {
dcCore::app()->getVersion($mod_id),
dcCore::app()->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
return null;
}
# Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare')
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf(
'%s requires Dotclear %s', $mod_id, $dc_min
'%s requires Dotclear %s',
$mod_id,
$dc_min
));
}
# Set module settings
$core->blog->settings->addNamespace($mod_id);
foreach($mod_conf as $v) {
$core->blog->settings->{$mod_id}->put(
$v[0], $v[2], $v[3], $v[1], false, true
dcCore::app()->blog->settings->addNamespace($mod_id);
foreach ($mod_conf as $v) {
dcCore::app()->blog->settings->{$mod_id}->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
# Set module version
$core->setVersion(
dcCore::app()->setVersion(
$mod_id,
$core->plugins->moduleInfo($mod_id, 'version')
dcCore::app()->plugins->moduleInfo($mod_id, 'version')
);
return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
return false;
}
}

View file

@ -1,23 +1,22 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
$core->addBehavior(
dcCore::app()->addBehavior(
'publicEntryAfterContent',
array('facPublic', 'publicEntryAfterContent')
['facPublic', 'publicEntryAfterContent']
);
/**
@ -29,64 +28,64 @@ class facPublic
{
/**
* Add feed after entry
*
*
* @param dcCore $core dcCore instance
* @param context $_ctx context instance
*/
public static function publicEntryAfterContent(dcCore $core, context $_ctx)
{
$core->blog->settings->addNamespace('fac');
dcCore::app()->blog->settings->addNamespace('fac');
# Not active or not a post
if (!$core->blog->settings->fac->fac_active
|| !$_ctx->exists('posts')) {
if (!dcCore::app()->blog->settings->fac->fac_active
|| !dcCore::app()->ctx->exists('posts')) {
return null;
}
# Not in page to show
$types = @unserialize($core->blog->settings->fac->fac_public_tpltypes);
$types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes);
if (!is_array($types)
|| !in_array($core->url->type,$types)) {
|| !in_array(dcCore::app()->url->type, $types)) {
return null;
}
# Get related feed
$fac_url = $core->meta->getMetadata([
$fac_url = dcCore::app()->meta->getMetadata([
'meta_type' => 'fac',
'post_id' => $_ctx->posts->post_id,
'limit' => 1
'post_id' => dcCore::app()->ctx->posts->post_id,
'limit' => 1,
]);
if ($fac_url->isEmpty()) {
return null;
}
# Get related format
$fac_format = $core->meta->getMetadata([
$fac_format = dcCore::app()->meta->getMetadata([
'meta_type' => 'facformat',
'post_id' => $_ctx->posts->post_id,
'limit' => 1
'post_id' => dcCore::app()->ctx->posts->post_id,
'limit' => 1,
]);
if ($fac_format->isEmpty()) {
return null;
}
# Get format info
$default_format = array(
'name' => 'default',
'dateformat' => '',
'lineslimit' => '5',
'linestitletext' => '%T',
'linestitleover' => '%D',
'linestitlelength' => '150',
'showlinesdescription' => '0',
$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'
);
'showlinescontent' => '0',
'linescontentlength' => '350',
'linescontentnohtml' => '1',
];
$formats = @unserialize($core->blog->settings->fac->fac_formats);
$formats = @unserialize((string) dcCore::app()->blog->settings->fac->fac_formats);
if (empty($formats)
|| !is_array($formats)
|| !isset($formats[$fac_format->meta_id])) {
@ -100,6 +99,7 @@ class facPublic
# 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) {
@ -113,91 +113,90 @@ class facPublic
# Feed title
$feedtitle = '';
if ('' != $core->blog->settings->fac->fac_defaultfeedtitle) {
$feedtitle = '<h3>' . html::escapeHTML(empty($feed->title) ?
if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) {
$feedtitle = '<h3>' . html::escapeHTML(
empty($feed->title) ?
str_replace(
'%T',
__('a related feed'),
$core->blog->settings->fac->fac_defaultfeedtitle
) :
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
) :
str_replace(
'%T',
$feed->title,
$core->blog->settings->fac->fac_defaultfeedtitle
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
)
) . '</h3>';
}
# Feed desc
$feeddesc = '';
if ($core->blog->settings->fac->fac_showfeeddesc
if (dcCore::app()->blog->settings->fac->fac_showfeeddesc
&& '' != $feed->description) {
$feeddesc =
'<p>' . context::global_filters(
$feed->description,
$feeddesc = '<p>' . context::global_filters(
$feed->description,
['encode_xml', 'remove_html']
) . '</p>';
}
# Date format
$dateformat = '' != $format['dateformat'] ?
$dateformat = '' != $format['dateformat'] ?
$format['dateformat'] :
$core->blog->settings->system->date_format . ',' . $core->blog->settings->system->time_format;
dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format;
# Enrties limit
$entrieslimit = abs((integer) $format['lineslimit']);
$uselimit = $entrieslimit > 0 ? true : false;
$entrieslimit = abs((int) $format['lineslimit']);
$uselimit = $entrieslimit > 0 ? true : false;
echo
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(
array(
[
'%D',
'%T',
'%A',
'%E',
'%C'
),
array(
'%C',
],
[
$date,
$item->title,
$item->creator,
$item->description,
$item->content
),
$item->content,
],
$format['linestitletext']
),
['remove_html', 'cut_string' => abs((integer) $format['linestitlelength'])],
['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])],
);
# Entries over title
$overtitle = context::global_filters(
str_replace(
array(
[
'%D',
'%T',
'%A',
'%E',
'%C'
),
array(
'%C',
],
[
$date,
$item->title,
$item->creator,
$item->description,
$item->content
),
$item->content,
],
$format['linestitleover']
),
['remove_html', 'cut_string' => 350],
@ -205,23 +204,23 @@ class facPublic
# Entries description
$description = '';
if ($format['showlinesdescription']
if ($format['showlinesdescription']
&& '' != $item->description) {
$description = '<dd>' .
context::global_filters(
$item->description,
['remove_html' => (integer) $format['linesdescriptionnohtml'], 'cut_string' => abs((integer) $format['linesdescriptionlength'])]
['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])]
) . '</dd>';
}
# Entries content
$content = '';
if ($format['showlinescontent']
if ($format['showlinescontent']
&& '' != $item->content) {
$content = '<dd>'.
$content = '<dd>' .
context::global_filters(
$item->content,
['remove_html' => (integer) $format['linescontentnohtml'], 'cut_string' => abs((integer) $format['linescontentlength'])]
['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])]
) . '</dd>';
}
@ -237,4 +236,4 @@ class facPublic
}
echo '</dl></div>';
}
}
}

View file

@ -1,12 +1,13 @@
<?xml version="1.0"?>
<modules xmlns:da="http://dotaddict.org/da/">
<module id="fac">
<name>Feed after content</name>
<version>0.9.2</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Add RSS/Atom feeds after entries content</desc>
<file>https://github.com/JcDenis/fac/releases/download/v0.9.2/plugin-fac.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/fac</da:details>
<da:support>https://github.com/JcDenis/fac</da:support>
</module>
<module id="fac">
<name>Feed after content</name>
<version>0.10</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Add RSS/Atom feeds after entries content</desc>
<file>https://github.com/JcDenis/fac/releases/download/v0.10/plugin-fac.zip</file>
<da:dcmin>2.24</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/fac</da:details>
<da:support>https://github.com/JcDenis/fac</da:support>
</module>
</modules>

View file

@ -1,10 +1,11 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of fac, a plugin for Dotclear 2.
#
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@ -15,4 +16,4 @@ if (!defined('DC_RC_PATH')) {
return;
}
$__resources['help']['fac'] = dirname(__FILE__) . '/help/fac.html';
dcCore::app()->resources['help']['fac'] = __DIR__ . '/help/fac.html';

View file

@ -1,10 +1,11 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of fac, a plugin for Dotclear 2.
#
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@ -15,4 +16,4 @@ if (!defined('DC_RC_PATH')) {
return;
}
$__resources['help']['fac'] = dirname(__FILE__) . '/help/fac.html';
dcCore::app()->resources['help']['fac'] = __DIR__ . '/help/fac.html';