1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | tagFlash - a plugin for Dotclear | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010 Nicolas Roudaire http://www.nikrou.net | |
---|
6 | // | Copyright(C) 2010 Guenaël | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | This program is free software; you can redistribute it and/or modify | |
---|
9 | // | it under the terms of the GNU General Public License as published by | |
---|
10 | // | the Free Software Foundation | |
---|
11 | // | | |
---|
12 | // | This program is distributed in the hope that it will be useful, but | |
---|
13 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
14 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
15 | // | General Public License for more details. | |
---|
16 | // | | |
---|
17 | // | You should have received a copy of the GNU General Public License | |
---|
18 | // | along with this program; if not, write to the Free Software | |
---|
19 | // | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
---|
20 | // | MA 02110-1301 USA. | |
---|
21 | // +-----------------------------------------------------------------------+ |
---|
22 | |
---|
23 | class tplTagFlash |
---|
24 | { |
---|
25 | private static $size_translator = array(0 => 0, 10 => 8, 20 => 10, 30 => 12, 40 => 14, 50 => 16, |
---|
26 | 60 => 18, 70 => 20, 80 => 22, 90 => 24, 100 => 26); |
---|
27 | |
---|
28 | public static function widget($w) { |
---|
29 | global $core, $_ctx; |
---|
30 | |
---|
31 | if (!$core->blog->settings->tagflash->active) { |
---|
32 | return; |
---|
33 | } |
---|
34 | |
---|
35 | $flash_url = html::stripHostURL($GLOBALS['core']->blog->getQmarkURL().'pf=tagflash/tagcloud.swf'); |
---|
36 | $settings = $core->blog->settings->tagflash; |
---|
37 | |
---|
38 | $res = ''; |
---|
39 | |
---|
40 | if ($w->title) { |
---|
41 | $res .= '<h2>'.$w->title.'</h2>'; |
---|
42 | } |
---|
43 | |
---|
44 | $res .= sprintf('<object data="%s" width="%s" height="%s" type="application/x-shockwave-flash">', |
---|
45 | $flash_url, |
---|
46 | $settings->width, |
---|
47 | $settings->height |
---|
48 | ); |
---|
49 | |
---|
50 | $res .= sprintf('<param name="movie" value="%s"/>', $flash_url); |
---|
51 | $res .= '<param name="allowScriptAccess" value="sameDomain"/>'; |
---|
52 | $res .= sprintf('<param name="flashvars" value="%s"/>', |
---|
53 | self::tagFlashParams($w) |
---|
54 | ); |
---|
55 | $res .= '<param name="quality" value="high"/>'."\n"; |
---|
56 | if ($w->transparent_mode) { |
---|
57 | $res .= '<param name="wmode" value="transparent"/>'."\n"; |
---|
58 | } else { |
---|
59 | $res .= '<param name="bgcolor" value="#'.$settings->bgcolor.'"/>'."\n"; |
---|
60 | } |
---|
61 | if ($w->with_seo_content) { |
---|
62 | $res .= '<div id="tagFlashContent">'.self::getTags($w, false).'</div>'."\n"; |
---|
63 | } else { |
---|
64 | $res .= '<p>'. __('This will be shown to users with no Flash plugin.').'</p>'; |
---|
65 | } |
---|
66 | $res .= '</object>'."\n"; |
---|
67 | $res .= '<p><a href="'.$core->blog->url.$core->url->getBase('tags').'">'.__('All tags').'</a></p>'; |
---|
68 | |
---|
69 | return '<div class="tagFlash">'.$res.'</div>'; |
---|
70 | } |
---|
71 | |
---|
72 | public static function tagFlashParams($w) { |
---|
73 | global $core; |
---|
74 | |
---|
75 | $res = ''; |
---|
76 | $res .= 'mode=tags'; |
---|
77 | $res .= '&tcolor=0x'.$core->blog->settings->tagflash->color1; |
---|
78 | $res .= '&tcolor2=0x'.$core->blog->settings->tagflash->color2; |
---|
79 | $res .= '&hicolor=0x'.$core->blog->settings->tagflash->hicolor; |
---|
80 | $res .= '&tspeed='.$core->blog->settings->tagflash->speed; |
---|
81 | $res .= '&distr=true'; |
---|
82 | $res .= '&tagcloud='.self::getTags($w); |
---|
83 | |
---|
84 | return $res; |
---|
85 | } |
---|
86 | |
---|
87 | public static function getTags($w, $for_flash=true) { |
---|
88 | global $core; |
---|
89 | |
---|
90 | $limit = null; |
---|
91 | if ($w->limit && is_numeric($w->limit)) { |
---|
92 | $limit = $w->limit; |
---|
93 | } |
---|
94 | |
---|
95 | $rs = $core->meta->computeMetaStats( |
---|
96 | $core->meta->getMetadata(array('meta_type'=> 'tag', |
---|
97 | 'limit'=> $limit) |
---|
98 | ) |
---|
99 | ); |
---|
100 | $res = ''; |
---|
101 | if ($for_flash) { |
---|
102 | $fmt_tag = "<a href='%s' rel='tag' style='font-size:%spt'>%s</a>"; |
---|
103 | } else { |
---|
104 | $fmt_tag = '<li><a href="%s" class="tag%s" rel="tag">%s</a></li>'; |
---|
105 | } |
---|
106 | |
---|
107 | if (!$rs->isEmpty()) { |
---|
108 | while ($rs->fetch()) { |
---|
109 | $res .= sprintf($fmt_tag, |
---|
110 | $core->blog->url.$core->url->getBase('tag').'/'.urlencode(utf8_encode($rs->meta_id)), |
---|
111 | self::$size_translator[$rs->roundpercent], |
---|
112 | $rs->meta_id |
---|
113 | ); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | if ($for_flash) { |
---|
118 | $res = '<tags>'.$res.'</tags>'; |
---|
119 | } else { |
---|
120 | $res = '<ul>'.$res.'</ul>'; |
---|
121 | } |
---|
122 | |
---|
123 | return $res; |
---|
124 | } |
---|
125 | } |
---|
126 | ?> |
---|