Index: tag/edit.php =================================================================== RCS file: /cvsroot/moodle/moodle/tag/edit.php,v retrieving revision 1.1 diff -c -r1.1 edit.php *** tag/edit.php 31 Jul 2007 07:51:37 -0000 1.1 --- tag/edit.php 1 Aug 2007 19:49:32 -0000 *************** *** 13,23 **** $tagid = required_param('id', PARAM_INT); // user id $tag = tag_by_id($tagid); ! $tagname = /*ucwords*/($tag->name); ! //Editing a tag requires moodle/tag:edittags capability $systemcontext = get_context_instance(CONTEXT_SYSTEM); ! require_capability('moodle/tag:edittags', $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) ); --- 13,23 ---- $tagid = required_param('id', PARAM_INT); // user id $tag = tag_by_id($tagid); ! $tagname = tag_display_name($tag); ! //Editing a tag requires moodle/tag:edit capability $systemcontext = get_context_instance(CONTEXT_SYSTEM); ! 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) ); Index: tag/index.php =================================================================== RCS file: /cvsroot/moodle/moodle/tag/index.php,v retrieving revision 1.1 diff -c -r1.1 index.php *** tag/index.php 31 Jul 2007 07:51:37 -0000 1.1 --- tag/index.php 1 Aug 2007 19:49:32 -0000 *************** *** 20,26 **** redirect($CFG->wwwroot.'/tag/search.php'); } ! $tagname = mb_convert_case($tag->name, MB_CASE_TITLE, "UTF-8"); $navlinks = array(); $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => ''); --- 20,26 ---- redirect($CFG->wwwroot.'/tag/search.php'); } ! $tagname = tag_display_name($tag); $navlinks = array(); $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => ''); *************** *** 54,62 **** print_tagged_users_table($tag, 4, $userpage * $perpage, $perpage); } - //print_box_start('generalbox', 'small-tag-cloud-box'); - // print_tag_cloud(15,170,80); - //print_box_end(); print_footer(); --- 54,59 ---- Index: tag/manage.php =================================================================== RCS file: /cvsroot/moodle/moodle/tag/manage.php,v retrieving revision 1.1 diff -c -r1.1 manage.php *** tag/manage.php 31 Jul 2007 07:51:38 -0000 1.1 --- tag/manage.php 1 Aug 2007 19:49:36 -0000 *************** *** 10,18 **** error(get_string('tagsaredisabled', 'tag')); } ! //managing tags requires moodle/tag:managetags capability $systemcontext = get_context_instance(CONTEXT_SYSTEM); ! require_capability('moodle/tag:managetags', $systemcontext); $tagschecked = optional_param('tagschecked', array()); $action = optional_param('action', '', PARAM_ALPHA); --- 10,18 ---- error(get_string('tagsaredisabled', 'tag')); } ! //managing tags requires moodle/tag:manage capability $systemcontext = get_context_instance(CONTEXT_SYSTEM); ! require_capability('moodle/tag:manage', $systemcontext); $tagschecked = optional_param('tagschecked', array()); $action = optional_param('action', '', PARAM_ALPHA); Index: tag/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/tag/lib.php,v retrieving revision 1.1 diff -c -r1.1 lib.php *** tag/lib.php 31 Jul 2007 07:51:37 -0000 1.1 --- tag/lib.php 1 Aug 2007 19:49:36 -0000 *************** *** 17,25 **** function tag_create($tag_names_csv, $tag_type="default") { global $USER; ! $normalized_tag_names_csv = tag_normalize($tag_names_csv) ; ! ! $tags = explode(",", $normalized_tag_names_csv ); $tag_object = new StdClass; $tag_object->tagtype = $tag_type; --- 17,23 ---- function tag_create($tag_names_csv, $tag_type="default") { global $USER; ! $tags = explode(",", $tag_names_csv ); $tag_object = new StdClass; $tag_object->tagtype = $tag_type; *************** *** 28,45 **** $systemcontext = get_context_instance(CONTEXT_SYSTEM); $can_create_tags = has_capability('moodle/tag:create',$systemcontext); ! foreach ($tags as $tag_name) { ! $tag_object->name = $tag_name; ! $tag_object->timemodified = time(); ! // if ( !record_exists('tag', 'name', $tag_name) && !empty($tag_name) && !is_numeric($tag_name) ) { ! if ( $can_create_tags && !empty($tag_name) && !is_numeric($tag_name) ) { insert_record('tag', $tag_object); } } ! return tags_id($normalized_tag_names_csv); } --- 26,51 ---- $systemcontext = get_context_instance(CONTEXT_SYSTEM); $can_create_tags = has_capability('moodle/tag:create',$systemcontext); ! $norm_tag_names_csv = ''; ! foreach ($tags as $tag) { ! // rawname keeps the original casing of the string ! $tag_object->rawname = tag_normalize($tag, false); ! ! // name lowecases the string ! $tag_object->name = tag_normalize($tag); ! $norm_tag_names_csv .= $tag_object->name . ','; ! ! $tag_object->timemodified = time(); ! if ( $can_create_tags && !empty($tag_object->name) && !is_numeric($tag_object->name) ) { insert_record('tag', $tag_object); } } ! $norm_tag_names_csv = substr($norm_tag_names_csv,0,-1); ! ! return tags_id( $norm_tag_names_csv ); } *************** *** 77,83 **** * (optional, by default 'id, tagtype, name'). The first field will be used as key for the * array so must be a unique field such as 'id'. */ ! function get_all_tags($tag_types_csv="default", $sort='name ASC', $fields='id, tagtype, name') { if ($tag_types_csv == '*'){ return get_records('tag', '', '', $sort, $fields); --- 83,89 ---- * (optional, by default 'id, tagtype, name'). The first field will be used as key for the * array so must be a unique field such as 'id'. */ ! function get_all_tags($tag_types_csv="default", $sort='name ASC', $fields='id, tagtype, name, rawname') { if ($tag_types_csv == '*'){ return get_records('tag', '', '', $sort, $fields); *************** *** 113,119 **** */ function tag_id($tag_name) { $tag = get_record('tag', 'name', trim($tag_name), '', '', '', '', 'id'); ! return $tag->id; } /** --- 119,131 ---- */ function tag_id($tag_name) { $tag = get_record('tag', 'name', trim($tag_name), '', '', '', '', 'id'); ! ! if ($tag){ ! return $tag->id; ! } ! else{ ! return false; ! } } /** *************** *** 147,153 **** */ function tag_name($tag_id) { $tag = get_record('tag', 'id', $tag_id, '', '', '', '', 'name'); ! return $tag->name; } /** --- 159,171 ---- */ function tag_name($tag_id) { $tag = get_record('tag', 'id', $tag_id, '', '', '', '', 'name'); ! ! if ($tag){ ! return $tag->name; ! } ! else{ ! return ''; ! } } /** *************** *** 159,164 **** --- 177,185 ---- function tags_name($tag_ids_csv) { + //remove any white spaces + $tag_ids_csv = str_replace(' ', '', $tag_ids_csv); + $tag_ids_csv_with_apos = "'" . str_replace(',', "','", $tag_ids_csv ) . "'"; $tag_objects = get_records_list('tag','id', $tag_ids_csv_with_apos, "" , "name, id" ); *************** *** 172,177 **** --- 193,219 ---- } /** + * Function that returns the name of a tag for display. + * + * @param mixed $tag_object + * @return string + */ + function tag_display_name($tag_object){ + + global $CFG; + + if( !empty($CFG->keeptagnamecase) ) { + //this is the normalized tag name + return mb_convert_case($tag_object->name, MB_CASE_TITLE,"UTF-8"); + } + else { + //original casing of the tag name + return $tag_object->rawname; + } + + } + + /** * Function that retrieves a tag object by its id * * @param String $tag_id *************** *** 194,204 **** } /** ! * Returns comma separated ids of tags given a string with comma separated names or ids of tags ! * ! * Ex: tag_id_from_string('moodle, 12, education, 33, 11') ! * might return the string '10,12,22,33,11' * * This is a helper function used by functions of this API to process function arguments ($tag_name_or_id) * * @param string $tag_names_or_ids_csv comma separated **normalized** names or ids of tags --- 236,253 ---- } /** ! * In a comma separated string of ids or names of tags, replaces all tag names with their correspoding ids * + * Ex: + * Suppose the DB contains only the following entries in the tags table: + * id name + * 10 moodle + * 12 science + * 22 education + * + * tag_id_from_string('moodle, 12, education, programming, 33, 11') + * will return '10,12,22,,33,11' + * * This is a helper function used by functions of this API to process function arguments ($tag_name_or_id) * * @param string $tag_names_or_ids_csv comma separated **normalized** names or ids of tags *************** *** 212,218 **** foreach ($tag_names_or_ids as $name_or_id) { if (is_numeric($name_or_id)){ ! $tag_ids[] = $name_or_id; } elseif (is_string($name_or_id)) { $tag_ids[] = tag_id( $name_or_id ); --- 261,267 ---- foreach ($tag_names_or_ids as $name_or_id) { if (is_numeric($name_or_id)){ ! $tag_ids[] = trim($name_or_id); } elseif (is_string($name_or_id)) { $tag_ids[] = tag_id( $name_or_id ); *************** *** 223,236 **** $tag_ids_csv = implode(',',$tag_ids); $tag_ids_csv = str_replace(' ', '', $tag_ids_csv); ! return rtrim($tag_ids_csv, ','); } /** ! * Returns comma separated **normalized** names of tags given a string with comma separated names or ids of tags * ! * Ex: tag_name_from_string('mOOdle, 12, eduCAtIOn, 33, 11') ! * might return the string 'moodle,computers,education,algorithms,software' * * This is a helper function used by functions of this API to process function arguments ($tag_name_or_id) * --- 272,292 ---- $tag_ids_csv = implode(',',$tag_ids); $tag_ids_csv = str_replace(' ', '', $tag_ids_csv); ! return $tag_ids_csv; } /** ! * In a comma separated string of ids or names of tags, replaces all tag ids with their correspoding names ! * ! * Ex: ! * Suppose the DB contains only the following entries in the tags table: ! * id name ! * 10 moodle ! * 12 science ! * 22 education * ! * tag_name_from_string('mOOdle, 10, HiStOrY, 17, 22') ! * will return the string 'mOOdle,moodle,HiStOrY,,education' * * This is a helper function used by functions of this API to process function arguments ($tag_name_or_id) * *************** *** 248,261 **** $tag_names[] = tag_name($name_or_id); } elseif (is_string($name_or_id)) { ! $tag_names[] = tag_normalize($name_or_id); } } $tag_names_csv = implode(',',$tag_names); ! return rtrim($tag_names_csv, ','); } --- 304,317 ---- $tag_names[] = tag_name($name_or_id); } elseif (is_string($name_or_id)) { ! $tag_names[] = trim($name_or_id); } } $tag_names_csv = implode(',',$tag_names); ! return $tag_names_csv; } *************** *** 277,286 **** function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="default") { - $norm_tag_names_or_ids_csv = tag_normalize($tag_names_or_ids_csv); - //convert any tag ids passed to their corresponding tag names ! $tag_names_csv = tag_name_from_string($norm_tag_names_or_ids_csv); //create the tags $tags_created_ids = tag_create($tag_names_csv,$tag_type); --- 333,340 ---- function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="default") { //convert any tag ids passed to their corresponding tag names ! $tag_names_csv = tag_name_from_string($tag_names_or_ids_csv); //create the tags $tags_created_ids = tag_create($tag_names_csv,$tag_type); *************** *** 328,344 **** return; } - //normalize tags names - $norm_tag_names_or_ids_csv = tag_normalize($tag_names_or_ids_csv); - //convert any tag ids passed to their corresponding tag names ! $tag_names_csv = tag_name_from_string($norm_tag_names_or_ids_csv); //associate the tags passed with the item tag_an_item($item_type, $item_id, $tag_names_csv, $tag_type ); //get the ids of the tags passed ! $existing_and_new_tags_ids = tags_id( $tag_names_csv ); // delete any tag instance with $item_type and $item_id // that are not in $tag_names_csv --- 382,395 ---- return; } //convert any tag ids passed to their corresponding tag names ! $tag_names_csv = tag_name_from_string($tag_names_or_ids_csv); //associate the tags passed with the item tag_an_item($item_type, $item_id, $tag_names_csv, $tag_type ); //get the ids of the tags passed ! $existing_and_new_tags_ids = tags_id( tag_normalize($tag_names_csv) ); // delete any tag instance with $item_type and $item_id // that are not in $tag_names_csv *************** *** 403,409 **** * @return mixed an array of objects, or false if no records were found or an error occured. */ ! function get_item_tags($item_type, $item_id, $fields='id, name, tagtype, flag', $limitfrom='', $limitnum='') { global $CFG; --- 454,460 ---- * @return mixed an array of objects, or false if no records were found or an error occured. */ ! function get_item_tags($item_type, $item_id, $fields='id, name, rawname, tagtype, flag', $limitfrom='', $limitnum='') { global $CFG; *************** *** 441,447 **** * (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 * (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). * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). * @return mixed an array of objects indexed by their ids, or false if no records were found or an error occured. --- 492,499 ---- * (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 * (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'. To avoid field name ambiguity in the query, ! * use the identifier "it" Ex: 'it.name, it.id' ) * @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set). * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set). * @return mixed an array of objects indexed by their ids, or false if no records were found or an error occured. *************** *** 559,565 **** if ($ordered) { $query = " SELECT ! tg.id, tg.name, COUNT(ti.id) AS count FROM {$CFG->prefix}tag tg LEFT JOIN --- 611,617 ---- if ($ordered) { $query = " SELECT ! tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count FROM {$CFG->prefix}tag tg LEFT JOIN *************** *** 578,584 **** } else { $query = " SELECT ! tg.id, tg.name FROM {$CFG->prefix}tag tg WHERE --- 630,636 ---- } else { $query = " SELECT ! tg.id, tg.name, tg.rawname FROM {$CFG->prefix}tag tg WHERE *************** *** 609,619 **** $query = " SELECT ! * FROM ! {$CFG->prefix}tag t WHERE ! t.name LIKE '{$text}%' "; --- 661,671 ---- $query = " SELECT ! tg.id, tg.name, tg.rawname FROM ! {$CFG->prefix}tag tg WHERE ! tg.name LIKE '{$text}%' "; *************** *** 669,675 **** $tags_id_csv_with_apos = stripcslashes($tag_correlation->correlatedtags); ! return get_records_select('tag', "id IN ({$tags_id_csv_with_apos})", '', 'id, name, tagtype'); } /** --- 721,727 ---- $tags_id_csv_with_apos = stripcslashes($tag_correlation->correlatedtags); ! return get_records_select('tag', "id IN ({$tags_id_csv_with_apos})", '', 'id, name, rawname, tagtype'); } /** *************** *** 833,839 **** * @return string **normalized** CSV tag names */ ! function tag_normalize($tag_names_csv) { $tags = explode(',', $tag_names_csv); --- 885,891 ---- * @return string **normalized** CSV tag names */ ! function tag_normalize($tag_names_csv, $lowercase=true) { $tags = explode(',', $tag_names_csv); *************** *** 849,857 **** // only one tag was passed else { ! // value is converted to lowercase and all non-alphanumeric characters are removed ! //$value = preg_replace('|[^\w ]|i', '', strtolower(trim($tag_names_csv))); ! $value = preg_replace('|[\!\@\#\$\%\^\&\*\(\)\-\+\=\~\`\.\[\]\{\}\:\;\\\/\<\>\|]|i', '', moodle_strtolower(trim($tag_names_csv))); //removes excess white spaces $value = preg_replace('/\s\s+/', ' ', $value); --- 901,916 ---- // only one tag was passed else { ! ! if ($lowercase){ ! $value = moodle_strtolower($tag_names_csv); ! } ! else { ! $value = $tag_names_csv; ! } ! ! //$value = preg_replace('|[^\w ]|i', '', strtolower(trim($tag_names_csv))); ! $value = preg_replace('|[\!\@\#\$\%\^\&\*\(\)\-\+\=\~\`\.\[\]\{\}\:\;\?\ยด\^\\\/\<\>\|]|i', '', trim($value)); //removes excess white spaces $value = preg_replace('/\s\s+/', ' ', $value); *************** *** 927,933 **** foreach ($tag_objects as $tag){ //highlight tags that have been flagged as inappropriate for those who can manage them ! $tagname = $tag->name; if ($tag->flag > 0 && $can_manage_tags) { $tagname = '' . $tagname . ''; } --- 986,992 ---- foreach ($tag_objects as $tag){ //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 = '' . $tagname . ''; } *************** *** 954,960 **** $tags = array(); foreach ($tag_objects as $tag){ ! $tags[] = $tag->name; } return implode(',', $tags); --- 1013,1019 ---- $tags = array(); foreach ($tag_objects as $tag){ ! $tags[] = tag_display_name($tag); } return implode(',', $tags); *************** *** 991,997 **** $query = " SELECT ! tg.id, tg.name, COUNT(ti.id) AS count, tg.flag FROM {$CFG->prefix}tag_instance ti INNER JOIN --- 1050,1056 ---- $query = " SELECT ! tg.id, tg.name, tg.rawname, COUNT(ti.id) AS count, tg.flag FROM {$CFG->prefix}tag_instance ti INNER JOIN *************** *** 1025,1031 **** global $USER, $CFG; ! $tagname = /*ucwords*/($tag_object->name); print_box_start('box','tag-management-box'); --- 1084,1090 ---- global $USER, $CFG; ! $tagname = tag_display_name($tag_object); print_box_start('box','tag-management-box'); *************** *** 1044,1050 **** echo $addtaglink .' | '; } ! // only people with moodle/tag:edittags capability may edit the tag description if ( has_capability('moodle/tag:edit',$systemcontext) && is_item_tagged_with('user', $USER->id, $tag_object->id ) ) { echo ' '.get_string('edittag', 'tag').' | '; } --- 1103,1109 ---- echo $addtaglink .' | '; } ! // only people with moodle/tag:edit capability may edit the tag description if ( has_capability('moodle/tag:edit',$systemcontext) && is_item_tagged_with('user', $USER->id, $tag_object->id ) ) { echo ' '.get_string('edittag', 'tag').' | '; } *************** *** 1068,1074 **** global $USER, $CFG; ! $tagname = /*ucwords*/($tag_object->name); $related_tags = related_tags($tag_object->id); //get_item_tags('tags',$tag_object->id); --- 1127,1133 ---- global $USER, $CFG; ! $tagname = tag_display_name($tag_object); $related_tags = related_tags($tag_object->id); //get_item_tags('tags',$tag_object->id); *************** *** 1256,1262 **** for($i = 0; $i < $nr_of_uls; $i++) { echo '