[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file loads and initializes the blog to be displayed. 4 * 5 * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}. 9 * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}. 10 * 11 * @license http://b2evolution.net/about/license.html GNU General Public License (GPL) 12 * 13 * {@internal Open Source relicensing agreement: 14 * Daniel HAHLER grants Francois PLANQUE the right to license 15 * Daniel HAHLER's contributions to this file and the b2evolution project 16 * under any OSI approved OSS license (http://www.opensource.org/licenses/). 17 * }} 18 * 19 * @package main 20 * 21 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 22 * @author blueyed: Daniel HAHLER 23 * @author fplanque: Francois PLANQUE 24 * 25 * @version $Id: _blog_main.inc.php,v 1.88 2007/10/06 21:26:16 fplanque Exp $ 26 */ 27 28 if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' ); 29 30 /** 31 * Initialize everything: 32 */ 33 require_once dirname(__FILE__).'/_main.inc.php'; 34 35 load_funcs('skins/_skin.funcs.php'); 36 load_class('items/model/_itemlist.class.php'); 37 38 $Timer->start( '_blog_main.inc' ); 39 40 // Getting GET or POST parameters: 41 42 /* 43 * blog ID. This is a little bit special. 44 * If it has been explicitely memorized already, we don't touch it. 45 * Note: explicitely != auto_register_globals != stub file just setting it with $blog=x 46 * Note: stub files should probably memorize the param explicitely! 47 */ 48 if( ! param_ismemorized('blog') ) 49 { // Not explicitely memorized yet, get param from GET or auto_register_globals OR a stub $blog = x: 50 $Debuglog->add( 'blog param not memorized before _blog_main.inc', 'params' ); 51 // We default to 0 here because the param should always be included in regenerate_url() when present. 52 // This will prevent weird indexing/search results in case the default changes after indexing. 53 // On some occasions, we'll manually filter it out of regenerate_url() because we know we go through a stub for example. 54 param( 'blog', 'integer', 0, true ); 55 } 56 57 // Getting current blog info: 58 $BlogCache = & get_Cache( 'BlogCache' ); 59 /** 60 * @var Blog 61 */ 62 $Blog = & $BlogCache->get_by_ID( $blog, false ); 63 if( empty( $Blog ) ) 64 { 65 require $skins_path.'_404_blog_not_found.main.php'; // error & exit 66 // EXIT. 67 } 68 69 /* 70 * _______________________________ Locale / Charset for the Blog _________________________________ 71 * 72 TODO: blueyed>> This should get moved as default to the locale detection in _main.inc.php, 73 as we only want to activate the I/O charset, which is probably the user's.. 74 It prevents using a locale/charset in the front office, apart from the one given as default for the blog!! 75 fp>there is no blog defined in _main and there should not be any 76 blueyed> Sure, but that means we should either split it, or use the locale here only, if there's no-one given with higher priority. 77 */ 78 // Activate matching locale: 79 $Debuglog->add( 'Activating blog locale: '.$Blog->get('locale'), 'locale' ); 80 locale_activate( $Blog->get('locale') ); 81 82 83 // Re-Init charset handling, in case current_charset has changed: 84 if( init_charsets( $current_charset ) ) 85 { 86 // Reload Blog(s) (for encoding of name, tagline etc): 87 $BlogCache->clear(); 88 89 $Blog = & $BlogCache->get_by_ID( $blog ); 90 } 91 92 93 /* 94 * _____________________________ Extra path info decoding ________________________________ 95 * 96 * This will translate extra path into 'regular' params. 97 * 98 * Decoding should try to work like this: 99 * 100 * baseurl/blog-urlname/junk/.../junk/post-title -> points to a single post (no ending slash) 101 * baseurl/blog-urlname/junk/.../junk/p142 -> points to a single post 102 * baseurl/blog-urlname/2006/ -> points to a yearly archive because of ending slash + 4 digits 103 * baseurl/blog-urlname/2006/12/ -> points to a monthly archive 104 * baseurl/blog-urlname/2006/12/31/ -> points to a daily archive 105 * baseurl/blog-urlname/2006/w53/ -> points to a weekly archive 106 * baseurl/blog-urlname/junk/.../junk/chap-urlname/ -> points to a single chapter/category (because of ending slash) 107 * Note: category names cannot be named like this [a-z][0-9]+ 108 */ 109 if( ! isset( $resolve_extra_path ) ) { $resolve_extra_path = true; } 110 if( $resolve_extra_path ) 111 { 112 // Check and Remove blog base URI from ReqPath: 113 $blog_baseuri = substr( $Blog->gen_baseurl(), strlen( $Blog->get('baseurlroot') ) ); 114 $Debuglog->add( 'blog_baseuri: "'.$blog_baseuri.'"', 'params' ); 115 116 if( ($pos = strpos( $ReqPath, $blog_baseuri )) !== false ) 117 { // note: $pos will typically be 0 118 $path_string = substr( $ReqPath, $pos+strlen( $blog_baseuri ) ); 119 120 $Debuglog->add( 'Extra path info found! path_string=' . $path_string , 'params' ); 121 //echo "path=[$path_string]<br />"; 122 123 // Slice the path: 124 $path_split = explode( '/', $path_string, 20 ); 125 126 // Remove empty slots: 127 $path_elements = array(); 128 foreach( $path_split as $path_element ) 129 { 130 if( !empty( $path_element ) ) 131 { 132 $path_elements[] = $path_element; 133 } 134 } 135 // pre_dump( $path_elements ); 136 137 if( isset( $path_elements[0] ) && preg_match( '#.*\.php[0-9]?$#', $path_elements[0] ) ) 138 { // Ignore element ending with .php (fp: note: may be just '.php') 139 array_shift( $path_elements ); 140 $Debuglog->add( 'Ignoring *.php in extra path info' , 'params' ); 141 } 142 143 if( isset( $path_elements[0] ) 144 && ( $path_elements[0] == $Blog->stub 145 || $path_elements[0] == $Blog->urlname ) ) 146 { // Ignore stub file (if it ends with .php it should already have been filtered out above) 147 array_shift( $path_elements ); 148 $Debuglog->add( 'Ignoring stub filename OR blog urlname in extra path info' , 'params' ); 149 } 150 // pre_dump( $path_elements ); 151 152 $path_error = 0; 153 154 // Do we still have extra path info to decode? 155 if( count($path_elements) ) 156 { 157 // Does the pathinfo end with a / ? 158 if( substr( $path_string, -1 ) != '/' ) 159 { // NO ENDING SLASH -> We'll consider this to be a ref to a post: 160 // Set a lot of defaults as if we had received a complex URL: 161 $m = ''; 162 $more = 1; // Display the extended entries' text 163 $c = 1; // Display comments 164 $tb = 1; // Display trackbacks 165 $pb = 1; // Display pingbacks 166 167 $path_element = $path_elements[count($path_elements)-1]; 168 if( preg_match( "#^p([0-9]+)$#", $path_element, $req_post ) ) 169 { // The last param is of the form p000 170 // echo 'post number'; 171 $p = $req_post[1]; // Post to display 172 } 173 else 174 { // Last param is a string, we'll consider this to be a post urltitle 175 $title = $path_element; 176 // echo 'post title : ', $title; 177 } 178 } 179 else 180 { // ENDING SLASH -> we are looking for a daterange OR a chapter: 181 182 $last_part = $path_elements[count($path_elements)-1]; 183 // echo $last_part; 184 if( preg_match( '|^w?[0-9]+$|', $last_part ) ) 185 { // Last part is a number or a "week" number: 186 $i=0; 187 // echo $path_elements[$i]; 188 if( isset( $path_elements[$i] ) ) 189 { 190 if( is_numeric( $path_elements[$i] ) ) 191 { // We'll consider this to be the year 192 $m = $path_elements[$i++]; 193 $Debuglog->add( 'Setting year from extra path info. $m=' . $m , 'params' ); 194 195 if( isset( $path_elements[$i] ) && is_numeric( $path_elements[$i] ) ) 196 { // We'll consider this to be the month 197 $m .= $path_elements[$i++]; 198 $Debuglog->add( 'Setting month from extra path info. $m=' . $m , 'params' ); 199 200 if( isset( $path_elements[$i] ) && is_numeric( $path_elements[$i] ) ) 201 { // We'll consider this to be the day 202 $m .= $path_elements[$i++]; 203 $Debuglog->add( 'Setting day from extra path info. $m=' . $m , 'params' ); 204 } 205 } 206 elseif( isset( $path_elements[$i] ) && substr( $path_elements[$i], 0, 1 ) == 'w' ) 207 { // We consider this a week number 208 $w = substr( $path_elements[$i], 1, 2 ); 209 } 210 } 211 else 212 { // We did not get a number/year... 213 $path_error = 404; 214 } 215 } 216 } 217 elseif( preg_match( '|^[A-Za-z0-9\-]+$|', $last_part ) ) 218 { // We are pointing to a chapter/category: 219 $ChapterCache = & get_Cache( 'ChapterCache' ); 220 /** 221 * @var Chapter 222 */ 223 $Chapter = & $ChapterCache->get_by_urlname( $last_part, false ); 224 if( empty( $Chapter ) ) 225 { // We could not match a chapter... 226 // We are going to consider this to be a post title with a misplaced trailing slash. 227 // That happens when upgrading from WP for example. 228 $title = $last_part; // Will be sought later 229 } 230 else 231 { // We could match a chapter from the extra path: 232 $cat = $Chapter->ID; 233 } 234 } 235 else 236 { // We did not get anything we can decode... 237 // echo 'neither number nor cat'; 238 $path_error = 404; 239 } 240 } 241 } 242 243 if( $path_error == 404 ) 244 { // The request points to something we won't be able to resolve: 245 require $skins_path.'_404_not_found.main.php'; // error & exit 246 } 247 } 248 } 249 250 251 /* 252 * ____________________________ Query params ____________________________ 253 * 254 * Note: if the params have been set by the extra-path-info above, param() will not touch them. 255 */ 256 param( 'p', 'integer', '', true ); // Specific post number to display 257 param( 'title', 'string', '', true ); // urtitle of post to display 258 param( 'redir', 'string', 'yes', false ); // Do we allow redirection to canonical URL? (allows to force a 'single post' URL for commenting) 259 260 param( 'preview', 'integer', 0, true ); // Is this preview ? 261 if( $preview ) 262 { // Ignore this hit 263 $Hit->ignore = true; 264 } 265 266 param( 'stats', 'integer', 0 ); // Deprecated but might still be used by spambots 267 param( 'disp', 'string', 'posts', true ); 268 269 // In case these were not set by the stub: 270 if( !isset($timestamp_min) ) $timestamp_min = ''; 271 if( !isset($timestamp_max) ) $timestamp_max = ''; 272 273 274 /* 275 * ____________________________ Get specific Item if requested ____________________________ 276 */ 277 if( !empty($p) || !empty($title) ) 278 { // We are going to display a single post 279 // Make sure the single post we're requesting (still) exists: 280 $ItemCache = & get_Cache( 'ItemCache' ); 281 if( !empty($p) ) 282 { 283 $Item = & $ItemCache->get_by_ID( $p, false ); 284 } 285 else 286 { 287 $title = preg_replace( '/[^A-Za-z0-9_]/', '-', $title ); 288 $Item = & $ItemCache->get_by_urltitle( $title, false ); 289 } 290 if( empty( $Item ) ) 291 { // Post doesn't exist! Let's go 404! 292 // fp> TODO: ->viewing_allowed() for draft, private, protected and deprecated... 293 require $skins_path.'_404_not_found.main.php'; // error & exit 294 } 295 } 296 297 298 /* 299 * ____________________________ "Clean up" the request ____________________________ 300 * 301 * Make sure that: 302 * 1) disp is set to "single" if single post requested 303 * 2) URL is canonical if: 304 * - some content was requested in a weird/deprecated way 305 * - or if content identifiers have changed 306 */ 307 if( $stats || $disp == 'stats' ) 308 { // This used to be a spamfest... 309 require $skins_path.'_410_stats_gone.main.php'; // error & exit 310 // EXIT. 311 } 312 elseif( !empty($preview) ) 313 { // Preview 314 $disp = 'single'; 315 } 316 elseif( $disp == 'posts' && !empty($Item) ) 317 { // We are going to display a single post 318 if( $Item->ptyp_ID == 1000 ) 319 { 320 $disp = 'page'; 321 } 322 else 323 { 324 $disp = 'single'; 325 } 326 327 if( $redir == 'yes' ) 328 { // $redir=no here allows to force a 'single post' URL for commenting 329 330 // Check if the post has 'redirected' status: 331 if( $Item->status == 'redirected' ) 332 { // Redirect to the URL specified in the post: 333 $Debuglog->add( 'Redirecting to post URL ['.$Item->url.'].' ); 334 header_redirect( $Item->url, true ); 335 } 336 337 // Check if we want to redirect to a canonical URL for the post 338 // Please document encountered problems. 339 if( $Blog->get_setting( 'canonical_item_urls' ) && $redir == 'yes' ) 340 { // We want to redirect to the Item's canonical URL: 341 342 $canonical_url = $Item->get_permanent_url( '', '', '&' ); 343 344 $requested_crop = preg_replace( '¤\?.*$¤', '', $ReqHost.$ReqURI ); 345 $canonical_crop = preg_replace( '¤\?.*$¤', '', $canonical_url ); 346 // pre_dump( $requested_crop, $canonical_crop ); 347 348 if( $requested_crop != $canonical_crop ) 349 { // The requested URL does not look like the canonical URL for this post, 350 // REDIRECT TO THE CANONICAL URL: 351 // fp> TODO: we might be losing additional params, it would be better to keep them... (but we have redir=no for that) 352 $Debuglog->add( 'Redirecting to canonical URL ['.$canonical_url.'].' ); 353 header_redirect( $canonical_url, true ); 354 // EXITED. 355 } 356 } 357 } 358 } 359 360 361 /* 362 * ______________________ DETERMINE WHICH SKIN TO USE FOR DISPLAY _______________________ 363 */ 364 365 // Check if a temporary skin has been requested (used for RSS syndication for example): 366 param( 'tempskin', 'string', '', true ); 367 if( !empty( $tempskin ) ) 368 { // This will be handled like any other skin: 369 $skin = $tempskin; 370 } 371 372 if( isset( $skin ) ) 373 { // A skin has been requested by folder_name (url or stub): 374 375 // Check validity of requested skin name: 376 if( ereg( '([^-A-Za-z0-9._]|\.\.)', $skin ) ) 377 { 378 debug_die( 'The requested skin name is invalid.' ); 379 } 380 381 // Because a lot of bloggers will delete skins, we have to make this fool proof with extra checking: 382 if( !empty( $skin ) && !skin_exists( $skin ) ) 383 { // We want to use a skin, but it doesn't exist! 384 $err_msg = sprintf( T_('The skin [%s] set for blog [%s] does not exist. It must be properly set in the <a %s>blog properties</a> or properly overriden in a stub file.'), 385 htmlspecialchars($skin), $Blog->dget('shortname'), 'href="'.$admin_url.'?ctrl=coll_settings&tab=display&action=edit&blog='.$Blog->ID.'"' ); 386 debug_die( $err_msg ); 387 } 388 389 // EXPERIMENTAL: 390 load_class( 'skins/model/_skin.class.php' ); 391 $Skin = & new Skin(); 392 393 } 394 else 395 { // Use default skin from the database 396 $SkinCache = & get_cache( 'SkinCache' ); 397 398 $Skin = & $SkinCache->get_by_ID( $Blog->skin_ID ); 399 400 $skin = $Skin->folder; 401 } 402 403 404 $Timer->pause( '_blog_main.inc'); 405 406 407 /* 408 * _______________________________ READY TO DISPLAY _______________________________ 409 * 410 * At this point $skin holds the name of the skin we want to use, or '' for no skin! 411 */ 412 413 414 // Trigger plugin event: 415 // fp> TODO: please doc with example of what this can be used for 416 $Plugins->trigger_event( 'BeforeBlogDisplay', array('skin'=>$skin) ); 417 418 419 if( !empty( $skin ) ) 420 { // We want to display with a skin now: 421 422 if( $skin_provided_by_plugin = skin_provided_by_plugin($skin) ) 423 { 424 $Plugins->call_method( $skin_provided_by_plugin, 'DisplaySkin', $tmp_params = array('skin'=>$skin) ); 425 } 426 else 427 { 428 // Path for the current skin: 429 $ads_current_skin_path = $skins_path.$skin.'/'; 430 431 $disp_handlers = array( 432 'feedback-popup' => 'feedback_popup.tpl.php', 433 // 'arcdir' => 'arcdir.tpl.php', 434 'comments' => 'latestcom.tpl.php', 435 'posts' => 'items.main.php', 436 'single' => 'single.main.php', 437 'page' => 'page.main.php', 438 'msgform' => 'msgform.main.php', 439 // 'profile' => 'profile.tpl.php', 440 // 'subs' => 'subscriptions.tpl.php', 441 442 // All others will default to index.main.php 443 ); 444 445 if( !empty($disp_handlers[$disp]) 446 && file_exists( $disp_handler = $ads_current_skin_path.$disp_handlers[$disp] ) ) 447 { // The skin has a customized page handler for this display: 448 require $disp_handler; 449 } 450 else 451 { // Use the default handler from the skins dir: 452 require $ads_current_skin_path.'index.main.php'; 453 } 454 } 455 456 // log the hit on this page (in case the skin hasn't already done so) 457 $Hit->log(); 458 } 459 else 460 { // We don't use a skin. Hopefully the caller will do some displaying. 461 // Set a few vars with default values, just in case... 462 $ads_current_skin_path = $htsrv_path; 463 464 // We'll just return to the caller now... (if we have not used a skin, the caller should do the display after this) 465 } 466 467 468 /* 469 * $Log: _blog_main.inc.php,v $ 470 * Revision 1.88 2007/10/06 21:26:16 fplanque 471 * WP url decoding compatibility + cleanup 472 * 473 * Revision 1.87 2007/09/28 09:28:36 fplanque 474 * per blog advanced SEO settings 475 * 476 * Revision 1.86 2007/09/10 15:35:23 fplanque 477 * .php in blog url fix 478 * 479 * Revision 1.85 2007/07/13 23:47:36 fplanque 480 * New start pages! 481 * 482 * Revision 1.84 2007/06/27 02:23:24 fplanque 483 * new default template for skins named index.main.php 484 * 485 * Revision 1.83 2007/06/26 02:40:53 fplanque 486 * security checks 487 * 488 * Revision 1.82 2007/06/25 10:58:50 fplanque 489 * MODULES (refactored MVC) 490 * 491 * Revision 1.81 2007/06/25 01:21:28 fplanque 492 * minor / interim 493 * 494 * Revision 1.80 2007/06/24 01:05:31 fplanque 495 * skin_include() now does all the template magic for skins 2.0. 496 * .disp.php templates still need to be cleaned up. 497 * 498 * Revision 1.79 2007/05/28 15:18:30 fplanque 499 * cleanup 500 * 501 * Revision 1.78 2007/05/13 22:02:06 fplanque 502 * removed bloated $object_def 503 * 504 * Revision 1.77 2007/05/08 00:54:31 fplanque 505 * public blog list as a widget 506 * 507 * Revision 1.76 2007/05/07 18:59:45 fplanque 508 * renamed skin .page.php files to .tpl.php 509 * 510 * Revision 1.75 2007/05/02 20:39:27 fplanque 511 * meta robots handling 512 * 513 * Revision 1.74 2007/04/26 00:11:04 fplanque 514 * (c) 2007 515 * 516 * Revision 1.73 2007/03/26 12:59:18 fplanque 517 * basic pages support 518 * 519 * Revision 1.72 2007/03/24 20:41:16 fplanque 520 * Refactored a lot of the link junk. 521 * Made options blog specific. 522 * Some junk still needs to be cleaned out. Will do asap. 523 * 524 * Revision 1.71 2007/03/18 01:39:54 fplanque 525 * renamed _main.php to main.page.php to comply with 2.0 naming scheme. 526 * (more to come) 527 * 528 * Revision 1.70 2007/03/18 00:31:18 fplanque 529 * Delegated MainList init to skin *pages* which need it. 530 * 531 * Revision 1.69 2007/03/12 00:03:47 fplanque 532 * And finally: the redirect action :) 533 * 534 * Revision 1.68 2007/01/28 17:50:54 fplanque 535 * started moving towards 2.0 skin structure 536 * 537 * Revision 1.67 2007/01/26 04:52:53 fplanque 538 * clean comment popups (skins 2.0) 539 * 540 * Revision 1.66 2007/01/23 08:17:49 fplanque 541 * another simplification... 542 * 543 * Revision 1.65 2007/01/23 08:07:16 fplanque 544 * Fixed blog URLs including urlnames 545 * 546 * Revision 1.64 2007/01/09 00:55:16 blueyed 547 * fixed typo(s) 548 * 549 * Revision 1.63 2007/01/08 02:11:55 fplanque 550 * Blogs now make use of installed skins 551 * next step: make use of widgets inside of skins 552 * 553 * Revision 1.62 2007/01/07 05:32:11 fplanque 554 * added some more DB skin handling (install+uninstall+edit properties ok) 555 * still useless though :P 556 * next step: discover containers in installed skins 557 * 558 * Revision 1.61 2006/12/28 18:31:30 fplanque 559 * prevent impersonating of blog in multiblog situation 560 * 561 * Revision 1.60 2006/12/26 00:55:58 fplanque 562 * wording 563 * 564 * Revision 1.59 2006/12/24 00:45:51 fplanque 565 * bugfix 566 * 567 * Revision 1.58 2006/12/18 00:56:16 fplanque 568 * non existent blog error handling 569 * 570 * Revision 1.57 2006/12/14 22:05:18 fplanque 571 * doc 572 * 573 * Revision 1.56 2006/12/14 21:54:52 blueyed 574 * todo 575 * 576 * Revision 1.55 2006/12/14 21:41:15 fplanque 577 * Allow different number of items in feeds than on site 578 * 579 * Revision 1.54 2006/12/14 21:35:05 fplanque 580 * block reordering tentative 581 * 582 * Revision 1.53 2006/12/14 20:57:55 fplanque 583 * Hum... this really needed some cleaning up! 584 * 585 * Revision 1.52 2006/12/05 00:39:56 fplanque 586 * fixed some more permalinks/archive links 587 * 588 * Revision 1.51 2006/12/04 21:25:18 fplanque 589 * removed user skin switching 590 * 591 * Revision 1.50 2006/12/04 18:16:50 fplanque 592 * Each blog can now have its own "number of page/days to display" settings 593 * 594 * Revision 1.49 2006/11/30 22:34:15 fplanque 595 * bleh 596 * 597 * Revision 1.48 2006/11/14 21:56:11 blueyed 598 * Debuglog-entry, when redirecting to $canonical_url 599 * 600 * Revision 1.47 2006/11/11 20:33:14 blueyed 601 * Moved BeforeBlogDisplay hook to after $skin has been determined 602 * 603 * Revision 1.46 2006/10/24 14:03:52 blueyed 604 * Type $c param ("Display comments?") to integer 605 * 606 * Revision 1.45 2006/10/08 22:59:30 blueyed 607 * Added GetProvidedSkins and DisplaySkin hooks. Allow for optimization in Plugins::trigger_event_first_return() 608 * 609 * Revision 1.44 2006/10/04 12:55:24 blueyed 610 * - Reload $Blog, if charset has changed for Blog locale 611 * - only update DB connection charset, if not forced with $db_config['connection_charset'] 612 */ 613 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |