2021-08-25 23:06:22 +00:00
|
|
|
<?php
|
2021-09-02 12:32:26 +00:00
|
|
|
/**
|
|
|
|
* @brief kUtRL, a plugin for Dotclear 2
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-08-27 23:52:03 +00:00
|
|
|
if (!defined('DC_RC_PATH')) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-08-25 23:06:22 +00:00
|
|
|
|
|
|
|
class bilbolinksKutrlService extends kutrlService
|
|
|
|
{
|
2021-08-27 23:52:03 +00:00
|
|
|
protected $config = [
|
2021-10-26 21:03:38 +00:00
|
|
|
'id' => 'bilbolinks',
|
2021-08-27 23:52:03 +00:00
|
|
|
'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 .= '/';
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
$this->config['url_api'] = $base . 'api.php';
|
|
|
|
$this->config['url_base'] = $base;
|
2021-08-27 23:52:03 +00:00
|
|
|
$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()
|
|
|
|
{
|
2021-11-06 15:43:02 +00:00
|
|
|
echo
|
2021-08-27 23:52:03 +00:00
|
|
|
'<p><label class="classic">' .
|
|
|
|
__('Url of the service:') . '<br />' .
|
|
|
|
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/".') .
|
|
|
|
'</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testService()
|
|
|
|
{
|
|
|
|
if (empty($this->url_base)) {
|
|
|
|
$this->error->add(__('Service is not well configured.'));
|
2021-10-26 21:03:38 +00:00
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$arg = ['longurl' => urlencode($this->url_test)];
|
2021-11-06 15:43:02 +00:00
|
|
|
if (!self::post($this->url_api, $arg, true, true)) {
|
2021-08-27 23:52:03 +00:00
|
|
|
$this->error->add(__('Service is unavailable.'));
|
2021-10-26 21:03:38 +00:00
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-10-26 21:03:38 +00:00
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
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.'));
|
2021-10-26 21:03:38 +00:00
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($response == 'You are too speed!') {
|
|
|
|
$this->error->add(__('Service rate limit exceeded.'));
|
2021-10-26 21:03:38 +00:00
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
$rs = new ArrayObject();
|
2021-08-27 23:52:03 +00:00
|
|
|
$rs->hash = str_replace($this->url_base, '', $response);
|
2021-10-26 21:03:38 +00:00
|
|
|
$rs->url = $url;
|
2021-08-27 23:52:03 +00:00
|
|
|
$rs->type = $this->id;
|
|
|
|
|
|
|
|
return $rs;
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
}
|