From: toyomoyo Date: Thu, 20 Apr 2006 06:35:39 +0000 (+0000) Subject: added a feature that automatically adds 2 default blocks for new blog users. (block_m... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8c9814f9d8e25a48ae955728e5d33bc1a22af1f6;p=moodle.git added a feature that automatically adds 2 default blocks for new blog users. (block_menu and block_tags blocks) --- diff --git a/blog/header.php b/blog/header.php index b0250c792f..6973041bca 100755 --- a/blog/header.php +++ b/blog/header.php @@ -12,6 +12,9 @@ $blockaction = optional_param('blockaction','', PARAM_ALPHA); $instanceid = optional_param('instanceid', 0, PARAM_INT); $blockid = optional_param('blockid', 0, PARAM_INT); +/// If user has never visited this page before, install 2 blocks for him +blog_check_and_install_blocks(); + if (!$site = get_site()) { redirect($CFG->wwwroot.'/index.php'); } diff --git a/blog/index.php b/blog/index.php index 271da130a1..c890565b54 100755 --- a/blog/index.php +++ b/blog/index.php @@ -132,14 +132,14 @@ switch ($filtertype) { break; } -//first set the start and end day equal to the day argument passed in from the get vars +// first set the start and end day equal to the day argument passed in from the get vars if ($limit == 'none') { $limit = get_user_preferences('blogpagesize',10); } include($CFG->dirroot .'/blog/header.php'); -//prints the tabs +// prints the tabs $currenttab = 'blogs'; $user = $USER; if (!$course) { diff --git a/blog/lib.php b/blog/lib.php index a20596c574..44f38ba3bb 100755 --- a/blog/lib.php +++ b/blog/lib.php @@ -32,6 +32,40 @@ $SESSION->blog_editing_enabled = false; } + // checks to see if user has visited blogpages before, if not, install 2 default blocks + // (blog_menu and blog_tags) + function blog_check_and_install_blocks() { + global $USER; + if (isloggedin() && !isguest()) { + // if this user has not visited this page before + if (!get_user_preferences('blogpagesize')) { + // find the correct ids for blog_menu and blog_from blocks + $menublock = get_record('block','name','blog_menu'); + $tagsblock = get_record('block','name','blog_tags'); + // add those 2 into block_instance page + + // add blog_menu block + $newblock = new object; + $newblock -> blockid = $menublock->id; + $newblock -> pageid = $USER->id; + $newblock -> pagetype = 'blog-view'; + $newblock -> position = 'r'; + $newblock -> weight = 0; + $newblock -> visible = 1; + insert_record('block_instance', $newblock); + + // add blog_tags menu + $newblock -> blockid = $tagsblock->id; + $newblock -> weight = 1; + insert_record('block_instance', $newblock); + + // finally we set the page size pref + set_user_preference('blogpagesize',8); + } + } + } + + /** * Adaptation of isediting in moodlelib.php for blog module * @return bool