upgrade to dotclear 2.28

master v2023.10.20
Jean-Christian Paul Denis 2023-10-20 20:35:41 +02:00
parent 45e84abd9f
commit bf68f8d129
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
16 changed files with 229 additions and 313 deletions

View File

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

View File

@ -1,28 +1,25 @@
# README
[![Release](https://img.shields.io/badge/release-2023.08.15-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postWidgetText/releases)
[![Date](https://img.shields.io/badge/date-2023.08.15-c44d58.svg)](https://git.dotclear.watch/JcDenis/postWidgetText/releases)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download)
[![Release](https://img.shields.io/badge/release-2023.10.20-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postWidgetText/releases)
![Date](https://img.shields.io/badge/date-2023.10.20-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/postWidgetText)
[![License](https://img.shields.io/github/license/JcDenis/postWidgetText)](https://git.dotclear.watch/JcDenis/postWidgetText/blob/master/LICENSE)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/postWidgetText/src/branch/master/LICENSE)
## WHAT IS POSTWIDGETTEXT ?
## ABOUT
_Post widget text_ is a plugin for the open-source
web publishing software called Dotclear.
_postWidgetText_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
Add a widget related to an entry with custom titles and content.
> Add a widget related to an entry with custom titles and content.
## REQUIREMENTS
_postWidgetText_ requires:
* Dotclear 2.28
* PHP 8.1+
* Dotclear permissions to manage widgets
* Dotclear permissions to manage entries
* permissions to manage widgets
* permissions to manage entries
* Dotclear 2.27
* PHP 8.0+
Note this plugin add table called post_option to Dotclear database.
Note this plugin add table called "post_option" to Dotclear database.
## USAGE
@ -36,9 +33,10 @@ Manage (delete) "widgets" from sidebar menu called "Post widget text".
## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/postWidgetText) or [GitHub Page](https://github.com/JcDenis/postWidgetText)
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/postWidgetText/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/postWidgetText)
* [License](https://git.dotclear.watch/JcDenis/postWidgetText/src/branch/master/LICENSE)
* [Packages & details](https://git.dotclear.watch/JcDenis/postWidgetText/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/postWidgetText))
* [Sources & contributions](https://git.dotclear.watch/JcDenis/postWidgetText) (or on [GitHub](https://github.com/JcDenis/postWidgetText))
* [Issues & security](https://git.dotclear.watch/JcDenis/postWidgetText/issues) (or on [GitHub](https://github.com/JcDenis/postWidgetText/issues))
## CONTRIBUTORS

View File

@ -1,39 +1,31 @@
<?php
/**
* @brief postWidgetText, a plugin for Dotclear 2
* @file
* @brief The plugin postWidgetText definition
* @ingroup postWidgetText
*
* @package Dotclear
* @subpackage Plugin
* @defgroup postWidgetText Plugin postWidgetText.
*
* @author Jean-Christian Denis and Contributors
* Add a widget with a text related to an entry.
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
* @author Tomtom (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
$this->registerModule(
'Post widget text',
'Add a widget with a text related to an entry',
'Jean-Christian Denis and Contributors',
'2023.08.15',
'2023.10.20',
[
'requires' => [
['php', '8.0'],
['core', '2.27'],
],
'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
'settings' => [
'blog' => '#params.pwt_params',
],
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
'requires' => [['core', '2.28']],
'permissions' => 'My',
'settings' => ['blog' => '#params.pwt_params'],
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
]
);

View File

@ -1,20 +0,0 @@
<?php
/**
* @brief postWidgetText, 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;
}
class initPostWidgetText
{
public const PWT_TABLE_NAME = 'post_option';
}

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="postWidgetText">
<name>Post widget text</name>
<version>2023.08.15</version>
<version>2023.10.20</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Add a widget with a text related to an entry</desc>
<file>https://git.dotclear.watch/JcDenis/postWidgetText/releases/download/v2023.08.15/plugin-postWidgetText.zip</file>
<da:dcmin>2.27</da:dcmin>
<file>https://git.dotclear.watch/JcDenis/postWidgetText/releases/download/v2023.10.20/plugin-postWidgetText.zip</file>
<da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/postWidgetText/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/postWidgetText/issues</da:support>
</module>

View File

@ -1,22 +1,19 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
/**
* @brief postWidgetText backend class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Backend extends Process
{
public static function init(): bool
@ -36,37 +33,37 @@ class Backend extends Process
}
// backend pwt management
dcCore::app()->addBehaviors([
App::behavior()->addBehaviors([
// user pref
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'],
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
'adminColumnsListsV2' => BackendBehaviors::adminColumnsListsV2(...),
'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...),
'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...),
// post
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
'adminPostEditorTags' => [BackendBehaviors::class, 'adminPostEditorTags'],
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPostEditorTags' => BackendBehaviors::adminPostEditorTags(...),
'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...),
'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...),
'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...),
// Plugin "pages"
'adminPageHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
'adminPageFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
'adminAfterPageUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminAfterPageCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminBeforePageDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminAfterPageUpdate' => BackendBehaviors::adminAfterPostSave(...),
'adminAfterPageCreate' => BackendBehaviors::adminAfterPostSave(...),
'adminBeforePageDelete' => BackendBehaviors::adminBeforePostDelete(...),
// widgets registration
'initWidgets' => [Widgets::class, 'initWidgets'],
'initWidgets' => Widgets::initWidgets(...),
]);
// add plugin "importExport" features
if (!My::settings()->get('importexport_active')) {
dcCore::app()->addBehaviors([
'exportFullV2' => [ImportExport::class, 'exportFullV2'],
'exportSingleV2' => [ImportExport::class, 'exportSingleV2'],
'importInitV2' => [ImportExport::class, 'importInitV2'],
'importSingleV2' => [ImportExport::class, 'importSingleV2'],
'importFullV2' => [ImportExport::class, 'importFullV2'],
App::behavior()->addBehaviors([
'exportFullV2' => ImportExport::exportFullV2(...),
'exportSingleV2' => ImportExport::exportSingleV2(...),
'importInitV2' => ImportExport::importInitV2(...),
'importSingleV2' => ImportExport::importSingleV2(...),
'importFullV2' => ImportExport::importFullV2(...),
]);
}

View File

@ -1,32 +1,26 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use ArrayObject;
use dcSettings;
use Dotclear\Core\Backend\Favorites;
use Dotclear\Database\{
Cursor,
MetaRecord
};
use Dotclear\Helper\Html\Html;
use Dotclear\Interface\Core\BlogSettingsInterface;
use form;
/**
* Backend behaviors.
* @brief postWidgetText backend behaviors class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class BackendBehaviors
{
@ -85,7 +79,7 @@ class BackendBehaviors
*
* @param dcSettings $blog_settings The blog settings
*/
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void
public static function adminBlogPreferencesFormV2(BlogSettingsInterface $blog_settings): void
{
echo '
<div class="fieldset">
@ -111,7 +105,7 @@ class BackendBehaviors
*
* @param dcSettings $blog_settings The blog settings
*/
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void
public static function adminBeforeBlogSettingsUpdate(BlogSettingsInterface $blog_settings): void
{
$blog_settings->get(My::id())->put('active', !empty($_POST['active']));
$blog_settings->get(My::id())->put('importexport_active', !empty($_POST['importexport_active']));

View File

@ -1,22 +1,19 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
/**
* @brief postWidgetText frontend class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Frontend extends Process
{
public static function init(): bool
@ -30,7 +27,7 @@ class Frontend extends Process
return false;
}
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
App::behavior()->addBehavior('initWidgets', Widgets::initWidgets(...));
return true;
}

View File

@ -1,24 +1,17 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use dcBlog;
use Dotclear\App;
/**
* Plugin importExport features.
* @brief postWidgetText plugin importExport stuff.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImportExport
{
@ -30,11 +23,11 @@ class ImportExport
My::id(),
'SELECT option_type, option_content, ' .
'option_content_xhtml, W.post_id ' .
'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' W ' .
'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' .
'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' W ' .
'LEFT JOIN ' . App::con()->prefix() . App::blog()::POST_TABLE_NAME . ' P ' .
'ON P.post_id = W.post_id ' .
"WHERE P.blog_id = '" . $blog_id . "' " .
"AND W.option_type = '" . dcCore::app()->con->escapeStr((string) My::id()) . "' "
"AND W.option_type = '" . App::con()->escapeStr((string) My::id()) . "' "
);
}
@ -44,17 +37,17 @@ class ImportExport
My::id(),
'SELECT option_type, option_content, ' .
'option_content_xhtml, W.post_id ' .
'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' W ' .
'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' .
'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' W ' .
'LEFT JOIN ' . App::con()->prefix() . App::blog()::POST_TABLE_NAME . ' P ' .
'ON P.post_id = W.post_id ' .
"WHERE W.option_type = '" . dcCore::app()->con->escapeStr((string) My::id()) . "' "
"WHERE W.option_type = '" . App::con()->escapeStr((string) My::id()) . "' "
);
}
public static function importInitV2($bk)
{
self::$ie_cursor = dcCore::app()->con->openCursor(
dcCore::app()->prefix . My::TABLE_NAME
self::$ie_cursor = App::con()->openCursor(
App::con()->prefix() . My::TABLE_NAME
);
}

View File

@ -1,24 +1,21 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Process;
use Dotclear\Database\Structure;
use Exception;
/**
* @brief postWidgetText insatll class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Install extends Process
{
public static function init(): bool
@ -34,7 +31,7 @@ class Install extends Process
try {
// Table is the same for plugins pollsFactory, postTask, postWidgetText
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$s = new Structure(App::con(), App::con()->prefix());
$s->__get(My::TABLE_NAME)
->field('option_id', 'bigint', 0, false)
->field('post_id', 'bigint', 0, false)
@ -51,7 +48,7 @@ class Install extends Process
->index('idx_post_option_post', 'btree', 'post_id')
->index('idx_post_option_type', 'btree', 'option_type');
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
(new Structure(App::con(), App::con()->prefix()))->synchronize($s);
// Settings
$s = My::settings();
@ -74,7 +71,7 @@ class Install extends Process
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
return false;
}

View File

@ -1,20 +1,10 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Backend\Filter\{
Filters,
FiltersLibrary
@ -27,6 +17,13 @@ use Dotclear\Core\Process;
use Dotclear\Helper\Network\Http;
use Exception;
/**
* @brief postWidgetText manage class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Manage extends Process
{
public static function init(): bool
@ -56,7 +53,7 @@ class Manage extends Process
My::redirect();
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
}
}
@ -65,12 +62,9 @@ class Manage extends Process
public static function render(): void
{
if (!self::status()) {
return;
}
// nullsafe check
if (is_null(dcCore::app()->blog)) {
if (!self::status()
|| !App::blog()->isDefined()
) {
return;
}
@ -88,7 +82,7 @@ class Manage extends Process
$counter = Utils::getWidgets($params, true);
$posts_list = new ManageList($posts, $counter->f(0));
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
App::error()->add($e->getMessage());
$posts_list = null;
}

View File

@ -1,22 +1,11 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use ArrayObject;
use context;
use dcCore;
use Dotclear\App;
use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\Listing\{
Listing,
@ -27,23 +16,24 @@ use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html;
/**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin list methods.
* @since 2.6
* @brief postWidgetText backend list class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ManageList extends Listing
{
public function display(Filters $filter, string $enclose = '%s'): void
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
return;
}
// prepare page
$blocks = explode('%s', $enclose);
$pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC');
$tz = App::auth()->getInfo('user_tz') ?? (App::blog()->settings()->get('system')->get('blog_timezone') ?? 'UTC');
// no record
if ($this->rs->isEmpty()) {
@ -84,7 +74,8 @@ class ManageList extends Listing
$w_title = Html::escapeHTML($this->rs->option_title);
if ($w_title == '') {
// widget title can accept HTML, but backend table not
$w_title = context::global_filters(
/*
$w_title = App::frontend()->context()->global_filters(
$this->rs->option_content,
[
'encode_xml',
@ -92,6 +83,8 @@ class ManageList extends Listing
'cut_string' => 80,
]
);
*/
$w_title = '?';
}
// table body line
@ -102,7 +95,7 @@ class ManageList extends Listing
->__call('disabled', [!$this->rs->isEditable()])
->render() .
'</td>',
'name' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '#post-wtext-form">' .
'name' => '<td class="maximal"><a href="' . App::postTypes()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '#post-wtext-form">' .
Html::escapeHTML($this->rs->f('post_title')) . '</a></td>',
'post_dt' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz) . '</td>',
'option_title' => '<td class="nowrap">' . $w_title . '</td>',

View File

@ -1,15 +1,5 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
@ -17,10 +7,20 @@ namespace Dotclear\Plugin\postWidgetText;
use Dotclear\Module\MyPlugin;
/**
* This module definitions.
* @brief postWidgetText My helper.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class My extends MyPlugin
{
/** @var string Plugin table name */
public const TABLE_NAME = \initPostWidgetText::PWT_TABLE_NAME;
/**
* Plugin table name.
*
* @var string TABLE_NAME
*/
public const TABLE_NAME = 'post_option';
// Use default permissions
}

View File

@ -1,23 +1,19 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller;
/**
* @brief postWidgetText uninstall class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Uninstall extends Process
{
public static function init(): bool
@ -27,7 +23,7 @@ class Uninstall extends Process
public static function process(): bool
{
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
if (!self::status()) {
return false;
}

View File

@ -1,20 +1,10 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Database\{
Cursor,
MetaRecord
@ -28,9 +18,11 @@ use Dotclear\Helper\Text;
use Exception;
/**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin and public methods.
* @since 2.6
* @brief postWidgetText utils class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Utils
{
@ -51,7 +43,7 @@ class Utils
*/
public static function openCursor(): Cursor
{
return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME);
return App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME);
}
/**
@ -64,8 +56,7 @@ class Utils
*/
public static function getWidgets(array $params, bool $count_only = false): MetaRecord
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
throw new Exception(__('Blog is not set'));
}
@ -88,7 +79,7 @@ class Utils
$sql->join(
(new JoinStatement())
->left()
->from($sql->as(dcCore::app()->prefix . My::TABLE_NAME, 'W'))
->from($sql->as(App::con()->prefix() . My::TABLE_NAME, 'W'))
->on('P.post_id = W.post_id')
->statement()
);
@ -132,7 +123,7 @@ class Utils
$params['post_type'] = '';
}
return dcCore::app()->blog->getPosts($params, $count_only, $sql);
return App::blog()->getPosts($params, $count_only, $sql);
}
/**
@ -144,16 +135,15 @@ class Utils
*/
public static function addWidget(Cursor $cur): int
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
throw new Exception(__('Blog is not set'));
}
// check permissions to add post
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
if (!App::auth()->check(App::auth()->makePermissions([
App::auth()::PERMISSION_USAGE,
App::auth()::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id())) {
throw new Exception(__('You are not allowed to create an entry text widget'));
}
@ -163,11 +153,11 @@ class Utils
}
// lock table
dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
App::con()->writeLock(App::con()->prefix() . My::TABLE_NAME);
try {
$sql = new SelectStatement();
$rs = $sql->from(dcCore::app()->prefix . My::TABLE_NAME)->column($sql->max('option_id'))->select();
$rs = $sql->from(App::con()->prefix() . My::TABLE_NAME)->column($sql->max('option_id'))->select();
if (is_null($rs) || $rs->isEmpty()) {
throw new Exception(__('Something went wrong)'));
}
@ -183,15 +173,15 @@ class Utils
// add new widgetText
$cur->insert();
dcCore::app()->con->unlock();
App::con()->unlock();
} catch (Exception $e) {
dcCore::app()->con->unlock();
App::con()->unlock();
throw $e;
}
// update blog
dcCore::app()->blog->triggerBlog();
App::blog()->triggerBlog();
// return new widgetText ID
return (int) $cur->getField('option_id');
@ -205,16 +195,15 @@ class Utils
*/
public static function updWidget(int $id, Cursor $cur): void
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->isDefined()) {
throw new Exception(__('Blog is not set'));
}
// check permission to delete post
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
if (!App::auth()->check(App::auth()->makePermissions([
App::auth()::PERMISSION_USAGE,
App::auth()::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id())) {
throw new Exception(__('You are not allowed to update entries text widget'));
}
@ -228,10 +217,10 @@ class Utils
$cur->setField('option_upddt', date('Y-m-d H:i:s'));
// check if user is post owner
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)) {
if (!App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_CONTENT_ADMIN]), App::blog()->id())) {
$rs = self::getWidgets([
'option_id' => $id,
'user_id' => dcCore::app()->con->escapeStr((string) dcCore::app()->auth->userID()),
'user_id' => App::con()->escapeStr(App::auth()->userID()),
'no_content' => true,
'limit' => 1,
]);
@ -245,7 +234,7 @@ class Utils
$cur->update('WHERE option_id = ' . $id . ' ');
// update blog
dcCore::app()->blog->triggerBlog();
App::blog()->triggerBlog();
}
/**
@ -256,16 +245,15 @@ class Utils
*/
public static function delWidget(int $id, ?string $type = null): void
{
// nullsafe
if (is_null(dcCore::app()->blog)) {
if (!App::blog()->idDefined()) {
throw new Exception(__('Blog is not set'));
}
// check permission to delete post
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_DELETE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
if (!App::auth()->check(App::auth()->makePermissions([
App::auth()::PERMISSION_DELETE,
App::auth()::PERMISSION_CONTENT_ADMIN,
]), App::blog()->id())) {
throw new Exception(__('You are not allowed to delete entries text widget'));
}
@ -278,10 +266,10 @@ class Utils
}
// check if user is post owner
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)) {
if (!App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_CONTENT_ADMIN]), App::blog()->id())) {
$rs = self::getWidgets([
'option_id' => $id,
'user_id' => dcCore::app()->con->escapeStr((string) dcCore::app()->auth->userID()),
'user_id' => App::con()->escapeStr(App::auth()->userID()),
'no_content' => true,
'limit' => 1,
]);
@ -293,13 +281,13 @@ class Utils
// delete widgetText
$sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . My::TABLE_NAME)
$sql->from(App::con()->prefix() . My::TABLE_NAME)
->where('option_id = ' . $id)
->and('option_type = ' . $sql->quote($type))
->delete();
// update blog
dcCore::app()->blog->triggerBlog();
App::blog()->triggerBlog();
}
/**
@ -314,16 +302,16 @@ class Utils
public static function setWidgetContent(int $option_id, string $format, string $lang, ?string &$content, ?string &$content_xhtml): void
{
if ($format == 'wiki') {
dcCore::app()->initWikiPost();
dcCore::app()->wiki2xhtml->setOpt('note_prefix', 'wnote-' . $option_id);
App::filter()->initWikiPost();
App::filter()->wiki()->setOpt('note_prefix', 'wnote-' . $option_id);
if (strpos($lang, 'fr') === 0) {
dcCore::app()->wiki2xhtml->setOpt('active_fr_syntax', 1);
App::filter()->wiki()->setOpt('active_fr_syntax', 1);
}
}
if ($content) {
$content_xhtml = dcCore::app()->callFormater($format, $content);
$content_xhtml = dcCore::app()->HTMLfilter($content_xhtml);
$content_xhtml = App::formater()->callEditorFormater('dcLegacyEditor', $format, $content);
$content_xhtml = App::filter()->HTMLfilter($content_xhtml);
} else {
$content_xhtml = '';
}
@ -331,7 +319,7 @@ class Utils
$excerpt = $excerpt_xhtml = '';
# --BEHAVIOR-- coreAfterPostContentFormat -- array
dcCore::app()->callBehavior('coreAfterPostContentFormat', [
App::behavior()->callBehavior('coreAfterPostContentFormat', [
'excerpt' => &$excerpt,
'content' => &$content,
'excerpt_xhtml' => &$excerpt_xhtml,

View File

@ -1,28 +1,20 @@
<?php
/**
* @brief postWidgetText, 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\postWidgetText;
use dcCore;
use Dotclear\App;
use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement;
/**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin and public widget methods.
* @since 2.6
* @brief postWidgetText widgets class.
* @ingroup postWidgetText
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Widgets
{
@ -37,7 +29,7 @@ class Widgets
->create(
basename(__DIR__),
__('Post widget text'),
[self::class, 'parseWidget'],
self::parseWidget(...),
null,
__('Add a widget with a text related to an entry')
)
@ -68,9 +60,8 @@ class Widgets
{
if ($w->__get('offline')
|| !Utils::isActive()
|| is_null(dcCore::app()->ctx)
|| !dcCore::app()->ctx->exists('posts')
|| !dcCore::app()->ctx->__get('posts')->f('post_id')
|| !App::frontend()->context()->exists('posts')
|| !App::frontend()->context()->__get('posts')->f('post_id')
) {
return '';
}
@ -78,7 +69,7 @@ class Widgets
$title = $w->__get('title') ?: null;
$content = '';
$rs = Utils::getWidgets(['post_id' => dcCore::app()->ctx->__get('posts')->f('post_id')]);
$rs = Utils::getWidgets(['post_id' => App::frontend()->context()->__get('posts')->f('post_id')]);
if ($rs->isEmpty()) {
return '';
}
@ -86,11 +77,11 @@ class Widgets
if ('' != $rs->f('option_title')) {
$title = $rs->f('option_title');
}
if ('' != $rs->f('option_content_xhtml')) {
$content = $rs->f('option_content_xhtml');
if ('' != $rs->f('option_content')) {
$content = $rs->f('option_content');
}
if ('' == $content && $w->__get('excerpt')) {
$content = dcCore::app()->ctx->__get('posts')->f('post_excerpt_xhtml');
$content = App::frontend()->context()->__get('posts')->f('post_excerpt');
}
return $w->renderDiv(