b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.8) [ 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-2006 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.  *  Parts of this file are copyright (c)2004-2005 by The University of North Carolina at Charlotte as
  11.  *  contributed by Jason Edgecombe {@link http://tst.uncc.edu/team/members/jason_bio.php}.
  12.  *
  13.  * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  14.  *
  15.  *  {@internal Open Source relicensing agreement:
  16.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  17.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  18.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  19.  *
  20.  *  The University of North Carolina at Charlotte grants Francois PLANQUE the right to license
  21.  *  Jason EDGECOMBE's contributions to this file and the b2evolution project
  22.  *  under the GNU General Public License (http://www.opensource.org/licenses/gpl-license.php)
  23.  *  and the Mozilla Public License (http://www.opensource.org/licenses/mozilla1.1.php).
  24.  *  }}}
  25.  *
  26.  * @package main
  27.  *
  28.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29.  * @author blueyed: Daniel HAHLER
  30.  * @author fplanque: Francois PLANQUE
  31.  * @author jeffbearer: Jeff BEARER
  32.  * @author jwedgeco: Jason EDGECOMBE (for hire by UNC-Charlotte)
  33.  * @author edgester: Jason EDGECOMBE (personal contributions, not for hire)
  34.  *
  35.  *  {@internal Below is a list of former authors whose contributions to this file have been
  36.  *             either removed or redesigned and rewritten anew:
  37.  *             - cafelog (team)
  38.  *             - t3dworld
  39.  *  }}}
  40.  *
  41.  * @version $Id: _blog_main.inc.php,v 1.21.2.12 2006/12/02 02:41:27 fplanque Exp $
  42.  */
  43. if!defined('EVO_CONFIG_LOADED') ) die'Please, do not access this page directly.' );
  44.  
  45.  
  46. /**
  47.  * Initialize everything:
  48.  */
  49. require_once dirname(__FILE__).'/_main.inc.php';
  50. require_once $model_path.'items/_itemlist2.class.php';
  51.  
  52. $Timer->resume'blog_main.inc' );
  53.  
  54. // Getting GET or POST parameters:
  55. $Request->param'blog''integer'0true );  // Can't use $default_to_blog because the param must always be included in regenerate_url() when present
  56. $Request->param'p''integer'''true );              // Specific post number to display
  57. $Request->param'title''string'''true );                        // urtitle of post to display
  58. $Request->param'm''integer'''true );              // YearMonth(Day) to display
  59. $Request->param'w''integer'-1true );              // Week number
  60. $Request->param'dstart''integer'''true );         // YearMonth(Day) to start at
  61. $Request->param'unit''string'''true );            // list unit: 'posts' or 'days'
  62.  
  63. $Request->param'cat''/^[*\-]?([0-9]+(,[0-9]+)*)?$/'''true )// List of cats to restrict to
  64. $Request->param'catsel''array'array()true );  // Array of cats to restrict to
  65. foreach$catsel as $k => $v )
  66. // make sure this are all integers, to prevent SQL injection! TODO: use param( , 'array[integer]' )
  67.     $catsel[$k= (int)$v;
  68. }
  69. $Request->set_param'catsel'$catsel );
  70. // Let's compile those values right away (we use them in several different places):
  71. $cat_array array();
  72. $cat_modifier '';
  73. compile_cat_array$cat$catsel/* by ref */ $cat_array/* by ref */ $cat_modifier$blog == $blog );
  74.  
  75. $Request->param'author''/^-?[0-9]+(,[0-9]+)*$/'''true );         // List of authors to restrict to
  76.  
  77. $Request->param'order''string''DESC'true );       // ASC or DESC
  78. $Request->param'orderby''string'''true );         // list of fields to order by
  79.  
  80. $Request->param'posts''integer'0true );           // # of units to display on the page
  81. $Request->param'paged''integer'''true );          // List page number in paged display
  82.  
  83. $Request->param'poststart''integer'''true );      // Start results at this position
  84. $Request->param'postend''integer'''true );        // End results at this position
  85.  
  86. $Request->param's''string'''true );               // Search string
  87. $Request->param'sentence''string''AND'true );     // Search for sentence or for words
  88. $Request->param'exact''integer'''true );          // Require exact match of title or contents
  89.  
  90. $Request->param'preview''integer'0true );         // Is this preview ?
  91.  
  92. $Request->param'calendar''string'''true );        // Display a specific month in the calendar
  93.  
  94. $Request->param'page''integer'''true );
  95. $Request->param'more''integer'0true );
  96.  
  97. $Request->param'c''string'''true );
  98. $Request->param'tb''integer'0true );
  99. $Request->param'pb''integer'0true );
  100.  
  101. $Request->param'disp''string''posts'true );
  102. $Request->param'stats''integer');                 // deprecated
  103.  
  104. $Request->param'tempskin''string'''true );
  105.  
  106.  
  107. if!isset($timestamp_min) ) $timestamp_min '';
  108. if!isset($timestamp_max) ) $timestamp_max '';
  109.  
  110. if$preview )
  111. // Ignore this hit
  112.     $Hit->ignore true;
  113. }
  114.  
  115. ifempty($disp) )
  116. // Conversion support for old params:
  117.     if$c == 'last')
  118.     // Translate old last comments caller
  119.         $disp 'comments';
  120.     }
  121.     elseif$stats )
  122.     // Translate old stats caller
  123.         $disp 'stats';
  124.     }
  125. }
  126.  
  127. if$disp == 'stats' )
  128. {
  129.     require $view_path.'errors/_410_stats_gone.page.php'// error & exit
  130. }
  131.  
  132. // Getting current blog info:
  133. $Blog Blog_get_by_ID$blog )/* TODO: TMP: */ $blogparams get_blogparams_by_ID$blog );
  134.  
  135.  
  136. /*
  137.     TODO: blueyed>> This should get moved as default to the locale detection in _main.inc.php,
  138.             as we only want to activate the I/O charset, which is probably the user's..
  139.             It prevents using a locale/charset in the front office, apart from the one given as default for the blog!!
  140. fp>there is no blog defined in _main and there should not be any
  141. 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.
  142. */
  143. // Activate matching locale:
  144. $Debuglog->add'Activating blog locale: '.$Blog->get('locale')'locale' );
  145. locale_activate$Blog->get('locale') );
  146.  
  147.  
  148. // TODO: factorize the code below with the one in main.inc
  149.  
  150. // Check and possibly adjust $evo_charset:
  151. // NOTE: this is quite the same as with _main.inc.php, because of the (overriding) blog's locale above
  152. if$io_charset != locale_charset(false) )
  153. // io_charset changed from the initial setting in _main.inc.php
  154.  
  155.     $io_charset locale_charset(false);
  156.  
  157.     ifempty($mb_output_handler_started|| $evo_charset != $io_charset )
  158.     // we have to convert for I/O, which requires mbstrings extension
  159.         iffunction_exists('mb_convert_encoding') )
  160.         {
  161.             $Debuglog->add'$evo_charset differs from $io_charset, but mbstrings does not seem to be installed.'array('errors','locale') );
  162.             $evo_charset $io_charset// we cannot convert I/O to internal charset
  163.         }
  164.         else
  165.         // check if the encodings are supported:
  166.             iffunction_exists('mb_list_encodings') ) // PHP5
  167.             {
  168.                 $mb_encodings mb_list_encodings();
  169.             }
  170.             else
  171.             {
  172.                 $mb_encodings NULL;
  173.             }
  174.  
  175.             ifisset($mb_encodings&& in_arraystrtoupper($io_charset)$mb_encodings ) )
  176.             {
  177.                 $Debuglog->add'Cannot I/O convert because I/O charset ['.$io_charset.'] is not in mb_list_encodings()!'array('errors','locale') );
  178.                 $evo_charset $io_charset;
  179.             }
  180.             elseifisset($mb_encodings&& in_arraystrtoupper($evo_charset)$mb_encodings ) )
  181.             {
  182.                 $Debuglog->add'Cannot I/O convert because $evo_charset='.$evo_charset.' is not in mb_list_encodings()!'array('errors','locale') );
  183.                 $evo_charset $io_charset;
  184.             }
  185.             else
  186.             {
  187.                 mb_http_output$io_charset );
  188.                 ifempty($mb_output_handler_started) )
  189.                 // has not been started in _main.inc.php already:
  190.                     ob_start'mb_output_handler' );
  191.                 }
  192.             }
  193.             unset($mb_encodings);
  194.         }
  195.     }
  196.  
  197.     // Tell mbstrings what the internal encoding is:
  198.     iffunction_exists('mb_internal_encoding') )
  199.     {
  200.         mb_internal_encoding$evo_charset );
  201.     }
  202.  
  203.     $Debuglog->add'Adjusted I/O charset for blog''locale' );
  204.  
  205.     ifempty($db_config['connection_charset']) )
  206.     // Set encoding for MySQL connection (not overriding explicitely set one):
  207.         $DB->set_connection_charset$evo_charsettrue );
  208.     }
  209.  
  210.     $Debuglog->add'evo_charset: '.$evo_charset'locale' );
  211.     $Debuglog->add'io_charset: '.$io_charset'locale' );
  212.  
  213.     // Reload Blog(s) (for encoding of name, tagline etc):
  214.     // unset Cache:
  215.     $cache_blogs array();
  216.     // fills whole cache again:
  217.     $Blog Blog_get_by_ID$blog )/* TODO: TMP: */ $blogparams get_blogparams_by_ID$blog );
  218. // end of "if charset changed by blog"
  219.  
  220.  
  221. // -------------------------
  222. // Extra path info decoding:
  223. // -------------------------
  224. ifisset$resolve_extra_path ) ) $resolve_extra_path true}
  225. if$resolve_extra_path )
  226. {
  227.     // Check and Remove blog base URI from ReqPath:
  228.     $blog_baseuri substr$Blog->get('baseurl')strlen$Blog->get('baseurlroot') ) );
  229.     $Debuglog->add'blog_baseuri: "'.$blog_baseuri.'"''params' );
  230.  
  231.     if( ($pos strpos$ReqPath$blog_baseuri )) !== false )
  232.     // note: $pos will typically be 0
  233.         $path_string substr$ReqPath$pos+strlen$blog_baseuri ) );
  234.  
  235.         $Debuglog->add'Extra path info found! path_string=' $path_string 'params' );
  236.         //echo "path=[$path_string]<br />";
  237.  
  238.         // Slice the path:
  239.         $path_split explode'/'$path_string20 );
  240.  
  241.         // Remove empty slots:
  242.         $path_elements array();
  243.         foreach$path_split as $path_element )
  244.         {
  245.             if!empty$path_element ) )
  246.             {
  247.                 $path_elements[$path_element;
  248.             }
  249.         }
  250.         // echo count( $path_elements );
  251.  
  252.         $path_error 0;
  253.         $i=0;
  254.         // echo $path_elements[$i];
  255.         ifisset$path_elements[$i&& preg_match'#.+\.php[0-9]?#'$path_elements[$i) ) // QUESTION: add "$" at the end of the pattern to avoid false matches?
  256.         // Ignore *.php
  257.             $i++;
  258.             $Debuglog->add'Ignoring *.php in extra path info' 'params' );
  259.         }
  260.  
  261.         ifisset$path_elements[$i&& preg_match'#^'.$Blog->get'stub' ).'(\.php)?$#'$path_elements[$i)  )
  262.         // Ignore stub file
  263.             $i++;
  264.             $Debuglog->add'Ignoring stub file in extra path info' 'params' );
  265.         }
  266.  
  267.         // echo $path_elements[$i];
  268.         ifisset$path_elements[$i) )
  269.         {
  270.             ifis_numeric$path_elements[$i) )
  271.             // We'll consider this to be the year
  272.                 $m $path_elements[$i++];
  273.                 $Debuglog->add'Setting year from extra path info. $m=' $m 'params' );
  274.  
  275.                 ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  276.                 // We'll consider this to be the month
  277.                     $m .= $path_elements[$i++];
  278.                     $Debuglog->add'Setting month from extra path info. $m=' $m 'params' );
  279.  
  280.                     ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  281.                     // We'll consider this to be the day
  282.                         $m .= $path_elements[$i++];
  283.                         $Debuglog->add'Setting day from extra path info. $m=' $m 'params' );
  284.  
  285.                         ifisset$path_elements[$i&& (!empty$path_elements[$i)) )
  286.                         // We'll consider this to be a ref to a post
  287.                             // We are accessing a post by permalink
  288.                             // Set a lot of defaults as if we had received a complex URL:
  289.                             $m '';
  290.                             $more 1// Display the extended entries' text
  291.                             $c 1;    // Display comments
  292.                             $tb 1;   // Display trackbacks
  293.                             $pb 1;   // Display pingbacks
  294.  
  295.                             ifpreg_match"#^p([0-9]+)$#"$path_elements[$i]$req_post ) )
  296.                             // The last param is of the form p000
  297.                                 // echo 'post number';
  298.                                 $p $req_post[1];        // Post to display
  299.                             }
  300.                             else
  301.                             // Last param is a string, we'll consider this to be a post urltitle
  302.                                 $title $path_elements[$i];
  303.                                 // echo 'post title : ', $title;
  304.                             }
  305.                         }
  306.                     }
  307.                 }
  308.                 elseifisset$path_elements[$i&& substr$path_elements[$i]0== 'w' )
  309.                 // We consider this a week number
  310.                     $w substr$path_elements[$i]1);
  311.                 }
  312.             }
  313.             else
  314.             {    // We did not get a number/year...
  315.                 $path_error 404;
  316.             }
  317.         }
  318.  
  319.         if$path_error == 404 )
  320.         {    // The request points to something we won't be able to resolve:
  321.  
  322.             // First check, if it's an old-style backoffice-Path (from a redirect-everything non-existing to index.php mod_rewrite rule):
  323.             ifstrpos$ReqPath'/admin/' === )
  324.             {
  325.                 // Redirect to admin url and pass request_uri as path_info, so it can be resolved by admin.php to the right menu entry:
  326.                 header'Location: '.$admin_url.'/'.substr($ReqURI7) );
  327.                 exit;
  328.             }
  329.  
  330.             require $view_path.'errors/_404_not_found.page.php'// error & exit
  331.         }
  332.     }
  333. }
  334.  
  335. if( (!empty($p)) || (!empty($title)) || (!empty($preview)) )
  336. // We are going to display a single post
  337.     $disp 'single';
  338. }
  339.  
  340. ifempty$disp ) )
  341. // default display:
  342.     $disp 'posts';
  343. }
  344.  
  345. if( ($disp == 'posts'|| ($disp == 'single') )
  346. // If we are going to display posts and not something special...
  347.  
  348.     // On single post requests, check if we're on the right blog!
  349.     if$redirect_to_postblog && $disp == 'single' && $preview )
  350.     // Yes we need to check.
  351.         if!empty($p) )
  352.             $Item $ItemCache->get_by_ID$pfalse );
  353.         else
  354.             $Item $ItemCache->get_by_urltitle$titlefalse );
  355.  
  356.         if( ($Item !== false&& ($Item->blog_ID != $blog) )
  357.         // We're on the wrong blog (probably an old permalink) let's redirect
  358.             $new_permalink $Item->get_permanent_url''''false'&' );
  359.  
  360.             header ("Location: $new_permalink");
  361.             exit();
  362.         }
  363.     }
  364.  
  365.     // Note: even if we request the same post, the following will do more restrictions (dates, etc.)
  366.     // TODO: There's a bug here with using $catsel (instead of $cat_array), which I've reported to dev-ML (don't remember). Francois, please look into it.
  367.     $MainList new ItemList(
  368.         $blog$show_statuses$p$m$w$cat$catsel$author$order,
  369.         $orderby$posts$paged$poststart$postend$s$sentence$exact,
  370.         $preview$unit$timestamp_min$timestamp_max$title$dstart );
  371.     $MainList->get_max_paged();
  372.  
  373.     // Old style globals for category.funcs:
  374.     $postIDlist $MainList->postIDlist;
  375.     $postIDarray $MainList->postIDarray;
  376. }
  377.  
  378. // Default display params:
  379.  
  380. // Displaying of blog list on templates?
  381. if!isset($display_blog_list) )
  382. // If not already set in stub:
  383.     $display_blog_list $Blog->get('disp_bloglist');
  384. }
  385.  
  386.  
  387. /*
  388.  * Now, we'll jump to displaying!
  389.  */
  390.  
  391. // Trigger plugin event:
  392. $Plugins->trigger_event'BeforeBlogDisplay' );
  393.  
  394. // Check if a temporary skin has been requested (used for RSS syndication for example):
  395. if!empty($tempskin) )
  396. {
  397.     // This will be handled like any other skin, except that it will not be stored in a cookie:
  398.     $skin $tempskin;
  399.     $default_skin '_rss'// That's gonna be the fallback for now.
  400.     // TODO [post-phoenix]: decide when or when not you are allowed to override a 'force_skin' directive,
  401.     // and when or when not you are allowed to fall back to $default_skin.
  402. }
  403.  
  404. // Let's check if a skin has been forced in the stub file:
  405. // Note: URL skin requests are handled with param() 20 lines below
  406. // Note: with "register_globals = On" this may be set from URL.. (in which case the code 20 line sbelow becomes useless)
  407. //       blueyed>> You've said that it's not security issue etc.. but I still would init $skin in /conf/_advanced.php and use empty() here.
  408. if!isset$skin ) )
  409. // No skin forced in stub (not even '' for no-skin)...
  410.     $Debuglog->add'No skin forced.''skin' );
  411.     // We're going to need a default skin:
  412.     if(  ( !isset$default_skin ) )          // No default skin forced in stub
  413.         || !skin_exists$default_skin ) ) )  // Or the forced default does not exist
  414.     // Use default from the database
  415.         $default_skin $Blog->get('default_skin');
  416.     }
  417.  
  418.     if!skin_exists$default_skin || empty$default_skin ) )
  419.     // blog's default skin does not exist
  420.         // Because a lot of bloggers will set themseleves a cookie and delete the default skin,
  421.         // we have to make this fool proof extra checking!
  422.         printfT_('The default 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. Contact the <a %s>webmaster</a>...')$default_skin $Blog->dget('shortname')'href="'.$admin_url.'?ctrl=collections&amp;action=edit&amp;blog='.$Blog->ID.'"''href="mailto:'.$admin_email.'"');
  423.         debug_die();
  424.     }
  425.     $Debuglog->add'$default_skin = '.$default_skin'skin' );
  426.  
  427.     if$Blog->get('force_skin') )
  428.     // Blog params tell us to force the use of default skin
  429.         $skin $default_skin;
  430.         $Debuglog->add'Forced skin: '.$skin'skin' );
  431.     }
  432.     else
  433.     // Get the saved skin in cookie or default:
  434.         $Request->param$cookie_state'string'$default_skinfalsetrue )// override (in case there has been "param($cookie_state)" before, which set it already to '')
  435.         $Debuglog->add'Skin after looking at cookie: '.$$cookie_state'skin' );
  436.         // Get skin by params or default to cookie
  437.         // (if cookie was not set, the $$cookie_state contains default skin!)
  438.         $Request->param'skin''string'$$cookie_state );
  439.         $Debuglog->add'Skin after looking at params: '.$skin'skin' );
  440.     }
  441. }
  442.  
  443.  
  444. // At this point $skin holds the name of the skin we want to use, or '' for no skin!
  445.  
  446. // check to see if we want to display the popup or the main template
  447. $Request->param'template''string''main'true );
  448.  
  449. if!empty$skin ) )
  450. // We want to display now:
  451.  
  452.     ifempty$tempskin )
  453.      && !empty($_GET['skin']|| !empty($_POST['skin') ) )
  454.     // We have just asked for a skin change explicitely
  455.         // Set a cookie to remember it:
  456.         // Including config and functions files   ??
  457.  
  458.         ifsetcookie$cookie_state$skin$cookie_expires$Blog->get('cookie_path')$Blog->get('cookie_domain')) )
  459.         // This damn failed !
  460.             echo "<p>setcookie failed!</p>";
  461.         }
  462.     }
  463.  
  464.     ifereg'([^-A-Za-z0-9._]|\.\.)'$skin ) )
  465.     {
  466.         // echo ("<p>Invalid skin name!</p>");
  467.         $skin $default_skin;
  468.     }
  469.     elseif!skin_exists($skin) )
  470.     {
  471.         // echo "<p>Oops, no such skin!</p>";
  472.         $skin $default_skin;
  473.     }
  474.  
  475.     // TODO: sanitize $template and allow any request on _xxx.tpl.php or sth like that.
  476.     if$template == 'popup' )
  477.     // Do the popup display
  478.         requireget_path'skins' ).$skin.'/_popup.php' );
  479.     }
  480.     else
  481.     // Do the main display
  482.         requireget_path'skins' ).$skin.'/_main.php' );
  483.     }
  484. }
  485. else
  486. // we don't want to use a skin
  487.     if$template == 'popup' )
  488.     // Do the popup display
  489.         requireget_path'skins' ).'_popup.php' );
  490.         exit();
  491.     }
  492.  
  493.     $Debuglog->add'No skin or popup requested.''skin' );
  494.     // If we end up here the blog file should be a full template, not just a stub...
  495. }
  496.  
  497.  
  498. /*
  499.  nolog */
  500. ?>

Documentation generated on Tue, 18 Dec 2007 23:10:32 +0100 by phpDocumentor 1.4.0