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