1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of cinecturlink2, 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 | $core->addBehavior('initWidgets',array('cinecturlink2Widget','adminLinks')); |
---|
16 | $core->addBehavior('initWidgets',array('cinecturlink2Widget','adminCats')); |
---|
17 | |
---|
18 | class cinecturlink2Widget |
---|
19 | { |
---|
20 | public static function adminLinks($w) |
---|
21 | { |
---|
22 | global $core; |
---|
23 | |
---|
24 | $C2 = new cinecturlink2($core); |
---|
25 | |
---|
26 | $categories_combo = array('' => '', __('Uncategorized') => 'null'); |
---|
27 | $categories = $C2->getCategories(); |
---|
28 | while($categories->fetch()) |
---|
29 | { |
---|
30 | $cat_title = html::escapeHTML($categories->cat_title); |
---|
31 | $categories_combo[$cat_title] = $categories->cat_id; |
---|
32 | } |
---|
33 | |
---|
34 | $sortby_combo = array( |
---|
35 | __('Update date') => 'link_upddt', |
---|
36 | __('My rating') => 'link_note', |
---|
37 | __('Title') => 'link_title', |
---|
38 | __('Random') => 'RANDOM', |
---|
39 | __('Number of views') => 'COUNTER' |
---|
40 | ); |
---|
41 | $order_combo = array( |
---|
42 | __('Ascending') => 'asc', |
---|
43 | __('Descending') => 'desc' |
---|
44 | ); |
---|
45 | |
---|
46 | $w->create('cinecturlink2links', |
---|
47 | __('My cinecturlink'),array('cinecturlink2Widget','publicLinks') |
---|
48 | ); |
---|
49 | $w->cinecturlink2links->setting('title', |
---|
50 | __('Title:'),__('My cinecturlink'),'text' |
---|
51 | ); |
---|
52 | $w->cinecturlink2links->setting('category', |
---|
53 | __('Category:'),'','combo',$categories_combo |
---|
54 | ); |
---|
55 | $w->cinecturlink2links->setting('sortby', |
---|
56 | __('Order by:'),'link_upddt','combo',$sortby_combo |
---|
57 | ); |
---|
58 | $w->cinecturlink2links->setting('sort', |
---|
59 | __('Sort: (only for date, note and title)'),'desc','combo',$order_combo |
---|
60 | ); |
---|
61 | $w->cinecturlink2links->setting('limit', |
---|
62 | __('Limit:'),10,'text' |
---|
63 | ); |
---|
64 | $w->cinecturlink2links->setting('withlink', |
---|
65 | __('Enable link'),1,'check' |
---|
66 | ); |
---|
67 | $w->cinecturlink2links->setting('showauthor', |
---|
68 | __('Show author'),1,'check' |
---|
69 | ); |
---|
70 | $w->cinecturlink2links->setting('shownote', |
---|
71 | __('Show my rating'),0,'check' |
---|
72 | ); |
---|
73 | $w->cinecturlink2links->setting('showdesc', |
---|
74 | __('Show description'),0,'check' |
---|
75 | ); |
---|
76 | $w->cinecturlink2links->setting('showpagelink', |
---|
77 | __('Show a link to cinecturlink page'),0,'check' |
---|
78 | ); |
---|
79 | $w->cinecturlink2links->setting('homeonly', |
---|
80 | __('Home page only'),1,'check' |
---|
81 | ); |
---|
82 | } |
---|
83 | |
---|
84 | public static function adminCats($w) |
---|
85 | { |
---|
86 | $w->create('cinecturlink2cats', |
---|
87 | __('List of categories of cinecturlink'),array('cinecturlink2Widget','publicCats') |
---|
88 | ); |
---|
89 | $w->cinecturlink2cats->setting('title', |
---|
90 | __('Title:'),__('My cinecturlink by categories'),'text' |
---|
91 | ); |
---|
92 | $w->cinecturlink2cats->setting('shownumlink', |
---|
93 | __('Show number of links'),0,'check' |
---|
94 | ); |
---|
95 | $w->cinecturlink2cats->setting('homeonly', |
---|
96 | __('Home page only'),1,'check' |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | public static function publicLinks($w) |
---|
101 | { |
---|
102 | global $core; |
---|
103 | $core->blog->settings->addNamespace('cinecturlink2'); |
---|
104 | |
---|
105 | if (!$core->blog->settings->cinecturlink2->cinecturlink2_active |
---|
106 | || $w->homeonly && $core->url->type != 'default') return; |
---|
107 | |
---|
108 | $C2 = new cinecturlink2($core); |
---|
109 | |
---|
110 | if ($w->category) |
---|
111 | { |
---|
112 | if ($w->category == 'null') |
---|
113 | { |
---|
114 | $params['sql'] = ' AND L.cat_id IS NULL '; |
---|
115 | } |
---|
116 | elseif (is_numeric($w->category)) |
---|
117 | { |
---|
118 | $params['cat_id'] = (integer) $w->category; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | $limit = abs((integer) $w->limit); |
---|
123 | |
---|
124 | # Tirage aléatoire |
---|
125 | # Consomme beaucoup de ressources! |
---|
126 | if ($w->sortby == 'RANDOM') |
---|
127 | { |
---|
128 | $big_rs = $C2->getLinks($params); |
---|
129 | |
---|
130 | if ($big_rs->isEmpty()) return; |
---|
131 | |
---|
132 | $ids= array(); |
---|
133 | while($big_rs->fetch()) |
---|
134 | { |
---|
135 | $ids[] = $big_rs->link_id; |
---|
136 | } |
---|
137 | shuffle($ids); |
---|
138 | $ids = array_slice($ids,0,$limit); |
---|
139 | |
---|
140 | $params['link_id'] = array(); |
---|
141 | foreach($ids as $id) |
---|
142 | { |
---|
143 | $params['link_id'][] = $id; |
---|
144 | } |
---|
145 | } |
---|
146 | elseif ($w->sortby == 'COUNTER') |
---|
147 | { |
---|
148 | $params['order'] = 'link_count asc'; |
---|
149 | $params['limit'] = $limit; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | $params['order'] = $w->sortby; |
---|
154 | $params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc'; |
---|
155 | $params['limit'] = $limit; |
---|
156 | } |
---|
157 | |
---|
158 | $rs = $C2->getLinks($params); |
---|
159 | |
---|
160 | if ($rs->isEmpty()) return; |
---|
161 | |
---|
162 | $widthmax = (integer) $core->blog->settings->cinecturlink2->cinecturlink2_widthmax; |
---|
163 | $style = $widthmax ? ' style="width:'.$widthmax.'px;"' : ''; |
---|
164 | |
---|
165 | $entries = array(); |
---|
166 | while($rs->fetch()) |
---|
167 | { |
---|
168 | $url = $rs->link_url; |
---|
169 | $img = $rs->link_img; |
---|
170 | $title = html::escapeHTML($rs->link_title); |
---|
171 | $author = html::escapeHTML($rs->link_author); |
---|
172 | $cat = html::escapeHTML($rs->cat_title); |
---|
173 | $note = $w->shownote ? ' <em>('.$rs->link_note.'/20)</em>' : ''; |
---|
174 | $desc = $w->showdesc ? '<br /><em>'.html::escapeHTML($rs->link_desc).'</em>' : ''; |
---|
175 | $lang = $rs->link_lang ? ' hreflang="'.$rs->link_lang.'"' : ''; |
---|
176 | $count = abs((integer) $rs->link_count); |
---|
177 | |
---|
178 | # --BEHAVIOR-- cinecturlink2WidgetLinks |
---|
179 | $bhv = $core->callBehavior('cinecturlink2WidgetLinks',$rs->link_id); |
---|
180 | |
---|
181 | $entries[] = |
---|
182 | '<p style="text-align:center;">'. |
---|
183 | ($w->withlink && !empty($url) ? '<a href="'.$url.'"'.$lang.' title="'.$cat.'">' : ''). |
---|
184 | '<strong>'.$title.'</strong>'.$note.'<br />'. |
---|
185 | ($w->showauthor ? $author.'<br />' : '').'<br />'. |
---|
186 | '<img src="'.$img.'" alt="'.$title.' - '.$author.'"'.$style.' />'. |
---|
187 | $desc. |
---|
188 | ($w->withlink && !empty($url) ? '</a>' : ''). |
---|
189 | '</p>'.$bhv; |
---|
190 | |
---|
191 | try |
---|
192 | { |
---|
193 | $cur = $core->con->openCursor($C2->table); |
---|
194 | $cur->link_count = ($count + 1); |
---|
195 | $C2->updLink($rs->link_id,$cur,false); |
---|
196 | } |
---|
197 | catch (Exception $e) {} |
---|
198 | } |
---|
199 | # Tirage aléatoire |
---|
200 | if ($w->sortby == 'RANDOM' || $w->sortby == 'COUNTER') |
---|
201 | { |
---|
202 | shuffle($entries); |
---|
203 | if ($core->blog->settings->cinecturlink2->cinecturlink2_triggeronrandom) |
---|
204 | { |
---|
205 | $core->blog->triggerBlog(); |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | return |
---|
210 | '<div class="cinecturlink2list">'. |
---|
211 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
212 | implode(' ',$entries). |
---|
213 | ($w->showpagelink && $core->blog->settings->cinecturlink2->cinecturlink2_public_active ? |
---|
214 | '<p><a href="'.$core->blog->url.$core->url->getBase('cinecturlink2').'" title="'.__('view all links').'">'.__('More links').'</a></p>' : '' |
---|
215 | ). |
---|
216 | '</div>'; |
---|
217 | } |
---|
218 | |
---|
219 | public static function publicCats($w) |
---|
220 | { |
---|
221 | global $core; |
---|
222 | $core->blog->settings->addNamespace('cinecturlink2'); |
---|
223 | |
---|
224 | if (!$core->blog->settings->cinecturlink2->cinecturlink2_active |
---|
225 | || !$core->blog->settings->cinecturlink2->cinecturlink2_public_active |
---|
226 | || $w->homeonly && $core->url->type != 'default') return; |
---|
227 | |
---|
228 | $C2 = new cinecturlink2($core); |
---|
229 | |
---|
230 | $rs = $C2->getCategories(array()); |
---|
231 | |
---|
232 | if ($rs->isEmpty()) return; |
---|
233 | |
---|
234 | $res = |
---|
235 | '<li><a href="'. |
---|
236 | $core->blog->url.$core->url->getBase('cinecturlink2'). |
---|
237 | '" title="'.__('view all links').'">'.__('all links'). |
---|
238 | '</a>'; |
---|
239 | if ($w->shownumlink) |
---|
240 | { |
---|
241 | $res .= ' ('.($C2->getLinks(array(),true)->f(0)).')'; |
---|
242 | } |
---|
243 | $res .= '</li>'; |
---|
244 | |
---|
245 | while($rs->fetch()) |
---|
246 | { |
---|
247 | $res .= |
---|
248 | '<li><a href="'. |
---|
249 | $core->blog->url.$core->url->getBase('cinecturlink2').'/'.$core->blog->settings->cinecturlink2->cinecturlink2_public_caturl.'/'.urlencode($rs->cat_title). |
---|
250 | '" title="'.__('view links of this category').'">'. |
---|
251 | html::escapeHTML($rs->cat_title). |
---|
252 | '</a>'; |
---|
253 | if ($w->shownumlink) |
---|
254 | { |
---|
255 | $res .= ' ('.($C2->getLinks(array('cat_id'=>$rs->cat_id),true)->f(0)).')'; |
---|
256 | } |
---|
257 | $res .= '</li>'; |
---|
258 | } |
---|
259 | |
---|
260 | return |
---|
261 | '<div class="cinecturlink2cat">'. |
---|
262 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
263 | '<ul>'.$res.'</ul>'. |
---|
264 | '</div>'; |
---|
265 | } |
---|
266 | } |
---|
267 | ?> |
---|