zoneclearFeedServer/src/Config.php

198 lines
5.9 KiB
PHP
Raw Normal View History

2015-04-25 19:25:03 +00:00
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
2021-11-06 15:30:19 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:30:19 +00:00
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
2021-11-06 15:30:19 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-25 19:25:03 +00:00
if (!defined('DC_CONTEXT_MODULE')) {
return null;
2015-04-25 19:25:03 +00:00
}
2022-11-15 20:05:21 +00:00
$redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
2015-04-25 19:25:03 +00:00
# -- Get settings --
2022-12-10 16:16:41 +00:00
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
2015-04-25 19:25:03 +00:00
2022-12-11 19:18:26 +00:00
$active = (bool) $s->active;
$pub_active = (bool) $s->pub_active;
$post_status_new = (bool) $s->post_status_new;
$bhv_pub_upd = (int) $s->bhv_pub_upd;
$update_limit = (int) $s->update_limit;
$keep_empty_feed = (bool) $s->keep_empty_feed;
$tag_case = (int) $s->tag_case;
2022-12-11 20:15:50 +00:00
$post_full_tpl = json_decode($s->post_full_tpl);
$post_title_redir = json_decode($s->post_title_redir);
2022-12-11 19:18:26 +00:00
$feeduser = (string) $s->user;
2015-04-25 19:25:03 +00:00
if ($update_limit < 1) {
$update_limit = 10;
2015-04-25 19:25:03 +00:00
}
if (!is_array($post_full_tpl)) {
2021-09-12 19:15:07 +00:00
$post_full_tpl = [];
2015-04-25 19:25:03 +00:00
}
if (!is_array($post_title_redir)) {
2021-09-12 19:15:07 +00:00
$post_title_redir = [];
2015-04-25 19:25:03 +00:00
}
2022-11-15 20:05:21 +00:00
$zc = new zoneclearFeedServer();
2015-04-25 19:25:03 +00:00
# -- Set settings --
if (!empty($_POST['save'])) {
try {
2021-11-06 15:30:19 +00:00
$active = !empty($_POST['active']);
$pub_active = !empty($_POST['pub_active']);
$post_status_new = !empty($_POST['post_status_new']);
$bhv_pub_upd = (int) $_POST['bhv_pub_upd'];
$limit = abs((int) $_POST['update_limit']);
$keep_empty_feed = !empty($_POST['keep_empty_feed']);
$tag_case = (int) $_POST['tag_case'];
$post_full_tpl = $_POST['post_full_tpl'];
$post_title_redir = $_POST['post_title_redir'];
2021-11-06 15:30:19 +00:00
$feeduser = (string) $_POST['feeduser'];
if ($limit < 1) {
$limit = 10;
}
2022-12-11 19:18:26 +00:00
$s->put('active', $active);
$s->put('pub_active', $pub_active);
$s->put('post_status_new', $post_status_new);
$s->put('bhv_pub_upd', $bhv_pub_upd);
$s->put('update_limit', $limit);
$s->put('keep_empty_feed', $keep_empty_feed);
$s->put('tag_case', $tag_case);
2022-12-11 20:15:50 +00:00
$s->put('post_full_tpl', json_encode($post_full_tpl));
$s->put('post_title_redir', json_encode($post_title_redir));
2022-12-11 19:18:26 +00:00
$s->put('user', $feeduser);
2022-11-15 20:05:21 +00:00
dcCore::app()->blog->triggerBlog();
2022-11-15 20:05:21 +00:00
dcAdminNotices::addSuccessNotice(
__('Configuration successfully updated.')
);
2022-11-15 20:05:21 +00:00
dcCore::app()->adminurl->redirect(
2021-11-06 15:30:19 +00:00
'admin.plugins',
2022-12-10 16:16:41 +00:00
['module' => basename(__DIR__), 'conf' => 1, 'redir' => dcCore::app()->admin->list->getRedir()]
);
2021-09-12 19:15:07 +00:00
} catch (Exception $e) {
2022-11-15 20:05:21 +00:00
dcCore::app()->error->add($e->getMessage());
}
2015-04-25 19:25:03 +00:00
}
# -- Form combos --
$combo_admins = $zc->getAllBlogAdmins();
2021-09-12 19:15:07 +00:00
$combo_pubupd = [
__('Disable') => 0,
__('Before display') => 1,
2021-09-12 19:15:07 +00:00
__('After display') => 2,
2022-11-15 20:05:21 +00:00
__('Through Ajax') => 3,
2021-09-12 19:15:07 +00:00
];
$combo_status = [
__('Unpublished') => 0,
2022-11-15 20:05:21 +00:00
__('Published') => 1,
2021-09-12 19:15:07 +00:00
];
$combo_tagcase = [
__('Keep source case') => 0,
__('First upper case') => 1,
2021-09-12 19:15:07 +00:00
__('All lower case') => 2,
2022-11-15 20:05:21 +00:00
__('All upper case') => 3,
2021-09-12 19:15:07 +00:00
];
2015-04-25 19:25:03 +00:00
2022-11-15 20:05:21 +00:00
$pub_page_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage');
2015-04-25 19:25:03 +00:00
# -- Display form --
if (!is_writable(DC_TPL_CACHE)) {
2021-11-06 15:30:19 +00:00
echo '<p class="error">' . __('Dotclear cache is not writable or not well configured!') . '</p>';
}
2015-04-25 19:25:03 +00:00
echo '
<div class="fieldset">
2021-09-12 19:15:07 +00:00
<h4>' . __('Activation') . '</h4>
2015-04-25 19:25:03 +00:00
2021-09-12 19:15:07 +00:00
<p><label for="active">' .
form::checkbox('active', 1, $active) .
__('Enable plugin') . '</label></p>
</div>
2015-04-25 19:25:03 +00:00
<div class="fieldset">';
2022-12-11 19:18:26 +00:00
if ($s->pub_active) {
2021-09-12 19:15:07 +00:00
echo sprintf(
'<p><a class="onblog_link outgoing" href="%s" title="%s">%s <img alt="" src="images/outgoing-link.svg"></a></p>',
2021-09-12 19:15:07 +00:00
$pub_page_url,
$pub_page_url,
__('View the public list of feeds')
);
2015-04-25 19:25:03 +00:00
}
echo '
2021-09-12 19:15:07 +00:00
<h4>' . __('Rules') . '</h4>
2015-04-25 19:25:03 +00:00
<div class="two-boxes">
2021-09-12 19:15:07 +00:00
<p><label for="post_status_new">' . __('Status of new posts:') . '</label>' .
form::combo('post_status_new', $combo_status, $post_status_new) . '</p>
2015-04-25 19:25:03 +00:00
2021-11-06 15:30:19 +00:00
<p><label for="feeduser">' .
2021-09-12 19:15:07 +00:00
__('Owner of entries created by zoneclearFeedServer:') . '</label>' .
form::combo('feeduser', $combo_admins, $feeduser) . '</p>
2015-04-25 19:25:03 +00:00
2021-09-12 19:15:07 +00:00
<p><label for="tag_case">' . __('How to transform imported tags:') . '</label>' .
form::combo('tag_case', $combo_tagcase, $tag_case) . '</p>
2015-04-25 19:25:03 +00:00
</div><div class="two-boxes">
2021-09-12 19:15:07 +00:00
<p><label for="bhv_pub_upd">' . __('Update feeds on public side:') . '</label>' .
form::combo('bhv_pub_upd', $combo_pubupd, $bhv_pub_upd) . '</p>
2015-04-25 19:25:03 +00:00
2021-11-06 15:30:19 +00:00
<p class="classic"><label for="update_limit" class="ib">' . sprintf(
__('Update %s feed(s) at a time.'),
form::number('update_limit', ['min' => 0, 'max' => 20, 'default' => $update_limit])
) . '</label></p>
2015-04-25 19:25:03 +00:00
2021-09-12 19:15:07 +00:00
<p><label for="keep_empty_feed">' .
form::checkbox('keep_empty_feed', 1, $keep_empty_feed) . __('Keep active empty feeds') . '</label></p>
2015-04-25 19:25:03 +00:00
2021-09-12 19:15:07 +00:00
<p><label for="pub_active">' .
form::checkbox('pub_active', 1, $pub_active) . __('Enable public page') . '</label></p>
2015-04-25 19:25:03 +00:00
</div><div class="two-boxes">
2021-09-12 19:15:07 +00:00
<p>' . __('Redirect to original post on:') . '</p><ul>';
2015-04-25 19:25:03 +00:00
2022-11-15 20:05:21 +00:00
foreach ($zc->getPublicUrlTypes() as $k => $v) {
2021-09-12 19:15:07 +00:00
echo sprintf(
'<li><label for="post_title_redir_%s">%s%s</label></li>',
$v,
2021-09-12 19:15:07 +00:00
form::checkbox(['post_title_redir[]', 'post_title_redir_' . $v], $v, in_array($v, $post_title_redir)),
__($k)
);
2015-04-25 19:25:03 +00:00
}
echo '
</ul>
</div><div class="two-boxes">
2021-09-12 19:15:07 +00:00
<p>' . __('Show full content on:') . '</p><ul>';
2015-04-25 19:25:03 +00:00
2022-11-15 20:05:21 +00:00
foreach ($zc->getPublicUrlTypes() as $k => $v) {
2021-09-12 19:15:07 +00:00
echo sprintf(
'<li><label for="post_full_tpl_%s">%s%s</label></li>',
$v,
2021-09-12 19:15:07 +00:00
form::checkbox(['post_full_tpl[]', 'post_full_tpl_' . $v], $v, in_array($v, $post_full_tpl)),
__($k)
);
2015-04-25 19:25:03 +00:00
}
2021-09-12 19:15:07 +00:00
echo '</ul></div></div>';
2015-04-25 19:25:03 +00:00
2021-11-06 15:30:19 +00:00
dcPage::helpBlock('zoneclearFeedServer');