[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 | |
---|
[945] | 70 | |
---|
[0] | 71 | public static function bestof($w) |
---|
| 72 | { |
---|
| 73 | global $core; |
---|
| 74 | |
---|
[945] | 75 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 76 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 77 | return; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | $params = array( |
---|
| 81 | 'post_selected' => true, |
---|
| 82 | 'no_content' => true, |
---|
| 83 | 'order' => 'post_dt '.strtoupper($w->orderby) |
---|
| 84 | ); |
---|
| 85 | |
---|
| 86 | $rs = $core->blog->getPosts($params); |
---|
| 87 | |
---|
| 88 | if ($rs->isEmpty()) { |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | $res = |
---|
[1063] | 93 | ($w->content_only ? '' : '<div class="selected'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 94 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 95 | '<ul>'; |
---|
| 96 | |
---|
| 97 | while ($rs->fetch()) { |
---|
| 98 | $res .= ' <li><a href="'.$rs->getURL().'">'.html::escapeHTML($rs->post_title).'</a></li> '; |
---|
| 99 | } |
---|
| 100 | |
---|
[1063] | 101 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 102 | |
---|
| 103 | return $res; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | public static function langs($w) |
---|
| 107 | { |
---|
| 108 | global $core, $_ctx; |
---|
| 109 | |
---|
[945] | 110 | if (($w->homeonly == 1 && $core->url->type != 'default' && $core->url->type != 'lang') || |
---|
| 111 | ($w->homeonly == 2 && ($core->url->type == 'default' || $core->url->type == 'lang'))) { |
---|
[0] | 112 | return; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | $rs = $core->blog->getLangs(); |
---|
| 116 | |
---|
| 117 | if ($rs->count() <= 1) { |
---|
| 118 | return; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | $langs = l10n::getISOcodes(); |
---|
| 122 | $res = |
---|
[1063] | 123 | ($w->content_only ? '' : '<div class="langs'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 124 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 125 | '<ul>'; |
---|
| 126 | |
---|
| 127 | while ($rs->fetch()) |
---|
| 128 | { |
---|
| 129 | $l = ($_ctx->cur_lang == $rs->post_lang) ? '<strong>%s</strong>' : '%s'; |
---|
| 130 | |
---|
| 131 | $lang_name = isset($langs[$rs->post_lang]) ? $langs[$rs->post_lang] : $rs->post_lang; |
---|
| 132 | |
---|
| 133 | $res .= |
---|
| 134 | ' <li>'. |
---|
| 135 | sprintf($l, |
---|
[776] | 136 | '<a href="'.$core->url->getURLFor('lang',$rs->post_lang).'" '. |
---|
[0] | 137 | 'class="lang-'.$rs->post_lang.'">'. |
---|
| 138 | $lang_name.'</a>'). |
---|
| 139 | ' </li>'; |
---|
| 140 | } |
---|
| 141 | |
---|
[1063] | 142 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 143 | |
---|
| 144 | return $res; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | public static function subscribe($w) |
---|
| 148 | { |
---|
| 149 | global $core; |
---|
| 150 | |
---|
[945] | 151 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 152 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 153 | return; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | $type = ($w->type == 'atom' || $w->type == 'rss2') ? $w->type : 'rss2'; |
---|
| 157 | $mime = $type == 'rss2' ? 'application/rss+xml' : 'application/atom+xml'; |
---|
| 158 | |
---|
| 159 | $p_title = __('This blog\'s entries %s feed'); |
---|
| 160 | |
---|
| 161 | $res = |
---|
[1063] | 162 | ($w->content_only ? '' : '<div class="syndicate'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 163 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 164 | '<ul>'; |
---|
| 165 | |
---|
| 166 | $res .= |
---|
| 167 | '<li><a type="'.$mime.'" '. |
---|
[776] | 168 | 'href="'.$core->blog->url.$core->url->getURLFor('feed', $type).'" '. |
---|
[0] | 169 | 'title="'.sprintf($p_title,($type == 'atom' ? 'Atom' : 'RSS')).'" class="feed">'. |
---|
| 170 | __('Entries feed').'</a></li>'; |
---|
| 171 | |
---|
[1063] | 172 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 173 | |
---|
| 174 | return $res; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | public static function feed($w) |
---|
| 178 | { |
---|
| 179 | if (!$w->url) { |
---|
| 180 | return; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | global $core; |
---|
| 184 | |
---|
[945] | 185 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 186 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 187 | return; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | $limit = abs((integer) $w->limit); |
---|
| 191 | |
---|
| 192 | try { |
---|
| 193 | $feed = feedReader::quickParse($w->url,DC_TPL_CACHE); |
---|
| 194 | if ($feed == false || count($feed->items) == 0) { |
---|
| 195 | return; |
---|
| 196 | } |
---|
| 197 | } catch (Exception $e) { |
---|
| 198 | return; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | $res = |
---|
[1063] | 202 | ($w->content_only ? '' : '<div class="feed'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 203 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 204 | '<ul>'; |
---|
| 205 | |
---|
| 206 | $i = 0; |
---|
| 207 | foreach ($feed->items as $item) { |
---|
[862] | 208 | $title = isset($item->title) && strlen(trim($item->title)) ? $item->title : ''; |
---|
| 209 | $link = isset($item->link) && strlen(trim($item->link)) ? $item->link : ''; |
---|
| 210 | |
---|
| 211 | if (!$link && !$title) { |
---|
| 212 | continue; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | if (!$title) { |
---|
| 216 | $title = substr($link,0,25).'...'; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | $li = $link ? '<a href="'.html::escapeHTML($item->link).'">'.$title.'</a>' : $title; |
---|
[0] | 220 | $res .= ' <li>'.$li.'</li> '; |
---|
| 221 | $i++; |
---|
| 222 | if ($i >= $limit) { |
---|
| 223 | break; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
[1063] | 227 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 228 | |
---|
| 229 | return $res; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | public static function text($w) |
---|
| 233 | { |
---|
| 234 | global $core; |
---|
| 235 | |
---|
[945] | 236 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 237 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 238 | return; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | $res = |
---|
[1063] | 242 | ($w->content_only ? '' : '<div class="text'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 243 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 244 | $w->text. |
---|
[1063] | 245 | ($w->content_only ? '' : '</div>'); |
---|
[0] | 246 | |
---|
| 247 | return $res; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | public static function lastposts($w) |
---|
| 251 | { |
---|
| 252 | global $core; |
---|
| 253 | |
---|
[945] | 254 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 255 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 256 | return; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | $params['limit'] = abs((integer) $w->limit); |
---|
| 260 | $params['order'] = 'post_dt desc'; |
---|
| 261 | $params['no_content'] = true; |
---|
| 262 | |
---|
| 263 | if ($w->tag) |
---|
| 264 | { |
---|
| 265 | $params['meta_id'] = $w->tag; |
---|
| 266 | $rs = $core->meta->getPostsByMeta($params); |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | $rs = $core->blog->getPosts($params); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | if ($rs->isEmpty()) { |
---|
| 274 | return; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | $res = |
---|
[1063] | 278 | ($w->content_only ? '' : '<div class="lastposts'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 279 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 280 | '<ul>'; |
---|
| 281 | |
---|
| 282 | while ($rs->fetch()) { |
---|
| 283 | $res .= '<li><a href="'.$rs->getURL().'">'. |
---|
| 284 | html::escapeHTML($rs->post_title).'</a></li>'; |
---|
| 285 | } |
---|
| 286 | |
---|
[1063] | 287 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 288 | |
---|
| 289 | return $res; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | public static function lastcomments($w) |
---|
| 293 | { |
---|
| 294 | global $core; |
---|
| 295 | |
---|
[945] | 296 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 297 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 298 | return; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | $params['limit'] = abs((integer) $w->limit); |
---|
| 302 | $params['order'] = 'comment_dt desc'; |
---|
| 303 | $rs = $core->blog->getComments($params); |
---|
| 304 | |
---|
| 305 | if ($rs->isEmpty()) { |
---|
| 306 | return; |
---|
| 307 | } |
---|
| 308 | |
---|
[1063] | 309 | $res = ($w->content_only ? '' : '<div class="lastcomments'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 310 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 311 | '<ul>'; |
---|
| 312 | |
---|
| 313 | while ($rs->fetch()) |
---|
| 314 | { |
---|
| 315 | $res .= '<li class="'. |
---|
| 316 | ((boolean)$rs->comment_trackback ? 'last-tb' : 'last-comment'). |
---|
| 317 | '"><a href="'.$rs->getPostURL().'#c'.$rs->comment_id.'">'. |
---|
| 318 | html::escapeHTML($rs->post_title).' - '. |
---|
| 319 | html::escapeHTML($rs->comment_author). |
---|
| 320 | '</a></li>'; |
---|
| 321 | } |
---|
| 322 | |
---|
[1063] | 323 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[0] | 324 | |
---|
| 325 | return $res; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | ?> |
---|