Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-26859 improve coding style in blog related blocks

  • Loading branch information...
commit fd85ceac57e2d3cee92af5c29d96ea14d4e91449 1 parent d9e0b80
@skodak skodak authored
View
49 blocks/blog_menu/block_blog_menu.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,20 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* 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 @@ function instance_allow_config() {
}
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 @@ function get_content() {
// 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'));
View
39 blocks/blog_recent/block_blog_recent.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -15,18 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* 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,22 +45,36 @@ function instance_allow_config() {
}
function get_content() {
- global $CFG, $USER, $PAGE, $DB, $OUTPUT;
-
- if (empty($this->config->recentbloginterval)) {
- $this->config->recentbloginterval = 8400;
- }
+ global $CFG;
- if (empty($this->config->numberofrecentblogentries)) {
- $this->config->numberofrecentblogentries = 4;
+ if ($this->content !== NULL) {
+ return $this->content;
}
- if (empty($CFG->bloglevel) || ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser()))) {
+ // 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;
+ }
+
+ if (empty($this->config->numberofrecentblogentries)) {
+ $this->config->numberofrecentblogentries = 4;
}
$this->content = new stdClass();
View
79 blocks/blog_tags/block_blog_tags.php
@@ -1,12 +1,33 @@
<?php
-
-//TODO: fix these sloppy constant names or move them elsewhere!
-
-define('BLOGDEFAULTTIMEWITHIN', 90);
-define('BLOGDEFAULTNUMBEROFTAGS', 20);
-define('BLOGDEFAULTSORT', 'name');
-
-require_once($CFG->dirroot .'/blog/lib.php');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * 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
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+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 @@ function specialization() {
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;
+
+ } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
+ $this->content = new stdClass();
+ $this->content->text = '';
+ return $this->content;
}
+ // require the libs and do the work
+ require_once($CFG->dirroot .'/blog/lib.php');
+
if (empty($this->config->timewithin)) {
- $this->config->timewithin = BLOGDEFAULTTIMEWITHIN;
+ $this->config->timewithin = BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN;
}
if (empty($this->config->numberoftags)) {
- $this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS;
+ $this->config->numberoftags = BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS;
}
if (empty($this->config->sort)) {
- $this->config->sort = BLOGDEFAULTSORT;
- }
-
- if ($this->content !== NULL) {
- return $this->content;
+ $this->config->sort = BLOCK_BLOG_TAGS_DEFAULTSORT;
}
- $this->content = new stdClass;
+ $this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
@@ -129,7 +168,7 @@ function get_content() {
/// 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 @@ function get_content() {
}
}
-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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.