1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of kUtRL, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 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 kutrlWiki |
---|
16 | { |
---|
17 | public static function coreInitWiki($wiki2xhtml) |
---|
18 | { |
---|
19 | global $core; |
---|
20 | |
---|
21 | $_active = (boolean) $core->blog->settings->kutrl_active; |
---|
22 | $_wiki_service = (string) $core->blog->settings->kutrl_wiki_service; |
---|
23 | $_limit_to_blog = (boolean) $core->blog->settings->kutrl_limit_to_blog; |
---|
24 | |
---|
25 | if (!$_active || !$_wiki_service) return; |
---|
26 | |
---|
27 | if (!isset($core->kutrlServices[$_wiki_service])) return; |
---|
28 | |
---|
29 | try |
---|
30 | { |
---|
31 | $kut = new $core->kutrlServices[$_wiki_service]($core,$_limit_to_blog); |
---|
32 | } |
---|
33 | catch (Exception $e) |
---|
34 | { |
---|
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 | |
---|
51 | $_active = (boolean) $core->blog->settings->kutrl_active; |
---|
52 | $_wiki_service = (string) $core->blog->settings->kutrl_wiki_service; |
---|
53 | $_limit_to_blog = (boolean) $core->blog->settings->kutrl_limit_to_blog; |
---|
54 | |
---|
55 | if (!$_active || !$_wiki_service) return; |
---|
56 | |
---|
57 | if (!isset($core->kutrlServices[$_wiki_service])) return; |
---|
58 | |
---|
59 | try |
---|
60 | { |
---|
61 | $kut = new $core->kutrlServices[$_wiki_service]($core,$_limit_to_blog); |
---|
62 | } |
---|
63 | catch (Exception $e) |
---|
64 | { |
---|
65 | return array(); |
---|
66 | } |
---|
67 | |
---|
68 | $rs = $kut->hash($url); |
---|
69 | |
---|
70 | if (!$rs) |
---|
71 | { |
---|
72 | return array(); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $res = array(); |
---|
77 | $testurl = strlen($rs->url) > 35 ? substr($rs->url,0,35).'...' : $rs->url; |
---|
78 | $res['url'] = $kut->url_base.$rs->hash; |
---|
79 | $res['title'] = sprintf(__('%s (Shorten with %s)'),$rs->url,__($kut->name)); |
---|
80 | if ($testurl == $content) $res['content'] = $res['url']; |
---|
81 | |
---|
82 | return $res; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | ?> |
---|