clean services files and remove un-ping-able ones
This commit is contained in:
parent
2acf82b4e0
commit
cba24bc78c
20
_prepend.php
20
_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';
|
||||
|
@ -10,21 +10,24 @@
|
||||
# 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(
|
||||
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 .= '/';
|
||||
|
||||
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;
|
||||
@ -33,12 +36,12 @@ class bilbolinksKutrlService extends kutrlService
|
||||
public function saveSettings()
|
||||
{
|
||||
$base = '';
|
||||
if (!empty($_POST['kutrl_srv_bilbolinks_base']))
|
||||
{
|
||||
if (!empty($_POST['kutrl_srv_bilbolinks_base'])) {
|
||||
$base = $_POST['kutrl_srv_bilbolinks_base'];
|
||||
if (substr($base,-1,1) != '/') $base .= '/';
|
||||
if (substr($base, -1, 1) != '/') {
|
||||
$base .= '/';
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings->put('kutrl_srv_bilbolinks_base', $base);
|
||||
}
|
||||
|
||||
@ -47,7 +50,7 @@ class bilbolinksKutrlService extends kutrlService
|
||||
echo
|
||||
'<p><label class="classic">' .
|
||||
__('Url of the service:') . '<br />' .
|
||||
form::field(array('kutrl_srv_bilbolinks_base'),50,255,$this->settings->kutrl_srv_bilbolinks_base).
|
||||
form::field(['kutrl_srv_bilbolinks_base'], 50, 255, $this->settings->kutrl_srv_bilbolinks_base) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is the root URL of the "bilbolinks" service you want to use. Ex: "http://tux-pla.net/".') .
|
||||
@ -56,15 +59,13 @@ class bilbolinksKutrlService extends kutrlService
|
||||
|
||||
public function testService()
|
||||
{
|
||||
if (empty($this->url_base))
|
||||
{
|
||||
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))
|
||||
{
|
||||
$arg = ['longurl' => urlencode($this->url_test)];
|
||||
if (!self::post($this->url_api, $arg, true,true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -73,19 +74,16 @@ class bilbolinksKutrlService extends kutrlService
|
||||
|
||||
public function createHash($url, $hash = null)
|
||||
{
|
||||
$arg = array('longurl' => $url);
|
||||
$arg = ['longurl' => $url];
|
||||
|
||||
if (!($response = self::post($this->url_api,$arg,true,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
if ($response == 'You are too speed!')
|
||||
{
|
||||
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;
|
||||
@ -94,4 +92,3 @@ class bilbolinksKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,11 +10,13 @@
|
||||
# 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(
|
||||
protected $config = [
|
||||
'id' => 'bitly',
|
||||
'name' => 'bit.ly',
|
||||
'home' => 'http://bit.ly',
|
||||
@ -22,14 +24,14 @@ class bitlyKutrlService extends kutrlService
|
||||
'url_api' => 'http://api.bit.ly/v3/',
|
||||
'url_base' => 'http://bit.ly/',
|
||||
'url_min_len' => 25
|
||||
);
|
||||
];
|
||||
|
||||
private $args = array(
|
||||
private $args = [
|
||||
'format' => 'xml',
|
||||
'login' => '',
|
||||
'apiKey' => '',
|
||||
'history' => 0
|
||||
);
|
||||
];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
@ -49,19 +51,19 @@ class bitlyKutrlService extends kutrlService
|
||||
{
|
||||
echo
|
||||
'<p><label class="classic">' . __('Login:') . '<br />' .
|
||||
form::field(array('kutrl_srv_bitly_login'),50,255,$this->settings->kutrl_srv_bitly_login).
|
||||
form::field(['kutrl_srv_bitly_login'], 50, 255, $this->settings->kutrl_srv_bitly_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_bitly_apikey'),50,255,$this->settings->kutrl_srv_bitly_apikey).
|
||||
form::field(['kutrl_srv_bitly_apikey'], 50, 255, $this->settings->kutrl_srv_bitly_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']) .
|
||||
'</p>' .
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox(array('kutrl_srv_bitly_history'),'1',$this->settings->kutrl_srv_bitly_history).' '.
|
||||
form::checkbox(['kutrl_srv_bitly_history'], '1', $this->settings->kutrl_srv_bitly_history) . ' ' .
|
||||
__('Publish history') .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
@ -71,16 +73,14 @@ class bitlyKutrlService 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;
|
||||
$args['hash'] = 'WP9vc';
|
||||
if (!($response = self::post($this->url_api.'expand',$args,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api . 'expand', $args, true))) {
|
||||
$this->error->add(__('Failed to call service.'));
|
||||
return false;
|
||||
}
|
||||
@ -101,8 +101,7 @@ class bitlyKutrlService 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;
|
||||
}
|
||||
@ -124,4 +123,3 @@ class bitlyKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,21 +10,23 @@
|
||||
# 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(
|
||||
protected $config = [
|
||||
'id' => 'custom',
|
||||
'name' => 'Custom'
|
||||
);
|
||||
];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$config = unserialize(base64_decode($this->settings->kutrl_srv_custom));
|
||||
if (!is_array($config))
|
||||
{
|
||||
$config = array();
|
||||
$config = [];
|
||||
}
|
||||
|
||||
$this->config['url_api'] = !empty($config['url_api']) ? $config['url_api'] : '';
|
||||
@ -37,27 +39,26 @@ class customKutrlService extends kutrlService
|
||||
|
||||
public function saveSettings()
|
||||
{
|
||||
$config = array(
|
||||
$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 = array(
|
||||
$default = [
|
||||
'url_api' => '',
|
||||
'url_base' => '',
|
||||
'url_param' => '',
|
||||
'url_encode' => true
|
||||
);
|
||||
];
|
||||
$config = unserialize(base64_decode($this->settings->kutrl_srv_custom));
|
||||
if (!is_array($config))
|
||||
{
|
||||
$config = array();
|
||||
if (!is_array($config)) {
|
||||
$config = [];
|
||||
}
|
||||
$config = array_merge($default, $config);
|
||||
|
||||
@ -67,31 +68,31 @@ class customKutrlService extends kutrlService
|
||||
__('It must respond with a http code 200 on success.') . '<br />' .
|
||||
__('It must returned the short URL (or only hash) in clear text.') . '</p>' .
|
||||
'<p><label class="classic">' . __('API URL:') . '<br />' .
|
||||
form::field(array('kutrl_srv_custom_url_api'),50,255,$config['url_api']).
|
||||
form::field(['kutrl_srv_custom_url_api'], 50, 255, $config['url_api']) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' . __('Full path to API of the URL shortener. ex: "http://is.gd/api.php"') . '</p>' .
|
||||
'<p><label class="classic">' . __('Short URL domain:') . '<br />' .
|
||||
form::field(array('kutrl_srv_custom_url_base'),50,255,$config['url_base']).
|
||||
form::field(['kutrl_srv_custom_url_base'], 50, 255, $config['url_base']) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' . __('Common part of the short URL. ex: "http://is.gd/"') . '</p>' .
|
||||
'<p><label class="classic">' . __('API URL param:') . '<br />' .
|
||||
form::field(array('kutrl_srv_custom_url_param'),50,255,$config['url_param']).
|
||||
form::field(['kutrl_srv_custom_url_param'], 50, 255, $config['url_param']) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' . __('Param of the query. ex: "longurl"') . '</p>' .
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox(array('kutrl_srv_custom_url_encode'),'1',$config['url_encode']).' '.
|
||||
form::checkbox(['kutrl_srv_custom_url_encode'], '1', $config['url_encode']) . ' ' .
|
||||
__('Encode URL') .
|
||||
'</label></p>';
|
||||
}
|
||||
|
||||
public function testService()
|
||||
{
|
||||
if (empty($this->url_api)) return false;
|
||||
|
||||
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))
|
||||
{
|
||||
$arg = [$this->url_param => $url];
|
||||
if (!self::post($this->url_api, $arg, true, true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -103,12 +104,10 @@ class customKutrlService extends kutrlService
|
||||
$enc = $this->url_encode ? urlencode($url) : $url;
|
||||
$arg = array($this->url_param => $enc);
|
||||
|
||||
if (!($response = self::post($this->url_api,$arg,true,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$rs = new ArrayObject();
|
||||
$rs->hash = str_replace($this->url_base, '', $response);
|
||||
$rs->url = $url;
|
||||
@ -117,4 +116,3 @@ class customKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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
|
||||
@ -21,7 +23,7 @@ class defaultKutrlService extends kutrlService
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
$this->config = array(
|
||||
$this->config = [
|
||||
'id' => 'default',
|
||||
'name' => 'Default',
|
||||
'home' => '',
|
||||
@ -32,7 +34,7 @@ class defaultKutrlService extends kutrlService
|
||||
|
||||
'url_param' => SHORTEN_SERVICE_PARAM,
|
||||
'url_encode' => SHORTEN_SERVICE_ENCODE
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
public function settingsForm()
|
||||
@ -61,8 +63,7 @@ class defaultKutrlService extends kutrlService
|
||||
$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))
|
||||
{
|
||||
if (!self::post($this->url_api, $arg, true, true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -74,8 +75,7 @@ class defaultKutrlService extends kutrlService
|
||||
$enc = $this->url_encode ? urlencode($url) : $url;
|
||||
$arg = array($this->url_param => $url);
|
||||
|
||||
if (!($response = self::post($this->url_api,$arg,true,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -88,4 +88,3 @@ class defaultKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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;
|
||||
}
|
||||
|
||||
class googlKutrlService extends kutrlService
|
||||
{
|
||||
@ -20,9 +22,9 @@ class googlKutrlService extends kutrlService
|
||||
|
||||
private $url_api = 'https://www.googleapis.com/urlshortener/v1/url';
|
||||
private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL';
|
||||
private $args = array(
|
||||
private $args = [
|
||||
'key' => 'AIzaSyDE1WfOMdnrnX8p51jSmVodenaNk385asc'
|
||||
);
|
||||
];
|
||||
private $headers = array('Content-Type: application/json');
|
||||
|
||||
protected function init()
|
||||
@ -35,8 +37,7 @@ class googlKutrlService extends kutrlService
|
||||
{
|
||||
$args = $this->args;
|
||||
$args['shortUrl'] = $this->url_base . 'PLovn';
|
||||
if (!($response = self::post($this->url_api,$args,true,true,$this->headers)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $args, true, true, $this->headers))) {
|
||||
$this->error->add(__('Failed to call service.'));
|
||||
return false;
|
||||
}
|
||||
@ -56,8 +57,7 @@ class googlKutrlService extends kutrlService
|
||||
$args['longUrl'] = $url;
|
||||
$args = json_encode($args);
|
||||
|
||||
if (!($response = self::post($this->url_api,$args,true,false,$this->headers)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $args, true, false, $this->headers))) {
|
||||
$this->error->add(__('Failed to call service.'));
|
||||
return false;
|
||||
}
|
||||
@ -77,4 +77,3 @@ class googlKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -14,7 +14,7 @@ if (!defined('DC_RC_PATH')){return;}
|
||||
|
||||
class isgdKutrlService extends kutrlService
|
||||
{
|
||||
protected $config = array(
|
||||
protected $config = [
|
||||
'id' => 'isgd',
|
||||
'name' => 'is.gd',
|
||||
'home' => 'http://is.gd/',
|
||||
@ -22,13 +22,12 @@ class isgdKutrlService extends kutrlService
|
||||
'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))
|
||||
{
|
||||
$arg = ['longurl' => urlencode($this->url_test)];
|
||||
if (!self::post($this->url_api, $arg, true, true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -37,10 +36,9 @@ class isgdKutrlService extends kutrlService
|
||||
|
||||
public function createHash($url, $hash = null)
|
||||
{
|
||||
$arg = array('longurl' => $url);
|
||||
$arg = ['longurl' => $url];
|
||||
|
||||
if (!($response = self::post($this->url_api,$arg,true,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -53,4 +51,3 @@ class isgdKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,22 +10,24 @@
|
||||
# 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(
|
||||
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) ? array() : explode(',',$protocols);
|
||||
$this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols);
|
||||
|
||||
$this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/';
|
||||
$this->config['url_min_len'] = strlen($this->url_base) + 2;
|
||||
@ -48,7 +50,7 @@ class localKutrlService extends kutrlService
|
||||
'<p><strong>' . __('Settings:') . '</strong></p>' .
|
||||
'<p><label class="classic">' .
|
||||
__('Allowed protocols:') . '<br />' .
|
||||
form::field(array('kutrl_srv_local_protocols'),50,255,$this->settings->kutrl_srv_local_protocols).
|
||||
form::field(['kutrl_srv_local_protocols'], 50, 255, $this->settings->kutrl_srv_local_protocols) .
|
||||
'</label></p>' .
|
||||
|
||||
'<p class="form-note">' .
|
||||
@ -56,7 +58,7 @@ class localKutrlService extends kutrlService
|
||||
'</p>' .
|
||||
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox(array('kutrl_srv_local_public'),'1',$this->settings->kutrl_srv_local_public).' '.
|
||||
form::checkbox(['kutrl_srv_local_public'], '1', $this->settings->kutrl_srv_local_public) . ' ' .
|
||||
__('Enable public page for visitors to shorten links') .
|
||||
'</label></p>' .
|
||||
|
||||
@ -66,7 +68,7 @@ class localKutrlService extends kutrlService
|
||||
'<p class="form-note">' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '</p>' .
|
||||
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox(array('kutrl_srv_local_404_active'),'1',$this->settings->kutrl_srv_local_404_active).' '.
|
||||
form::checkbox(['kutrl_srv_local_404_active'], '1', $this->settings->kutrl_srv_local_404_active) . ' ' .
|
||||
__('Enable special 404 error public page for unknow urls') .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' . __('If this is not activated, the default 404 page of the theme will be display.') . '</p>' .
|
||||
@ -81,8 +83,7 @@ class localKutrlService extends kutrlService
|
||||
'<p>' .
|
||||
__("You can use Dotclear's plugin called myUrlHandlers to change short links prefix on your blog.");
|
||||
|
||||
if (preg_match('/index\.php/',$this->url_base))
|
||||
{
|
||||
if (preg_match('/index\.php/', $this->url_base)) {
|
||||
echo
|
||||
'<p>' .
|
||||
__("We recommand that you use a rewrite engine in order to remove 'index.php' from your blog's URL.") .
|
||||
@ -101,11 +102,9 @@ class localKutrlService extends kutrlService
|
||||
public function testService()
|
||||
{
|
||||
$ap = $this->allow_protocols;
|
||||
if (!empty($ap))
|
||||
{
|
||||
if (!empty($ap)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->error->add(__('Service is not well configured.'));
|
||||
return false;
|
||||
}
|
||||
@ -119,34 +118,26 @@ class localKutrlService extends kutrlService
|
||||
$rs->url = $url;
|
||||
|
||||
# Normal link
|
||||
if ($hash === null)
|
||||
{
|
||||
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))
|
||||
{
|
||||
} 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'))
|
||||
{
|
||||
} 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
|
||||
{
|
||||
} else {
|
||||
$this->error->add(__('Custom short link is not valid.'));
|
||||
return false;
|
||||
}
|
||||
@ -155,9 +146,7 @@ class localKutrlService extends kutrlService
|
||||
try {
|
||||
$this->log->insert($rs->url, $rs->hash, $type, $rs->type);
|
||||
return $rs;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
$this->error->add(__('Failed to save link.'));
|
||||
}
|
||||
return false;
|
||||
@ -172,29 +161,21 @@ class localKutrlService extends kutrlService
|
||||
|
||||
protected function next($last_id, $prefix = '')
|
||||
{
|
||||
if ($last_id == -1)
|
||||
{
|
||||
if ($last_id == -1) {
|
||||
$next_id = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for($x = 1; $x <= strlen($last_id); $x++)
|
||||
{
|
||||
} else {
|
||||
for($x = 1; $x <= strlen($last_id); $x++) {
|
||||
$pos = strlen($last_id) - $x;
|
||||
|
||||
if ($last_id[$pos] != 'z')
|
||||
{
|
||||
if ($last_id[$pos] != 'z') {
|
||||
$next_id = $this->increment($last_id, $pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($next_id))
|
||||
{
|
||||
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);
|
||||
@ -203,8 +184,7 @@ class localKutrlService extends kutrlService
|
||||
protected function append($id)
|
||||
{
|
||||
$id = str_split($id);
|
||||
for ($x = 0; $x < count($id); $x++)
|
||||
{
|
||||
for ($x = 0; $x < count($id); $x++) {
|
||||
$id[$x] = 0;
|
||||
}
|
||||
return implode($id) . '0';
|
||||
@ -215,57 +195,43 @@ class localKutrlService extends kutrlService
|
||||
$id = str_split($id);
|
||||
$char = $id[$pos];
|
||||
|
||||
if (is_numeric($char))
|
||||
{
|
||||
if (is_numeric($char)) {
|
||||
$new_char = $char < 9 ? $char + 1 : 'a';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$new_char = chr(ord($char) + 1);
|
||||
}
|
||||
$id[$pos] = $new_char;
|
||||
|
||||
if ($pos != (count($id) - 1))
|
||||
{
|
||||
for ($x = ($pos + 1); $x < count($id); $x++)
|
||||
{
|
||||
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')))
|
||||
{
|
||||
if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) {
|
||||
return false;
|
||||
}
|
||||
if (!$rs->url) //previously removed url
|
||||
{
|
||||
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')))
|
||||
{
|
||||
if (false === ($rs = $this->log->select($url, null, null, 'local'))) {
|
||||
return false;
|
||||
}
|
||||
if ($delete)
|
||||
{
|
||||
if ($delete) {
|
||||
$this->log->delete($rs->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->log->clear($rs->id, '');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,11 +10,13 @@
|
||||
# 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(
|
||||
protected $config = [
|
||||
'id' => 'shortto',
|
||||
'name' => 'short.to',
|
||||
'home' => 'http://short.to',
|
||||
@ -22,13 +24,12 @@ class shorttoKutrlService extends kutrlService
|
||||
'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))
|
||||
{
|
||||
$arg = ['url' => urlencode($this->url_test)];
|
||||
if (!self::post($this->url_api, $arg, true, true)) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -37,10 +38,9 @@ class shorttoKutrlService extends kutrlService
|
||||
|
||||
public function createHash($url, $hash = null)
|
||||
{
|
||||
$arg = array('url' => $url);
|
||||
$arg = ['url' => $url];
|
||||
|
||||
if (!($response = self::post($this->url_api,$arg,true,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
@ -53,4 +53,3 @@ class shorttoKutrlService extends kutrlService
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,22 +10,24 @@
|
||||
# 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(
|
||||
protected $config = [
|
||||
'id' => 'yourls',
|
||||
'name' => 'YOURLS',
|
||||
'home' => 'http://yourls.org'
|
||||
);
|
||||
];
|
||||
|
||||
private $args = array(
|
||||
private $args = [
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'format' => 'xml',
|
||||
'action' => 'shorturl'
|
||||
);
|
||||
];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
@ -52,19 +54,19 @@ class yourlsKutrlService extends kutrlService
|
||||
echo
|
||||
'<p><label class="classic">' .
|
||||
__('Url of the service:') . '<br />' .
|
||||
form::field(array('kutrl_srv_yourls_base'),50,255,$this->settings->kutrl_srv_yourls_base).
|
||||
form::field(['kutrl_srv_yourls_base'], 50, 255, $this->settings->kutrl_srv_yourls_base) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is the URL of the YOURLS service you want to use. Ex: "http://www.smaller.org/api.php".') .
|
||||
'</p>' .
|
||||
'<p><label class="classic">' . __('Login:') . '<br />' .
|
||||
form::field(array('kutrl_srv_yourls_username'),50,255,$this->settings->kutrl_srv_yourls_username).
|
||||
form::field(['kutrl_srv_yourls_username'], 50, 255, $this->settings->kutrl_srv_yourls_username) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is your user name to sign up to this YOURLS service.') .
|
||||
'</p>' .
|
||||
'<p><label class="classic">' . __('Password:') . '<br />' .
|
||||
form::field(array('kutrl_srv_yourls_password'),50,255,$this->settings->kutrl_srv_yourls_password).
|
||||
form::field(['kutrl_srv_yourls_password'], 50, 255, $this->settings->kutrl_srv_yourls_password) .
|
||||
'</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
__('This is your password to sign up to this YOURLS service.') .
|
||||
@ -73,8 +75,7 @@ class yourlsKutrlService extends kutrlService
|
||||
|
||||
public function testService()
|
||||
{
|
||||
if (empty($this->url_api))
|
||||
{
|
||||
if (empty($this->url_api)) {
|
||||
$this->error->add(__('Service is not well configured.'));
|
||||
return false;
|
||||
}
|
||||
@ -82,15 +83,13 @@ class yourlsKutrlService extends kutrlService
|
||||
$args = $this->args;
|
||||
$args['url'] = $this->url_test;
|
||||
|
||||
if (!($response = self::post($this->url_api,$this->args,true)))
|
||||
{
|
||||
if (!($response = self::post($this->url_api, $this->args, true))) {
|
||||
$this->error->add(__('Service is unavailable.'));
|
||||
return false;
|
||||
}
|
||||
$rsp = @simplexml_load_string($response);
|
||||
|
||||
if ($rsp && $rsp->status == 'success')
|
||||
{
|
||||
if ($rsp && $rsp->status == 'success') {
|
||||
return true;
|
||||
}
|
||||
$this->error->add(__('Authentication to service failed.'));
|
||||
@ -102,16 +101,14 @@ class yourlsKutrlService extends kutrlService
|
||||
$args = $this->args;
|
||||
$args['url'] = $url;
|
||||
|
||||
if (!($response = self::post($this->url_api,$args,true)))
|
||||
{
|
||||
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')
|
||||
{
|
||||
if ($rsp && $rsp->status == 'success') {
|
||||
$rs = new ArrayObject();
|
||||
$rs->hash = $rsp->url[0]->keyword;
|
||||
$rs->url = $url;
|
||||
@ -123,4 +120,3 @@ class yourlsKutrlService extends kutrlService
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user