update to PSR12
parent
40a3269b20
commit
cfcccf32d7
20
_admin.php
20
_admin.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -124,8 +123,7 @@ class adminKutrl
|
|||
$rs = false;
|
||||
}
|
||||
|
||||
$ret =
|
||||
'<div id="kUtRL"><h5>' . __('Short link') . '</h5>' .
|
||||
$ret = '<div id="kUtRL"><h5>' . __('Short link') . '</h5>' .
|
||||
form::hidden(['kutrl_old_post_url'], $post_url);
|
||||
|
||||
if (!$rs) {
|
||||
|
@ -134,14 +132,12 @@ class adminKutrl
|
|||
} else {
|
||||
$chk = !empty($_POST['kutrl_create']);
|
||||
}
|
||||
$ret .=
|
||||
'<p><label class="classic">' .
|
||||
$ret .= '<p><label class="classic">' .
|
||||
form::checkbox('kutrl_create', 1, $chk, '', 3) . ' ' .
|
||||
__('Create short link') . '</label></p>';
|
||||
|
||||
if ($kut->allow_custom_hash) {
|
||||
$ret .=
|
||||
'<p class="classic">' .
|
||||
$ret .= '<p class="classic">' .
|
||||
'<label for="custom">' . __('Custom short link:') . ' ' .
|
||||
form::field('kutrl_create_custom', 32, 32, '', 3) .
|
||||
'</label></p>';
|
||||
|
@ -157,8 +153,7 @@ class adminKutrl
|
|||
}
|
||||
$href = $kut->url_base . $rs->hash;
|
||||
|
||||
$ret .=
|
||||
'<p><label class="classic">' .
|
||||
$ret .= '<p><label class="classic">' .
|
||||
form::checkbox('kutrl_delete', 1, !empty($_POST['kutrl_delete']), '', 3) . ' ' .
|
||||
__('Delete short link') . '</label></p>' .
|
||||
'<p><a href="' . $href . '" ' . 'title="' . $title . '">' . $href . '</a></p>';
|
||||
|
@ -316,7 +311,8 @@ class backupKutrl
|
|||
{
|
||||
public static function exportSingle($core, $exp, $blog_id)
|
||||
{
|
||||
$exp->export('kutrl',
|
||||
$exp->export(
|
||||
'kutrl',
|
||||
'SELECT kut_id, blog_id, kut_service, kut_type, ' .
|
||||
'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' .
|
||||
'FROM ' . $core->prefix . 'kutrl ' .
|
||||
|
@ -349,14 +345,14 @@ class backupKutrl
|
|||
{
|
||||
if ($line->__name == 'kutrl') {
|
||||
$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->kut_service = (string) $line->kut_service;
|
||||
$bk->cur_kutrl->kut_type = (string) $line->kut_type;
|
||||
$bk->cur_kutrl->kut_hash = (string) $line->kut_hash;
|
||||
$bk->cur_kutrl->kut_url = (string) $line->kut_url;
|
||||
$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->insert();
|
||||
}
|
||||
|
|
10
_config.php
10
_config.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
@ -33,14 +32,14 @@ foreach(kutrl::getServices($core) as $service_id => $service) {
|
|||
$ext_services_combo = array_merge([__('Disabled') => ''], $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_admin_service = (string) $s->kutrl_admin_service;
|
||||
$s_tpl_service = (string) $s->kutrl_tpl_service;
|
||||
$s_wiki_service = (string) $s->kutrl_wiki_service;
|
||||
$s_allow_external_url = (boolean) $s->kutrl_allow_external_url;
|
||||
$s_tpl_passive = (boolean) $s->kutrl_tpl_passive;
|
||||
$s_tpl_active = (boolean) $s->kutrl_tpl_active;
|
||||
$s_allow_external_url = (bool) $s->kutrl_allow_external_url;
|
||||
$s_tpl_passive = (bool) $s->kutrl_tpl_passive;
|
||||
$s_tpl_active = (bool) $s->kutrl_tpl_active;
|
||||
$s_admin_entry_default = (string) $s->kutrl_admin_entry_default;
|
||||
|
||||
if (!empty($_POST['save'])) {
|
||||
|
@ -175,6 +174,7 @@ foreach(kutrl::getServices($core) as $service_id => $service) {
|
|||
|
||||
if (!empty($_REQUEST['chk'])) {
|
||||
$img_chk = $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name);
|
||||
|
||||
try {
|
||||
if ($o->testService()) {
|
||||
$img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
@ -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_admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true);
|
||||
# Settings for "local" service
|
||||
$local_css =
|
||||
".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" .
|
||||
".dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }";
|
||||
$local_css = ".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" .
|
||||
'.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_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);
|
||||
|
@ -82,6 +80,7 @@ try {
|
|||
if ($core->plugins->moduleExists('dcMiniUrl')) {
|
||||
require_once dirname(__FILE__) . '/inc/patch.dcminiurl.php';
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
|
|
15
_prepend.php
15
_prepend.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
@ -41,22 +40,22 @@ $__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php';
|
|||
|
||||
# Services
|
||||
$__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')) {
|
||||
$__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')) {
|
||||
$__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')) {
|
||||
$__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')) {
|
||||
$__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')) {
|
||||
// $__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php';
|
||||
|
@ -64,7 +63,7 @@ if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) {
|
|||
//}
|
||||
if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
|
||||
$__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')) {
|
||||
// $__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php';
|
||||
|
@ -76,7 +75,7 @@ if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
|
|||
//}
|
||||
if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) {
|
||||
$__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')) {
|
||||
// $__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php';
|
||||
|
|
52
_public.php
52
_public.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ class urlKutrl extends dcUrlHandlers
|
|||
return null;
|
||||
}
|
||||
|
||||
$args = isset($m[3]) ? $m[3] : '';
|
||||
$args = $m[3] ?? '';
|
||||
$_ctx->kutrl_msg = '';
|
||||
$_ctx->kutrl_hmf = hmfKutrl::create();
|
||||
$_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf);
|
||||
|
@ -269,6 +268,7 @@ class pubKutrl
|
|||
if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
|
||||
return '<?php $GLOBALS["disable_kutrl"] = true; ?>';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -278,6 +278,7 @@ class pubKutrl
|
|||
if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
|
||||
return '<?php $GLOBALS["disable_kutrl"] = false; ?>';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -324,7 +325,7 @@ class pubKutrl
|
|||
$s = $core->blog->settings->kUtRL;
|
||||
|
||||
# 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) {
|
||||
return null;
|
||||
|
@ -353,6 +354,7 @@ class tplKutrl
|
|||
public static function pageURL($attr)
|
||||
{
|
||||
$f = $GLOBALS['core']->tpl->getFilters($attr);
|
||||
|
||||
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']) : '&&';
|
||||
|
||||
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 (empty($if)) {
|
||||
|
@ -369,7 +371,7 @@ class tplKutrl
|
|||
}
|
||||
|
||||
return
|
||||
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
'<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
$content .
|
||||
"<?php endif; unset(\$s);?>\n";
|
||||
}
|
||||
|
@ -379,7 +381,7 @@ class tplKutrl
|
|||
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
|
||||
|
||||
if (isset($attr['has_message'])) {
|
||||
$sign = (boolean) $attr['has_message'] ? '!' : '=';
|
||||
$sign = (bool) $attr['has_message'] ? '!' : '=';
|
||||
$if[] = '"" ' . $sign . '= $_ctx->kutrl_msg';
|
||||
}
|
||||
if (empty($if)) {
|
||||
|
@ -387,7 +389,7 @@ class tplKutrl
|
|||
}
|
||||
|
||||
return
|
||||
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
'<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
$content .
|
||||
"<?php endif; ?>\n";
|
||||
}
|
||||
|
@ -405,8 +407,8 @@ class tplKutrl
|
|||
public static function humanFieldProtect($attr)
|
||||
{
|
||||
return
|
||||
"<input type=\"hidden\" name=\"hmfp\" id=\"hmfp\" value=\"<?php echo \$_ctx->kutrl_hmfp; ?>\" />".
|
||||
"<?php echo \$core->formNonce(); ?>";
|
||||
'<input type="hidden" name="hmfp" id="hmfp" value="<?php echo $_ctx->kutrl_hmfp; ?>" />' .
|
||||
'<?php echo $core->formNonce(); ?>';
|
||||
}
|
||||
|
||||
public static function AttachmentKutrlIf($attr, $content)
|
||||
|
@ -474,22 +476,23 @@ class tplKutrl
|
|||
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
|
||||
|
||||
if (isset($attr['is_active'])) {
|
||||
$sign = (boolean) $attr['is_active'] ? '' : '!';
|
||||
$sign = (bool) $attr['is_active'] ? '' : '!';
|
||||
$if[] = $sign . '$_ctx->exists("kutrl")';
|
||||
}
|
||||
if (isset($attr['passive_mode'])) {
|
||||
$sign = (boolean) $attr['passive_mode'] ? '' : '!';
|
||||
$sign = (bool) $attr['passive_mode'] ? '' : '!';
|
||||
$if[] = $sign . '$_ctx->kutrl_passive';
|
||||
}
|
||||
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 (empty($if)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return
|
||||
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
'<?php if(' . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||
$content .
|
||||
"<?php endif; ?>\n";
|
||||
}
|
||||
|
@ -497,29 +500,30 @@ class tplKutrl
|
|||
protected static function genericKutrl($str, $attr)
|
||||
{
|
||||
$f = $GLOBALS['core']->tpl->getFilters($attr);
|
||||
|
||||
return
|
||||
"<?php \n" .
|
||||
# Preview
|
||||
"if (\$_ctx->preview) { \n" .
|
||||
" echo " . sprintf($f, $str) . "; " .
|
||||
' echo ' . sprintf($f, $str) . '; ' .
|
||||
"} else { \n" .
|
||||
# Disable
|
||||
"if (!\$_ctx->exists('kutrl')) { \n" .
|
||||
# Passive mode
|
||||
" if (\$_ctx->kutrl_passive) { " .
|
||||
" echo " . sprintf($f, $str) . "; " .
|
||||
' if ($_ctx->kutrl_passive) { ' .
|
||||
' echo ' . sprintf($f, $str) . '; ' .
|
||||
" } \n" .
|
||||
"} else { \n" .
|
||||
# Existing
|
||||
" if (false !== (\$kutrl_rs = \$_ctx->kutrl->isKnowUrl(" . $str . "))) { " .
|
||||
" echo " . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . "; " .
|
||||
' if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl(' . $str . '))) { ' .
|
||||
' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
|
||||
" } \n" .
|
||||
# New
|
||||
" elseif (false !== (\$kutrl_rs = \$_ctx->kutrl->hash(" . $str . "))) { " .
|
||||
" echo " . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . "; " .
|
||||
' elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash(' . $str . '))) { ' .
|
||||
' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
|
||||
|
||||
# ex: Send new url to messengers
|
||||
" if (!empty(\$kutrl_rs)) { " .
|
||||
' if (!empty($kutrl_rs)) { ' .
|
||||
" \$core->callBehavior('publicAfterKutrlCreate',\$core,\$kutrl_rs,__('New public short URL')); " .
|
||||
" } \n" .
|
||||
|
||||
|
@ -555,6 +559,7 @@ class hmfKutrl
|
|||
for ($i = 0; $i < $len; $i++) {
|
||||
$res .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -562,10 +567,10 @@ class hmfKutrl
|
|||
{
|
||||
$res = '';
|
||||
$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];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -576,6 +581,7 @@ class hmfKutrl
|
|||
$i++;
|
||||
$res .= $str[$i];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
|
@ -10,59 +10,86 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'settings',
|
||||
/* action */ 'delete_all',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ __('delete all settings')
|
||||
/* type */
|
||||
'settings',
|
||||
/* action */
|
||||
'delete_all',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
__('delete all settings')
|
||||
);
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'tables',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'kutrl',
|
||||
/* description */ __('delete table')
|
||||
/* type */
|
||||
'tables',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'kutrl',
|
||||
/* description */
|
||||
__('delete table')
|
||||
);
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'plugins',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ __('delete plugin files')
|
||||
/* type */
|
||||
'plugins',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
__('delete plugin files')
|
||||
);
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'versions',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ __('delete the version number')
|
||||
/* type */
|
||||
'versions',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
__('delete the version number')
|
||||
);
|
||||
|
||||
# Delete only dc version and plugin files from pluginsBeforeDelete
|
||||
# Keep table
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'settings',
|
||||
/* action */ 'delete_all',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ sprintf(__('delete all %s settings'),'kUtRL')
|
||||
/* type */
|
||||
'settings',
|
||||
/* action */
|
||||
'delete_all',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
sprintf(__('delete all %s settings'), 'kUtRL')
|
||||
);
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'versions',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ sprintf(__('delete %s version number'),'kUtRL')
|
||||
/* type */
|
||||
'versions',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
sprintf(__('delete %s version number'), 'kUtRL')
|
||||
);
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'plugins',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'kUtRL',
|
||||
/* description */ sprintf(__('delete %s plugin files'),'kUtRL')
|
||||
/* type */
|
||||
'plugins',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'kUtRL',
|
||||
/* description */
|
||||
sprintf(__('delete %s plugin files'), 'kUtRL')
|
||||
);
|
18
_widgets.php
18
_widgets.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -60,7 +59,8 @@ class widgetKutrl
|
|||
'type',
|
||||
__('Type:'),
|
||||
'all',
|
||||
'combo',[
|
||||
'combo',
|
||||
[
|
||||
__('All') => '-',
|
||||
__('Mini URL') => 'localnormal',
|
||||
__('Custom URL') => 'localcustom',
|
||||
|
@ -162,9 +162,9 @@ class widgetKutrl
|
|||
|
||||
$type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ?
|
||||
"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 = '';
|
||||
if ($w->type == 'localmix' && '' != $w->mixprefix) {
|
||||
|
@ -176,11 +176,11 @@ class widgetKutrl
|
|||
|
||||
$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(
|
||||
'SELECT kut_counter, kut_hash ' .
|
||||
"FROM " . $core->prefix . "kutrl " .
|
||||
'FROM ' . $core->prefix . 'kutrl ' .
|
||||
"WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " .
|
||||
"AND kut_service = 'local' " .
|
||||
$type . $hide . $more . 'ORDER BY ' . $order . $limit
|
||||
|
@ -198,7 +198,7 @@ class widgetKutrl
|
|||
|
||||
$hash = $rs->kut_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) {
|
||||
$url = '...' . substr($url, $cut_len);
|
||||
|
@ -216,8 +216,7 @@ class widgetKutrl
|
|||
$counttext = sprintf(__('followed %s times'), $rs->kut_counter);
|
||||
}
|
||||
|
||||
$content .=
|
||||
'<li><a href="' .
|
||||
$content .= '<li><a href="' .
|
||||
$core->blog->url . $core->url->getBase('kutrl') . '/' . $rs->kut_hash .
|
||||
'">' .
|
||||
str_replace(
|
||||
|
@ -239,6 +238,5 @@ class widgetKutrl
|
|||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||
sprintf('<ul>%s</ul>', $content)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -24,7 +23,6 @@ class kUtRL
|
|||
$list = $core->getBehaviors('kutrlService');
|
||||
|
||||
if (empty($list)) {
|
||||
|
||||
return [];
|
||||
}
|
||||
$services = [];
|
||||
|
@ -33,7 +31,6 @@ class kUtRL
|
|||
list($service_id, $service_class) = call_user_func($callback);
|
||||
$services[(string) $service_id] = (string) $service_class;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,12 +45,10 @@ class kUtRL
|
|||
|
||||
try {
|
||||
if (empty($id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
$services = self::getServices($core);
|
||||
if (isset($services[$id])) {
|
||||
|
||||
return new $services[$id]($core);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
@ -70,12 +65,10 @@ class kUtRL
|
|||
|
||||
try {
|
||||
if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) {
|
||||
|
||||
return null;
|
||||
}
|
||||
$id = $core->blog->settings->kUtRL->get('kutrl_' . $place . '_service');
|
||||
if (!empty($id)) {
|
||||
|
||||
return self::quickService($id);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
@ -93,14 +86,13 @@ class kUtRL
|
|||
try {
|
||||
$srv = self::quickPlace($place);
|
||||
if (empty($srv)) {
|
||||
|
||||
return $url;
|
||||
}
|
||||
$rs = $srv->hash($url, $custom);
|
||||
if (empty($rs)) {
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
return $srv->url_base . $rs->hash;
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
# This file is used with plugin activityReport
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
# This file contents class to acces local short links records
|
||||
|
||||
class kutrlLog
|
||||
|
@ -63,6 +62,7 @@ class kutrlLog
|
|||
];
|
||||
} catch (Exception $e) {
|
||||
$this->con->unlock();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
@ -73,8 +73,7 @@ class kutrlLog
|
|||
{
|
||||
//$this->con->writeLock($this->table);
|
||||
|
||||
$req =
|
||||
'SELECT kut_id as id, kut_hash as hash, kut_url as url, ' .
|
||||
$req = '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 ' .
|
||||
'FROM ' . $this->table . ' ' .
|
||||
"WHERE blog_id = '" . $this->blog . "' " .
|
||||
|
@ -104,7 +103,7 @@ class kutrlLog
|
|||
|
||||
public function clear($id)
|
||||
{
|
||||
$id = (integer) $id;
|
||||
$id = (int) $id;
|
||||
|
||||
$cur = $this->con->openCursor($this->table);
|
||||
$this->con->writeLock($this->table);
|
||||
|
@ -123,6 +122,7 @@ class kutrlLog
|
|||
return true;
|
||||
} catch (Exception $e) {
|
||||
$this->con->unlock();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ class kutrlLog
|
|||
|
||||
public function delete($id)
|
||||
{
|
||||
$id = (integer) $id;
|
||||
$id = (int) $id;
|
||||
|
||||
return $this->con->execute(
|
||||
'DELETE FROM ' . $this->table . ' ' .
|
||||
|
@ -142,7 +142,7 @@ class kutrlLog
|
|||
|
||||
public function counter($id, $do = 'get')
|
||||
{
|
||||
$id = (integer) $id;
|
||||
$id = (int) $id;
|
||||
|
||||
$rs = $this->con->select(
|
||||
'SELECT kut_counter ' .
|
||||
|
@ -154,21 +154,19 @@ class kutrlLog
|
|||
$counter = $rs->isEmpty() ? 0 : $rs->kut_counter;
|
||||
|
||||
if ('get' == $do) {
|
||||
|
||||
return $counter;
|
||||
} elseif ('up' == $do) {
|
||||
$counter += 1;
|
||||
} elseif ('reset' == $do) {
|
||||
$counter = 0;
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$cur = $this->con->openCursor($this->table);
|
||||
$this->con->writeLock($this->table);
|
||||
|
||||
$cur->kut_counter = (integer) $counter;
|
||||
$cur->kut_counter = (int) $counter;
|
||||
$cur->update(
|
||||
"WHERE blog_id='" . $this->blog . "' " .
|
||||
"AND kut_id='" . $id . "'"
|
||||
|
@ -188,8 +186,7 @@ class kutrlLog
|
|||
if (!empty($p['columns']) && is_array($p['columns'])) {
|
||||
$content_req .= implode(', ', $p['columns']) . ', ';
|
||||
}
|
||||
$r =
|
||||
'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
|
||||
$r = 'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
|
||||
$content_req . 'S.kut_dt ';
|
||||
}
|
||||
$r .= 'FROM ' . $this->table . ' S ';
|
||||
|
@ -203,8 +200,7 @@ class kutrlLog
|
|||
$r .= "AND kut_service='kutrl' ";
|
||||
}
|
||||
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']);
|
||||
} elseif ($p['kut_type'] != '') {
|
||||
$r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' ";
|
||||
|
@ -232,18 +228,15 @@ class kutrlLog
|
|||
}
|
||||
}
|
||||
if (!empty($p['kut_year'])) {
|
||||
$r .=
|
||||
'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
|
||||
$r .= 'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
|
||||
"'" . sprintf('%04d', $p['kut_year']) . "' ";
|
||||
}
|
||||
if (!empty($p['kut_month'])) {
|
||||
$r .=
|
||||
'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
|
||||
$r .= 'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
|
||||
"'" . sprintf('%02d', $p['kut_month']) . "' ";
|
||||
}
|
||||
if (!empty($p['kut_day'])) {
|
||||
$r .=
|
||||
'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
|
||||
$r .= 'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
|
||||
"'" . sprintf('%02d', $p['kut_day']) . "' ";
|
||||
}
|
||||
if (!empty($p['sql'])) {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
class kutrlLinkslist
|
||||
{
|
||||
protected $core;
|
||||
|
@ -55,7 +54,7 @@ class kutrlLinkslist
|
|||
$links = [];
|
||||
if (isset($_REQUEST['entries'])) {
|
||||
foreach ($_REQUEST['entries'] as $v) {
|
||||
$links[(integer) $v] = true;
|
||||
$links[(int) $v] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,10 +67,10 @@ class kutrlLinkslist
|
|||
$cols = new ArrayObject($cols);
|
||||
$this->userColumns('kUtRL', $cols);
|
||||
|
||||
$html_block =
|
||||
'<div class="table-outer">' .
|
||||
$html_block = '<div class="table-outer">' .
|
||||
'<table>' .
|
||||
'<caption>' . ($filter ?
|
||||
'<caption>' . (
|
||||
$filter ?
|
||||
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
|
||||
sprintf(__('List of links (%s)'), $this->rs_count)
|
||||
) . '</caption>' .
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
# Generic class for shorten link service
|
||||
# A service class must extends this one
|
||||
class kutrlService
|
||||
|
@ -20,7 +19,7 @@ class kutrlService
|
|||
public $settings;
|
||||
public $log;
|
||||
|
||||
protected $config = array();
|
||||
protected $config = [];
|
||||
|
||||
public function __construct($core)
|
||||
{
|
||||
|
@ -65,7 +64,7 @@ class kutrlService
|
|||
# get config value
|
||||
public function get($k)
|
||||
{
|
||||
return isset($this->config[$k]) ? $this->config[$k] : null;
|
||||
return $this->config[$k] ?? null;
|
||||
}
|
||||
|
||||
# Additionnal actions on child start
|
||||
|
@ -98,7 +97,7 @@ class kutrlService
|
|||
# Test if an url is valid
|
||||
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
|
||||
|
@ -110,7 +109,7 @@ class kutrlService
|
|||
# Test if an url is long enoutgh
|
||||
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
|
||||
|
@ -121,7 +120,6 @@ class kutrlService
|
|||
continue;
|
||||
}
|
||||
if (strpos($url, $protocol) === 0) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +180,8 @@ class kutrlService
|
|||
|
||||
# --BEHAVIOR-- kutrlAfterCreateShortUrl
|
||||
$this->core->callBehavior('kutrlAfterCreateShortUrl', $rs);
|
||||
|
||||
}
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
# This file contents class to shorten url pass through wiki
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
@ -62,18 +61,20 @@ class kutrlWiki
|
|||
}
|
||||
if (!$rs) {
|
||||
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'];
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,21 +10,18 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
# This file takes records from plugin dcMiniUrl
|
||||
# and inserts them into plugin kUtRL.
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')){return;}
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$miniurl_patch = new dcMiniUrl2kUtRL($core);
|
||||
if ($miniurl_patch->parseRecords())
|
||||
{
|
||||
try
|
||||
{
|
||||
if ($miniurl_patch->parseRecords()) {
|
||||
try {
|
||||
$core->plugins->deactivateModule('dcMiniUrl');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
//$core->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -50,20 +47,19 @@ class dcMiniUrl2kUtRL
|
|||
'SELECT * FROM ' . $this->m_tb . ' '
|
||||
);
|
||||
|
||||
while ($rs->fetch())
|
||||
{
|
||||
if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl')
|
||||
{
|
||||
if ($this->exists($rs)) continue;
|
||||
while ($rs->fetch()) {
|
||||
if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') {
|
||||
if ($this->exists($rs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->insertKutrl($rs);
|
||||
$this->insertLocal($rs);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->insertOther($rs);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -123,6 +119,7 @@ class dcMiniUrl2kUtRL
|
|||
"AND kut_service = 'local' " .
|
||||
"AND kut_hash = '" . $rs->miniurl_id . "' "
|
||||
);
|
||||
|
||||
return !$chk->isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -88,7 +87,6 @@ class customKutrlService extends kutrlService
|
|||
public function testService()
|
||||
{
|
||||
if (empty($this->url_api)) {
|
||||
|
||||
return false;
|
||||
}
|
||||
$url = $this->url_encode ? urlencode($this->url_test) : $this->url_test;
|
||||
|
@ -109,6 +107,7 @@ class customKutrlService extends kutrlService
|
|||
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
$rs = new ArrayObject();
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ class googlKutrlService extends kutrlService
|
|||
private $args = [
|
||||
'key' => ''
|
||||
];
|
||||
private $headers = array('Content-Type: application/json');
|
||||
private $headers = ['Content-Type: application/json'];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
@ -40,6 +39,7 @@ class googlKutrlService extends kutrlService
|
|||
$args['shortUrl'] = $this->url_base . 'PLovn';
|
||||
if (!($response = self::post($this->url_api, $args, true, true, $this->headers))) {
|
||||
$this->error->add(__('Failed to call service.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,10 @@ class googlKutrlService extends kutrlService
|
|||
|
||||
if (empty($rsp->status)) {
|
||||
$this->error->add(__('An error occured'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -60,6 +62,7 @@ class googlKutrlService extends kutrlService
|
|||
|
||||
if (!($response = self::post($this->url_api, $args, true, false, $this->headers))) {
|
||||
$this->error->add(__('Failed to call service.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,6 +70,7 @@ class googlKutrlService extends kutrlService
|
|||
|
||||
if (empty($rsp->id)) {
|
||||
$this->error->add(__('An error occured'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
class isgdKutrlService extends kutrlService
|
||||
{
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -32,7 +31,6 @@ class localKutrlService extends kutrlService
|
|||
|
||||
$this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/';
|
||||
$this->config['url_min_len'] = strlen($this->url_base) + 2;
|
||||
|
||||
}
|
||||
|
||||
public function saveSettings()
|
||||
|
@ -104,14 +102,12 @@ class localKutrlService extends kutrlService
|
|||
{
|
||||
$ap = $this->allow_protocols;
|
||||
if (!empty($ap)) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
$this->error->add(__('Service is not well configured.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function createHash($url, $hash = null)
|
||||
{
|
||||
|
@ -175,6 +171,7 @@ class localKutrlService extends kutrlService
|
|||
|
||||
if ($last_id[$pos] != 'z') {
|
||||
$next_id = $this->increment($last_id, $pos);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +218,6 @@ class localKutrlService extends kutrlService
|
|||
public function getUrl($hash)
|
||||
{
|
||||
if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) {
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!$rs->url) { //previously removed url
|
||||
|
@ -236,7 +232,6 @@ class localKutrlService extends kutrlService
|
|||
public function deleteUrl($url, $delete = false)
|
||||
{
|
||||
if (false === ($rs = $this->log->select($url, null, null, 'local'))) {
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($delete) {
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -32,8 +31,10 @@ class shorttoKutrlService extends kutrlService
|
|||
$arg = ['url' => urlencode($this->url_test)];
|
||||
if (!self::post($this->url_api, $arg, true, true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,7 @@ class shorttoKutrlService extends kutrlService
|
|||
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,13 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
class suprKutrlService extends kutrlService
|
||||
{
|
||||
protected $config = array(
|
||||
protected $config = [
|
||||
'id' => 'supr',
|
||||
'name' => 'su.pr StumbleUpon',
|
||||
'home' => 'http://su.pr',
|
||||
|
@ -23,14 +24,14 @@ class suprKutrlService extends kutrlService
|
|||
'url_api' => 'http://su.pr/api/',
|
||||
'url_base' => 'http://su.pr/',
|
||||
'url_min_len' => 23
|
||||
);
|
||||
];
|
||||
|
||||
private $args = array(
|
||||
private $args = [
|
||||
'version' => '1.0',
|
||||
'format' => 'xml',
|
||||
'login' => '',
|
||||
'apiKey' => ''
|
||||
);
|
||||
];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
@ -48,13 +49,13 @@ class suprKutrlService extends kutrlService
|
|||
{
|
||||
echo
|
||||
'<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>' .
|
||||
'<p class="form-note">' .
|
||||
sprintf(__('This is your login to sign up to %s'), $this->config['name']) .
|
||||
'</p>' .
|
||||
'<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>' .
|
||||
'<p class="form-note">' .
|
||||
sprintf(__('This is your personnal %s API key. You can find it on your account page.'), $this->config['name']) .
|
||||
|
@ -63,17 +64,17 @@ class suprKutrlService extends kutrlService
|
|||
|
||||
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.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = $this->args;
|
||||
$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.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -81,11 +82,13 @@ class suprKutrlService extends kutrlService
|
|||
|
||||
$status = (string) $rsp->statusCode;
|
||||
if ($status != 'OK') {
|
||||
$err_no = (integer) $rsp->errorCode;
|
||||
$err_msg = (integer) $rsp->errorMessage;
|
||||
$err_no = (int) $rsp->errorCode;
|
||||
$err_msg = (int) $rsp->errorMessage;
|
||||
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,9 +97,9 @@ class suprKutrlService extends kutrlService
|
|||
$args = $this->args;
|
||||
$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.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -104,9 +107,10 @@ class suprKutrlService extends kutrlService
|
|||
|
||||
$status = (string) $rsp->statusCode;
|
||||
if ($status != 'OK') {
|
||||
$err_no = (integer) $rsp->errorCode;
|
||||
$err_msg = (integer) $rsp->errorMessage;
|
||||
$err_no = (int) $rsp->errorCode;
|
||||
$err_msg = (int) $rsp->errorMessage;
|
||||
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,13 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')){return;}
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
class trimKutrlService extends kutrlService
|
||||
{
|
||||
protected $config = array(
|
||||
protected $config = [
|
||||
'id' => 'trim',
|
||||
'name' => 'tr.im',
|
||||
'home' => 'http://tr.im',
|
||||
|
@ -23,12 +24,12 @@ class trimKutrlService extends kutrlService
|
|||
'url_api' => 'http://api.tr.im/v1/',
|
||||
'url_base' => 'http://tr.im/',
|
||||
'url_min_len' => 25
|
||||
);
|
||||
];
|
||||
|
||||
private $args = array(
|
||||
private $args = [
|
||||
'username' => '',
|
||||
'password' => ''
|
||||
);
|
||||
];
|
||||
|
||||
private $api_rate_time = 0;
|
||||
|
||||
|
@ -37,7 +38,7 @@ class trimKutrlService extends kutrlService
|
|||
$this->args['username'] = $this->settings->kutrl_srv_trim_username;
|
||||
$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()
|
||||
|
@ -50,13 +51,13 @@ class trimKutrlService extends kutrlService
|
|||
{
|
||||
echo
|
||||
'<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>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is your login to sign up to tr.im.') .
|
||||
'</p>' .
|
||||
'<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>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is your password to sign up to tr.im.') .
|
||||
|
@ -65,28 +66,28 @@ class trimKutrlService extends kutrlService
|
|||
|
||||
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.'));
|
||||
|
||||
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.'));
|
||||
|
||||
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.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
$r = simplexml_load_string($rsp);
|
||||
|
||||
if ($r['code'] == 200)
|
||||
{
|
||||
if ($r['code'] == 200) {
|
||||
return true;
|
||||
}
|
||||
$this->error->add(__('Authentication to service failed.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,24 +96,23 @@ class trimKutrlService extends kutrlService
|
|||
$arg = $this->args;
|
||||
$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.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = simplexml_load_string($rsp);
|
||||
|
||||
# API rate limit
|
||||
if ($r['code'] == 425)
|
||||
{
|
||||
if ($r['code'] == 425) {
|
||||
$this->settings->put('kutrl_srv_trim_apiratetime', time());
|
||||
|
||||
$this->error->add(__('Service rate limit exceeded.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
if (isset($r->trimpath))
|
||||
{
|
||||
if (isset($r->trimpath)) {
|
||||
$rs = new ArrayObject();
|
||||
$rs->hash = $r->trimpath;
|
||||
$rs->url = $url;
|
||||
|
@ -121,6 +121,7 @@ class trimKutrlService extends kutrlService
|
|||
return $rs;
|
||||
}
|
||||
$this->error->add(__('Unreadable service response.'));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -93,7 +92,6 @@ class yourlsKutrlService extends kutrlService
|
|||
$rsp = @simplexml_load_string($response);
|
||||
|
||||
if ($rsp && $rsp->status == 'success') {
|
||||
|
||||
return true;
|
||||
}
|
||||
$this->error->add(__('Authentication to service failed.'));
|
||||
|
|
14
index.php
14
index.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
@ -19,8 +18,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
|||
dcPage::check('admin');
|
||||
|
||||
$header = '';
|
||||
$part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'links';
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||||
$part = $_REQUEST['part'] ?? 'links';
|
||||
$action = $_POST['action'] ?? '';
|
||||
|
||||
# link creation
|
||||
if ($part == 'link') {
|
||||
|
@ -75,6 +74,7 @@ if ($part == 'link') {
|
|||
if ($kut->error->flag()) {
|
||||
throw new Exception($kut->error->toHTML());
|
||||
}
|
||||
|
||||
throw new Exception(__('Failed to create short link. This could be caused by a service failure.'));
|
||||
} else {
|
||||
$url = $rs->url;
|
||||
|
@ -113,7 +113,10 @@ if ($part == 'link') {
|
|||
$kUtRL_filter->add('part', 'links');
|
||||
$kUtRL_filter->add(dcAdminFilters::getPageFilter());
|
||||
$kUtRL_filter->add(dcAdminFilters::getSelectFilter(
|
||||
'urlsrv', __('Service:'), $lst_services_combo, 'kut_type'
|
||||
'urlsrv',
|
||||
__('Service:'),
|
||||
$lst_services_combo,
|
||||
'kut_type'
|
||||
));
|
||||
|
||||
$params = $kUtRL_filter->params();
|
||||
|
@ -126,8 +129,7 @@ if ($part == 'link') {
|
|||
$core->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
$header =
|
||||
$kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) .
|
||||
$header = $kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) .
|
||||
dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js'));
|
||||
|
||||
if (!empty($_POST['deletelinks'])) {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of kUtRL, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
/**
|
||||
* @brief kUtRL, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html';
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of kUtRL, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
/**
|
||||
* @brief kUtRL, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html';
|
Loading…
Reference in New Issue