update to PSR12

This commit is contained in:
Jean-Christian Denis 2021-11-06 16:43:02 +01:00
parent 40a3269b20
commit cfcccf32d7
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
29 changed files with 798 additions and 790 deletions

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -118,14 +117,13 @@ class adminKutrl
if ($post) { if ($post) {
$post_url = $post->getURL(); $post_url = $post->getURL();
$rs = $kut->isKnowUrl($post_url); $rs = $kut->isKnowUrl($post_url);
} else { } else {
$post_url = ''; $post_url = '';
$rs = false; $rs = false;
} }
$ret = $ret = '<div id="kUtRL"><h5>' . __('Short link') . '</h5>' .
'<div id="kUtRL"><h5>' . __('Short link') . '</h5>' .
form::hidden(['kutrl_old_post_url'], $post_url); form::hidden(['kutrl_old_post_url'], $post_url);
if (!$rs) { if (!$rs) {
@ -134,14 +132,12 @@ class adminKutrl
} else { } else {
$chk = !empty($_POST['kutrl_create']); $chk = !empty($_POST['kutrl_create']);
} }
$ret .= $ret .= '<p><label class="classic">' .
'<p><label class="classic">' .
form::checkbox('kutrl_create', 1, $chk, '', 3) . ' ' . form::checkbox('kutrl_create', 1, $chk, '', 3) . ' ' .
__('Create short link') . '</label></p>'; __('Create short link') . '</label></p>';
if ($kut->allow_custom_hash) { if ($kut->allow_custom_hash) {
$ret .= $ret .= '<p class="classic">' .
'<p class="classic">' .
'<label for="custom">' . __('Custom short link:') . ' ' . '<label for="custom">' . __('Custom short link:') . ' ' .
form::field('kutrl_create_custom', 32, 32, '', 3) . form::field('kutrl_create_custom', 32, 32, '', 3) .
'</label></p>'; '</label></p>';
@ -153,12 +149,11 @@ class adminKutrl
} elseif ($count == 1) { } elseif ($count == 1) {
$title = __('followed one time'); $title = __('followed one time');
} else { } else {
$title = sprintf(__('followed %s times'),$count); $title = sprintf(__('followed %s times'), $count);
} }
$href = $kut->url_base . $rs->hash; $href = $kut->url_base . $rs->hash;
$ret .= $ret .= '<p><label class="classic">' .
'<p><label class="classic">' .
form::checkbox('kutrl_delete', 1, !empty($_POST['kutrl_delete']), '', 3) . ' ' . form::checkbox('kutrl_delete', 1, !empty($_POST['kutrl_delete']), '', 3) . ' ' .
__('Delete short link') . '</label></p>' . __('Delete short link') . '</label></p>' .
'<p><a href="' . $href . '" ' . 'title="' . $title . '">' . $href . '</a></p>'; '<p><a href="' . $href . '" ' . 'title="' . $title . '">' . $href . '</a></p>';
@ -194,7 +189,7 @@ class adminKutrl
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
} }
$title = html::escapeHTML($rs->post_title); $title = html::escapeHTML($rs->post_title);
$new_post_url = $rs->getURL(); $new_post_url = $rs->getURL();
# Delete # Delete
@ -208,12 +203,12 @@ class adminKutrl
$kut->remove($old_post_url); $kut->remove($old_post_url);
$rs = $kut->hash($new_post_url, $custom); // better to update (not yet implemented) $rs = $kut->hash($new_post_url, $custom); // better to update (not yet implemented)
$url = $kut->url_base . $rs->hash; $url = $kut->url_base . $rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate' ,$core, $rs, $title); $core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title);
} }
} }
} }
@ -239,7 +234,7 @@ class adminKutrl
$custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ? $custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ?
$_POST['kutrl_create_custom'] : null; $_POST['kutrl_create_custom'] : null;
$rs = $kut->hash($rs->getURL(), $custom); $rs = $kut->hash($rs->getURL(), $custom);
$url = $kut->url_base . $rs->hash; $url = $kut->url_base . $rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
@ -274,7 +269,7 @@ class adminKutrl
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active if (!$s->kutrl_active
|| !$core->auth->check('admin',$core->blog->id)) { || !$core->auth->check('admin', $core->blog->id)) {
return null; return null;
} }
@ -316,7 +311,8 @@ class backupKutrl
{ {
public static function exportSingle($core, $exp, $blog_id) public static function exportSingle($core, $exp, $blog_id)
{ {
$exp->export('kutrl', $exp->export(
'kutrl',
'SELECT kut_id, blog_id, kut_service, kut_type, ' . 'SELECT kut_id, blog_id, kut_service, kut_type, ' .
'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' . 'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' .
'FROM ' . $core->prefix . 'kutrl ' . 'FROM ' . $core->prefix . 'kutrl ' .
@ -332,10 +328,10 @@ class backupKutrl
public static function importInit($bk, $core) public static function importInit($bk, $core)
{ {
$bk->cur_kutrl = $core->con->openCursor($core->prefix . 'kutrl'); $bk->cur_kutrl = $core->con->openCursor($core->prefix . 'kutrl');
$bk->kutrl = new kutrlLog($core); $bk->kutrl = new kutrlLog($core);
} }
public static function importSingle($line,$bk,$core) public static function importSingle($line, $bk, $core)
{ {
if ($line->__name == 'kutrl') { if ($line->__name == 'kutrl') {
# Do nothing if str/type exists ! # Do nothing if str/type exists !
@ -349,14 +345,14 @@ class backupKutrl
{ {
if ($line->__name == 'kutrl') { if ($line->__name == 'kutrl') {
$bk->cur_kutrl->clean(); $bk->cur_kutrl->clean();
$bk->cur_kutrl->kut_id = (integer) $line->kut_id; $bk->cur_kutrl->kut_id = (int) $line->kut_id;
$bk->cur_kutrl->blog_id = (string) $line->blog_id; $bk->cur_kutrl->blog_id = (string) $line->blog_id;
$bk->cur_kutrl->kut_service = (string) $line->kut_service; $bk->cur_kutrl->kut_service = (string) $line->kut_service;
$bk->cur_kutrl->kut_type = (string) $line->kut_type; $bk->cur_kutrl->kut_type = (string) $line->kut_type;
$bk->cur_kutrl->kut_hash = (string) $line->kut_hash; $bk->cur_kutrl->kut_hash = (string) $line->kut_hash;
$bk->cur_kutrl->kut_url = (string) $line->kut_url; $bk->cur_kutrl->kut_url = (string) $line->kut_url;
$bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt; $bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt;
$bk->cur_kutrl->kut_counter = (integer) $line->kut_counter; $bk->cur_kutrl->kut_counter = (int) $line->kut_counter;
$bk->cur_kutrl->kut_password = (string) $line->kut_password; $bk->cur_kutrl->kut_password = (string) $line->kut_password;
$bk->cur_kutrl->insert(); $bk->cur_kutrl->insert();
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
@ -26,34 +25,34 @@ $img_green = '<img src="images/check-on.png" alt="ok" />';
$img_red = '<img src="images/check-off.png" alt="fail" />'; $img_red = '<img src="images/check-off.png" alt="fail" />';
$services_combo = []; $services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service) { foreach (kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core); $o = new $service($core);
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
$lst_services_combo = array_merge(['-' => ''], $services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo);
$s_active = (boolean) $s->kutrl_active; $s_active = (bool) $s->kutrl_active;
$s_plugin_service = (string) $s->kutrl_plugin_service; $s_plugin_service = (string) $s->kutrl_plugin_service;
$s_admin_service = (string) $s->kutrl_admin_service; $s_admin_service = (string) $s->kutrl_admin_service;
$s_tpl_service = (string) $s->kutrl_tpl_service; $s_tpl_service = (string) $s->kutrl_tpl_service;
$s_wiki_service = (string) $s->kutrl_wiki_service; $s_wiki_service = (string) $s->kutrl_wiki_service;
$s_allow_external_url = (boolean) $s->kutrl_allow_external_url; $s_allow_external_url = (bool) $s->kutrl_allow_external_url;
$s_tpl_passive = (boolean) $s->kutrl_tpl_passive; $s_tpl_passive = (bool) $s->kutrl_tpl_passive;
$s_tpl_active = (boolean) $s->kutrl_tpl_active; $s_tpl_active = (bool) $s->kutrl_tpl_active;
$s_admin_entry_default = (string) $s->kutrl_admin_entry_default; $s_admin_entry_default = (string) $s->kutrl_admin_entry_default;
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
# settings # settings
$s_active = !empty($_POST['s_active']); $s_active = !empty($_POST['s_active']);
$s_admin_service = (string) $_POST['s_admin_service']; $s_admin_service = (string) $_POST['s_admin_service'];
$s_plugin_service = (string) $_POST['s_plugin_service']; $s_plugin_service = (string) $_POST['s_plugin_service'];
$s_tpl_service = (string) $_POST['s_tpl_service']; $s_tpl_service = (string) $_POST['s_tpl_service'];
$s_wiki_service = (string) $_POST['s_wiki_service']; $s_wiki_service = (string) $_POST['s_wiki_service'];
$s_allow_external_url = !empty($_POST['s_allow_external_url']); $s_allow_external_url = !empty($_POST['s_allow_external_url']);
$s_tpl_passive = !empty($_POST['s_tpl_passive']); $s_tpl_passive = !empty($_POST['s_tpl_passive']);
$s_tpl_active = !empty($_POST['s_tpl_active']); $s_tpl_active = !empty($_POST['s_tpl_active']);
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']); $s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
$s->put('kutrl_active', $s_active); $s->put('kutrl_active', $s_active);
@ -67,7 +66,7 @@ if (!empty($_POST['save'])) {
$s->put('kutrl_admin_entry_default', $s_admin_entry_default); $s->put('kutrl_admin_entry_default', $s_admin_entry_default);
# services # services
foreach(kutrl::getServices($core) as $service_id => $service) { foreach (kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core); $o = new $service($core);
$o->saveSettings(); $o->saveSettings();
} }
@ -88,16 +87,16 @@ if (!empty($_POST['save'])) {
} }
echo ' echo '
<div class="fieldset"><h4>' . __('Settings') . '</h4> <div class="fieldset"><h4>' . __('Settings') . '</h4>
<div id="setting-plugin"> <div id="setting-plugin">
<h5>' . __('Activation') . '</h5> <h5>' . __('Activation') . '</h5>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(['s_active'], '1', $s_active) . form::checkbox(['s_active'], '1', $s_active) .
__('Enable plugin') . '</label></p> __('Enable plugin') . '</label></p>
</div> </div>
<hr/><div id="setting-option"> <hr/><div id="setting-option">
<h5>' . __('Behaviors') . '</h5> <h5>' . __('Behaviors') . '</h5>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) . form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) .
__('Allow short link for external URL') . '</label></p> __('Allow short link for external URL') . '</label></p>
@ -119,7 +118,7 @@ __('Create short link for new entries') . '</label></p>
</div> </div>
<hr/><div id="setting-service"> <hr/><div id="setting-service">
<h5>' . __('Default services') . '</h5> <h5>' . __('Default services') . '</h5>
<p><label>'; <p><label>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
if (null !== ($o = kutrl::quickPlace($s_admin_service))) { if (null !== ($o = kutrl::quickPlace($s_admin_service))) {
@ -164,17 +163,18 @@ form::combo(['s_wiki_service'], $ext_services_combo, $s_wiki_service) . '
</div> </div>
<div class="fieldset"> <div class="fieldset">
<h4>' .__('Services') . '</h4> <h4>' . __('Services') . '</h4>
<p class="info">' . __('List of services you can use to shorten links with pkugin kUtRL.') . '</p> <p class="info">' . __('List of services you can use to shorten links with pkugin kUtRL.') . '</p>
'; ';
foreach(kutrl::getServices($core) as $service_id => $service) { foreach (kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core); $o = new $service($core);
echo '<hr/><div id="setting-' . $service_id . '"><h5>' . $o->name . '</h5>'; echo '<hr/><div id="setting-' . $service_id . '"><h5>' . $o->name . '</h5>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
$img_chk = $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name); $img_chk = $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name);
try { try {
if ($o->testService()) { if ($o->testService()) {
$img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name); $img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name);

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
@ -45,7 +44,7 @@ try {
->index('idx_kut_service', 'btree', 'kut_service') ->index('idx_kut_service', 'btree', 'kut_service')
->index('idx_kut_type', 'btree', 'kut_type'); ->index('idx_kut_type', 'btree', 'kut_type');
$ti = new dbStruct($core->con, $core->prefix); $ti = new dbStruct($core->con, $core->prefix);
$changes = $ti->synchronize($t); $changes = $ti->synchronize($t);
# Settings # Settings
@ -61,9 +60,8 @@ try {
$s->put('kutrl_tpl_active', false, 'boolean', 'Return short url on dotclear tags if kutrl is active', false, true); $s->put('kutrl_tpl_active', false, 'boolean', 'Return short url on dotclear tags if kutrl is active', false, true);
$s->put('kutrl_admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true); $s->put('kutrl_admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true);
# Settings for "local" service # Settings for "local" service
$local_css = $local_css = ".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" .
".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" . '.dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }';
".dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }";
$s->put('kutrl_srv_local_protocols', 'http:,https:,ftp:,ftps:,irc:', 'string', 'Allowed kutrl local service protocols', false, true); $s->put('kutrl_srv_local_protocols', 'http:,https:,ftp:,ftps:,irc:', 'string', 'Allowed kutrl local service protocols', false, true);
$s->put('kutrl_srv_local_public', false, 'boolean', 'Enabled local service public page', false, true); $s->put('kutrl_srv_local_public', false, 'boolean', 'Enabled local service public page', false, true);
$s->put('kutrl_srv_local_css', $local_css, 'string', 'Special CSS for kutrl local service', false, true); $s->put('kutrl_srv_local_css', $local_css, 'string', 'Special CSS for kutrl local service', false, true);
@ -82,6 +80,7 @@ try {
if ($core->plugins->moduleExists('dcMiniUrl')) { if ($core->plugins->moduleExists('dcMiniUrl')) {
require_once dirname(__FILE__) . '/inc/patch.dcminiurl.php'; require_once dirname(__FILE__) . '/inc/patch.dcminiurl.php';
} }
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return; return;
} }
@ -33,7 +32,7 @@ if (!defined('SHORTEN_SERVICE_ENCODE')) {
} }
# Main class # Main class
$d = dirname(__FILE__) . '/inc/'; $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';
@ -41,22 +40,22 @@ $__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php';
# Services # Services
$__autoload['defaultKutrlService'] = $d . 'services/class.default.service.php'; $__autoload['defaultKutrlService'] = $d . 'services/class.default.service.php';
$core->addBehavior('kutrlService', function() { return ["default","defaultKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['default','defaultKutrlService']; });
if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) { if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) {
$__autoload['customKutrlService'] = $d . 'services/class.custom.service.php'; $__autoload['customKutrlService'] = $d . 'services/class.custom.service.php';
$core->addBehavior('kutrlService', function() { return ["custom","customKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['custom','customKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) { if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) {
$__autoload['localKutrlService'] = $d . 'services/class.local.service.php'; $__autoload['localKutrlService'] = $d . 'services/class.local.service.php';
$core->addBehavior('kutrlService', function() { return ["local","localKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['local','localKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) { if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) {
$__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php'; $__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php';
$core->addBehavior('kutrlService', function() { return ["bilbolinks","bilbolinksKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['bilbolinks','bilbolinksKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) { if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) {
$__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php'; $__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php';
$core->addBehavior('kutrlService', function() { return ["bitly","bitlyKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['bitly','bitlyKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_GOOGL')) { //if (!defined('SHORTEN_SERVICE_DISABLE_GOOGL')) {
// $__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php'; // $__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php';
@ -64,7 +63,7 @@ if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) {
//} //}
if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) { if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
$__autoload['isgdKutrlService'] = $d . 'services/class.isgd.service.php'; $__autoload['isgdKutrlService'] = $d . 'services/class.isgd.service.php';
$core->addBehavior('kutrlService', function() { return ["isgd","isgdKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['isgd','isgdKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_SHORTTO')) { //if (!defined('SHORTEN_SERVICE_DISABLE_SHORTTO')) {
// $__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php'; // $__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php';
@ -76,7 +75,7 @@ if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
//} //}
if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) { if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) {
$__autoload['yourlsKutrlService'] = $d . 'services/class.yourls.service.php'; $__autoload['yourlsKutrlService'] = $d . 'services/class.yourls.service.php';
$core->addBehavior('kutrlService', function() { return ["yourls","yourlsKutrlService"]; } ); $core->addBehavior('kutrlService', function () { return ['yourls','yourlsKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_SUPR')) { //if (!defined('SHORTEN_SERVICE_DISABLE_SUPR')) {
// $__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php'; // $__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php';
@ -85,9 +84,9 @@ if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) {
# Shorten url passed through wiki functions # Shorten url passed through wiki functions
$__autoload['kutrlWiki'] = $d . 'lib.wiki.kutrl.php'; $__autoload['kutrlWiki'] = $d . 'lib.wiki.kutrl.php';
$core->addBehavior('coreInitWikiPost',['kutrlWiki','coreInitWiki']); $core->addBehavior('coreInitWikiPost', ['kutrlWiki','coreInitWiki']);
$core->addBehavior('coreInitWikiComment',['kutrlWiki','coreInitWiki']); $core->addBehavior('coreInitWikiComment', ['kutrlWiki','coreInitWiki']);
$core->addBehavior('coreInitWikiSimpleComment',['kutrlWiki','coreInitWiki']); $core->addBehavior('coreInitWikiSimpleComment', ['kutrlWiki','coreInitWiki']);
# Public page # Public page
$core->url->register('kutrl', 'go', '^go(/(.*?)|)$', ['urlKutrl', 'redirectUrl']); $core->url->register('kutrl', 'go', '^go(/(.*?)|)$', ['urlKutrl', 'redirectUrl']);

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -67,9 +66,9 @@ class urlKutrl extends dcUrlHandlers
return null; return null;
} }
$args = isset($m[3]) ? $m[3] : ''; $args = $m[3] ?? '';
$_ctx->kutrl_msg = ''; $_ctx->kutrl_msg = '';
$_ctx->kutrl_hmf = hmfKutrl::create(); $_ctx->kutrl_hmf = hmfKutrl::create();
$_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf); $_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf);
$kut = new localKutrlService($core); $kut = new localKutrlService($core);
@ -81,7 +80,7 @@ class urlKutrl extends dcUrlHandlers
# find suffix on redirect url # find suffix on redirect url
$suffix = ''; $suffix = '';
if (preg_match('@^([^?/#]+)(.*?)$@', $args, $more)) { if (preg_match('@^([^?/#]+)(.*?)$@', $args, $more)) {
$args = $more[1]; $args = $more[1];
$suffix = $more[2]; $suffix = $more[2];
} }
# No arg, go to kurtl page # No arg, go to kurtl page
@ -131,50 +130,50 @@ class urlKutrl extends dcUrlHandlers
# Validation form # Validation form
$url = !empty($_POST['longurl']) ? trim($core->con->escape($_POST['longurl'])) : ''; $url = !empty($_POST['longurl']) ? trim($core->con->escape($_POST['longurl'])) : '';
if (!empty($url)) { if (!empty($url)) {
$hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!'; $hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!';
$hmfu = !empty($_POST['hmfp']) ? hmfKutrl::unprotect($_POST['hmfp']) : '?'; $hmfu = !empty($_POST['hmfp']) ? hmfKutrl::unprotect($_POST['hmfp']) : '?';
$err = false; $err = false;
if (!$err) { if (!$err) {
if ($hmf != $hmfu) { if ($hmf != $hmfu) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Failed to verify protected field.'); $_ctx->kutrl_msg = __('Failed to verify protected field.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->testService()) { if (!$kut->testService()) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Service is not well configured.'); $_ctx->kutrl_msg = __('Service is not well configured.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isValidUrl($url)) { if (!$kut->isValidUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This string is not a valid URL.'); $_ctx->kutrl_msg = __('This string is not a valid URL.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isLongerUrl($url)) { if (!$kut->isLongerUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This link is too short.'); $_ctx->kutrl_msg = __('This link is too short.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isProtocolUrl($url)) { if (!$kut->isProtocolUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This type of link is not allowed.'); $_ctx->kutrl_msg = __('This type of link is not allowed.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Short links are limited to this blog URL.'); $_ctx->kutrl_msg = __('Short links are limited to this blog URL.');
} }
} }
if (!$err) { if (!$err) {
if ($kut->isServiceUrl($url)) { if ($kut->isServiceUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This link is already a short link.'); $_ctx->kutrl_msg = __('This link is already a short link.');
} }
} }
@ -182,7 +181,7 @@ class urlKutrl extends dcUrlHandlers
if (false !== ($rs = $kut->isKnowUrl($url))) { if (false !== ($rs = $kut->isKnowUrl($url))) {
$err = true; $err = true;
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
$_ctx->kutrl_msg = sprintf( $_ctx->kutrl_msg = sprintf(
@ -194,10 +193,10 @@ class urlKutrl extends dcUrlHandlers
} }
if (!$err) { if (!$err) {
if (false === ($rs = $kut->hash($url))) { if (false === ($rs = $kut->hash($url))) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Failed to create short link.'); $_ctx->kutrl_msg = __('Failed to create short link.');
} else { } else {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
$_ctx->kutrl_msg = sprintf( $_ctx->kutrl_msg = sprintf(
@ -232,13 +231,13 @@ class urlKutrl extends dcUrlHandlers
} }
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates');
$_ctx =& $GLOBALS['_ctx']; $_ctx = & $GLOBALS['_ctx'];
$core = $GLOBALS['core']; $core = $GLOBALS['core'];
header('Content-Type: text/html; charset=UTF-8'); header('Content-Type: text/html; charset=UTF-8');
http::head(404, 'Not Found'); http::head(404, 'Not Found');
$core->url->type = '404'; $core->url->type = '404';
$_ctx->current_tpl = 'kutrl404.html'; $_ctx->current_tpl = 'kutrl404.html';
$_ctx->content_type = 'text/html'; $_ctx->content_type = 'text/html';
echo $core->tpl->getData($_ctx->current_tpl); echo $core->tpl->getData($_ctx->current_tpl);
@ -266,18 +265,20 @@ class pubKutrl
# Disable URL shoretning on filtered tag # Disable URL shoretning on filtered tag
public static function templateBeforeValue($core, $tag, $attr) public static function templateBeforeValue($core, $tag, $attr)
{ {
if (!empty($attr['disable_kutrl']) && in_array($tag,pubKutrl::$know_tags)) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
return '<?php $GLOBALS["disable_kutrl"] = true; ?>'; return '<?php $GLOBALS["disable_kutrl"] = true; ?>';
} }
return null; return null;
} }
# Re unable it after tag # Re unable it after tag
public static function templateAfterValue($core, $tag, $attr) public static function templateAfterValue($core, $tag, $attr)
{ {
if (!empty($attr['disable_kutrl']) && in_array($tag,pubKutrl::$know_tags)) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
return '<?php $GLOBALS["disable_kutrl"] = false; ?>'; return '<?php $GLOBALS["disable_kutrl"] = false; ?>';
} }
return null; return null;
} }
@ -285,7 +286,7 @@ class pubKutrl
public static function publicBeforeContentFilter($core, $tag, $args) public static function publicBeforeContentFilter($core, $tag, $args)
{ {
# Unknow tag # Unknow tag
if (!in_array($tag,pubKutrl::$know_tags)) { if (!in_array($tag, pubKutrl::$know_tags)) {
return null; return null;
} }
# URL shortening is disabled by tag attribute # URL shortening is disabled by tag attribute
@ -324,7 +325,7 @@ class pubKutrl
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
# Passive : all kutrl tag return long url # Passive : all kutrl tag return long url
$_ctx->kutrl_passive = (boolean) $s->kutrl_tpl_passive; $_ctx->kutrl_passive = (bool) $s->kutrl_tpl_passive;
if (!$s->kutrl_active || !$s->kutrl_tpl_service) { if (!$s->kutrl_active || !$s->kutrl_tpl_service) {
return null; return null;
@ -353,6 +354,7 @@ class tplKutrl
public static function pageURL($attr) public static function pageURL($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f, '$core->blog->url.$core->url->getBase("kutrl")') . '; ?>'; return '<?php echo ' . sprintf($f, '$core->blog->url.$core->url->getBase("kutrl")') . '; ?>';
} }
@ -361,7 +363,7 @@ class tplKutrl
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (boolean) $attr['is_active'] ? '' : '!'; $sign = (bool) $attr['is_active'] ? '' : '!';
$if[] = $sign . '$core->blog->settings->kUtRL->kutrl_srv_local_public'; $if[] = $sign . '$core->blog->settings->kUtRL->kutrl_srv_local_public';
} }
if (empty($if)) { if (empty($if)) {
@ -369,7 +371,7 @@ class tplKutrl
} }
return return
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
$content . $content .
"<?php endif; unset(\$s);?>\n"; "<?php endif; unset(\$s);?>\n";
} }
@ -379,7 +381,7 @@ class tplKutrl
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
if (isset($attr['has_message'])) { if (isset($attr['has_message'])) {
$sign = (boolean) $attr['has_message'] ? '!' : '='; $sign = (bool) $attr['has_message'] ? '!' : '=';
$if[] = '"" ' . $sign . '= $_ctx->kutrl_msg'; $if[] = '"" ' . $sign . '= $_ctx->kutrl_msg';
} }
if (empty($if)) { if (empty($if)) {
@ -387,7 +389,7 @@ class tplKutrl
} }
return return
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
$content . $content .
"<?php endif; ?>\n"; "<?php endif; ?>\n";
} }
@ -405,8 +407,8 @@ class tplKutrl
public static function humanFieldProtect($attr) public static function humanFieldProtect($attr)
{ {
return return
"<input type=\"hidden\" name=\"hmfp\" id=\"hmfp\" value=\"<?php echo \$_ctx->kutrl_hmfp; ?>\" />". '<input type="hidden" name="hmfp" id="hmfp" value="<?php echo $_ctx->kutrl_hmfp; ?>" />' .
"<?php echo \$core->formNonce(); ?>"; '<?php echo $core->formNonce(); ?>';
} }
public static function AttachmentKutrlIf($attr, $content) public static function AttachmentKutrlIf($attr, $content)
@ -439,7 +441,7 @@ class tplKutrl
return self::genericKutrl('$_ctx->posts->user_url', $attr); return self::genericKutrl('$_ctx->posts->user_url', $attr);
} }
public static function EntryKutrlIf($attr,$content) public static function EntryKutrlIf($attr, $content)
{ {
return self::genericKutrlIf('$_ctx->posts->getURL()', $attr, $content); return self::genericKutrlIf('$_ctx->posts->getURL()', $attr, $content);
} }
@ -474,22 +476,23 @@ class tplKutrl
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (boolean) $attr['is_active'] ? '' : '!'; $sign = (bool) $attr['is_active'] ? '' : '!';
$if[] = $sign . '$_ctx->exists("kutrl")'; $if[] = $sign . '$_ctx->exists("kutrl")';
} }
if (isset($attr['passive_mode'])) { if (isset($attr['passive_mode'])) {
$sign = (boolean) $attr['passive_mode'] ? '' : '!'; $sign = (bool) $attr['passive_mode'] ? '' : '!';
$if[] = $sign . '$_ctx->kutrl_passive'; $if[] = $sign . '$_ctx->kutrl_passive';
} }
if (isset($attr['has_kutrl'])) { if (isset($attr['has_kutrl'])) {
$sign = (boolean) $attr['has_kutrl'] ? '!' : '='; $sign = (bool) $attr['has_kutrl'] ? '!' : '=';
$if[] = '($_ctx->exists("kutrl") && false ' . $sign . '== $_ctx->kutrl->select(' . $str . ',null,null,"kutrl"))'; $if[] = '($_ctx->exists("kutrl") && false ' . $sign . '== $_ctx->kutrl->select(' . $str . ',null,null,"kutrl"))';
} }
if (empty($if)) { if (empty($if)) {
return $content; return $content;
} }
return return
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" . '<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
$content . $content .
"<?php endif; ?>\n"; "<?php endif; ?>\n";
} }
@ -497,29 +500,30 @@ class tplKutrl
protected static function genericKutrl($str, $attr) protected static function genericKutrl($str, $attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return return
"<?php \n" . "<?php \n" .
# Preview # Preview
"if (\$_ctx->preview) { \n" . "if (\$_ctx->preview) { \n" .
" echo " . sprintf($f, $str) . "; " . ' echo ' . sprintf($f, $str) . '; ' .
"} else { \n" . "} else { \n" .
# Disable # Disable
"if (!\$_ctx->exists('kutrl')) { \n" . "if (!\$_ctx->exists('kutrl')) { \n" .
# Passive mode # Passive mode
" if (\$_ctx->kutrl_passive) { " . ' if ($_ctx->kutrl_passive) { ' .
" echo " . sprintf($f, $str) . "; " . ' echo ' . sprintf($f, $str) . '; ' .
" } \n" . " } \n" .
"} else { \n" . "} else { \n" .
# Existing # Existing
" if (false !== (\$kutrl_rs = \$_ctx->kutrl->isKnowUrl(" . $str . "))) { " . ' if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl(' . $str . '))) { ' .
" echo " . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . "; " . ' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
" } \n" . " } \n" .
# New # New
" elseif (false !== (\$kutrl_rs = \$_ctx->kutrl->hash(" . $str . "))) { " . ' elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash(' . $str . '))) { ' .
" echo " . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . "; " . ' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
# ex: Send new url to messengers # ex: Send new url to messengers
" if (!empty(\$kutrl_rs)) { " . ' if (!empty($kutrl_rs)) { ' .
" \$core->callBehavior('publicAfterKutrlCreate',\$core,\$kutrl_rs,__('New public short URL')); " . " \$core->callBehavior('publicAfterKutrlCreate',\$core,\$kutrl_rs,__('New public short URL')); " .
" } \n" . " } \n" .
@ -548,34 +552,36 @@ class hmfKutrl
{ {
public static $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; public static $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
public static function create($len=6) public static function create($len = 6)
{ {
$res = ''; $res = '';
$chars = self::$chars; $chars = self::$chars;
for($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
$res .= $chars[rand(0, strlen($chars)-1)]; $res .= $chars[rand(0, strlen($chars) - 1)];
} }
return $res; return $res;
} }
public static function protect($str) public static function protect($str)
{ {
$res = ''; $res = '';
$chars = self::$chars; $chars = self::$chars;
for($i = 0; $i < strlen($str); $i++) for ($i = 0; $i < strlen($str); $i++) {
{ $res .= $chars[rand(0, strlen($chars) - 1)] . $str[$i];
$res .= $chars[rand(0, strlen($chars)-1)] . $str[$i];
} }
return $res; return $res;
} }
public static function unprotect($str) public static function unprotect($str)
{ {
$res = ''; $res = '';
for($i = 0; $i < strlen($str); $i++) { for ($i = 0; $i < strlen($str); $i++) {
$i++; $i++;
$res .= $str[$i]; $res .= $str[$i];
} }
return $res; return $res;
} }
} }

View file

@ -10,59 +10,86 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'kUtRL', /* action */
/* description */ __('delete all settings') 'delete_all',
/* ns */
'kUtRL',
/* description */
__('delete all settings')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */
/* action */ 'delete', 'tables',
/* ns */ 'kutrl', /* action */
/* description */ __('delete table') 'delete',
/* ns */
'kutrl',
/* description */
__('delete table')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'kUtRL', /* action */
/* description */ __('delete plugin files') 'delete',
/* ns */
'kUtRL',
/* description */
__('delete plugin files')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'kUtRL', /* action */
/* description */ __('delete the version number') 'delete',
/* ns */
'kUtRL',
/* description */
__('delete the version number')
); );
# Delete only dc version and plugin files from pluginsBeforeDelete # Delete only dc version and plugin files from pluginsBeforeDelete
# Keep table # Keep table
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'kUtRL', /* action */
/* description */ sprintf(__('delete all %s settings'),'kUtRL') 'delete_all',
/* ns */
'kUtRL',
/* description */
sprintf(__('delete all %s settings'), 'kUtRL')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'kUtRL', /* action */
/* description */ sprintf(__('delete %s version number'),'kUtRL') 'delete',
/* ns */
'kUtRL',
/* description */
sprintf(__('delete %s version number'), 'kUtRL')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'kUtRL', /* action */
/* description */ sprintf(__('delete %s plugin files'),'kUtRL') 'delete',
/* ns */
'kUtRL',
/* description */
sprintf(__('delete %s plugin files'), 'kUtRL')
); );

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -60,10 +59,11 @@ class widgetKutrl
'type', 'type',
__('Type:'), __('Type:'),
'all', 'all',
'combo',[ 'combo',
__('All') => '-', [
__('Mini URL') => 'localnormal', __('All') => '-',
__('Custom URL') => 'localcustom', __('Mini URL') => 'localnormal',
__('Custom URL') => 'localcustom',
__('Semi-custom') => 'localmix' __('Semi-custom') => 'localmix'
] ]
) )
@ -90,7 +90,7 @@ class widgetKutrl
'desc', 'desc',
'combo', 'combo',
[ [
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc'
] ]
) )
@ -124,7 +124,7 @@ class widgetKutrl
return null; return null;
} }
$hmf = hmfKutrl::create(); $hmf = hmfKutrl::create();
$hmfp = hmfKutrl::protect($hmf); $hmfp = hmfKutrl::protect($hmf);
return $w->renderDiv( return $w->renderDiv(
@ -140,10 +140,10 @@ class widgetKutrl
'</label></p>' . '</label></p>' .
'<p><label>' . '<p><label>' .
sprintf(__('Rewrite "%s" in next field to show that you are not a robot:'), $hmf) . '<br />' . sprintf(__('Rewrite "%s" in next field to show that you are not a robot:'), $hmf) . '<br />' .
form::field('hmf',20,255,'') . form::field('hmf', 20, 255, '') .
'</label></p>' . '</label></p>' .
'<p><input class="submit" type="submit" name="submiturl" value="' . __('Shorten') . '" />' . '<p><input class="submit" type="submit" name="submiturl" value="' . __('Shorten') . '" />' .
form::hidden('hmfp',$hmfp) . form::hidden('hmfp', $hmfp) .
$core->formNonce() . $core->formNonce() .
'</p>' . '</p>' .
'</form>' '</form>'
@ -162,9 +162,9 @@ class widgetKutrl
$type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ? $type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ?
"AND kut_type ='" . $w->type . "' " : "AND kut_type ='" . $w->type . "' " :
"AND kut_type " . $core->con->in(['localnormal', 'localmix', 'localcustom']) . " "; 'AND kut_type ' . $core->con->in(['localnormal', 'localmix', 'localcustom']) . ' ';
$hide = (boolean) $w->hideempty ? 'AND kut_counter > 0 ' : ''; $hide = (bool) $w->hideempty ? 'AND kut_counter > 0 ' : '';
$more = ''; $more = '';
if ($w->type == 'localmix' && '' != $w->mixprefix) { if ($w->type == 'localmix' && '' != $w->mixprefix) {
@ -176,11 +176,11 @@ class widgetKutrl
$order .= $w->sort == 'desc' ? ' DESC' : ' ASC'; $order .= $w->sort == 'desc' ? ' DESC' : ' ASC';
$limit = $core->con->limit(abs((integer) $w->limit)); $limit = $core->con->limit(abs((int) $w->limit));
$rs = $core->con->select( $rs = $core->con->select(
'SELECT kut_counter, kut_hash ' . 'SELECT kut_counter, kut_hash ' .
"FROM " . $core->prefix . "kutrl " . 'FROM ' . $core->prefix . 'kutrl ' .
"WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . "WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " .
"AND kut_service = 'local' " . "AND kut_service = 'local' " .
$type . $hide . $more . 'ORDER BY ' . $order . $limit $type . $hide . $more . 'ORDER BY ' . $order . $limit
@ -191,23 +191,23 @@ class widgetKutrl
} }
$content = ''; $content = '';
$i = 0; $i = 0;
while($rs->fetch()) { while ($rs->fetch()) {
$i++; $i++;
$rank = '<span class="rankkutrl-rank">' . $i . '</span>'; $rank = '<span class="rankkutrl-rank">' . $i . '</span>';
$hash = $rs->kut_hash; $hash = $rs->kut_hash;
$url = $core->blog->url . $core->url->getBase('kutrl') . '/' . $hash; $url = $core->blog->url . $core->url->getBase('kutrl') . '/' . $hash;
$cut_len = - abs((integer) $w->urllen); $cut_len = - abs((int) $w->urllen);
if (strlen($url) > $cut_len) { if (strlen($url) > $cut_len) {
$url = '...' . substr($url, $cut_len); $url = '...' . substr($url, $cut_len);
} }
/* /*
if (strlen($hash) > $cut_len) { if (strlen($hash) > $cut_len) {
$url = '...'.substr($hash, $cut_len); $url = '...'.substr($hash, $cut_len);
} }
//*/ //*/
if ($rs->kut_counter == 0) { if ($rs->kut_counter == 0) {
$counttext = __('never followed'); $counttext = __('never followed');
} elseif ($rs->kut_counter == 1) { } elseif ($rs->kut_counter == 1) {
@ -216,8 +216,7 @@ class widgetKutrl
$counttext = sprintf(__('followed %s times'), $rs->kut_counter); $counttext = sprintf(__('followed %s times'), $rs->kut_counter);
} }
$content .= $content .= '<li><a href="' .
'<li><a href="' .
$core->blog->url . $core->url->getBase('kutrl') . '/' . $rs->kut_hash . $core->blog->url . $core->url->getBase('kutrl') . '/' . $rs->kut_hash .
'">' . '">' .
str_replace( str_replace(
@ -239,6 +238,5 @@ class widgetKutrl
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
sprintf('<ul>%s</ul>', $content) sprintf('<ul>%s</ul>', $content)
); );
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -24,16 +23,14 @@ class kUtRL
$list = $core->getBehaviors('kutrlService'); $list = $core->getBehaviors('kutrlService');
if (empty($list)) { if (empty($list)) {
return []; return [];
} }
$services = []; $services = [];
foreach($list as $k => $callback) { foreach ($list as $k => $callback) {
try { try {
list($service_id,$service_class) = call_user_func($callback); list($service_id, $service_class) = call_user_func($callback);
$services[(string) $service_id] = (string) $service_class; $services[(string) $service_id] = (string) $service_class;
} catch (Exception $e) { } catch (Exception $e) {
} }
} }
@ -48,15 +45,13 @@ class kUtRL
try { try {
if (empty($id)) { if (empty($id)) {
return null; return null;
} }
$services = self::getServices($core); $services = self::getServices($core);
if (isset($services[$id])) { if (isset($services[$id])) {
return new $services[$id]($core); return new $services[$id]($core);
} }
} catch(Exception $e) { } catch (Exception $e) {
} }
return null; return null;
@ -70,15 +65,13 @@ class kUtRL
try { try {
if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) { if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) {
return null; return null;
} }
$id = $core->blog->settings->kUtRL->get('kutrl_' . $place .'_service'); $id = $core->blog->settings->kUtRL->get('kutrl_' . $place . '_service');
if (!empty($id)) { if (!empty($id)) {
return self::quickService($id); return self::quickService($id);
} }
} catch(Exception $e) { } catch (Exception $e) {
} }
return null; return null;
@ -93,16 +86,15 @@ class kUtRL
try { try {
$srv = self::quickPlace($place); $srv = self::quickPlace($place);
if (empty($srv)) { if (empty($srv)) {
return $url; return $url;
} }
$rs = $srv->hash($url,$custom); $rs = $srv->hash($url, $custom);
if (empty($rs)) { if (empty($rs)) {
return $url; return $url;
} }
return $srv->url_base.$rs->hash;
} catch(Exception $e) { return $srv->url_base . $rs->hash;
} catch (Exception $e) {
} }
return $url; return $url;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# This file is used with plugin activityReport # This file is used with plugin activityReport
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# This file contents class to acces local short links records # This file contents class to acces local short links records
class kutrlLog class kutrlLog
@ -54,27 +53,27 @@ class kutrlLog
$this->con->unlock(); $this->con->unlock();
return [ return [
'id' => $cur->kut_id, 'id' => $cur->kut_id,
'url' => $url, 'url' => $url,
'hash' => $hash, 'hash' => $hash,
'type' => $type, 'type' => $type,
'service' => $service, 'service' => $service,
'counter '=> 0 'counter ' => 0
]; ];
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
return false; return false;
} }
public function select($url = null, $hash = null, $type =null, $service = 'kutrl') public function select($url = null, $hash = null, $type = null, $service = 'kutrl')
{ {
//$this->con->writeLock($this->table); //$this->con->writeLock($this->table);
$req = $req = 'SELECT kut_id as id, kut_hash as hash, kut_url as url, ' .
'SELECT kut_id as id, kut_hash as hash, kut_url as url, ' .
'kut_type as type, kut_service as service, kut_counter as counter ' . 'kut_type as type, kut_service as service, kut_counter as counter ' .
'FROM ' . $this->table . ' ' . 'FROM ' . $this->table . ' ' .
"WHERE blog_id = '" . $this->blog . "' " . "WHERE blog_id = '" . $this->blog . "' " .
@ -88,7 +87,7 @@ class kutrlLog
} }
if (null !== $type) { if (null !== $type) {
if (is_array($type)) { if (is_array($type)) {
$req .= "AND kut_type '" . $this->con->in($type) ."' "; $req .= "AND kut_type '" . $this->con->in($type) . "' ";
} else { } else {
$req .= "AND kut_type = '" . $this->con->escape($type) . "' "; $req .= "AND kut_type = '" . $this->con->escape($type) . "' ";
} }
@ -104,7 +103,7 @@ class kutrlLog
public function clear($id) public function clear($id)
{ {
$id = (integer) $id; $id = (int) $id;
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
@ -123,6 +122,7 @@ class kutrlLog
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -131,7 +131,7 @@ class kutrlLog
public function delete($id) public function delete($id)
{ {
$id = (integer) $id; $id = (int) $id;
return $this->con->execute( return $this->con->execute(
'DELETE FROM ' . $this->table . ' ' . 'DELETE FROM ' . $this->table . ' ' .
@ -142,7 +142,7 @@ class kutrlLog
public function counter($id, $do = 'get') public function counter($id, $do = 'get')
{ {
$id = (integer) $id; $id = (int) $id;
$rs = $this->con->select( $rs = $this->con->select(
'SELECT kut_counter ' . 'SELECT kut_counter ' .
@ -154,21 +154,19 @@ class kutrlLog
$counter = $rs->isEmpty() ? 0 : $rs->kut_counter; $counter = $rs->isEmpty() ? 0 : $rs->kut_counter;
if ('get' == $do) { if ('get' == $do) {
return $counter; return $counter;
} elseif ('up' == $do) { } elseif ('up' == $do) {
$counter += 1; $counter += 1;
} elseif ('reset' == $do) { } elseif ('reset' == $do) {
$counter = 0; $counter = 0;
} else { } else {
return 0; return 0;
} }
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
$cur->kut_counter = (integer) $counter; $cur->kut_counter = (int) $counter;
$cur->update( $cur->update(
"WHERE blog_id='" . $this->blog . "' " . "WHERE blog_id='" . $this->blog . "' " .
"AND kut_id='" . $id . "'" "AND kut_id='" . $id . "'"
@ -188,8 +186,7 @@ class kutrlLog
if (!empty($p['columns']) && is_array($p['columns'])) { if (!empty($p['columns']) && is_array($p['columns'])) {
$content_req .= implode(', ', $p['columns']) . ', '; $content_req .= implode(', ', $p['columns']) . ', ';
} }
$r = $r = 'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
$content_req . 'S.kut_dt '; $content_req . 'S.kut_dt ';
} }
$r .= 'FROM ' . $this->table . ' S '; $r .= 'FROM ' . $this->table . ' S ';
@ -203,8 +200,7 @@ class kutrlLog
$r .= "AND kut_service='kutrl' "; $r .= "AND kut_service='kutrl' ";
} }
if (isset($p['kut_type'])) { if (isset($p['kut_type'])) {
if (is_array($p['kut_type']) && !empty($p['kut_type'])) if (is_array($p['kut_type']) && !empty($p['kut_type'])) {
{
$r .= 'AND kut_type ' . $this->con->in($p['kut_type']); $r .= 'AND kut_type ' . $this->con->in($p['kut_type']);
} elseif ($p['kut_type'] != '') { } elseif ($p['kut_type'] != '') {
$r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' "; $r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' ";
@ -232,18 +228,15 @@ class kutrlLog
} }
} }
if (!empty($p['kut_year'])) { if (!empty($p['kut_year'])) {
$r .= $r .= 'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
"'" . sprintf('%04d', $p['kut_year']) . "' "; "'" . sprintf('%04d', $p['kut_year']) . "' ";
} }
if (!empty($p['kut_month'])) { if (!empty($p['kut_month'])) {
$r .= $r .= 'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
"'" . sprintf('%02d', $p['kut_month']) . "' "; "'" . sprintf('%02d', $p['kut_month']) . "' ";
} }
if (!empty($p['kut_day'])) { if (!empty($p['kut_day'])) {
$r .= $r .= 'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
"'" . sprintf('%02d', $p['kut_day']) . "' "; "'" . sprintf('%02d', $p['kut_day']) . "' ";
} }
if (!empty($p['sql'])) { if (!empty($p['sql'])) {

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class kutrlLinkslist class kutrlLinkslist
{ {
protected $core; protected $core;
@ -51,30 +50,30 @@ class kutrlLinkslist
echo '<p><strong>' . __('No short link') . '</strong></p>'; echo '<p><strong>' . __('No short link') . '</strong></p>';
} }
} else { } else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$links = []; $links = [];
if (isset($_REQUEST['entries'])) { if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) { foreach ($_REQUEST['entries'] as $v) {
$links[(integer) $v] = true; $links[(int) $v] = true;
} }
} }
$cols = [ $cols = [
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>', 'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>', 'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
'kut_dt' => '<th scope="col">' . __('Date') . '</th>', 'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
'kut_service' => '<th scope="col">' . __('Service') . '</th>' 'kut_service' => '<th scope="col">' . __('Service') . '</th>'
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols); $this->userColumns('kUtRL', $cols);
$html_block = $html_block = '<div class="table-outer">' .
'<div class="table-outer">' .
'<table>' . '<table>' .
'<caption>' . ($filter ? '<caption>' . (
$filter ?
sprintf(__('List of %s links matching the filter.'), $this->rs_count) : sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
sprintf(__('List of links (%s)'), $this->rs_count) sprintf(__('List of links (%s)'), $this->rs_count)
). '</caption>' . ) . '</caption>' .
'<thead>' . '<thead>' .
'<tr>' . implode(iterator_to_array($cols)) . '</tr>' . '<tr>' . implode(iterator_to_array($cols)) . '</tr>' .
'</thead>' . '</thead>' .
@ -109,7 +108,7 @@ class kutrlLinkslist
$cols = [ $cols = [
'check' => '<td class="nowrap">' . 'check' => '<td class="nowrap">' .
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) . form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
'</td>', '</td>',
'kut_url' => '<td class="maximal" scope="row">' . 'kut_url' => '<td class="maximal" scope="row">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' . '<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
@ -128,6 +127,6 @@ class kutrlLinkslist
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols); $this->userColumns('kUtRL', $cols);
return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n"; return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n";
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# Generic class for shorten link service # Generic class for shorten link service
# A service class must extends this one # A service class must extends this one
class kutrlService class kutrlService
@ -20,7 +19,7 @@ class kutrlService
public $settings; public $settings;
public $log; public $log;
protected $config = array(); protected $config = [];
public function __construct($core) public function __construct($core)
{ {
@ -33,24 +32,24 @@ class kutrlService
$this->init(); $this->init();
// Force setting // Force setting
$allow_external_url = $this->settings->kutrl_allow_external_url; $allow_external_url = $this->settings->kutrl_allow_external_url;
$this->config['$allow_external_url'] = null === $allow_external_url ? $this->config['$allow_external_url'] = null === $allow_external_url ?
true : $allow_external_url; true : $allow_external_url;
$this->config = array_merge( $this->config = array_merge(
[ [
'id' => 'undefined', 'id' => 'undefined',
'name' => 'undefined', 'name' => 'undefined',
'home' => '', 'home' => '',
'allow_external_url' => true, 'allow_external_url' => true,
'allow_custom_hash' => false, 'allow_custom_hash' => false,
'allow_protocols' => ['http://'], 'allow_protocols' => ['http://'],
'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL',
'url_api' => '', 'url_api' => '',
'url_base' => '', 'url_base' => '',
'url_min_len' => 0 'url_min_len' => 0
], ],
$this->config $this->config
); );
@ -65,7 +64,7 @@ class kutrlService
# get config value # get config value
public function get($k) public function get($k)
{ {
return isset($this->config[$k]) ? $this->config[$k] : null; return $this->config[$k] ?? null;
} }
# Additionnal actions on child start # Additionnal actions on child start
@ -98,7 +97,7 @@ class kutrlService
# Test if an url is valid # Test if an url is valid
public function isValidUrl($url) public function isValidUrl($url)
{ {
return (boolean) filter_var($url, FILTER_VALIDATE_URL); return (bool) filter_var($url, FILTER_VALIDATE_URL);
} }
# Test if an url contents know prefix # Test if an url contents know prefix
@ -110,18 +109,17 @@ class kutrlService
# Test if an url is long enoutgh # Test if an url is long enoutgh
public function isLongerUrl($url) public function isLongerUrl($url)
{ {
return (strlen($url) >= (integer) $this->url_min_len); return (strlen($url) >= (int) $this->url_min_len);
} }
# Test if an url protocol (eg: http://) is allowed # Test if an url protocol (eg: http://) is allowed
public function isProtocolUrl($url) public function isProtocolUrl($url)
{ {
foreach($this->allow_protocols as $protocol) { foreach ($this->allow_protocols as $protocol) {
if (empty($protocol)) { if (empty($protocol)) {
continue; continue;
} }
if (strpos($url,$protocol) === 0) { if (strpos($url, $protocol) === 0) {
return true; return true;
} }
} }
@ -133,7 +131,7 @@ class kutrlService
public function isBlogUrl($url) public function isBlogUrl($url)
{ {
$base = $this->core->blog->url; $base = $this->core->blog->url;
$url = substr($url, 0, strlen($base)); $url = substr($url, 0, strlen($base));
return $url == $base; return $url == $base;
} }
@ -182,8 +180,8 @@ class kutrlService
# --BEHAVIOR-- kutrlAfterCreateShortUrl # --BEHAVIOR-- kutrlAfterCreateShortUrl
$this->core->callBehavior('kutrlAfterCreateShortUrl', $rs); $this->core->callBehavior('kutrlAfterCreateShortUrl', $rs);
} }
return $rs; return $rs;
} }
@ -220,13 +218,13 @@ class kutrlService
# Post request # Post request
public static function post($server, $data, $verbose = true, $get = false, $headers = []) public static function post($server, $data, $verbose = true, $get = false, $headers = [])
{ {
$url = (string) $server; $url = (string) $server;
$client = netHttp::initClient($url, $url); $client = netHttp::initClient($url, $url);
$client->setUserAgent('kUtRL - http://kutrl.fr'); $client->setUserAgent('kUtRL - http://kutrl.fr');
$client->setPersistReferers(false); $client->setPersistReferers(false);
if (is_array($headers) && !empty($headers)) { if (is_array($headers) && !empty($headers)) {
foreach($headers as $header) { foreach ($headers as $header) {
$client->setMoreHeader($header); $client->setMoreHeader($header);
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# This file contents class to shorten url pass through wiki # This file contents class to shorten url pass through wiki
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
@ -34,7 +33,7 @@ class kutrlWiki
if (null === ($kut = kutrl::quickPlace('wiki'))) { if (null === ($kut = kutrl::quickPlace('wiki'))) {
return null; return null;
} }
foreach($kut->allow_protocols as $protocol) { foreach ($kut->allow_protocols as $protocol) {
$wiki2xhtml->registerFunction( $wiki2xhtml->registerFunction(
'url:' . $protocol, 'url:' . $protocol,
['kutrlWiki', 'transform'] ['kutrlWiki', 'transform']
@ -55,25 +54,27 @@ class kutrlWiki
} }
# Test if long url exists # Test if long url exists
$is_new = false; $is_new = false;
$rs = $kut->isKnowUrl($url); $rs = $kut->isKnowUrl($url);
if (!$rs) { if (!$rs) {
$is_new = true; $is_new = true;
$rs = $kut->hash($url); $rs = $kut->hash($url);
} }
if (!$rs) { if (!$rs) {
return []; return [];
} else {
$res = [];
$testurl = strlen($rs->url) > 35 ? substr($rs->url, 0, 35) . '...' : $rs->url;
$res['url'] = $kut->url_base . $rs->hash;
$res['title'] = sprintf(__('%s (Shorten with %s)'), $rs->url, __($kut->name));
if ($testurl == $content) $res['content'] = $res['url'];
# ex: Send new url to messengers
if (!empty($rs)) {
$core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL'));
}
return $res;
} }
$res = [];
$testurl = strlen($rs->url) > 35 ? substr($rs->url, 0, 35) . '...' : $rs->url;
$res['url'] = $kut->url_base . $rs->hash;
$res['title'] = sprintf(__('%s (Shorten with %s)'), $rs->url, __($kut->name));
if ($testurl == $content) {
$res['content'] = $res['url'];
}
# ex: Send new url to messengers
if (!empty($rs)) {
$core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL'));
}
return $res;
} }
} }

View file

@ -10,21 +10,18 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# This file takes records from plugin dcMiniUrl # This file takes records from plugin dcMiniUrl
# and inserts them into plugin kUtRL. # and inserts them into plugin kUtRL.
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
$miniurl_patch = new dcMiniUrl2kUtRL($core); $miniurl_patch = new dcMiniUrl2kUtRL($core);
if ($miniurl_patch->parseRecords()) if ($miniurl_patch->parseRecords()) {
{ try {
try
{
$core->plugins->deactivateModule('dcMiniUrl'); $core->plugins->deactivateModule('dcMiniUrl');
} } catch (Exception $e) {
catch (Exception $e)
{
//$core->error->add($e->getMessage()); //$core->error->add($e->getMessage());
} }
} }
@ -39,40 +36,39 @@ class dcMiniUrl2kUtRL
public function __construct($core) public function __construct($core)
{ {
$this->core = $core; $this->core = $core;
$this->con = $core->con; $this->con = $core->con;
$this->k_tb = $core->prefix.'kutrl'; $this->k_tb = $core->prefix . 'kutrl';
$this->m_tb = $core->prefix.'miniurl'; $this->m_tb = $core->prefix . 'miniurl';
} }
public function parseRecords() public function parseRecords()
{ {
$rs = $this->con->select( $rs = $this->con->select(
'SELECT * FROM '.$this->m_tb.' ' 'SELECT * FROM ' . $this->m_tb . ' '
); );
while ($rs->fetch()) while ($rs->fetch()) {
{ if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') {
if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') if ($this->exists($rs)) {
{ continue;
if ($this->exists($rs)) continue; }
$this->insertKutrl($rs); $this->insertKutrl($rs);
$this->insertLocal($rs); $this->insertLocal($rs);
} } else {
else
{
$this->insertOther($rs); $this->insertOther($rs);
} }
} }
return true; return true;
} }
private function insertKutrl($rs) private function insertKutrl($rs)
{ {
$cur = $this->common($rs); $cur = $this->common($rs);
$cur->kut_service = 'kutrl'; $cur->kut_service = 'kutrl';
$cur->kut_type = 'local'; $cur->kut_type = 'local';
$cur->kut_counter = 0; $cur->kut_counter = 0;
$cur->kut_password = null; $cur->kut_password = null;
$cur->insert(); $cur->insert();
@ -81,9 +77,9 @@ class dcMiniUrl2kUtRL
private function insertLocal($rs) private function insertLocal($rs)
{ {
$cur = $this->common($rs); $cur = $this->common($rs);
$cur->kut_service = 'local'; $cur->kut_service = 'local';
$cur->kut_type = $rs->miniurl_type == 'customurl' ? $cur->kut_type = $rs->miniurl_type == 'customurl' ?
'localcustom' : 'localnormal'; 'localcustom' : 'localnormal';
$cur->insert(); $cur->insert();
@ -102,14 +98,14 @@ class dcMiniUrl2kUtRL
{ {
$cur = $this->con->openCursor($this->k_tb); $cur = $this->con->openCursor($this->k_tb);
$this->con->writeLock($this->k_tb); $this->con->writeLock($this->k_tb);
$cur->kut_id = $this->nextId(); $cur->kut_id = $this->nextId();
$cur->blog_id = $rs->blog_id; $cur->blog_id = $rs->blog_id;
$cur->kut_service = 'unknow'; $cur->kut_service = 'unknow';
$cur->kut_type = $rs->miniurl_type; $cur->kut_type = $rs->miniurl_type;
$cur->kut_hash = $rs->miniurl_id; $cur->kut_hash = $rs->miniurl_id;
$cur->kut_url = $rs->miniurl_str; $cur->kut_url = $rs->miniurl_str;
$cur->kut_dt = $rs->miniurl_dt; $cur->kut_dt = $rs->miniurl_dt;
$cur->kut_counter = $rs->miniurl_counter; $cur->kut_counter = $rs->miniurl_counter;
$cur->kut_password = $rs->miniurl_password; $cur->kut_password = $rs->miniurl_password;
return $cur; return $cur;
@ -118,18 +114,19 @@ class dcMiniUrl2kUtRL
private function exists($rs) private function exists($rs)
{ {
$chk = $this->con->select( $chk = $this->con->select(
'SELECT kut_hash FROM '.$this->k_tb.' '. 'SELECT kut_hash FROM ' . $this->k_tb . ' ' .
"WHERE blog_id = '".$rs->blog_id."' ". "WHERE blog_id = '" . $rs->blog_id . "' " .
"AND kut_service = 'local' ". "AND kut_service = 'local' " .
"AND kut_hash = '".$rs->miniurl_id."' " "AND kut_hash = '" . $rs->miniurl_id . "' "
); );
return !$chk->isEmpty(); return !$chk->isEmpty();
} }
private function nextId() private function nextId()
{ {
return $this->con->select( return $this->con->select(
'SELECT MAX(kut_id) FROM '.$this->k_tb.' ' 'SELECT MAX(kut_id) FROM ' . $this->k_tb . ' '
)->f(0) + 1; )->f(0) + 1;
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -29,8 +28,8 @@ class bilbolinksKutrlService extends kutrlService
if (!empty($base) && substr($base, -1, 1) != '/') { if (!empty($base) && substr($base, -1, 1) != '/') {
$base .= '/'; $base .= '/';
} }
$this->config['url_api'] = $base . 'api.php'; $this->config['url_api'] = $base . 'api.php';
$this->config['url_base'] = $base; $this->config['url_base'] = $base;
$this->config['url_min_len'] = 25; $this->config['url_min_len'] = 25;
} }
@ -67,7 +66,7 @@ class bilbolinksKutrlService extends kutrlService
} }
$arg = ['longurl' => urlencode($this->url_test)]; $arg = ['longurl' => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true,true)) { if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
@ -90,7 +89,7 @@ class bilbolinksKutrlService extends kutrlService
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response); $rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -18,24 +17,24 @@ if (!defined('DC_RC_PATH')) {
class bitlyKutrlService extends kutrlService class bitlyKutrlService extends kutrlService
{ {
protected $config = [ protected $config = [
'id' => 'bitly', 'id' => 'bitly',
'name' => 'bit.ly', 'name' => 'bit.ly',
'home' => 'https://bit.ly', 'home' => 'https://bit.ly',
'url_api' => 'https://api-ssl.bitly.com/v4/', 'url_api' => 'https://api-ssl.bitly.com/v4/',
'url_base' => 'https://bit.ly/', 'url_base' => 'https://bit.ly/',
'url_min_len' => 25, 'url_min_len' => 25,
'allow_protocols' => ['http://', 'https://'], 'allow_protocols' => ['http://', 'https://'],
]; ];
private $args = [ private $args = [
'apiKey' => '' 'apiKey' => ''
]; ];
protected function init() protected function init()
{ {
$this->args['apiKey'] = $this->settings->kutrl_srv_bitly_apikey; $this->args['apiKey'] = $this->settings->kutrl_srv_bitly_apikey;
} }
public function saveSettings() public function saveSettings()
@ -84,7 +83,7 @@ class bitlyKutrlService extends kutrlService
$rsp = json_decode($response); $rsp = json_decode($response);
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', (string) $rsp->link); $rs->hash = str_replace($this->url_base, '', (string) $rsp->link);
$rs->url = (string) $rsp->long_url; $rs->url = (string) $rsp->long_url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -29,10 +28,10 @@ class customKutrlService extends kutrlService
$config = []; $config = [];
} }
$this->config['url_api'] = !empty($config['url_api']) ? $config['url_api'] : ''; $this->config['url_api'] = !empty($config['url_api']) ? $config['url_api'] : '';
$this->config['url_base'] = !empty($config['url_base']) ? $config['url_base'] : ''; $this->config['url_base'] = !empty($config['url_base']) ? $config['url_base'] : '';
$this->config['url_param'] = !empty($config['url_param']) ? $config['url_param'] : ''; $this->config['url_param'] = !empty($config['url_param']) ? $config['url_param'] : '';
$this->config['url_encode'] = !empty($config['url_api']); $this->config['url_encode'] = !empty($config['url_api']);
$this->config['url_min_length'] = strlen($this->url_base) + 2; $this->config['url_min_length'] = strlen($this->url_base) + 2;
} }
@ -66,7 +65,7 @@ class customKutrlService extends kutrlService
'<p>' . __('You can set a configurable service.') . '<br />' . '<p>' . __('You can set a configurable service.') . '<br />' .
__('It consists on a simple query to an URL with only one param.') . '<br />' . __('It consists on a simple query to an URL with only one param.') . '<br />' .
__('It must respond with a http code 200 on success.') . '<br />' . __('It must respond with a http code 200 on success.') . '<br />' .
__('It must returned the short URL (or only hash) in clear text.') . '</p>' . __('It must returned the short URL (or only hash) in clear text.') . '</p>' .
'<p><label class="classic">' . __('API URL:') . '<br />' . '<p><label class="classic">' . __('API URL:') . '<br />' .
form::field(['kutrl_srv_custom_url_api'], 50, 255, $config['url_api']) . form::field(['kutrl_srv_custom_url_api'], 50, 255, $config['url_api']) .
'</label></p>' . '</label></p>' .
@ -88,7 +87,6 @@ class customKutrlService extends kutrlService
public function testService() public function testService()
{ {
if (empty($this->url_api)) { if (empty($this->url_api)) {
return false; return false;
} }
$url = $this->url_encode ? urlencode($this->url_test) : $this->url_test; $url = $this->url_encode ? urlencode($this->url_test) : $this->url_test;
@ -109,9 +107,10 @@ class customKutrlService extends kutrlService
if (!($response = self::post($this->url_api, $arg, true, true))) { if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response); $rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -25,16 +24,16 @@ class defaultKutrlService extends kutrlService
protected function init() protected function init()
{ {
$this->config = [ $this->config = [
'id' => 'default', 'id' => 'default',
'name' => 'Default', 'name' => 'Default',
'home' => '', 'home' => '',
'url_api' => SHORTEN_SERVICE_API, 'url_api' => SHORTEN_SERVICE_API,
'url_base' => SHORTEN_SERVICE_BASE, 'url_base' => SHORTEN_SERVICE_BASE,
'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2, 'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2,
'url_param' => SHORTEN_SERVICE_PARAM, 'url_param' => SHORTEN_SERVICE_PARAM,
'url_encode' => SHORTEN_SERVICE_ENCODE 'url_encode' => SHORTEN_SERVICE_ENCODE
]; ];
} }
@ -84,7 +83,7 @@ class defaultKutrlService extends kutrlService
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response); $rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,36 +10,36 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
class googlKutrlService extends kutrlService class googlKutrlService extends kutrlService
{ {
public $id = 'googl'; public $id = 'googl';
public $name = 'goo.gl'; public $name = 'goo.gl';
public $home = 'http://goo.gl'; public $home = 'http://goo.gl';
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' => '' 'key' => ''
]; ];
private $headers = array('Content-Type: application/json'); private $headers = ['Content-Type: application/json'];
protected function init() protected function init()
{ {
$this->url_base = 'http://goo.gl/'; $this->url_base = 'http://goo.gl/';
$this->url_min_length = 20; $this->url_min_length = 20;
} }
public function testService() public function testService()
{ {
$args = $this->args; $args = $this->args;
$args['shortUrl'] = $this->url_base . 'PLovn'; $args['shortUrl'] = $this->url_base . 'PLovn';
if (!($response = self::post($this->url_api, $args, true, true, $this->headers))) { if (!($response = self::post($this->url_api, $args, true, true, $this->headers))) {
$this->error->add(__('Failed to call service.')); $this->error->add(__('Failed to call service.'));
return false; return false;
} }
@ -47,19 +47,22 @@ class googlKutrlService extends kutrlService
if (empty($rsp->status)) { if (empty($rsp->status)) {
$this->error->add(__('An error occured')); $this->error->add(__('An error occured'));
return false; return false;
} }
return true; return true;
} }
public function createHash($url, $hash = null) public function createHash($url, $hash = null)
{ {
$args = $this->args; $args = $this->args;
$args['longUrl'] = $url; $args['longUrl'] = $url;
$args = json_encode($args); $args = json_encode($args);
if (!($response = self::post($this->url_api, $args, true, false, $this->headers))) { if (!($response = self::post($this->url_api, $args, true, false, $this->headers))) {
$this->error->add(__('Failed to call service.')); $this->error->add(__('Failed to call service.'));
return false; return false;
} }
@ -67,12 +70,13 @@ class googlKutrlService extends kutrlService
if (empty($rsp->id)) { if (empty($rsp->id)) {
$this->error->add(__('An error occured')); $this->error->add(__('An error occured'));
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $rsp->id); $rs->hash = str_replace($this->url_base, '', $rsp->id);
$rs->url = $rsp->longUrl; $rs->url = $rsp->longUrl;
$rs->type = $this->id; $rs->type = $this->id;
return $rs; return $rs;

View file

@ -10,15 +10,16 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')){return;} return;
}
class isgdKutrlService extends kutrlService class isgdKutrlService extends kutrlService
{ {
protected $config = [ protected $config = [
'id' => 'isgd', 'id' => 'isgd',
'name' => 'is.gd', 'name' => 'is.gd',
'home' => 'http://is.gd/', 'home' => 'http://is.gd/',
'url_api' => 'http://is.gd/api.php', 'url_api' => 'http://is.gd/api.php',
'url_base' => 'http://is.gd/', 'url_base' => 'http://is.gd/',
@ -47,7 +48,7 @@ class isgdKutrlService extends kutrlService
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response); $rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -18,21 +17,20 @@ if (!defined('DC_RC_PATH')) {
class localKutrlService extends kutrlService class localKutrlService extends kutrlService
{ {
protected $config = [ protected $config = [
'id' => 'local', 'id' => 'local',
'name' => 'kUtRL', 'name' => 'kUtRL',
'home' => 'https://github.com/JcDenis/kUtRL', 'home' => 'https://github.com/JcDenis/kUtRL',
'allow_custom_hash' => true 'allow_custom_hash' => true
]; ];
protected function init() protected function init()
{ {
$protocols = (string) $this->settings->kutrl_srv_local_protocols; $protocols = (string) $this->settings->kutrl_srv_local_protocols;
$this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols); $this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols);
$this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/'; $this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/';
$this->config['url_min_len'] = strlen($this->url_base) + 2; $this->config['url_min_len'] = strlen($this->url_base) + 2;
} }
public function saveSettings() public function saveSettings()
@ -46,9 +44,9 @@ class localKutrlService extends kutrlService
public function settingsForm() public function settingsForm()
{ {
echo echo
'<div class="two-cols"><div class="col">' . '<div class="two-cols"><div class="col">' .
'<p><strong>' . __('Settings:') . '</strong></p>' . '<p><strong>' . __('Settings:') . '</strong></p>' .
'<p><label class="classic">' . '<p><label class="classic">' .
__('Allowed protocols:') . '<br />' . __('Allowed protocols:') . '<br />' .
form::field(['kutrl_srv_local_protocols'], 50, 255, $this->settings->kutrl_srv_local_protocols) . form::field(['kutrl_srv_local_protocols'], 50, 255, $this->settings->kutrl_srv_local_protocols) .
@ -64,7 +62,7 @@ class localKutrlService extends kutrlService
'</label></p>' . '</label></p>' .
'<p class="area" id="style-area"><label for="_style">' . __('CSS:') . '</label>' . '<p class="area" id="style-area"><label for="_style">' . __('CSS:') . '</label>' .
form::textarea('kutrl_srv_local_css',50,3,html::escapeHTML($this->settings->kutrl_srv_local_css), '', 2) . form::textarea('kutrl_srv_local_css', 50, 3, html::escapeHTML($this->settings->kutrl_srv_local_css), '', 2) .
'</p>' . '</p>' .
'<p class="form-note">' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '</p>' . '<p class="form-note">' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '</p>' .
@ -104,30 +102,28 @@ class localKutrlService extends kutrlService
{ {
$ap = $this->allow_protocols; $ap = $this->allow_protocols;
if (!empty($ap)) { if (!empty($ap)) {
return true; return true;
} else {
$this->error->add(__('Service is not well configured.'));
return false;
} }
$this->error->add(__('Service is not well configured.'));
return false;
} }
public function createHash($url, $hash = null) public function createHash($url, $hash = null)
{ {
# Create response object # Create response object
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->type = 'local'; $rs->type = 'local';
$rs->url = $url; $rs->url = $url;
# Normal link # Normal link
if ($hash === null) { if ($hash === null) {
$type = 'localnormal'; $type = 'localnormal';
$rs->hash = $this->next($this->last('localnormal')); $rs->hash = $this->next($this->last('localnormal'));
# Mixed custom link # Mixed custom link
} elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/', $hash, $m)) { } elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/', $hash, $m)) {
$type = 'localmix'; $type = 'localmix';
$rs->hash = $m[1] . $this->next(-1, $m[1]); $rs->hash = $m[1] . $this->next(-1, $m[1]);
# Custom link # Custom link
@ -137,7 +133,7 @@ class localKutrlService extends kutrlService
return false; return false;
} }
$type = 'localcustom'; $type = 'localcustom';
$rs->hash = $hash; $rs->hash = $hash;
# Wrong char in custom hash # Wrong char in custom hash
@ -170,11 +166,12 @@ class localKutrlService extends kutrlService
if ($last_id == -1) { if ($last_id == -1) {
$next_id = 0; $next_id = 0;
} else { } else {
for($x = 1; $x <= strlen($last_id); $x++) { for ($x = 1; $x <= strlen($last_id); $x++) {
$pos = strlen($last_id) - $x; $pos = strlen($last_id) - $x;
if ($last_id[$pos] != 'z') { if ($last_id[$pos] != 'z') {
$next_id = $this->increment($last_id, $pos); $next_id = $this->increment($last_id, $pos);
break; break;
} }
} }
@ -183,7 +180,7 @@ class localKutrlService extends kutrlService
} }
} }
return false === $this->log->select(null,$prefix . $next_id, null, 'local') ? return false === $this->log->select(null, $prefix . $next_id, null, 'local') ?
$next_id : $this->next($next_id, $prefix); $next_id : $this->next($next_id, $prefix);
} }
@ -199,7 +196,7 @@ class localKutrlService extends kutrlService
protected function increment($id, $pos) protected function increment($id, $pos)
{ {
$id = str_split($id); $id = str_split($id);
$char = $id[$pos]; $char = $id[$pos];
if (is_numeric($char)) { if (is_numeric($char)) {
@ -221,7 +218,6 @@ class localKutrlService extends kutrlService
public function getUrl($hash) public function getUrl($hash)
{ {
if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) { if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) {
return false; return false;
} }
if (!$rs->url) { //previously removed url if (!$rs->url) { //previously removed url
@ -236,7 +232,6 @@ class localKutrlService extends kutrlService
public function deleteUrl($url, $delete = false) public function deleteUrl($url, $delete = false)
{ {
if (false === ($rs = $this->log->select($url, null, null, 'local'))) { if (false === ($rs = $this->log->select($url, null, null, 'local'))) {
return false; return false;
} }
if ($delete) { if ($delete) {

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -18,12 +17,12 @@ if (!defined('DC_RC_PATH')) {
class shorttoKutrlService extends kutrlService class shorttoKutrlService extends kutrlService
{ {
protected $config = [ protected $config = [
'id' => 'shortto', 'id' => 'shortto',
'name' => 'short.to', 'name' => 'short.to',
'home' => 'http://short.to', 'home' => 'http://short.to',
'url_api' => 'http://short.to/s.txt', 'url_api' => 'http://short.to/s.txt',
'url_base' => 'http://short.to/', 'url_base' => 'http://short.to/',
'url_min_len' => 25 'url_min_len' => 25
]; ];
@ -32,8 +31,10 @@ class shorttoKutrlService extends kutrlService
$arg = ['url' => urlencode($this->url_test)]; $arg = ['url' => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true, true)) { if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
} }
return true; return true;
} }
@ -43,12 +44,13 @@ class shorttoKutrlService extends kutrlService
if (!($response = self::post($this->url_api, $arg, true, true))) { if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response); $rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;
return $rs; return $rs;

View file

@ -10,70 +10,71 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')){return;} return;
}
class suprKutrlService extends kutrlService class suprKutrlService extends kutrlService
{ {
protected $config = array( protected $config = [
'id' => 'supr', 'id' => 'supr',
'name' => 'su.pr StumbleUpon', 'name' => 'su.pr StumbleUpon',
'home' => 'http://su.pr', 'home' => 'http://su.pr',
'url_api' => 'http://su.pr/api/', 'url_api' => 'http://su.pr/api/',
'url_base' => 'http://su.pr/', 'url_base' => 'http://su.pr/',
'url_min_len' => 23 'url_min_len' => 23
); ];
private $args = array( private $args = [
'version' => '1.0', 'version' => '1.0',
'format' => 'xml', 'format' => 'xml',
'login' => '', 'login' => '',
'apiKey' => '' 'apiKey' => ''
); ];
protected function init() protected function init()
{ {
$this->args['login'] = $this->settings->kutrl_srv_supr_login; $this->args['login'] = $this->settings->kutrl_srv_supr_login;
$this->args['apiKey'] = $this->settings->kutrl_srv_supr_apikey; $this->args['apiKey'] = $this->settings->kutrl_srv_supr_apikey;
} }
public function saveSettings() public function saveSettings()
{ {
$this->settings->put('kutrl_srv_supr_login',$_POST['kutrl_srv_supr_login']); $this->settings->put('kutrl_srv_supr_login', $_POST['kutrl_srv_supr_login']);
$this->settings->put('kutrl_srv_supr_apikey',$_POST['kutrl_srv_supr_apikey']); $this->settings->put('kutrl_srv_supr_apikey', $_POST['kutrl_srv_supr_apikey']);
} }
public function settingsForm() public function settingsForm()
{ {
echo echo
'<p><label class="classic">'.__('Login:').'<br />'. '<p><label class="classic">' . __('Login:') . '<br />' .
form::field(array('kutrl_srv_supr_login'),50,255,$this->settings->kutrl_srv_supr_login). form::field(['kutrl_srv_supr_login'], 50, 255, $this->settings->kutrl_srv_supr_login) .
'</label></p>'. '</label></p>' .
'<p class="form-note">'. '<p class="form-note">' .
sprintf(__('This is your login to sign up to %s'),$this->config['name']). sprintf(__('This is your login to sign up to %s'), $this->config['name']) .
'</p>'. '</p>' .
'<p><label class="classic">'.__('API Key:').'<br />'. '<p><label class="classic">' . __('API Key:') . '<br />' .
form::field(array('kutrl_srv_supr_apikey'),50,255,$this->settings->kutrl_srv_supr_apikey). form::field(['kutrl_srv_supr_apikey'], 50, 255, $this->settings->kutrl_srv_supr_apikey) .
'</label></p>'. '</label></p>' .
'<p class="form-note">'. '<p class="form-note">' .
sprintf(__('This is your personnal %s API key. You can find it on your account page.'),$this->config['name']). sprintf(__('This is your personnal %s API key. You can find it on your account page.'), $this->config['name']) .
'</p>'; '</p>';
} }
public function testService() public function testService()
{ {
if (empty($this->args['login']) || empty($this->args['apiKey'])) if (empty($this->args['login']) || empty($this->args['apiKey'])) {
{
$this->error->add(__('Service is not well configured.')); $this->error->add(__('Service is not well configured.'));
return false; return false;
} }
$args = $this->args; $args = $this->args;
$arg['longUrl'] = $this->url_test; $arg['longUrl'] = $this->url_test;
if (!($response = self::post($this->url_api.'shorten',$args,true))) if (!($response = self::post($this->url_api . 'shorten', $args, true))) {
{
$this->error->add(__('Failed to call service.')); $this->error->add(__('Failed to call service.'));
return false; return false;
} }
@ -81,22 +82,24 @@ class suprKutrlService extends kutrlService
$status = (string) $rsp->statusCode; $status = (string) $rsp->statusCode;
if ($status != 'OK') { if ($status != 'OK') {
$err_no = (integer) $rsp->errorCode; $err_no = (int) $rsp->errorCode;
$err_msg = (integer) $rsp->errorMessage; $err_msg = (int) $rsp->errorMessage;
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'),$err_no,$err_msg)); $this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
return false; return false;
} }
return true; return true;
} }
public function createHash($url,$hash=null) public function createHash($url, $hash = null)
{ {
$args = $this->args; $args = $this->args;
$args['longUrl'] = $url; $args['longUrl'] = $url;
if (!($response = self::post($this->url_api.'shorten',$args,true))) if (!($response = self::post($this->url_api . 'shorten', $args, true))) {
{
$this->error->add(__('Failed to call service.')); $this->error->add(__('Failed to call service.'));
return false; return false;
} }
@ -104,15 +107,16 @@ class suprKutrlService extends kutrlService
$status = (string) $rsp->statusCode; $status = (string) $rsp->statusCode;
if ($status != 'OK') { if ($status != 'OK') {
$err_no = (integer) $rsp->errorCode; $err_no = (int) $rsp->errorCode;
$err_msg = (integer) $rsp->errorMessage; $err_msg = (int) $rsp->errorMessage;
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'),$err_no,$err_msg)); $this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
return false; return false;
} }
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = (string) $rsp->results[0]->nodeKeyVal->hash; $rs->hash = (string) $rsp->results[0]->nodeKeyVal->hash;
$rs->url = (string) $rsp->results[0]->nodeKeyVal->nodeKey; $rs->url = (string) $rsp->results[0]->nodeKeyVal->nodeKey;
$rs->type = $this->id; $rs->type = $this->id;
return $rs; return $rs;

View file

@ -10,25 +10,26 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')){return;} return;
}
class trimKutrlService extends kutrlService class trimKutrlService extends kutrlService
{ {
protected $config = array( protected $config = [
'id' => 'trim', 'id' => 'trim',
'name' => 'tr.im', 'name' => 'tr.im',
'home' => 'http://tr.im', 'home' => 'http://tr.im',
'url_api' => 'http://api.tr.im/v1/', 'url_api' => 'http://api.tr.im/v1/',
'url_base' => 'http://tr.im/', 'url_base' => 'http://tr.im/',
'url_min_len' => 25 'url_min_len' => 25
); ];
private $args = array( private $args = [
'username' => '', 'username' => '',
'password' => '' 'password' => ''
); ];
private $api_rate_time = 0; private $api_rate_time = 0;
@ -37,90 +38,90 @@ class trimKutrlService extends kutrlService
$this->args['username'] = $this->settings->kutrl_srv_trim_username; $this->args['username'] = $this->settings->kutrl_srv_trim_username;
$this->args['password'] = $this->settings->kutrl_srv_trim_password; $this->args['password'] = $this->settings->kutrl_srv_trim_password;
$this->api_rate_time = (integer) $this->settings->kutrl_srv_trim_apiratetime; $this->api_rate_time = (int) $this->settings->kutrl_srv_trim_apiratetime;
} }
public function saveSettings() public function saveSettings()
{ {
$this->settings->put('kutrl_srv_trim_username',$_POST['kutrl_srv_trim_username']); $this->settings->put('kutrl_srv_trim_username', $_POST['kutrl_srv_trim_username']);
$this->settings->put('kutrl_srv_trim_password',$_POST['kutrl_srv_trim_password']); $this->settings->put('kutrl_srv_trim_password', $_POST['kutrl_srv_trim_password']);
} }
public function settingsForm() public function settingsForm()
{ {
echo echo
'<p><label class="classic">'.__('Login:').'<br />'. '<p><label class="classic">' . __('Login:') . '<br />' .
form::field(array('kutrl_srv_trim_username'),50,255,$this->settings->kutrl_srv_trim_username). form::field(['kutrl_srv_trim_username'], 50, 255, $this->settings->kutrl_srv_trim_username) .
'</label></p>'. '</label></p>' .
'<p class="form-note">'. '<p class="form-note">' .
__('This is your login to sign up to tr.im.'). __('This is your login to sign up to tr.im.') .
'</p>'. '</p>' .
'<p><label class="classic">'.__('Password:').'<br />'. '<p><label class="classic">' . __('Password:') . '<br />' .
form::field(array('kutrl_srv_trim_password'),50,255,$this->settings->kutrl_srv_trim_password). form::field(['kutrl_srv_trim_password'], 50, 255, $this->settings->kutrl_srv_trim_password) .
'</label></p>'. '</label></p>' .
'<p class="form-note">'. '<p class="form-note">' .
__('This is your password to sign up to tr.im.'). __('This is your password to sign up to tr.im.') .
'</p>'; '</p>';
} }
public function testService() public function testService()
{ {
if (empty($this->args['username']) || empty($this->args['password'])) if (empty($this->args['username']) || empty($this->args['password'])) {
{
$this->error->add(__('Service is not well configured.')); $this->error->add(__('Service is not well configured.'));
return false; return false;
} }
if (time() < $this->api_rate_time + 300) // bloc service within 5min on API rate limit if (time() < $this->api_rate_time + 300) { // bloc service within 5min on API rate limit
{
$this->error->add(__('Prevent service rate limit.')); $this->error->add(__('Prevent service rate limit.'));
return false; return false;
} }
if (!($rsp = self::post($this->url_api.'verify.xml',$this->args,true,true))) if (!($rsp = self::post($this->url_api . 'verify.xml', $this->args, true, true))) {
{
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
} }
$r = simplexml_load_string($rsp); $r = simplexml_load_string($rsp);
if ($r['code'] == 200) if ($r['code'] == 200) {
{
return true; return true;
} }
$this->error->add(__('Authentication to service failed.')); $this->error->add(__('Authentication to service failed.'));
return false; return false;
} }
public function createHash($url,$hash=null) public function createHash($url, $hash = null)
{ {
$arg = $this->args; $arg = $this->args;
$arg['url'] = $url; $arg['url'] = $url;
if (!($rsp = self::post($this->url_api.'trim_url.xml',$arg,true,true))) if (!($rsp = self::post($this->url_api . 'trim_url.xml', $arg, true, true))) {
{
$this->error->add(__('Service is unavailable.')); $this->error->add(__('Service is unavailable.'));
return false; return false;
} }
$r = simplexml_load_string($rsp); $r = simplexml_load_string($rsp);
# API rate limit # API rate limit
if ($r['code'] == 425) if ($r['code'] == 425) {
{ $this->settings->put('kutrl_srv_trim_apiratetime', time());
$this->settings->put('kutrl_srv_trim_apiratetime',time());
$this->error->add(__('Service rate limit exceeded.')); $this->error->add(__('Service rate limit exceeded.'));
return false; return false;
} }
if (isset($r->trimpath)) if (isset($r->trimpath)) {
{ $rs = new ArrayObject();
$rs = new ArrayObject();
$rs->hash = $r->trimpath; $rs->hash = $r->trimpath;
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;
return $rs; return $rs;
} }
$this->error->add(__('Unreadable service response.')); $this->error->add(__('Unreadable service response.'));
return false; return false;
} }
} }

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -40,7 +39,7 @@ class yourlsKutrlService extends kutrlService
$this->config['url_api'] = $base; $this->config['url_api'] = $base;
$this->config['url_base'] = $base; $this->config['url_base'] = $base;
$this->config['url_min_len'] = strlen($base)+3; $this->config['url_min_len'] = strlen($base) + 3;
} }
public function saveSettings() public function saveSettings()
@ -82,7 +81,7 @@ class yourlsKutrlService extends kutrlService
return false; return false;
} }
$args = $this->args; $args = $this->args;
$args['url'] = $this->url_test; $args['url'] = $this->url_test;
if (!($response = self::post($this->url_api, $this->args, true))) { if (!($response = self::post($this->url_api, $this->args, true))) {
@ -93,7 +92,6 @@ class yourlsKutrlService extends kutrlService
$rsp = @simplexml_load_string($response); $rsp = @simplexml_load_string($response);
if ($rsp && $rsp->status == 'success') { if ($rsp && $rsp->status == 'success') {
return true; return true;
} }
$this->error->add(__('Authentication to service failed.')); $this->error->add(__('Authentication to service failed.'));
@ -114,7 +112,7 @@ class yourlsKutrlService extends kutrlService
$rsp = @simplexml_load_string($response); $rsp = @simplexml_load_string($response);
if ($rsp && $rsp->status == 'success') { if ($rsp && $rsp->status == 'success') {
$rs = new ArrayObject(); $rs = new ArrayObject();
$rs->hash = $rsp->url[0]->keyword; $rs->hash = $rsp->url[0]->keyword;
$rs->url = $url; $rs->url = $url;
$rs->type = $this->id; $rs->type = $this->id;

View file

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
@ -19,8 +18,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
dcPage::check('admin'); dcPage::check('admin');
$header = ''; $header = '';
$part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'links'; $part = $_REQUEST['part'] ?? 'links';
$action = isset($_POST['action']) ? $_POST['action'] : ''; $action = $_POST['action'] ?? '';
# link creation # link creation
if ($part == 'link') { if ($part == 'link') {
@ -31,7 +30,7 @@ if ($part == 'link') {
if (null === $kut) { if (null === $kut) {
throw new Exception('Unknow service'); throw new Exception('Unknow service');
} }
$url = trim($core->con->escape($_POST['str'])); $url = trim($core->con->escape($_POST['str']));
$hash = empty($_POST['custom']) ? null : $_POST['custom']; $hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) { if (empty($url)) {
@ -62,8 +61,8 @@ if ($part == 'link') {
throw new Exception(__('This custom short url is already taken.')); throw new Exception(__('This custom short url is already taken.'));
} }
if (false !== ($rs = $kut->isKnowUrl($url))) { if (false !== ($rs = $kut->isKnowUrl($url))) {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base .$rs->hash; $new_url = $kut->url_base . $rs->hash;
dcPage::addSuccessNotice(sprintf( dcPage::addSuccessNotice(sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
@ -75,9 +74,10 @@ if ($part == 'link') {
if ($kut->error->flag()) { if ($kut->error->flag()) {
throw new Exception($kut->error->toHTML()); throw new Exception($kut->error->toHTML());
} }
throw new Exception(__('Failed to create short link. This could be caused by a service failure.')); throw new Exception(__('Failed to create short link. This could be caused by a service failure.'));
} else { } else {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
dcPage::addSuccessNotice(sprintf( dcPage::addSuccessNotice(sprintf(
@ -88,7 +88,7 @@ if ($part == 'link') {
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL')); $core->callBehavior('adminAfterKutrlCreate', $core, $rs, __('New short URL'));
} }
} }
} }
@ -97,15 +97,15 @@ if ($part == 'link') {
} }
} }
# links # links
} else { } else {
$services_combo = []; $services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service) { foreach (kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core); $o = new $service($core);
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge([__('Disabled')=>''], $services_combo); $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
$lst_services_combo = array_merge(['-'=>''], $services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo);
$log = new kutrlLog($core); $log = new kutrlLog($core);
@ -113,26 +113,28 @@ if ($part == 'link') {
$kUtRL_filter->add('part', 'links'); $kUtRL_filter->add('part', 'links');
$kUtRL_filter->add(dcAdminFilters::getPageFilter()); $kUtRL_filter->add(dcAdminFilters::getPageFilter());
$kUtRL_filter->add(dcAdminFilters::getSelectFilter( $kUtRL_filter->add(dcAdminFilters::getSelectFilter(
'urlsrv', __('Service:'), $lst_services_combo, 'kut_type' 'urlsrv',
__('Service:'),
$lst_services_combo,
'kut_type'
)); ));
$params = $kUtRL_filter->params(); $params = $kUtRL_filter->params();
try { try {
$list_all = $log->getLogs($params); $list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0); $list_counter = $log->getLogs($params, true)->f(0);
$list_current = new kutrlLinksList($core, $list_all, $list_counter); $list_current = new kutrlLinksList($core, $list_all, $list_counter);
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
$header = $header = $kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) .
$kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) .
dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js'));
if (!empty($_POST['deletelinks'])) { if (!empty($_POST['deletelinks'])) {
try { try {
foreach($_POST['entries'] as $id) { foreach ($_POST['entries'] as $id) {
$rs = $log->getLogs(['kut_id' => $id]); $rs = $log->getLogs(['kut_id' => $id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
continue; continue;
@ -165,9 +167,9 @@ $header .
if ($part == 'link') { if ($part == 'link') {
echo echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Links shortener') => $core->adminurl->get('admin.plugin.kUtRL'), __('Links shortener') => $core->adminurl->get('admin.plugin.kUtRL'),
__('New link') => '' __('New link') => ''
]) . ]) .
dcPage::notices(); dcPage::notices();
@ -205,14 +207,14 @@ if ($part == 'link') {
} else { } else {
echo echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Links shortener') => '' __('Links shortener') => ''
]) . ]) .
dcPage::notices() . dcPage::notices() .
'<p class="top-add"><a class="button add" href="' . '<p class="top-add"><a class="button add" href="' .
$core->adminurl->get('admin.plugin.kUtRL', ['part' => 'link']) . $core->adminurl->get('admin.plugin.kUtRL', ['part' => 'link']) .
'">' . __('New Link') .'</a></p>'; '">' . __('New Link') . '</a></p>';
$kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links')); $kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links'));
@ -229,7 +231,7 @@ if ($part == 'link') {
</div> </div>
<p class="col right"> <p class="col right">
<input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' . <input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . $core->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) .
$core->formNonce() . ' $core->formNonce() . '
</p> </p>
</div> </div>

View file

@ -1,16 +1,17 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief kUtRL, a plugin for Dotclear 2
# This file is part of kUtRL, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors * @subpackage Plugin
# *
# Licensed under the GPL version 2.0 license. * @author Jean-Christian Denis and contributors
# A copy of this license is available in LICENSE file or at *
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ */
if (!defined('DC_RC_PATH')) {
return;
}
if (!defined('DC_RC_PATH')) { return; } $__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html';
$__resources['help']['kUtRL'] = dirname(__FILE__).'/help/help.html';

View file

@ -1,16 +1,17 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief kUtRL, a plugin for Dotclear 2
# This file is part of kUtRL, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors * @subpackage Plugin
# *
# Licensed under the GPL version 2.0 license. * @author Jean-Christian Denis and contributors
# A copy of this license is available in LICENSE file or at *
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ */
if (!defined('DC_RC_PATH')) {
return;
}
if (!defined('DC_RC_PATH')) { return; } $__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html';
$__resources['help']['kUtRL'] = dirname(__FILE__).'/help/help.html';