2021-08-25 23:06:22 +00:00
|
|
|
|
<?php
|
|
|
|
|
# -- BEGIN LICENSE BLOCK ----------------------------------
|
2021-08-27 23:53:13 +00:00
|
|
|
|
#
|
2021-08-25 23:06:22 +00:00
|
|
|
|
# This file is part of kUtRL, a plugin for Dotclear 2.
|
|
|
|
|
#
|
2021-08-27 23:53:13 +00:00
|
|
|
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
2021-08-25 23:06:22 +00:00
|
|
|
|
#
|
|
|
|
|
# Licensed under the GPL version 2.0 license.
|
|
|
|
|
# A copy of this license is available in LICENSE file or at
|
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2021-08-27 23:53:13 +00:00
|
|
|
|
#
|
2021-08-25 23:06:22 +00:00
|
|
|
|
# -- END LICENSE BLOCK ------------------------------------
|
|
|
|
|
|
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
|
|
|
|
|
# cela permet de configurer ces constantes dans le fichier
|
|
|
|
|
# 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 = [
|
|
|
|
|
'id' => 'default',
|
|
|
|
|
'name' => 'Default',
|
|
|
|
|
'home' => '',
|
|
|
|
|
|
|
|
|
|
'url_api' => SHORTEN_SERVICE_API,
|
|
|
|
|
'url_base' => SHORTEN_SERVICE_BASE,
|
|
|
|
|
'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2,
|
|
|
|
|
|
|
|
|
|
'url_param' => SHORTEN_SERVICE_PARAM,
|
|
|
|
|
'url_encode' => SHORTEN_SERVICE_ENCODE
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function settingsForm()
|
|
|
|
|
{
|
|
|
|
|
echo
|
|
|
|
|
'<p class="form-note">' .
|
|
|
|
|
__('There is nothing to configure for this service.') .
|
|
|
|
|
'</p>' .
|
|
|
|
|
'<p>' . __('This service is set to:') . '</p>' .
|
|
|
|
|
'<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>' .
|
|
|
|
|
'</dl>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testService()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->url_encode ? urlencode($this->url_test) : $this->url_test;
|
|
|
|
|
$arg = array($this->url_param => urlencode($this->url_test));
|
|
|
|
|
|
|
|
|
|
if (!self::post($this->url_api, $arg, true, true)) {
|
|
|
|
|
$this->error->add(__('Service is unavailable.'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createHash($url, $hash = null)
|
|
|
|
|
{
|
|
|
|
|
$enc = $this->url_encode ? urlencode($url) : $url;
|
|
|
|
|
$arg = array($this->url_param => $url);
|
|
|
|
|
|
|
|
|
|
if (!($response = self::post($this->url_api, $arg, true, true))) {
|
|
|
|
|
$this->error->add(__('Service is unavailable.'));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rs = new ArrayObject();
|
|
|
|
|
$rs->hash = str_replace($this->url_base, '', $response);
|
|
|
|
|
$rs->url = $url;
|
|
|
|
|
$rs->type = $this->id;
|
|
|
|
|
|
|
|
|
|
return $rs;
|
|
|
|
|
}
|
|
|
|
|
}
|