full rewrite of index file, remove sub parts, js ...

This commit is contained in:
Jean-Christian Denis 2021-08-28 18:27:58 +02:00
parent 61609a8464
commit 9607d9d86d
18 changed files with 640 additions and 825 deletions

View file

@ -1,17 +1,17 @@
todo todo
- Added public page of the list of know urls and in/visible status - Added public page of the list of know urls and in/visible status
- Added passworded links - Added passworded links
- clean PSR-2 codding style and short array
- fix php 7.3+ and php 8.0.x compatibility
- fix compatibility with Dotclear 2.19
- fix widgets rendering - fix widgets rendering
- move setting to config file - move setting to config file
- fix dashboard rendering - fix dashboard rendering
- fix deprecated external service - fix deprecated external service
- create readme file
2021.08.27 2021.08.27
- add dashboard icon - add dashboard icon
- clean PSR-2 codding style and short array
- fix php 7.3+ and php 8.0.x compatibility
- fix compatibility with Dotclear 2.19
- create readme file
2011.04.01 2011.04.01
* Changed version numbering * Changed version numbering

View file

@ -42,6 +42,7 @@ $d = dirname(__FILE__) . '/inc/';
$__autoload['kutrl'] = $d . 'class.kutrl.php'; $__autoload['kutrl'] = $d . 'class.kutrl.php';
$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php'; $__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php';
$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php'; $__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php';
$__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php';
# Services # Services
$__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php'; $__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php';

13
dcstore.xml Normal file
View file

@ -0,0 +1,13 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="kUtRL">
<name>kUtRL</name>
<version>2021.08.27</version>
<author>Jean-Christian Denis and contributors</author>
<desc>Use, create and serve short url on your blog</desc>
<file>https://github.com/JcDenis/kUtRL/releases/download/v2021.08.27/plugin-kUtRL.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>http://plugins.dotaddict.org/dc2/details/kUtRL</da:details>
<da:section></da:section>
<da:support>https://github.com/JcDenis/kUtRL</da:support>
</module>
</modules>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 713 B

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View file

@ -1,140 +0,0 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of kUtRL, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
# This file manage admin link creation of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$kut = kutrl::quickPlace('admin');
# Create a new link
if ($action == 'createlink') {
try {
if (null === $kut) {
throw new Exception('Unknow service');
}
$url = trim($core->con->escape($_POST['str']));
$hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) {
throw new Exception(__('There is nothing to shorten.'));
}
if (!$kut->testService()) {
throw new Exception(__('Service is not well configured.'));
}
if (null !== $hash && !$kut->allow_custom_hash) {
throw new Exception(__('This service does not allowed custom hash.'));
}
if (!$kut->isValidUrl($url)) {
throw new Exception(__('This link is not a valid URL.'));
}
if (!$kut->isLongerUrl($url)) {
throw new Exception(__('This link is too short.'));
}
if (!$kut->isProtocolUrl($url)) {
throw new Exception(__('This type of link is not allowed.'));
}
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
throw new Exception(__('Short links are limited to this blog URL.'));
}
if ($kut->isServiceUrl($url)) {
throw new Exception(__('This link is already a short link.'));
}
if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) {
throw new Exception(__('This custom short url is already taken.'));
}
if (false !== ($rs = $kut->isKnowUrl($url))) {
$url = $rs->url;
$new_url = $kut->url_base .$rs->hash;
$msg =
'<p class="message">' .
sprintf(
__('Short link for %s is %s') ,
'<strong>' . html::escapeHTML($url) .'</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
) . '</p>';
} else {
if (false === ($rs = $kut->hash($url, $hash))) {
if ($kut->error->flag()) {
throw new Exception($kut->error->toHTML());
}
throw new Exception(__('Failed to create short link. This could be caused by a service failure.'));
} else {
$url = $rs->url;
$new_url = $kut->url_base . $rs->hash;
$msg =
'<p class="message">' .
sprintf(
__('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
) . '</p>';
# ex: Send new url to messengers
if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL'));
}
}
}
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
echo '
<html>
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header . '</head>
<body>
<h2>kUtRL' .
' &rsaquo; <a href="' . $p_url . '&amp;part=links">' . __('Links') . '</a>' .
' &rsaquo; ' . __('New link') .
'</h2>' . $msg;
if (null === $kut) {
echo '<p>' . __('You must set an admin service.') . '</p>';
} else {
echo '
<form id="create-link" method="post" action="' . $p_url . '">
<h3>' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '</h3>
<p class="classic"><label for="str">' . __('Long link:') .
form::field('str', 100, 255, '') . '</label></p>';
if ($kut->allow_custom_hash) {
echo
'<p class="classic"><label for="custom">' .
__('Custom short link:') .
form::field('custom', 50, 32, '') . '</label></p>' .
'<p class="form-note">' . __('Only if you want a custom short link.') . '</p>';
if ($kut->admin_service == 'local') {
echo '<p class="form-note">' .
__('You can use "bob!!" if you want a semi-custom link, it starts with "bob" and "!!" will be replaced by an increment value.') .
'</p>';
}
}
echo '
<div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() .
form::hidden(['p'], 'kUtRL') .
form::hidden(['part'], 'link') .
form::hidden(['action'], 'createlink') . '
</p></div>
</form>';
}
dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>';

View file

@ -1,264 +0,0 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of kUtRL, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
# This file manage links of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# Short links list
class kutrlLinkslist extends adminGenericList
{
public function display($page, $nb_per_page, $url)
{
if ($this->rs->isEmpty()) {
echo '<p><strong>' . __('No short link') . '</strong></p>';
} else {
$pager = new pager($page, $this->rs_count, $nb_per_page, 10);
$pager->base_url = $url;
$html_block =
'<table class="clear">' .
'<thead>' .
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Hash') . '</th>' .
'<th class="maximal">' . __('Link') . '</th>' .
'<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">' . __('Service') . '</th>' .
'</tr>' .
'</thead>' .
'<tbody>%s</tbody>' .
'</table>';
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
$blocks = explode('%s', $html_block);
echo $blocks[0];
$this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0;
while ($iter < $nb_per_page) {
echo $this->line($url,$iter);
if ($this->rs->isEnd()) {
break;
} else {
$this->rs->moveNext();
}
$iter++;
}
echo $blocks[1];
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
}
}
private function line($url, $loop)
{
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
return
'<tr class="line">' . "\n" .
'<td class="nowrap">' .
form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
'</td>' .
'<td class="nowrap">' .
$hash .
"</td>\n" .
'<td class="maximal">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
"</td>\n" .
'<td class="nowrap">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
"</td>\n" .
'<td class="nowrap">' .
$type .
"</td>\n" .
'</tr>' . "\n";
}
}
# Logs class
$log = new kutrlLog($core);
# Filters
$show_filters = false;
$urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : '';
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'kut_dt';
$order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
$nb_per_page = 30;
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
if ($nb_per_page != $_GET['nb']) {
$show_filters = true;
}
$nb_per_page = (integer) $_GET['nb'];
}
# Combos
$sortby_combo = [
__('Date') => 'kut_dt',
__('Long link') => 'kut_url',
__('Short link') => 'kut_hash'
];
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
$services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service)
{
$o = new $service($core);
$services_combo[__($o->name)] = $o->id;
}
$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
$lst_services_combo = array_merge(['-' => ''], $services_combo);
# Params for list
$params = [];
$params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page];
if ($sortby != '' && in_array($sortby, $sortby_combo)) {
if ($urlsrv != '' && in_array($urlsrv, $lst_services_combo)) {
$params['kut_type'] = $urlsrv;
}
if ($order != '' && in_array($order, $order_combo)) {
$params['order'] = $sortby . ' ' . $order;
}
if ($sortby != 'kut_dt' || $order != 'desc' || $urlsrv != '') {
$show_filters = true;
}
}
$pager_base_url =
$p_url .
'&amp;tab=list' .
'&amp;urlsrv=' . $urlsrv .
'&amp;sortby=' . $sortby .
'&amp;order=' . $order .
'&amp;nb=' . $nb_per_page .
'&amp;page=%s';
# Delete links from list
if ($action == 'deletelinks') {
try {
foreach($_POST['entries'] as $k => $id) {
$rs = $log->getLogs(['kut_id' => $id]);
if ($rs->isEmpty()) {
continue;
}
if (null === ($o = kutrl::quickService($rs->kut_type))) {
continue;
}
$o->remove($rs->kut_url);
}
$core->blog->triggerBlog();
http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page . '&msg=' . $action);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# Get links and pager
try {
$list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0);
$list_current = new kutrlLinksList($core, $list_all, $list_counter, $pager_base_url);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
if (!$show_filters) {
$header .= dcPage::jsLoad('js/filter-controls.js');
}
echo '
<html>
<head><title>kUtRL, ' . __('Links shortener') . '</title>' .
"\n<script type=\"text/javascript\"> \n" .
"$(function(){ $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); }); \n" .
"</script>\n" .
$header . '</head>
<body>
<h2>kUtRL' .
' &rsaquo; ' . __('Links') .
' - <a class="button" href="' . $p_url . '&amp;part=link">' . __('New link') . '</a>' .
'</h2>' . $msg;
if (!$show_filters) {
echo '<p><a id="filter-control" class="form-control" href="#">' .
__('Filters') . '</a></p>';
}
echo '
<form action="' . $p_url . '&amp;part=links" method="get" id="filters-form">
<fieldset><legend>' . __('Filters') . '</legend>
<div class="three-cols">
<div class="col">
<label>' . __('Service:') . form::combo('urlsrv', $lst_services_combo, $urlsrv) . '
</label>
</div>
<div class="col">
<label>' . __('Order by:') . form::combo('sortby', $sortby_combo, $sortby) . '
</label>
<label>' . __('Sort:') . form::combo('order', $order_combo, $order) . '
</label>
</div>
<div class="col">
<p>
<label class="classic">' . form::field('nb', 3, 3, $nb_per_page) . ' ' . __('Entries per page') . '
</label>
<input type="submit" value="' . __('filter') . '" />' .
form::hidden(['p'], 'kUtRL') .
form::hidden(['part'], 'links') . '
</p>
</div>
</div>
<br class="clear" />
</fieldset>
</form>
<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">';
$list_current->display($page, $nb_per_page, $pager_base_url);
echo '
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
<p class="col right">
<input type="submit" value="' . __('Delete selected short links') . '" />' .
form::hidden(['action'], 'deletelinks') .
form::hidden(['urlsrv'], $urlsrv) .
form::hidden(['sortby'], $sortby) .
form::hidden(['order'], $order) .
form::hidden(['page'], $page) .
form::hidden(['nb'], $nb_per_page) .
form::hidden(['p'], 'kUtRL') .
form::hidden(['part'], 'links') .
$core->formNonce() . '
</p>
</div>
</form>';
dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>';
?>

View file

@ -1,84 +0,0 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of kUtRL, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
# This file manage services of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# Save services settings
if ($action == 'saveservice') {
try {
foreach(kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
$o->saveSettings();
}
$core->blog->triggerBlog();
http::redirect($p_url . '&part=service&section=' . $section . '&msg=' . $action);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
echo '
<html>
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header .
dcPage::jsLoad('index.php?pf=kUtRL/js/service.js') .
"<script type=\"text/javascript\">\n//<![CDATA[\n" .
dcPage::jsVar('jcToolsBox.prototype.section', $section) .
"\n//]]>\n</script>\n" .
'</head>
<body>
<h2>kUtRL' .
' &rsaquo; <a href="' . $p_url . '&amp;part=links">' . __('Links') . '</a>' .
' &rsaquo; ' . __('Services') .
' - <a class="button" href="' . $p_url . '&amp;part=link">' . __('New link') . '</a>' .
'</h2>' . $msg . '
<form id="service-form" method="post" action="' . $p_url . '">';
foreach(kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
echo '<fieldset id="setting-' . $service_id . '"><legend>' . $o->name . '</legend>';
if (!empty($msg)) {
echo '<p><em>' . (
$o->testService() ?
$img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name) :
$img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name)
) . '</em></p>';
//if ($o->error->flag()) {
echo $o->error->toHTML();
//}
}
if (!empty($o->home)) {
echo '<p><a title="' . __('homepage') . '" href="' . $o->home . '">' . sprintf(__('Learn more about %s.'), $o->name) . '</a></p>';
}
$o->settingsForm();
echo '</fieldset>';
}
echo '
<div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() .
form::hidden(['p'], 'kUtRL') .
form::hidden(['part'], 'service') .
form::hidden(['action'], 'saveservice') .
form::hidden(['section'], $section) . '
</p></div>
</form>';
dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>';

View file

@ -1,163 +0,0 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of kUtRL, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
# This file manage settings of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$s_active = (boolean) $s->kutrl_active;
$s_plugin_service = (string) $s->kutrl_plugin_service;
$s_admin_service = (string) $s->kutrl_admin_service;
$s_tpl_service = (string) $s->kutrl_tpl_service;
$s_wiki_service = (string) $s->kutrl_wiki_service;
$s_allow_external_url = (boolean) $s->kutrl_allow_external_url;
$s_tpl_passive = (boolean) $s->kutrl_tpl_passive;
$s_tpl_active = (boolean) $s->kutrl_tpl_active;
$s_admin_entry_default = (string) $s->kutrl_admin_entry_default;
if ($default_part == 'setting' && $action == 'savesetting') {
try {
$s_active = !empty($_POST['s_active']);
$s_admin_service = $_POST['s_admin_service'];
$s_plugin_service = $_POST['s_plugin_service'];
$s_tpl_service = $_POST['s_tpl_service'];
$s_wiki_service = $_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']);
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
$s->put('kutrl_active', $s_active);
$s->put('kutrl_plugin_service', $s_plugin_service);
$s->put('kutrl_admin_service', $s_admin_service);
$s->put('kutrl_tpl_service', $s_tpl_service);
$s->put('kutrl_wiki_service', $s_wiki_service);
$s->put('kutrl_allow_external_url', $s_allow_external_url);
$s->put('kutrl_tpl_passive', $s_tpl_passive);
$s->put('kutrl_tpl_active', $s_tpl_active);
$s->put('kutrl_admin_entry_default', $s_admin_entry_default);
$core->blog->triggerBlog();
http::redirect($p_url . '&part=setting&msg=' . $action . '&section=' . $section);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
$services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
$services_combo[__($o->name)] = $o->id;
}
$ext_services_combo = array_merge([__('Disabled')=>''], $services_combo);
$lst_services_combo = array_merge(['-'=>''], $services_combo);
echo '
<html>
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header .
dcPage::jsLoad('index.php?pf=kUtRL/js/setting.js') .
"<script type=\"text/javascript\">\n//<![CDATA[\n" .
dcPage::jsVar('jcToolsBox.prototype.section', $section) .
"\n//]]>\n</script>\n" .
'</head>
<body>
<h2>kUtRL' .
' &rsaquo; <a href="' . $p_url . '&amp;part=links">' . __('Links') . '</a>' .
' &rsaquo; ' . __('Settings') .
' - <a class="button" href="' . $p_url . '&amp;part=link">' . __('New link') . '</a>' .
'</h2>' . $msg . '
<form id="setting-form" method="post" action="' . $p_url . '">
<fieldset id="setting-plugin"><legend>' . __('Plugin activation') . '</legend>
<p><label class="classic">' .
form::checkbox(['s_active'], '1', $s_active) .
__('Enable plugin') . '</label></p>
</fieldset>
<fieldset id="setting-option"><legend>' . __('General rules') . '</legend>
<p><label class="classic">' .
form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) .
__('Allow short link for external URL') . '</label></p>
<p class="form-note">' . __('Not only link started with this blog URL could be shortened.') . '</p>
<p><label class="classic">' .
form::checkbox(['s_tpl_passive'], '1', $s_tpl_passive) .
__('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>
<p><label class="classic">' .
form::checkbox(['s_tpl_active'], '1', $s_tpl_active) .
__('Active mode') . '</label></p>
<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 />' .
__('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '</p>
<p><label class="classic">' .
form::checkbox(['s_admin_entry_default'], '1', $s_admin_entry_default) .
__('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>
</fieldset>
<fieldset id="setting-service"><legend>' . __('Default services') . '</legend>
<p><label>';
if (!empty($msg)) {
if (null !== ($o = kutrl::quickPlace($s_admin_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Administration:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_plugin_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Extensions:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_tpl_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Templates:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_wiki_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Contents:') . '<br />' .
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>
</fieldset>
<div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() .
form::hidden(['p'], 'kUtRL') .
form::hidden(['part'], 'setting') .
form::hidden(['action'], 'savesetting') .
form::hidden(['section'], $section) . '
</p></div>
</form>';
dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>';

78
inc/lib.kutrl.lst.php Normal file
View file

@ -0,0 +1,78 @@
<?php
class kutrlLinkslist extends adminGenericList
{
public function display($page, $nb_per_page, $url)
{
if ($this->rs->isEmpty()) {
echo '<p><strong>' . __('No short link') . '</strong></p>';
} else {
$pager = new pager($page, $this->rs_count, $nb_per_page, 10);
$pager->base_url = $url;
$html_block =
'<table class="clear">' .
'<thead>' .
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Hash') . '</th>' .
'<th class="maximal">' . __('Link') . '</th>' .
'<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">' . __('Service') . '</th>' .
'</tr>' .
'</thead>' .
'<tbody>%s</tbody>' .
'</table>';
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
$blocks = explode('%s', $html_block);
echo $blocks[0];
$this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0;
while ($iter < $nb_per_page) {
echo $this->line($url,$iter);
if ($this->rs->isEnd()) {
break;
} else {
$this->rs->moveNext();
}
$iter++;
}
echo $blocks[1];
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
}
}
private function line($url, $loop)
{
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
return
'<tr class="line">' . "\n" .
'<td class="nowrap">' .
form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
'</td>' .
'<td class="nowrap">' .
$hash .
"</td>\n" .
'<td class="maximal">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
"</td>\n" .
'<td class="nowrap">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
"</td>\n" .
'<td class="nowrap">' .
$type .
"</td>\n" .
'</tr>' . "\n";
}
}

View file

@ -24,7 +24,7 @@ class googlKutrlService extends kutrlService
private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; private $url_api = 'https://www.googleapis.com/urlshortener/v1/url';
private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL';
private $args = [ private $args = [
'key' => 'AIzaSyDE1WfOMdnrnX8p51jSmVodenaNk385asc' 'key' => ''
]; ];
private $headers = array('Content-Type: application/json'); private $headers = array('Content-Type: application/json');

View file

@ -97,7 +97,7 @@ class localKutrlService extends kutrlService
'<p>' . __('There are two templates delivered with kUtRL, if you do not use default theme, you may adapt them to yours.') . '<br />' . '<p>' . __('There are two templates delivered with kUtRL, if you do not use default theme, you may adapt them to yours.') . '<br />' .
__('Files are in plugin directory /default-templates, just copy them into your theme and edit them.') . '</p>' . __('Files are in plugin directory /default-templates, just copy them into your theme and edit them.') . '</p>' .
'</div></div>'; '</div></div><br class="clear"/>';
} }
public function testService() public function testService()

581
index.php
View file

@ -12,7 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
# Check user perms # Check user perms
@ -23,45 +23,548 @@ $s = $core->blog->settings->kUtRL;
# Default values # Default values
$show_filters = false; $show_filters = false;
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $p_url = $core->adminurl->get('admin.plugin.kUtRL');
$section = isset($_REQUEST['section']) ? $_REQUEST['section'] : ''; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'links';
$img_green = '<img src="images/check-on.png" alt="ok" />'; $action = isset($_POST['action']) ? $_POST['action'] : '';
$img_red = '<img src="images/check-off.png" alt="fail" />';
$header = # used in setting & links
dcPage::jsLoad('index.php?pf=kUtRL/js/main.js') . if (in_array($part, ['setting', 'links'])) {
'<script type="text/javascript">' . "\n//<![CDATA[\n" . $services_combo = [];
"jcToolsBox.prototype.text_wait = '" . html::escapeJS(__('Please wait')) . "';\n" . foreach(kutrl::getServices($core) as $service_id => $service) {
"\n//]]>\n</script>\n" . $o = new $service($core);
'<style type="text/css"> $services_combo[__($o->name)] = $o->id;
.titleKutrl { margin: -20px; text-align:center; } }
.titleKutrl a { border:none; text-decoration: none; } $ext_services_combo = array_merge([__('Disabled')=>''], $services_combo);
</style>'; $lst_services_combo = array_merge(['-'=>''], $services_combo);
$footer = '<hr class="clear"/><p class="right">
<a class="button" href="' . $p_url . '&amp;part=setting" title="' . __('Configure extension') . '">' . __('Settings') . '</a> -
<a class="button" href="' . $p_url . '&amp;part=service" title="' . __('Configure services') . '">' . __('Services') . '</a> -
kUtRL - ' . $core->plugins->moduleInfo('kUtRL','version') . '&nbsp;
<img alt="' . __('kUtRL') . '" src="index.php?pf=kUtRL/icon.png" />
</p>';
# Messages
$msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : '';
$msg_list = [
'savesetting' => __('Configuration successfully saved'),
'saveservice' => __('Services successfully updated'),
'createlink' => __('Link successfully shorten'),
'deletelinks' => __('Links successfully deleted')
];
if (isset($msg_list[$msg])) {
$msg = sprintf('<p class="message">%s</p>', $msg_list[$msg]);
} }
# Pages # used in setting & service
$start_part = $s->kutrl_active ? 'links' : 'setting'; if (in_array($part, ['setting', 'service'])) {
$default_part = isset($_REQUEST['part']) ? $_REQUEST['part'] : $start_part; $img_green = '<img src="images/check-on.png" alt="ok" />';
$img_red = '<img src="images/check-off.png" alt="fail" />';
if (!file_exists(dirname(__FILE__) . '/inc/index.' . $default_part . '.php')) {
$default_part = 'setting';
} }
include dirname(__FILE__) . '/inc/index.' . $default_part . '.php';
# setting
if ($part == 'setting') {
$s_active = (boolean) $s->kutrl_active;
$s_plugin_service = (string) $s->kutrl_plugin_service;
$s_admin_service = (string) $s->kutrl_admin_service;
$s_tpl_service = (string) $s->kutrl_tpl_service;
$s_wiki_service = (string) $s->kutrl_wiki_service;
$s_allow_external_url = (boolean) $s->kutrl_allow_external_url;
$s_tpl_passive = (boolean) $s->kutrl_tpl_passive;
$s_tpl_active = (boolean) $s->kutrl_tpl_active;
$s_admin_entry_default = (string) $s->kutrl_admin_entry_default;
if (!empty($_POST['save'])) {
try {
$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']);
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
$s->put('kutrl_active', $s_active);
$s->put('kutrl_plugin_service', $s_plugin_service);
$s->put('kutrl_admin_service', $s_admin_service);
$s->put('kutrl_tpl_service', $s_tpl_service);
$s->put('kutrl_wiki_service', $s_wiki_service);
$s->put('kutrl_allow_external_url', $s_allow_external_url);
$s->put('kutrl_tpl_passive', $s_tpl_passive);
$s->put('kutrl_tpl_active', $s_tpl_active);
$s->put('kutrl_admin_entry_default', $s_admin_entry_default);
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Configuration successfully saved')
);
http::redirect($p_url . '&part=setting');
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
}
# services
if ($part == 'service' && !empty($_POST['save'])) {
try {
foreach(kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
$o->saveSettings();
}
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Configuration successfully saved')
);
http::redirect($p_url . '&part=service');
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# link creation
if ($part == 'link') {
$kut = kutrl::quickPlace('admin');
if (!empty($_POST['save'])) {
try {
if (null === $kut) {
throw new Exception('Unknow service');
}
$url = trim($core->con->escape($_POST['str']));
$hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) {
throw new Exception(__('There is nothing to shorten.'));
}
if (!$kut->testService()) {
throw new Exception(__('Service is not well configured.'));
}
if (null !== $hash && !$kut->allow_custom_hash) {
throw new Exception(__('This service does not allowed custom hash.'));
}
if (!$kut->isValidUrl($url)) {
throw new Exception(__('This link is not a valid URL.'));
}
if (!$kut->isLongerUrl($url)) {
throw new Exception(__('This link is too short.'));
}
if (!$kut->isProtocolUrl($url)) {
throw new Exception(__('This type of link is not allowed.'));
}
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
throw new Exception(__('Short links are limited to this blog URL.'));
}
if ($kut->isServiceUrl($url)) {
throw new Exception(__('This link is already a short link.'));
}
if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) {
throw new Exception(__('This custom short url is already taken.'));
}
if (false !== ($rs = $kut->isKnowUrl($url))) {
$url = $rs->url;
$new_url = $kut->url_base .$rs->hash;
dcPage::addSuccessNotice(sprintf(
__('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
));
} else {
if (false === ($rs = $kut->hash($url, $hash))) {
if ($kut->error->flag()) {
throw new Exception($kut->error->toHTML());
}
throw new Exception(__('Failed to create short link. This could be caused by a service failure.'));
} else {
$url = $rs->url;
$new_url = $kut->url_base . $rs->hash;
dcPage::addSuccessNotice(sprintf(
__('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
));
# ex: Send new url to messengers
if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL'));
}
}
}
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
}
# links
if ($part == 'links') {
$log = new kutrlLog($core);
$sortby_combo = [
__('Date') => 'kut_dt',
__('Long link') => 'kut_url',
__('Short link') => 'kut_hash'
];
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
$core->auth->user_prefs->addWorkspace('interface');
$default_sortby = 'kut_dt';
$default_order = $core->auth->user_prefs->interface->posts_order ?: 'desc';
$nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30;
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby;
$order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
$urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : '';
$page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1;
$show_filters = false;
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
if ($nb_per_page != (integer) $_GET['nb']) {
$show_filters = true;
}
$nb_per_page = (integer) $_GET['nb'];
}
$params = [];
$params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page];
if (!in_array($sortby, $sortby_combo)) {
$sortby = $default_sortby;
}
if (!in_array($order, $order_combo)) {
$order = $default_order;
}
$params['order'] = $sortby . ' ' . $order;
if ($urlsrv != '' && in_array($urlsrv, $lst_services_combo)) {
$params['kut_type'] = $urlsrv;
}
if ($sortby != $default_sortby || $order != $default_order || $urlsrv != '') {
$show_filters = true;
}
$pager_base_url =
$p_url .
'&amp;urlsrv=' . $urlsrv .
'&amp;sortby=' . $sortby .
'&amp;order=' . $order .
'&amp;nb=' . $nb_per_page .
'&amp;page=%s';
try {
$list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0);
$list_current = new kutrlLinksList($core, $list_all, $list_counter);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
if (!empty($_POST['deletelinks'])) {
try {
foreach($_POST['entries'] as $id) {
$rs = $log->getLogs(['kut_id' => $id]);
if ($rs->isEmpty()) {
continue;
}
if (null === ($o = kutrl::quickService($rs->kut_type))) {
continue;
}
$o->remove($rs->kut_url);
}
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Links successfully deleted')
);
http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
}
# display header
echo
'<html><head><title>kUtRL, ' . __('Links shortener') . '</title>';
if ($part == 'links') {
echo
'<script type="text/javascript">' . "\n" .
"//<![CDATA[\n" .
dcPage::jsVar(
'dotclear.filter_reset_url',
html::escapeJS($p_url . '&part=links')
) . "\n" .
"\$(function(){\$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});});\n" .
"//]]>\n" .
"</script>\n" .
dcPage::jsFilterControl($show_filters);
}
echo
'</head><body>';
# display setting
if ($part == 'setting') {
echo
dcPage::breadcrumb(
[
__('Links shortener') => '',
'<span class="page-title">' . __('Plugin configuration') . '</span>' => '',
__('Services configuration') => $p_url .'&amp;part=service'
],
['hl' => false]
) .
dcPage::notices() .
'<h3>' . __('Plugin configuration') . '</h3>
<p><a class="back" href="' . $p_url . '">' . __('Back to links list') . '</a></p>
<form id="setting-form" method="post" action="' . $p_url . '">
<div class="fieldset" id="setting-plugin">
<h4>' . __('Plugin activation') . '</h4>
<p><label class="classic">' .
form::checkbox(['s_active'], '1', $s_active) .
__('Enable plugin') . '</label></p>
</div>
<div class="fieldset" id="setting-option">
<h4>' . __('Behaviors') . '</h4>
<p><label class="classic">' .
form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) .
__('Allow short link for external URL') . '</label></p>
<p class="form-note">' . __('Not only link started with this blog URL could be shortened.') . '</p>
<p><label class="classic">' .
form::checkbox(['s_tpl_passive'], '1', $s_tpl_passive) .
__('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>
<p><label class="classic">' .
form::checkbox(['s_tpl_active'], '1', $s_tpl_active) .
__('Active mode') . '</label></p>
<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 />' .
__('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '</p>
<p><label class="classic">' .
form::checkbox(['s_admin_entry_default'], '1', $s_admin_entry_default) .
__('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>
<div class="fieldset" id="setting-service">
<h4>' . __('Default services') . '</h4>
<p><label>';
if (!empty($msg)) {
if (null !== ($o = kutrl::quickPlace($s_admin_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Administration:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_plugin_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Extensions:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_tpl_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Templates:') . '<br />' .
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($msg)) {
if (null !== ($o = kutrl::quickPlace($s_wiki_service))) {
echo $o->testService() ? $img_green : $img_red;
}
}
echo '&nbsp;' . __('Contents:') . '<br />' .
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>
<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() .
form::hidden(['part'], 'setting') . '
</p>
</form>';
}
# display service
if ($part == 'service') {
echo
dcPage::breadcrumb(
[
__('Links shortener') => '',
__('Plugin configuration') => $p_url . '&amp;part=setting',
'<span class="page-title">' . __('Services configuration') . '</span>' => ''
],
['hl' => false]
) .
dcPage::notices() .
'<h3>' . __('Services configuration') . '</h3>' .
'<p><a class="back" href="' . $p_url . '">' . __('Back to links list') . '</a></p>';
'<form id="service-form" method="post" action="' . $p_url . '">';
foreach(kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
echo '<div class="fieldset" id="setting-' . $service_id . '"><h4>' . $o->name . '</h4>';
if (!empty($_POST['save'])) {
echo '<p><em>' . (
$o->testService() ?
$img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name) :
$img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name)
) . '</em></p>';
//if ($o->error->flag()) {
echo $o->error->toHTML();
//}
}
if (!empty($o->home)) {
echo '<p><a title="' . __('homepage') . '" href="' . $o->home . '">' . sprintf(__('Learn more about %s.'), $o->name) . '</a></p>';
}
$o->settingsForm();
echo '</div>';
}
echo '
<div class="clear">
<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() .
form::hidden(['part'], 'service') . '
</p></div>
</form>';
}
# display link creation
if ($part == 'link') {
echo
dcPage::breadcrumb(
[
__('Links shortener') => '',
__('Links') => $core->adminurl->get('admin.plugin.kUtRL'),
'<span class="page-title">' . __('New link') . '</span>' => ''
],
['hl' => false]
) .
dcPage::notices();
if (null === $kut) {
echo '<p>' . __('You must set an admin service.') . '</p>';
} else {
echo '
<div class="fieldset">
<h4>' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '</h4>
<form id="create-link" method="post" action="' . $p_url . '">
<p><label for="str">' . __('Long link:') . '</label>' .
form::field('str', 100, 255, '') . '</p>';
if ($kut->allow_custom_hash) {
echo
'<p><label for="custom">' . __('Custom short link:') . '</label>' .
form::field('custom', 50, 32, '') . '</p>' .
'<p class="form-note">' . __('Only if you want a custom short link.') . '</p>';
if ($kut->admin_service == 'local') {
echo '<p class="form-note">' .
__('You can use "bob!!" if you want a semi-custom link, it starts with "bob" and "!!" will be replaced by an increment value.') .
'</p>';
}
}
echo '
<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() .
form::hidden(['part'], 'link') . '
</p></div>
</form>';
}
}
if ($part == 'links') {
echo
dcPage::breadcrumb(
[
__('Links shortener') => '',
'<span class="page-title">' . __('Links') . '</span>' => '',
__('New link') => $core->adminurl->get('admin.plugin.kUtRL').'&amp;part=link'
],
['hl' => false]
) .
dcPage::notices();
echo '
<form action="' . $p_url . '&amp;part=links" method="get" id="filters-form">
<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>
<div class="table">
<div class="cell">
<h4>' . __('Filters') . '</h4>
<p><label for="urlsrv" class="ib">' . __('Service:') . '</label>' .
form::combo('urlsrv', $lst_services_combo, $urlsrv) . '
</div>
<div class="cell filters-options">
<h4>' . __('Display options') . '</h4>
<p><label for="sortby" class="ib">' . __('Order by:') . '</label>' .
form::combo('sortby', $sortby_combo, $sortby) . '</p>
<p><label for="order" class="ib">' . __('Sort:') . '</label>' .
form::combo('order', $order_combo, $order) . '</p>
<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' .
form::number('nb', 0, 999, $nb_per_page) .
__('entries per page') . '</label></p>' .
form::hidden('part', 'links') .
form::hidden('p', 'kUtRL') . '
</div>
</div>
<p><input type="submit" value="' . __('Apply filters and display options') . '" />
<br class="clear" /></p>
</form>
<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">';
$list_current->display($page, $nb_per_page, $pager_base_url);
echo '
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
<p class="col right">
<input type="submit" value="' . __('Delete selected short links') . '" />' .
form::hidden(['deletelinks'], 1) .
form::hidden(['urlsrv'], $urlsrv) .
form::hidden(['sortby'], $sortby) .
form::hidden(['order'], $order) .
form::hidden(['page'], $page) .
form::hidden(['nb'], $nb_per_page) .
form::hidden(['part'], 'links') .
$core->formNonce() . '
</p>
</div>
</form>';
}
# display footer
dcPage::helpBlock('kUtRL');
echo
'<p class="clear right">
<a href="' . $p_url . '&amp;part=setting">' . __('Plugin configuration') . '</a> -
<a href="' . $p_url . '&amp;part=service">' . __('Services configuration') . '</a> -
kUtRL - ' . $core->plugins->moduleInfo('kUtRL', 'version') . '&nbsp;
<a href="' . $core->plugins->getModules('kUtRL')['support'] . '">
<img alt="' . __('kUtRL') . '" src="index.php?pf=kUtRL/icon.png" /></a>
</p>
</body></html>';

View file

@ -1,15 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
* This file is part of kUtRL, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2011 JC Denis and contributors
* jcdenis@gdwd.com
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* -- END LICENSE BLOCK ------------------------------------*/
$(function(){
/* toogle admin form sidebar */
$('#kutrl-form-title').toggleWithLegend($('#kutrl-form-content'),{cookie:'dcx_kutrl_admin_form_sidebar'});
});

View file

@ -1,80 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
* This file is part of kUtRL, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2011 JC Denis and contributors
* jcdenis@gdwd.com
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* -- END LICENSE BLOCK ------------------------------------*/
$(function(){
/* tools */
dotclear.jcTools = new jcToolsBox();
/* wait message */
$('#content').submit(function(){dotclear.jcTools.waitMessage();return true;});
});
function jcToolsBox(){}
jcToolsBox.prototype={
text_wait:'Please wait',
section:'',
formFieldsetToMenu:function(form){
var This=this;
var section=$(form).children('fieldset[id='+This.section+']').attr('id');
var hidden_section=$(form).children('input[name=section]').attr('value');
var formMenu=$(form).children('p.formMenu').get(0);
if (formMenu==undefined) {
$(form).prepend($('<p></p>').addClass('formMenu'));
}
$(form).children('fieldset').each(function(){
var Fieldset=this;
$(Fieldset).hide();
var title=$(Fieldset).children('legend').text();
var menu=$('<a></a>').text(title).addClass('button').attr('tabindex','2').click(
function(){
var fieldset_visible=$(form).children('fieldset:visible');
if (fieldset_visible==undefined){
$(Fieldset).slideDown('slow');$(form).children('input[type=submit]').show();
}else{
$(fieldset_visible).fadeOut('fast',function(){$(Fieldset).fadeIn('fast');$(form).children('input[type=submit]').show();})
}
if (hidden_section==undefined){
$(form).children('input[name=section]').remove();
$(form).append($('<input type="hidden" />').attr('name','section').attr('value',$(Fieldset).attr('id')));
}
$('.message').fadeOut('slow',function(){$(this).slideUp('slow',function(){$(this).remove();})});
}
);
$(form).children('.formMenu').append(menu).append(' ');
});
if (section!=undefined){
$(form).children('fieldset[id='+section+']').show();
}else{
$(form).children('fieldset:first').show();
}
},
waitMessage:function(){
var This=this;
var content=$('div[id=content]');
if (content!=undefined){
$(content).hide();
}else{
$('input').hide();$('select').hide();
content=$('body');
}
var text=$('<p></p>').addClass('message').text(This.text_wait);
This.blinkItem(text);
var box=$('<div></div>').attr('style','margin: 60px auto auto;width:200px;').append(text);
$(content).before($(box));
},
blinkItem:function(item){
var This=this;
$(item).fadeOut('slow',function(){$(this).fadeIn('slow',function(){This.blinkItem(this);})});
}
}

View file

@ -1,17 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
* This file is part of kUtRL, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2011 JC Denis and contributors
* jcdenis@gdwd.com
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* -- END LICENSE BLOCK ------------------------------------*/
$(function() {
var kutrlForm=$('#service-form');
if (kutrlForm!=undefined){
dotclear.jcTools.formFieldsetToMenu(kutrlForm);
}
});

View file

@ -1,17 +0,0 @@
/* -- BEGIN LICENSE BLOCK ----------------------------------
* This file is part of kUtRL, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2011 JC Denis and contributors
* jcdenis@gdwd.com
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* -- END LICENSE BLOCK ------------------------------------*/
$(function() {
var kutrlForm=$('#setting-form');
if (kutrlForm!=undefined){
dotclear.jcTools.formFieldsetToMenu(kutrlForm);
}
});