[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 ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | class dcUrlHandlers extends urlHandler |
---|
| 15 | { |
---|
| 16 | public $args; |
---|
[2566] | 17 | |
---|
[772] | 18 | public function getURLFor($type,$value='') { |
---|
| 19 | $core =& $GLOBALS['core']; |
---|
| 20 | $url = $core->callBehavior("publicGetURLFor",$type,$value); |
---|
[775] | 21 | if (!$url) { |
---|
[776] | 22 | $url = $this->getBase($type); |
---|
| 23 | if ($value) { |
---|
[779] | 24 | if ($url) { |
---|
| 25 | $url .= '/'; |
---|
| 26 | } |
---|
[776] | 27 | $url .= $value; |
---|
[772] | 28 | } |
---|
| 29 | } |
---|
| 30 | return $url; |
---|
| 31 | } |
---|
[2566] | 32 | |
---|
[772] | 33 | public function register($type,$url,$representation,$handler) |
---|
| 34 | { |
---|
| 35 | $core =& $GLOBALS['core']; |
---|
| 36 | $t = new ArrayObject(array($type,$url,$representation,$handler)); |
---|
| 37 | $core->callBehavior("publicRegisterURL",$t); |
---|
| 38 | parent::register($t[0],$t[1],$t[2],$t[3]); |
---|
| 39 | } |
---|
[2566] | 40 | |
---|
[0] | 41 | public static function p404() |
---|
| 42 | { |
---|
| 43 | throw new Exception ("Page not found",404); |
---|
| 44 | } |
---|
[2566] | 45 | |
---|
[0] | 46 | public static function default404($args,$type,$e) |
---|
| 47 | { |
---|
| 48 | if ($e->getCode() != 404) { |
---|
| 49 | throw $e; |
---|
| 50 | } |
---|
| 51 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 52 | $core = $GLOBALS['core']; |
---|
[2566] | 53 | |
---|
[0] | 54 | header('Content-Type: text/html; charset=UTF-8'); |
---|
| 55 | http::head(404,'Not Found'); |
---|
| 56 | $core->url->type = '404'; |
---|
| 57 | $_ctx->current_tpl = '404.html'; |
---|
| 58 | $_ctx->content_type = 'text/html'; |
---|
[2566] | 59 | |
---|
[0] | 60 | echo $core->tpl->getData($_ctx->current_tpl); |
---|
[2566] | 61 | |
---|
[0] | 62 | # --BEHAVIOR-- publicAfterDocument |
---|
| 63 | $core->callBehavior('publicAfterDocument',$core); |
---|
| 64 | exit; |
---|
| 65 | } |
---|
[2566] | 66 | |
---|
[0] | 67 | protected static function getPageNumber(&$args) |
---|
| 68 | { |
---|
| 69 | if (preg_match('#(^|/)page/([0-9]+)$#',$args,$m)) { |
---|
| 70 | $n = (integer) $m[2]; |
---|
| 71 | if ($n > 0) { |
---|
| 72 | $args = preg_replace('#(^|/)page/([0-9]+)$#','',$args); |
---|
| 73 | return $n; |
---|
| 74 | } |
---|
| 75 | } |
---|
[2566] | 76 | |
---|
[0] | 77 | return false; |
---|
| 78 | } |
---|
[2566] | 79 | |
---|
[0] | 80 | protected static function serveDocument($tpl,$content_type='text/html',$http_cache=true,$http_etag=true) |
---|
| 81 | { |
---|
| 82 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 83 | $core =& $GLOBALS['core']; |
---|
[2566] | 84 | |
---|
[0] | 85 | if ($_ctx->nb_entry_per_page === null) { |
---|
| 86 | $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_page; |
---|
| 87 | } |
---|
[2577] | 88 | if ($_ctx->nb_entry_first_page === null) { |
---|
| 89 | $_ctx->nb_entry_first_page = $_ctx->nb_entry_per_page; |
---|
| 90 | } |
---|
[2566] | 91 | |
---|
[0] | 92 | $tpl_file = $core->tpl->getFilePath($tpl); |
---|
[2566] | 93 | |
---|
[0] | 94 | if (!$tpl_file) { |
---|
| 95 | throw new Exception('Unable to find template '); |
---|
| 96 | } |
---|
[2566] | 97 | |
---|
[0] | 98 | $result = new ArrayObject; |
---|
[2566] | 99 | |
---|
[0] | 100 | $_ctx->current_tpl = $tpl; |
---|
| 101 | $_ctx->content_type = $content_type; |
---|
| 102 | $_ctx->http_cache = $http_cache; |
---|
| 103 | $_ctx->http_etag = $http_etag; |
---|
| 104 | $core->callBehavior('urlHandlerBeforeGetData',$_ctx); |
---|
[2566] | 105 | |
---|
[0] | 106 | if ($_ctx->http_cache) { |
---|
| 107 | $GLOBALS['mod_files'][] = $tpl_file; |
---|
| 108 | http::cache($GLOBALS['mod_files'],$GLOBALS['mod_ts']); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | header('Content-Type: '.$_ctx->content_type.'; charset=UTF-8'); |
---|
| 112 | $result['content'] = $core->tpl->getData($_ctx->current_tpl); |
---|
| 113 | $result['content_type'] = $_ctx->content_type; |
---|
| 114 | $result['tpl'] = $_ctx->current_tpl; |
---|
| 115 | $result['blogupddt'] = $core->blog->upddt; |
---|
[2566] | 116 | |
---|
[0] | 117 | # --BEHAVIOR-- urlHandlerServeDocument |
---|
| 118 | $core->callBehavior('urlHandlerServeDocument',$result); |
---|
[2566] | 119 | |
---|
[0] | 120 | if ($_ctx->http_cache && $_ctx->http_etag) { |
---|
| 121 | http::etag($result['content'],http::getSelfURI()); |
---|
| 122 | } |
---|
| 123 | echo $result['content']; |
---|
| 124 | } |
---|
[2566] | 125 | |
---|
[0] | 126 | public function getDocument() |
---|
| 127 | { |
---|
| 128 | $core =& $GLOBALS['core']; |
---|
[2566] | 129 | |
---|
[0] | 130 | $type = $args = ''; |
---|
[2566] | 131 | |
---|
[0] | 132 | if ($this->mode == 'path_info') |
---|
| 133 | { |
---|
| 134 | $part = substr($_SERVER['PATH_INFO'],1); |
---|
| 135 | } |
---|
| 136 | else |
---|
| 137 | { |
---|
| 138 | $part = ''; |
---|
[2566] | 139 | |
---|
[0] | 140 | $qs = $this->parseQueryString(); |
---|
[2566] | 141 | |
---|
[0] | 142 | # Recreates some _GET and _REQUEST pairs |
---|
| 143 | if (!empty($qs)) |
---|
| 144 | { |
---|
| 145 | foreach ($_GET as $k => $v) { |
---|
| 146 | if (isset($_REQUEST[$k])) { |
---|
| 147 | unset($_REQUEST[$k]); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | $_GET = $qs; |
---|
| 151 | $_REQUEST = array_merge($qs,$_REQUEST); |
---|
[2566] | 152 | |
---|
[0] | 153 | list($k,$v) = each($qs); |
---|
| 154 | if ($v === null) { |
---|
| 155 | $part = $k; |
---|
| 156 | unset($_GET[$k]); |
---|
| 157 | unset($_REQUEST[$k]); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | } |
---|
[2566] | 161 | |
---|
[0] | 162 | $_SERVER['URL_REQUEST_PART'] = $part; |
---|
[2566] | 163 | |
---|
[0] | 164 | $this->getArgs($part,$type,$this->args); |
---|
[2566] | 165 | |
---|
[0] | 166 | # --BEHAVIOR-- urlHandlerGetArgsDocument |
---|
| 167 | $core->callBehavior('urlHandlerGetArgsDocument',$this); |
---|
[2566] | 168 | |
---|
[0] | 169 | if (!$type) |
---|
| 170 | { |
---|
| 171 | $this->type = 'default'; |
---|
| 172 | $this->callDefaultHandler($this->args); |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | $this->type = $type; |
---|
| 177 | $this->callHandler($type,$this->args); |
---|
| 178 | } |
---|
| 179 | } |
---|
[2566] | 180 | |
---|
[0] | 181 | public static function home($args) |
---|
| 182 | { |
---|
| 183 | $n = self::getPageNumber($args); |
---|
[2566] | 184 | |
---|
[0] | 185 | if ($args && !$n) |
---|
| 186 | { |
---|
[2566] | 187 | # "Then specified URL went unrecognized by all URL handlers and |
---|
[0] | 188 | # defaults to the home page, but is not a page number. |
---|
| 189 | self::p404(); |
---|
| 190 | } |
---|
| 191 | else |
---|
| 192 | { |
---|
[2577] | 193 | $_ctx =& $GLOBALS['_ctx']; |
---|
[0] | 194 | $core =& $GLOBALS['core']; |
---|
[2566] | 195 | |
---|
[0] | 196 | if ($n) { |
---|
| 197 | $GLOBALS['_page_number'] = $n; |
---|
| 198 | $core->url->type = $n > 1 ? 'default-page' : 'default'; |
---|
| 199 | } |
---|
[2566] | 200 | |
---|
[0] | 201 | if (empty($_GET['q'])) { |
---|
[2577] | 202 | if ($core->blog->settings->system->nb_post_for_home !== null) { |
---|
| 203 | $_ctx->nb_entry_first_page = $core->blog->settings->system->nb_post_for_home; |
---|
| 204 | } |
---|
[0] | 205 | self::serveDocument('home.html'); |
---|
| 206 | $core->blog->publishScheduledEntries(); |
---|
| 207 | } else { |
---|
| 208 | self::search(); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
[2566] | 212 | |
---|
[0] | 213 | public static function search() |
---|
| 214 | { |
---|
| 215 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 216 | $core =& $GLOBALS['core']; |
---|
[2566] | 217 | |
---|
[0] | 218 | $core->url->type='search'; |
---|
[2566] | 219 | |
---|
[0] | 220 | $GLOBALS['_search'] = !empty($_GET['q']) ? rawurldecode($_GET['q']) : ''; |
---|
| 221 | if ($GLOBALS['_search']) { |
---|
| 222 | $params = new ArrayObject(array('search' => $GLOBALS['_search'])); |
---|
| 223 | $core->callBehavior('publicBeforeSearchCount',$params); |
---|
| 224 | $GLOBALS['_search_count'] = $core->blog->getPosts($params,true)->f(0); |
---|
| 225 | } |
---|
[2566] | 226 | |
---|
[0] | 227 | self::serveDocument('search.html'); |
---|
| 228 | } |
---|
[2566] | 229 | |
---|
[0] | 230 | public static function lang($args) |
---|
| 231 | { |
---|
| 232 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 233 | $core =& $GLOBALS['core']; |
---|
[2566] | 234 | |
---|
[0] | 235 | $n = self::getPageNumber($args); |
---|
[306] | 236 | $params = new ArrayObject(array( |
---|
| 237 | 'lang' => $args)); |
---|
[2566] | 238 | |
---|
[306] | 239 | $core->callBehavior('publicLangBeforeGetLangs',$params,$args); |
---|
[2566] | 240 | |
---|
[0] | 241 | $_ctx->langs = $core->blog->getLangs($params); |
---|
[2566] | 242 | |
---|
[0] | 243 | if ($_ctx->langs->isEmpty()) { |
---|
| 244 | # The specified language does not exist. |
---|
| 245 | self::p404(); |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
| 249 | if ($n) { |
---|
| 250 | $GLOBALS['_page_number'] = $n; |
---|
| 251 | } |
---|
| 252 | $_ctx->cur_lang = $args; |
---|
| 253 | self::home(null); |
---|
| 254 | } |
---|
| 255 | } |
---|
[2566] | 256 | |
---|
[0] | 257 | public static function category($args) |
---|
| 258 | { |
---|
| 259 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 260 | $core =& $GLOBALS['core']; |
---|
[2566] | 261 | |
---|
[0] | 262 | $n = self::getPageNumber($args); |
---|
[2566] | 263 | |
---|
[0] | 264 | if ($args == '' && !$n) { |
---|
| 265 | # No category was specified. |
---|
| 266 | self::p404(); |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
[306] | 270 | $params = new ArrayObject(array( |
---|
| 271 | 'cat_url' => $args, |
---|
[1610] | 272 | 'post_type' => 'post', |
---|
| 273 | 'without_empty' => false)); |
---|
[2566] | 274 | |
---|
[306] | 275 | $core->callBehavior('publicCategoryBeforeGetCategories',$params,$args); |
---|
[2566] | 276 | |
---|
[0] | 277 | $_ctx->categories = $core->blog->getCategories($params); |
---|
[2566] | 278 | |
---|
[0] | 279 | if ($_ctx->categories->isEmpty()) { |
---|
| 280 | # The specified category does no exist. |
---|
| 281 | self::p404(); |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | if ($n) { |
---|
| 286 | $GLOBALS['_page_number'] = $n; |
---|
| 287 | } |
---|
| 288 | self::serveDocument('category.html'); |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | } |
---|
[2566] | 292 | |
---|
[0] | 293 | public static function archive($args) |
---|
| 294 | { |
---|
| 295 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 296 | $core =& $GLOBALS['core']; |
---|
[2566] | 297 | |
---|
[0] | 298 | $year = $month = $cat_url = null; |
---|
| 299 | # Nothing or year and month |
---|
| 300 | if ($args == '') |
---|
| 301 | { |
---|
| 302 | self::serveDocument('archive.html'); |
---|
| 303 | } |
---|
| 304 | elseif (preg_match('|^/([0-9]{4})/([0-9]{2})$|',$args,$m)) |
---|
| 305 | { |
---|
[306] | 306 | $params = new ArrayObject(array( |
---|
| 307 | 'year' => $m[1], |
---|
| 308 | 'month' => $m[2], |
---|
| 309 | 'type' => 'month')); |
---|
[2566] | 310 | |
---|
[306] | 311 | $core->callBehavior('publicArchiveBeforeGetDates',$params,$args); |
---|
[2566] | 312 | |
---|
[0] | 313 | $_ctx->archives = $core->blog->getDates($params); |
---|
[2566] | 314 | |
---|
[0] | 315 | if ($_ctx->archives->isEmpty()) { |
---|
| 316 | # There is no entries for the specified period. |
---|
| 317 | self::p404(); |
---|
| 318 | } |
---|
| 319 | else |
---|
| 320 | { |
---|
| 321 | self::serveDocument('archive_month.html'); |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | else { |
---|
| 325 | # The specified URL is not a date. |
---|
| 326 | self::p404(); |
---|
| 327 | } |
---|
| 328 | } |
---|
[2566] | 329 | |
---|
[0] | 330 | public static function post($args) |
---|
| 331 | { |
---|
| 332 | if ($args == '') { |
---|
| 333 | # No entry was specified. |
---|
| 334 | self::p404(); |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
| 338 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 339 | $core =& $GLOBALS['core']; |
---|
[2566] | 340 | |
---|
[0] | 341 | $core->blog->withoutPassword(false); |
---|
[2566] | 342 | |
---|
[306] | 343 | $params = new ArrayObject(array( |
---|
| 344 | 'post_url' => $args)); |
---|
[2566] | 345 | |
---|
[306] | 346 | $core->callBehavior('publicPostBeforeGetPosts',$params,$args); |
---|
| 347 | |
---|
[0] | 348 | $_ctx->posts = $core->blog->getPosts($params); |
---|
[2566] | 349 | |
---|
[0] | 350 | $_ctx->comment_preview = new ArrayObject(); |
---|
| 351 | $_ctx->comment_preview['content'] = ''; |
---|
| 352 | $_ctx->comment_preview['rawcontent'] = ''; |
---|
| 353 | $_ctx->comment_preview['name'] = ''; |
---|
| 354 | $_ctx->comment_preview['mail'] = ''; |
---|
| 355 | $_ctx->comment_preview['site'] = ''; |
---|
| 356 | $_ctx->comment_preview['preview'] = false; |
---|
| 357 | $_ctx->comment_preview['remember'] = false; |
---|
[2566] | 358 | |
---|
[0] | 359 | $core->blog->withoutPassword(true); |
---|
[2566] | 360 | |
---|
[0] | 361 | if ($_ctx->posts->isEmpty()) |
---|
| 362 | { |
---|
| 363 | # The specified entry does not exist. |
---|
| 364 | self::p404(); |
---|
| 365 | } |
---|
| 366 | else |
---|
| 367 | { |
---|
| 368 | $post_id = $_ctx->posts->post_id; |
---|
| 369 | $post_password = $_ctx->posts->post_password; |
---|
[2566] | 370 | |
---|
[0] | 371 | # Password protected entry |
---|
| 372 | if ($post_password != '' && !$_ctx->preview) |
---|
| 373 | { |
---|
| 374 | # Get passwords cookie |
---|
| 375 | if (isset($_COOKIE['dc_passwd'])) { |
---|
[2634] | 376 | $pwd_cookie = json_decode($_COOKIE['dc_passwd']); |
---|
| 377 | if ($pwd_cookie === NULL) { |
---|
| 378 | $pwd_cookie = array(); |
---|
| 379 | } else { |
---|
| 380 | $pwd_cookie = (array) $pwd_cookie; |
---|
| 381 | } |
---|
[0] | 382 | } else { |
---|
| 383 | $pwd_cookie = array(); |
---|
| 384 | } |
---|
[2566] | 385 | |
---|
[0] | 386 | # Check for match |
---|
| 387 | if ((!empty($_POST['password']) && $_POST['password'] == $post_password) |
---|
| 388 | || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password)) |
---|
| 389 | { |
---|
| 390 | $pwd_cookie[$post_id] = $post_password; |
---|
[2634] | 391 | setcookie('dc_passwd',json_encode($pwd_cookie),0,'/'); |
---|
[0] | 392 | } |
---|
| 393 | else |
---|
| 394 | { |
---|
| 395 | self::serveDocument('password-form.html','text/html',false); |
---|
| 396 | return; |
---|
| 397 | } |
---|
| 398 | } |
---|
[2566] | 399 | |
---|
[0] | 400 | $post_comment = |
---|
| 401 | isset($_POST['c_name']) && isset($_POST['c_mail']) && |
---|
| 402 | isset($_POST['c_site']) && isset($_POST['c_content']) && |
---|
| 403 | $_ctx->posts->commentsActive(); |
---|
[2566] | 404 | |
---|
[0] | 405 | # Posting a comment |
---|
| 406 | if ($post_comment) |
---|
| 407 | { |
---|
| 408 | # Spam trap |
---|
| 409 | if (!empty($_POST['f_mail'])) { |
---|
| 410 | http::head(412,'Precondition Failed'); |
---|
| 411 | header('Content-Type: text/plain'); |
---|
| 412 | echo "So Long, and Thanks For All the Fish"; |
---|
| 413 | # Exits immediately the application to preserve the server. |
---|
| 414 | exit; |
---|
| 415 | } |
---|
[2566] | 416 | |
---|
[0] | 417 | $name = $_POST['c_name']; |
---|
| 418 | $mail = $_POST['c_mail']; |
---|
| 419 | $site = $_POST['c_site']; |
---|
| 420 | $content = $_POST['c_content']; |
---|
| 421 | $preview = !empty($_POST['preview']); |
---|
[2566] | 422 | |
---|
[0] | 423 | if ($content != '') |
---|
| 424 | { |
---|
[2585] | 425 | # --BEHAVIOR-- publicBeforeCommentTransform |
---|
| 426 | $buffer = $core->callBehavior('publicBeforeCommentTransform',$content); |
---|
| 427 | if ($buffer != '') { |
---|
| 428 | $content = $buffer; |
---|
[0] | 429 | } else { |
---|
[2585] | 430 | if ($core->blog->settings->system->wiki_comments) { |
---|
| 431 | $core->initWikiComment(); |
---|
| 432 | } else { |
---|
| 433 | $core->initWikiSimpleComment(); |
---|
| 434 | } |
---|
| 435 | $content = $core->wikiTransform($content); |
---|
[0] | 436 | } |
---|
| 437 | $content = $core->HTMLfilter($content); |
---|
| 438 | } |
---|
[2566] | 439 | |
---|
[0] | 440 | $_ctx->comment_preview['content'] = $content; |
---|
| 441 | $_ctx->comment_preview['rawcontent'] = $_POST['c_content']; |
---|
| 442 | $_ctx->comment_preview['name'] = $name; |
---|
| 443 | $_ctx->comment_preview['mail'] = $mail; |
---|
| 444 | $_ctx->comment_preview['site'] = $site; |
---|
[2566] | 445 | |
---|
[0] | 446 | if ($preview) |
---|
| 447 | { |
---|
| 448 | # --BEHAVIOR-- publicBeforeCommentPreview |
---|
| 449 | $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview); |
---|
[2566] | 450 | |
---|
[0] | 451 | $_ctx->comment_preview['preview'] = true; |
---|
| 452 | } |
---|
| 453 | else |
---|
| 454 | { |
---|
| 455 | # Post the comment |
---|
| 456 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
| 457 | $cur->comment_author = $name; |
---|
| 458 | $cur->comment_site = html::clean($site); |
---|
| 459 | $cur->comment_email = html::clean($mail); |
---|
| 460 | $cur->comment_content = $content; |
---|
| 461 | $cur->post_id = $_ctx->posts->post_id; |
---|
| 462 | $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1; |
---|
| 463 | $cur->comment_ip = http::realIP(); |
---|
[2566] | 464 | |
---|
[0] | 465 | $redir = $_ctx->posts->getURL(); |
---|
[303] | 466 | $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?'; |
---|
[2566] | 467 | |
---|
[0] | 468 | try |
---|
| 469 | { |
---|
| 470 | if (!text::isEmail($cur->comment_email)) { |
---|
| 471 | throw new Exception(__('You must provide a valid email address.')); |
---|
| 472 | } |
---|
[2566] | 473 | |
---|
[0] | 474 | # --BEHAVIOR-- publicBeforeCommentCreate |
---|
| 475 | $core->callBehavior('publicBeforeCommentCreate',$cur); |
---|
[2566] | 476 | if ($cur->post_id) { |
---|
[0] | 477 | $comment_id = $core->blog->addComment($cur); |
---|
[2566] | 478 | |
---|
[0] | 479 | # --BEHAVIOR-- publicAfterCommentCreate |
---|
| 480 | $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id); |
---|
| 481 | } |
---|
[2566] | 482 | |
---|
[0] | 483 | if ($cur->comment_status == 1) { |
---|
| 484 | $redir_arg = 'pub=1'; |
---|
| 485 | } else { |
---|
| 486 | $redir_arg = 'pub=0'; |
---|
| 487 | } |
---|
[2566] | 488 | |
---|
[0] | 489 | header('Location: '.$redir.$redir_arg); |
---|
| 490 | } |
---|
| 491 | catch (Exception $e) |
---|
| 492 | { |
---|
| 493 | $_ctx->form_error = $e->getMessage(); |
---|
| 494 | $_ctx->form_error; |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | } |
---|
[2566] | 498 | |
---|
[0] | 499 | # The entry |
---|
[1674] | 500 | if ($_ctx->posts->trackbacksActive()) { |
---|
| 501 | header('X-Pingback: '.$core->blog->url.$core->url->getURLFor("xmlrpc",$core->blog->id)); |
---|
| 502 | } |
---|
[0] | 503 | self::serveDocument('post.html'); |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | } |
---|
[2566] | 507 | |
---|
[0] | 508 | public static function preview($args) |
---|
| 509 | { |
---|
| 510 | $core = $GLOBALS['core']; |
---|
| 511 | $_ctx = $GLOBALS['_ctx']; |
---|
[2566] | 512 | |
---|
[0] | 513 | if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) { |
---|
| 514 | # The specified Preview URL is malformed. |
---|
| 515 | self::p404(); |
---|
| 516 | } |
---|
| 517 | else |
---|
| 518 | { |
---|
| 519 | $user_id = $m[1]; |
---|
| 520 | $user_key = $m[2]; |
---|
| 521 | $post_url = $m[3]; |
---|
| 522 | if (!$core->auth->checkUser($user_id,null,$user_key)) { |
---|
| 523 | # The user has no access to the entry. |
---|
| 524 | self::p404(); |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | { |
---|
| 528 | $_ctx->preview = true; |
---|
| 529 | self::post($post_url); |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | } |
---|
[2566] | 533 | |
---|
[0] | 534 | public static function feed($args) |
---|
| 535 | { |
---|
| 536 | $type = null; |
---|
| 537 | $comments = false; |
---|
| 538 | $cat_url = false; |
---|
| 539 | $post_id = null; |
---|
| 540 | $subtitle = ''; |
---|
[2566] | 541 | |
---|
[0] | 542 | $mime = 'application/xml'; |
---|
[2566] | 543 | |
---|
[0] | 544 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 545 | $core =& $GLOBALS['core']; |
---|
[2566] | 546 | |
---|
[0] | 547 | if (preg_match('!^([a-z]{2}(-[a-z]{2})?)/(.*)$!',$args,$m)) { |
---|
[306] | 548 | $params = new ArrayObject(array('lang' => $m[1])); |
---|
[2566] | 549 | |
---|
[0] | 550 | $args = $m[3]; |
---|
[2566] | 551 | |
---|
[306] | 552 | $core->callBehavior('publicFeedBeforeGetLangs',$params,$args); |
---|
[2566] | 553 | |
---|
[0] | 554 | $_ctx->langs = $core->blog->getLangs($params); |
---|
[2566] | 555 | |
---|
[0] | 556 | if ($_ctx->langs->isEmpty()) { |
---|
| 557 | # The specified language does not exist. |
---|
| 558 | self::p404(); |
---|
| 559 | return; |
---|
| 560 | } else { |
---|
| 561 | $_ctx->cur_lang = $m[1]; |
---|
| 562 | } |
---|
| 563 | } |
---|
[2566] | 564 | |
---|
[0] | 565 | if (preg_match('#^rss2/xslt$#',$args,$m)) |
---|
| 566 | { |
---|
| 567 | # RSS XSLT stylesheet |
---|
| 568 | self::serveDocument('rss2.xsl','text/xml'); |
---|
| 569 | return; |
---|
| 570 | } |
---|
| 571 | elseif (preg_match('#^(atom|rss2)/comments/([0-9]+)$#',$args,$m)) |
---|
| 572 | { |
---|
| 573 | # Post comments feed |
---|
| 574 | $type = $m[1]; |
---|
| 575 | $comments = true; |
---|
| 576 | $post_id = (integer) $m[2]; |
---|
| 577 | } |
---|
| 578 | elseif (preg_match('#^(?:category/(.+)/)?(atom|rss2)(/comments)?$#',$args,$m)) |
---|
| 579 | { |
---|
| 580 | # All posts or comments feed |
---|
| 581 | $type = $m[2]; |
---|
| 582 | $comments = !empty($m[3]); |
---|
| 583 | if (!empty($m[1])) { |
---|
| 584 | $cat_url = $m[1]; |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | else |
---|
| 588 | { |
---|
| 589 | # The specified Feed URL is malformed. |
---|
| 590 | self::p404(); |
---|
| 591 | return; |
---|
| 592 | } |
---|
[2566] | 593 | |
---|
[0] | 594 | if ($cat_url) |
---|
| 595 | { |
---|
[306] | 596 | $params = new ArrayObject(array( |
---|
| 597 | 'cat_url' => $cat_url, |
---|
| 598 | 'post_type' => 'post')); |
---|
[2566] | 599 | |
---|
[306] | 600 | $core->callBehavior('publicFeedBeforeGetCategories',$params,$args); |
---|
[2566] | 601 | |
---|
[0] | 602 | $_ctx->categories = $core->blog->getCategories($params); |
---|
[2566] | 603 | |
---|
[0] | 604 | if ($_ctx->categories->isEmpty()) { |
---|
| 605 | # The specified category does no exist. |
---|
| 606 | self::p404(); |
---|
| 607 | return; |
---|
| 608 | } |
---|
[2566] | 609 | |
---|
[0] | 610 | $subtitle = ' - '.$_ctx->categories->cat_title; |
---|
| 611 | } |
---|
| 612 | elseif ($post_id) |
---|
| 613 | { |
---|
[306] | 614 | $params = new ArrayObject(array( |
---|
| 615 | 'post_id' => $post_id, |
---|
| 616 | 'post_type' => '')); |
---|
[2566] | 617 | |
---|
[306] | 618 | $core->callBehavior('publicFeedBeforeGetPosts',$params,$args); |
---|
[2566] | 619 | |
---|
[0] | 620 | $_ctx->posts = $core->blog->getPosts($params); |
---|
[2566] | 621 | |
---|
[0] | 622 | if ($_ctx->posts->isEmpty()) { |
---|
| 623 | # The specified post does not exist. |
---|
| 624 | self::p404(); |
---|
| 625 | return; |
---|
| 626 | } |
---|
[2566] | 627 | |
---|
[0] | 628 | $subtitle = ' - '.$_ctx->posts->post_title; |
---|
| 629 | } |
---|
[2566] | 630 | |
---|
[0] | 631 | $tpl = $type; |
---|
| 632 | if ($comments) { |
---|
| 633 | $tpl .= '-comments'; |
---|
| 634 | $_ctx->nb_comment_per_page = $core->blog->settings->system->nb_comment_per_feed; |
---|
| 635 | } else { |
---|
| 636 | $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed; |
---|
| 637 | $_ctx->short_feed_items = $core->blog->settings->system->short_feed_items; |
---|
| 638 | } |
---|
| 639 | $tpl .= '.xml'; |
---|
[2566] | 640 | |
---|
[0] | 641 | if ($type == 'atom') { |
---|
| 642 | $mime = 'application/atom+xml'; |
---|
| 643 | } |
---|
[2566] | 644 | |
---|
[0] | 645 | $_ctx->feed_subtitle = $subtitle; |
---|
[2566] | 646 | |
---|
[0] | 647 | header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->system->robots_policy,'')); |
---|
| 648 | self::serveDocument($tpl,$mime); |
---|
| 649 | if (!$comments && !$cat_url) { |
---|
| 650 | $core->blog->publishScheduledEntries(); |
---|
| 651 | } |
---|
| 652 | } |
---|
[2566] | 653 | |
---|
[0] | 654 | public static function trackback($args) |
---|
| 655 | { |
---|
| 656 | if (!preg_match('/^[0-9]+$/',$args)) { |
---|
| 657 | # The specified trackback URL is not an number |
---|
| 658 | self::p404(); |
---|
| 659 | } else { |
---|
| 660 | $tb = new dcTrackback($GLOBALS['core']); |
---|
| 661 | $tb->receive($args); |
---|
| 662 | } |
---|
| 663 | } |
---|
[2566] | 664 | |
---|
[0] | 665 | public static function rsd($args) |
---|
| 666 | { |
---|
| 667 | $core =& $GLOBALS['core']; |
---|
| 668 | http::cache($GLOBALS['mod_files'],$GLOBALS['mod_ts']); |
---|
[2566] | 669 | |
---|
[0] | 670 | header('Content-Type: text/xml; charset=UTF-8'); |
---|
| 671 | echo |
---|
| 672 | '<?xml version="1.0" encoding="UTF-8"?>'."\n". |
---|
| 673 | '<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">'."\n". |
---|
| 674 | "<service>\n". |
---|
| 675 | " <engineName>Dotclear</engineName>\n". |
---|
| 676 | " <engineLink>http://www.dotclear.org/</engineLink>\n". |
---|
| 677 | ' <homePageLink>'.html::escapeHTML($core->blog->url)."</homePageLink>\n"; |
---|
[2566] | 678 | |
---|
[0] | 679 | if ($core->blog->settings->system->enable_xmlrpc) |
---|
| 680 | { |
---|
| 681 | $u = sprintf(DC_XMLRPC_URL,$core->blog->url,$core->blog->id); |
---|
[2566] | 682 | |
---|
[0] | 683 | echo |
---|
| 684 | " <apis>\n". |
---|
| 685 | ' <api name="WordPress" blogID="1" preferred="true" apiLink="'.$u.'"/>'."\n". |
---|
| 686 | ' <api name="Movable Type" blogID="1" preferred="false" apiLink="'.$u.'"/>'."\n". |
---|
| 687 | ' <api name="MetaWeblog" blogID="1" preferred="false" apiLink="'.$u.'"/>'."\n". |
---|
| 688 | ' <api name="Blogger" blogID="1" preferred="false" apiLink="'.$u.'"/>'."\n". |
---|
| 689 | " </apis>\n"; |
---|
| 690 | } |
---|
[2566] | 691 | |
---|
[0] | 692 | echo |
---|
| 693 | "</service>\n". |
---|
| 694 | "</rsd>\n"; |
---|
| 695 | } |
---|
[2566] | 696 | |
---|
[0] | 697 | public static function xmlrpc($args) |
---|
| 698 | { |
---|
| 699 | $core =& $GLOBALS['core']; |
---|
| 700 | $blog_id = preg_replace('#^([^/]*).*#','$1',$args); |
---|
| 701 | $server = new dcXmlRpc($core,$blog_id); |
---|
| 702 | $server->serve(); |
---|
| 703 | } |
---|
| 704 | } |
---|