'yourls', 'name' => 'YOURLS', 'home' => 'http://yourls.org', ]; private $args = [ 'username' => '', 'password' => '', 'format' => 'xml', 'action' => 'shorturl', ]; protected function init() { $this->args['username'] = $this->settings->get('srv_yourls_username'); $this->args['password'] = $this->settings->get('srv_yourls_password'); $base = (string) $this->settings->get('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('srv_yourls_username', $_POST['kutrl_srv_yourls_username']); $this->settings->put('srv_yourls_password', $_POST['kutrl_srv_yourls_password']); $this->settings->put('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 = array_merge($this->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; } }