[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | class defaultWidgets |
---|
| 15 | { |
---|
| 16 | public static function search($w) |
---|
| 17 | { |
---|
| 18 | global $core; |
---|
| 19 | |
---|
[945] | 20 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 21 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
| 22 | return; |
---|
| 23 | } |
---|
| 24 | |
---|
[0] | 25 | $value = isset($GLOBALS['_search']) ? html::escapeHTML($GLOBALS['_search']) : ''; |
---|
| 26 | |
---|
| 27 | return |
---|
[1063] | 28 | ($w->content_only ? '' : '<div id="search"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). |
---|
[0] | 29 | ($w->title ? '<h2><label for="q">'.html::escapeHTML($w->title).'</label></h2>' : ''). |
---|
| 30 | '<form action="'.$core->blog->url.'" method="get">'. |
---|
| 31 | '<fieldset>'. |
---|
| 32 | '<p><input type="text" size="10" maxlength="255" id="q" name="q" value="'.$value.'" /> '. |
---|
[75] | 33 | '<input type="submit" class="submit" value="ok" /></p>'. |
---|
[0] | 34 | '</fieldset>'. |
---|
| 35 | '</form>'. |
---|
[1063] | 36 | ($w->content_only ? '' : '</div>'); |
---|
[0] | 37 | } |
---|
| 38 | |
---|
| 39 | public static function navigation($w) |
---|
| 40 | { |
---|
| 41 | global $core; |
---|
| 42 | |
---|
[945] | 43 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 44 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
| 45 | return; |
---|
| 46 | } |
---|
| 47 | |
---|
[0] | 48 | $res = |
---|
[1063] | 49 | ($w->content_only ? '' : '<div id="topnav"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). |
---|
[0] | 50 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 51 | '<ul>'; |
---|
| 52 | |
---|
| 53 | if ($core->url->type != 'default') { |
---|
| 54 | $res .= |
---|
| 55 | '<li class="topnav-home">'. |
---|
| 56 | '<a href="'.$core->blog->url.'">'.__('Home').'</a>'. |
---|
| 57 | '<span> - </span></li>'; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | $res .= |
---|
| 61 | '<li class="topnav-arch">'. |
---|
[776] | 62 | '<a href="'.$core->blog->url.$core->url->getURLFor("archive").'">'. |
---|
[0] | 63 | __('Archives').'</a></li>'. |
---|
| 64 | '</ul>'. |
---|
[1063] | 65 | ($w->content_only ? '' : '</div>'); |
---|
[0] | 66 | |
---|
| 67 | return $res; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | public static function categories($w) |
---|
| 71 | { |
---|
| 72 | global $core, $_ctx; |
---|
| 73 | |
---|
[945] | 74 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 75 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
| 76 | return; |
---|
| 77 | } |
---|
| 78 | |
---|
[0] | 79 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 80 | if ($rs->isEmpty()) { |
---|
| 81 | return; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $res = |
---|
[1063] | 85 | ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 86 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''); |
---|
| 87 | |
---|
| 88 | $ref_level = $level = $rs->level-1; |
---|
| 89 | while ($rs->fetch()) |
---|
| 90 | { |
---|
| 91 | $class = ''; |
---|
| 92 | if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id) |
---|
| 93 | || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) { |
---|
| 94 | $class = ' class="category-current"'; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if ($rs->level > $level) { |
---|
| 98 | $res .= str_repeat('<ul><li'.$class.'>',$rs->level - $level); |
---|
| 99 | } elseif ($rs->level < $level) { |
---|
| 100 | $res .= str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | if ($rs->level <= $level) { |
---|
| 104 | $res .= '</li><li'.$class.'>'; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | $res .= |
---|
[776] | 108 | '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'. |
---|
[0] | 109 | html::escapeHTML($rs->cat_title).'</a>'. |
---|
[475] | 110 | ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : ''); |
---|
[0] | 111 | |
---|
| 112 | |
---|
| 113 | $level = $rs->level; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | if ($ref_level - $level < 0) { |
---|
| 117 | $res .= str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 118 | } |
---|
[1063] | 119 | $res .= ($w->content_only ? '' : '</div>'); |
---|
[0] | 120 | |
---|
| 121 | return $res; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | public static function bestof($w) |
---|
| 125 | { |
---|
| 126 | global $core; |
---|
| 127 | |
---|
[945] | 128 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 129 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 130 | return; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | $params = array( |
---|
| 134 | 'post_selected' => true, |
---|
| 135 | 'no_content' => true, |
---|
| 136 | 'order' => 'post_dt '.strtoupper($w->orderby) |
---|
| 137 | ); |
---|
| 138 | |
---|
| 139 | $rs = $core->blog->getPosts($params); |
---|
| 140 | |
---|
| 141 | if ($rs->isEmpty()) { |
---|
| 142 | return; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | $res = |
---|
[1063] | 146 | ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 147 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 148 | '<ul>'; |
---|
| 149 | |
---|
| 150 | while ($rs->fetch()) { |
---|
| 151 | $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> '; |
---|
| 152 | } |
---|
| 153 | |
---|
[1063] | 154 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 155 | |
---|
| 156 | return $res; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | public static function langs($w) |
---|
| 160 | { |
---|
| 161 | global $core, $_ctx; |
---|
| 162 | |
---|
[945] | 163 | if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') || |
---|
| 164 | ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) { |
---|
[0] | 165 | return; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | $rs = $core->blog->getLangs(); |
---|
| 169 | |
---|
| 170 | if ($rs->count() <= 1) { |
---|
| 171 | return; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | $langs = l10n::getISOcodes(); |
---|
| 175 | $res = |
---|
[1063] | 176 | ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 177 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 178 | '<ul>'; |
---|
| 179 | |
---|
| 180 | while ($rs->fetch()) |
---|
| 181 | { |
---|
| 182 | $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s'; |
---|
| 183 | |
---|
| 184 | $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang; |
---|
| 185 | |
---|
| 186 | $res .= |
---|
| 187 | ' <li>'. |
---|
| 188 | sprintf($l, |
---|
[776] | 189 | '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '. |
---|
[0] | 190 | 'class="lang-'.$rs->post_lang.'">'. |
---|
| 191 | $lang_name.'</a>'). |
---|
| 192 | ' </li>'; |
---|
| 193 | } |
---|
| 194 | |
---|
[1063] | 195 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 196 | |
---|
| 197 | return $res; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | public static function subscribe($w) |
---|
| 201 | { |
---|
| 202 | global $core; |
---|
| 203 | |
---|
[945] | 204 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 205 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 206 | return; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2'; |
---|
| 210 | $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml'; |
---|
| 211 | |
---|
| 212 | $p_title = __('This blog\'s entries %s feed'); |
---|
| 213 | $c_title = __('This blog\'s comments %s feed'); |
---|
| 214 | |
---|
| 215 | $res = |
---|
[1063] | 216 | ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 217 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 218 | '<ul>'; |
---|
| 219 | |
---|
| 220 | $res .= |
---|
| 221 | '<li><a type="'.$mime.'" '. |
---|
[776] | 222 | 'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '. |
---|
[0] | 223 | 'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. |
---|
| 224 | __('Entries feed').'</a></li>'; |
---|
| 225 | |
---|
| 226 | if ($core->blog->settings->system->allow_comments || $core->blog->settings->system->allow_trackbacks) |
---|
| 227 | { |
---|
| 228 | $res .= |
---|
| 229 | '<li><a type="'.$mime.'" '. |
---|
[776] | 230 | 'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '. |
---|
[0] | 231 | 'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. |
---|
| 232 | __('Comments feed').'</a></li>'; |
---|
| 233 | } |
---|
| 234 | |
---|
[1063] | 235 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 236 | |
---|
| 237 | return $res; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | public static function feed($w) |
---|
| 241 | { |
---|
| 242 | if (!$w->url) { |
---|
| 243 | return; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | global $core; |
---|
| 247 | |
---|
[945] | 248 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 249 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 250 | return; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | $limit = abs((integer) $w->limit); |
---|
| 254 | |
---|
| 255 | try { |
---|
| 256 | $feed = feedReader::quickParse($w->url,DC_TPL_CACHE); |
---|
| 257 | if ($feed == false || count($feed->items) == 0) { |
---|
| 258 | return; |
---|
| 259 | } |
---|
| 260 | } catch (Exception $e) { |
---|
| 261 | return; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | $res = |
---|
[1063] | 265 | ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 266 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 267 | '<ul>'; |
---|
| 268 | |
---|
| 269 | $i = 0; |
---|
| 270 | foreach ($feed->items as $item) { |
---|
[862] | 271 | $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : ''; |
---|
| 272 | $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : ''; |
---|
| 273 | |
---|
| 274 | if (!$link && !$title) { |
---|
| 275 | continue; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | if (!$title) { |
---|
| 279 | $title = substr($link,0,25).'...'; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title; |
---|
[0] | 283 | $res .= ' <li>'.$li.'</li> '; |
---|
| 284 | $i++; |
---|
| 285 | if ($i >= $limit) { |
---|
| 286 | break; |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
[1063] | 290 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 291 | |
---|
| 292 | return $res; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | public static function text($w) |
---|
| 296 | { |
---|
| 297 | global $core; |
---|
| 298 | |
---|
[945] | 299 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 300 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 301 | return; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | $res = |
---|
[1063] | 305 | ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 306 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 307 | $w->text. |
---|
[1063] | 308 | ($w->content_only ? '' : '</div>'); |
---|
[0] | 309 | |
---|
| 310 | return $res; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | public static function lastposts($w) |
---|
| 314 | { |
---|
| 315 | global $core; |
---|
| 316 | |
---|
[945] | 317 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 318 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 319 | return; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | $params['limit'] = abs((integer) $w->limit); |
---|
| 323 | $params['order'] = 'post_dt desc'; |
---|
| 324 | $params['no_content'] = true; |
---|
| 325 | |
---|
| 326 | if ($w->category) |
---|
| 327 | { |
---|
| 328 | if ($w->category == 'null') { |
---|
| 329 | $params['sql'] = ' AND P.cat_id IS NULL '; |
---|
| 330 | } elseif (is_numeric($w->category)) { |
---|
| 331 | $params['cat_id'] = (integer) $w->category; |
---|
| 332 | } else { |
---|
| 333 | $params['cat_url'] = $w->category; |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | if ($w->tag) |
---|
| 338 | { |
---|
| 339 | $params['meta_id'] = $w->tag; |
---|
| 340 | $rs = $core->meta->getPostsByMeta($params); |
---|
| 341 | } |
---|
| 342 | else |
---|
| 343 | { |
---|
| 344 | $rs = $core->blog->getPosts($params); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | if ($rs->isEmpty()) { |
---|
| 348 | return; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | $res = |
---|
[1063] | 352 | ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 353 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 354 | '<ul>'; |
---|
| 355 | |
---|
| 356 | while ($rs->fetch()) { |
---|
| 357 | $res .= '<li><a href="'.$rs->getURL().'">'. |
---|
| 358 | html::escapeHTML($rs->post_title).'</a></li>'; |
---|
| 359 | } |
---|
| 360 | |
---|
[1063] | 361 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 362 | |
---|
| 363 | return $res; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | public static function lastcomments($w) |
---|
| 367 | { |
---|
| 368 | global $core; |
---|
| 369 | |
---|
[945] | 370 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 371 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 372 | return; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | $params['limit'] = abs((integer) $w->limit); |
---|
| 376 | $params['order'] = 'comment_dt desc'; |
---|
| 377 | $rs = $core->blog->getComments($params); |
---|
| 378 | |
---|
| 379 | if ($rs->isEmpty()) { |
---|
| 380 | return; |
---|
| 381 | } |
---|
| 382 | |
---|
[1063] | 383 | $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 384 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 385 | '<ul>'; |
---|
| 386 | |
---|
| 387 | while ($rs->fetch()) |
---|
| 388 | { |
---|
| 389 | $res .= '<li class="'. |
---|
| 390 | ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment'). |
---|
| 391 | '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'. |
---|
| 392 | html::escapeHTML($rs->post_title).' - '. |
---|
| 393 | html::escapeHTML($rs->comment_author). |
---|
| 394 | '</a></li>'; |
---|
| 395 | } |
---|
| 396 | |
---|
[1063] | 397 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 398 | |
---|
| 399 | return $res; |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | ?> |
---|