postWidgetText/_widgets.php

95 lines
2.4 KiB
PHP
Raw Normal View History

2021-09-10 19:18:51 +00:00
<?php
/**
* @brief postWidgetText, a plugin for Dotclear 2
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
2022-11-15 21:05:23 +00:00
dcCore::app()->addBehavior('initWidgets', ['postWidgetTextWidget', 'init']);
2021-09-10 19:18:51 +00:00
/**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin and public widget methods.
* @since 2.6
*/
class postWidgetTextWidget
{
public static function init($w)
{
2021-10-29 21:51:56 +00:00
$w
->create(
basename(__DIR__),
2021-10-29 21:51:56 +00:00
__('Post widget text'),
['postWidgetTextWidget', 'display'],
null,
__('Add a widget with a text related to an entry')
)
->addTitle(__('More about this entry'))
->setting(
'excerpt',
__('Use excerpt if no content'),
0,
'check'
)
->setting(
'show',
__('Show widget even if empty'),
0,
'check'
)
->addContentOnly()
->addClass()
->addOffline();
2021-09-10 19:18:51 +00:00
}
public static function display($w)
{
2021-10-29 21:51:56 +00:00
if ($w->offline) {
return null;
}
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')
2022-11-15 21:05:23 +00:00
|| !dcCore::app()->ctx->exists('posts')
|| !dcCore::app()->ctx->posts->post_id
2021-09-10 19:18:51 +00:00
) {
return null;
}
2021-11-06 15:11:19 +00:00
$title = $w->title ?: null;
2021-09-10 19:18:51 +00:00
$content = '';
2022-11-15 21:05:23 +00:00
$pwt = new postWidgetText();
$rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->posts->post_id]);
2021-09-10 19:18:51 +00:00
2021-10-30 20:09:59 +00:00
if ($rs->isEmpty()) {
return null;
}
2021-09-10 19:18:51 +00:00
if ('' != $rs->option_title) {
2021-10-29 21:51:56 +00:00
$title = $rs->option_title;
2021-09-10 19:18:51 +00:00
}
if ('' != $rs->option_content_xhtml) {
$content = $rs->option_content_xhtml;
}
if ('' == $content && $w->excerpt) {
2022-11-15 21:05:23 +00:00
$content = dcCore::app()->ctx->posts->post_excerpt_xhtml;
2021-09-10 19:18:51 +00:00
}
2021-10-29 21:51:56 +00:00
return $w->renderDiv(
$w->content_only,
basename(__DIR__) . ' ' . $w->class,
2021-10-29 21:51:56 +00:00
'',
($title ? $w->renderTitle(html::escapeHTML($title)) : '') . $content
);
2021-09-10 19:18:51 +00:00
}
2021-11-06 15:11:19 +00:00
}