2022-08-15 10:52:22 +00:00
|
|
|
<?php
|
2022-11-26 22:43:34 +00:00
|
|
|
/**
|
|
|
|
* @brief myUrlHandlers, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Alex Pirine and contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:04:39 +00:00
|
|
|
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]));
|
2022-08-15 10:52:22 +00:00
|
|
|
|
|
|
|
$page_title = __('URL handlers');
|
|
|
|
|
2022-11-26 22:43:34 +00:00
|
|
|
try {
|
2022-08-15 10:52:22 +00:00
|
|
|
# Read default handlers
|
|
|
|
$handlers = myUrlHandlers::getDefaults();
|
|
|
|
|
|
|
|
# Overwrite with user settings
|
|
|
|
$settings = @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
|
|
|
|
if (is_array($settings)) {
|
2022-11-26 22:43:34 +00:00
|
|
|
foreach ($settings as $name => $url) {
|
2022-08-15 10:52:22 +00:00
|
|
|
if (isset($handlers[$name])) {
|
|
|
|
$handlers[$name] = $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($settings);
|
|
|
|
|
2022-11-26 22:43:34 +00:00
|
|
|
if (!empty($_POST['handlers']) && is_array($_POST['handlers'])) {
|
|
|
|
foreach ($_POST['handlers'] as $name => $url) {
|
2022-08-15 10:52:22 +00:00
|
|
|
$url = text::tidyURL($url);
|
|
|
|
|
|
|
|
if (empty($handlers[$name])) {
|
|
|
|
throw new Exception(sprintf(
|
2022-11-26 22:43:34 +00:00
|
|
|
__('Handler "%s" doesn\'t exist.'),
|
|
|
|
html::escapeHTML($name)
|
|
|
|
));
|
2022-08-15 10:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($url)) {
|
|
|
|
throw new Exception(sprintf(
|
2022-11-26 22:43:34 +00:00
|
|
|
__('Invalid URL for handler "%s".'),
|
|
|
|
html::escapeHTML($name)
|
|
|
|
));
|
2022-08-15 10:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$handlers[$name] = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get duplicates
|
2022-11-26 22:43:34 +00:00
|
|
|
$w = array_unique(array_diff_key($handlers, array_unique($handlers)));
|
2022-08-15 10:52:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Error on the line
|
|
|
|
* array_walk($w,create_function('&$v,$k,$h','$v = array_keys($h,$v);'),$handlers);
|
|
|
|
*
|
|
|
|
* Begin fix
|
|
|
|
*/
|
2022-11-26 22:43:34 +00:00
|
|
|
$v = function (&$v, $k, $h) {
|
|
|
|
return array_keys($h, $v);
|
2022-08-15 10:52:22 +00:00
|
|
|
};
|
|
|
|
|
2022-11-26 22:43:34 +00:00
|
|
|
array_walk($w, $v, $handlers);
|
2022-08-15 10:52:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* End fix
|
|
|
|
*/
|
2022-11-26 22:43:34 +00:00
|
|
|
$w = call_user_func_array('array_merge', $w);
|
2022-08-15 10:52:22 +00:00
|
|
|
|
|
|
|
if (!empty($w)) {
|
|
|
|
throw new Exception(sprintf(
|
2022-11-26 22:43:34 +00:00
|
|
|
__('Duplicate URL in handlers "%s".'),
|
|
|
|
implode('", "', $w)
|
|
|
|
));
|
2022-08-15 10:52:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 22:43:34 +00:00
|
|
|
if (isset($_POST['act_save'])) {
|
|
|
|
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers', serialize($handlers));
|
2022-08-15 10:52:22 +00:00
|
|
|
dcCore::app()->blog->triggerBlog();
|
2022-11-26 22:43:34 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(__('URL handlers have been successfully updated.'));
|
|
|
|
} elseif (isset($_POST['act_restore'])) {
|
|
|
|
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers', serialize([]));
|
2022-08-15 10:52:22 +00:00
|
|
|
dcCore::app()->blog->triggerBlog();
|
|
|
|
$handlers = myUrlHandlers::getDefaults();
|
2022-11-26 22:43:34 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(__('URL handlers have been successfully restored.'));
|
2022-08-15 10:52:22 +00:00
|
|
|
}
|
2022-11-26 22:43:34 +00:00
|
|
|
} catch (Exception $e) {
|
2022-08-15 10:52:22 +00:00
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DISPLAY
|
|
|
|
--------------------------------------------------- */
|
|
|
|
|
|
|
|
?>
|
2022-12-02 00:04:39 +00:00
|
|
|
<html><head>
|
|
|
|
<title><?php echo $page_title; ?></title>
|
|
|
|
</head><body>
|
2022-08-15 10:52:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
echo dcPage::breadcrumb(
|
2022-11-26 22:43:34 +00:00
|
|
|
[
|
|
|
|
html::escapeHTML(dcCore::app()->blog->name) => '',
|
|
|
|
'<span class="page-title">' . $page_title . '</span>' => '',
|
|
|
|
]
|
|
|
|
) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
2022-08-15 10:52:22 +00:00
|
|
|
?>
|
2022-12-02 00:04:39 +00:00
|
|
|
|
2022-08-15 10:52:22 +00:00
|
|
|
<?php if (empty($handlers)): ?>
|
2022-12-02 00:04:39 +00:00
|
|
|
<p class="message"><?php echo __('No URL handler to configure.'); ?></p>
|
2022-08-15 10:52:22 +00:00
|
|
|
<?php else: ?>
|
2022-12-02 00:04:39 +00:00
|
|
|
<p><?php echo __('You can write your own URL for each handler of this list.'); ?></p>
|
|
|
|
<form action="<?php echo dcCore::app()->admin->getPageURL(); ?>" method="post">
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr><th>Type</th><th>URL</th></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-08-15 10:52:22 +00:00
|
|
|
<?php
|
2022-11-26 22:43:34 +00:00
|
|
|
foreach ($handlers as $name => $url) {
|
2022-08-15 10:52:22 +00:00
|
|
|
echo
|
2022-11-26 22:43:34 +00:00
|
|
|
'<tr><td>' . html::escapeHTML($name) . '</td><td>' .
|
|
|
|
form::field(['handlers[' . $name . ']'], 20, 255, html::escapeHTML($url)) .
|
|
|
|
'</td></tr>' . "\n";
|
2022-08-15 10:52:22 +00:00
|
|
|
}
|
2022-11-26 22:43:34 +00:00
|
|
|
?>
|
2022-12-02 00:04:39 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<p><input type="submit" name="act_save" value="<?php echo __('Save'); ?>" />
|
|
|
|
<input type="submit" name="act_restore" value="<?php echo __('Reset'); ?>" />
|
|
|
|
<?php echo dcCore::app()->formNonce(); ?></p>
|
|
|
|
</form>
|
2022-08-15 10:52:22 +00:00
|
|
|
<?php endif; ?>
|
2022-12-02 00:04:39 +00:00
|
|
|
</body></html>
|