b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _blog_main.php

Documentation is available at _blog_main.php

  1. <?php
  2. /**
  3.  * This file loads the blog!
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11.  
  12. /**
  13.  * Initialize everything:
  14.  */
  15. require_once (dirname(__FILE__)'/_main.php');
  16.  
  17. // Getting GET or POST parameters:
  18. param'blog''integer'0true );  // Can't use $default_to_blog because the param must always be included in regenerate_url() when present
  19. param'p''integer'''true );              // Specific post number to display
  20. param'm''integer'''true );              // YearMonth(Day) to display
  21. param'w''integer'-1true );              // Week number
  22. param'cat''string'''true );             // List of cats to restrict to
  23. param'catsel''array'array()true );      // Array of cats to restrict to
  24. foreach$catsel as $k => $v )
  25. // make sure this are all integers, to prevent SQL injection!
  26.     $catsel[$k= (int)$v;
  27. }
  28. param'author''integer'''true );         // List of authors to restrict to
  29. param'order''string''DESC'true );       // ASC or DESC
  30. param'orderby''string'''true );         // list of fields to order by
  31. param'posts''integer'''true );          // # of posts to display on the page
  32. param'paged''integer'''true );          // List page number in paged display
  33. param'poststart''integer'''true );      // Start results at this position
  34. param'postend''integer'''true );        // End results at this position
  35. // param( 'search', 'string' );                 // obsolete (dangerous!)
  36. param's''string'''true );               // Search string
  37. param'sentence''string''AND'true );     // Search for sentence or for words
  38. param'exact''integer'''true );          // Require exact match of title or contents
  39. param'preview''integer'0true );         // Is this preview ?
  40. param'calendar''string'''true );        // Display a specific month in the calendar
  41. param'c''string'''true );                                
  42. param'page''integer'''true );
  43. param'more''integer'0true );
  44. param'title''string'''true );                        // urtitle of post to display
  45. param'tb''integer'0true );
  46. param'pb''integer'0true );
  47. param'disp''string'''true );
  48. param'stats''integer');                 // deprecated
  49. if!isset($timestamp_min) ) $timestamp_min '';
  50. if!isset($timestamp_max) ) $timestamp_max '';
  51.  
  52. ifempty($disp) )
  53. {    // Conversion support for old params:
  54.     if$c == 'last'
  55.     {    // Translate old last comments caller
  56.         $disp 'comments';
  57.     }
  58.     elseif$stats )
  59.     {    // Translate old stats caller
  60.         $disp 'stats';
  61.     }
  62. }
  63.  
  64. if$disp == 'stats' )
  65. {
  66.      require dirname(__FILE__).'/_410_stats_gone.page.php';    // error & exit
  67. }
  68.  
  69. // Getting current blog info:
  70. $Blog Blog_get_by_ID$blog )/* TMP: */ $blogparams get_blogparams_by_ID$blog );
  71.  
  72. // Activate matching locale:
  73. debug_log('Activating blog locale: '.$Blog->get('locale'));
  74. locale_activate$Blog->get('locale') );
  75.  
  76. // -------------------------
  77. // Extra path info decoding:
  78. // -------------------------
  79. if!isset$resolve_extra_path ) ) $resolve_extra_path true;
  80. if!isset$generating_static ) ) $generating_static false;
  81. if$resolve_extra_path && $generating_static )
  82. {
  83.     // Check and Remove blog baseurl from ReqPath:
  84.     $blog_baseurl substr$Blog->get'baseurl' )strlen$baseurlroot ) );
  85.     if( ($pos strpos$ReqPath$blog_baseurl )) !== false )
  86.     // note: $pos will typically be 0
  87.         $path_string substr$ReqPath$pos+strlen$blog_baseurl ) );
  88.         //echo "path=[$path_string]<br />";
  89.  
  90.         // Slice the path:
  91.         $path_split explode'/'$path_string20 );
  92.  
  93.         // Remove empty slots:
  94.         $path_elements array();
  95.         foreach$path_split as $path_element )
  96.         {
  97.             if!empty$path_element ) )
  98.             {
  99.                 $path_elements[$path_element;
  100.             }
  101.         }
  102.         // echo count( $path_elements );
  103.  
  104.         $path_error 0;
  105.         $i=0;
  106.         // echo $path_elements[$i];
  107.         ifisset$path_elements[$i&& preg_match'#.+\.php[0-9]?#'$path_elements[$i) )
  108.         // Ignore *.php
  109.             // echo 'Ignoring *.php';
  110.             $i++;
  111.         }
  112.  
  113.         ifisset$path_elements[$i&& preg_match'#^'.$Blog->get'stub' ).'(\.php)?$#'$path_elements[$i)  )
  114.         // Ignore stub file
  115.             // echo 'Ignoring stub file';
  116.             $i++;
  117.         }
  118.  
  119.         // echo $path_elements[$i];
  120.         ifisset$path_elements[$i) )
  121.         {
  122.             ifis_numeric$path_elements[$i) )
  123.             // We'll consider this to be the year
  124.                 $m $path_elements[$i++];
  125.  
  126.                 ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  127.                 // We'll consider this to be the month
  128.                     $m .= $path_elements[$i++];
  129.  
  130.                     ifisset$path_elements[$i&& is_numeric$path_elements[$i) )
  131.                     // We'll consider this to be the day
  132.                         $m .= $path_elements[$i++];
  133.  
  134.                         ifisset$path_elements[$i&& (!empty$path_elements[$i)) )
  135.                         // We'll consider this to be a ref to a post
  136.                             // We are accessing a post by permalink
  137.                             // Set a lot of defaults as if we had received a complex URL:
  138.                             $m '';
  139.                             $more 1// Display the extended entries' text
  140.                             $c 1;    // Display comments
  141.                             $tb 1;   // Display trackbacks
  142.                             $pb 1;   // Display pingbacks
  143.  
  144.                             ifpreg_match"#^p([0-9]+)$#"$path_elements[$i]$req_post ) )
  145.                             // The last param is of the form p000
  146.                                 // echo 'post number';
  147.                                 $p $req_post[1];        // Post to display
  148.                             }
  149.                             else
  150.                             // Last param is a string, we'll consider this to be a post urltitle
  151.                                 $title $path_elements[$i];
  152.                                 // echo 'post title : ', $title;
  153.                             }
  154.                         }
  155.                     }
  156.                 }
  157.                 elseifisset$path_elements[$i&& substr$path_elements[$i]0== 'w' )
  158.                 // We consider this a week number
  159.                     $w substr$path_elements[$i]1);
  160.                 }
  161.             }
  162.             else
  163.             {    // We did not get a number/year...
  164.                 $path_error 404;
  165.             }
  166.         }
  167.  
  168.         if$path_error == 404 )
  169.         {    // The request points to something we won't be able to resolve:
  170.            require dirname(__FILE__).'/_404_not_found.page.php';    // error & exit
  171.         }
  172.     }
  173. }
  174.  
  175. if( (!empty($p)) || (!empty($title)) || (!empty($preview)) )
  176. // We are going to display a single post
  177.     $disp 'single';
  178. }
  179.  
  180. ifempty$disp ) )
  181. // default display:
  182.     $disp 'posts';
  183. }
  184.  
  185. if( ($disp == 'posts'|| ($disp == 'single') )
  186. // If we are going to display posts and not something special...
  187.  
  188.     // On single post requests, check if we're on the right blog!
  189.     if$redirect_to_postblog && $disp == 'single' ) )
  190.     {    // Yes we need to check.
  191.         if!empty($p) )
  192.             $Item Item_get_by_ID$p );    // TODO: use cache
  193.         else
  194.             $Item Item_get_by_title$title );    // TODO: use cache
  195.             
  196.         if( ($Item !== false&& ($Item->blog_ID != $blog) )
  197.         {    // We're on the wrong blog (probably an old permalink) let's redirect
  198.             $new_permalink $Item->gen_permalink''''false'&' );
  199.       # echo $new_permalink;
  200.             header ("Location: $new_permalink");
  201.             exit();
  202.         }
  203.     }
  204.  
  205.     // Note: even if we request the same post, the following will do more restrictions (dates, etc.)
  206.     $MainList new ItemList$blog$show_statuses$p$m$w$cat$catsel$author$order
  207.                                                             $orderby$posts$paged$poststart$postend$s$sentence$exact,
  208.                                                             $preview''''$timestamp_min$timestamp_max$title );
  209.     
  210.     $posts_per_page $MainList->posts_per_page;
  211.     $what_to_show $MainList->what_to_show;
  212.     $request $MainList->request;
  213.     // $result = & $MainList->result;
  214.     $result_num_rows $MainList->get_num_rows();
  215.     $postIDlist $MainList->postIDlist;
  216.     $postIDarray $MainList->postIDarray;
  217. }
  218. else
  219. {    // we are not trying to display posts:
  220.     $result_num_rows 0;
  221. }
  222.  
  223. // Default display params:
  224.  
  225. // Displaying of vlog list on templates?
  226. if!isset($display_blog_list) )
  227. {    // If not already set in stub:
  228.     $display_blog_list get_bloginfo('disp_bloglist');
  229. }
  230.  
  231. /*
  232.  * Now, we'll jump to displaying!
  233.  */
  234. if!isset$skin ) ) 
  235. // No skin forced in stub (not even '' for no-skin)...
  236.  
  237.     // We're going to need a default skin:
  238.     if(  ( !isset$default_skin ) )                     // No default skin forced in stub
  239.         || !skin_exists$default_skin ) ) )    // Or the forced default does not exist
  240.     {    // Use default from the datatabse
  241.         $default_skin $Blog->get('default_skin');
  242.     }
  243.     
  244.     if!skin_exists$default_skin )    || empty$default_skin ) )
  245.     // blog's default skin does not exist
  246.         // Because a lot of bloggers will set themseleves a cookie and delete the default skin,
  247.         // we have to make this fool proof extra checking!
  248.         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.'/b2blogs.php?action=edit&amp;blog='.$Blog->ID.'"''href="mailto:'.$admin_email.'"');
  249.         die();
  250.     }
  251.  
  252.     if$Blog->get('force_skin') )
  253.     {    // Blog params tell us to force the use of default skin
  254.         $skin $default_skin;
  255.     }
  256.     else
  257.     {    // Get the saved skin in cookie or default:
  258.         param$cookie_state'string'$default_skin );
  259.         // Get skin by params or default to cookie 
  260.         // (if cookie was not set, the $$cookie_state contains default skin!)
  261.         param'skin''string'$$cookie_state );
  262.     }
  263. }
  264.  
  265. // At this point $skin holds the name of the skin we want to use, or '' for no skin!
  266.  
  267. // check to see if we want to display the popup or the main template
  268. param'template''string''main'true );
  269.  
  270. if!empty$skin ) )
  271. {    // We want to display now:
  272.     
  273.     if( (!empty($_GET['skin'])) || (!empty($_POST['skin'])) )
  274.     {    // We have just asked for the skin explicitely
  275.         // Set a cookie to remember it:
  276.         // Including config and functions files
  277.         ifsetcookie$cookie_state$skin$cookie_expires$cookie_path$cookie_domain) )
  278.         {    // This damn failed !
  279.             echo "<p>setcookie failed!</p>";
  280.         }
  281.         // Erase OLD versions cookies:
  282.         ifsetcookie'b2evostate'''$cookie_expired$cookie_path$cookie_domain) )
  283.         {    // This damn failed !
  284.             echo "<p>setcookie failed!</p>";
  285.         }
  286.         ifsetcookie'b2evostate'''$cookie_expired'/') )
  287.         {    // This damn failed !
  288.             echo "<p>setcookie failed!</p>";
  289.         }
  290.     }
  291.  
  292.     ifereg'([^-A-Za-z0-9._]|\.\.)'$skin ) )
  293.     {
  294.         // echo ("<p>Invalid skin name!</p>");
  295.         $skin $default_skin;
  296.     }
  297.     elseif!skin_exists($skin) )
  298.     {
  299.         // echo "<p>Oops, no such skin!</p>";
  300.         $skin $default_skin;
  301.     }
  302.  
  303.     if$template == 'popup' )
  304.     {    // Do the popup display
  305.         require get_path'skins' )."/$skin/_popup.php";
  306.     }
  307.     else
  308.     {    // Do the main display
  309.         require get_path'skins' )."/$skin/_main.php";
  310.     }
  311. }
  312. else
  313. {    // we don't want to use a skin
  314.     if$template == 'popup' )
  315.     {    // Do the popup display
  316.         require get_path'skins' ).'/_popup.php';
  317.         exit();
  318.     }
  319.     // If we end up here the blog file should be a full template, not just a stub...
  320. }
  321. ?>

Documentation generated on Tue, 20 May 2008 01:52:24 +0200 by phpDocumentor 1.4.2