addBehavior('initWidgets', ['postWidgetTextWidget', 'init']); /** * @ingroup DC_PLUGIN_POSTWIDGETTEXT * @brief postWidgetText - admin and public widget methods. * @since 2.6 */ class postWidgetTextWidget { public static function init($w) { $w ->create( basename(__DIR__), __('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(); } public static function display($w) { if ($w->offline || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') || !dcCore::app()->ctx->exists('posts') || !dcCore::app()->ctx->__get('posts')->post_id ) { return null; } $title = $w->title ?: null; $content = ''; $pwt = new postWidgetText(); $rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->__get('posts')->post_id]); if ($rs->isEmpty()) { return null; } if ('' != $rs->option_title) { $title = $rs->option_title; } if ('' != $rs->option_content_xhtml) { $content = $rs->option_content_xhtml; } if ('' == $content && $w->excerpt) { $content = dcCore::app()->ctx->__get('posts')->post_excerpt_xhtml; } return $w->renderDiv( $w->content_only, basename(__DIR__) . ' ' . $w->class, '', ($title ? $w->renderTitle(html::escapeHTML($title)) : '') . $content ); } }