cleanup code, fix nav links, fix some urls and hidden fields

This commit is contained in:
Jean-Christian Paul Denis 2021-10-10 11:08:40 +02:00
parent 4169b0533f
commit 67a214bbe8
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951

183
index.php
View File

@ -12,13 +12,12 @@
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
if ($core->getVersion('zoneclearFeedServer') != if ($core->getVersion('zoneclearFeedServer') !=
$core->plugins->moduleInfo('zoneclearFeedServer', 'version')) { $core->plugins->moduleInfo('zoneclearFeedServer', 'version')
) {
return null; return null;
} }
@ -33,7 +32,6 @@ $zcfs = new zoneclearFeedServer($core);
############################################################ ############################################################
if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$feed_id = ''; $feed_id = '';
$feed_name = ''; $feed_name = '';
$feed_desc = ''; $feed_desc = '';
@ -59,31 +57,27 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$combo_langs = l10n::getISOcodes(true); $combo_langs = l10n::getISOcodes(true);
$combo_status = $zcfs->getAllStatus(); $combo_status = $zcfs->getAllStatus();
$combo_upd_int = $zcfs->getAllUpdateInterval(); $combo_upd_int = $zcfs->getAllUpdateInterval();
$combo_categories = array('-' => ''); $combo_categories = ['-' => ''];
try { try {
$categories = $core->blog->getCategories(array( $categories = $core->blog->getCategories(['post_type' => 'post']);
'post_type' => 'post'
));
while ($categories->fetch()) { while ($categories->fetch()) {
$combo_categories[ $combo_categories[
str_repeat('  ', $categories->level-1) . str_repeat('  ', $categories->level-1) .
'• ' . html::escapeHTML($categories->cat_title) '• ' . html::escapeHTML($categories->cat_title)
] = $categories->cat_id; ] = $categories->cat_id;
} }
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
# Get entry informations # Get entry informations
if (!empty($_REQUEST['feed_id'])) { if (!empty($_REQUEST['feed_id'])) {
$feed = $zcfs->getFeeds(array('feed_id' => $_REQUEST['feed_id'])); $feed = $zcfs->getFeeds(['feed_id' => $_REQUEST['feed_id']]);
if ($feed->isEmpty()) { if ($feed->isEmpty()) {
$core->error->add(__('This feed does not exist.')); $core->error->add(__('This feed does not exist.'));
$can_view_page = false; $can_view_page = false;
} } else {
else {
$feed_id = $feed->feed_id; $feed_id = $feed->feed_id;
$feed_name = $feed->feed_name; $feed_name = $feed->feed_name;
$feed_desc = $feed->feed_desc; $feed_desc = $feed->feed_desc;
@ -137,10 +131,10 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$feed_tags = $_POST['feed_tags']; $feed_tags = $_POST['feed_tags'];
$feed_get_tags = empty($_POST['feed_get_tags']) ? 0 : 1; $feed_get_tags = empty($_POST['feed_get_tags']) ? 0 : 1;
$feed_cat_id = $_POST['feed_cat_id']; $feed_cat_id = $_POST['feed_cat_id'];
$feed_upd_int = $_POST['feed_upd_int'];
if (isset($_POST['feed_status'])) { if (isset($_POST['feed_status'])) {
$feed_status = (integer) $_POST['feed_status']; $feed_status = (integer) $_POST['feed_status'];
} }
$feed_upd_int = $_POST['feed_upd_int'];
$testfeed_params['feed_feed'] = $feed_feed; $testfeed_params['feed_feed'] = $feed_feed;
if ($feed_id) { if ($feed_id) {
@ -165,16 +159,12 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
if ($feed_cat_id != '' && !$get_feed_cat_id) { if ($feed_cat_id != '' && !$get_feed_cat_id) {
throw new Exception(__('You must provide valid category.')); throw new Exception(__('You must provide valid category.'));
} }
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
if (!empty($_POST['action']) && $_POST['action'] == 'savefeed' if (!empty($_POST['action']) && $_POST['action'] == 'savefeed' && !$core->error->flag()) {
&& !$core->error->flag()
) {
$cur = $zcfs->openCursor(); $cur = $zcfs->openCursor();
$cur->feed_name = $feed_name; $cur->feed_name = $feed_name;
$cur->feed_desc = $feed_desc; $cur->feed_desc = $feed_desc;
@ -193,57 +183,39 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
if ($feed_id) { if ($feed_id) {
try { try {
# --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedUpdate # --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedUpdate
$core->callBehavior( $core->callBehavior('adminBeforeZoneclearFeedServerFeedUpdate', $cur, $feed_id);
'adminBeforeZoneclearFeedServerFeedUpdate',
$cur,
$feed_id
);
$zcfs->updFeed($feed_id, $cur); $zcfs->updFeed($feed_id, $cur);
# --BEHAVIOR-- adminAfterZoneclearFeedServerFeedUpdate # --BEHAVIOR-- adminAfterZoneclearFeedServerFeedUpdate
$core->callBehavior( $core->callBehavior('adminAfterZoneclearFeedServerFeedUpdate', $cur, $feed_id);
'adminAfterZoneclearFeedServerFeedUpdate',
$cur,
$feed_id
);
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Feed successfully updated.') __('Feed successfully updated.')
); );
http::redirect( $core->adminurl->redirect(
$p_url.'&part=feed&feed_id='.$feed_id 'admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $feed_id]
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} } else {
else {
try { try {
# --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedCreate # --BEHAVIOR-- adminBeforeZoneclearFeedServerFeedCreate
$core->callBehavior( $core->callBehavior('adminBeforeZoneclearFeedServerFeedCreate', $cur);
'adminBeforeZoneclearFeedServerFeedCreate',
$cur
);
$return_id = $zcfs->addFeed($cur); $return_id = $zcfs->addFeed($cur);
# --BEHAVIOR-- adminAfterZoneclearFeedServerFeedCreate # --BEHAVIOR-- adminAfterZoneclearFeedServerFeedCreate
$core->callBehavior( $core->callBehavior('adminAfterZoneclearFeedServerFeedCreate', $cur, $return_id);
'adminAfterZoneclearFeedServerFeedCreate',
$cur,
$return_id
);
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Feed successfully created.') __('Feed successfully created.')
); );
http::redirect( $core->adminurl->redirect(
$p_url.'&part=feed&feed_id='.$return_id 'admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $return_id]
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -251,7 +223,7 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# Prepared entries list # Prepared entries list
if ($feed_id && $can_view_page) { if ($feed_id && $can_view_page) {
# Posts action # action
$posts_actions_page = new dcPostsActionsPage( $posts_actions_page = new dcPostsActionsPage(
$core, $core,
'plugin.php', 'plugin.php',
@ -262,18 +234,14 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
'_ANCHOR' => 'entries' '_ANCHOR' => 'entries'
] ]
); );
if ($posts_actions_page->process()) { if ($posts_actions_page->process()) {
return null; return null;
} }
/* Get posts # filters
-------------------------------------------------------- */
$post_filter = new adminZcfsPostFilter($core); $post_filter = new adminZcfsPostFilter($core);
$post_filter->add('part', 'feed'); $post_filter->add('part', 'feed');
$post_filter->add('feed_id', $feed_id); $post_filter->add('feed_id', $feed_id);
# get list params
$params = $post_filter->params(); $params = $post_filter->params();
# lexical sort # lexical sort
@ -286,15 +254,14 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# --BEHAVIOR-- adminPostsSortbyLexCombo # --BEHAVIOR-- adminPostsSortbyLexCombo
$core->callBehavior('adminPostsSortbyLexCombo', [& $sortby_lex]); $core->callBehavior('adminPostsSortbyLexCombo', [& $sortby_lex]);
$params['no_content'] = true;
$params['feed_id'] = $feed_id;
$params['order'] = (array_key_exists($post_filter->sortby, $sortby_lex) ? $params['order'] = (array_key_exists($post_filter->sortby, $sortby_lex) ?
$core->con->lexFields($sortby_lex[$post_filter->sortby]) : $core->con->lexFields($sortby_lex[$post_filter->sortby]) :
$post_filter->sortby) . ' ' . $post_filter->order; $post_filter->sortby) . ' ' . $post_filter->order;
$params['no_content'] = true; # posts
# Get posts
try { try {
$params['feed_id'] = $feed_id;
$posts = $zcfs->getPostsByFeed($params); $posts = $zcfs->getPostsByFeed($params);
$counter = $zcfs->getPostsByFeed($params,true); $counter = $zcfs->getPostsByFeed($params,true);
$post_list = new zcfsEntriesList( $post_list = new zcfsEntriesList(
@ -302,13 +269,12 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$posts, $posts,
$counter->f(0) $counter->f(0)
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
# Display # display
echo echo
'<html><head><title>' . __('Feeds server') . '</title>' . '<html><head><title>' . __('Feeds server') . '</title>' .
($feed_id && !$core->error->flag() ? ($feed_id && !$core->error->flag() ?
@ -318,33 +284,30 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
$next_headlink . "\n" . $prev_headlink . $next_headlink . "\n" . $prev_headlink .
# --BEHAVIOR-- packmanAdminHeader # --BEHAVIOR-- adminZoneclearFeedServerHeader
$core->callBehavior('zcfsAdminHeader', $core). $core->callBehavior('adminZoneclearFeedServerHeader', $core) .
'</head><body>' . '</head><body>' .
dcPage::breadcrumb( dcPage::breadcrumb([
array(
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
__('Feeds') => $p_url, __('Feeds') => $p_url,
($feed_id ? __('Edit feed') : __('New feed')) => '' ($feed_id ? __('Edit feed') : __('New feed')) => ''
) ]).
).
dcPage::notices() . dcPage::notices() .
($feed_id ? '<h3>' . sprintf(__('Edit feed "%s"'), $feed_name) .'</h3>' : ''); ($feed_id ? '<h3>' . sprintf(__('Edit feed "%s"'), $feed_name) .'</h3>' : '');
# Feed # Feed
if ($can_view_page) { if ($can_view_page) {
# nav link # nav link
if ($feed_id && ($next_link || $prev_link)) { if ($feed_id && ($next_link || $prev_link)) {
echo '<p>'; echo '<p class="nav_prevnext">';
if ($prev_link) { if ($prev_link) {
echo $prev_link; echo $prev_link;
} }
if ($next_link && $prev_link) { if ($next_link && $prev_link) {
echo ' - '; echo ' | ';
} }
if ($next_link) { if ($next_link) {
echo $next_link; echo $next_link;
@ -399,8 +362,8 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
form::field('feed_tags', 60, 255, $feed_tags, 'maximal') . form::field('feed_tags', 60, 255, $feed_tags, 'maximal') .
'</p>' . '</p>' .
# --BEHAVIOR-- zoneclearFeedServerFeedForm # --BEHAVIOR-- adminZoneclearFeedServerFeedForm
$core->callBehavior('zoneclearFeedServerFeedForm', $core, $feed_id). $core->callBehavior('adminZoneclearFeedServerFeedForm', $core, $feed_id) .
'</div>' . '</div>' .
@ -431,36 +394,42 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
'</div>' . '</div>' .
'<p class="clear">'. '<p class="clear">
form::hidden(array('action'), 'savefeed'). <input type="submit" name="save" value="'.__('Save').' (s)" accesskey="s"/>' .
form::hidden(array('feed_id'), $feed_id). $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
form::hidden(array('p'), 'zoneclearFeedServer'). 'part' => 'feed',
form::hidden(array('part'), 'feed'). 'feed_id' => $feed_id,
'action' => 'savefeed'
]) .
$core->formNonce() . $core->formNonce() .
'<input type="submit" name="save" value="'.__('Save').'" /></p> '</p>
</form> </form>
</div>'; </div>';
} }
# Entries # entries
if ($feed_id && $can_view_page && !$core->error->flag()) { if ($feed_id && $can_view_page && !$core->error->flag()) {
echo '<div class="multi-part" title="'.__('Entries').'" id="entries">'; echo '<div class="multi-part" title="'.__('Entries').'" id="entries">';
# show filters
$post_filter->display(['admin.plugin.zoneclearFeedServer','#entries'], $post_filter->display(['admin.plugin.zoneclearFeedServer','#entries'],
form::hidden('p', 'zoneclearFeedServer') . $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
form::hidden('part', 'feed') . 'part' => 'feed',
form::hidden('feed_id', $feed_id) 'feed_id' => $feed_id
])
); );
# fix pager url # fix pager url
$args = $post_filter->values(); $args = $post_filter->values();
unset($args['page']); unset($args['page']);
$args['page'] = '%s'; $args['page'] = '%s';
$base_url = $core->adminurl->get('admin.plugin.zoneclearFeedServer', $args, '&').'#entries';
# Show posts # show posts
$post_list->display($post_filter->page, $post_filter->nb, $base_url, $post_list->display(
'<form action="'.$p_url.'&amp;part=feed#entries" method="post" id="form-entries">'. $post_filter->page,
$post_filter->nb,
$core->adminurl->get('admin.plugin.zoneclearFeedServer', $args, '&') . '#entries',
'<form action="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed']) . '#entries" method="post" id="form-entries">'.
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
@ -477,9 +446,7 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
$post_filter->show() $post_filter->show()
); );
echo echo '</div>';
'</div>';
}
} }
############################################################ ############################################################
@ -488,24 +455,24 @@ if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') {
# #
############################################################ ############################################################
else { } else {
# actions
# Actions page
$feeds_actions_page = new zcfsFeedsActionsPage( $feeds_actions_page = new zcfsFeedsActionsPage(
$core, $core,
'plugin.php', 'plugin.php',
array('p' => 'zoneclearFeedServer', 'part' => 'feeds') ['p' => 'zoneclearFeedServer', 'part' => 'feeds']
); );
if ($feeds_actions_page->process()) { if ($feeds_actions_page->process()) {
return null; return null;
} }
# filters
$feeds_filter = new adminGenericFilter($core, 'zcfs_feeds'); $feeds_filter = new adminGenericFilter($core, 'zcfs_feeds');
$feeds_filter->add('part', 'feeds'); $feeds_filter->add('part', 'feeds');
$feeds_filter->add(dcAdminFilters::getPageFilter()); $feeds_filter->add(dcAdminFilters::getPageFilter());
$params = $feeds_filter->params(); $params = $feeds_filter->params();
# feeds
try { try {
$feeds = $zcfs->getFeeds($params); $feeds = $zcfs->getFeeds($params);
$feeds_counter = $zcfs->getFeeds($params, true)->f(0); $feeds_counter = $zcfs->getFeeds($params, true)->f(0);
@ -514,40 +481,40 @@ else {
$feeds, $feeds,
$feeds_counter $feeds_counter
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
# Display # display
echo echo
'<html><head><title>' . __('Feeds server') . '</title>' . '<html><head><title>' . __('Feeds server') . '</title>' .
$feeds_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'], '&')) . $feeds_filter->js($core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feeds'], '&')) .
dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) . dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/list.js')) .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
# --BEHAVIOR-- packmanAdminHeader # --BEHAVIOR-- adminZoneclearFeedServerHeader
$core->callBehavior('zcfsAdminHeader', $core). $core->callBehavior('adminZoneclearFeedServerHeader', $core) .
'</head><body>' . '</head><body>' .
dcPage::breadcrumb( dcPage::breadcrumb([
array(
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Feeds server') => '', __('Feeds server') => '',
__('Feeds') => '' __('Feeds') => ''
) ]).
).
dcPage::notices() . dcPage::notices() .
'<p class="top-add">' . '<p class="top-add">' .
'<a class="button add" href="'.$p_url.'&amp;part=feed">'. '<a class="button add" href="' . $core->adminurl->get('admin.plugin.zoneclearFeedServer', ['part' => 'feed']) . '">' .
__('New feed') . '</a></p>'; __('New feed') . '</a></p>';
$feeds_filter->display('admin.plugin.zoneclearFeedServer', form::hidden('p', 'zoneclearFeedServer') . form::hidden('part', 'feeds')); $feeds_filter->display(
'admin.plugin.zoneclearFeedServer',
$core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', ['part', 'feeds'])
);
$feeds_list->feedsDisplay($feeds_filter->page, $feeds_filter->nb, $feeds_list->feedsDisplay($feeds_filter->page, $feeds_filter->nb,
'<form action="'.$p_url.'&amp;part=feeds" method="post" id="form-actions">'. '<form action="' . $core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', ['part', 'feeds']) . '" method="post" id="form-actions">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
@ -559,7 +526,7 @@ else {
'</p>' . '</p>' .
'</div>' . '</div>' .
'</form>', '</form>',
false $feeds_filter->show()
); );
} }