Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  •    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  /**
      19   * A full display of tags allowing some filtering and reordering
      20   *
      21   * @package    core_tag
      22   * @category   tag
      23   * @copyright  2007 j.beedell@open.ac.uk
      24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      25   */
      26  
      27  require_once('../config.php');
      28  require_once($CFG->dirroot.'/tag/coursetagslib.php');
      29  require_once($CFG->dirroot.'/tag/lib.php');
      30  
      31  $sort = optional_param('sort', 'alpha', PARAM_ALPHA); //alpha, date or popularity
      32  $show = optional_param('show', 'all', PARAM_ALPHA); //all, my, official, community or course
      33  $courseid = optional_param('courseid', 0, PARAM_INT);
      34  
      35  $url = new moodle_url('/tag/coursetags_more.php');
      36  if ($sort !== 'alpha') {
      37      $url->param('sort', $sort);
      38  }
      39  if ($show !== 'all') {
      40      $url->param('show', $show);
      41  }
      42  if ($courseid !== 0) {
      43      $url->param('courseid', $courseid);
      44  }
      45  $PAGE->set_url($url);
      46  
      47  if (empty($CFG->usetags)) {
      48      print_error('tagsaredisabled', 'tag');
      49  }
      50  
      51  // Some things require logging in
      52  if ($CFG->forcelogin or $show == 'my') {
      53      require_login();
      54  }
      55  
      56  // Permissions
      57  $loggedin = isloggedin() && !isguestuser();
      58  
      59  // Course check
      60  if ($courseid) {
      61      if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
      62          $courseid = 0;
      63      }
      64      if ($courseid == SITEID) $courseid = 0;
      65  }
      66  
      67  if ($courseid) {
      68      $PAGE->set_context(context_course::instance($courseid));
      69  } else {
      70      $PAGE->set_context(context_system::instance());
      71  }
      72  
      73  // Language strings
      74  $tagslang = 'block_tags';
      75  $title = get_string('moretitle', $tagslang);
      76  $link1 = get_string('moreshow', $tagslang);
      77  $link2 = get_string('moreorder', $tagslang);
      78  $showalltags = get_string('moreshowalltags', $tagslang);
      79  $showofficialtags = get_string('moreshowofficialtags', $tagslang);
      80  $showmytags = get_string('moreshowmytags', $tagslang);
      81  $showcommtags = get_string('moreshowcommtags', $tagslang);
      82  $orderalpha = get_string('moreorderalpha', $tagslang);
      83  $orderdate = get_string('moreorderdate', $tagslang);
      84  $orderpop = get_string('moreorderpop', $tagslang);
      85  $welcome = get_string('morewelcome', $tagslang);
      86  
      87  // The title and breadcrumb
      88  if ($courseid) {
      89      $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid)));
      90      $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
      91  }
      92  $PAGE->navbar->add($title);
      93  $PAGE->set_title($title);
      94  $PAGE->set_heading($COURSE->fullname);
      95  echo $OUTPUT->header();
      96  echo $OUTPUT->heading($title, 2, 'centre');
      97  
      98  // Prepare data for tags
      99  $courselink = '';
     100  if ($courseid) {
     101      $courselink = '&amp;courseid='.$courseid;
     102  }
     103  $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
     104  $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
     105  
     106  if ($show == 'course' and $courseid) { // Course tags.
     107      $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, ''), 150, true, $sort);
     108  } else if ($show == 'my' and $loggedin) { // My tags.
     109      $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), 150, true, $sort);
     110  } else if ($show == 'official') { // Official course tags.
     111      $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official'), 150, true, $sort);
     112  } else if ($show == 'community') { // Community (official and personal together) also called user tags.
     113      $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default'), 150, true, $sort);
     114  } else {
     115      // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all).
     116      $subtitle = $showalltags;
     117      $tags = tag_print_cloud(coursetag_get_all_tags(), 150, true, $sort);
     118  }
     119  
     120  // Prepare the links for the show and order lines
     121  if ($show == 'all') {
     122      $link1 .= '<b>'.$showalltags.'</b>';
     123  } else {
     124      $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
     125  }
     126  //if ($show == 'official') { //add back in if you start to use official course tags
     127  //    $link1 .= ' | <b>'.$showofficialtags.'</b>';
     128  //} else {
     129  //    $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
     130  //}
     131  if ($show == 'community') {
     132      $link1 .= ' | <b>'.$showcommtags.'</b>';
     133  } else {
     134      $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
     135  }
     136  if ($loggedin) {
     137      if ($show == 'my') {
     138          $link1 .= ' | <b>'.$showmytags.'</b>';
     139      } else {
     140          $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
     141      }
     142  }
     143  if ($courseid) {
     144      $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
     145      if ($show == 'course') {
     146          $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
     147      } else {
     148          $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
     149      }
     150  }
     151  if ($sort == 'alpha') {
     152      $link2 .= '<b>'.$orderalpha.'</b> | ';
     153  } else {
     154      $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
     155  }
     156  if ($sort == 'popularity') {
     157      $link2 .= '<b>'.$orderpop.'</b> | ';
     158  } else {
     159      $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
     160  }
     161  if ($sort == 'date') {
     162      $link2 .= '<b>'.$orderdate.'</b>';
     163  } else {
     164      $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
     165  }
     166  
     167  // Prepare output
     168  $fclass = '';
     169  // make the tags larger when there are not so many
     170  if (strlen($tags) < 10000) {
     171      $fclass = 'coursetag_more_large';
     172  }
     173  $outstr = '
     174  <div class="coursetag_more_title">
     175  <div style="padding-bottom:5px">'.$welcome.'</div>
     176  <div class="coursetag_more_link">'.$link1.'</div>
     177  <div class="coursetag_more_link">'.$link2.'</div>
     178  </div>
     179  <div class="coursetag_more_tags '.$fclass.'">'.
     180  $tags.'
     181  </div>';
     182  echo $outstr;
     183  
     184  echo $OUTPUT->footer();
    

    Search This Site: