| 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 | if (!defined('DC_RC_PATH')) { return; } | 
|---|
| 13 |  | 
|---|
| 14 | class defaultWidgets | 
|---|
| 15 | { | 
|---|
| 16 |      public static function search($w) | 
|---|
| 17 |      { | 
|---|
| 18 |           global $core; | 
|---|
| 19 |            | 
|---|
| 20 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 21 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 22 |                return; | 
|---|
| 23 |           } | 
|---|
| 24 |  | 
|---|
| 25 |           $value = isset($GLOBALS['_search']) ? html::escapeHTML($GLOBALS['_search']) : ''; | 
|---|
| 26 |            | 
|---|
| 27 |           return | 
|---|
| 28 |           ($w->content_only ? '' : '<div id="search"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). | 
|---|
| 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.'" /> '. | 
|---|
| 33 |           '<input type="submit" class="submit" value="ok" /></p>'. | 
|---|
| 34 |           '</fieldset>'. | 
|---|
| 35 |           '</form>'. | 
|---|
| 36 |           ($w->content_only ? '' : '</div>'); | 
|---|
| 37 |      } | 
|---|
| 38 |       | 
|---|
| 39 |      public static function navigation($w) | 
|---|
| 40 |      { | 
|---|
| 41 |           global $core; | 
|---|
| 42 |            | 
|---|
| 43 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 44 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 45 |                return; | 
|---|
| 46 |           } | 
|---|
| 47 |  | 
|---|
| 48 |           $res = | 
|---|
| 49 |           ($w->content_only ? '' : '<div id="topnav"'.($w->class ? ' class="'.html::escapeHTML($w->class).'"' : '').'>'). | 
|---|
| 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">'. | 
|---|
| 62 |           '<a href="'.$core->blog->url.$core->url->getURLFor("archive").'">'. | 
|---|
| 63 |           __('Archives').'</a></li>'. | 
|---|
| 64 |           '</ul>'. | 
|---|
| 65 |           ($w->content_only ? '' : '</div>'); | 
|---|
| 66 |            | 
|---|
| 67 |           return $res; | 
|---|
| 68 |      } | 
|---|
| 69 |       | 
|---|
| 70 |      public static function categories($w) | 
|---|
| 71 |      { | 
|---|
| 72 |           global $core, $_ctx; | 
|---|
| 73 |            | 
|---|
| 74 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 75 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 76 |                return; | 
|---|
| 77 |           } | 
|---|
| 78 |  | 
|---|
| 79 |           $rs = $core->blog->getCategories(array('post_type'=>'post')); | 
|---|
| 80 |           if ($rs->isEmpty()) { | 
|---|
| 81 |                return; | 
|---|
| 82 |           } | 
|---|
| 83 |            | 
|---|
| 84 |           $res = | 
|---|
| 85 |           ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 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 .= | 
|---|
| 108 |                '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'. | 
|---|
| 109 |                html::escapeHTML($rs->cat_title).'</a>'. | 
|---|
| 110 |                ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : ''); | 
|---|
| 111 |                 | 
|---|
| 112 |                 | 
|---|
| 113 |                $level = $rs->level; | 
|---|
| 114 |           } | 
|---|
| 115 |            | 
|---|
| 116 |           if ($ref_level - $level < 0) { | 
|---|
| 117 |                $res .= str_repeat('</li></ul>',-($ref_level - $level)); | 
|---|
| 118 |           } | 
|---|
| 119 |           $res .= ($w->content_only ? '' : '</div>'); | 
|---|
| 120 |            | 
|---|
| 121 |           return $res; | 
|---|
| 122 |      } | 
|---|
| 123 |       | 
|---|
| 124 |      public static function bestof($w) | 
|---|
| 125 |      { | 
|---|
| 126 |           global $core; | 
|---|
| 127 |            | 
|---|
| 128 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 129 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 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 = | 
|---|
| 146 |           ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 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 |            | 
|---|
| 154 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 155 |            | 
|---|
| 156 |           return $res; | 
|---|
| 157 |      } | 
|---|
| 158 |       | 
|---|
| 159 |      public static function langs($w) | 
|---|
| 160 |      { | 
|---|
| 161 |           global $core, $_ctx; | 
|---|
| 162 |            | 
|---|
| 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'))) { | 
|---|
| 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 = | 
|---|
| 176 |           ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 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, | 
|---|
| 189 |                     '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '. | 
|---|
| 190 |                     'class="lang-'.$rs->post_lang.'">'. | 
|---|
| 191 |                     $lang_name.'</a>'). | 
|---|
| 192 |                ' </li>'; | 
|---|
| 193 |           } | 
|---|
| 194 |            | 
|---|
| 195 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 196 |            | 
|---|
| 197 |           return $res; | 
|---|
| 198 |      } | 
|---|
| 199 |       | 
|---|
| 200 |      public static function subscribe($w) | 
|---|
| 201 |      { | 
|---|
| 202 |           global $core; | 
|---|
| 203 |            | 
|---|
| 204 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 205 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 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 = | 
|---|
| 216 |           ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 217 |           ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). | 
|---|
| 218 |           '<ul>'; | 
|---|
| 219 |            | 
|---|
| 220 |           $res .= | 
|---|
| 221 |           '<li><a type="'.$mime.'" '. | 
|---|
| 222 |           'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '. | 
|---|
| 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.'" '. | 
|---|
| 230 |                'href="'.$core->blog->url.$core->url->getURLFor('feed',$type.'/comments').'" '. | 
|---|
| 231 |                'title="'.sprintf($c_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. | 
|---|
| 232 |                __('Comments feed').'</a></li>'; | 
|---|
| 233 |           } | 
|---|
| 234 |            | 
|---|
| 235 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 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 |            | 
|---|
| 248 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 249 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 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 = | 
|---|
| 265 |           ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 266 |           ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). | 
|---|
| 267 |           '<ul>'; | 
|---|
| 268 |            | 
|---|
| 269 |           $i = 0; | 
|---|
| 270 |           foreach ($feed->items as $item) { | 
|---|
| 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; | 
|---|
| 283 |                $res .= ' <li>'.$li.'</li> '; | 
|---|
| 284 |                $i++; | 
|---|
| 285 |                if ($i >= $limit) { | 
|---|
| 286 |                     break; | 
|---|
| 287 |                } | 
|---|
| 288 |           } | 
|---|
| 289 |            | 
|---|
| 290 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 291 |            | 
|---|
| 292 |           return $res; | 
|---|
| 293 |      } | 
|---|
| 294 |       | 
|---|
| 295 |      public static function text($w) | 
|---|
| 296 |      { | 
|---|
| 297 |           global $core; | 
|---|
| 298 |            | 
|---|
| 299 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 300 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 301 |                return; | 
|---|
| 302 |           } | 
|---|
| 303 |            | 
|---|
| 304 |           $res = | 
|---|
| 305 |           ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 306 |           ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). | 
|---|
| 307 |           $w->text. | 
|---|
| 308 |           ($w->content_only ? '' : '</div>'); | 
|---|
| 309 |            | 
|---|
| 310 |           return $res; | 
|---|
| 311 |      } | 
|---|
| 312 |       | 
|---|
| 313 |      public static function lastposts($w) | 
|---|
| 314 |      { | 
|---|
| 315 |           global $core; | 
|---|
| 316 |            | 
|---|
| 317 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 318 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 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 = | 
|---|
| 352 |           ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 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 |            | 
|---|
| 361 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 362 |            | 
|---|
| 363 |           return $res; | 
|---|
| 364 |      } | 
|---|
| 365 |       | 
|---|
| 366 |      public static function lastcomments($w) | 
|---|
| 367 |      { | 
|---|
| 368 |           global $core; | 
|---|
| 369 |            | 
|---|
| 370 |           if (($w->homeonly == 1 && $core->url->type != 'default') || | 
|---|
| 371 |                ($w->homeonly == 2 && $core->url->type == 'default')) { | 
|---|
| 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 |            | 
|---|
| 383 |           $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). | 
|---|
| 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 |            | 
|---|
| 397 |           $res .= '</ul>'.($w->content_only ? '' : '</div>'); | 
|---|
| 398 |            | 
|---|
| 399 |           return $res; | 
|---|
| 400 |      } | 
|---|
| 401 | } | 
|---|
| 402 | ?> | 
|---|