diff --git a/src/ManageList.php b/src/ManageList.php index 567ed06..05ed2df 100644 --- a/src/ManageList.php +++ b/src/ManageList.php @@ -31,33 +31,30 @@ use Dotclear\Helper\Html\Html; */ class ManageList extends adminGenericListV2 { - public function display(adminGenericFilterV2 $filter, string $enclose = ''): void + public function display(adminGenericFilterV2 $filter, string $enclose = '%s'): void { + // nullsafe if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { return; } + // prepare page + $blocks = explode('%s', $enclose); + $pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); + $tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC'); + + // no record if ($this->rs->isEmpty()) { - echo '

' . ( - $filter->show() ? - __('No widgets matching the filter.') : __('No widget') - ) . '

'; + echo sprintf( + '

%s

', + $filter->show() ? __('No widgets matching the filter.') : __('No widget') + ); return; } - $pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); - - $content = '
' . - '' . - '' . - ''; - - $cols = new ArrayObject([ + // table head line + $thead = new ArrayObject([ 'name' => '', 'post_dt' => '', 'option_title' => '', @@ -66,49 +63,65 @@ class ManageList extends adminGenericListV2 'post_type' => '', ]); - $this->userColumns(My::id(), $cols); + $this->userColumns(My::id(), $thead); - $content .= implode(iterator_to_array($cols)) . ''; - - $tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC'); + // display list header + echo + $pager->getLinks() . + ($blocks[0] ?? '') . + sprintf( + '
' . ( - $filter->show() ? - sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) : - sprintf(__('List of widgets (%s)'), $this->rs_count) - ) . '
' . __('Post title') . '' . __('Post date') . '' . __('Widget title') . '' . __('Type') . '
%s', + $filter->show() ? + sprintf(__('List of %s widgets matching the filter.'), $this->rs_count) : + sprintf(__('List of widgets (%s)'), $this->rs_count), + implode(iterator_to_array($thead)) + ); + // parses lines while ($this->rs->fetch()) { $w_title = Html::escapeHTML($this->rs->option_title); if ($w_title == '') { - $w_title = '' . context::global_filters( + // widget title can accept HTML, but backend table not + $w_title = context::global_filters( $this->rs->option_content, [ 'encode_xml', 'remove_html', 'cut_string' => 80, ] - ) . ''; + ); } - $cols = new ArrayObject([ - 'check' => '', - 'name' => '', + 'name' => '', 'post_dt' => '', 'option_title' => '', 'option_creadt' => '', 'user_id' => '', 'post_type' => '', - ]); - $this->userColumns(My::id(), $cols); + $this->userColumns(My::id(), $tbody); - $content .= '' . - implode(iterator_to_array($cols)) . + // display table body line + echo + '' . + implode(iterator_to_array($tbody)) . ''; } - $content .= '
%s
' . (new Checkbox(['widgets[]'], (bool) $this->rs->f('option_id')))->value($this->rs->f('option_id'))->disabled(!$this->rs->isEditable())->render() . '' . + // table body line + $tbody = new ArrayObject([ + 'check' => '' . + (new Checkbox(['widgets[]'], (bool) in_array($this->rs->f('option_id'), $_REQUEST['widgets'] ?? []))) + ->__call('value', [$this->rs->f('option_id')]) + ->__call('disabled', [!$this->rs->isEditable()]) + ->render() . + '' . Html::escapeHTML($this->rs->f('post_title')) . '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt'), $tz) . '' . $w_title . '' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('option_upddt'), $tz) . '' . $this->rs->f('user_id') . '' . $this->rs->f('post_type') . '
'; - + // display list footer echo - $pager->getLinks() . - sprintf($enclose, $content) . - $pager->getLinks(); + '' . + ($blocks[1] ?? ''). + $pager->getLinks(); } }