postWidgetText/_widgets.php

99 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
*
* @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->blog->settings->addNamespace('postwidgettext');
2021-10-29 21:51:56 +00:00
$core->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(
'postwidgettext',
__('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)
{
global $core, $_ctx;
2021-10-29 21:51:56 +00:00
if ($w->offline) {
return null;
}
2021-09-10 19:18:51 +00:00
if (!$core->blog->settings->postwidgettext->postwidgettext_active
2021-10-29 21:51:56 +00:00
|| !$_ctx->exists('posts')
|| !$_ctx->posts->post_id
2021-09-10 19:18:51 +00:00
) {
return null;
}
2021-10-29 21:51:56 +00:00
$title = $w->title ?: null;
2021-09-10 19:18:51 +00:00
$content = '';
$pwt = new postWidgetText($core);
2021-10-29 21:51:56 +00:00
$rs = $pwt->getWidgets(['post_id' => $_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) {
$content = $_ctx->posts->post_excerpt_xhtml;
}
2021-10-29 21:51:56 +00:00
return $w->renderDiv(
$w->content_only,
'postwidgettext ' . $w->class,
'',
($title ? $w->renderTitle(html::escapeHTML($title)) : '') . $content
);
2021-09-10 19:18:51 +00:00
}
}