Compare commits

..

No commits in common. "master" and "v2023.08.15" have entirely different histories.

16 changed files with 313 additions and 229 deletions

View File

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

View File

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

View File

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

20
_init.php 100644
View File

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

View File

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

View File

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

View File

@ -1,19 +1,22 @@
<?php <?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); declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; 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 class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -27,7 +30,7 @@ class Frontend extends Process
return false; return false;
} }
App::behavior()->addBehavior('initWidgets', Widgets::initWidgets(...)); dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
return true; return true;
} }

View File

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

View File

@ -1,21 +1,24 @@
<?php <?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); declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use Dotclear\App; use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; 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 class Install extends Process
{ {
public static function init(): bool public static function init(): bool
@ -31,7 +34,7 @@ class Install extends Process
try { try {
// Table is the same for plugins pollsFactory, postTask, postWidgetText // Table is the same for plugins pollsFactory, postTask, postWidgetText
$s = new Structure(App::con(), App::con()->prefix()); $s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
$s->__get(My::TABLE_NAME) $s->__get(My::TABLE_NAME)
->field('option_id', 'bigint', 0, false) ->field('option_id', 'bigint', 0, false)
->field('post_id', 'bigint', 0, false) ->field('post_id', 'bigint', 0, false)
@ -48,7 +51,7 @@ class Install extends Process
->index('idx_post_option_post', 'btree', 'post_id') ->index('idx_post_option_post', 'btree', 'post_id')
->index('idx_post_option_type', 'btree', 'option_type'); ->index('idx_post_option_type', 'btree', 'option_type');
(new Structure(App::con(), App::con()->prefix()))->synchronize($s); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
// Settings // Settings
$s = My::settings(); $s = My::settings();
@ -71,7 +74,7 @@ class Install extends Process
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
App::error()->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
return false; return false;
} }

View File

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

View File

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

View File

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

View File

@ -1,19 +1,23 @@
<?php <?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); declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; 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 class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
@ -23,7 +27,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }

View File

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

View File

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