fix widget rendering

master
Jean-Christian Paul Denis 2021-10-29 23:51:56 +02:00
parent 374c9590b7
commit 326705c351
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 40 additions and 56 deletions

View File

@ -12,16 +12,12 @@
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->blog->settings->addNamespace('postwidgettext'); $core->blog->settings->addNamespace('postwidgettext');
$core->addBehavior( $core->addBehavior('initWidgets', ['postWidgetTextWidget', 'init']);
'initWidgets',
array('postWidgetTextWidget', 'init')
);
/** /**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT * @ingroup DC_PLUGIN_POSTWIDGETTEXT
@ -32,50 +28,40 @@ class postWidgetTextWidget
{ {
public static function init($w) public static function init($w)
{ {
global $core; $w
->create(
$w->create(
'postwidgettext', 'postwidgettext',
__('Post widget text'), __('Post widget text'),
array('postWidgetTextWidget', 'display'), ['postWidgetTextWidget', 'display'],
null, null,
__('Add a widget with a text related to an entry') __('Add a widget with a text related to an entry')
); )
$w->postwidgettext->setting( ->addTitle(__('More about this entry'))
'title', ->setting(
__('Title:'),
__('More about this entry'),
'text'
);
$w->postwidgettext->setting(
'excerpt', 'excerpt',
__('Use excerpt if no content'), __('Use excerpt if no content'),
0, 0,
'check' 'check'
); )
$w->postwidgettext->setting( ->setting(
'show', 'show',
__('Show widget even if empty'), __('Show widget even if empty'),
0, 0,
'check' 'check'
); )
$w->postwidgettext->setting( ->addContentOnly()
'content_only', ->addClass()
__('Content only'), ->addOffline();
0,
'check'
);
$w->postwidgettext->setting(
'class',
__('CSS class:'),
''
);
} }
public static function display($w) public static function display($w)
{ {
global $core, $_ctx; global $core, $_ctx;
if ($w->offline) {
return null;
}
if (!$core->blog->settings->postwidgettext->postwidgettext_active if (!$core->blog->settings->postwidgettext->postwidgettext_active
|| !$_ctx->exists('posts') || !$_ctx->exists('posts')
|| !$_ctx->posts->post_id || !$_ctx->posts->post_id
@ -83,15 +69,14 @@ class postWidgetTextWidget
return null; return null;
} }
$title = (strlen($w->title) > 0) ? $title = $w->title ?: null;
'<h2>'.html::escapeHTML($w->title).'</h2>' : null;
$content = ''; $content = '';
$pwt = new postWidgetText($core); $pwt = new postWidgetText($core);
$rs = $pwt->getWidgets(array('post_id'=>$_ctx->posts->post_id)); $rs = $pwt->getWidgets(['post_id' => $_ctx->posts->post_id]);
if ('' != $rs->option_title) { if ('' != $rs->option_title) {
$title = '<h2>'.$rs->option_title.'</h2>'; $title = $rs->option_title;
} }
if ('' != $rs->option_content_xhtml) { if ('' != $rs->option_content_xhtml) {
$content = $rs->option_content_xhtml; $content = $rs->option_content_xhtml;
@ -100,12 +85,11 @@ class postWidgetTextWidget
$content = $_ctx->posts->post_excerpt_xhtml; $content = $_ctx->posts->post_excerpt_xhtml;
} }
return '' == $content && !$w->show ? return $w->renderDiv(
null : $w->content_only,
($w->content_only ? '' : '<div class="postwidgettext'. 'postwidgettext ' . $w->class,
($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). '',
$title. ($title ? $w->renderTitle(html::escapeHTML($title)) : '') . $content
$content. );
($w->content_only ? '' : '</div>');
} }
} }