diff --git a/tag/edit.php b/tag/edit.php
index ca71353e442..b9197578754 100644
--- a/tag/edit.php
+++ b/tag/edit.php
@@ -3,7 +3,6 @@
require_once('../config.php');
require_once('lib.php');
require_once('edit_form.php');
-require_once($CFG->dirroot.'/lib/weblib.php');
require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
@@ -25,14 +24,24 @@ require_capability('moodle/tag:edit', $systemcontext);
// set the relatedtags field of the $tag object that will be passed to the form
$tag->relatedtags = tag_names_csv(get_item_tags('tag',$tagid));
+if (can_use_html_editor()) {
+ $options = new object();
+ $options->smiley = false;
+ $options->filter = false;
+
+ // convert and remove any XSS
+ $tag->description = format_text($tag->description, $tag->descriptionformat, $options);
+ $tag->descriptionformat = FORMAT_HTML;
+}
+
$tagform = new tag_edit_form();
$tagform->set_data($tag);
// if new data has been sent, update the tag record
if ($tagnew = $tagform->get_data()) {
-
+
$tagnew->timemodified = time();
-
+
if (!update_record('tag', $tagnew)) {
error('Error updating tag record');
}
diff --git a/tag/edit_form.php b/tag/edit_form.php
index 8521c9d0235..ec954fdbbab 100644
--- a/tag/edit_form.php
+++ b/tag/edit_form.php
@@ -7,25 +7,24 @@ class tag_edit_form extends moodleform {
function definition () {
$mform =& $this->_form;
-
+
$mform->addElement('header', 'tag', get_string('description','tag'));
-
+
$mform->addElement('hidden', 'id');
-
+
$mform->addElement('htmleditor', 'description', get_string('description', 'tag'), array('rows'=>20));
- $mform->setType('description', PARAM_CLEANHTML);
-
+
$mform->addElement('format', 'descriptionformat', get_string('format'));
-
+
$mform->addElement('html', '
');
$mform->addElement('textarea', 'relatedtags', get_string('relatedtags','tag'), 'cols="50" rows="3"');
- $mform->setType('relatedtags', PARAM_MULTILANG);
+ $mform->setType('relatedtags', PARAM_TAGLIST);
$mform->addElement('html', '
');
$mform->addElement('html', '');
-
-
+
+
$this->add_action_buttons(false, get_string('updatetag', 'tag'));
-
+
}
}
diff --git a/tag/lib.php b/tag/lib.php
index 9e354d9751f..03a378ad4f1 100644
--- a/tag/lib.php
+++ b/tag/lib.php
@@ -1,15 +1,15 @@
prefix}tag_instance ti
INNER JOIN
{$CFG->prefix}tag tg
ON
tg.id = ti.tagid
- WHERE
+ WHERE
ti.itemtype = '{$item_type}' AND
ti.itemid = '{$item_id}'
$tagwhere
@@ -566,15 +566,15 @@ function get_item_tags($item_type, $item_id, $sort='ti.ordering ASC', $fields=DE
/**
* Function that returns the items of a certain type associated with a certain tag
- *
+ *
* Ex 1: get_items_tagged_with('user', 'banana')
* Ex 2: get_items_tagged_with('user', '11')
- *
+ *
* @param string $item_type name of the table where the item is stored. Ex: 'user'
* @param string $tag_name_or_id is a single **normalized** tag name or the id of a tag
* @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
* (to avoid field name ambiguity in the query, use the identifier "it" Ex: 'it.name ASC' )
- * @param string $fields a comma separated list of fields to return
+ * @param string $fields a comma separated list of fields to return
* (optional, by default all fields are returned). The first field will be used as key for the
* array so must be a unique field such as 'id'. )
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
@@ -598,15 +598,15 @@ function get_items_tagged_with($item_type, $tag_name_or_id, $sort='', $fields='*
$query = "
SELECT
{$fields}
- FROM
+ FROM
{$CFG->prefix}{$item_type} it
INNER JOIN
{$CFG->prefix}tag_instance tt
ON
it.id = tt.itemid
- WHERE
+ WHERE
tt.itemtype = '{$item_type}' AND
- tt.tagid = '{$tag_id}'
+ tt.tagid = '{$tag_id}'
{$sort}
";
@@ -619,7 +619,7 @@ function get_items_tagged_with($item_type, $tag_name_or_id, $sort='', $fields='*
* Returns the number of items tagged with a tag
*
* @param string $tag_name_or_id is a single **normalized** tag name or the id of a tag
- * @param string $item_type name of the table where the item is stored. Ex: 'user' (optional, if none is set any
+ * @param string $item_type name of the table where the item is stored. Ex: 'user' (optional, if none is set any
* type will be counted)
* @return int the count. If an error occurrs, 0 is returned.
*/
@@ -633,9 +633,9 @@ function count_items_tagged_with($tag_name_or_id, $item_type='') {
$query = "
SELECT
COUNT(*) AS count
- FROM
+ FROM
{$CFG->prefix}tag_instance tt
- WHERE
+ WHERE
tagid = {$tag_id}";
}
else
@@ -643,15 +643,15 @@ function count_items_tagged_with($tag_name_or_id, $item_type='') {
$query = "
SELECT
COUNT(*) AS count
- FROM
+ FROM
{$CFG->prefix}{$item_type} it
INNER JOIN
{$CFG->prefix}tag_instance tt
ON
it.id = tt.itemid
- WHERE
+ WHERE
tt.itemtype = '{$item_type}' AND
- tt.tagid = '{$tag_id}' ";
+ tt.tagid = '{$tag_id}' ";
}
@@ -693,26 +693,26 @@ function search_tags($text, $ordered=true, $limitfrom='' , $limitnum='' ) {
if ($ordered) {
$query = "
- SELECT
- tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count
- FROM
+ SELECT
+ tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count
+ FROM
{$CFG->prefix}tag tg
- LEFT JOIN
+ LEFT JOIN
{$CFG->prefix}tag_instance ti
- ON
+ ON
tg.id = ti.tagid
- WHERE
+ WHERE
tg.name
LIKE
- '%{$text}%'
- GROUP BY
- tg.id
- ORDER BY
- count
+ '%{$text}%'
+ GROUP BY
+ tg.id
+ ORDER BY
+ count
DESC";
} else {
$query = "
- SELECT
+ SELECT
tg.id, tg.name, tg.rawname
FROM
{$CFG->prefix}tag tg
@@ -720,7 +720,7 @@ function search_tags($text, $ordered=true, $limitfrom='' , $limitnum='' ) {
tg.name
LIKE
'%{$text}%'
- ";
+ ";
}
@@ -750,11 +750,11 @@ function similar_tags($text, $limitfrom='' , $limitnum='' ) {
/**
* Returns tags related to a tag
- *
- * Related tags of a tag come from two sources:
+ *
+ * Related tags of a tag come from two sources:
* - manually added related tags, which are tag_instance entries for that tag
* - correlated tags, which are a calculated
- *
+ *
* @param string $tag_name_or_id is a single **normalized** tag name or the id of a tag
* @param int $limitnum return a subset comprising this many records (optional, default is 10)
* @return mixed an array of tag objects
@@ -801,7 +801,7 @@ function correlated_tags($tag_name_or_id) {
/**
* Recalculates tag correlations of all the tags associated with an item
- * This function could be called whenever the tags associations with an item changes
+ * This function could be called whenever the tags associations with an item changes
* ( for example when tag_an_item() or untag_an_item() is called )
*
* @param string $item_type name of the table where the item is stored. Ex: 'user'
@@ -822,11 +822,11 @@ function update_tag_correlations($item_type, $item_id) {
*
* Two tags are correlated if they appear together a lot.
* Ex.: Users tagged with "computers" will probably also be tagged with "algorithms".
- *
- * The rationale for the 'tag_correlation' table is performance.
- * It works as a cache for a potentially heavy load query done at the 'tag_instance' table.
- * So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table.
- *
+ *
+ * The rationale for the 'tag_correlation' table is performance.
+ * It works as a cache for a potentially heavy load query done at the 'tag_instance' table.
+ * So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table.
+ *
* @param string $tag_name_or_id is a single **normalized** tag name or the id of a tag
* @param number $min_correlation cutoff percentage (optional, default is 0.25)
* @param int $limitnum return a subset comprising this many records (optional, default is 10)
@@ -835,7 +835,7 @@ function cache_correlated_tags($tag_name_or_id, $min_correlation=0.25, $limitnum
global $CFG;
$textlib = textlib_get_instance();
-
+
$tag_id = tag_id_from_string($tag_name_or_id);
// query that counts how many times any tag appears together in items
@@ -843,17 +843,17 @@ function cache_correlated_tags($tag_name_or_id, $min_correlation=0.25, $limitnum
$query =
" SELECT
tb.tagid , COUNT(*) nr
- FROM
- {$CFG->prefix}tag_instance ta
- INNER JOIN
- {$CFG->prefix}tag_instance tb
- ON
+ FROM
+ {$CFG->prefix}tag_instance ta
+ INNER JOIN
+ {$CFG->prefix}tag_instance tb
+ ON
ta.itemid = tb.itemid
- WHERE
+ WHERE
ta.tagid = {$tag_id}
- GROUP BY
- tb.tagid
- ORDER BY
+ GROUP BY
+ tb.tagid
+ ORDER BY
nr DESC";
$tag_correlations = get_records_sql($query, 0, $limitnum);
@@ -888,7 +888,7 @@ function cache_correlated_tags($tag_name_or_id, $min_correlation=0.25, $limitnum
}
/**
- * This function cleans up the 'tag_instance' table
+ * This function cleans up the 'tag_instance' table
* It removes orphans in 'tag_instances' table
*
*/
@@ -914,14 +914,14 @@ function tag_instance_table_cleanup() {
$query = "
{$CFG->prefix}tag_instance.id
IN
- ( SELECT sq1.id
- FROM
- (SELECT sq2.*
+ ( SELECT sq1.id
+ FROM
+ (SELECT sq2.*
FROM {$CFG->prefix}tag_instance sq2
LEFT JOIN {$CFG->prefix}{$type->itemtype} item
- ON sq2.itemid = item.id
- WHERE item.id IS NULL
- AND sq2.itemtype = '{$type->itemtype}')
+ ON sq2.itemid = item.id
+ WHERE item.id IS NULL
+ AND sq2.itemtype = '{$type->itemtype}')
sq1
) ";
@@ -933,15 +933,15 @@ function tag_instance_table_cleanup() {
$query = "
{$CFG->prefix}tag_instance.id
IN
- (SELECT sq1.id
- FROM
- (SELECT sq2.*
+ (SELECT sq1.id
+ FROM
+ (SELECT sq2.*
FROM {$CFG->prefix}tag_instance sq2
LEFT JOIN {$CFG->prefix}tag tg
- ON sq2.tagid = tg.id
- WHERE tg.id IS NULL )
+ ON sq2.tagid = tg.id
+ WHERE tg.id IS NULL )
sq1
- )
+ )
";
delete_records_select('tag_instance', $query);
@@ -950,13 +950,13 @@ function tag_instance_table_cleanup() {
/**
* Function that normalizes a list of tag names
- *
+ *
* Ex: tag_normalize('bANAana') -> returns 'banana'
* tag_normalize('lots of spaces') -> returns 'lots of spaces'
* tag_normalize('%!%!% non alpha numeric %!%!%') -> returns 'non alpha numeric'
- * tag_normalize('tag one, TAG TWO, TAG three, and anotheR tag')
- * -> returns 'tag one,tag two,tag three,and another tag'
- *
+ * tag_normalize('tag one, TAG TWO, TAG three, and anotheR tag')
+ * -> returns 'tag one,tag two,tag three,and another tag'
+ *
* @param string $tag_names_csv unnormalized CSV tag names
* @return string **normalized** CSV tag names
*/
@@ -1000,11 +1000,11 @@ function tag_flag_reset($tag_names_or_ids_csv){
$query = "
UPDATE
{$CFG->prefix}tag tg
- SET
+ SET
tg.flag = 0,
tg.timemodified = {$timemodified}
WHERE
- tg.id
+ tg.id
IN
({$tag_ids_csv_with_apos})
";
@@ -1013,7 +1013,7 @@ function tag_flag_reset($tag_names_or_ids_csv){
}
/**
- * Function that updates tags names.
+ * Function that updates tags names.
* Updates only if the new name suggested for a tag doesn´t exist already.
*
* @param Array $tags_names_changed array of new tag names indexed by tag ids.
@@ -1084,8 +1084,8 @@ function tag_links_csv($tag_objects) {
/**
* Function that returns comma separated names of the tags passed
* Example of string that might be returned: 'history, wars, greek history'
- *
- * @param array $tag_objects
+ *
+ * @param array $tag_objects
* @return string CSV tag names
*/
@@ -1117,18 +1117,18 @@ function popular_tags_count($nr_of_tags=20, $tag_type = 'default') {
global $CFG;
$query = "
- SELECT
- tg.rawname, tg.id, tg.name, COUNT(ti.id) AS count, tg.flag
- FROM
- {$CFG->prefix}tag_instance ti
- INNER JOIN
- {$CFG->prefix}tag tg
- ON
+ SELECT
+ tg.rawname, tg.id, tg.name, COUNT(ti.id) AS count, tg.flag
+ FROM
+ {$CFG->prefix}tag_instance ti
+ INNER JOIN
+ {$CFG->prefix}tag tg
+ ON
tg.id = ti.tagid
- GROUP BY
- tagid
- ORDER BY
- count
+ GROUP BY
+ tagid
+ ORDER BY
+ count
DESC
";
@@ -1222,19 +1222,19 @@ function print_tag_description_box($tag_object, $return=false) {
$content = !empty($tag_object->description) || $related_tags;
$output = '';
-
+
if ($content) {
$output .= print_box_start('generalbox', 'tag-description',true);
}
if (!empty($tag_object->description)) {
- $options = new object;
- $options->para=false;
- $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options );
+ $options = new object();
+ $options->para = false;
+ $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
}
if ($related_tags) {
- $output .= '
'.get_string('relatedtags','tag').': ' . tag_links_csv($related_tags);
+ $output .= '
'.get_string('relatedtags','tag').': ' . tag_links_csv($related_tags);
}
if ($content) {
@@ -1312,7 +1312,7 @@ function print_user_box($user, $return=false) {
global $CFG;
$textlib = textlib_get_instance();
-
+
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
$profilelink = '';