diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 125ea4c4e6a..28081638b3f 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -63,10 +63,10 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page // blog $temp = new admin_settingpage('blog', get_string('blog','blog')); $temp->add(new admin_setting_configcheckbox('useblogassociations', get_string('useblogassociations', 'blog'), get_string('configuseblogassociations','blog'), 1)); - $temp->add(new admin_setting_bloglevel('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(5 => get_string('worldblogs','blog'), - 4 => get_string('siteblogs','blog'), - 1 => get_string('personalblogs','blog'), - 0 => get_string('disableblogs','blog')))); + $temp->add(new admin_setting_bloglevel('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => get_string('worldblogs','blog'), + BLOG_SITE_LEVEL => get_string('siteblogs','blog'), + BLOG_USER_LEVEL => get_string('personalblogs','blog'), + 0 => get_string('disableblogs','blog')))); $temp->add(new admin_setting_configcheckbox('useexternalblogs', get_string('useexternalblogs', 'blog'), get_string('configuseexternalblogs','blog'), 1)); $temp->add(new admin_setting_configselect('externalblogcrontime', get_string('externalblogcrontime', 'blog'), get_string('configexternalblogcrontime', 'blog'), 86400, array(43200 => get_string('numhours', '', 12), @@ -130,7 +130,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page // link to tag management interface $ADMIN->add('appearance', new admin_externalpage('managetags', get_string('managetags', 'tag'), "$CFG->wwwroot/tag/manage.php")); - + $temp = new admin_settingpage('additionalhtml', get_string('additionalhtml', 'admin')); $temp->add(new admin_setting_heading('additionalhtml_heading', get_string('additionalhtml_heading', 'admin'), get_string('additionalhtml_desc', 'admin'))); $temp->add(new admin_setting_configtextarea('additionalhtmlhead', get_string('additionalhtmlhead', 'admin'), get_string('additionalhtmlhead_desc', 'admin'), '', PARAM_RAW)); diff --git a/blocks/blog_menu/block_blog_menu.php b/blocks/blog_menu/block_blog_menu.php index b431a39e702..9b237ecb3ef 100644 --- a/blocks/blog_menu/block_blog_menu.php +++ b/blocks/blog_menu/block_blog_menu.php @@ -1,5 +1,4 @@ . - /** * Blog Menu Block page. * - * @package moodlecore - * @subpackage blog + * @package block + * @subpackage blog_menu * @copyright 2009 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * Require the blog lib file, several useful functions in there - */ -require_once($CFG->dirroot .'/blog/lib.php'); +defined('MOODLE_INTERNAL') || die(); /** * The blog menu block class @@ -56,27 +51,37 @@ class block_blog_menu extends block_base { } function get_content() { + global $CFG; - // Check if we've already generated content - if (!empty($this->content)) { + // detect if blog enabled + if ($this->content !== NULL) { return $this->content; } - // Prep the content - $this->content = new stdClass; - - /** - * Prepare the content for this block - */ - $options = blog_get_all_options($this->page); - if (count($options)==0) { - // Don't display menu block if block is set at site level, and user is not logged in + if (empty($CFG->bloglevel)) { + $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { - // If editing is enabled show an informative message $this->content->text = get_string('blogdisable', 'blog'); } return $this->content; + + } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) { + $this->content = new stdClass(); + $this->content->text = ''; + return $this->content; + } + + // require necessary libs and get content + require_once($CFG->dirroot .'/blog/lib.php'); + + // Prep the content + $this->content = new stdClass(); + + $options = blog_get_all_options($this->page); + if (count($options) == 0) { + $this->content->text = ''; + return $this->content; } // Iterate the option types @@ -92,9 +97,7 @@ class block_blog_menu extends block_base { // Display the content as a list $this->content->text = html_writer::alist($menulist, array('class'=>'list')); - /** - * Prepare the footer for this block - */ + // Prepare the footer for this block if (has_capability('moodle/blog:search', get_context_instance(CONTEXT_SYSTEM))) { // Full-text search field $form = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide')); diff --git a/blocks/blog_recent/block_blog_recent.php b/blocks/blog_recent/block_blog_recent.php index 478b4585437..20313b626a0 100644 --- a/blocks/blog_recent/block_blog_recent.php +++ b/blocks/blog_recent/block_blog_recent.php @@ -1,5 +1,4 @@ . - /** * Recent Blog Entries Block page. * - * @package moodlecore - * @subpackage blog + * @package block + * @subpackage blog_recent * @copyright 2009 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once($CFG->dirroot .'/blog/lib.php'); -require_once($CFG->dirroot .'/blog/locallib.php'); +defined('MOODLE_INTERNAL') || die(); /** * This block simply outputs a list of links to recent blog entries, depending on @@ -48,7 +45,29 @@ class block_blog_recent extends block_base { } function get_content() { - global $CFG, $USER, $PAGE, $DB, $OUTPUT; + global $CFG; + + if ($this->content !== NULL) { + return $this->content; + } + + // verify blog is enabled + if (empty($CFG->bloglevel)) { + $this->content = new stdClass(); + $this->content->text = ''; + if ($this->page->user_is_editing()) { + $this->content->text = get_string('blogdisable', 'blog'); + } + return $this->content; + + } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) { + $this->content = new stdClass(); + $this->content->text = ''; + return $this->content; + } + + require_once($CFG->dirroot .'/blog/lib.php'); + require_once($CFG->dirroot .'/blog/locallib.php'); if (empty($this->config->recentbloginterval)) { $this->config->recentbloginterval = 8400; @@ -58,14 +77,6 @@ class block_blog_recent extends block_base { $this->config->numberofrecentblogentries = 4; } - if (empty($CFG->bloglevel) || ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser()))) { - $this->content->text = ''; - if ($this->page->user_is_editing()) { - $this->content->text = get_string('blogdisable', 'blog'); - } - return $this->content; - } - $this->content = new stdClass(); $this->content->footer = ''; diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index a5d82507549..c3fa8d8f2d7 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -1,12 +1,33 @@ . -//TODO: fix these sloppy constant names or move them elsewhere! +/** + * Blog tags block. + * + * @package block + * @subpackage blog_tags + * @copyright 2006 Shane Elliott + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ -define('BLOGDEFAULTTIMEWITHIN', 90); -define('BLOGDEFAULTNUMBEROFTAGS', 20); -define('BLOGDEFAULTSORT', 'name'); +defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot .'/blog/lib.php'); +define('BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN', 90); +define('BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS', 20); +define('BLOCK_BLOG_TAGS_DEFAULTSORT', 'name'); class block_blog_tags extends block_base { function init() { @@ -42,29 +63,47 @@ class block_blog_tags extends block_base { function get_content() { global $CFG, $SITE, $USER, $DB, $OUTPUT; - if (empty($CFG->usetags) || empty($CFG->bloglevel)) { + if ($this->content !== NULL) { + return $this->content; + } + + // make sure blog and tags are actually enabled + if (empty($CFG->bloglevel)) { + $this->content = new stdClass(); + $this->content->text = ''; + if ($this->page->user_is_editing()) { + $this->content->text = get_string('blogdisable', 'blog'); + } + return $this->content; + + } else if (empty($CFG->usetags)) { + $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('tagsaredisabled', 'tag'); } return $this->content; - } - if (empty($this->config->timewithin)) { - $this->config->timewithin = BLOGDEFAULTTIMEWITHIN; - } - if (empty($this->config->numberoftags)) { - $this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS; - } - if (empty($this->config->sort)) { - $this->config->sort = BLOGDEFAULTSORT; - } - - if ($this->content !== NULL) { + } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) { + $this->content = new stdClass(); + $this->content->text = ''; return $this->content; } - $this->content = new stdClass; + // require the libs and do the work + require_once($CFG->dirroot .'/blog/lib.php'); + + if (empty($this->config->timewithin)) { + $this->config->timewithin = BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN; + } + if (empty($this->config->numberoftags)) { + $this->config->numberoftags = BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS; + } + if (empty($this->config->sort)) { + $this->config->sort = BLOCK_BLOG_TAGS_DEFAULTSORT; + } + + $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; @@ -129,7 +168,7 @@ class block_blog_tags extends block_base { /// Now we sort the tag display order $CFG->tagsort = $this->config->sort; - usort($etags, "blog_tags_sort"); + usort($etags, "block_blog_tags_sort"); /// Finally we create the output /// Accessibility: markup as a list. @@ -163,7 +202,7 @@ class block_blog_tags extends block_base { } } -function blog_tags_sort($a, $b) { +function block_blog_tags_sort($a, $b) { global $CFG; if (empty($CFG->tagsort)) { @@ -175,7 +214,7 @@ function blog_tags_sort($a, $b) { if (is_numeric($a->$tagsort)) { return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1; } elseif (is_string($a->$tagsort)) { - return strcmp($a->$tagsort, $b->$tagsort); + return strcmp($a->$tagsort, $b->$tagsort); //TODO: this is not compatible with UTF-8!! } else { return 0; } diff --git a/blocks/blog_tags/edit_form.php b/blocks/blog_tags/edit_form.php index 7dd134eeb57..1571066013c 100644 --- a/blocks/blog_tags/edit_form.php +++ b/blocks/blog_tags/edit_form.php @@ -43,7 +43,7 @@ class block_blog_tags_edit_form extends block_edit_form { $numberoftags[$i] = $i; } $mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags); - $mform->setDefault('config_numberoftags', BLOGDEFAULTNUMBEROFTAGS); + $mform->setDefault('config_numberoftags', BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS); $timewithin = array( 10 => get_string('numdays', '', 10), @@ -55,13 +55,13 @@ class block_blog_tags_edit_form extends block_edit_form { 365 => get_string('numdays', '', 365), ); $mform->addElement('select', 'config_timewithin', get_string('timewithin', 'blog'), $timewithin); - $mform->setDefault('config_timewithin', BLOGDEFAULTTIMEWITHIN); + $mform->setDefault('config_timewithin', BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN); $sort = array( 'name' => get_string('tagtext', 'blog'), 'id' => get_string('tagdatelastused', 'blog'), ); $mform->addElement('select', 'config_sort', get_string('tagsort', 'blog'), $sort); - $mform->setDefault('config_sort', BLOGDEFAULTSORT); + $mform->setDefault('config_sort', BLOCK_BLOG_TAGS_DEFAULTSORT); } } diff --git a/blog/index.php b/blog/index.php index 7827e4ca082..2ba9884ff65 100644 --- a/blog/index.php +++ b/blog/index.php @@ -34,6 +34,10 @@ foreach ($url_params as $var => $val) { } $PAGE->set_url('/blog/index.php', $url_params); +if (empty($CFG->bloglevel)) { + print_error('blogdisable', 'blog'); +} + //correct tagid if a text tag is provided as a param if (!empty($tag)) { if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE ". $DB->sql_like('name', '?', false), array("%$tag%"))) { @@ -52,11 +56,32 @@ if (!empty($groupid) && empty($courseid)) { $courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid)); } -if (empty($CFG->bloglevel)) { +$sitecontext = get_context_instance(CONTEXT_SYSTEM); + +// check basic permissions +if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { + // everybody can see anything - no login required unless site is locked down using forcelogin + if ($CFG->forcelogin) { + require_login(); + } + +} else if ($CFG->bloglevel == BLOG_SITE_LEVEL) { + // users must log in and can not be guests + require_login(); + if (isguestuser()) { + // they must have entered the url manually... + print_error('blogdisable', 'blog'); + } + +} else if ($CFG->bloglevel == BLOG_USER_LEVEL) { + // users can see own blogs only! with the exception of ppl with special cap + require_login(); + +} else { + // weird! print_error('blogdisable', 'blog'); } -$sitecontext = get_context_instance(CONTEXT_SYSTEM); if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) { if ($entryid) { @@ -83,9 +108,6 @@ if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) { if ($CFG->bloglevel < BLOG_SITE_LEVEL) { print_error('siteblogdisable', 'blog'); } - if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) { - require_login(); - } if (!has_capability('moodle/blog:view', $sitecontext)) { print_error('cannotviewsiteblog', 'blog'); } diff --git a/blog/lib.php b/blog/lib.php index 1137e8ec55e..e4ac2774a9e 100644 --- a/blog/lib.php +++ b/blog/lib.php @@ -398,12 +398,14 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) { } // Get the options for the user - if ($user !== null) { + if ($user !== null and !isguestuser($user)) { // Load for the requested user $options[CONTEXT_USER+1] = blog_get_options_for_user($user); } // Load for the current user - $options[CONTEXT_USER] = blog_get_options_for_user(); + if (isloggedin() and !isguestuser()) { + $options[CONTEXT_USER] = blog_get_options_for_user(); + } } // If blog level is global then display a link to view all site entries diff --git a/lib/adminlib.php b/lib/adminlib.php index b94fb7c1318..4668e0ab688 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3002,11 +3002,20 @@ class admin_setting_bloglevel extends admin_setting_configselect { * @return string empty or error message */ public function write_setting($data) { - global $DB; + global $DB, $CFG; if ($data['bloglevel'] == 0) { - $DB->set_field('block', 'visible', 0, array('name' => 'blog_menu')); + $blogblocks = $DB->get_records_select('block', "name LIKE 'blog_%' AND visible = 1"); + foreach ($blogblocks as $block) { + $DB->set_field('block', 'visible', 0, array('id' => $block->id)); + } } else { - $DB->set_field('block', 'visible', 1, array('name' => 'blog_menu')); + // reenable all blocks only when switching from disabled blogs + if (isset($CFG->bloglevel) and $CFG->bloglevel == 0) { + $blogblocks = $DB->get_records_select('block', "name LIKE 'blog_%' AND visible = 0"); + foreach ($blogblocks as $block) { + $DB->set_field('block', 'visible', 1, array('id' => $block->id)); + } + } } return parent::write_setting($data); } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 5376bed4cae..df6095957a9 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1967,7 +1967,6 @@ class global_navigation extends navigation_node { //Participants if (has_capability('moodle/course:viewparticipants', $this->page->context)) { - require_once($CFG->dirroot.'/blog/lib.php'); $participants = $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), self::TYPE_CONTAINER, get_string('participants'), 'participants'); $currentgroup = groups_get_course_group($course, true); if ($course->id == SITEID) { @@ -1978,7 +1977,8 @@ class global_navigation extends navigation_node { $filterselect = $currentgroup; } $filterselect = clean_param($filterselect, PARAM_INT); - if ($CFG->bloglevel >= 3) { + if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) + and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); $participants->add(get_string('blogs','blog'), $blogsurls->out()); } @@ -2036,12 +2036,11 @@ class global_navigation extends navigation_node { $filterselect = 0; // Blogs - if (has_capability('moodle/blog:view', $this->page->context)) { - require_once($CFG->dirroot.'/blog/lib.php'); - if (blog_is_enabled_for_user()) { - $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); - $coursenode->add(get_string('blogs','blog'), $blogsurls->out()); - } + if (!empty($CFG->bloglevel) + and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) + and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) { + $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); + $coursenode->add(get_string('blogs','blog'), $blogsurls->out()); } // Notes