Dotclear

source: plugins/kUtRL/inc/services/class.bilbolinks.service.php @ 2190

Revision 2190, 2.6 KB checked in by JcDenis, 14 years ago (diff)

kUtRL 0.3:

  • Added DC 2.2 compatibility (new settings)
  • Added semi-custom hash on kUtRL service
  • Added status update for Twitter/Identi?.ca on new short link
  • Added services error management (first step)
  • Added options to widgets
  • Upgraded bitly service to v3
  • Changed admin design
Line 
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
13if (!defined('DC_RC_PATH')){return;}
14
15class bilbolinksKutrlService extends kutrlServices
16{
17     public $id = 'bilbolinks';
18     public $name = 'BilboLinks';
19     public $home = 'http://www.tux-planet.fr/bilbobox/';
20
21     private $url_api = '';
22     private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL';
23
24     public function __construct($core,$limit_to_blog=true)
25     {
26          parent::__construct($core,$limit_to_blog);
27
28          $base = (string) $this->s->kutrl_srv_bilbolinks_base;
29          if (!empty($base) && substr($base,-1,1) != '/') $base .= '/';
30
31          $this->url_api = $base.'api.php';
32          $this->url_base = $base;
33          $this->url_min_length = 25;
34     }
35
36     public function saveSettings()
37     {
38          $base = '';
39          if (!empty($_POST['kutrl_srv_bilbolinks_base']))
40          {
41               $base = $_POST['kutrl_srv_bilbolinks_base'];
42               if (substr($base,-1,1) != '/') $base .= '/';
43          }
44
45          $this->s->put('kutrl_srv_bilbolinks_base',$base);
46     }
47
48     public function settingsForm()
49     {
50          echo 
51         '<p><label class="classic">'.
52          __('Url of the service:').'<br />'.
53         form::field(array('kutrl_srv_bilbolinks_base'),50,255,$this->s->kutrl_srv_bilbolinks_base).
54          '</label></p>'.
55         '<p class="form-note">'.
56         __('This is the root URL of the "bilbolinks" service you want to use. Ex: "http://tux-pla.net/".').
57         '</p>';
58     }
59
60     public function testService()
61     {
62          if (empty($this->url_base))
63          {
64               $this->error->add(__('Service is not well configured.'));
65               return false;
66          }
67
68          $arg = array('longurl' => urlencode($this->url_test));
69          if (!self::post($this->url_api,$arg,true,true))
70          {
71               $this->error->add(__('Service is unavailable.'));
72               return false;
73          }
74          return true;
75     }
76
77     public function createHash($url,$hash=null)
78     {
79          $arg = array('longurl' => $url);
80
81          if (!($response = self::post($this->url_api,$arg,true,true)))
82          {
83               $this->error->add(__('Service is unavailable.'));
84               return false;
85          }
86          if ($response == 'You are too speed!')
87          {
88               $this->error->add(__('Service rate limit exceeded.'));
89               return false;
90          }
91
92          $rs = new ArrayObject();
93          $rs->hash = str_replace($this->url_base,'',$response);
94          $rs->url = $url;
95          $rs->type = $this->id;
96
97          return $rs;
98     }
99}
100?>
Note: See TracBrowser for help on using the repository browser.

Sites map