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