use Dotclear Helper

This commit is contained in:
Jean-Christian Denis 2023-04-08 14:15:18 +02:00
parent 6fa20dbf48
commit f269e109bd
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 132 additions and 108 deletions

View file

@ -23,9 +23,19 @@ use dcPage;
use dcPostsActions; use dcPostsActions;
use dcRecord; use dcRecord;
use dcSettings; use dcSettings;
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
Form,
Hidden,
Label,
Para,
Select,
Submit,
Text
};
use Dotclear\Helper\Html\Html;
use Exception; use Exception;
use form;
use html;
/** /**
* @ingroup DC_PLUGIN_PERIODICAL * @ingroup DC_PLUGIN_PERIODICAL
@ -46,24 +56,28 @@ class BackendBehaviors
$s = $blog_settings->get('periodical'); $s = $blog_settings->get('periodical');
echo echo
'<div class="fieldset"><h4 id="periodical_params">' . __('Periodical') . '</h4>' . (new Div())->class('fieldset')->items([
'<div class="two-cols">' . (new Text('h4', __('Periodical')))->id('periodical_params'),
'<div class="col">' . (new Div())->class('two-cols')->items([
'<p><label class="classic" for="periodical_active">' . (new Div())->class('col')->items([
form::checkbox('periodical_active', 1, (bool) $s->get('periodical_active')) . (new Para())->items([
__('Enable periodical on this blog') . '</label></p>' . (new Checkbox('periodical_active', (bool) $s->get('periodical_active')))->value(1),
'</div>' . (new Label(__('Enable periodical on this blog'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_active')->class('classic'),
'<div class="col">' . ]),
'<p><label for="periodical_upddate">' . ]),
form::checkbox('periodical_upddate', 1, (bool) $s->get('periodical_upddate')) . (new Div())->class('col')->items([
__('Update post date when publishing it') . '</label></p>' . (new Para())->items([
'<p><label for="periodical_updurl">' . (new Checkbox('periodical_upddate', (bool) $s->get('periodical_upddate')))->value(1),
form::checkbox('periodical_updurl', 1, (bool) $s->get('periodical_updurl')) . (new Label(__('Update post date when publishing it'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_upddate')->class('classic'),
__('Update post url when publishing it') . '</label></p>' . ]),
'</div>' . (new Para())->items([
'</div>' . (new Checkbox('periodical_updurl', (bool) $s->get('periodical_updurl')))->value(1),
'<br class="clear" />' . (new Label(__('Update post url when publishing it'), Label::OUTSIDE_LABEL_AFTER))->for('periodical_updurl')->class('classic'),
'</div>'; ]),
]),
]),
(new Text('br'))->class('clear'),
])->render();
} }
/** /**
@ -145,7 +159,7 @@ class BackendBehaviors
$name = '-'; $name = '-';
} else { } else {
$url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]); $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($r->f('periodical_title')) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($r->f('periodical_title')) . '</a>';
} }
$cols['period'] = '<td class="nowrap">' . $name . '</td>'; $cols['period'] = '<td class="nowrap">' . $name . '</td>';
} }
@ -274,24 +288,25 @@ class BackendBehaviors
else { else {
$pa->beginPage( $pa->beginPage(
dcPage::breadcrumb([ dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true), $pa->getCallerTitle() => $pa->getRedirection(true),
__('Add a period to this selection') => '', __('Add a period to this selection') => '',
]) ])
); );
echo echo
'<form action="' . $pa->getURI() . '" method="post">' . (new Form('periodicaladd'))->method('post')->action($pa->getURI())->fields([
$pa->getCheckboxes() . (new Text('', $pa->getCheckboxes())),
self::formPeriod(0),
self::formPeriod() . (new Para())->items(array_merge(
[
'<p>' . dcCore::app()->formNonce(false),
dcCore::app()->formNonce() . (new Hidden(['action'], 'periodical_add')),
$pa->getHiddenFields() . (new Submit(['do']))->value(__('Save')),
form::hidden(['action'], 'periodical_add') . ],
'<input type="submit" value="' . __('Save') . '" /></p>' . $pa->hiddenFields()
'</form>'; )),
])->render();
$pa->endPage(); $pa->endPage();
} }
@ -314,7 +329,7 @@ class BackendBehaviors
} }
# Set linked period form items # 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 * Posts period form field
* *
* @param int $period Period * @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(); $combo = self::comboPeriod();
if (empty($combo)) { return empty($combo) ? null : (new Para())->items([
return ''; (new Label(__('Period:')))->for('periodical'),
} (new Select('periodical'))->default((string) $period)->items($combo),
]);
return
'<p><label for="periodical">' .
__('Periodical') . '</label>' .
form::combo('periodical', $combo, $period) .
'</p>';
} }
/** /**
@ -370,7 +380,7 @@ class BackendBehaviors
if (!$periods->isEmpty()) { if (!$periods->isEmpty()) {
$combo = ['-' => '']; $combo = ['-' => ''];
while ($periods->fetch()) { 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; self::$combo_period = $combo;
} }

View file

@ -19,9 +19,12 @@ use dcAuth;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcPage; use dcPage;
use Dotclear\Helper\Html\Form\{
Hidden,
Select
};
use Dotclear\Helper\Network\Http;
use Exception; use Exception;
use form;
use http;
/** /**
* Admin page for periods * Admin page for periods
@ -71,7 +74,7 @@ class Manage extends dcNsProcess
); );
if (!empty($vars->redir)) { if (!empty($vars->redir)) {
http::redirect($vars->redir); Http::redirect($vars->redir);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']);
} }
@ -92,7 +95,7 @@ class Manage extends dcNsProcess
); );
if (!empty($vars->redir)) { if (!empty($vars->redir)) {
http::redirect($vars->redir); Http::redirect($vars->redir);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']);
} }
@ -153,7 +156,7 @@ class Manage extends dcNsProcess
if (isset($period_list)) { if (isset($period_list)) {
# Filters # 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 # Periods list
$period_list->periodDisplay( $period_list->periodDisplay(
@ -166,7 +169,7 @@ class Manage extends dcNsProcess
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . __('Selected periods action:') . ' ' . '<p class="col right">' . __('Selected periods action:') . ' ' .
form::combo('action', My::periodsActionCombo()) . (new Select('action'))->items(My::periodsActionCombo())->render() .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $p_filter->values(true))) . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $p_filter->values(true))) .
dcCore::app()->formNonce() . dcCore::app()->formNonce() .

View file

@ -22,9 +22,9 @@ use dcAuth;
use dcBlog; use dcBlog;
use dcCore; use dcCore;
use dcPager; use dcPager;
use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html;
use dt; use dt;
use html;
use form;
/** /**
* @ingroup DC_PLUGIN_PERIODICAL * @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); $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')]); $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($this->rs->periodical_title) . '</a>';
$posts = $nb_posts ? $posts = $nb_posts ?
'<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' : '<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' :
@ -100,7 +100,7 @@ class ManageList extends adminGenericList
__((string) array_search($this->rs->f('periodical_pub_int'), My::periodCombo())) : __('Unknow frequence'); __((string) array_search($this->rs->f('periodical_pub_int'), My::periodCombo())) : __('Unknow frequence');
$cols = new ArrayObject([ $cols = new ArrayObject([
'check' => '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->f('periodical_id'), ['checked' => $checked]) . '</td>', 'check' => '<td class="nowrap">' . (new Checkbox(['periods[]'], $checked))->value($this->rs->f('periodical_id'))->render() . '</td>',
'name' => '<td class="maximal">' . $name . '</td>', 'name' => '<td class="maximal">' . $name . '</td>',
'curdt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_curdt'), dcCore::app()->auth->getInfo('user_tz')) . '</td>', 'curdt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('periodical_curdt'), dcCore::app()->auth->getInfo('user_tz')) . '</td>',
'pub_int' => '<td class="nowrap">' . $interval . '</td>', 'pub_int' => '<td class="nowrap">' . $interval . '</td>',
@ -191,7 +191,7 @@ class ManageList extends adminGenericList
$cat_title = sprintf( $cat_title = sprintf(
$cat_link, $cat_link,
$this->rs->f('cat_id'), $this->rs->f('cat_id'),
html::escapeHTML($this->rs->f('cat_title')) Html::escapeHTML($this->rs->f('cat_title'))
); );
} else { } else {
$cat_title = __('None'); $cat_title = __('None');
@ -239,9 +239,9 @@ class ManageList extends adminGenericList
} }
$cols = [ $cols = [
'check' => '<td class="minimal">' . form::checkbox(['periodical_entries[]'], $this->rs->f('post_id'), ['checked' => $checked]) . '</td>', 'check' => '<td class="minimal">' . (new Checkbox(['periodical_entries[]'], $checked))->value($this->rs->f('post_id'))->render() . '</td>',
'title' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '" ' . 'title' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '" ' .
'title="' . html::escapeHTML($this->rs->getURL()) . '">' . html::escapeHTML($this->rs->post_title) . '</a></td>', 'title="' . Html::escapeHTML($this->rs->getURL()) . '">' . Html::escapeHTML($this->rs->post_title) . '</a></td>',
'date' => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '</td>', 'date' => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '</td>',
'category' => '<td class="nowrap">' . $cat_title . '</td>', 'category' => '<td class="nowrap">' . $cat_title . '</td>',
'author' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>', 'author' => '<td class="nowrap">' . $this->rs->f('user_id') . '</td>',

View file

@ -19,10 +19,22 @@ use dcAuth;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcPage; 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 Exception;
use form;
use html;
use http;
/** /**
* Admin page for a period * Admin page for a period
@ -205,47 +217,46 @@ class ManagePeriod extends dcNsProcess
dcPage::notices(); dcPage::notices();
# Period form # Period form
echo ' echo
<div id="period"><h3>' . (null === $vars->period_id ? __('New period') : __('Edit period')) . '</h3> (new Div('period'))->items([
<form method="post" action="' . dcCore::app()->admin->getPageURL() . '"> (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),
]),
]),
<p><label for="period_title">' . __('Title:') . '</label>' . (new Div())->class('clear')->items([
form::field('period_title', 60, 255, html::escapeHTML($vars->period_title), 'maximal') . '</p> (new Para())->items([
(new Submit(['save']))->value(__('Save')),
<div class="two-boxes"> dcCore::app()->formNonce(false),
(new Hidden(['action'], 'setperiod')),
<p><label for="period_curdt">' . __('Next update:') . '</label>' . (new Hidden(['period_id'], (string) $vars->period_id)),
form::datetime('period_curdt', [ (new Hidden(['part'], 'period')),
'default' => html::escapeHTML(Dater::toUser($vars->period_curdt)), ]),
'class' => ($vars->bad_period_curdt ? 'invalid' : ''), ]),
]) . '</p> ]),
])->render();
<p><label for="period_enddt">' . __('End date:') . '</label>' .
form::datetime('period_enddt', [
'default' => html::escapeHTML(Dater::toUser($vars->period_enddt)),
'class' => ($vars->bad_period_enddt ? 'invalid' : ''),
]) . '</p>
</div><div class="two-boxes">
<p><label for="period_pub_int">' . __('Publication frequency:') . '</label>' .
form::combo('period_pub_int', My::periodCombo(), $vars->period_pub_int) . '</p>
<p><label for="period_pub_nb">' . __('Number of entries to publish every time:') . '</label>' .
form::number('period_pub_nb', ['min' => 1, 'max' => 20, 'default' => $vars->period_pub_nb]) . '</p>
</div>
<div class="clear">
<p><input type="submit" name="save" value="' . __('Save') . '" />' .
dcCore::app()->formNonce() .
form::hidden(['action'], 'setperiod') .
form::hidden(['period_id'], $vars->period_id) .
form::hidden(['part'], 'period') . '
</p>
</div>
</form>
</div>';
if ($vars->period_id && isset($post_filter) && isset($post_list) && !dcCore::app()->error->flag()) { if ($vars->period_id && isset($post_filter) && isset($post_list) && !dcCore::app()->error->flag()) {
$base_url = dcCore::app()->admin->getPageURL() . $base_url = dcCore::app()->admin->getPageURL() .
@ -288,7 +299,7 @@ class ManagePeriod extends dcNsProcess
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . __('Selected entries action:') . ' ' . '<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action', My::entriesActionsCombo()) . (new Select('action'))->items(My::entriesActionsCombo())->redner() .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [ dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [
'period_id' => $vars->period_id, 'period_id' => $vars->period_id,
@ -313,7 +324,7 @@ class ManagePeriod extends dcNsProcess
dcPage::addSuccessNotice($msg); dcPage::addSuccessNotice($msg);
if (!empty($redir)) { if (!empty($redir)) {
http::redirect($redir); Http::redirect($redir);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $id], $tab); dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $id], $tab);
} }

View file

@ -20,9 +20,9 @@ use dcBlog;
use dcCore; use dcCore;
use dcMeta; use dcMeta;
use dcRecord; use dcRecord;
use Dotclear\Helper\File\Files;
use Dotclear\Helper\File\Path;
use Exception; use Exception;
use files;
use path;
/** /**
* Manage records * Manage records
@ -363,13 +363,13 @@ class Utils
$f_md5 $f_md5
); );
# Real path # Real path
$cached_file = path::real($cached_file, false); $cached_file = Path::real($cached_file, false);
if (is_bool($cached_file)) { if (is_bool($cached_file)) {
throw new Exception("Can't write in cache fodler"); throw new Exception("Can't write in cache fodler");
} }
# Make dir # Make dir
if (!is_dir(dirname($cached_file))) { if (!is_dir(dirname($cached_file))) {
files::makeDir(dirname($cached_file), true); Files::makeDir(dirname($cached_file), true);
} }
# Make file # Make file
if (!file_exists($cached_file)) { if (!file_exists($cached_file)) {