diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6cd993f..b83440b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@ xxx.xx.xx
- [ ] Add public page of the list of know urls and in/visible status
- [ ] Add passworded links
- [ ] fix deprecated external service
-- [ ] update php header to phpdoc style
+- [x] update php header to phpdoc style
- [x] fix post page options display
2021.08.28 - pre release
diff --git a/_admin.php b/_admin.php
index 8c7e801..20eff0b 100644
--- a/_admin.php
+++ b/_admin.php
@@ -1,15 +1,15 @@
blog->settings->kUtRL;
-
+
if (!$s->kutrl_active || !$s->kutrl_admin_service) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) {
return null;
}
-
+
if ($post) {
$post_url = $post->getURL();
$rs = $kut->isKnowUrl($post_url);
@@ -136,7 +136,7 @@ class adminKutrl
{
global $core;
$s = $core->blog->settings->kUtRL;
-
+
# Create: see adminAfterPostCreate
if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) {
return null;
@@ -160,7 +160,7 @@ class adminKutrl
}
$title = html::escapeHTML($rs->post_title);
$new_post_url = $rs->getURL();
-
+
# Delete
if (!empty($_POST['kutrl_delete'])) {
$kut->remove($old_post_url);
@@ -216,7 +216,7 @@ class adminKutrl
{
global $core;
$s = $core->blog->settings->kUtRL;
-
+
if (!$s->kutrl_active) {
return null;
}
diff --git a/_define.php b/_define.php
index e4e1a48..f13cbde 100644
--- a/_define.php
+++ b/_define.php
@@ -1,15 +1,15 @@
blog->settings->kUtRL;
-
+
# Not active, go to default 404
if (!$s->kutrl_active) {
self::p404();
@@ -215,7 +215,7 @@ class urlKutrl extends dcUrlHandlers
protected static function kutrl404()
{
global $core;
-
+
if (!$core->blog->settings->kUtRL->kutrl_srv_local_404_active) {
self::p404();
return null;
@@ -348,7 +348,7 @@ class tplKutrl
public static function pageIf($attr, $content)
{
$operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&';
-
+
if (isset($attr['is_active'])) {
$sign = (boolean) $attr['is_active'] ? '' : '!';
$if[] = $sign . '$core->blog->settings->kUtRL->kutrl_srv_local_public';
@@ -511,7 +511,7 @@ class tplKutrl
" if (!empty(\$kutrl_rs)) { " .
" \$core->callBehavior('publicAfterKutrlCreate',\$core,\$kutrl_rs,__('New public short URL')); " .
" } \n" .
-
+
" } \n" .
" unset(\$kutrl_rs); \n" .
"} \n" .
diff --git a/_uninstall.php b/_uninstall.php
index aafd684..f338ee8 100644
--- a/_uninstall.php
+++ b/_uninstall.php
@@ -1,15 +1,15 @@
addUserAction(
/* description */ __('delete the version number')
);
-
# Delete only dc version and plugin files from pluginsBeforeDelete
# Keep table
diff --git a/_widgets.php b/_widgets.php
index b0ca9c2..ae3716e 100644
--- a/_widgets.php
+++ b/_widgets.php
@@ -1,15 +1,15 @@
blog->settings->kUtRL;
-
+
if (!$s->kutrl_active
|| !$s->kutrl_srv_local_public
|| ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 2 && $core->url->isHome($core->url->type))
@@ -177,7 +177,7 @@ class widgetKutrl
$order .= $w->sort == 'desc' ? ' DESC' : ' ASC';
$limit = $core->con->limit(abs((integer) $w->limit));
-
+
$rs = $core->con->select(
'SELECT kut_counter, kut_hash ' .
"FROM " . $core->prefix . "kutrl " .
@@ -195,7 +195,7 @@ class widgetKutrl
while($rs->fetch()) {
$i++;
$rank = '' . $i . '';
-
+
$hash = $rs->kut_hash;
$url = $core->blog->url . $core->url->getBase('kutrl') . '/' . $hash;
$cut_len = - abs((integer) $w->urllen);
@@ -227,7 +227,7 @@ class widgetKutrl
) .
'';
}
-
+
if (empty($content)) {
return null;
}
diff --git a/dcstore.xml b/dcstore.xml
index 928e6ca..32ae32a 100644
--- a/dcstore.xml
+++ b/dcstore.xml
@@ -5,9 +5,7 @@
' . __('Settings:') . '
' . '' . __('Note:') . '
' . '' .
__('This service use your own Blog to shorten and serve URL.') . '
' .
@@ -96,7 +96,7 @@ class localKutrlService extends kutrlService
'
' . __('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.') . '
'. - 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']). - '
'; - } - - public function testService() - { - if (empty($this->args['login']) || empty($this->args['apiKey'])) - { - $this->error->add(__('Service is not well configured.')); - return false; - } + protected $config = array( + 'id' => 'supr', + 'name' => 'su.pr StumbleUpon', + 'home' => 'http://su.pr', - $args = $this->args; - $arg['longUrl'] = $this->url_test; - if (!($response = self::post($this->url_api.'shorten',$args,true))) - { - $this->error->add(__('Failed to call service.')); - return false; - } - - $rsp = simplexml_load_string($response); - - $status = (string) $rsp->statusCode; - if ($status != 'OK') { - $err_no = (integer) $rsp->errorCode; - $err_msg = (integer) $rsp->errorMessage; - $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); - - $status = (string) $rsp->statusCode; - if ($status != 'OK') { - $err_no = (integer) $rsp->errorCode; - $err_msg = (integer) $rsp->errorMessage; - $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->results[0]->nodeKeyVal->hash; - $rs->url = (string) $rsp->results[0]->nodeKeyVal->nodeKey; - $rs->type = $this->id; - - return $rs; - } -} -?> \ No newline at end of file + 'url_api' => 'http://su.pr/api/', + 'url_base' => 'http://su.pr/', + 'url_min_len' => 23 + ); + + private $args = array( + 'version' => '1.0', + 'format' => 'xml', + 'login' => '', + 'apiKey' => '' + ); + + protected function init() + { + $this->args['login'] = $this->settings->kutrl_srv_supr_login; + $this->args['apiKey'] = $this->settings->kutrl_srv_supr_apikey; + } + + public function saveSettings() + { + $this->settings->put('kutrl_srv_supr_login',$_POST['kutrl_srv_supr_login']); + $this->settings->put('kutrl_srv_supr_apikey',$_POST['kutrl_srv_supr_apikey']); + } + + 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']). + '
'; + } + + 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; + $arg['longUrl'] = $this->url_test; + if (!($response = self::post($this->url_api.'shorten',$args,true))) + { + $this->error->add(__('Failed to call service.')); + return false; + } + + $rsp = simplexml_load_string($response); + + $status = (string) $rsp->statusCode; + if ($status != 'OK') { + $err_no = (integer) $rsp->errorCode; + $err_msg = (integer) $rsp->errorMessage; + $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); + + $status = (string) $rsp->statusCode; + if ($status != 'OK') { + $err_no = (integer) $rsp->errorCode; + $err_msg = (integer) $rsp->errorMessage; + $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->results[0]->nodeKeyVal->hash; + $rs->url = (string) $rsp->results[0]->nodeKeyVal->nodeKey; + $rs->type = $this->id; + + return $rs; + } +} \ No newline at end of file diff --git a/inc/services/class.trim.service.php b/inc/services/class.trim.service.php index 2e3c87c..67f3c00 100644 --- a/inc/services/class.trim.service.php +++ b/inc/services/class.trim.service.php @@ -1,127 +1,126 @@ 'trim', - 'name' => 'tr.im', - 'home' => 'http://tr.im', - - 'url_api' => 'http://api.tr.im/v1/', - 'url_base' => 'http://tr.im/', - 'url_min_len' => 25 - ); - - private $args = array( - 'username' => '', - 'password' => '' - ); - - private $api_rate_time = 0; - - protected function init() - { - $this->args['username'] = $this->settings->kutrl_srv_trim_username; - $this->args['password'] = $this->settings->kutrl_srv_trim_password; - - $this->api_rate_time = (integer) $this->settings->kutrl_srv_trim_apiratetime; - } - - public function saveSettings() - { - $this->settings->put('kutrl_srv_trim_username',$_POST['kutrl_srv_trim_username']); - $this->settings->put('kutrl_srv_trim_password',$_POST['kutrl_srv_trim_password']); - } - - public function settingsForm() - { - echo - ''. - ''. - __('This is your login to sign up to tr.im.'). - '
'. - ''. - ''. - __('This is your password to sign up to tr.im.'). - '
'; - } - - public function testService() - { - if (empty($this->args['username']) || empty($this->args['password'])) - { - $this->error->add(__('Service is not well configured.')); - return false; - } - if (time() < $this->api_rate_time + 300) // bloc service within 5min on API rate limit - { - $this->error->add(__('Prevent service rate limit.')); - return false; - } - if (!($rsp = self::post($this->url_api.'verify.xml',$this->args,true,true))) - { - $this->error->add(__('Service is unavailable.')); - return false; - } - $r = simplexml_load_string($rsp); - - if ($r['code'] == 200) - { - return true; - } - $this->error->add(__('Authentication to service failed.')); - return false; - } - - public function createHash($url,$hash=null) - { - $arg = $this->args; - $arg['url'] = $url; - - if (!($rsp = self::post($this->url_api.'trim_url.xml',$arg,true,true))) - { - $this->error->add(__('Service is unavailable.')); - return false; - } - - $r = simplexml_load_string($rsp); - - # API rate limit - if ($r['code'] == 425) - { - $this->settings->put('kutrl_srv_trim_apiratetime',time()); + protected $config = array( + 'id' => 'trim', + 'name' => 'tr.im', + 'home' => 'http://tr.im', - $this->error->add(__('Service rate limit exceeded.')); - return false; - } - if (isset($r->trimpath)) - { - $rs = new ArrayObject(); - $rs->hash = $r->trimpath; - $rs->url = $url; - $rs->type = $this->id; - - return $rs; - } - $this->error->add(__('Unreadable service response.')); - return false; - } -} -?> \ No newline at end of file + 'url_api' => 'http://api.tr.im/v1/', + 'url_base' => 'http://tr.im/', + 'url_min_len' => 25 + ); + + private $args = array( + 'username' => '', + 'password' => '' + ); + + private $api_rate_time = 0; + + protected function init() + { + $this->args['username'] = $this->settings->kutrl_srv_trim_username; + $this->args['password'] = $this->settings->kutrl_srv_trim_password; + + $this->api_rate_time = (integer) $this->settings->kutrl_srv_trim_apiratetime; + } + + public function saveSettings() + { + $this->settings->put('kutrl_srv_trim_username',$_POST['kutrl_srv_trim_username']); + $this->settings->put('kutrl_srv_trim_password',$_POST['kutrl_srv_trim_password']); + } + + public function settingsForm() + { + echo + ''. + ''. + __('This is your login to sign up to tr.im.'). + '
'. + ''. + ''. + __('This is your password to sign up to tr.im.'). + '
'; + } + + public function testService() + { + if (empty($this->args['username']) || empty($this->args['password'])) + { + $this->error->add(__('Service is not well configured.')); + return false; + } + if (time() < $this->api_rate_time + 300) // bloc service within 5min on API rate limit + { + $this->error->add(__('Prevent service rate limit.')); + return false; + } + if (!($rsp = self::post($this->url_api.'verify.xml',$this->args,true,true))) + { + $this->error->add(__('Service is unavailable.')); + return false; + } + $r = simplexml_load_string($rsp); + + if ($r['code'] == 200) + { + return true; + } + $this->error->add(__('Authentication to service failed.')); + return false; + } + + public function createHash($url,$hash=null) + { + $arg = $this->args; + $arg['url'] = $url; + + if (!($rsp = self::post($this->url_api.'trim_url.xml',$arg,true,true))) + { + $this->error->add(__('Service is unavailable.')); + return false; + } + + $r = simplexml_load_string($rsp); + + # API rate limit + if ($r['code'] == 425) + { + $this->settings->put('kutrl_srv_trim_apiratetime',time()); + + $this->error->add(__('Service rate limit exceeded.')); + return false; + } + if (isset($r->trimpath)) + { + $rs = new ArrayObject(); + $rs->hash = $r->trimpath; + $rs->url = $url; + $rs->type = $this->id; + + return $rs; + } + $this->error->add(__('Unreadable service response.')); + return false; + } +} \ No newline at end of file diff --git a/inc/services/class.yourls.service.php b/inc/services/class.yourls.service.php index 05eb5da..57dda33 100644 --- a/inc/services/class.yourls.service.php +++ b/inc/services/class.yourls.service.php @@ -1,15 +1,15 @@ 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; @@ -80,16 +80,16 @@ class yourlsKutrlService extends kutrlService $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; } diff --git a/index.php b/index.php index 2c8d4c4..bd4b402 100644 --- a/index.php +++ b/index.php @@ -1,15 +1,15 @@ con->escape($_POST['str'])); $hash = empty($_POST['custom']) ? null : $_POST['custom']; - + if (empty($url)) { throw new Exception(__('There is nothing to shorten.')); } @@ -257,7 +257,7 @@ if ($part == 'links') { } $o->remove($rs->kut_url); } - + $core->blog->triggerBlog(); dcPage::addSuccessNotice( @@ -408,7 +408,7 @@ if ($part == 'service') { foreach(kutrl::getServices($core) as $service_id => $service) { $o = new $service($core); - + echo '