diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 8a3f96c..625f6d1 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -23,9 +23,19 @@ use dcPage; use dcPostsActions; use dcRecord; use dcSettings; +use Dotclear\Helper\Html\Form\{ + Checkbox, + Div, + Form, + Hidden, + Label, + Para, + Select, + Submit, + Text +}; +use Dotclear\Helper\Html\Html; use Exception; -use form; -use html; /** * @ingroup DC_PLUGIN_PERIODICAL @@ -46,24 +56,28 @@ class BackendBehaviors $s = $blog_settings->get('periodical'); echo - '

' . __('Periodical') . '

' . - '
' . - '
' . - '

' . - '
' . - '
' . - '

' . - '

' . - '
' . - '
' . - '
' . - '
'; + (new Div())->class('fieldset')->items([ + (new Text('h4', __('Periodical')))->id('periodical_params'), + (new Div())->class('two-cols')->items([ + (new Div())->class('col')->items([ + (new Para())->items([ + (new Checkbox('periodical_active', (bool) $s->get('periodical_active')))->value(1), + (new Label(__('Enable periodical on this blog'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_active')->class('classic'), + ]), + ]), + (new Div())->class('col')->items([ + (new Para())->items([ + (new Checkbox('periodical_upddate', (bool) $s->get('periodical_upddate')))->value(1), + (new Label(__('Update post date when publishing it'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_upddate')->class('classic'), + ]), + (new Para())->items([ + (new Checkbox('periodical_updurl', (bool) $s->get('periodical_updurl')))->value(1), + (new Label(__('Update post url when publishing it'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_updurl')->class('classic'), + ]), + ]), + ]), + (new Text('br'))->class('clear'), + ])->render(); } /** @@ -145,7 +159,7 @@ class BackendBehaviors $name = '-'; } else { $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]); - $name = '' . html::escapeHTML($r->f('periodical_title')) . ''; + $name = '' . Html::escapeHTML($r->f('periodical_title')) . ''; } $cols['period'] = '' . $name . ''; } @@ -274,24 +288,25 @@ class BackendBehaviors else { $pa->beginPage( dcPage::breadcrumb([ - html::escapeHTML(dcCore::app()->blog->name) => '', + Html::escapeHTML(dcCore::app()->blog->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), __('Add a period to this selection') => '', ]) ); echo - '
' . - $pa->getCheckboxes() . - - self::formPeriod() . - - '

' . - dcCore::app()->formNonce() . - $pa->getHiddenFields() . - form::hidden(['action'], 'periodical_add') . - '

' . - '
'; + (new Form('periodicaladd'))->method('post')->action($pa->getURI())->fields([ + (new Text('', $pa->getCheckboxes())), + self::formPeriod(0), + (new Para())->items(array_merge( + [ + dcCore::app()->formNonce(false), + (new Hidden(['action'], 'periodical_add')), + (new Submit(['do']))->value(__('Save')), + ], + $pa->hiddenFields() + )), + ])->render(); $pa->endPage(); } @@ -314,7 +329,7 @@ class BackendBehaviors } # Set linked period form items - $sidebar_items['options-box']['items']['period'] = self::formPeriod((int) $period); + $sidebar_items['options-box']['items']['period'] = (string) self::formPeriod((int) $period)?->render(); } /** @@ -340,21 +355,16 @@ class BackendBehaviors * Posts period form field * * @param int $period Period - * @return string Period form content + * @return null|Para Period form object */ - private static function formPeriod(int $period = 0): string + private static function formPeriod(int $period = 0): ?Para { $combo = self::comboPeriod(); - if (empty($combo)) { - return ''; - } - - return - '

' . - form::combo('periodical', $combo, $period) . - '

'; + return empty($combo) ? null : (new Para())->items([ + (new Label(__('Period:')))->for('periodical'), + (new Select('periodical'))->default((string) $period)->items($combo), + ]); } /** @@ -370,7 +380,7 @@ class BackendBehaviors if (!$periods->isEmpty()) { $combo = ['-' => '']; while ($periods->fetch()) { - $combo[html::escapeHTML($periods->f('periodical_title'))] = $periods->f('periodical_id'); + $combo[Html::escapeHTML($periods->f('periodical_title'))] = $periods->f('periodical_id'); } self::$combo_period = $combo; } diff --git a/src/Manage.php b/src/Manage.php index 6f83be8..536f2d1 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -19,9 +19,12 @@ use dcAuth; use dcCore; use dcNsProcess; use dcPage; +use Dotclear\Helper\Html\Form\{ + Hidden, + Select +}; +use Dotclear\Helper\Network\Http; use Exception; -use form; -use http; /** * Admin page for periods @@ -71,7 +74,7 @@ class Manage extends dcNsProcess ); if (!empty($vars->redir)) { - http::redirect($vars->redir); + Http::redirect($vars->redir); } else { dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); } @@ -92,7 +95,7 @@ class Manage extends dcNsProcess ); if (!empty($vars->redir)) { - http::redirect($vars->redir); + Http::redirect($vars->redir); } else { dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); } @@ -153,7 +156,7 @@ class Manage extends dcNsProcess if (isset($period_list)) { # Filters - $p_filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id()) . form::hidden('part', 'periods')); + $p_filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render() . (new Hidden('part', 'periods'))->render()); # Periods list $period_list->periodDisplay( @@ -166,7 +169,7 @@ class Manage extends dcNsProcess '

' . '

' . __('Selected periods action:') . ' ' . - form::combo('action', My::periodsActionCombo()) . + (new Select('action'))->items(My::periodsActionCombo())->render() . '

' . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $p_filter->values(true))) . dcCore::app()->formNonce() . diff --git a/src/ManageList.php b/src/ManageList.php index 8bd7492..2ab6bdf 100644 --- a/src/ManageList.php +++ b/src/ManageList.php @@ -22,9 +22,9 @@ use dcAuth; use dcBlog; use dcCore; use dcPager; +use Dotclear\Helper\Html\Form\Checkbox; +use Dotclear\Helper\Html\Html; use dt; -use html; -use form; /** * @ingroup DC_PLUGIN_PERIODICAL @@ -90,7 +90,7 @@ class ManageList extends adminGenericList $nb_posts = Utils::getPosts(['periodical_id' => $this->rs->f('periodical_id')], true)->f(0); $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]); - $name = '' . html::escapeHTML($this->rs->periodical_title) . ''; + $name = '' . Html::escapeHTML($this->rs->periodical_title) . ''; $posts = $nb_posts ? '' . $nb_posts . '' : @@ -100,7 +100,7 @@ class ManageList extends adminGenericList __((string) array_search($this->rs->f('periodical_pub_int'), My::periodCombo())) : __('Unknow frequence'); $cols = new ArrayObject([ - 'check' => '' . form::checkbox(['periods[]'], $this->rs->f('periodical_id'), ['checked' => $checked]) . '', + 'check' => '' . (new Checkbox(['periods[]'], $checked))->value($this->rs->f('periodical_id'))->render() . '', 'name' => '' . $name . '', 'curdt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_curdt'), dcCore::app()->auth->getInfo('user_tz')) . '', 'pub_int' => '' . $interval . '', @@ -191,7 +191,7 @@ class ManageList extends adminGenericList $cat_title = sprintf( $cat_link, $this->rs->f('cat_id'), - html::escapeHTML($this->rs->f('cat_title')) + Html::escapeHTML($this->rs->f('cat_title')) ); } else { $cat_title = __('None'); @@ -239,9 +239,9 @@ class ManageList extends adminGenericList } $cols = [ - 'check' => '' . form::checkbox(['periodical_entries[]'], $this->rs->f('post_id'), ['checked' => $checked]) . '', + 'check' => '' . (new Checkbox(['periodical_entries[]'], $checked))->value($this->rs->f('post_id'))->render() . '', 'title' => '' . html::escapeHTML($this->rs->post_title) . '', + 'title="' . Html::escapeHTML($this->rs->getURL()) . '">' . Html::escapeHTML($this->rs->post_title) . '', 'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '', 'category' => '' . $cat_title . '', 'author' => '' . $this->rs->f('user_id') . '', diff --git a/src/ManagePeriod.php b/src/ManagePeriod.php index 260abe1..76f98a6 100644 --- a/src/ManagePeriod.php +++ b/src/ManagePeriod.php @@ -19,10 +19,22 @@ use dcAuth; use dcCore; use dcNsProcess; use dcPage; +use Dotclear\Helper\Html\Form\{ + Datetime, + Div, + Form, + Hidden, + Input, + Label, + Number, + Para, + Select, + Submit, + Text +}; +use Dotclear\Helper\Html\Html; +use Dotclear\Helper\Network\Http; use Exception; -use form; -use html; -use http; /** * Admin page for a period @@ -205,47 +217,46 @@ class ManagePeriod extends dcNsProcess dcPage::notices(); # Period form - echo ' -

' . (null === $vars->period_id ? __('New period') : __('Edit period')) . '

-
+ echo + (new Div('period'))->items([ + (new Text('h3', null === $vars->period_id ? __('New period') : __('Edit period'))), + (new Form('periodicalbhv'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([ + (new Para())->items([ + (new Label(__('Title:')))->for('period_title'), + (new Input('period_title'))->size(65)->maxlenght(255)->class('maximal')->value(Html::escapeHTML($vars->period_title)), + ]), + (new Div())->class('two-boxes')->items([ + (new Para())->items([ + (new Label(__('Next update:')))->for('period_curdt'), + (new Datetime('period_curdt', Html::escapeHTML(Dater::toUser($vars->period_curdt))))->class($vars->bad_period_curdt ? 'invalid' : ''), + ]), + (new Para())->items([ + (new Label(__('End date:')))->for('period_enddt'), + (new Datetime('period_enddt', Html::escapeHTML(Dater::toUser($vars->period_enddt))))->class($vars->bad_period_enddt ? 'invalid' : ''), + ]), + ]), + (new Div())->class('two-boxes')->items([ + (new Para())->items([ + (new Label(__('Publication frequency:'), Label::OUTSIDE_LABEL_BEFORE))->for('period_pub_int'), + (new Select('period_pub_int'))->default($vars->period_pub_int)->items(My::periodCombo()), + ]), + (new Para())->items([ + (new Label(__('Number of entries to publish every time:'), Label::OUTSIDE_LABEL_BEFORE))->for('period_pub_nb'), + (new Number('period_pub_nb'))->min(1)->max(20)->value($vars->period_pub_nb), + ]), + ]), -

' . - form::field('period_title', 60, 255, html::escapeHTML($vars->period_title), 'maximal') . '

- -
- -

' . - form::datetime('period_curdt', [ - 'default' => html::escapeHTML(Dater::toUser($vars->period_curdt)), - 'class' => ($vars->bad_period_curdt ? 'invalid' : ''), - ]) . '

- -

' . - form::datetime('period_enddt', [ - 'default' => html::escapeHTML(Dater::toUser($vars->period_enddt)), - 'class' => ($vars->bad_period_enddt ? 'invalid' : ''), - ]) . '

- -
- -

' . - form::combo('period_pub_int', My::periodCombo(), $vars->period_pub_int) . '

- -

' . - form::number('period_pub_nb', ['min' => 1, 'max' => 20, 'default' => $vars->period_pub_nb]) . '

- -
- -
-

' . - dcCore::app()->formNonce() . - form::hidden(['action'], 'setperiod') . - form::hidden(['period_id'], $vars->period_id) . - form::hidden(['part'], 'period') . ' -

-
-
-
'; + (new Div())->class('clear')->items([ + (new Para())->items([ + (new Submit(['save']))->value(__('Save')), + dcCore::app()->formNonce(false), + (new Hidden(['action'], 'setperiod')), + (new Hidden(['period_id'], (string) $vars->period_id)), + (new Hidden(['part'], 'period')), + ]), + ]), + ]), + ])->render(); if ($vars->period_id && isset($post_filter) && isset($post_list) && !dcCore::app()->error->flag()) { $base_url = dcCore::app()->admin->getPageURL() . @@ -288,7 +299,7 @@ class ManagePeriod extends dcNsProcess '

' . '

' . __('Selected entries action:') . ' ' . - form::combo('action', My::entriesActionsCombo()) . + (new Select('action'))->items(My::entriesActionsCombo())->redner() . '

' . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [ 'period_id' => $vars->period_id, @@ -313,7 +324,7 @@ class ManagePeriod extends dcNsProcess dcPage::addSuccessNotice($msg); if (!empty($redir)) { - http::redirect($redir); + Http::redirect($redir); } else { dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $id], $tab); } diff --git a/src/Utils.php b/src/Utils.php index 4bedb1f..8fa5c77 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -20,9 +20,9 @@ use dcBlog; use dcCore; use dcMeta; use dcRecord; +use Dotclear\Helper\File\Files; +use Dotclear\Helper\File\Path; use Exception; -use files; -use path; /** * Manage records @@ -363,13 +363,13 @@ class Utils $f_md5 ); # Real path - $cached_file = path::real($cached_file, false); + $cached_file = Path::real($cached_file, false); if (is_bool($cached_file)) { throw new Exception("Can't write in cache fodler"); } # Make dir if (!is_dir(dirname($cached_file))) { - files::makeDir(dirname($cached_file), true); + Files::makeDir(dirname($cached_file), true); } # Make file if (!file_exists($cached_file)) {