diff --git a/tag/coursetags_more.php b/tag/coursetags_more.php
index 61c3ccd333115..da4d25e2fabd3 100644
--- a/tag/coursetags_more.php
+++ b/tag/coursetags_more.php
@@ -105,44 +105,44 @@
if ($show == 'course' and $courseid) {
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), 150, true);
}
// My tags
} else if ($show == 'my' and $loggedin) {
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), 150, true);
}
// Official course tags
} else if ($show == 'official') {
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), 150, true);
}
// Community (official and personal together) also called user tags
} else if ($show == 'community') {
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), 150, true);
}
// All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
@@ -150,11 +150,11 @@
$subtitle = $showalltags;
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('name'), 150, true);
}
}
diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php
index 7d36b473642a4..bde390df00941 100644
--- a/tag/coursetagslib.php
+++ b/tag/coursetagslib.php
@@ -24,6 +24,7 @@
*/
require_once $CFG->dirroot.'/tag/lib.php';
+require_once $CFG->dirroot.'/tag/locallib.php';
/**
* Returns an ordered array of tags associated with visible courses
@@ -186,110 +187,26 @@ function coursetag_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)) {
+ } else if (is_string($a->$tagsort)) {
return strcmp($a->$tagsort, $b->$tagsort);
} else {
return 0;
}
}
-/**
- * Prints a tag cloud
- *
- * @package core_tag
- * @category tag
- * @param array $tagcloud array of tag objects (fields: id, name, rawname, count and flag)
- * @param mixed $return if true return html string
- * @param int $max_size maximum text size, in percentage
- * @param int $min_size minimum text size, in percentage
- */
-function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_size=80) {
-
- global $CFG;
-
- if (empty($tagcloud)) {
- return;
- }
-
- ksort($tagcloud);
-
- $count = array();
- foreach ($tagcloud as $key => $value) {
- if(!empty($value->count)) {
- $count[$key] = log10($value->count);
- } else {
- $count[$key] = 0;
- }
- }
-
- $max = max($count);
- $min = min($count);
-
- $spread = $max - $min;
- if (0 == $spread) { // we don't want to divide by zero
- $spread = 1;
- }
-
- $step = ($max_size - $min_size)/($spread);
-
- $systemcontext = context_system::instance();
- $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext);
-
- //prints the tag cloud
- $output = '
';
- foreach ($tagcloud as $key => $tag) {
-
- $size = $min_size + ((log10($tag->count) - $min) * $step);
- $size = ceil($size);
-
- $style = 'style="font-size: '.$size.'%"';
-
- if ($tag->count > 1) {
- $title = 'title="'.s(get_string('thingstaggedwith','tag', $tag)).'"';
- } else {
- $title = 'title="'.s(get_string('thingtaggedwith','tag', $tag)).'"';
- }
-
- $href = 'href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'"';
-
- //highlight tags that have been flagged as inappropriate for those who can manage them
- $tagname = tag_display_name($tag);
- if ($tag->flag > 0 && $can_manage_tags) {
- $tagname = '' . tag_display_name($tag) . '';
- }
-
- $tag_link = '- '.$tagname.'
';
-
- $output .= $tag_link;
-
- }
- $output .= '
'."\n";
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
-}
-
/**
* Returns javascript for use in tags block and supporting pages
*
* @package core_tag
* @category tag
- * @param string $coursetagdivs comma separated divs ids
* @return null
*/
-function coursetag_get_jscript($coursetagdivs = '') {
+function coursetag_get_jscript() {
global $CFG, $DB, $PAGE;
$PAGE->requires->js('/tag/tag.js');
$PAGE->requires->strings_for_js(array('jserror1', 'jserror2'), 'block_tags');
- if ($coursetagdivs) {
- $PAGE->requires->js_function_call('set_course_tag_divs', $coursetagdivs);
- }
-
if ($coursetags = $DB->get_records('tag', null, 'name ASC', 'name, id')) {
foreach ($coursetags as $key => $value) {
$PAGE->requires->js_function_call('set_course_tag', array($key));
@@ -359,7 +276,7 @@ function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='officia
global $CFG;
if (is_array($tags) and !empty($tags)) {
- foreach($tags as $tag) {
+ foreach ($tags as $tag) {
$tag = trim($tag);
if (strlen($tag) > 0) {
//tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
@@ -494,221 +411,3 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) {
}
}
-/*
- * Function called by cron to create/update users rss feeds
- *
- * @return true
- *
- * Function removed.
- * rsslib.php needs updating to accept Dublin Core tags (dc/cc) input before this can work.
- */
-/*
-function coursetag_rss_feeds() {
-
- global $CFG, $DB;
- require_once($CFG->dirroot.'/lib/dmllib.php');
- require_once($CFG->dirroot.'/lib/rsslib.php');
-
- $status = true;
- mtrace(' Preparing to update all user unit tags RSS feeds');
- if (empty($CFG->enablerssfeeds)) {
- mtrace(' RSS DISABLED (admin variables - enablerssfeeds)');
- } else {
-
- // Load all the categories for use later on
- $categories = $DB->get_records('course_categories');
-
- // get list of users who have tagged a unit
- $sql = "
- SELECT DISTINCT u.id as userid, u.username, u.firstname, u.lastname, u.email
- FROM {user} u, {course} c, {tag_instance} cti, {tag} t
- WHERE c.id = cti.itemid
- AND u.id = cti.tiuserid
- AND t.id = cti.tagid
- AND t.tagtype = 'personal'
- AND u.confirmed = 1
- AND u.deleted = 0
- ORDER BY userid";
- if ($users = $DB->get_records_sql($sql)) {
-
- $items = array(); //contains rss data items for each user
- foreach ($users as $user) {
-
- // loop through each user, getting the data (tags for courses)
- $sql = "
- SELECT cti.id, c.id as courseid, c.fullname, c.shortname, c.category, t.rawname, cti.timemodified
- FROM {course} c, {tag_instance} cti, {tag} t
- WHERE c.id = cti.itemid
- AND cti.tiuserid = :userid{$user->userid}
- AND cti.tagid = t.id
- AND t.tagtype = 'personal'
- ORDER BY courseid";
- if ($usertags = $DB->get_records_sql($sql, array('userid' => $user->userid))) {
- $latest_date = 0; //latest date any tag was created by a user
- $c = 0; //course identifier
-
- foreach ($usertags as $usertag) {
- if ($usertag->courseid != $c) {
- $c = $usertag->courseid;
- $items[$c] = new stdClass();
- $items[$c]->title = $usertag->fullname . '(' . $usertag->shortname . ')';
- $items[$c]->link = $CFG->wwwroot . '/course/view.php?name=' . $usertag->shortname;
- $items[$c]->description = ''; //needs to be blank
- $items[$c]->category = $categories[$usertag->category]->name;
- $items[$c]->subject[] = $usertag->rawname;
- $items[$c]->pubdate = $usertag->timemodified;
- $items[$c]->tag = true;
- } else {
- $items[$c]->subject[] .= $usertag->rawname;
- }
- // Check and set the latest modified date.
- $latest_date = $usertag->timemodified > $latest_date ? $usertag->timemodified : $latest_date;
- }
-
- // Setup some vars for use while creating the file
- $path = $CFG->dataroot.'/1/usertagsrss/'.$user->userid;
- $file_name = 'user_unit_tags_rss.xml';
- $title = get_string('rsstitle', 'tag', ucwords(strtolower($user->firstname.' '.$user->lastname)));
- $desc = get_string('rssdesc', 'tag');
- // check that the path exists
- if (!file_exists($path)) {
- mtrace(' Creating folder '.$path);
- check_dir_exists($path, TRUE, TRUE);
- }
-
- // create or update the feed for the user
- // this functionality can be copied into seperate lib as in next two lines
- //require_once($CFG->dirroot.'/local/ocilib.php');
- //oci_create_rss_feed( $path, $file_name, $latest_date, $items, $title, $desc, $dc=true, $cc=false);
-
- // Set path to RSS file
- $full_path = "$save_path/$file_name";
-
- mtrace(" Preparing to update RSS feed for $file_name");
-
- // First let's make sure there is work to do by checking the time the file was last modified,
- // if a course was update after the file was mofified
- if (file_exists($full_path)) {
- if ($lastmodified = filemtime($full_path)) {
- mtrace(" XML File $file_name Created on ".date( "D, j M Y G:i:s T", $lastmodified ));
- mtrace(' Lastest course modification on '.date( "D, j M Y G:i:s T", $latest_date ));
- if ($latest_date > $lastmodified) {
- mtrace(" XML File $file_name needs updating");
- $changes = true;
- } else {
- mtrace(" XML File $file_name doesn't need updating");
- $changes = false;
- }
- }
- } else {
- mtrace(" XML File $file_name needs updating");
- $changes = true;
- }
-
- if ($changes) {
- // Now we know something has changed, write the new file
-
- if (!empty($items)) {
- // First set rss feeds common headers
- $header = rss_standard_header(strip_tags(format_string($title,true)),
- $CFG->wwwroot,
- $desc,
- true, true);
- // Now all the rss items
- if (!empty($header)) {
- $articles = rss_add_items($items,$dc,$cc);
- }
- // Now all rss feeds common footers
- if (!empty($header) && !empty($articles)) {
- $footer = rss_standard_footer();
- }
- // Now, if everything is ok, concatenate it
- if (!empty($header) && !empty($articles) && !empty($footer)) {
- $result = $header.$articles.$footer;
- } else {
- $result = false;
- }
- } else {
- $result = false;
- }
-
- // Save the XML contents to file
- if (!empty($result)) {
- $rss_file = fopen($full_path, "w");
- if ($rss_file) {
- $status = fwrite ($rss_file, $result);
- fclose($rss_file);
- } else {
- $status = false;
- }
- }
-
- // Output result
- if (empty($result)) {
- // There was nothing to put into the XML file. Delete it!
- if( is_file($full_path) ) {
- mtrace(" There were no items for XML File $file_name. Deleting XML File");
- unlink($full_path);
- mtrace(" $full_path -> (deleted)");
- } else {
- mtrace(" There were no items for the XML File $file_name and no file to delete. Ignore.");
- }
- } else {
- if (!empty($status)) {
- mtrace(" $full_path -> OK");
- } else {
- mtrace(" $full_path -> FAILED");
- }
- }
- }
- //end of oci_create_rss_feed()
- }
- }
- }
- }
-
- return $status;
-}
- */
-
-/*
- * Get official keywords for the
in header.html
- * use: echo '
';
- *
- * @param int $courseid
- * @return string
- *
- * Function removed but fully working
- * This function is potentially useful to anyone wanting to improve search results for course pages.
- * The idea is to add official tags (not personal tags to prevent their deletion) to all
- * courses (facility not added yet) which will be automatically added to the page header to boost
- * search engine specificity/ratings.
- */
-/*
-function coursetag_get_official_keywords($courseid, $asarray=false) {
- global $CFG;
- $returnstr = '';
- $sql = "SELECT t.id, name, rawname
- FROM {tag} t, {tag_instance} ti
- WHERE ti.itemid = :courseid
- AND ti.itemtype = 'course'
- AND t.tagtype = 'official'
- AND ti.tagid = t.id
- ORDER BY name ASC";
- if ($tags = $DB->get_records_sql($sql, array('courseid' => $courseid))) {
- if ($asarray) {
- return $tags;
- }
- foreach ($tags as $tag) {
- if( empty($CFG->keeptagnamecase) ) {
- $name = textlib::strtotitle($tag->name);
- } else {
- $name = $tag->rawname;
- }
- $returnstr .= $name.', ';
- }
- $returnstr = rtrim($returnstr, ', ');
- }
- return $returnstr;
-}
-*/
diff --git a/tag/locallib.php b/tag/locallib.php
index 158524c72f38d..56e9e0f8ea54f 100644
--- a/tag/locallib.php
+++ b/tag/locallib.php
@@ -32,21 +32,29 @@
* @package core_tag
* @access public
* @category tag
- * @param int $nr_of_tags Limit for the number of tags to return/display
+ * @param array $tagset Array of tags to display
+ * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null
* @param bool $return if true the function will return the generated tag cloud instead of displaying it.
* @return string|null a HTML string or null if this function does the output
*/
-function tag_print_cloud($nr_of_tags=150, $return=false) {
+//TODO question for integrator - for contrib work would it be best to add $tagset at the end of the parameter list
+// not the beginning? I put it at the beginning because it sits better as alternative to $nr_of_tags there
+function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false) {
global $CFG, $DB;
$can_manage_tags = has_capability('moodle/tag:manage', context_system::instance());
- if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
- FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
- WHERE ti.itemtype <> \'tag\'
- GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype
- ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) {
- $tagsincloud = array();
+ if (is_null($tagset)) {
+ // No tag set received, so fetch tags from database
+ if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
+ FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
+ WHERE ti.itemtype <> \'tag\'
+ GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype
+ ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) {
+ $tagsincloud = array();
+ }
+ } else {
+ $tagsincloud = $tagset;
}
$tagkeys = array_keys($tagsincloud);
@@ -200,8 +208,10 @@ function tag_print_management_box($tag_object, $return=false) {
$links[] = '
'. get_string('addtagtomyinterests', 'tag', $tagname) .'';
}
- // flag as inappropriate link
- $links[] = '
'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'';
+ // Flag as inappropriate link. Only people with moodle/tag:flag capability.
+ if (has_capability('moodle/tag:flag', $systemcontext)) {
+ $links[] = '
'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'';
+ }
// Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags
if (has_capability('moodle/tag:edit', $systemcontext) ||
diff --git a/tag/search.php b/tag/search.php
index 422d4e1bc7ca0..b399bac2d1279 100644
--- a/tag/search.php
+++ b/tag/search.php
@@ -72,7 +72,7 @@
echo '
';
echo $OUTPUT->box_start('generalbox', 'big-tag-cloud-box');
-tag_print_cloud(150);
+tag_print_cloud(null, 150);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
diff --git a/tag/tag.js b/tag/tag.js
index 5cab660389dce..85fc306266bfd 100644
--- a/tag/tag.js
+++ b/tag/tag.js
@@ -45,10 +45,6 @@ function ctags_checkinput(val) {
}
}
-function set_course_tag_divs(ctagdivs) {
- window.coursetagdivs = ctagdivs;
-}
-
function set_course_tag(key) {
window.coursetag_tags[window.coursetag_tags.length] = key;
}
diff --git a/version.php b/version.php
index 7bcbdd2b562f5..62cba88f43915 100644
--- a/version.php
+++ b/version.php
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2012092100.01; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2012092100.06; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes