cosmetics

This commit is contained in:
Jean-Christian Denis 2021-10-26 23:03:38 +02:00
parent 9e9bb94f1d
commit 79a77474f0
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
17 changed files with 187 additions and 120 deletions

View file

@ -1,4 +1,15 @@
<?php
/**
* @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_CONTEXT_ADMIN')) {
return;

View file

@ -21,11 +21,11 @@ $this->registerModule(
'Jean-Christian Denis and contributors',
'2021.09.16',
[
'requires' => [['core', '2.19']],
'requires' => [['core', '2.19']],
'permissions' => 'usage,contentadmin,admin',
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/kUtRL',
'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL',
'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml'
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/kUtRL',
'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL',
'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml'
]
);

View file

@ -21,15 +21,11 @@ $old_version = $core->getVersion('kUtRL');
# Compare versions
if (version_compare($old_version, $new_version, '>=')) {
return;
return null;
}
# Install or update
try {
if (version_compare(str_replace("-r", "-p", DC_VERSION), '2.2-alpha', '<')) {
throw new Exception('kUtRL requires Dotclear 2.2');
}
# Table
$t = new dbStruct($core->con, $core->prefix);
$t->kutrl
@ -89,5 +85,6 @@ try {
return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
return false;
}
}
return false;

View file

@ -14,11 +14,6 @@
if (!defined('DC_RC_PATH')) {
return;
}
if (version_compare(str_replace("-r", "-p", DC_VERSION), '2.2-alpha', '<')) {
return;
}
global $__autoload, $core;
# Set a URL shortener for quick get request
if (!defined('SHORTEN_SERVICE_NAME')) {
@ -39,9 +34,9 @@ if (!defined('SHORTEN_SERVICE_ENCODE')) {
# Main class
$d = dirname(__FILE__) . '/inc/';
$__autoload['kutrl'] = $d . 'class.kutrl.php';
$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php';
$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php';
$__autoload['kutrl'] = $d . 'class.kutrl.php';
$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php';
$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php';
$__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php';
# Services

View file

@ -57,11 +57,13 @@ class urlKutrl extends dcUrlHandlers
# Not active, go to default 404
if (!$s->kutrl_active) {
self::p404();
return null;
}
# Not a valid url, go to kutrl 404
if (!preg_match('#^(|(/(.*?)))$#', $args, $m)) {
self::kutrl404();
return null;
}
@ -85,6 +87,7 @@ class urlKutrl extends dcUrlHandlers
# No arg, go to kurtl page
if ($args == '') {
self::pageKutrl($kut);
return null;
}
# Not find, go to kutrl 404
@ -92,16 +95,19 @@ class urlKutrl extends dcUrlHandlers
//$_ctx->kutrl_msg = 'Failed to find short link.';
//self::pageKutrl($kut);
self::kutrl404();
return null;
}
# Removed (empty url), go to kutrl 404
if (!$url) {
self::kutrl404();
return null;
}
$core->blog->triggerBlog();
http::redirect($url . $suffix);
return null;
}
@ -113,11 +119,13 @@ class urlKutrl extends dcUrlHandlers
# Not active, go to default 404
if (!$s->kutrl_active) {
self::p404();
return null;
}
# Public page not active, go to kutrl 404
if (!$s->kutrl_srv_local_public) {
self::kutrl404();
return null;
}
# Validation form
@ -209,6 +217,7 @@ class urlKutrl extends dcUrlHandlers
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates');
self::serveDocument('kutrl.html');
return null;
}
@ -218,6 +227,7 @@ class urlKutrl extends dcUrlHandlers
if (!$core->blog->settings->kUtRL->kutrl_srv_local_404_active) {
self::p404();
return null;
}
@ -282,7 +292,8 @@ class pubKutrl
if (empty($GLOBALS['disable_kutrl'])) {
# kUtRL is not activated
if (!$core->blog->settings->kUtRL->kutrl_active
|| !$core->blog->settings->kUtRL->kutrl_tpl_active) {
|| !$core->blog->settings->kUtRL->kutrl_tpl_active
) {
return null;
}

View file

@ -19,11 +19,12 @@ if (!defined('DC_RC_PATH')) {
class kUtRL
{
# Load services list from behavior
public static function getServices($core)
public static function getServices(dcCore $core)
{
$list = $core->getBehaviors('kutrlService');
if (empty($list)) {
return [];
}
$services = [];
@ -35,6 +36,7 @@ class kUtRL
}
}
return $services;
}
@ -46,15 +48,17 @@ class kUtRL
try {
if (empty($id)) {
return null;
}
$services = self::getServices($core);
if (isset($services[$id])) {
return new $services[$id]($core);
}
} catch(Exception $e) {
}
return null;
}
@ -66,15 +70,17 @@ 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) {
}
return null;
}
@ -87,16 +93,18 @@ 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) {
}
return $url;
}
}

View file

@ -20,12 +20,12 @@ class kutrlLog
public $blog;
public $con;
public function __construct($core)
public function __construct(dcCore $core)
{
$this->core = $core;
$this->core = $core;
$this->table = $core->prefix . 'kutrl';
$this->blog = $core->con->escape($core->blog->id);
$this->con = $core->con;
$this->blog = $core->con->escape($core->blog->id);
$this->con = $core->con;
}
public function nextId()
@ -41,23 +41,23 @@ class kutrlLog
$this->con->writeLock($this->table);
try {
$cur->kut_id = $this->nextId();
$cur->blog_id = $this->blog;
$cur->kut_url = (string) $url;
$cur->kut_hash = (string) $hash;
$cur->kut_type = (string) $type;
$cur->kut_id = $this->nextId();
$cur->blog_id = $this->blog;
$cur->kut_url = (string) $url;
$cur->kut_hash = (string) $hash;
$cur->kut_type = (string) $type;
$cur->kut_service = (string) $service;
$cur->kut_dt = date('Y-m-d H:i:s');
$cur->kut_dt = date('Y-m-d H:i:s');
$cur->kut_counter = 0;
$cur->insert();
$this->con->unlock();
return [
'id' => $cur->kut_id,
'url' => $url,
'hash' => $hash,
'type' => $type,
'id' => $cur->kut_id,
'url' => $url,
'hash' => $hash,
'type' => $type,
'service' => $service,
'counter '=> 0
];
@ -65,6 +65,7 @@ class kutrlLog
$this->con->unlock();
throw $e;
}
return false;
}
@ -109,8 +110,8 @@ class kutrlLog
$this->con->writeLock($this->table);
try {
$cur->kut_url = '';
$cur->kut_dt = date('Y-m-d H:i:s');
$cur->kut_url = '';
$cur->kut_dt = date('Y-m-d H:i:s');
$cur->kut_counter = 0;
$cur->update(
@ -124,6 +125,7 @@ class kutrlLog
$this->con->unlock();
throw $e;
}
return false;
}
@ -152,12 +154,14 @@ 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;
}
@ -253,6 +257,7 @@ class kutrlLog
if (!$count_only && !empty($p['limit'])) {
$r .= $this->con->limit($p['limit']);
}
return $this->con->select($r);
}
}

View file

@ -60,8 +60,8 @@ class kutrlLinkslist
}
$cols = [
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
'kut_service' => '<th scope="col">' . __('Service') . '</th>'
];

View file

@ -24,10 +24,10 @@ class kutrlService
public function __construct($core)
{
$this->core = $core;
$this->core = $core;
$this->settings = $core->blog->settings->kUtRL;
$this->log = new kutrlLog($core);
$this->error = new dcError();
$this->log = new kutrlLog($core);
$this->error = new dcError();
$this->error->setHTMLFormat('%s', "%s\n");
$this->init();
@ -39,18 +39,18 @@ class kutrlService
$this->config = array_merge(
[
'id' => 'undefined',
'name' => 'undefined',
'home' => '',
'id' => 'undefined',
'name' => 'undefined',
'home' => '',
'allow_external_url' => true,
'allow_custom_hash' => false,
'allow_protocols' => ['http://'],
'allow_custom_hash' => false,
'allow_protocols' => ['http://'],
'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL',
'url_api' => '',
'url_base' => '',
'url_min_len' => 0
'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL',
'url_api' => '',
'url_base' => '',
'url_min_len' => 0
],
$this->config
);
@ -121,9 +121,11 @@ class kutrlService
continue;
}
if (strpos($url,$protocol) === 0) {
return true;
}
}
return false;
}
@ -199,6 +201,7 @@ class kutrlService
}
$this->deleteUrl($url);
$this->log->delete($rs->id);
return true;
}
@ -238,6 +241,7 @@ class kutrlService
if ($verbose) {
return $client->getContent();
}
return true;
}
}

View file

@ -26,8 +26,9 @@ class kutrlWiki
# Do nothing on comment preview and post preview
if (!empty($_POST['preview'])
|| !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview
|| !$s->kutrl_active) {
|| !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview
|| !$s->kutrl_active
) {
return null;
}
if (null === ($kut = kutrl::quickPlace('wiki'))) {

View file

@ -18,7 +18,7 @@ if (!defined('DC_RC_PATH')) {
class bilbolinksKutrlService extends kutrlService
{
protected $config = [
'id' => 'bilbolinks',
'id' => 'bilbolinks',
'name' => 'BilboLinks',
'home' => 'http://www.tux-planet.fr/bilbobox/'
];
@ -62,14 +62,17 @@ class bilbolinksKutrlService extends kutrlService
{
if (empty($this->url_base)) {
$this->error->add(__('Service is not well configured.'));
return false;
}
$arg = ['longurl' => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true,true)) {
$this->error->add(__('Service is unavailable.'));
return false;
}
return true;
}
@ -79,15 +82,17 @@ class bilbolinksKutrlService extends kutrlService
if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.'));
return false;
}
if ($response == 'You are too speed!') {
$this->error->add(__('Service rate limit exceeded.'));
return false;
}
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url;
$rs->url = $url;
$rs->type = $this->id;
return $rs;

View file

@ -18,26 +18,26 @@ if (!defined('DC_RC_PATH')) {
class bitlyKutrlService extends kutrlService
{
protected $config = [
'id' => 'bitly',
'name' => 'bit.ly',
'home' => 'http://bit.ly',
'id' => 'bitly',
'name' => 'bit.ly',
'home' => 'http://bit.ly',
'url_api' => 'http://api.bit.ly/v3/',
'url_base' => 'http://bit.ly/',
'url_api' => 'http://api.bit.ly/v3/',
'url_base' => 'http://bit.ly/',
'url_min_len' => 25
];
private $args = [
'format' => 'xml',
'login' => '',
'apiKey' => '',
'format' => 'xml',
'login' => '',
'apiKey' => '',
'history' => 0
];
protected function init()
{
$this->args['login'] = $this->settings->kutrl_srv_bitly_login;
$this->args['apiKey'] = $this->settings->kutrl_srv_bitly_apikey;
$this->args['login'] = $this->settings->kutrl_srv_bitly_login;
$this->args['apiKey'] = $this->settings->kutrl_srv_bitly_apikey;
$this->args['history'] = $this->settings->kutrl_srv_bitly_history ? 1 : 0;
}
@ -76,6 +76,7 @@ class bitlyKutrlService extends kutrlService
{
if (empty($this->args['login']) || empty($this->args['apiKey'])) {
$this->error->add(__('Service is not well configured.'));
return false;
}
@ -83,6 +84,7 @@ class bitlyKutrlService extends kutrlService
$args['hash'] = 'WP9vc';
if (!($response = self::post($this->url_api . 'expand', $args, true))) {
$this->error->add(__('Failed to call service.'));
return false;
}
@ -92,18 +94,20 @@ class bitlyKutrlService extends kutrlService
if ($err_msg != 'OK') {
$err_no = (integer) $rsp->status_code;
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
return false;
}
return true;
}
public function createHash($url, $hash = null)
{
$args = $this->args;
$args['longUrl'] = $url;
$args = array_merge($this->args, ['longUrl' => $url]);
if (!($response = self::post($this->url_api . 'shorten', $args, true))) {
$this->error->add(__('Failed to call service.'));
return false;
}
@ -113,12 +117,13 @@ class bitlyKutrlService extends kutrlService
if ($err_msg != 'OK') {
$err_no = (integer) $rsp->status_code;
$this->error->add(sprintf(__('An error occured with code %s and message "%s"'), $err_no, $err_msg));
return false;
}
$rs = new ArrayObject();
$rs->hash = (string) $rsp->data[0]->hash;
$rs->url = (string) $rsp->data[0]->long_url;
$rs->url = (string) $rsp->data[0]->long_url;
$rs->type = $this->id;
return $rs;

View file

@ -18,22 +18,21 @@ if (!defined('DC_RC_PATH')) {
class customKutrlService extends kutrlService
{
protected $config = [
'id' => 'custom',
'id' => 'custom',
'name' => 'Custom'
];
protected function init()
{
$config = unserialize(base64_decode($this->settings->kutrl_srv_custom));
if (!is_array($config))
{
if (!is_array($config)) {
$config = [];
}
$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_param'] = !empty($config['url_param']) ? $config['url_param'] : '';
$this->config['url_encode'] = !empty($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_param'] = !empty($config['url_param']) ? $config['url_param'] : '';
$this->config['url_encode'] = !empty($config['url_api']);
$this->config['url_min_length'] = strlen($this->url_base) + 2;
}
@ -41,9 +40,9 @@ class customKutrlService extends kutrlService
public function saveSettings()
{
$config = [
'url_api' => $_POST['kutrl_srv_custom_url_api'],
'url_base' => $_POST['kutrl_srv_custom_url_base'],
'url_param' => $_POST['kutrl_srv_custom_url_param'],
'url_api' => $_POST['kutrl_srv_custom_url_api'],
'url_base' => $_POST['kutrl_srv_custom_url_base'],
'url_param' => $_POST['kutrl_srv_custom_url_param'],
'url_encode' => !empty($_POST['kutrl_srv_custom_url_encode'])
];
$this->settings->put('kutrl_srv_custom', base64_encode(serialize($config)));
@ -52,9 +51,9 @@ class customKutrlService extends kutrlService
public function settingsForm()
{
$default = [
'url_api' => '',
'url_base' => '',
'url_param' => '',
'url_api' => '',
'url_base' => '',
'url_param' => '',
'url_encode' => true
];
$config = unserialize(base64_decode($this->settings->kutrl_srv_custom));
@ -89,21 +88,24 @@ 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;
$arg = [$this->url_param => $url];
if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.'));
return false;
}
return true;
}
public function createHash($url, $hash = null)
{
$enc = $this->url_encode ? urlencode($url) : $url;
$arg = array($this->url_param => $enc);
$arg = [$this->url_param => $enc];
if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.'));
@ -111,7 +113,7 @@ class customKutrlService extends kutrlService
}
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url;
$rs->url = $url;
$rs->type = $this->id;
return $rs;

View file

@ -25,16 +25,16 @@ class defaultKutrlService extends kutrlService
protected function init()
{
$this->config = [
'id' => 'default',
'name' => 'Default',
'home' => '',
'id' => 'default',
'name' => 'Default',
'home' => '',
'url_api' => SHORTEN_SERVICE_API,
'url_base' => SHORTEN_SERVICE_BASE,
'url_api' => SHORTEN_SERVICE_API,
'url_base' => SHORTEN_SERVICE_BASE,
'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2,
'url_param' => SHORTEN_SERVICE_PARAM,
'url_encode' => SHORTEN_SERVICE_ENCODE
'url_param' => SHORTEN_SERVICE_PARAM,
'url_encode' => SHORTEN_SERVICE_ENCODE
];
}
@ -62,28 +62,31 @@ class defaultKutrlService extends kutrlService
public function testService()
{
$url = $this->url_encode ? urlencode($this->url_test) : $this->url_test;
$arg = array($this->url_param => urlencode($this->url_test));
$arg = [$this->url_param => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.'));
return false;
}
return true;
}
public function createHash($url, $hash = null)
{
$enc = $this->url_encode ? urlencode($url) : $url;
$arg = array($this->url_param => $url);
$arg = [$this->url_param => $url];
if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.'));
return false;
}
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url;
$rs->url = $url;
$rs->type = $this->id;
return $rs;

View file

@ -16,12 +16,12 @@ if (!defined('DC_RC_PATH')){return;}
class isgdKutrlService extends kutrlService
{
protected $config = [
'id' => 'isgd',
'name' => 'is.gd',
'home' => 'http://is.gd/',
'id' => 'isgd',
'name' => 'is.gd',
'home' => 'http://is.gd/',
'url_api' => 'http://is.gd/api.php',
'url_base' => 'http://is.gd/',
'url_api' => 'http://is.gd/api.php',
'url_base' => 'http://is.gd/',
'url_min_length' => 25
];
@ -30,8 +30,10 @@ class isgdKutrlService extends kutrlService
$arg = ['longurl' => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.'));
return false;
}
return true;
}
@ -41,12 +43,13 @@ class isgdKutrlService extends kutrlService
if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.'));
return false;
}
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url;
$rs->url = $url;
$rs->type = $this->id;
return $rs;

View file

@ -18,9 +18,9 @@ if (!defined('DC_RC_PATH')) {
class localKutrlService extends kutrlService
{
protected $config = [
'id' => 'local',
'name' => 'kUtRL',
'home' => 'https://github.com/JcDenis/kUtRL',
'id' => 'local',
'name' => 'kUtRL',
'home' => 'https://github.com/JcDenis/kUtRL',
'allow_custom_hash' => true
];
@ -104,9 +104,11 @@ class localKutrlService extends kutrlService
{
$ap = $this->allow_protocols;
if (!empty($ap)) {
return true;
} else {
$this->error->add(__('Service is not well configured.'));
return false;
}
}
@ -116,7 +118,7 @@ class localKutrlService extends kutrlService
# Create response object
$rs = new ArrayObject();
$rs->type = 'local';
$rs->url = $url;
$rs->url = $url;
# Normal link
if ($hash === null) {
@ -132,6 +134,7 @@ class localKutrlService extends kutrlService
} elseif (preg_match('/^[A-Za-z0-9\.\-\_]{2,}$/', $hash)) {
if (false !== $this->log->select(null, $hash, null, 'local')) {
$this->error->add(__('Custom short link is already taken.'));
return false;
}
$type = 'localcustom';
@ -140,23 +143,25 @@ class localKutrlService extends kutrlService
# Wrong char in custom hash
} else {
$this->error->add(__('Custom short link is not valid.'));
return false;
}
# Save link
try {
$this->log->insert($rs->url, $rs->hash, $type, $rs->type);
return $rs;
} catch (Exception $e) {
$this->error->add(__('Failed to save link.'));
}
return false;
}
protected function last($type)
{
return
false === ($rs = $this->log->select(null, null, $type, 'local')) ?
return false === ($rs = $this->log->select(null, null, $type, 'local')) ?
-1 : $rs->hash;
}
@ -177,9 +182,9 @@ class localKutrlService extends kutrlService
$next_id = $this->append($last_id);
}
}
return
false === $this->log->select(null,$prefix . $next_id, null, 'local') ?
$next_id : $this->next($next_id, $prefix);
return false === $this->log->select(null,$prefix . $next_id, null, 'local') ?
$next_id : $this->next($next_id, $prefix);
}
protected function append($id)
@ -188,6 +193,7 @@ class localKutrlService extends kutrlService
for ($x = 0; $x < count($id); $x++) {
$id[$x] = 0;
}
return implode($id) . '0';
}
@ -208,24 +214,29 @@ class localKutrlService extends kutrlService
$id[$x] = 0;
}
}
return implode($id);
}
public function getUrl($hash)
{
if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) {
return false;
}
if (!$rs->url) { //previously removed url
return false;
}
$this->log->counter($rs->id, 'up');
return $rs->url;
}
public function deleteUrl($url, $delete = false)
{
if (false === ($rs = $this->log->select($url, null, null, 'local'))) {
return false;
}
if ($delete) {
@ -233,6 +244,7 @@ class localKutrlService extends kutrlService
} else {
$this->log->clear($rs->id, '');
}
return true;
}
}

View file

@ -18,7 +18,7 @@ if (!defined('DC_RC_PATH')) {
class yourlsKutrlService extends kutrlService
{
protected $config = [
'id' => 'yourls',
'id' => 'yourls',
'name' => 'YOURLS',
'home' => 'http://yourls.org'
];
@ -26,8 +26,8 @@ class yourlsKutrlService extends kutrlService
private $args = [
'username' => '',
'password' => '',
'format' => 'xml',
'action' => 'shorturl'
'format' => 'xml',
'action' => 'shorturl'
];
protected function init()
@ -38,8 +38,8 @@ class yourlsKutrlService extends kutrlService
$base = (string) $this->settings->kutrl_srv_yourls_base;
//if (!empty($base) && substr($base,-1,1) != '/') $base .= '/';
$this->config['url_api'] = $base;
$this->config['url_base'] = $base;
$this->config['url_api'] = $base;
$this->config['url_base'] = $base;
$this->config['url_min_len'] = strlen($base)+3;
}
@ -78,6 +78,7 @@ class yourlsKutrlService extends kutrlService
{
if (empty($this->url_api)) {
$this->error->add(__('Service is not well configured.'));
return false;
}
@ -86,24 +87,27 @@ class yourlsKutrlService extends kutrlService
if (!($response = self::post($this->url_api, $this->args, true))) {
$this->error->add(__('Service is unavailable.'));
return false;
}
$rsp = @simplexml_load_string($response);
if ($rsp && $rsp->status == 'success') {
return true;
}
$this->error->add(__('Authentication to service failed.'));
return false;
}
public function createHash($url, $hash = null)
{
$args = $this->args;
$args['url'] = $url;
$args = array_merge($this->args, ['url' => $url]);
if (!($response = self::post($this->url_api, $args, true))) {
$this->error->add(__('Service is unavailable.'));
return false;
}
@ -112,12 +116,13 @@ class yourlsKutrlService extends kutrlService
if ($rsp && $rsp->status == 'success') {
$rs = new ArrayObject();
$rs->hash = $rsp->url[0]->keyword;
$rs->url = $url;
$rs->url = $url;
$rs->type = $this->id;
return $rs;
}
$this->error->add(__('Unreadable service response.'));
return false;
}
}