Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/blog_menu/block_blog_menu.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 defined('MOODLE_INTERNAL') || die();
00027 
00031 class block_blog_menu extends block_base {
00032 
00033     function init() {
00034         $this->title = get_string('pluginname', 'block_blog_menu');
00035     }
00036 
00037     function instance_allow_multiple() {
00038         return true;
00039     }
00040 
00041     function has_config() {
00042         return false;
00043     }
00044 
00045     function applicable_formats() {
00046         return array('all' => true, 'my' => false, 'tag' => false);
00047     }
00048 
00049     function instance_allow_config() {
00050         return true;
00051     }
00052 
00053     function get_content() {
00054         global $CFG;
00055 
00056         // detect if blog enabled
00057         if ($this->content !== NULL) {
00058             return $this->content;
00059         }
00060 
00061         if (empty($CFG->bloglevel)) {
00062             $this->content = new stdClass();
00063             $this->content->text = '';
00064             if ($this->page->user_is_editing()) {
00065                 $this->content->text = get_string('blogdisable', 'blog');
00066             }
00067             return $this->content;
00068 
00069         } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
00070             $this->content = new stdClass();
00071             $this->content->text = '';
00072             return $this->content;
00073         }
00074 
00075         // require necessary libs and get content
00076         require_once($CFG->dirroot .'/blog/lib.php');
00077 
00078         // Prep the content
00079         $this->content = new stdClass();
00080 
00081         $options = blog_get_all_options($this->page);
00082         if (count($options) == 0) {
00083             $this->content->text = '';
00084             return $this->content;
00085         }
00086 
00087         // Iterate the option types
00088         $menulist = array();
00089         foreach ($options as $types) {
00090             foreach ($types as $link) {
00091                 $menulist[] = html_writer::link($link['link'], $link['string']);
00092             }
00093             $menulist[] = '<hr />';
00094         }
00095         // Remove the last element (will be an HR)
00096         array_pop($menulist);
00097         // Display the content as a list
00098         $this->content->text = html_writer::alist($menulist, array('class'=>'list'));
00099 
00100         // Prepare the footer for this block
00101         if (has_capability('moodle/blog:search', get_context_instance(CONTEXT_SYSTEM))) {
00102             // Full-text search field
00103             $form  = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide'));
00104             $form .= html_writer::empty_tag('input', array('id'=>'blogsearchquery', 'type'=>'text', 'name'=>'search'));
00105             $form .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search')));
00106             $this->content->footer = html_writer::tag('form', html_writer::tag('div', $form), array('class'=>'blogsearchform', 'method'=>'get', 'action'=>new moodle_url('/blog/index.php')));
00107         } else {
00108             // No footer to display
00109             $this->content->footer = '';
00110         }
00111 
00112         // Return the content object
00113         return $this->content;
00114     }
00115 }
 All Data Structures Namespaces Files Functions Variables Enumerations