b2evolution

Multilingual multiuser multiblog engine

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

Source for file _functions_blogs.php

Documentation is available at _functions_blogs.php

  1. <?php
  2. /**
  3.  * Blog handling functions
  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_blogcache.php';
  17.  
  18. /**
  19.  * blog_create(-)
  20.  *
  21.  * Create a new a blog
  22.  * This funtion has to handle all needed DB dependencies!
  23.  *
  24.  * fplanque: created
  25.  */
  26. function blog_create(
  27.     $blog_name,
  28.     $blog_shortname,
  29.     $blog_siteurl,
  30.     $blog_stub,
  31.     $blog_staticfilename '',
  32.     $blog_tagline '',
  33.     $blog_description '',
  34.     $blog_longdesc '',
  35.     $blog_locale '#',
  36.     $blog_notes '',
  37.     $blog_keywords '',
  38.     $blog_links_blog_ID 0,
  39.     $blog_UID '',
  40.     $blog_allowtrackbacks 1,
  41.     $blog_allowpingbacks 0,
  42.     $blog_pingb2evonet 0,
  43.     $blog_pingtechnorati 0,
  44.     $blog_pingweblogs 1,
  45.     $blog_pingblodotgs 0,
  46.     $blog_disp_bloglist    1,
  47.     $blog_in_bloglist )
  48. {
  49.     global $DB$tableblogs$query$querycount$default_locale;
  50.  
  51.     if$blog_locale == '#' $blog_locale $default_locale;
  52.  
  53.     $query "INSERT INTO $tableblogs( blog_name, blog_shortname, blog_siteurl,
  54.                         blog_stub, blog_staticfilename,
  55.                         blog_tagline, blog_description, blog_longdesc, blog_locale, blog_notes, blog_keywords,
  56.                         blog_UID, blog_allowtrackbacks, blog_allowpingbacks, blog_pingb2evonet,
  57.                         blog_pingtechnorati, blog_pingweblogs, blog_pingblodotgs, blog_disp_bloglist,
  58.                         blog_in_bloglist, blog_links_blog_ID )
  59.     VALUES ( ";
  60.     $query .= "'".$DB->escape($blog_name)."', ";
  61.     $query .= "'".$DB->escape($blog_shortname)."', ";
  62.     $query .= "'".$DB->escape($blog_siteurl)."', ";
  63.     $query .= "'".$DB->escape($blog_stub)."', ";
  64.     $query .= "'".$DB->escape($blog_staticfilename)."', ";
  65.     $query .= "'".$DB->escape($blog_tagline)."', ";
  66.     $query .= "'".$DB->escape($blog_description)."', ";
  67.     $query .= "'".$DB->escape($blog_longdesc)."', ";
  68.     $query .= "'".$DB->escape($blog_locale)."', ";
  69.     $query .= "'".$DB->escape($blog_notes)."', ";
  70.     $query .= "'".$DB->escape($blog_keywords)."', ";
  71.     $query .= "'".$DB->escape($blog_UID)."',
  72.     $blog_allowtrackbacks$blog_allowpingbacks,
  73.     $blog_pingb2evonet$blog_pingtechnorati$blog_pingweblogs$blog_pingblodotgs,
  74.     $blog_disp_bloglist$blog_in_bloglist$blog_links_blog_ID )    ";
  75.     if($DB->query$query )) )
  76.         return 0;
  77.  
  78.     return $DB->insert_id;  // blog ID
  79. }
  80.  
  81.  
  82.  
  83.  
  84. /**
  85.  * Update the user permissions for edited blog
  86.  *
  87.  * {@internal blog_update_user_perms(-) }}
  88.  *
  89.  * @param int Blog ID
  90.  */
  91. function blog_update_user_perms$blog )
  92. {
  93.     global $DB$tableblogusers$tableusers;
  94.  
  95.     // Delete old perms for thos blog:
  96.     $DB->query"DELETE FROM $tableblogusers
  97.                                 WHERE bloguser_blog_ID = $blog);
  98.  
  99.     // Now we need a full user list:
  100.     $user_IDs $DB->get_col"SELECT ID FROM $tableusers);
  101.  
  102.     $inserted_values array();
  103.     ifcount$user_IDs ) ) foreach$user_IDs as $loop_user_ID )
  104.     {    // Check new permissions for each user:
  105.         // echo "getting perms for user : $loop_user_ID <br />";
  106.  
  107.         $perm_post array();
  108.  
  109.         $ismember param'blog_ismember_'.$loop_user_ID'integer');
  110.  
  111.         $perm_published param'blog_perm_published_'.$loop_user_ID'string''' );
  112.         if!empty($perm_published) ) $perm_post['published';
  113.  
  114.         $perm_protected param'blog_perm_protected_'.$loop_user_ID'string''' );
  115.         if!empty($perm_protected) ) $perm_post['protected';
  116.  
  117.         $perm_private param'blog_perm_private_'.$loop_user_ID'string''' );
  118.         if!empty($perm_private) ) $perm_post['private';
  119.  
  120.         $perm_draft param'blog_perm_draft_'.$loop_user_ID'string''' );
  121.         if!empty($perm_draft) ) $perm_post['draft';
  122.  
  123.         $perm_deprecated param'blog_perm_deprecated_'.$loop_user_ID'string''' );
  124.         if!empty($perm_deprecated) ) $perm_post['deprecated';
  125.  
  126.         $perm_delpost param'blog_perm_delpost_'.$loop_user_ID'integer');
  127.         $perm_comments param'blog_perm_comments_'.$loop_user_ID'integer');
  128.         $perm_cats param'blog_perm_cats_'.$loop_user_ID'integer');
  129.         $perm_properties param'blog_perm_properties_'.$loop_user_ID'integer');
  130.  
  131.         // Update those permissions in DB:
  132.  
  133.         if$ismember || count($perm_post|| $perm_delpost || $perm_comments || $perm_cats || $perm_properties )
  134.         {    // There are some permissions for this user:
  135.             $ismember 1;    // Must have this permission
  136.         
  137.             // insert new perms:
  138.             $inserted_values[" ( $blog$loop_user_ID$ismember, '".implode(',',$perm_post)."', 
  139.                                                                 $perm_delpost$perm_comments$perm_cats$perm_properties )";
  140.         }
  141.     }
  142.  
  143.     // Proceed insertions:
  144.     ifcount$inserted_values ) )
  145.     {
  146.         $DB->query"INSERT INTO $tableblogusers( bloguser_blog_ID, bloguser_user_ID, bloguser_ismember,
  147.                                             bloguser_perm_poststatuses, bloguser_perm_delpost, bloguser_perm_comments,
  148.                                             bloguser_perm_cats, bloguser_perm_properties )
  149.                                     VALUES ".implode','$inserted_values ) );
  150.     }
  151. }
  152.  
  153. /**
  154.  * get_bloginfo(-)
  155.  *
  156.  * @deprecated deprecated by Blog::get() This is now a dirty stub
  157.  */
  158. function get_bloginfo$show ''$this_blogparams '' )
  159. {
  160.     global $Blog$blog$BlogCache;
  161.  
  162.     ifempty$this_blogparams ) )
  163.     {    // We want the global blog on the page
  164.         ifisset$Blog ) )
  165.             $current_Blog $Blog;        
  166.         else
  167.             $current_Blog $BlogCache->get_by_ID($blog);
  168.     }
  169.     else
  170.     {
  171.         $current_Blog $BlogCache->get_by_ID($this_blogparams->blog_ID);
  172.     }
  173.     
  174.     return $current_Blog->get$show );
  175. }
  176.  
  177.  
  178.  
  179. /**
  180.  * Get blog params for specified ID
  181.  *
  182.  * {@internal get_blogparams_by_ID(-)}}
  183.  *
  184.  * @todo on a heavy multiblog system, cache them one by one...
  185.  * @deprecated deprecated by {@link Blog_get_by_ID()}
  186.  *
  187.  * @param integer Blog ID
  188.  */
  189. function get_blogparams_by_ID$blog_ID )
  190. {
  191.     global $tableblogs$cache_blogs$use_cache$querycount;
  192.  
  193.     if$blog_ID die'No blog is selected!' );
  194.  
  195.     if( (empty($cache_blogs[$blog_ID])) OR (!$use_cache) )
  196.     {
  197.         blog_load_cache();
  198.     }
  199.     if!isset$cache_blogs[$blog_ID) ) dieT_('Requested blog does not exist!') );
  200.     return $cache_blogs$blog_ID ];
  201. }
  202.  
  203. /**
  204.  * Get Blog for specified ID
  205.  *
  206.  * {@internal Blog_get_by_ID(-)}}
  207.  *
  208.  * @todo on a heavy multiblog system, cache them one by one...
  209.  *
  210.  * @param integer ID of Blog we want
  211.  */
  212. function Blog_get_by_ID$blog_ID )
  213. {
  214.     global $tableblogs$cache_blogs$use_cache$querycount;
  215.  
  216.     if$blog_ID die'No blog is selected!' );
  217.  
  218.     if ((empty($cache_blogs[$blog_ID])) OR (!$use_cache))
  219.     {
  220.         blog_load_cache();
  221.     }
  222.     if!isset$cache_blogs[$blog_ID) ) dieT_('Requested blog does not exist!') );
  223.  
  224.     return new Blog$cache_blogs[$blog_ID)// COPY !
  225. }
  226.  
  227.  
  228. /*
  229.  * blog_load_cache(-)
  230.  */
  231. function blog_load_cache()
  232. {
  233.     global $DB$tableblogs$cache_blogs$use_cache;
  234.     ifempty($cache_blogs|| !$use_cache )
  235.     {
  236.         $cache_blogs array();
  237.         $query "SELECT * FROM $tableblogs ORDER BY blog_ID";
  238.         $result $DB->get_results$query );
  239.         ifcount$result ) ) foreach$result as $this_blog )
  240.         {
  241.             $cache_blogs[$this_blog->blog_ID$this_blog;
  242.             //echo 'just cached:'.$cache_blogs[$this_blog->blog_ID]->blog_name.'('.$this_blog->blog_ID.')<br />';
  243.         }
  244.     }
  245. }
  246.  
  247.  
  248.  
  249. /*****
  250.  * About-the-blog tags
  251.  * Note: these tags go anywhere in the template
  252.  *****/
  253.  
  254. /**
  255.  * bloginfo(-)
  256.  *
  257.  * Template tag
  258.  *
  259.  * @deprecated deprecated by {@link Blog:disp()}
  260.  */
  261. function bloginfo$show=''$format 'raw'$display true$this_blogparams '' )
  262. {
  263.     $content get_bloginfo$show$this_blogparams );
  264.     $content format_to_output$content$format );
  265.     if$display )
  266.         echo $content;
  267.     else
  268.         return $content;
  269. }
  270.  
  271.  
  272.  
  273. /**
  274.  * Start blog iterator
  275.  *
  276.  * blog_list_start(-)
  277.  */
  278. function blog_list_start$need '' )
  279. {
  280.     global $cache_blogs$curr_blogparams$curr_blog_ID;
  281.  
  282.     blog_load_cache();
  283.     // echo "nb blogs=", count($cache_blogs );
  284.  
  285.     $curr_blogparams reset$cache_blogs );
  286.     if$curr_blogparams === false )
  287.         return false;    // No blog!
  288.  
  289.     if( (!empty($need)) && (!get_bloginfo($need$curr_blogparams )) )
  290.     {    // We need the blog to have a specific criteria that is not met, search on...
  291.         return blog_list_next$need );        // This can be recursive
  292.     }
  293.  
  294.     $curr_blog_ID $curr_blogparams->blog_ID;
  295.     //echo "blogID=", $curr_blog_ID;
  296.     return $curr_blog_ID;
  297. }
  298.  
  299.  
  300. /**
  301.  * Next blog iteration
  302.  *
  303.  * blog_list_next(-)
  304.  */
  305. function blog_list_next$need='' )
  306. {
  307.     global $cache_blogs$curr_blogparams$curr_blog_ID;
  308.  
  309.     $curr_blogparams next$cache_blogs );
  310.     if$curr_blogparams === false )
  311.         return false;    // No more blog!
  312.  
  313.     // echo 'need: ', $need, ' info:',get_bloginfo($need, $curr_blogparams );
  314.  
  315.     if( (!empty($need)) && (!get_bloginfo($need$curr_blogparams )) )
  316.     {    // We need the blog to have a specific criteria that is not met, search on...
  317.         return blog_list_next$need );        // This can be recursive
  318.     }
  319.  
  320.     $curr_blog_ID $curr_blogparams->blog_ID;
  321.     // echo "blogID=", $curr_blog_ID;
  322.     return $curr_blog_ID;
  323. }
  324.  
  325.  
  326. /*
  327.  * blog_list_iteminfo(-)
  328.  *
  329.  * Display info about item
  330.  *
  331.  * fplanque: created
  332.  */
  333. function blog_list_iteminfo$what$show 'raw' )
  334. {
  335.     global $curr_blogparams;
  336.  
  337.     $raw_info get_bloginfo$what$curr_blogparams );
  338.  
  339.     if$show )
  340.     {
  341.         echo format_to_output$raw_info$show );
  342.     }
  343.  
  344.     return $raw_info;
  345. }
  346.  
  347. ?>

Documentation generated on Tue, 20 May 2008 01:54:36 +0200 by phpDocumentor 1.4.2