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