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 | # This file contents class to shorten url pass through wiki |
---|
14 | |
---|
15 | if (!defined('DC_RC_PATH')){return;} |
---|
16 | |
---|
17 | class kutrlWiki |
---|
18 | { |
---|
19 | public static function coreInitWiki($wiki2xhtml) |
---|
20 | { |
---|
21 | global $core; |
---|
22 | $s = kutrlSettings($core); |
---|
23 | |
---|
24 | # Do nothing on comment preview and post preview |
---|
25 | if (!empty($_POST['preview']) |
---|
26 | || !empty($GLOBALS['c_ctx']) && $GLOBALS['c_ctx']->preview) return; |
---|
27 | |
---|
28 | if (!$s->kutrl_active || !$s->kutrl_wiki_service |
---|
29 | || !isset($core->kutrlServices[$s->kutrl_wiki_service])) return; |
---|
30 | |
---|
31 | try { |
---|
32 | $kut = new $core->kutrlServices[$s->kutrl_wiki_service]($core,$s->kutrl_limit_to_blog); |
---|
33 | } |
---|
34 | catch (Exception $e) { |
---|
35 | return; |
---|
36 | } |
---|
37 | |
---|
38 | foreach($kut->allowed_protocols as $protocol) |
---|
39 | { |
---|
40 | $wiki2xhtml->registerFunction( |
---|
41 | 'url:'.$protocol, |
---|
42 | array('kutrlWiki','transform') |
---|
43 | ); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | public static function transform($url,$content) |
---|
48 | { |
---|
49 | global $core; |
---|
50 | $s = kutrlSettings($core); |
---|
51 | |
---|
52 | if (!$s->kutrl_active || !$s->kutrl_wiki_service |
---|
53 | || !isset($core->kutrlServices[$s->kutrl_wiki_service])) return; |
---|
54 | |
---|
55 | try { |
---|
56 | $kut = new $core->kutrlServices[$s->kutrl_wiki_service]($core,$s->kutrl_limit_to_blog); |
---|
57 | } |
---|
58 | catch (Exception $e) { |
---|
59 | return array(); |
---|
60 | } |
---|
61 | |
---|
62 | $rs = $kut->hash($url); |
---|
63 | |
---|
64 | if (!$rs) |
---|
65 | { |
---|
66 | return array(); |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | $res = array(); |
---|
71 | $testurl = strlen($rs->url) > 35 ? substr($rs->url,0,35).'...' : $rs->url; |
---|
72 | $res['url'] = $kut->url_base.$rs->hash; |
---|
73 | $res['title'] = sprintf(__('%s (Shorten with %s)'),$rs->url,__($kut->name)); |
---|
74 | if ($testurl == $content) $res['content'] = $res['url']; |
---|
75 | |
---|
76 | # Send new url by libDcTwitter |
---|
77 | if ($s->kutrl_twit_onwiki) { |
---|
78 | $user = !defined('DC_CONTEXT_ADMIN') ? __('public') : $core->auth->getInfo('user_cn'); |
---|
79 | $twit = libDcTwitter::getMessage('kUtRL'); |
---|
80 | $twit = str_replace(array('%L','%B','%U'),array($res['url'],$core->blog->name,$user),$twit); |
---|
81 | libDcTwitter::sendMessage('kUtRL',$twit); |
---|
82 | } |
---|
83 | |
---|
84 | return $res; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | ?> |
---|