2021-10-26 20:27:27 +00:00
|
|
|
<?php
|
2021-10-26 21:03:38 +00:00
|
|
|
/**
|
|
|
|
* @brief kUtRL, a plugin for Dotclear 2
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-10-26 21:03:38 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-10-26 21:03:38 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-10-26 21:03:38 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-10-26 20:27:27 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check user perms
|
2022-12-01 22:22:10 +00:00
|
|
|
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]));
|
2021-10-26 20:27:27 +00:00
|
|
|
|
|
|
|
# Settings
|
2022-12-22 14:37:09 +00:00
|
|
|
$s = dcCore::app()->blog->settings->get(basename(__DIR__));
|
2021-10-26 20:27:27 +00:00
|
|
|
|
|
|
|
# Default values
|
|
|
|
$img_green = '<img src="images/check-on.png" alt="ok" />';
|
|
|
|
$img_red = '<img src="images/check-off.png" alt="fail" />';
|
|
|
|
|
|
|
|
$services_combo = [];
|
2022-11-20 16:15:36 +00:00
|
|
|
foreach (kUtRL::getServices() as $service_id => $service) {
|
|
|
|
$o = new $service();
|
2021-10-26 20:27:27 +00:00
|
|
|
$services_combo[__($o->name)] = $o->id;
|
|
|
|
}
|
|
|
|
$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
|
|
|
|
$lst_services_combo = array_merge(['-' => ''], $services_combo);
|
|
|
|
|
2022-12-22 20:18:49 +00:00
|
|
|
$s_active = (bool) $s->get('active');
|
|
|
|
$s_plugin_service = (string) $s->get('plugin_service');
|
|
|
|
$s_admin_service = (string) $s->get('admin_service');
|
|
|
|
$s_tpl_service = (string) $s->get('tpl_service');
|
|
|
|
$s_wiki_service = (string) $s->get('wiki_service');
|
|
|
|
$s_allow_external_url = (bool) $s->get('allow_external_url');
|
|
|
|
$s_tpl_passive = (bool) $s->get('tpl_passive');
|
|
|
|
$s_tpl_active = (bool) $s->get('tpl_active');
|
|
|
|
$s_admin_entry_default = (string) $s->get('admin_entry_default');
|
2021-10-26 20:27:27 +00:00
|
|
|
|
|
|
|
if (!empty($_POST['save'])) {
|
|
|
|
try {
|
|
|
|
# settings
|
2021-11-06 15:43:02 +00:00
|
|
|
$s_active = !empty($_POST['s_active']);
|
|
|
|
$s_admin_service = (string) $_POST['s_admin_service'];
|
|
|
|
$s_plugin_service = (string) $_POST['s_plugin_service'];
|
|
|
|
$s_tpl_service = (string) $_POST['s_tpl_service'];
|
|
|
|
$s_wiki_service = (string) $_POST['s_wiki_service'];
|
|
|
|
$s_allow_external_url = !empty($_POST['s_allow_external_url']);
|
|
|
|
$s_tpl_passive = !empty($_POST['s_tpl_passive']);
|
|
|
|
$s_tpl_active = !empty($_POST['s_tpl_active']);
|
2021-10-26 20:27:27 +00:00
|
|
|
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
|
|
|
|
|
2022-12-22 20:18:49 +00:00
|
|
|
$s->put('active', $s_active);
|
|
|
|
$s->put('plugin_service', $s_plugin_service);
|
|
|
|
$s->put('admin_service', $s_admin_service);
|
|
|
|
$s->put('tpl_service', $s_tpl_service);
|
|
|
|
$s->put('wiki_service', $s_wiki_service);
|
|
|
|
$s->put('allow_external_url', $s_allow_external_url);
|
|
|
|
$s->put('tpl_passive', $s_tpl_passive);
|
|
|
|
$s->put('tpl_active', $s_tpl_active);
|
|
|
|
$s->put('admin_entry_default', $s_admin_entry_default);
|
2021-10-26 20:27:27 +00:00
|
|
|
|
|
|
|
# services
|
2022-11-20 16:15:36 +00:00
|
|
|
foreach (kUtRL::getServices() as $service_id => $service) {
|
|
|
|
$o = new $service();
|
2021-10-26 20:27:27 +00:00
|
|
|
$o->saveSettings();
|
|
|
|
}
|
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
dcCore::app()->blog->triggerBlog();
|
2021-10-26 20:27:27 +00:00
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(
|
2021-10-26 21:18:12 +00:00
|
|
|
__('Configuration successfully updated.')
|
2021-10-26 20:27:27 +00:00
|
|
|
);
|
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
dcCore::app()->adminurl->redirect(
|
2021-11-06 15:43:02 +00:00
|
|
|
'admin.plugins',
|
2022-12-22 14:37:09 +00:00
|
|
|
['module' => basename(__DIR__), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()]
|
2021-10-26 20:27:27 +00:00
|
|
|
);
|
|
|
|
} catch (Exception $e) {
|
2022-11-20 16:15:36 +00:00
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2021-10-26 20:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2021-11-06 15:43:02 +00:00
|
|
|
<div class="fieldset"><h4>' . __('Settings') . '</h4>
|
2021-10-26 20:27:27 +00:00
|
|
|
<div id="setting-plugin">
|
2021-11-06 15:43:02 +00:00
|
|
|
<h5>' . __('Activation') . '</h5>
|
|
|
|
<p><label class="classic">' .
|
|
|
|
form::checkbox(['s_active'], '1', $s_active) .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('Enable plugin') . '</label></p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr/><div id="setting-option">
|
2021-11-06 15:43:02 +00:00
|
|
|
<h5>' . __('Behaviors') . '</h5>
|
|
|
|
<p><label class="classic">' .
|
|
|
|
form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('Allow short link for external URL') . '</label></p>
|
|
|
|
<p class="form-note">' . __('Not only link started with this blog URL could be shortened.') . '</p>
|
2021-11-06 15:43:02 +00:00
|
|
|
<p><label class="classic">' .
|
|
|
|
form::checkbox(['s_tpl_passive'], '1', $s_tpl_passive) .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('Passive mode') . '</label></p>
|
|
|
|
<p class="form-note">' . __('If this extension is disabled and the passive mode is enabled, "kutrl" tags (like EntryKurl) will display long urls instead of nothing on templates.') . '</p>
|
2021-11-06 15:43:02 +00:00
|
|
|
<p><label class="classic">' .
|
|
|
|
form::checkbox(['s_tpl_active'], '1', $s_tpl_active) .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('Active mode') . '</label></p>
|
2021-11-06 15:43:02 +00:00
|
|
|
<p class="form-note">' . __('If the active mode is enabled, all know default template tags (like EntryURL) will display short urls instead of long ones on templates.') . '<br />' .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '</p>
|
|
|
|
<p class="warning">' . __('We strongly discourage using active mode as it crashes public post form and complex url if theme is not customize for kUtRL.') . '</p>
|
2021-11-06 15:43:02 +00:00
|
|
|
<p><label class="classic">' .
|
|
|
|
form::checkbox(['s_admin_entry_default'], '1', $s_admin_entry_default) .
|
2021-10-26 20:27:27 +00:00
|
|
|
__('Create short link for new entries') . '</label></p>
|
|
|
|
<p class="form-note">' . __('This can be changed on page of creation/edition of an entry.') . '</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr/><div id="setting-service">
|
2021-11-06 15:43:02 +00:00
|
|
|
<h5>' . __('Default services') . '</h5>
|
2021-10-26 20:27:27 +00:00
|
|
|
<p><label>';
|
|
|
|
if (!empty($_REQUEST['chk'])) {
|
2022-11-20 16:15:36 +00:00
|
|
|
if (null !== ($o = kUtRL::quickPlace($s_admin_service))) {
|
2021-10-26 20:27:27 +00:00
|
|
|
echo $o->testService() ? $img_green : $img_red;
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
echo ' ' . __('Administration:') . '<br />' .
|
2021-10-26 20:27:27 +00:00
|
|
|
form::combo(['s_admin_service'], $services_combo, $s_admin_service) . '
|
|
|
|
</label></p>
|
|
|
|
<p class="form-note">' . __('Service to use in this admin page and on edit page of an entry.') . '</p>
|
|
|
|
<p><label>';
|
|
|
|
if (!empty($_REQUEST['chk'])) {
|
2022-11-20 16:15:36 +00:00
|
|
|
if (null !== ($o = kUtRL::quickPlace($s_plugin_service))) {
|
2021-10-26 20:27:27 +00:00
|
|
|
echo $o->testService() ? $img_green : $img_red;
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
echo ' ' . __('Extensions:') . '<br />' .
|
2021-10-26 20:27:27 +00:00
|
|
|
form::combo(['s_plugin_service'], $services_combo, $s_plugin_service) . '
|
|
|
|
</label></p>
|
|
|
|
<p class="form-note">' . __('Service to use on third part plugins.') . '</p>
|
|
|
|
<p><label>';
|
|
|
|
if (!empty($_REQUEST['chk'])) {
|
2022-11-20 16:15:36 +00:00
|
|
|
if (null !== ($o = kUtRL::quickPlace($s_tpl_service))) {
|
2021-10-26 20:27:27 +00:00
|
|
|
echo $o->testService() ? $img_green : $img_red;
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
echo ' ' . __('Templates:') . '<br />' .
|
2021-10-26 20:27:27 +00:00
|
|
|
form::combo(['s_tpl_service'], $ext_services_combo, $s_tpl_service) . '
|
|
|
|
</label></p>
|
|
|
|
<p class="form-note">' . __('Shorten links automatically when using template value like "EntryKutrl".') . '</p>
|
|
|
|
<p><label>';
|
|
|
|
if (!empty($_REQUEST['chk'])) {
|
2022-11-20 16:15:36 +00:00
|
|
|
if (null !== ($o = kUtRL::quickPlace($s_wiki_service))) {
|
2021-10-26 20:27:27 +00:00
|
|
|
echo $o->testService() ? $img_green : $img_red;
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
echo ' ' . __('Contents:') . '<br />' .
|
2021-10-26 20:27:27 +00:00
|
|
|
form::combo(['s_wiki_service'], $ext_services_combo, $s_wiki_service) . '
|
|
|
|
</label></p>
|
|
|
|
<p class="form-note">' . __('Shorten links automatically found in contents using wiki synthax.') . '</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="fieldset">
|
2021-11-06 15:43:02 +00:00
|
|
|
<h4>' . __('Services') . '</h4>
|
2021-10-26 20:27:27 +00:00
|
|
|
<p class="info">' . __('List of services you can use to shorten links with pkugin kUtRL.') . '</p>
|
|
|
|
';
|
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
foreach (kUtRL::getServices() as $service_id => $service) {
|
|
|
|
$o = new $service();
|
2021-10-26 20:27:27 +00:00
|
|
|
|
|
|
|
echo '<hr/><div id="setting-' . $service_id . '"><h5>' . $o->name . '</h5>';
|
|
|
|
|
|
|
|
if (!empty($_REQUEST['chk'])) {
|
|
|
|
$img_chk = $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name);
|
2021-11-06 15:43:02 +00:00
|
|
|
|
2021-10-26 20:27:27 +00:00
|
|
|
try {
|
|
|
|
if ($o->testService()) {
|
|
|
|
$img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2022-11-20 16:15:36 +00:00
|
|
|
dcCore::app()->error->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage()));
|
2021-10-26 20:27:27 +00:00
|
|
|
}
|
|
|
|
echo sprintf('<p><em>%s</em></p>', $img_chk) . $o->error->toHTML();
|
|
|
|
}
|
|
|
|
if ($o->home != '') {
|
|
|
|
echo '<p><a title="' . __('homepage') . '" href="' . $o->home . '">' . sprintf(__('Learn more about %s.'), $o->name) . '</a></p>';
|
|
|
|
}
|
|
|
|
$o->settingsForm();
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:43:02 +00:00
|
|
|
echo'</div>';
|