b2evolution

Multilingual multiuser multiblog engine

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

Source for file _class_blog.php

Documentation is available at _class_blog.php

  1. <?php
  2. /**
  3.  * This file implements the blog object
  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. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__).'/_class_dataobject.php';
  17.  
  18. /**
  19.  * Blog
  20.  *
  21.  * Blog object with params
  22.  *
  23.  * @package evocore
  24.  */
  25. class Blog extends DataObject
  26. {
  27.     /**
  28.      * Short name for use in navigation menus
  29.      */
  30.     var $shortname;
  31.     /**
  32.      * Complete name
  33.      */
  34.     var $name;
  35.     /**
  36.      * Tagline to be displayed on template
  37.      */
  38.     var $tagline;
  39.     var $shortdesc;    // description
  40.     var $longdesc;
  41.     var $locale;
  42.     var $access_type;
  43.     var $siteurl;
  44.     var $staticfilename;
  45.     var $stub;
  46.     var $links_blog_ID = 0;
  47.     var $notes;
  48.     var $keywords;
  49.     var $allowtrackbacks = 0;
  50.     var $allowpingbacks = 0;
  51.     var $pingb2evonet = 0;
  52.     var $pingtechnorati = 0;
  53.     var $pingweblogs = 1;
  54.     var $pingblodotgs = 0;
  55.     var $default_skin;
  56.     var $force_skin = 0;
  57.     var $disp_bloglist = 1;
  58.     var $in_bloglist = 1;
  59.     var $UID;
  60.  
  61.     /** 
  62.      * Constructor
  63.      *
  64.      * {@internal Blog::Blog(-) }}
  65.      *
  66.      * @param object DB row
  67.      */
  68.     function Blog$db_row NULL )
  69.     {
  70.         global $tableblogs;
  71.         
  72.         // Call parent constructor:
  73.         parent::DataObject$tableblogs'blog_''blog_ID' );
  74.     
  75.         if$db_row == NULL )
  76.         {
  77.             global $default_locale;
  78.             // echo 'Creating blank blog';
  79.             $this->shortname = T_('New blog');
  80.             $this->name = T_('New weblog');
  81.             $this->locale = $default_locale;
  82.             $this->access_type = 'index.php';
  83.             $this->stub = 'new';
  84.             $this->default_skin = 'basic';
  85.         }
  86.         else
  87.         {
  88.             $this->ID = $db_row->blog_ID;
  89.             $this->shortname = $db_row->blog_shortname;
  90.             $this->name = $db_row->blog_name;
  91.             $this->tagline = $db_row->blog_tagline;
  92.             $this->shortdesc = $db_row->blog_description;    // description
  93.             $this->longdesc = $db_row->blog_longdesc;
  94.             $this->locale = $db_row->blog_locale;
  95.             $this->access_type = $db_row->blog_access_type;
  96.             $this->siteurl = $db_row->blog_siteurl;
  97.             $this->staticfilename = $db_row->blog_staticfilename;
  98.             $this->stub = $db_row->blog_stub;
  99.             $this->links_blog_ID = $db_row->blog_links_blog_ID;
  100.             $this->notes = $db_row->blog_notes;
  101.             $this->keywords = $db_row->blog_keywords;
  102.             $this->allowtrackbacks = $db_row->blog_allowtrackbacks;
  103.             $this->allowpingbacks = $db_row->blog_allowpingbacks;
  104.             $this->pingb2evonet = $db_row->blog_pingb2evonet;
  105.             $this->pingtechnorati = $db_row->blog_pingtechnorati;
  106.             $this->pingweblogs = $db_row->blog_pingweblogs;
  107.             $this->pingblodotgs = $db_row->blog_pingblodotgs;
  108.             $this->default_skin = $db_row->blog_default_skin;
  109.             $this->force_skin = $db_row->blog_force_skin;
  110.             $this->disp_bloglist = $db_row->blog_disp_bloglist;
  111.             $this->in_bloglist = $db_row->blog_in_bloglist;
  112.             $this->UID = $db_row->blog_UID;
  113.         }
  114.     }    
  115.  
  116.  
  117.     /** 
  118.      * Set param value
  119.      *
  120.      * {@internal Blog::set(-) }}
  121.      *
  122.      * @param string Parameter name
  123.      * @return mixed Parameter value
  124.      */
  125.     function set$parname$parvalue )
  126.     {
  127.         global $Settings;
  128.         
  129.         switch$parname )
  130.         {
  131.             case 'ID':
  132.             case 'allowtrackbacks':
  133.             case 'allowpingbacks':
  134.             case 'pingb2evonet':
  135.             case 'pingtechnorati':
  136.             case 'pingweblogs':
  137.             case 'pingblodotgs':
  138.             case 'disp_bloglist':
  139.             case 'force_skin':
  140.                 parent::set_param$parname'number'$parvalue );
  141.                 break;
  142.             
  143.             case 'access_type':
  144.                 if$parvalue == 'default' )
  145.                 {
  146.                     $Settings->set('default_blog_ID'$this->ID);
  147.                     $Settings->updateDB();
  148.                 }
  149.                 
  150.             default:
  151.                 parent::set_param$parname'string'$parvalue );
  152.         }
  153.     }
  154.  
  155.     /** 
  156.      * Generate blog URL
  157.      *
  158.      * {@internal Blog::gen_blogurl(-)}}
  159.      *
  160.      * @param string default|dynamic|static
  161.      * @param boolean should this be an absolute URL? (otherwise: relative to $baseurl)
  162.      */
  163.     function gen_blogurl$type 'default'$absolute true )
  164.     {
  165.         global $baseurl$basepath$Settings;
  166.         
  167.         $base $absolute $baseurl '';
  168.  
  169.         if$type == 'static' )
  170.         {    // We want the static page, there is no acces type option here:
  171.             ifis_file$basepath.$this->siteurl.'/'.$this->staticfilename ) )
  172.             // If static page exists:
  173.                 return $base.$this->siteurl.'/'.$this->staticfilename;
  174.             }
  175.         }
  176.         
  177.         switch$this->access_type )
  178.         {
  179.             case 'default':
  180.                 // Access through index.php as default blog
  181.                 if$Settings->get('default_blog_ID'== $this->ID )
  182.                 {    // Safety check! We only do that kind of linking if this is really the default blog...
  183.                     return $base.$this->siteurl.'/index.php';
  184.                 }
  185.                 // ... otherwise, we add the blog ID:
  186.             
  187.             case 'index.php':
  188.                 // Access through index.php + blog qualifier
  189.                 if$Settings->get('links_extrapath') )
  190.                 {
  191.                     return $base.$this->siteurl.'/index.php/'.$this->stub;
  192.                 }
  193.                 return $base.$this->siteurl.'/index.php?blog='.$this->ID;
  194.             
  195.             case 'stub':
  196.                 // Access through stub file
  197.                 $blogurl $base.$this->siteurl.'/'.$this->stub;
  198.                 if( ($type == 'dynamic'&& !preg_match'#.php$#'$blogurl ) ) )
  199.                 {    // We want to force the dynamic page but the URL is not explicitely dynamic
  200.                     $blogurl .= '.php';
  201.                 }
  202.                 return $blogurl;
  203.         
  204.             default:
  205.                 die'Unhandled Blog access type ['.$this->access_type.']' );
  206.         }
  207.     }
  208.  
  209.     /** 
  210.      * Get a param
  211.      *
  212.      * {@internal Blog::get(-)}}
  213.      */
  214.     function get$parname )
  215.     {
  216.         global $xmlsrv_url$admin_email$baseurl$basepath;
  217.  
  218.         switch$parname )
  219.         {
  220.             case 'subdir':
  221.                 return $this->siteurl;
  222.     
  223.             case 'suburl':
  224.                 return $this->gen_blogurl'default'false );
  225.  
  226.             case 'blogurl':
  227.             case 'link':            // RSS wording
  228.             case 'url':
  229.                 return $this->gen_blogurl'default' );
  230.             
  231.             case 'dynurl':
  232.                 return $this->gen_blogurl'dynamic' );
  233.  
  234.             case 'staticurl':
  235.                 return $this->gen_blogurl'static' );
  236.             
  237.             case 'dynfilepath':
  238.                 return $basepath.$this->siteurl.'/'.$this->stub.preg_match'#.php$#'$this->stub '' '.php' );
  239.  
  240.             case 'staticfilepath':
  241.                 return $basepath.$this->siteurl.'/'.$this->staticfilename;
  242.             
  243.             case 'baseurl':
  244.                 return $baseurl.$this->siteurl.'/';
  245.             
  246.             case 'blogstatsurl':
  247.                 return '';                        // Deprecated!
  248.             
  249.             case 'lastcommentsurl':
  250.                 return url_add_param$this->gen_blogurl'default' )'disp=comments' );
  251.             
  252.             case 'arcdirurl':
  253.                 return url_add_param$this->gen_blogurl'default' )'disp=arcdir' );
  254.             
  255.             case 'description':            // RSS wording
  256.             case 'shortdesc':
  257.                     return $this->shortdesc;
  258.                 break;
  259.             
  260.             case 'rdf_url':
  261.                 return $xmlsrv_url.'/rdf.php?blog='.$this->ID;
  262.  
  263.             case 'rss_url':
  264.                 return $xmlsrv_url.'/rss.php?blog='.$this->ID;
  265.             
  266.             case 'rss2_url':
  267.                 return $xmlsrv_url.'/rss2.php?blog='.$this->ID;
  268.             
  269.             case 'atom_url':
  270.                 return $xmlsrv_url.'/atom.php?blog='.$this->ID;
  271.             
  272.             case 'comments_rdf_url':
  273.                 return $xmlsrv_url.'/rdf.comments.php?blog='.$this->ID;
  274.             
  275.             case 'comments_rss_url':
  276.                 return $xmlsrv_url.'/rss.comments.php?blog='.$this->ID;
  277.             
  278.             case 'comments_rss2_url':
  279.                 return $xmlsrv_url.'/rss2.comments.php?blog='.$this->ID;
  280.             
  281.             case 'comments_atom_url':
  282.                 return $xmlsrv_url.'/atom.comments.php?blog='.$this->ID;
  283.             
  284.             case 'pingback_url':
  285.                 return $xmlsrv_url.'/xmlrpc.php';
  286.             
  287.             case 'admin_email':
  288.                 return $admin_email;
  289.                         
  290.             default:
  291.                 // All other params:
  292.                 return parent::get$parname );
  293.         }
  294.     }
  295.  
  296.     
  297.     /** 
  298.      * Delete a blog and dependencies from database
  299.      *
  300.      * Includes WAY TOO MANY requests because we try to be compatible with mySQL 3.23, bleh!
  301.      *
  302.      * {@internal Blog::dbdelete(-) }}
  303.      *
  304.      * @param boolean true if you want to try to delete the stub file
  305.      * @param boolean true if you want to try to delete the static file
  306.      * @param boolean true if you want to echo progress
  307.      */
  308.     function dbdelete$delete_stub_file false$delete_static_file false$echo false )
  309.     {
  310.         global $DB$tablehitlog$tablecategories$tablecomments$tableposts
  311.                         $tablepostcats$tableblogusers$cache_blogs;
  312.  
  313.         // Note: No need to localize the status messages...
  314.         if$echo echo '<p>mySQL 3.23 compatibility mode!';
  315.  
  316.         // Get list of cats that are going to be deleted (3.23)
  317.         if$echo echo '<br />Getting category list to delete... ';
  318.         $cat_list $DB->get_list"SELECT cat_ID 
  319.                                                                 FROM $tablecategories
  320.                                                                 WHERE cat_blog_ID = $this->ID" );
  321.  
  322.         ifempty$cat_list ) )
  323.         {    // There are no cats to delete
  324.             echo 'None!';
  325.         }
  326.         else
  327.         {    // Delete the cats & dependencies
  328.     
  329.             // Get list of posts that are going to be deleted (3.23)
  330.             if$echo echo '<br />Getting post list to delete... ';
  331.             $post_list $DB->get_list"SELECT postcat_post_ID 
  332.                                                                         FROM $tablepostcats
  333.                                                                         WHERE postcat_cat_ID IN ($cat_list));
  334.             
  335.             ifempty$post_list ) )
  336.             {    // There are no posts to delete
  337.                 echo 'None!';
  338.             }
  339.             else
  340.             {    // Delete the posts & dependencies
  341.             
  342.                 // Delete postcats
  343.                 if$echo echo '<br />Deleting post-categories... ';
  344.                 $ret $DB->query(    "DELETE FROM $tablepostcats
  345.                                                             WHERE postcat_cat_ID IN ($cat_list));
  346.                 if$echo printf'(%d rows)'$ret );
  347.                 
  348.                 
  349.                 // Delete comments
  350.                 if$echo echo '<br />Deleting comments on blog\'s posts... ';
  351.                 $ret $DB->query"DELETE FROM $tablecomments 
  352.                                                         WHERE comment_post_ID IN ($post_list));
  353.                 if$echo printf'(%d rows)'$ret );
  354.         
  355.         
  356.                 // Delete posts
  357.                 if$echo echo '<br />Deleting blog\'s posts... ';
  358.                 $ret $DB->query(    "DELETE FROM $tableposts 
  359.                                                             WHERE ID  IN ($post_list));
  360.                 if$echo printf'(%d rows)'$ret );
  361.  
  362.             // / are there posts?
  363.             
  364.             // Delete categories
  365.             if$echo echo '<br />Deleting blog\'s categories... ';
  366.             $ret $DB->query"DELETE FROM $tablecategories
  367.                                                     WHERE cat_blog_ID = $this->ID" );
  368.             if$echo printf'(%d rows)'$ret );
  369.  
  370.         // / are there cats?
  371.         
  372.         // Delete blogusers        
  373.         if$echo echo '<br />Deleting user-blog permissions... ';
  374.         $ret $DB->query"DELETE FROM $tableblogusers 
  375.                                                 WHERE bloguser_blog_ID = $this->ID" );
  376.         if$echo printf'(%d rows)'$ret );
  377.         
  378.         // Delete hitlogs
  379.         if$echo echo '<br />Deleting blog hitlogs... ';
  380.         $ret $DB->query"DELETE FROM $tablehitlog 
  381.                                                 WHERE hit_blog_ID = $this->ID" );
  382.         if$echo printf'(%d rows)'$ret );
  383.     
  384.         if$delete_stub_file )
  385.         // Delete stub file
  386.             if$echo echo '<br />Trying to delete stub file... ';
  387.             if@unlink$this->get('dynfilepath') ) )
  388.                 if$echo 
  389.                 {
  390.                     echo '<span class="error">';
  391.                     printf(    T_('ERROR! Could not delete! You will have to delete the file [%s] by hand.')
  392.                                     $this->get('dynfilepath') );
  393.                     echo '</span>';
  394.                 }
  395.             else
  396.                 if$echo echo 'OK.';
  397.         }
  398.         if$delete_static_file )
  399.         // Delete static file
  400.             if$echo echo '<br />Trying to delete static file... ';
  401.             if@unlink$this->get('staticfilepath') ) )
  402.                 if$echo 
  403.                 {
  404.                     echo '<span class="error">';
  405.                     printf(    T_('ERROR! Could not delete! You will have to delete the file [%s] by hand.')
  406.                                     $this->get('staticfilepath') );
  407.                     echo '</span>';
  408.                 }
  409.             else
  410.                 if$echo echo 'OK.';
  411.         }
  412.                     
  413.         // Unset cache entry:
  414.         unset$cache_blogs[$this->ID);
  415.         
  416.         // Delete main (blog) object:
  417.         parent::dbdelete();
  418.                 
  419.         echo '<br/>Done.</p>';
  420.     }
  421.     
  422. }
  423. ?>

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