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