kUtRL/inc/services/class.shortto.service.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2021-08-25 23:06:22 +00:00
<?php
/**
* @brief kUtRL, a plugin for Dotclear 2
2021-11-06 15:43:02 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:43:02 +00:00
*
* @author Jean-Christian Denis and contributors
2021-11-06 15:43:02 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
2021-08-25 23:06:22 +00:00
class shorttoKutrlService extends kutrlService
{
protected $config = [
2022-12-22 14:37:09 +00:00
'id' => 'shortto',
'name' => 'short.to',
'home' => 'http://short.to',
2021-11-06 15:43:02 +00:00
'url_api' => 'http://short.to/s.txt',
'url_base' => 'http://short.to/',
2022-11-20 16:15:36 +00:00
'url_min_len' => 25,
];
public function testService()
{
$arg = ['url' => urlencode($this->url_test)];
if (!self::post($this->url_api, $arg, true, true)) {
$this->error->add(__('Service is unavailable.'));
2021-11-06 15:43:02 +00:00
return false;
}
2021-11-06 15:43:02 +00:00
return true;
}
public function createHash($url, $hash = null)
{
$arg = ['url' => $url];
if (!($response = self::post($this->url_api, $arg, true, true))) {
$this->error->add(__('Service is unavailable.'));
2021-11-06 15:43:02 +00:00
return false;
}
2021-11-06 15:43:02 +00:00
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
2021-11-06 15:43:02 +00:00
$rs->url = $url;
$rs->type = $this->id;
return $rs;
}
2021-11-06 15:43:02 +00:00
}