From cba24bc78c02bdff92976395f37c05e79c7a9575 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 28 Aug 2021 01:52:03 +0200 Subject: [PATCH] clean services files and remove un-ping-able ones --- _prepend.php | 20 +- inc/services/class.bilbolinks.service.php | 161 ++++---- inc/services/class.bitly.service.php | 220 ++++++----- inc/services/class.custom.service.php | 206 +++++----- inc/services/class.default.service.php | 141 ++++--- inc/services/class.googl.service.php | 121 +++--- inc/services/class.isgd.service.php | 77 ++-- inc/services/class.local.service.php | 450 ++++++++++------------ inc/services/class.shortto.service.php | 79 ++-- inc/services/class.yourls.service.php | 218 +++++------ 10 files changed, 821 insertions(+), 872 deletions(-) diff --git a/_prepend.php b/_prepend.php index 16aeaac..7ede583 100644 --- a/_prepend.php +++ b/_prepend.php @@ -45,26 +45,26 @@ $__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php'; # Services $__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php'; $core->addBehavior('kutrlService', function() { return ["bilbolinks","bilbolinksKutrlService"]; } ); -$__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php'; -$core->addBehavior('kutrlService', function() { return ["bitly","bitlyKutrlService"]; } ); +//$__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php'; +//$core->addBehavior('kutrlService', function() { return ["bitly","bitlyKutrlService"]; } ); $__autoload['customKutrlService'] = $d . 'services/class.custom.service.php'; $core->addBehavior('kutrlService', function() { return ["custom","customKutrlService"]; } ); $__autoload['defaultKutrlService'] = $d . 'services/class.default.service.php'; $core->addBehavior('kutrlService', function() { return ["default","defaultKutrlService"]; } ); -$__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php'; -$core->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } ); +//$__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php'; +//$core->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } ); $__autoload['isgdKutrlService'] = $d . 'services/class.isgd.service.php'; $core->addBehavior('kutrlService', function() { return ["isgd","isgdKutrlService"]; } ); $__autoload['localKutrlService'] = $d . 'services/class.local.service.php'; $core->addBehavior('kutrlService', function() { return ["local","localKutrlService"]; } ); -$__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php'; -$core->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } ); -$__autoload['trimKutrlService'] = $d . 'services/class.trim.service.php'; -$core->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } ); +//$__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php'; +//$core->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } ); +//$__autoload['trimKutrlService'] = $d . 'services/class.trim.service.php'; +//$core->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } ); $__autoload['yourlsKutrlService'] = $d . 'services/class.yourls.service.php'; $core->addBehavior('kutrlService', function() { return ["yourls","yourlsKutrlService"]; } ); -$__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php'; -$core->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } ); +//$__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php'; +//$core->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } ); # Shorten url passed through wiki functions $__autoload['kutrlWiki'] = $d . 'lib.wiki.kutrl.php'; diff --git a/inc/services/class.bilbolinks.service.php b/inc/services/class.bilbolinks.service.php index f1eac24..2aef065 100644 --- a/inc/services/class.bilbolinks.service.php +++ b/inc/services/class.bilbolinks.service.php @@ -10,88 +10,85 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class bilbolinksKutrlService extends kutrlService { - protected $config = array( - 'id' => 'bilbolinks', - 'name' => 'BilboLinks', - 'home' => 'http://www.tux-planet.fr/bilbobox/' - ); - - protected function init() - { - $base = (string) $this->settings->kutrl_srv_bilbolinks_base; - if (!empty($base) && substr($base,-1,1) != '/') $base .= '/'; - - $this->config['url_api'] = $base.'api.php'; - $this->config['url_base'] = $base; - $this->config['url_min_len'] = 25; - } - - public function saveSettings() - { - $base = ''; - if (!empty($_POST['kutrl_srv_bilbolinks_base'])) - { - $base = $_POST['kutrl_srv_bilbolinks_base']; - if (substr($base,-1,1) != '/') $base .= '/'; - } - - $this->settings->put('kutrl_srv_bilbolinks_base',$base); - } - - public function settingsForm() - { - echo - '

'. - '

'. - __('This is the root URL of the "bilbolinks" service you want to use. Ex: "http://tux-pla.net/".'). - '

'; - } - - public function testService() - { - if (empty($this->url_base)) - { - $this->error->add(__('Service is not well configured.')); - return false; - } - - $arg = array('longurl' => 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) - { - $arg = array('longurl' => $url); - - 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->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + protected $config = [ + 'id' => 'bilbolinks', + 'name' => 'BilboLinks', + 'home' => 'http://www.tux-planet.fr/bilbobox/' + ]; + + protected function init() + { + $base = (string) $this->settings->kutrl_srv_bilbolinks_base; + if (!empty($base) && substr($base, -1, 1) != '/') { + $base .= '/'; + } + $this->config['url_api'] = $base . 'api.php'; + $this->config['url_base'] = $base; + $this->config['url_min_len'] = 25; + } + + public function saveSettings() + { + $base = ''; + if (!empty($_POST['kutrl_srv_bilbolinks_base'])) { + $base = $_POST['kutrl_srv_bilbolinks_base']; + if (substr($base, -1, 1) != '/') { + $base .= '/'; + } + } + $this->settings->put('kutrl_srv_bilbolinks_base', $base); + } + + public function settingsForm() + { + echo + '

' . + '

' . + __('This is the root URL of the "bilbolinks" service you want to use. Ex: "http://tux-pla.net/".') . + '

'; + } + + public function testService() + { + 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; + } + + public function createHash($url, $hash = null) + { + $arg = ['longurl' => $url]; + + 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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.bitly.service.php b/inc/services/class.bitly.service.php index 235a978..1cbe4cb 100644 --- a/inc/services/class.bitly.service.php +++ b/inc/services/class.bitly.service.php @@ -10,118 +10,116 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class bitlyKutrlService extends kutrlService { - protected $config = array( - 'id' => 'bitly', - 'name' => 'bit.ly', - 'home' => 'http://bit.ly', - - 'url_api' => 'http://api.bit.ly/v3/', - 'url_base' => 'http://bit.ly/', - 'url_min_len' => 25 - ); - - private $args = array( - '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['history'] = $this->settings->kutrl_srv_bitly_history ? 1 : 0; - } - - public function saveSettings() - { - $this->settings->put('kutrl_srv_bitly_login',$_POST['kutrl_srv_bitly_login']); - $this->settings->put('kutrl_srv_bitly_apikey',$_POST['kutrl_srv_bitly_apikey']); - $this->settings->put('kutrl_srv_bitly_history',isset($_POST['kutrl_srv_bitly_history'])); - } - - public function settingsForm() - { - echo - '

'. - '

'. - sprintf(__('This is your login to sign up to %s'),$this->config['name']). - '

'. - '

'. - '

'. - sprintf(__('This is your personnal %s API key. You can find it on your account page.'),$this->config['name']). - '

'. - '

'. - '

'. - __('This publish all short links on your bit.ly public page.'). - '

'; - } - - public function testService() - { - if (empty($this->args['login']) || empty($this->args['apiKey'])) - { - $this->error->add(__('Service is not well configured.')); - return false; - } + protected $config = [ + 'id' => 'bitly', + 'name' => 'bit.ly', + 'home' => 'http://bit.ly', + + 'url_api' => 'http://api.bit.ly/v3/', + 'url_base' => 'http://bit.ly/', + 'url_min_len' => 25 + ]; - $args = $this->args; - $args['hash'] = 'WP9vc'; - if (!($response = self::post($this->url_api.'expand',$args,true))) - { - $this->error->add(__('Failed to call service.')); - return false; - } - - $rsp = simplexml_load_string($response); - - $err_msg = (string) $rsp->status_txt; - 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; - - if (!($response = self::post($this->url_api.'shorten',$args,true))) - { - $this->error->add(__('Failed to call service.')); - return false; - } - - $rsp = simplexml_load_string($response); - - $err_msg = (string) $rsp->status_txt; - 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->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + private $args = [ + '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['history'] = $this->settings->kutrl_srv_bitly_history ? 1 : 0; + } + + public function saveSettings() + { + $this->settings->put('kutrl_srv_bitly_login', $_POST['kutrl_srv_bitly_login']); + $this->settings->put('kutrl_srv_bitly_apikey', $_POST['kutrl_srv_bitly_apikey']); + $this->settings->put('kutrl_srv_bitly_history', isset($_POST['kutrl_srv_bitly_history'])); + } + + public function settingsForm() + { + echo + '

' . + '

' . + sprintf(__('This is your login to sign up to %s'), $this->config['name']) . + '

' . + '

' . + '

' . + sprintf(__('This is your personnal %s API key. You can find it on your account page.'), $this->config['name']) . + '

' . + '

' . + '

' . + __('This publish all short links on your bit.ly public page.') . + '

'; + } + + public function testService() + { + if (empty($this->args['login']) || empty($this->args['apiKey'])) { + $this->error->add(__('Service is not well configured.')); + return false; + } + + $args = $this->args; + $args['hash'] = 'WP9vc'; + if (!($response = self::post($this->url_api . 'expand', $args, true))) { + $this->error->add(__('Failed to call service.')); + return false; + } + + $rsp = simplexml_load_string($response); + + $err_msg = (string) $rsp->status_txt; + 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; + + if (!($response = self::post($this->url_api . 'shorten', $args, true))) { + $this->error->add(__('Failed to call service.')); + return false; + } + + $rsp = simplexml_load_string($response); + + $err_msg = (string) $rsp->status_txt; + 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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.custom.service.php b/inc/services/class.custom.service.php index 449d25b..05926e8 100644 --- a/inc/services/class.custom.service.php +++ b/inc/services/class.custom.service.php @@ -10,111 +10,109 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class customKutrlService extends kutrlService { - protected $config = array( - 'id' => 'custom', - 'name' => 'Custom' - ); - - protected function init() - { - $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); - if (!is_array($config)) - { - $config = array(); - } - - $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; - } - - public function saveSettings() - { - $config = array( - '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))); - } - - public function settingsForm() - { - $default = array( - 'url_api' => '', - 'url_base' => '', - 'url_param' => '', - 'url_encode' => true - ); - $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); - if (!is_array($config)) - { - $config = array(); - } - $config = array_merge($default,$config); - - echo - '

'.__('You can set a configurable service.').'
'. - __('It consists on a simple query to an URL with only one param.').'
'. - __('It must respond with a http code 200 on success.').'
'. - __('It must returned the short URL (or only hash) in clear text.').'

' . - '

'. - '

'.__('Full path to API of the URL shortener. ex: "http://is.gd/api.php"').'

'. - '

'. - '

'.__('Common part of the short URL. ex: "http://is.gd/"').'

'. - '

'. - '

'.__('Param of the query. ex: "longurl"').'

'. - '

'; - } - - public function testService() - { - if (empty($this->url_api)) return false; - - $url = $this->url_encode ? urlencode($this->url_test) : $this->url_test; - $arg = array($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); - - 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->type = $this->id; + protected $config = [ + 'id' => 'custom', + 'name' => 'Custom' + ]; + + protected function init() + { + $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); + 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_min_length'] = strlen($this->url_base) + 2; + } - return $rs; - } -} -?> \ No newline at end of file + 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_encode' => !empty($_POST['kutrl_srv_custom_url_encode']) + ]; + $this->settings->put('kutrl_srv_custom', base64_encode(serialize($config))); + } + + public function settingsForm() + { + $default = [ + 'url_api' => '', + 'url_base' => '', + 'url_param' => '', + 'url_encode' => true + ]; + $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); + if (!is_array($config)) { + $config = []; + } + $config = array_merge($default, $config); + + echo + '

' . __('You can set a configurable service.') . '
' . + __('It consists on a simple query to an URL with only one param.') . '
' . + __('It must respond with a http code 200 on success.') . '
' . + __('It must returned the short URL (or only hash) in clear text.') . '

' . + '

' . + '

' . __('Full path to API of the URL shortener. ex: "http://is.gd/api.php"') . '

' . + '

' . + '

' . __('Common part of the short URL. ex: "http://is.gd/"') . '

' . + '

' . + '

' . __('Param of the query. ex: "longurl"') . '

' . + '

'; + } + + 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); + + 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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.default.service.php b/inc/services/class.default.service.php index 1f71056..f7e943d 100644 --- a/inc/services/class.default.service.php +++ b/inc/services/class.default.service.php @@ -10,7 +10,9 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} # nb: "default" ne veut pas dire service par défaut # mais service simple et rapide configuré par des constantes @@ -19,73 +21,70 @@ if (!defined('DC_RC_PATH')){return;} class defaultKutrlService extends kutrlService { - protected function init() - { - $this->config = array( - 'id' => 'default', - 'name' => 'Default', - 'home' => '', - - '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 - ); - } - - public function settingsForm() - { - echo - '

'. - __('There is nothing to configure for this service.'). - '

'. - '

'.__('This service is set to:').'

'. - '
'. - '
'.__('Service name:').'
'. - '
'.SHORTEN_SERVICE_NAME.'
'. - '
'.__('Full API URL:').'
'. - '
'.SHORTEN_SERVICE_API.'
'. - '
'.__('Query param:').'
'. - '
'.SHORTEN_SERVICE_PARAM.'
'. - '
'.__('Short URL domain:').'
'. - '
'.SHORTEN_SERVICE_BASE.'
'. - '
'.__('Encode URL:').'
'. - '
'.(SHORTEN_SERVICE_ENCODE ? __('yes') : __('no')).'
'. - '
'; - } - - public function testService() - { - $url = $this->url_encode ? urlencode($this->url_test) : $this->url_test; - $arg = array($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); - - 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->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + protected function init() + { + $this->config = [ + 'id' => 'default', + 'name' => 'Default', + 'home' => '', + + '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 + ]; + } + + public function settingsForm() + { + echo + '

' . + __('There is nothing to configure for this service.') . + '

' . + '

' . __('This service is set to:') . '

' . + '
' . + '
' . __('Service name:') . '
' . + '
' . SHORTEN_SERVICE_NAME . '
' . + '
' . __('Full API URL:') . '
' . + '
' . SHORTEN_SERVICE_API . '
' . + '
' . __('Query param:') . '
' . + '
' . SHORTEN_SERVICE_PARAM . '
' . + '
' . __('Short URL domain:') . '
' . + '
' . SHORTEN_SERVICE_BASE . '
' . + '
' . __('Encode URL:') . '
' . + '
' . (SHORTEN_SERVICE_ENCODE ? __('yes') : __('no')) . '
' . + '
'; + } + + public function testService() + { + $url = $this->url_encode ? urlencode($this->url_test) : $this->url_test; + $arg = array($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); + + 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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.googl.service.php b/inc/services/class.googl.service.php index 5a175e1..bcc70fd 100644 --- a/inc/services/class.googl.service.php +++ b/inc/services/class.googl.service.php @@ -10,71 +10,70 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class googlKutrlService extends kutrlService { - public $id = 'googl'; - public $name = 'goo.gl'; - public $home = 'http://goo.gl'; + public $id = 'googl'; + public $name = 'goo.gl'; + public $home = 'http://goo.gl'; - private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; - private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; - private $args = array( - 'key' => 'AIzaSyDE1WfOMdnrnX8p51jSmVodenaNk385asc' - ); - private $headers = array('Content-Type: application/json'); - - protected function init() - { - $this->url_base = 'http://goo.gl/'; - $this->url_min_length = 20; - } + private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; + private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; + private $args = [ + 'key' => 'AIzaSyDE1WfOMdnrnX8p51jSmVodenaNk385asc' + ]; + private $headers = array('Content-Type: application/json'); + + protected function init() + { + $this->url_base = 'http://goo.gl/'; + $this->url_min_length = 20; + } - public function testService() - { - $args = $this->args; - $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; - } - - $rsp = json_decode($response); - - if (empty($rsp->status)) { - $this->error->add(__('An error occured')); - return false; - } - return true; - } + public function testService() + { + $args = $this->args; + $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; + } - public function createHash($url,$hash=null) - { - $args = $this->args; - $args['longUrl'] = $url; - $args = json_encode($args); + $rsp = json_decode($response); - if (!($response = self::post($this->url_api,$args,true,false,$this->headers))) - { - $this->error->add(__('Failed to call service.')); - return false; - } - - $rsp = json_decode($response); - - if (empty($rsp->id)) { - $this->error->add(__('An error occured')); - return false; - } - - $rs = new ArrayObject(); - $rs->hash = str_replace($this->url_base,'',$rsp->id); - $rs->url = $rsp->longUrl; - $rs->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + if (empty($rsp->status)) { + $this->error->add(__('An error occured')); + return false; + } + return true; + } + + public function createHash($url, $hash = null) + { + $args = $this->args; + $args['longUrl'] = $url; + $args = json_encode($args); + + if (!($response = self::post($this->url_api, $args, true, false, $this->headers))) { + $this->error->add(__('Failed to call service.')); + return false; + } + + $rsp = json_decode($response); + + if (empty($rsp->id)) { + $this->error->add(__('An error occured')); + return false; + } + + $rs = new ArrayObject(); + $rs->hash = str_replace($this->url_base, '', $rsp->id); + $rs->url = $rsp->longUrl; + $rs->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.isgd.service.php b/inc/services/class.isgd.service.php index 62ef7e6..1252e2c 100644 --- a/inc/services/class.isgd.service.php +++ b/inc/services/class.isgd.service.php @@ -14,43 +14,40 @@ if (!defined('DC_RC_PATH')){return;} class isgdKutrlService extends kutrlService { - protected $config = array( - 'id' => 'isgd', - 'name' => 'is.gd', - 'home' => 'http://is.gd/', - - 'url_api' => 'http://is.gd/api.php', - 'url_base' => 'http://is.gd/', - 'url_min_length' => 25 - ); - - public function testService() - { - $arg = array('longurl' => 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) - { - $arg = array('longurl' => $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->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + protected $config = [ + 'id' => 'isgd', + 'name' => 'is.gd', + 'home' => 'http://is.gd/', + + 'url_api' => 'http://is.gd/api.php', + 'url_base' => 'http://is.gd/', + 'url_min_length' => 25 + ]; + + public function testService() + { + $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; + } + + public function createHash($url, $hash = null) + { + $arg = ['longurl' => $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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.local.service.php b/inc/services/class.local.service.php index 7354b91..15c2315 100644 --- a/inc/services/class.local.service.php +++ b/inc/services/class.local.service.php @@ -10,262 +10,228 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class localKutrlService extends kutrlService { - protected $config = array( - 'id' => 'local', - 'name' => 'kUtRL', - 'home' => 'http://kutrl.fr', - - 'allow_custom_hash' => true - ); - - protected function init() - { - $protocols = (string) $this->settings->kutrl_srv_local_protocols; - $this->config['allow_protocols'] = empty($protocols) ? array() : explode(',',$protocols); + protected $config = [ + 'id' => 'local', + 'name' => 'kUtRL', + 'home' => 'http://kutrl.fr', + + 'allow_custom_hash' => true + ]; + + protected function init() + { + $protocols = (string) $this->settings->kutrl_srv_local_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_min_len'] = strlen($this->url_base) + 2; - - } - - public function saveSettings() - { - $this->settings->put('kutrl_srv_local_protocols',$_POST['kutrl_srv_local_protocols'],'string'); - $this->settings->put('kutrl_srv_local_public',isset($_POST['kutrl_srv_local_public']),'boolean'); - $this->settings->put('kutrl_srv_local_css',$_POST['kutrl_srv_local_css'],'string'); - $this->settings->put('kutrl_srv_local_404_active',isset($_POST['kutrl_srv_local_404_active']),'boolean'); - } + $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() + { + $this->settings->put('kutrl_srv_local_protocols', $_POST['kutrl_srv_local_protocols'], 'string'); + $this->settings->put('kutrl_srv_local_public', isset($_POST['kutrl_srv_local_public']), 'boolean'); + $this->settings->put('kutrl_srv_local_css', $_POST['kutrl_srv_local_css'], 'string'); + $this->settings->put('kutrl_srv_local_404_active', isset($_POST['kutrl_srv_local_404_active']), 'boolean'); + } - public function settingsForm() - { - echo - '
'. - - '

'.__('Settings:').'

'. - '

'. + public function settingsForm() + { + echo + '
' . + + '

' . __('Settings:') . '

' . + '

' . - '

'. - __('Use comma seperated list like: "http:,https:,ftp:"'). - '

'. + '

' . + __('Use comma seperated list like: "http:,https:,ftp:"') . + '

' . - '

'. + '

' . - '

'. - form::textarea('kutrl_srv_local_css',50,3,html::escapeHTML($this->settings->kutrl_srv_local_css),'',2). - '

'. - '

'.__('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".').'

'. + '

' . + form::textarea('kutrl_srv_local_css',50,3,html::escapeHTML($this->settings->kutrl_srv_local_css), '', 2) . + '

' . + '

' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '

' . - '

'. - '

'.__('If this is not activated, the default 404 page of the theme will be display.').'

'. + '

' . + '

' . __('If this is not activated, the default 404 page of the theme will be display.') . '

' . - '
'. - - '

'.__('Note:').'

'. - '

'. - __('This service use your own Blog to shorten and serve URL.').'
'. - sprintf(__('This means that with this service short links start with "%s".'),$this->url_base). - '

'. - '

'. - __("You can use Dotclear's plugin called myUrlHandlers to change short links prefix on your blog."); + '

' . + + '

' . __('Note:') . '

' . + '

' . + __('This service use your own Blog to shorten and serve URL.') . '
' . + sprintf(__('This means that with this service short links start with "%s".'), $this->url_base) . + '

' . + '

' . + __("You can use Dotclear's plugin called myUrlHandlers to change short links prefix on your blog."); - if (preg_match('/index\.php/',$this->url_base)) - { - echo - '

'. - __("We recommand that you use a rewrite engine in order to remove 'index.php' from your blog's URL."). - '
'. - __("You can find more about this on the Dotclear's documentation."). - '

'; - } - echo - '

'. - '

'.__('There are two templates delivered with kUtRL, if you do not use default theme, you may adapt them to yours.').'
'. - __('Files are in plugin directory /default-templates, just copy them into your theme and edit them.').'

'. - - '
'; - } + if (preg_match('/index\.php/', $this->url_base)) { + echo + '

' . + __("We recommand that you use a rewrite engine in order to remove 'index.php' from your blog's URL.") . + '
' . + __("You can find more about this on the Dotclear's documentation.") . + '

'; + } + echo + '

' . + '

' . __('There are two templates delivered with kUtRL, if you do not use default theme, you may adapt them to yours.') . '
' . + __('Files are in plugin directory /default-templates, just copy them into your theme and edit them.') . '

' . + + '
'; + } - public function testService() - { - $ap = $this->allow_protocols; - if (!empty($ap)) - { - return true; - } - else { - $this->error->add(__('Service is not well configured.')); - return false; - } - } + public function testService() + { + $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) - { - # Create response object - $rs = new ArrayObject(); - $rs->type = 'local'; - $rs->url = $url; + public function createHash($url, $hash = null) + { + # Create response object + $rs = new ArrayObject(); + $rs->type = 'local'; + $rs->url = $url; - # Normal link - if ($hash === null) - { - $type = 'localnormal'; - $rs->hash = $this->next($this->last('localnormal')); - } + # Normal link + if ($hash === null) { + $type = 'localnormal'; + $rs->hash = $this->next($this->last('localnormal')); - # Mixed custom link - elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/',$hash,$m)) - { - $type = 'localmix'; - $rs->hash = $m[1].$this->next(-1,$m[1]); - } + # Mixed custom link + } elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/', $hash, $m)) { + $type = 'localmix'; + $rs->hash = $m[1] . $this->next(-1, $m[1]); - # Custom link - 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'; - $rs->hash = $hash; - } + # Custom link + } 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'; + $rs->hash = $hash; - # 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')) ? - -1 : $rs->hash; - } - - protected function next($last_id,$prefix='') - { - if ($last_id == -1) - { - $next_id = 0; - } - else - { - for($x = 1; $x <= strlen($last_id); $x++) - { - $pos = strlen($last_id) - $x; - - if ($last_id[$pos] != 'z') - { - $next_id = $this->increment($last_id,$pos); - break; - } - } - - if (!isset($next_id)) - { - $next_id = $this->append($last_id); - } - } - - return - false === $this->log->select(null,$prefix.$next_id,null,'local') ? - $next_id : $this->next($next_id,$prefix); - } - - protected function append($id) - { - $id = str_split($id); - for ($x = 0; $x < count($id); $x++) - { - $id[$x] = 0; - } - return implode($id).'0'; - } - - protected function increment($id,$pos) - { - $id = str_split($id); - $char = $id[$pos]; - - if (is_numeric($char)) - { - $new_char = $char < 9 ? $char + 1 : 'a'; - } - else - { - $new_char = chr(ord($char) + 1); - } - $id[$pos] = $new_char; - - if ($pos != (count($id) - 1)) - { - for ($x = ($pos + 1); $x < count($id); $x++) - { - $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) - { - $this->log->delete($rs->id); - } - else - { - $this->log->clear($rs->id,''); - } - return true; - } -} -?> \ No newline at end of file + # 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')) ? + -1 : $rs->hash; + } + + protected function next($last_id, $prefix = '') + { + if ($last_id == -1) { + $next_id = 0; + } else { + for($x = 1; $x <= strlen($last_id); $x++) { + $pos = strlen($last_id) - $x; + + if ($last_id[$pos] != 'z') { + $next_id = $this->increment($last_id, $pos); + break; + } + } + if (!isset($next_id)) { + $next_id = $this->append($last_id); + } + } + return + false === $this->log->select(null,$prefix . $next_id, null, 'local') ? + $next_id : $this->next($next_id, $prefix); + } + + protected function append($id) + { + $id = str_split($id); + for ($x = 0; $x < count($id); $x++) { + $id[$x] = 0; + } + return implode($id) . '0'; + } + + protected function increment($id, $pos) + { + $id = str_split($id); + $char = $id[$pos]; + + if (is_numeric($char)) { + $new_char = $char < 9 ? $char + 1 : 'a'; + } else { + $new_char = chr(ord($char) + 1); + } + $id[$pos] = $new_char; + + if ($pos != (count($id) - 1)) { + for ($x = ($pos + 1); $x < count($id); $x++) { + $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) { + $this->log->delete($rs->id); + } else { + $this->log->clear($rs->id, ''); + } + return true; + } +} \ No newline at end of file diff --git a/inc/services/class.shortto.service.php b/inc/services/class.shortto.service.php index 8559608..0703bd8 100644 --- a/inc/services/class.shortto.service.php +++ b/inc/services/class.shortto.service.php @@ -10,47 +10,46 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class shorttoKutrlService extends kutrlService { - protected $config = array( - 'id' => 'shortto', - 'name' => 'short.to', - 'home' => 'http://short.to', - - 'url_api' => 'http://short.to/s.txt', - 'url_base' => 'http://short.to/', - 'url_min_len' => 25 - ); - - public function testService() - { - $arg = array('url' => 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) - { - $arg = array('url' => $url); + protected $config = [ + 'id' => 'shortto', + 'name' => 'short.to', + 'home' => 'http://short.to', - 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->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + 'url_api' => 'http://short.to/s.txt', + 'url_base' => 'http://short.to/', + 'url_min_len' => 25 + ]; + + public function testService() + { + $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; + } + + public function createHash($url, $hash = null) + { + $arg = ['url' => $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->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.yourls.service.php b/inc/services/class.yourls.service.php index 4c847dc..beddc02 100644 --- a/inc/services/class.yourls.service.php +++ b/inc/services/class.yourls.service.php @@ -10,117 +10,113 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} class yourlsKutrlService extends kutrlService { - protected $config = array( - 'id' => 'yourls', - 'name' => 'YOURLS', - 'home' => 'http://yourls.org' - ); - - private $args = array( - 'username' => '', - 'password' => '', - 'format' => 'xml', - 'action' => 'shorturl' - ); - - protected function init() - { - $this->args['username'] = $this->settings->kutrl_srv_yourls_username; - $this->args['password'] = $this->settings->kutrl_srv_yourls_password; - - $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_min_len'] = strlen($base)+3; - } - - public function saveSettings() - { - $this->settings->put('kutrl_srv_yourls_username',$_POST['kutrl_srv_yourls_username']); - $this->settings->put('kutrl_srv_yourls_password',$_POST['kutrl_srv_yourls_password']); - $this->settings->put('kutrl_srv_yourls_base',$_POST['kutrl_srv_yourls_base']); - } - - public function settingsForm() - { - echo - '

'. - '

'. - __('This is the URL of the YOURLS service you want to use. Ex: "http://www.smaller.org/api.php".'). - '

'. - '

'. - '

'. - __('This is your user name to sign up to this YOURLS service.'). - '

'. - '

'. - '

'. - __('This is your password to sign up to this YOURLS service.'). - '

'; - } - - public function testService() - { - if (empty($this->url_api)) - { - $this->error->add(__('Service is not well configured.')); - return false; - } - - $args = $this->args; - $args['url'] = $this->url_test; - - 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; - - if (!($response = self::post($this->url_api,$args,true))) - { - $this->error->add(__('Service is unavailable.')); - return false; - } - - $rsp = @simplexml_load_string($response); - - if ($rsp && $rsp->status == 'success') - { - $rs = new ArrayObject(); - $rs->hash = $rsp->url[0]->keyword; - $rs->url = $url; - $rs->type = $this->id; - - return $rs; - } - $this->error->add(__('Unreadable service response.')); - return false; - } -} -?> \ No newline at end of file + protected $config = [ + 'id' => 'yourls', + 'name' => 'YOURLS', + 'home' => 'http://yourls.org' + ]; + + private $args = [ + 'username' => '', + 'password' => '', + 'format' => 'xml', + 'action' => 'shorturl' + ]; + + protected function init() + { + $this->args['username'] = $this->settings->kutrl_srv_yourls_username; + $this->args['password'] = $this->settings->kutrl_srv_yourls_password; + + $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_min_len'] = strlen($base)+3; + } + + public function saveSettings() + { + $this->settings->put('kutrl_srv_yourls_username', $_POST['kutrl_srv_yourls_username']); + $this->settings->put('kutrl_srv_yourls_password', $_POST['kutrl_srv_yourls_password']); + $this->settings->put('kutrl_srv_yourls_base', $_POST['kutrl_srv_yourls_base']); + } + + public function settingsForm() + { + echo + '

' . + '

' . + __('This is the URL of the YOURLS service you want to use. Ex: "http://www.smaller.org/api.php".') . + '

' . + '

' . + '

' . + __('This is your user name to sign up to this YOURLS service.') . + '

' . + '

' . + '

' . + __('This is your password to sign up to this YOURLS service.') . + '

'; + } + + public function testService() + { + if (empty($this->url_api)) { + $this->error->add(__('Service is not well configured.')); + return false; + } + + $args = $this->args; + $args['url'] = $this->url_test; + + 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; + + if (!($response = self::post($this->url_api, $args, true))) { + $this->error->add(__('Service is unavailable.')); + return false; + } + + $rsp = @simplexml_load_string($response); + + if ($rsp && $rsp->status == 'success') { + $rs = new ArrayObject(); + $rs->hash = $rsp->url[0]->keyword; + $rs->url = $url; + $rs->type = $this->id; + + return $rs; + } + $this->error->add(__('Unreadable service response.')); + return false; + } +} \ No newline at end of file