b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file _blog_main.inc.php

Documentation is available at _blog_main.inc.php

  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-2010 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.163 2010/02/08 17:51:18 efy-yury Exp $
  26.  */
  27. if!defined('EVO_CONFIG_LOADED') ) die'Please, do not access this page directly.' );
  28.  
  29. /**
  30.  * Initialize everything:
  31.  */
  32. require_once dirname(__FILE__).'/_main.inc.php';
  33.  
  34. load_funcs('skins/_skin.funcs.php');
  35. load_class'items/model/_itemlist.class.php''ItemList' );
  36.  
  37. // fp> A lot of time (like 40ms) will be consumed the first time a new Blog object is created.
  38. // This happens within _BLOG_MAIN bloc in non logged in mode and is pretty much perturbing.
  39. // Trying to create a dummy Blog below move the delay out.
  40. // The constructor doesn't consume any time at all.
  41. // This is very strange. Is it because of recursive class loading that happens when instanciating a Blog?
  42. //$dummy = new Blog();
  43. $Timer->start'_BLOG_MAIN.inc' );
  44.  
  45.  
  46. /*
  47.  * blog ID. This is a little bit special.
  48.  *
  49.  * In most cases $blog should be set by a stub file and the param() call below will just check that it's an integer.
  50.  *
  51.  * Note we do NOT memorize the param as we don't want it in regenerate_url() calls.
  52.  * Whenever we do, index.php will already have called param() with memorize=true
  53.  *
  54.  * In some cases $blog will not have been set before and it will be set with the param() call below.
  55.  * Currently, this only happens with the old /xmlsrv/ RSS stubs.
  56.  */
  57. param'blog''integer'''false );
  58.  
  59. // Getting current blog info:
  60. $BlogCache get_BlogCache();
  61. /**
  62.  * @var Blog 
  63.  */
  64. $Blog $BlogCache->get_by_ID$blogfalsefalse );
  65. ifempty$Blog ) )
  66. {
  67.     require $skins_path.'_404_blog_not_found.main.php'// error & exit
  68.     // EXIT.
  69. }
  70.  
  71.  
  72. // Init $disp
  73. param'disp''string''posts'true );
  74. $disp_detail '';
  75.  
  76.  
  77. /*
  78.  * _______________________________ Locale / Charset for the Blog _________________________________
  79.  *
  80.     TODO: blueyed>> This should get moved as default to the locale detection in _main.inc.php,
  81.             as we only want to activate the I/O charset, which is probably the user's..
  82.             It prevents using a locale/charset in the front office, apart from the one given as default for the blog!!
  83. fp>there is no blog defined in _main and there should not be any
  84. 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.
  85. */
  86. // Activate matching locale:
  87. $Debuglog->add'Activating blog locale: '.$Blog->get('locale')'locale' );
  88. locale_activate$Blog->get('locale') );
  89.  
  90.  
  91. // Re-Init charset handling, in case current_charset has changed:
  92. ifinit_charsets$current_charset ) )
  93. {
  94.   // Reload Blog(s) (for encoding of name, tagline etc):
  95.   $BlogCache->clear();
  96.  
  97.   $Blog $BlogCache->get_by_ID$blog );
  98. }
  99.  
  100.  
  101. /*
  102.  * _____________________________ Extra path info decoding ________________________________
  103.  *
  104.  * This will translate extra path into 'regular' params.
  105.  *
  106.  * Decoding should try to work like this:
  107.  *
  108.  * baseurl/blog-urlname/junk/.../junk/post-title    -> points to a single post (no ending slash)
  109.  * baseurl/blog-urlname/junk/.../junk/p142          -> points to a single post
  110.  * baseurl/blog-urlname/2006/                       -> points to a yearly archive because of ending slash + 4 digits
  111.  * baseurl/blog-urlname/2006/12/                    -> points to a monthly archive
  112.  * baseurl/blog-urlname/2006/12/31/                 -> points to a daily archive
  113.  * baseurl/blog-urlname/2006/w53/                   -> points to a weekly archive
  114.  * baseurl/blog-urlname/junk/.../junk/chap-urlname/ -> points to a single chapter/category (because of ending slash)
  115.  * Note: category names cannot be named like this [a-z][0-9]+
  116.  */
  117. ifisset$resolve_extra_path ) ) $resolve_extra_path true}
  118. if$resolve_extra_path )
  119. {
  120.     // Check and Remove blog base URI from ReqPath:
  121.     $blog_baseuri substr$Blog->gen_baseurl()strlen$Blog->get('baseurlroot') ) );
  122.     $Debuglog->add'blog_baseuri: "'.$blog_baseuri.'"''params' );
  123.  
  124.     // Remove trailer:
  125.     $blog_baseuri_regexp preg_replace'¤(\.php[0-9]?)?/?$¤'''$blog_baseuri );
  126.     // Readd possibilities in order to get a broad match:
  127.     $blog_baseuri_regexp '¤^'.preg_quote$blog_baseuri_regexp ).'(\.php[0-9]?)?/(.+)$¤';
  128.     // pre_dump( 'blog_baseuri_regexp: "', $blog_baseuri_regexp );
  129.  
  130.     ifpreg_match$blog_baseuri_regexp$ReqPath$matches ) )
  131.     // We have extra path info
  132.         $path_string $matches[2];
  133.  
  134.         $Debuglog->add'Extra path info found! path_string=' $path_string 'params' );
  135.         // echo "path=[$path_string]<br />";
  136.  
  137.         // Replace encoded ";" and ":" with regular chars (used for tags)
  138.         // TODO: dh> why not urldecode it altogether? fp> would prolly make sense but requires testing -- note: check with tags (move urldecode from tags up here)
  139.         // TODO: PHP5: use str_ireplace
  140.         $path_string str_replace(
  141.             array('%3b''%3B''%3a''%3A'),
  142.             array(';'';'':'':'),
  143.             $path_string );
  144.  
  145.         // Slice the path:
  146.         $path_elements preg_split'~/~'$path_string20PREG_SPLIT_NO_EMPTY );
  147.         // pre_dump( '',$path_elements );
  148.  
  149.         /* Tblue> This breaks proper error handling for non-existent php
  150.          *        files (returns HTTP 301 instead of 404) because the last
  151.          *        part of the URI is being removed and b2evo then redirects
  152.          *        to the canonical blog homepage URL.
  153.          *        Why is this done here? Blog base URLs ending with *.php
  154.          *        will be removed above and blog stub names will be removed
  155.          *        below anyway?!
  156.          * dh> I've fallen into this myself, e.g. with some GET-var => $debug hacking.
  157.          *     The workaround appears to be using redir=no.
  158.          *     Apart from that, I'm not that much involved in this part of the code.
  159.          * fp> Can you give an example URL of undesired behaviour on the demo blog?
  160.          * Tblue> dh: Even when using redir=no, 200 OK is returned when
  161.          *            404 Not found would be the right status code to return.
  162.          *        fp: http://test.b2evo.net/HEAD/blogs/blog1.php/foo.php
  163.          *            (compare to http://test.b2evo.net/HEAD/blogs/blog1.php/foo).
  164.          * fp> I know I had a good reason for this back in 2003!! I can't remember exactly though :)
  165.          * If you want, we can try to comment it out and see how it goes... (please do so, I am not sure exactly how much you want to comment out)
  166.          * Tblue> Done, let's see if this has any side-effects.
  167.          * dh> Well, http://test.b2evo.net/HEAD/blogs/blog1.php?c=1 still redirects (that's what
  168.          *     I've meant above). Should params like those trigger redir=no internally?
  169.          * fp> ?c=1 should redirect because in 99% of use cases it gives a junk duplicate content page. If you don't want it to redirect, you should turn off redirects.
  170.         if( isset( $path_elements[0] ) && preg_match( '#.*\.php[0-9]?$#', $path_elements[0] ) )
  171.         { // Ignore element ending with .php (fp: note: may be just '.php')
  172.             array_shift( $path_elements );
  173.             $Debuglog->add( 'Ignoring *.php in extra path info' , 'params' );
  174.         }
  175.         */
  176.  
  177.         ifisset$path_elements[0)
  178.                 && $path_elements[0== $Blog->stub
  179.                         || $path_elements[0== $Blog->urlname ) )
  180.         // Ignore stub file (if it ends with .php it should already have been filtered out above)
  181.             array_shift$path_elements );
  182.             $Debuglog->add'Ignoring stub filename OR blog urlname in extra path info' 'params' );
  183.         }
  184.         // pre_dump( $path_elements );
  185.  
  186.         // Do we still have extra path info to decode?
  187.         ifcount($path_elements) )
  188.         {
  189.             // TODO: dh> add plugin hook here, which would allow to handle path elements (name spaces in clean URLs), and to override internal functionality (e.g. handle tags in a different way).
  190.             // Is this a tag ("prefix-only" mode)?
  191.             if$Blog->get_setting('tag_links'== 'prefix-only'
  192.                 && count($path_elements== 2
  193.                 && $path_elements[0== $Blog->get_setting('tag_prefix')
  194.                 && isset($path_elements[1]) )
  195.             {
  196.                 $tag strip_tags(urldecode($path_elements[1]));
  197.  
  198.                 // # of posts per page for tag page:
  199.                 if$posts $Blog->get_setting'tag_posts_per_page' ) )
  200.                 // use blog default
  201.                     $posts $Blog->get_setting'posts_per_page' );
  202.                 }
  203.             }
  204.             else
  205.             {
  206.                 // Does the pathinfo end with a / or a ; ?
  207.                 $last_char substr$path_string-);
  208.                 $last_part $path_elements[count$path_elements )-1];
  209.                 $last_len  strlen$last_part );
  210.                 if( ( $last_char == '-' && $tags_dash_fix || $last_len != 40 ) ) || $last_char == ':'|| $last_char == ';' )
  211.                 {    // - : or ; -> We'll consider this to be a tag page
  212.                     $tag substr$last_part0-);
  213.                     $tag urldecode($tag);
  214.                     $tag strip_tags($tag);    // security
  215.                     // pre_dump( $tag );
  216.  
  217.                     // # of posts per page:
  218.                     if$posts $Blog->get_setting'tag_posts_per_page' ) )
  219.                     // use blog default
  220.                         $posts $Blog->get_setting'posts_per_page' );
  221.                     }
  222.                 }
  223.                 elseif( ( $tags_dash_fix && $last_char == '-' && $last_len == 40 || $last_char != '/' )
  224.                 {    // NO ENDING SLASH or ends with a dash, is 40 chars long and $tags_dash_fix is true
  225.                     // -> We'll consider this to be a ref to a post.
  226.                     $Debuglog->add'We consider this o be a ref to a post - last char: '.$last_char'params' );
  227.  
  228.                     // Set a lot of defaults as if we had received a complex URL:
  229.                     $m '';
  230.                     $more 1// Display the extended entries' text
  231.                     $c 1;    // Display comments
  232.                     $tb 1;   // Display trackbacks
  233.                     $pb 1;   // Display pingbacks
  234.  
  235.                     ifpreg_match'#^p([0-9]+)$#'$last_part$req_post ) )
  236.                     // The last param is of the form p000
  237.                         // echo 'post number';
  238.                         $p $req_post[1];        // Post to display
  239.                     }
  240.                     else
  241.                     // Last param is a string, we'll consider this to be a post urltitle
  242.                         $title $last_part;
  243.                         // echo 'post title : ', $title;
  244.                     }
  245.                 }
  246.                 else
  247.                 {    // ENDING SLASH -> we are looking for a daterange OR a chapter:
  248.                     $Debuglog->add'Last part: '.$last_part 'params' );
  249.                     // echo $last_part;
  250.                     ifpreg_match'|^w?[0-9]+$|'$last_part ) )
  251.                     // Last part is a number or a "week" number:
  252.                         $i=0;
  253.                         $Debuglog->add'Last part is a number or a "week" number: '.$path_elements[$i'params' );
  254.                         // echo $path_elements[$i];
  255.                         ifisset$path_elements[$i) )
  256.                         {
  257.                             ifis_numeric$path_elements[$i) )
  258.                             // We'll consider this to be the year
  259.                                 $m $path_elements[$i++];
  260.                                 $Debuglog->add'Setting year from extra path info. $m=' $m 'params' );
  261.  
  262.                                 // Also use the prefered posts per page for archives (may be NULL, in which case the blog default will be used later on)
  263.                                 if$posts $Blog->get_setting'archive_posts_per_page' ) )
  264.                                 // use blog default
  265.                                     $posts $Blog->get_setting'posts_per_page' );
  266.                                 }
  267.  
  268.                                 ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  269.                                 // We'll consider this to be the month
  270.                                     $m .= $path_elements[$i++];
  271.                                     $Debuglog->add'Setting month from extra path info. $m=' $m 'params' );
  272.  
  273.                                     ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  274.                                     // We'll consider this to be the day
  275.                                         $m .= $path_elements[$i++];
  276.                                         $Debuglog->add'Setting day from extra path info. $m=' $m 'params' );
  277.                                     }
  278.                                 }
  279.                                 elseifisset$path_elements[$i&& substr$path_elements[$i]0== 'w' )
  280.                                 // We consider this a week number
  281.                                     $w substr$path_elements[$i]1);
  282.                                 }
  283.                             }
  284.                             else
  285.                             {    // We did not get a number/year...
  286.                                 $disp '404';
  287.                                 $disp_detail '404-malformed_url-missing_year';
  288.                             }
  289.                         }
  290.                     }
  291.                     elseifpreg_match'|^[A-Za-z0-9\-_]+$|'$last_part ) )    // UNDERSCORES for catching OLD URLS!!!
  292.                     {    // We are pointing to a chapter/category:
  293.                         $ChapterCache get_ChapterCache();
  294.                         /**
  295.                          * @var Chapter 
  296.                          */
  297.                         $Chapter $ChapterCache->get_by_urlname$last_partfalse );
  298.                         ifempty$Chapter ) )
  299.                         {    // We could not match a chapter...
  300.                             // We are going to consider this to be a post title with a misplaced trailing slash.
  301.                             // That happens when upgrading from WP for example.
  302.                             $title $last_part// Will be sought later
  303.                             $already_looked_into_chapters true;
  304.                         }
  305.                         else
  306.                         {    // We could match a chapter from the extra path:
  307.                             $cat $Chapter->ID;
  308.                             // Also use the prefered posts per page for a cat
  309.                             if$posts $Blog->get_setting'chapter_posts_per_page' ) )
  310.                             // use blog default
  311.                                 $posts $Blog->get_setting'posts_per_page' );
  312.                             }
  313.                         }
  314.                     }
  315.                     else
  316.                     {    // We did not get anything we can decode...
  317.                         // echo 'neither number nor cat';
  318.                         $disp '404';
  319.                         $disp_detail '404-malformed_url-bad_char';
  320.                     }
  321.                 }
  322.             }
  323.         }
  324.  
  325.     }
  326. }
  327.  
  328.  
  329. /*
  330.  * ____________________________ Query params ____________________________
  331.  *
  332.  * Note: if the params have been set by the extra-path-info above, param() will not touch them.
  333.  */
  334. param'p''integer'''true );              // Specific post number to display
  335. param'title''string'''true );                        // urtitle of post to display
  336. param'redir''string''yes'false );                // Do we allow redirection to canonical URL? (allows to force a 'single post' URL for commenting)
  337. param'preview''integer'0true );         // Is this preview ?
  338. param'stats''integer');                                    // Deprecated but might still be used by spambots
  339.  
  340. // In case these were not set by the stub:
  341. if!isset($timestamp_min) ) $timestamp_min '';
  342. if!isset($timestamp_max) ) $timestamp_max '';
  343.  
  344.  
  345.  
  346. // Front page detection & selection should probably occur here.
  347.  
  348.  
  349.  
  350. /*
  351.  * ____________________________ Get specific Item if requested ____________________________
  352.  */
  353. if!empty($p|| !empty($title) )
  354. // We are going to display a single post
  355.     $title rawurldecode($title);
  356.     // Make sure the single post we're requesting (still) exists:
  357.     $ItemCache get_ItemCache();
  358.     if!empty($p) )
  359.     {    // Get from post ID:
  360.         $Item $ItemCache->get_by_ID$pfalse );
  361.     }
  362.     else
  363.     {    // Get from post title:
  364.         $orig_title $title;
  365.         $title preg_replace'/[^A-Za-z0-9_]/''-'$title );
  366.         $Item $ItemCache->get_by_urltitle$titlefalse );
  367.  
  368.         ifempty($Item&& substr($title-1== '-' )
  369.         // Try lookup by removing last invalid char, which might have been e.g. ">"
  370.             $Item $ItemCache->get_by_urltitle(substr($title0-1)false);
  371.         }
  372.     }
  373.     ifempty$Item ) )
  374.     {    // Post doesn't exist!
  375.  
  376.         // fp> TODO: ->viewing_allowed() for draft, private, protected and deprecated...
  377.  
  378.         $title_fallback false;
  379.         $tag_fallback $tags_dash_fix && substr$orig_title-== '-' && strlen$orig_title == 40 );
  380.  
  381.         if$tag_fallback && !empty($title&& empty($already_looked_into_chapters) )
  382.         {    // Let's try to fall back to a category/chapter...
  383.             $ChapterCache get_ChapterCache();
  384.             /**
  385.              * @var Chapter 
  386.              */
  387.             $Chapter $ChapterCache->get_by_urlname$titlefalse );
  388.             if!empty$Chapter ) )
  389.             {    // We could match a chapter from the extra path:
  390.                 $cat $Chapter->ID;
  391.                 $title_fallback true;
  392.                 $title NULL;
  393.                 // Also use the prefered posts per page for a cat
  394.                 if$posts $Blog->get_setting'chapter_posts_per_page' ) )
  395.                 // use blog default
  396.                     $posts $Blog->get_setting'posts_per_page' );
  397.                 }
  398.             }
  399.         }
  400.  
  401.         if!empty($title) )
  402.         {    // Let's try to fall back to a tag...
  403.             if$tag_fallback )
  404.             {
  405.                 $title substr$orig_title0-);
  406.             }
  407.             if$Blog->get_tag_post_count$title ) )
  408.             // We could match a tag from the extra path:
  409.                 $tag $title;
  410.                 $title_fallback true;
  411.                 $title NULL;
  412.             }
  413.         }
  414.  
  415.         if$title_fallback )
  416.         {    // We were not able to fallback to anythign meaningful:
  417.             $disp '404';
  418.             $disp_detail '404-post_not_found';
  419.         }
  420.     }
  421. }
  422.  
  423.  
  424. /*
  425.  * ____________________________ "Clean up" the request ____________________________
  426.  *
  427.  * Make sure that:
  428.  * 1) disp is set to "single" if single post requested
  429.  * 2) URL is canonical if:
  430.  *    - some content was requested in a weird/deprecated way
  431.  *    - or if content identifiers have changed
  432.  */
  433. if$stats || $disp == 'stats' )
  434. {    // This used to be a spamfest...
  435.     require $skins_path.'_410_stats_gone.main.php'// error & exit
  436.     // EXIT.
  437. }
  438. elseif!empty($preview) )
  439. {    // Preview
  440.     $disp 'single';
  441.     // Consider this as an admin hit!
  442.     $Hit->referer_type 'admin';
  443. }
  444. elseif$disp == 'posts' && !empty($Item) )
  445. // We are going to display a single post
  446.     // if( in_array( $Item->ptyp_ID, array( 1000, 1500, 1520, 1530, 1570 ) ) ) // pages and intros
  447.     if$Item->ptyp_ID == 1000 )
  448.     {
  449.         $disp 'page';
  450.     }
  451.     else
  452.     {
  453.         $disp 'single';
  454.     }
  455.  
  456.     // fp> note: the redirecting code that was here moved to skin_init() with the other redirecting code.
  457.     // That feels more consistent and may also allow some skins to handle redirects differently (framing?)
  458.     // I hope I didn't screw that up... but it felt like the historical reasons for this to be here no longer applied.
  459. }
  460.  
  461.  
  462. /*
  463.  * ______________________ DETERMINE WHICH SKIN TO USE FOR DISPLAY _______________________
  464.  */
  465.  
  466. // Check if a temporary skin has been requested (used for RSS syndication for example):
  467. param'tempskin''string'''true );
  468. if!empty$tempskin ) )
  469. // This will be handled like any other skin:
  470.     // TODO: maybe restrict that to authorized users
  471.     $skin $tempskin;
  472. }
  473.  
  474. ifisset$skin ) )
  475. {    // A skin has been requested by folder_name (url or stub):
  476.  
  477.     // Check validity of requested skin name:
  478.     ifpreg_match'~([^-A-Za-z0-9._]|\.\.)~'$skin ) )
  479.     {
  480.         debug_die'The requested skin name is invalid.' );
  481.     }
  482.  
  483.     $SkinCache get_SkinCache();
  484.     $Skin $SkinCache->new_objNULL$skin );
  485.  
  486.     if$Skin->type == 'feed' )
  487.     {    // Check if we actually allow the display of the feed; last chance to revert to 404 displayed in default skin.
  488.         // Note: Skins with the type "feed" can always be accessed, even when they're not installed.
  489.         if$Blog->get_setting('feed_content'== 'none' )
  490.         // We don't want to provide feeds; revert to 404!
  491.             unset$skin );
  492.             unset$Skin );
  493.             $disp '404';
  494.             $disp_detail '404-feeds-disabled';
  495.         }
  496.     }
  497.     elseif$Skin->type == 'sitemap' )
  498.     {    // Check if we actually allow the display of sitemaps.
  499.         // Note: Skins with the type "sitemap" can always be accessed, even when they're not installed.
  500.         if$Blog->get_setting('enable_sitemaps') )
  501.         // We don't want to show this sitemap, revert to error 404:
  502.             unset$skin );
  503.             unset$Skin );
  504.             $disp '404';
  505.             $disp_detail '404-sitemaps-disabled';
  506.         }
  507.     }
  508.     elseifskin_exists$skin && skin_installed$skin ) )
  509.     {    // The requested skin is not a feed skin and exists in the file system, but isn't installed:
  510.         debug_diesprintfT_'The skin [%s] is not installed on this system.' )htmlspecialchars$skin ) ) );
  511.     }
  512.     elseifempty$tempskin ) )
  513.     // By definition, we want to see the temporary skin (if we don't use feedburner... )
  514.         $redir 'no';
  515.     }
  516. }
  517.  
  518. if!isset$skin && !empty($Blog->skin_ID) )    // Note: if $skin is set to '', then we want to do a "no skin" display
  519. // Use default skin from the database
  520.     $SkinCache get_SkinCache();
  521.     $Skin $SkinCache->get_by_ID$Blog->skin_ID );
  522.     $skin $Skin->folder;
  523. }
  524.  
  525. // Because a lot of bloggers will delete skins, we have to make this fool proof with extra checking:
  526. if!empty$skin && !skin_exists$skin ) )
  527. // We want to use a skin, but it doesn't exist!
  528.     $err_msg sprintfT_('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.'),
  529.         htmlspecialchars($skin),
  530.         $Blog->dget('shortname'),
  531.         'href="'.$admin_url.'?ctrl=coll_settings&amp;tab=skin&amp;blog='.$Blog->ID.'"' );
  532.     debug_die$err_msg );
  533. }
  534.  
  535.  
  536. $Timer->pause'_BLOG_MAIN.inc');
  537.  
  538.  
  539. /*
  540.  * _______________________________ READY TO DISPLAY _______________________________
  541.  *
  542.  * At this point $skin holds the name of the skin we want to use, or '' for no skin!
  543.  */
  544.  
  545.  
  546. // Trigger plugin event:
  547. // fp> TODO: please doc with example of what this can be used for
  548. $Plugins->trigger_event'BeforeBlogDisplay'array('skin'=>$skin) );
  549.  
  550.  
  551. if!empty$skin ) )
  552. // We want to display with a skin now:
  553.     $Timer->resume'SKIN DISPLAY' );
  554.  
  555.     $Debuglog->add('Selected skin: '.$skin'skins' );
  556.  
  557.     // Instantiate PageCache:
  558.     $Timer->resume'PageCache' );
  559.     load_class'_core/model/_pagecache.class.php''PageCache' );
  560.     $PageCache new PageCache$Blog );
  561.     // Check for cached content & Start caching if needed
  562.     // Note: there are some redirects inside the skins themselves for canonical URLs,
  563.     // If we have a cache hit, the redirect won't take place until the cache expires -- probably ok.
  564.     // If we start collecting and a redirect happens, the collecting will just be lost and that's what we want.
  565.     if$PageCache->check() )
  566.     {    // Cache miss, we have to generate:
  567.         $Timer->pause'PageCache' );
  568.  
  569.         if$skin_provided_by_plugin skin_provided_by_plugin($skin) )
  570.         {
  571.             $Plugins->call_method$skin_provided_by_plugin'DisplaySkin'$tmp_params array('skin'=>$skin) );
  572.         }
  573.         else
  574.         {
  575.             // Path for the current skin:
  576.             $ads_current_skin_path $skins_path.$skin.'/';
  577.  
  578.             $disp_handlers array(
  579.                     '404'            => '404_not_found.main.php',
  580.                     'arcdir'         => 'arcdir.main.php',
  581.                     'catdir'         => 'catdir.main.php',
  582.                     'comments'       => 'comments.main.php',
  583.                     'feedback-popup' => 'feedback_popup.main.php',
  584.                     'mediaidx'       => 'mediaidx.main.php',
  585.                     'msgform'        => 'msgform.main.php',
  586.                     'page'           => 'page.main.php',
  587.                     'postidx'        => 'postidx.main.php',
  588.                     'posts'          => 'posts.main.php',
  589.                     'profile'        => 'profile.main.php',
  590.                     'search'         => 'search.main.php',
  591.                     'single'         => 'single.main.php',
  592.                     'sitemap'        => 'sitemap.main.php',
  593.                     'subs'           => 'subs.main.php',
  594.                     // All others will default to index.main.php
  595.                 );
  596.  
  597.             if!empty($disp_handlers[$disp]) )
  598.             {
  599.                 iffile_exists$disp_handler $ads_current_skin_path.$disp_handlers[$disp) )
  600.                 {    // The skin has a customized page handler for this display:
  601.                     $Debuglog->add('blog_main: include '.rel_path_to_base($disp_handler).' (custom to this skin)''skins' );
  602.                     require $disp_handler;
  603.                 }
  604.                 elseif$disp_handlers[$disp== 'posts.main.php' && file_exists$disp_handler $ads_current_skin_path.'items.main.php' ) )
  605.                 {    // Compatibility with skins < 2.2.0
  606.                     $Debuglog->add('blog_main: include '.rel_path_to_base($disp_handler).' (compat with skins < 2.2.0)''skins' );
  607.                     require $disp_handler;
  608.                 }
  609.                 elseif$disp_handlers[$disp== 'comments.main.php' && file_exists$disp_handler $ads_current_skin_path.'latestcom.tpl.php' ) )
  610.                 {    // Compatibility with skins < 2.2.0
  611.                     $Debuglog->add('blog_main: include '.rel_path_to_base($disp_handler).' (compat with skins < 2.2.0)''skins' );
  612.                     require $disp_handler;
  613.                 }
  614.                 elseif$disp_handlers[$disp== 'feedback_popup.main.php' && file_exists$disp_handler $ads_current_skin_path.'feedback_popup.tpl.php' ) )
  615.                 {    // Compatibility with skins < 2.2.0
  616.                     $Debuglog->add('blog_main: include '.rel_path_to_base($disp_handler).' (compat with skins < 2.2.0)''skins' );
  617.                     require $disp_handler;
  618.                 }
  619.                 else
  620.                 {    // Use the default handler from the skins dir:
  621.                     $Debuglog->add('blog_main: include '.rel_path_to_base($ads_current_skin_path.'index.main.php').' (default handler)''skins' );
  622.                     require $ads_current_skin_path.'index.main.php';
  623.                 }
  624.             }
  625.             else
  626.             {    // Use the default handler from the skins dir:
  627.                 $Debuglog->add('blog_main: include '.rel_path_to_base($ads_current_skin_path.'index.main.php').' (default index handler)''skins' );
  628.                 require $ads_current_skin_path.'index.main.php';
  629.             }
  630.         }
  631.  
  632.         // Save collected cached data if needed:
  633.         $PageCache->end_collect();
  634.     }
  635.     $Timer->pause'PageCache' );
  636.  
  637.     $Timer->pause'SKIN DISPLAY' );
  638.  
  639.     // We probably don't want to return to the caller if we have displayed a skin...
  640.     // That is useful if the caller implements a custom display but we still use skins for RSS/ Atom etc..
  641.     exit(0);
  642. }
  643. else
  644. {    // We don't use a skin. Hopefully the caller will do some displaying.
  645.     // Set a few vars with default values, just in case...
  646.     $ads_current_skin_path $htsrv_path;
  647.  
  648.     // We'll just return to the caller now... (if we have not used a skin, the caller should do the display after this)
  649. }
  650.  
  651.  
  652. /*
  653.  * $Log: _blog_main.inc.php,v $
  654.  * Revision 1.163  2010/02/08 17:51:18  efy-yury
  655.  * copyright 2009 -> 2010
  656.  *
  657.  * Revision 1.162  2010/01/13 23:39:17  fplanque
  658.  * doc
  659.  *
  660.  * Revision 1.161  2009/12/22 23:13:37  fplanque
  661.  * Skins v4, step 1:
  662.  * Added new disp modes
  663.  * Hooks for plugin disp modes
  664.  * Enhanced menu widgets (BIG TIME! :)
  665.  *
  666.  * Revision 1.160  2009/12/20 22:12:20  fplanque
  667.  * doc
  668.  *
  669.  * Revision 1.159  2009/12/12 02:16:17  blueyed
  670.  * doc
  671.  *
  672.  * Revision 1.158  2009/11/30 00:22:04  fplanque
  673.  * clean up debug info
  674.  * show more timers in view of block caching
  675.  *
  676.  * Revision 1.157  2009/11/15 19:33:05  tblue246
  677.  * bugfix/testing
  678.  *
  679.  * Revision 1.156  2009/11/15 19:05:45  fplanque
  680.  * no message
  681.  *
  682.  * Revision 1.155  2009/10/29 20:44:30  blueyed
  683.  * urldecode title and check if it can be found with the last invalid char removed.
  684.  *
  685.  * Revision 1.154  2009/10/17 15:23:04  tblue246
  686.  * doc/correction
  687.  *
  688.  * Revision 1.153  2009/10/17 15:16:56  tblue246
  689.  * doc
  690.  *
  691.  * Revision 1.152  2009/10/17 15:01:23  fplanque
  692.  * doc
  693.  *
  694.  * Revision 1.151  2009/10/15 00:45:00  blueyed
  695.  * doc/reply
  696.  *
  697.  * Revision 1.150  2009/10/10 21:12:12  tblue246
  698.  * Doc
  699.  *
  700.  * Revision 1.149  2009/09/29 16:56:07  tblue246
  701.  * Added setting to disable sitemaps skins
  702.  *
  703.  * Revision 1.148  2009/09/29 15:39:16  tblue246
  704.  * doc
  705.  *
  706.  * Revision 1.147  2009/09/29 03:47:07  fplanque
  707.  * doc
  708.  *
  709.  * Revision 1.146  2009/09/26 13:41:54  tblue246
  710.  * If XML feeds are disabled for a blog, still allow accessing "sitemap" skins.
  711.  *
  712.  * Revision 1.145  2009/09/26 12:00:42  tblue246
  713.  * Minor/coding style
  714.  *
  715.  * Revision 1.144  2009/09/25 07:32:52  efy-cantor
  716.  * replace get_cache to get_*cache
  717.  *
  718.  * Revision 1.143  2009/09/24 00:32:28  blueyed
  719.  * Add some timers. skin_display is taking too long - obviously.
  720.  *
  721.  * Revision 1.142  2009/09/20 23:51:24  blueyed
  722.  * whitespace
  723.  *
  724.  * Revision 1.141  2009/09/14 14:00:35  efy-arrin
  725.  * Included the ClassName in load_class() call with proper UpperCase
  726.  *
  727.  * Revision 1.140  2009/07/30 20:22:04  blueyed
  728.  * Debuglog: log selected skin
  729.  *
  730.  * Revision 1.139  2009/06/29 02:14:04  fplanque
  731.  * no message
  732.  *
  733.  * Revision 1.138  2009/06/07 14:22:20  yabs
  734.  * minor bug fix
  735.  *
  736.  * Revision 1.137  2009/05/31 14:03:31  tblue246
  737.  * Fix feed redirection (external feed provider). Fixes http://forums.b2evolution.net/viewtopic.php?t=18824
  738.  *
  739.  * Revision 1.136  2009/05/28 22:44:37  blueyed
  740.  * Add info about the included skin display handler to debuglog.
  741.  *
  742.  * Revision 1.135  2009/05/23 20:20:18  fplanque
  743.  * Skins can now have a _skin.class.php file to override default Skin behaviour. Currently only the default name but can/will be extended.
  744.  *
  745.  * Revision 1.134  2009/05/20 12:58:14  fplanque
  746.  * Homepage: option to 301 redirect to canonical homepage.
  747.  * Option to support rel="canonical" instead of or when 301 redirect cannot be used.
  748.  *
  749.  * Revision 1.133  2009/05/20 12:56:34  fplanque
  750.  * made tga-prefix-only  mode matching more strict
  751.  *
  752.  * Revision 1.132  2009/04/23 19:50:35  blueyed
  753.  * TODO
  754.  *
  755.  * Revision 1.131  2009/04/22 22:46:33  blueyed
  756.  * Add support for rel=tag in tag URLs. This adds a new tag_links mode 'prefix-only', which requires a prefix (default: tag) and uses no suffix (dash/colon/semicolon). Also adds more JS juice and cleans up/normalized previously existing JS. Not much tested, but implemented as discussed on ML.
  757.  *
  758.  * Revision 1.130  2009/04/22 20:11:42  blueyed
  759.  * Use preg_split instead of split and manually removing empty slots/parts. Less code and faster in benchmark.
  760.  *
  761.  * Revision 1.129  2009/03/24 21:03:56  fplanque
  762.  * Surely enough, everytime someone touches the resolver, they break it!
  763.  * Stop playing with it!
  764.  *
  765.  * Revision 1.128  2009/03/23 12:19:19  tblue246
  766.  * (temp)skin param: Allow plugin-provided skins
  767.  *
  768.  * Revision 1.127  2009/03/20 03:55:50  fplanque
  769.  * (explain to me why it's better to have the fix enabled by default)
  770.  *
  771.  * Revision 1.126  2009/03/19 16:08:07  tblue246
  772.  * minor
  773.  *
  774.  * Revision 1.125  2009/03/19 15:38:47  tblue246
  775.  * Ugly bug fix for workaround
  776.  *
  777.  * Revision 1.124  2009/03/19 15:05:05  tblue246
  778.  * Trying to fix the post URL dash issue.
  779.  *
  780.  * Revision 1.123  2009/03/17 14:01:20  waltercruz
  781.  * rollbaking my broken commit
  782.  *
  783.  * Revision 1.121  2009/03/15 21:01:28  tblue246
  784.  * minor
  785.  *
  786.  * Revision 1.120  2009/03/15 18:46:37  fplanque
  787.  * please don't do whitespace edits
  788.  *
  789.  * Revision 1.119  2009/03/15 12:32:59  tblue246
  790.  * minor
  791.  *
  792.  * Revision 1.118  2009/03/14 19:22:29  fplanque
  793.  * minor
  794.  *
  795.  * Revision 1.117  2009/03/13 21:43:12  blueyed
  796.  * fix doc
  797.  *
  798.  * Revision 1.115  2009/03/13 14:22:40  tblue246
  799.  * (temp)skin param: Only allow the use of installed skins.
  800.  *
  801.  * Revision 1.112  2009/03/13 00:56:55  fplanque
  802.  * Better handling of blog param for cleaner URLs.
  803.  * A lot of testing was involved but I have tested many versions before reducing it to the max.
  804.  * I hope this final version has no side effects.
  805.  *
  806.  * Revision 1.111  2009/03/08 23:57:38  fplanque
  807.  * 2009
  808.  *
  809.  * Revision 1.110  2009/01/21 20:33:49  fplanque
  810.  * different display between featured and intro posts
  811.  *
  812.  * Revision 1.109  2008/12/31 00:25:26  fplanque
  813.  * bugfix
  814.  *
  815.  * Revision 1.108  2008/12/20 22:36:33  blueyed
  816.  * Add is_same_url() to compare URLs without taking case of urlencoded parts into account. This is required to prevent infinite redirects in the handling of canonical URLs.
  817.  *
  818.  * Revision 1.107  2008/10/14 23:18:50  blueyed
  819.  * Replace encoded ':' for tags in $path_string, too (and the lowercase encoded version)
  820.  *
  821.  * Revision 1.106  2008/09/28 08:06:04  fplanque
  822.  * Refactoring / extended page level caching
  823.  *
  824.  * Revision 1.105  2008/09/27 08:14:02  fplanque
  825.  * page level caching
  826.  *
  827.  * Revision 1.104  2008/09/09 06:03:29  fplanque
  828.  * More tag URL options
  829.  * Enhanced URL resolution for categories and tags
  830.  *
  831.  * Revision 1.103  2008/05/26 19:22:00  fplanque
  832.  * fixes
  833.  *
  834.  * Revision 1.102  2008/05/06 23:37:06  fplanque
  835.  * revert
  836.  *
  837.  * Revision 1.99  2008/03/30 23:04:23  fplanque
  838.  * fix
  839.  *
  840.  * Revision 1.98  2008/03/23 23:40:42  fplanque
  841.  * no message
  842.  *
  843.  * Revision 1.97  2008/03/21 19:42:44  fplanque
  844.  * enhanced 404 handling
  845.  *
  846.  * Revision 1.96  2008/03/21 17:41:56  fplanque
  847.  * custom 404 pages
  848.  *
  849.  * Revision 1.95  2008/02/19 11:11:16  fplanque
  850.  * no message
  851.  *
  852.  * Revision 1.94  2008/02/11 23:48:14  fplanque
  853.  * tag URL decoding fux
  854.  *
  855.  * Revision 1.93  2008/01/21 09:35:23  fplanque
  856.  * (c) 2008
  857.  *
  858.  * Revision 1.92  2008/01/07 02:53:26  fplanque
  859.  * cleaner tag urls
  860.  *
  861.  * Revision 1.91  2008/01/04 23:18:11  blueyed
  862.  * Use preg_match instead of ereg; Move skin-does-not-exist debug_die further down
  863.  *
  864.  * Revision 1.90  2007/11/29 19:29:22  fplanque
  865.  * normalized skin filenames
  866.  *
  867.  * Revision 1.89  2007/11/25 14:28:17  fplanque
  868.  * additional SEO settings
  869.  *
  870.  * Revision 1.88  2007/10/06 21:26:16  fplanque
  871.  * WP url decoding compatibility + cleanup
  872.  *
  873.  * Revision 1.87  2007/09/28 09:28:36  fplanque
  874.  * per blog advanced SEO settings
  875.  *
  876.  * Revision 1.86  2007/09/10 15:35:23  fplanque
  877.  * .php in blog url fix
  878.  *
  879.  * Revision 1.85  2007/07/13 23:47:36  fplanque
  880.  * New start pages!
  881.  */
  882. ?>

Documentation generated on Sat, 06 Mar 2010 04:02:42 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).