Changeset 2566:9bf417837888 for inc/public/lib.urlhandlers.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/public/lib.urlhandlers.php
r1674 r2566 15 15 { 16 16 public $args; 17 17 18 18 public function getURLFor($type,$value='') { 19 19 $core =& $GLOBALS['core']; … … 30 30 return $url; 31 31 } 32 32 33 33 public function register($type,$url,$representation,$handler) 34 34 { … … 38 38 parent::register($t[0],$t[1],$t[2],$t[3]); 39 39 } 40 40 41 41 public static function p404() 42 42 { 43 43 throw new Exception ("Page not found",404); 44 44 } 45 45 46 46 public static function default404($args,$type,$e) 47 47 { … … 51 51 $_ctx =& $GLOBALS['_ctx']; 52 52 $core = $GLOBALS['core']; 53 53 54 54 header('Content-Type: text/html; charset=UTF-8'); 55 55 http::head(404,'Not Found'); … … 57 57 $_ctx->current_tpl = '404.html'; 58 58 $_ctx->content_type = 'text/html'; 59 59 60 60 echo $core->tpl->getData($_ctx->current_tpl); 61 61 62 62 # --BEHAVIOR-- publicAfterDocument 63 63 $core->callBehavior('publicAfterDocument',$core); 64 64 exit; 65 65 } 66 66 67 67 protected static function getPageNumber(&$args) 68 68 { … … 74 74 } 75 75 } 76 76 77 77 return false; 78 78 } 79 79 80 80 protected static function serveDocument($tpl,$content_type='text/html',$http_cache=true,$http_etag=true) 81 81 { 82 82 $_ctx =& $GLOBALS['_ctx']; 83 83 $core =& $GLOBALS['core']; 84 84 85 85 if ($_ctx->nb_entry_per_page === null) { 86 86 $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_page; 87 87 } 88 88 89 89 $tpl_file = $core->tpl->getFilePath($tpl); 90 90 91 91 if (!$tpl_file) { 92 92 throw new Exception('Unable to find template '); 93 93 } 94 94 95 95 $result = new ArrayObject; 96 96 97 97 $_ctx->current_tpl = $tpl; 98 98 $_ctx->content_type = $content_type; … … 100 100 $_ctx->http_etag = $http_etag; 101 101 $core->callBehavior('urlHandlerBeforeGetData',$_ctx); 102 102 103 103 if ($_ctx->http_cache) { 104 104 $GLOBALS['mod_files'][] = $tpl_file; … … 111 111 $result['tpl'] = $_ctx->current_tpl; 112 112 $result['blogupddt'] = $core->blog->upddt; 113 113 114 114 # --BEHAVIOR-- urlHandlerServeDocument 115 115 $core->callBehavior('urlHandlerServeDocument',$result); 116 116 117 117 if ($_ctx->http_cache && $_ctx->http_etag) { 118 118 http::etag($result['content'],http::getSelfURI()); … … 120 120 echo $result['content']; 121 121 } 122 122 123 123 public function getDocument() 124 124 { 125 125 $core =& $GLOBALS['core']; 126 126 127 127 $type = $args = ''; 128 128 129 129 if ($this->mode == 'path_info') 130 130 { … … 134 134 { 135 135 $part = ''; 136 136 137 137 $qs = $this->parseQueryString(); 138 138 139 139 # Recreates some _GET and _REQUEST pairs 140 140 if (!empty($qs)) … … 147 147 $_GET = $qs; 148 148 $_REQUEST = array_merge($qs,$_REQUEST); 149 149 150 150 list($k,$v) = each($qs); 151 151 if ($v === null) { … … 156 156 } 157 157 } 158 158 159 159 $_SERVER['URL_REQUEST_PART'] = $part; 160 160 161 161 $this->getArgs($part,$type,$this->args); 162 162 163 163 # --BEHAVIOR-- urlHandlerGetArgsDocument 164 164 $core->callBehavior('urlHandlerGetArgsDocument',$this); 165 165 166 166 if (!$type) 167 167 { … … 175 175 } 176 176 } 177 177 178 178 public static function home($args) 179 179 { 180 180 $n = self::getPageNumber($args); 181 181 182 182 if ($args && !$n) 183 183 { 184 # "Then specified URL went unrecognized by all URL handlers and 184 # "Then specified URL went unrecognized by all URL handlers and 185 185 # defaults to the home page, but is not a page number. 186 186 self::p404(); … … 189 189 { 190 190 $core =& $GLOBALS['core']; 191 191 192 192 if ($n) { 193 193 $GLOBALS['_page_number'] = $n; 194 194 $core->url->type = $n > 1 ? 'default-page' : 'default'; 195 195 } 196 196 197 197 if (empty($_GET['q'])) { 198 198 self::serveDocument('home.html'); … … 203 203 } 204 204 } 205 205 206 206 public static function search() 207 207 { 208 208 $_ctx =& $GLOBALS['_ctx']; 209 209 $core =& $GLOBALS['core']; 210 210 211 211 $core->url->type='search'; 212 212 213 213 $GLOBALS['_search'] = !empty($_GET['q']) ? rawurldecode($_GET['q']) : ''; 214 214 if ($GLOBALS['_search']) { … … 217 217 $GLOBALS['_search_count'] = $core->blog->getPosts($params,true)->f(0); 218 218 } 219 219 220 220 self::serveDocument('search.html'); 221 221 } 222 222 223 223 public static function lang($args) 224 224 { 225 225 $_ctx =& $GLOBALS['_ctx']; 226 226 $core =& $GLOBALS['core']; 227 227 228 228 $n = self::getPageNumber($args); 229 229 $params = new ArrayObject(array( 230 230 'lang' => $args)); 231 231 232 232 $core->callBehavior('publicLangBeforeGetLangs',$params,$args); 233 233 234 234 $_ctx->langs = $core->blog->getLangs($params); 235 235 236 236 if ($_ctx->langs->isEmpty()) { 237 237 # The specified language does not exist. … … 247 247 } 248 248 } 249 249 250 250 public static function category($args) 251 251 { 252 252 $_ctx =& $GLOBALS['_ctx']; 253 253 $core =& $GLOBALS['core']; 254 254 255 255 $n = self::getPageNumber($args); 256 256 257 257 if ($args == '' && !$n) { 258 258 # No category was specified. … … 265 265 'post_type' => 'post', 266 266 'without_empty' => false)); 267 267 268 268 $core->callBehavior('publicCategoryBeforeGetCategories',$params,$args); 269 269 270 270 $_ctx->categories = $core->blog->getCategories($params); 271 271 272 272 if ($_ctx->categories->isEmpty()) { 273 273 # The specified category does no exist. … … 283 283 } 284 284 } 285 285 286 286 public static function archive($args) 287 287 { 288 288 $_ctx =& $GLOBALS['_ctx']; 289 289 $core =& $GLOBALS['core']; 290 290 291 291 $year = $month = $cat_url = null; 292 292 # Nothing or year and month … … 301 301 'month' => $m[2], 302 302 'type' => 'month')); 303 303 304 304 $core->callBehavior('publicArchiveBeforeGetDates',$params,$args); 305 305 306 306 $_ctx->archives = $core->blog->getDates($params); 307 307 308 308 if ($_ctx->archives->isEmpty()) { 309 309 # There is no entries for the specified period. … … 320 320 } 321 321 } 322 322 323 323 public static function post($args) 324 324 { … … 331 331 $_ctx =& $GLOBALS['_ctx']; 332 332 $core =& $GLOBALS['core']; 333 333 334 334 $core->blog->withoutPassword(false); 335 335 336 336 $params = new ArrayObject(array( 337 337 'post_url' => $args)); 338 338 339 339 $core->callBehavior('publicPostBeforeGetPosts',$params,$args); 340 340 341 341 $_ctx->posts = $core->blog->getPosts($params); 342 342 343 343 $_ctx->comment_preview = new ArrayObject(); 344 344 $_ctx->comment_preview['content'] = ''; … … 349 349 $_ctx->comment_preview['preview'] = false; 350 350 $_ctx->comment_preview['remember'] = false; 351 351 352 352 $core->blog->withoutPassword(true); 353 353 354 354 if ($_ctx->posts->isEmpty()) 355 355 { … … 361 361 $post_id = $_ctx->posts->post_id; 362 362 $post_password = $_ctx->posts->post_password; 363 363 364 364 # Password protected entry 365 365 if ($post_password != '' && !$_ctx->preview) … … 371 371 $pwd_cookie = array(); 372 372 } 373 373 374 374 # Check for match 375 375 if ((!empty($_POST['password']) && $_POST['password'] == $post_password) … … 385 385 } 386 386 } 387 387 388 388 $post_comment = 389 389 isset($_POST['c_name']) && isset($_POST['c_mail']) && 390 390 isset($_POST['c_site']) && isset($_POST['c_content']) && 391 391 $_ctx->posts->commentsActive(); 392 392 393 393 # Posting a comment 394 394 if ($post_comment) … … 402 402 exit; 403 403 } 404 404 405 405 $name = $_POST['c_name']; 406 406 $mail = $_POST['c_mail']; … … 408 408 $content = $_POST['c_content']; 409 409 $preview = !empty($_POST['preview']); 410 410 411 411 if ($content != '') 412 412 { … … 419 419 $content = $core->HTMLfilter($content); 420 420 } 421 421 422 422 $_ctx->comment_preview['content'] = $content; 423 423 $_ctx->comment_preview['rawcontent'] = $_POST['c_content']; … … 425 425 $_ctx->comment_preview['mail'] = $mail; 426 426 $_ctx->comment_preview['site'] = $site; 427 427 428 428 if ($preview) 429 429 { 430 430 # --BEHAVIOR-- publicBeforeCommentPreview 431 431 $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview); 432 432 433 433 $_ctx->comment_preview['preview'] = true; 434 434 } … … 444 444 $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1; 445 445 $cur->comment_ip = http::realIP(); 446 446 447 447 $redir = $_ctx->posts->getURL(); 448 448 $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?'; 449 449 450 450 try 451 451 { … … 453 453 throw new Exception(__('You must provide a valid email address.')); 454 454 } 455 455 456 456 # --BEHAVIOR-- publicBeforeCommentCreate 457 457 $core->callBehavior('publicBeforeCommentCreate',$cur); 458 if ($cur->post_id) { 458 if ($cur->post_id) { 459 459 $comment_id = $core->blog->addComment($cur); 460 460 461 461 # --BEHAVIOR-- publicAfterCommentCreate 462 462 $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id); 463 463 } 464 464 465 465 if ($cur->comment_status == 1) { 466 466 $redir_arg = 'pub=1'; … … 468 468 $redir_arg = 'pub=0'; 469 469 } 470 470 471 471 header('Location: '.$redir.$redir_arg); 472 472 } … … 478 478 } 479 479 } 480 480 481 481 # The entry 482 482 if ($_ctx->posts->trackbacksActive()) { … … 487 487 } 488 488 } 489 489 490 490 public static function preview($args) 491 491 { 492 492 $core = $GLOBALS['core']; 493 493 $_ctx = $GLOBALS['_ctx']; 494 494 495 495 if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) { 496 496 # The specified Preview URL is malformed. … … 513 513 } 514 514 } 515 515 516 516 public static function feed($args) 517 517 { … … 521 521 $post_id = null; 522 522 $subtitle = ''; 523 523 524 524 $mime = 'application/xml'; 525 525 526 526 $_ctx =& $GLOBALS['_ctx']; 527 527 $core =& $GLOBALS['core']; 528 528 529 529 if (preg_match('!^([a-z]{2}(-[a-z]{2})?)/(.*)$!',$args,$m)) { 530 530 $params = new ArrayObject(array('lang' => $m[1])); 531 531 532 532 $args = $m[3]; 533 533 534 534 $core->callBehavior('publicFeedBeforeGetLangs',$params,$args); 535 535 536 536 $_ctx->langs = $core->blog->getLangs($params); 537 537 538 538 if ($_ctx->langs->isEmpty()) { 539 539 # The specified language does not exist. … … 544 544 } 545 545 } 546 546 547 547 if (preg_match('#^rss2/xslt$#',$args,$m)) 548 548 { … … 573 573 return; 574 574 } 575 575 576 576 if ($cat_url) 577 577 { … … 579 579 'cat_url' => $cat_url, 580 580 'post_type' => 'post')); 581 581 582 582 $core->callBehavior('publicFeedBeforeGetCategories',$params,$args); 583 583 584 584 $_ctx->categories = $core->blog->getCategories($params); 585 585 586 586 if ($_ctx->categories->isEmpty()) { 587 587 # The specified category does no exist. … … 589 589 return; 590 590 } 591 591 592 592 $subtitle = ' - '.$_ctx->categories->cat_title; 593 593 } … … 597 597 'post_id' => $post_id, 598 598 'post_type' => '')); 599 599 600 600 $core->callBehavior('publicFeedBeforeGetPosts',$params,$args); 601 601 602 602 $_ctx->posts = $core->blog->getPosts($params); 603 603 604 604 if ($_ctx->posts->isEmpty()) { 605 605 # The specified post does not exist. … … 607 607 return; 608 608 } 609 609 610 610 $subtitle = ' - '.$_ctx->posts->post_title; 611 611 } 612 612 613 613 $tpl = $type; 614 614 if ($comments) { … … 620 620 } 621 621 $tpl .= '.xml'; 622 622 623 623 if ($type == 'atom') { 624 624 $mime = 'application/atom+xml'; 625 625 } 626 626 627 627 $_ctx->feed_subtitle = $subtitle; 628 628 629 629 header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->system->robots_policy,'')); 630 630 self::serveDocument($tpl,$mime); … … 633 633 } 634 634 } 635 635 636 636 public static function trackback($args) 637 637 { … … 644 644 } 645 645 } 646 646 647 647 public static function rsd($args) 648 648 { 649 649 $core =& $GLOBALS['core']; 650 650 http::cache($GLOBALS['mod_files'],$GLOBALS['mod_ts']); 651 651 652 652 header('Content-Type: text/xml; charset=UTF-8'); 653 653 echo … … 658 658 " <engineLink>http://www.dotclear.org/</engineLink>\n". 659 659 ' <homePageLink>'.html::escapeHTML($core->blog->url)."</homePageLink>\n"; 660 660 661 661 if ($core->blog->settings->system->enable_xmlrpc) 662 662 { 663 663 $u = sprintf(DC_XMLRPC_URL,$core->blog->url,$core->blog->id); 664 664 665 665 echo 666 666 " <apis>\n". … … 671 671 " </apis>\n"; 672 672 } 673 673 674 674 echo 675 675 "</service>\n". 676 676 "</rsd>\n"; 677 677 } 678 678 679 679 public static function xmlrpc($args) 680 680 { … … 685 685 } 686 686 } 687 ?>
Note: See TracChangeset
for help on using the changeset viewer.