1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of kUtRL, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2010 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')){return;} |
---|
14 | |
---|
15 | class shorttoKutrlService extends kutrlServices |
---|
16 | { |
---|
17 | public $core; |
---|
18 | |
---|
19 | public $id = 'shortto'; |
---|
20 | public $name = 'short.to'; |
---|
21 | public $home = 'http://short.to'; |
---|
22 | |
---|
23 | private $url_api = 'http://short.to/s.txt'; |
---|
24 | private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; |
---|
25 | |
---|
26 | public function __construct($core,$limit_to_blog=true) |
---|
27 | { |
---|
28 | parent::__construct($core,$limit_to_blog); |
---|
29 | |
---|
30 | $this->url_base = 'http://short.to/'; |
---|
31 | $this->url_min_length = 25; |
---|
32 | } |
---|
33 | |
---|
34 | public function testService() |
---|
35 | { |
---|
36 | $arg = array('url' => urlencode($this->url_test)); |
---|
37 | if (!self::post($this->url_api,$arg,true,true)) |
---|
38 | { |
---|
39 | $this->error->add(__('Service is unavailable.')); |
---|
40 | return false; |
---|
41 | } |
---|
42 | return true; |
---|
43 | } |
---|
44 | |
---|
45 | public function createHash($url,$hash=null) |
---|
46 | { |
---|
47 | $arg = array('url' => $url); |
---|
48 | |
---|
49 | if (!($response = self::post($this->url_api,$arg,true,true))) |
---|
50 | { |
---|
51 | $this->error->add(__('Service is unavailable.')); |
---|
52 | return false; |
---|
53 | } |
---|
54 | |
---|
55 | $rs = new ArrayObject(); |
---|
56 | $rs->hash = str_replace($this->url_base,'',$response); |
---|
57 | $rs->url = $url; |
---|
58 | $rs->type = $this->id; |
---|
59 | |
---|
60 | return $rs; |
---|
61 | } |
---|
62 | } |
---|
63 | ?> |
---|