[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/blog_menu/ -> block_blog_menu.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Blog Menu Block page.
  19   *
  20   * @package    block_blog_menu
  21   * @copyright  2009 Nicolas Connault
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * The blog menu block class
  29   */
  30  class block_blog_menu extends block_base {
  31  
  32      function init() {
  33          $this->title = get_string('pluginname', 'block_blog_menu');
  34      }
  35  
  36      function instance_allow_multiple() {
  37          return true;
  38      }
  39  
  40      function has_config() {
  41          return false;
  42      }
  43  
  44      function applicable_formats() {
  45          return array('all' => true, 'my' => false, 'tag' => false);
  46      }
  47  
  48      function instance_allow_config() {
  49          return true;
  50      }
  51  
  52      function get_content() {
  53          global $CFG;
  54  
  55          // detect if blog enabled
  56          if ($this->content !== NULL) {
  57              return $this->content;
  58          }
  59  
  60          if (empty($CFG->enableblogs)) {
  61              $this->content = new stdClass();
  62              $this->content->text = '';
  63              if ($this->page->user_is_editing()) {
  64                  $this->content->text = get_string('blogdisable', 'blog');
  65              }
  66              return $this->content;
  67  
  68          } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
  69              $this->content = new stdClass();
  70              $this->content->text = '';
  71              return $this->content;
  72          }
  73  
  74          // require necessary libs and get content
  75          require_once($CFG->dirroot .'/blog/lib.php');
  76  
  77          // Prep the content
  78          $this->content = new stdClass();
  79  
  80          $options = blog_get_all_options($this->page);
  81          if (count($options) == 0) {
  82              $this->content->text = '';
  83              return $this->content;
  84          }
  85  
  86          // Iterate the option types
  87          $menulist = array();
  88          foreach ($options as $types) {
  89              foreach ($types as $link) {
  90                  $menulist[] = html_writer::link($link['link'], $link['string']);
  91              }
  92              $menulist[] = '<hr />';
  93          }
  94          // Remove the last element (will be an HR)
  95          array_pop($menulist);
  96          // Display the content as a list
  97          $this->content->text = html_writer::alist($menulist, array('class'=>'list'));
  98  
  99          // Prepare the footer for this block
 100          if (has_capability('moodle/blog:search', context_system::instance())) {
 101              // Full-text search field
 102              $form  = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide'));
 103              $form .= html_writer::empty_tag('input', array('id'=>'blogsearchquery', 'type'=>'text', 'name'=>'search'));
 104              $form .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('search')));
 105              $this->content->footer = html_writer::tag('form', html_writer::tag('div', $form), array('class'=>'blogsearchform', 'method'=>'get', 'action'=>new moodle_url('/blog/index.php')));
 106          } else {
 107              // No footer to display
 108              $this->content->footer = '';
 109          }
 110  
 111          // Return the content object
 112          return $this->content;
 113      }
 114  
 115      /**
 116       * Returns the role that best describes the blog menu block.
 117       *
 118       * @return string
 119       */
 120      public function get_aria_role() {
 121          return 'navigation';
 122      }
 123  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1