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 @@ Jean-Christian Denis and contributors Use, create and serve short url on your blog https://github.com/JcDenis/kUtRL/releases/download/v2021.08.28/plugin-kUtRL.zip -2.19 http://plugins.dotaddict.org/dc2/details/kUtRL - https://github.com/JcDenis/kUtRL \ No newline at end of file diff --git a/inc/class.kutrl.php b/inc/class.kutrl.php index 9cc0fce..2484834 100644 --- a/inc/class.kutrl.php +++ b/inc/class.kutrl.php @@ -1,15 +1,15 @@ kut_url = ''; $cur->kut_dt = date('Y-m-d H:i:s'); $cur->kut_counter = 0; - + $cur->update( "WHERE blog_id='" . $this->blog . "' " . "AND kut_id='" . $id . "' " @@ -180,7 +180,7 @@ class kutrlLog $r = 'SELECT count(S.kut_id) '; } else { $content_req = ''; - + if (!empty($p['columns']) && is_array($p['columns'])) { $content_req .= implode(', ', $p['columns']) . ', '; } diff --git a/inc/lib.kutrl.lst.php b/inc/lib.kutrl.lst.php index 0f9a97c..9a4c714 100644 --- a/inc/lib.kutrl.lst.php +++ b/inc/lib.kutrl.lst.php @@ -1,15 +1,15 @@ parseRecords()) { - try - { - $core->plugins->deactivateModule('dcMiniUrl'); - } - catch (Exception $e) - { - //$core->error->add($e->getMessage()); - } + try + { + $core->plugins->deactivateModule('dcMiniUrl'); + } + catch (Exception $e) + { + //$core->error->add($e->getMessage()); + } } class dcMiniUrl2kUtRL { - public $core; - - public $k_tb; - public $m_tb; + public $core; - public function __construct($core) - { - $this->core = $core; - $this->con = $core->con; - $this->k_tb = $core->prefix.'kutrl'; - $this->m_tb = $core->prefix.'miniurl'; - } - - public function parseRecords() - { - $rs = $this->con->select( - 'SELECT * FROM '.$this->m_tb.' ' - ); + public $k_tb; + public $m_tb; - while ($rs->fetch()) - { - if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') - { - if ($this->exists($rs)) continue; + public function __construct($core) + { + $this->core = $core; + $this->con = $core->con; + $this->k_tb = $core->prefix.'kutrl'; + $this->m_tb = $core->prefix.'miniurl'; + } - $this->insertKutrl($rs); - $this->insertLocal($rs); - } - else - { - $this->insertOther($rs); - } - } - return true; - } + public function parseRecords() + { + $rs = $this->con->select( + 'SELECT * FROM '.$this->m_tb.' ' + ); - private function insertKutrl($rs) - { - $cur = $this->common($rs); - $cur->kut_service = 'kutrl'; - $cur->kut_type = 'local'; - $cur->kut_counter = 0; - $cur->kut_password = null; + while ($rs->fetch()) + { + if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') + { + if ($this->exists($rs)) continue; - $cur->insert(); - $this->con->unlock(); - } + $this->insertKutrl($rs); + $this->insertLocal($rs); + } + else + { + $this->insertOther($rs); + } + } + return true; + } - private function insertLocal($rs) - { - $cur = $this->common($rs); - $cur->kut_service = 'local'; - $cur->kut_type = $rs->miniurl_type == 'customurl' ? - 'localcustom' : 'localnormal'; + private function insertKutrl($rs) + { + $cur = $this->common($rs); + $cur->kut_service = 'kutrl'; + $cur->kut_type = 'local'; + $cur->kut_counter = 0; + $cur->kut_password = null; - $cur->insert(); - $this->con->unlock(); - } + $cur->insert(); + $this->con->unlock(); + } - private function insertOther($rs) - { - $cur = $this->common($rs); + private function insertLocal($rs) + { + $cur = $this->common($rs); + $cur->kut_service = 'local'; + $cur->kut_type = $rs->miniurl_type == 'customurl' ? + 'localcustom' : 'localnormal'; - $cur->insert(); - $this->con->unlock(); - } + $cur->insert(); + $this->con->unlock(); + } - private function common($rs) - { - $cur = $this->con->openCursor($this->k_tb); - $this->con->writeLock($this->k_tb); - $cur->kut_id = $this->nextId(); - $cur->blog_id = $rs->blog_id; - $cur->kut_service = 'unknow'; - $cur->kut_type = $rs->miniurl_type; - $cur->kut_hash = $rs->miniurl_id; - $cur->kut_url = $rs->miniurl_str; - $cur->kut_dt = $rs->miniurl_dt; - $cur->kut_counter = $rs->miniurl_counter; - $cur->kut_password = $rs->miniurl_password; - - return $cur; - } + private function insertOther($rs) + { + $cur = $this->common($rs); - private function exists($rs) - { - $chk = $this->con->select( - 'SELECT kut_hash FROM '.$this->k_tb.' '. - "WHERE blog_id = '".$rs->blog_id."' ". - "AND kut_service = 'local' ". - "AND kut_hash = '".$rs->miniurl_id."' " - ); - return !$chk->isEmpty(); - } - - private function nextId() - { - return $this->con->select( - 'SELECT MAX(kut_id) FROM '.$this->k_tb.' ' - )->f(0) + 1; - } -} -?> \ No newline at end of file + $cur->insert(); + $this->con->unlock(); + } + + private function common($rs) + { + $cur = $this->con->openCursor($this->k_tb); + $this->con->writeLock($this->k_tb); + $cur->kut_id = $this->nextId(); + $cur->blog_id = $rs->blog_id; + $cur->kut_service = 'unknow'; + $cur->kut_type = $rs->miniurl_type; + $cur->kut_hash = $rs->miniurl_id; + $cur->kut_url = $rs->miniurl_str; + $cur->kut_dt = $rs->miniurl_dt; + $cur->kut_counter = $rs->miniurl_counter; + $cur->kut_password = $rs->miniurl_password; + + return $cur; + } + + private function exists($rs) + { + $chk = $this->con->select( + 'SELECT kut_hash FROM '.$this->k_tb.' '. + "WHERE blog_id = '".$rs->blog_id."' ". + "AND kut_service = 'local' ". + "AND kut_hash = '".$rs->miniurl_id."' " + ); + return !$chk->isEmpty(); + } + + private function nextId() + { + return $this->con->select( + 'SELECT MAX(kut_id) FROM '.$this->k_tb.' ' + )->f(0) + 1; + } +} \ No newline at end of file diff --git a/inc/services/class.bilbolinks.service.php b/inc/services/class.bilbolinks.service.php index eb4b490..6c2f860 100644 --- a/inc/services/class.bilbolinks.service.php +++ b/inc/services/class.bilbolinks.service.php @@ -1,15 +1,15 @@ 'bitly', 'name' => 'bit.ly', 'home' => 'http://bit.ly', - + 'url_api' => 'http://api.bit.ly/v3/', 'url_base' => 'http://bit.ly/', 'url_min_len' => 25 diff --git a/inc/services/class.custom.service.php b/inc/services/class.custom.service.php index 5ca17c9..afd7a2d 100644 --- a/inc/services/class.custom.service.php +++ b/inc/services/class.custom.service.php @@ -1,15 +1,15 @@ 'custom', 'name' => 'Custom' ]; - + protected function init() { $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); @@ -29,12 +29,12 @@ class customKutrlService extends kutrlService { $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; } diff --git a/inc/services/class.default.service.php b/inc/services/class.default.service.php index a8c686b..2845b55 100644 --- a/inc/services/class.default.service.php +++ b/inc/services/class.default.service.php @@ -1,15 +1,15 @@ SHORTEN_SERVICE_ENCODE ]; } - + public function settingsForm() { echo diff --git a/inc/services/class.googl.service.php b/inc/services/class.googl.service.php index 95523d1..02dd284 100644 --- a/inc/services/class.googl.service.php +++ b/inc/services/class.googl.service.php @@ -1,15 +1,15 @@ '' ]; private $headers = array('Content-Type: application/json'); - + protected function init() { $this->url_base = 'http://goo.gl/'; diff --git a/inc/services/class.isgd.service.php b/inc/services/class.isgd.service.php index a040f93..59a2b49 100644 --- a/inc/services/class.isgd.service.php +++ b/inc/services/class.isgd.service.php @@ -1,15 +1,15 @@ '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)]; diff --git a/inc/services/class.local.service.php b/inc/services/class.local.service.php index 31204ef..cb4462c 100644 --- a/inc/services/class.local.service.php +++ b/inc/services/class.local.service.php @@ -1,15 +1,15 @@ 'local', 'name' => 'kUtRL', 'home' => 'http://kutrl.fr', - + 'allow_custom_hash' => true ]; - + protected function init() { $protocols = (string) $this->settings->kutrl_srv_local_protocols; @@ -32,9 +32,9 @@ class localKutrlService extends kutrlService $this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/'; $this->config['url_min_len'] = strlen($this->url_base) + 2; - + } - + public function saveSettings() { $this->settings->put('kutrl_srv_local_protocols', $_POST['kutrl_srv_local_protocols'], 'string'); @@ -47,7 +47,7 @@ class localKutrlService extends kutrlService { echo '
' . - + '

' . __('Settings:') . '

' . '

' . __('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.') . '
' . @@ -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.') . '

' . - + '

'; } @@ -181,7 +181,7 @@ class localKutrlService extends kutrlService 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); @@ -210,7 +210,7 @@ class localKutrlService extends kutrlService } return implode($id); } - + public function getUrl($hash) { if (false === ($rs = $this->log->select(null, $hash, null, 'local'))) { diff --git a/inc/services/class.shortto.service.php b/inc/services/class.shortto.service.php index 23bbb58..b24575a 100644 --- a/inc/services/class.shortto.service.php +++ b/inc/services/class.shortto.service.php @@ -1,15 +1,15 @@ 'supr', - 'name' => 'su.pr StumbleUpon', - 'home' => 'http://su.pr', - - '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; - } + 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 '

' . $o->name . '

'; if (!empty($_POST['save'])) { @@ -458,7 +458,7 @@ if ($part == 'link') {

' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '