create( 'epclist', My::name(), [self::class, 'parseWidget'], null, __('List filtered contents.') ); # Title $w->epclist->addTitle(__('In this article')); # Text $w->epclist->setting( 'text', __('Description:'), '', 'text' ); # Type $w->epclist->setting( 'type', __('Type:'), 'Definition', 'combo', Epc::getFilters()->nid(true) ); # Content foreach (Epc::widgetAllowedTemplateValue() as $name => $info) { $w->epclist->setting( 'content' . $info['id'], sprintf(__('Enable filter on %s'), __($name)), 1, 'check' ); } # Show count $w->epclist->setting( 'show_total', __('Show the number of appearance'), 1, 'check' ); # widget options $w->epclist ->addContentOnly() ->addClass() ->addOffline(); } /** * Public part for widget that show extracted content * * @param WidgetsElement $w WidgetsElement instance */ public static function parseWidget(WidgetsElement $w): string { if ($w->offline) { return ''; } # Page if (!dcCore::app()->blog?->settings->get(My::id())->get('active') || !in_array(dcCore::app()->ctx?->__get('current_tpl'), ['post.html', 'page.html']) ) { return ''; } # Content $content = ''; foreach (Epc::widgetAllowedTemplateValue() as $info) { $ns = 'content' . $info['id']; if ($w->$ns && is_callable($info['cb'])) { $content .= call_user_func( $info['cb'], $w ); } } if (empty($content)) { return ''; } # Filter $list = new ArrayObject(); $filter = Epc::getFilters()->get($w->type); if (!is_null($filter)) { $filter->widgetList($content, $w, $list); } if (!count($list)) { return ''; } # Parse result $res = ''; foreach ($list as $line) { if ((int) $line['total'] == 0) { continue; } $res .= '
' . Html::escapeHTML($w->text) . '
' : '') . '