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
|
|
|
|
|
|
|
|
|
# nb: "default" ne veut pas dire service par d<>faut
|
|
|
|
|
# mais service simple et rapide configur<75> par des constantes
|
2021-11-06 15:43:02 +00:00
|
|
|
|
# cela permet de configurer ces constantes dans le fichier
|
2021-08-25 23:06:22 +00:00
|
|
|
|
# config de Dotclear pour une plateforme compl<70>te.
|
|
|
|
|
|
|
|
|
|
class defaultKutrlService extends kutrlService
|
|
|
|
|
{
|
2021-08-27 23:52:03 +00:00
|
|
|
|
protected function init()
|
|
|
|
|
{
|
|
|
|
|
$this->config = [
|
2021-11-06 15:43:02 +00:00
|
|
|
|
'id' => 'default',
|
|
|
|
|
'name' => 'Default',
|
|
|
|
|
'home' => '',
|
2021-08-27 23:52:03 +00:00
|
|
|
|
|
2021-10-26 21:03:38 +00:00
|
|
|
|
'url_api' => SHORTEN_SERVICE_API,
|
|
|
|
|
'url_base' => SHORTEN_SERVICE_BASE,
|
2021-08-27 23:52:03 +00:00
|
|
|
|
'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2,
|
|
|
|
|
|
2021-11-06 15:43:02 +00:00
|
|
|
|
'url_param' => SHORTEN_SERVICE_PARAM,
|
2022-11-20 16:15:36 +00:00
|
|
|
|
'url_encode' => SHORTEN_SERVICE_ENCODE,
|
2021-08-27 23:52:03 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
2021-09-02 12:32:26 +00:00
|
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
|
public function settingsForm()
|
|
|
|
|
{
|
2021-11-06 15:43:02 +00:00
|
|
|
|
echo
|
2021-08-27 23:52:03 +00:00
|
|
|
|
'<p class="form-note">' .
|
|
|
|
|
__('There is nothing to configure for this service.') .
|
2021-11-06 15:43:02 +00:00
|
|
|
|
'</p>' .
|
2021-08-27 23:52:03 +00:00
|
|
|
|
'<p>' . __('This service is set to:') . '</p>' .
|
2021-11-06 15:43:02 +00:00
|
|
|
|
'<dl>' .
|
|
|
|
|
'<dt>' . __('Service name:') . '</dt>' .
|
|
|
|
|
'<dd>' . SHORTEN_SERVICE_NAME . '</dd>' .
|
|
|
|
|
'<dt>' . __('Full API URL:') . '</dt>' .
|
|
|
|
|
'<dd>' . SHORTEN_SERVICE_API . '</dd>' .
|
|
|
|
|
'<dt>' . __('Query param:') . '</dt>' .
|
|
|
|
|
'<dd>' . SHORTEN_SERVICE_PARAM . '</dd>' .
|
|
|
|
|
'<dt>' . __('Short URL domain:') . '</dt>' .
|
|
|
|
|
'<dd>' . SHORTEN_SERVICE_BASE . '</dd>' .
|
|
|
|
|
'<dt>' . __('Encode URL:') . '</dt>' .
|
|
|
|
|
'<dd>' . (SHORTEN_SERVICE_ENCODE ? __('yes') : __('no')) . '</dd>' .
|
2021-08-27 23:52:03 +00:00
|
|
|
|
'</dl>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testService()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->url_encode ? urlencode($this->url_test) : $this->url_test;
|
2021-10-26 21:03:38 +00:00
|
|
|
|
$arg = [$this->url_param => urlencode($this->url_test)];
|
2021-08-27 23:52:03 +00:00
|
|
|
|
|
|
|
|
|
if (!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;
|
|
|
|
|
}
|
2021-10-26 21:03:38 +00:00
|
|
|
|
|
2021-08-27 23:52:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createHash($url, $hash = null)
|
|
|
|
|
{
|
|
|
|
|
$enc = $this->url_encode ? urlencode($url) : $url;
|
2021-10-26 21:03:38 +00:00
|
|
|
|
$arg = [$this->url_param => $url];
|
2021-08-27 23:52:03 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|