mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-13404 - Merge from 1.9 (re-commit, including missing file)
This commit is contained in:
parent
d3477228d0
commit
3d535996db
@ -1280,7 +1280,7 @@
|
||||
|
||||
//Check if we have user tags to backup
|
||||
if (!empty($CFG->usetags)) {
|
||||
if ($tags = get_item_tags('user', $user->id)) { //This return them ordered by default
|
||||
if ($tags = tag_get_tags(array('type'=>'user', 'id'=>$user->id))) { //This return them ordered by default
|
||||
//Start USER_TAGS tag
|
||||
fwrite ($bf,start_tag("USER_TAGS",4,true));
|
||||
//Write user tags fields
|
||||
|
@ -161,7 +161,7 @@ class block_blog_tags extends block_base {
|
||||
$this->content->text .= '<li><a href="'.$link.'" '.
|
||||
'class="'.$tag->class.'" '.
|
||||
'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
|
||||
$tag->name.'</a></li> ';
|
||||
tag_display_name($tag) .'</a></li> ';
|
||||
}
|
||||
$this->content->text .= "\n</ul>\n";
|
||||
|
||||
|
@ -39,12 +39,23 @@ class block_tag_flickr extends block_base {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
|
||||
$tag = optional_param('tag', '', PARAM_TAG); // tag
|
||||
|
||||
if ($tag) {
|
||||
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
|
||||
} elseif (!$tag && $tagid) {
|
||||
$tag_object = tag_get_tag_by_id($tagid);
|
||||
} else {
|
||||
// can't display the block if no tag was submitted!
|
||||
// todo: something useful here.
|
||||
error('Missing tag parameter');
|
||||
}
|
||||
|
||||
//include related tags in the photo query ?
|
||||
$tags_csv = tag_display_name(tag_by_id($tagid));
|
||||
$tags_csv = html_entity_decode(tag_display_name($tag_object));
|
||||
if (!empty($this->config->includerelatedtags)) {
|
||||
$tags_csv .= ',' . tag_names_csv( get_item_tags('tag',$tagid));
|
||||
$tags_csv .= ',' . tag_get_related_tags_csv(tag_get_related_tags(array('type'=>'tag','id'=>$tag_object->id)), TAG_RETURN_TEXT);
|
||||
}
|
||||
$tags_csv = urlencode($tags_csv);
|
||||
|
||||
|
@ -78,18 +78,29 @@ class block_tag_youtube extends block_base {
|
||||
|
||||
function get_videos_by_tag(){
|
||||
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
|
||||
$tag = optional_param('tag', '', PARAM_TAG); // tag
|
||||
|
||||
$query_tag = tag_display_name(tag_by_id($tagid));
|
||||
if ($tag) {
|
||||
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
|
||||
} elseif (!$tag && $tagid) {
|
||||
$tag_object = tag_get_tag_by_id($tagid);
|
||||
} else {
|
||||
// can't display the block if no tag was submitted!
|
||||
// todo: something useful here.
|
||||
error('Missing tag parameter');
|
||||
}
|
||||
|
||||
$query_tag = html_entity_decode(tag_display_name($tag_object));
|
||||
$query_tag = urlencode($query_tag);
|
||||
|
||||
$numberofvideos = DEFAULT_NUMBER_OF_VIDEOS;
|
||||
if( !empty($this->config->numberofvideos)) {
|
||||
if ( !empty($this->config->numberofvideos) ) {
|
||||
$numberofvideos = $this->config->numberofvideos;
|
||||
}
|
||||
|
||||
$request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag';
|
||||
$request .= '&dev_id=' . YOUTUBE_DEV_KEY;
|
||||
$request .= '&dev_id='. YOUTUBE_DEV_KEY;
|
||||
$request .= "&tag={$query_tag}";
|
||||
$request .= "&page=1";
|
||||
$request .= "&per_page={$numberofvideos}";
|
||||
@ -99,9 +110,20 @@ class block_tag_youtube extends block_base {
|
||||
|
||||
function get_videos_by_tag_and_category(){
|
||||
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
|
||||
$tag = optional_param('tag', '', PARAM_TAG); // tag
|
||||
|
||||
$query_tag = tag_display_name(tag_by_id($tagid));
|
||||
if ($tag) {
|
||||
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
|
||||
} elseif (!$tag && $tagid) {
|
||||
$tag_object = tag_get_tag_by_id($tagid);
|
||||
} else {
|
||||
// can't display the block if no tag was submitted!
|
||||
// todo: something useful here.
|
||||
error('Missing tag parameter');
|
||||
}
|
||||
|
||||
$query_tag = html_entity_decode(tag_display_name($tag_object));
|
||||
$query_tag = urlencode($query_tag);
|
||||
|
||||
$numberofvideos = DEFAULT_NUMBER_OF_VIDEOS;
|
||||
@ -158,18 +180,23 @@ class block_tag_youtube extends block_base {
|
||||
$text .= '<ul class="yt-video-entry unlist img-text">';
|
||||
$videos = $xmlobj['ut_response']['video_list']['video'];
|
||||
|
||||
foreach($videos as $video){
|
||||
$text .= '<li>';
|
||||
$text .= '<div class="clearfix">';
|
||||
$text .= '<a href="'. s($video['url']) . '">';
|
||||
$text .= '<img alt="" class="youtube-thumb" src="'. $video['thumbnail_url'] .'" /></a>';
|
||||
$text .= '</div><span><a href="'. s($video['url']) . '">'.s($video['title']).'</a></span>';
|
||||
$text .= '<div>';
|
||||
$text .= format_time($video['length_seconds']);
|
||||
$text .= "</div></li>\n";
|
||||
if (is_array($videos) ) {
|
||||
foreach($videos as $video){
|
||||
$text .= '<li>';
|
||||
$text .= '<div class="clearfix">';
|
||||
$text .= '<a href="'. s($video['url']) . '">';
|
||||
$text .= '<img alt="" class="youtube-thumb" src="'. $video['thumbnail_url'] .'" /></a>';
|
||||
$text .= '</div><span><a href="'. s($video['url']) . '">'.s($video['title']).'</a></span>';
|
||||
$text .= '<div>';
|
||||
$text .= format_time($video['length_seconds']);
|
||||
$text .= "</div></li>\n";
|
||||
}
|
||||
} else {
|
||||
// if youtube is offline, or for whatever reason the previous
|
||||
// call doesn't work...
|
||||
//add_to_log(SITEID, 'blocks/tag_youtube', 'problem in getting videos off youtube');
|
||||
}
|
||||
$text .= "</ul><div class=\"clearer\"></div>\n";
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class block_tags extends block_base {
|
||||
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
|
||||
$this->content->text = print_tag_cloud(popular_tags_count($this->config->numberoftags), false, 170, 70, true);
|
||||
$this->content->text = tag_print_cloud($this->config->numberoftags, false, 170, 70, true);
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
@ -119,18 +119,12 @@ switch ($action) {
|
||||
$post->action = $action;
|
||||
$strformheading = get_string('updateentrywithid', 'blog');
|
||||
|
||||
if ($itemptags = get_item_tags('post', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'default')) {
|
||||
if ($ptags = records_to_menu($itemptags, 'id','rawname')) {
|
||||
$post->ptags = implode(', ', $ptags);
|
||||
} else {
|
||||
$post->ptags = '';
|
||||
}
|
||||
if ($itemptags = html_entity_decode(tag_get_tags_csv(array('type'=>'post', 'id'=>$post->id), TAG_RETURN_TEXT, 'default'))) {
|
||||
$post->ptags = $itemptags;
|
||||
}
|
||||
|
||||
if ($itemotags = get_item_tags('post', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'official')) {
|
||||
if ($otags = records_to_menu($itemotags, 'id','rawname')) {
|
||||
$post->otags = array_keys($otags);
|
||||
}
|
||||
if ($itemotags = tag_get_tags_array(array('type'=>'post', 'id'=>$post->id), 'official')) {
|
||||
$post->otags = array_keys($itemotags);
|
||||
}
|
||||
break;
|
||||
default :
|
||||
@ -231,7 +225,7 @@ function do_delete($post) {
|
||||
|
||||
$status = delete_records('post', 'id', $post->id);
|
||||
//$status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status;
|
||||
untag_an_item('post', $post->id);
|
||||
tag_set('post', $post->id, array());
|
||||
|
||||
blog_delete_old_attachments($post);
|
||||
|
||||
@ -293,7 +287,7 @@ function do_edit($post, $blogeditform) {
|
||||
|
||||
//delete_records('blog_tag_instance', 'entryid', $post->id);
|
||||
//delete_records('tag_instance', 'itemid', $post->id, 'itemtype', 'blog');
|
||||
untag_an_item('post', $post->id);
|
||||
//untag_an_item('post', $post->id);
|
||||
// add them back
|
||||
add_tags_info($post->id);
|
||||
|
||||
@ -309,38 +303,19 @@ function do_edit($post, $blogeditform) {
|
||||
* @param int postid - id of the blog
|
||||
*/
|
||||
function add_tags_info($postid) {
|
||||
|
||||
global $USER;
|
||||
|
||||
$post = get_record('post', 'id', $postid);
|
||||
|
||||
/// Attach official tags
|
||||
|
||||
$tags = array();
|
||||
if ($otags = optional_param('otags', '', PARAM_INT)) {
|
||||
foreach ($otags as $otag) {
|
||||
$tag->tagid = $otag;
|
||||
//insert_record('blog_tag_instance', $tag);
|
||||
tag_an_item('post', $postid, $otag, 'official');
|
||||
foreach ($otags as $tagid) {
|
||||
// TODO : make this use the tag name in the form
|
||||
$tag = tag_get_tag_by_id($tagid);
|
||||
$tags[] = $tag->name;
|
||||
}
|
||||
}
|
||||
|
||||
/// Attach Personal Tags
|
||||
if ($ptags = optional_param('ptags', '', PARAM_NOTAGS)) {
|
||||
$ptags = explode(',', $ptags);
|
||||
foreach ($ptags as $ptag) {
|
||||
$ptag = trim($ptag);
|
||||
// check for existence
|
||||
// it does not matter whether it is an offical tag or personal tag
|
||||
// we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag)
|
||||
if ($ctag = tag_by_name($ptag)) {
|
||||
tag_an_item('post', $postid, $ctag->id);
|
||||
} else { // create a personal tag
|
||||
if ($tagid = tag_create($ptag)) {
|
||||
if ($tagid = array_shift($tagid)) {
|
||||
tag_an_item('post', $postid, $tagid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$manual_tags = optional_param('ptags', '', PARAM_NOTAGS);
|
||||
$tags = array_merge($tags, explode(',', $manual_tags));
|
||||
|
||||
tag_set('post', $postid, $tags);
|
||||
}
|
||||
?>
|
||||
|
@ -34,8 +34,8 @@ class blog_edit_form extends moodleform {
|
||||
|
||||
|
||||
if (!empty($CFG->usetags)) {
|
||||
$mform->addElement('header', 'tagshdr', get_string('tags', 'blog'));
|
||||
$mform->createElement('select', 'otags', get_string('otags','blog'));
|
||||
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
|
||||
$mform->createElement('select', 'otags', get_string('otags','tag'));
|
||||
|
||||
$js_escape = array(
|
||||
"\r" => '\r',
|
||||
@ -46,28 +46,11 @@ class blog_edit_form extends moodleform {
|
||||
'\\' => '\\\\'
|
||||
);
|
||||
|
||||
$otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'blog'), array(), 'size="5"');
|
||||
$otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"');
|
||||
$otagsselEl->setMultiple(true);
|
||||
$this->otags_select_setup();
|
||||
|
||||
if (has_capability('moodle/blog:manageofficialtags', $sitecontext)){
|
||||
$deleteotagsmsg = strtr(get_string('deleteotagswarn', 'blog'), $js_escape);
|
||||
$mform->registerNoSubmitButton('deleteotags');
|
||||
$mform->addElement('submit', 'deleteotags', get_string('delete'),
|
||||
array('onclick'=>"return confirm('$deleteotagsmsg');"));
|
||||
$mform->disabledIf('deleteotags', 'otags[]', 'noitemselected');
|
||||
$mform->setAdvanced('deleteotags');
|
||||
|
||||
$mform->registerNoSubmitButton('addotags');
|
||||
$otagsgrp = array();
|
||||
$otagsgrp[] =& $mform->createElement('text', 'otagsadd', get_string('addotags', 'blog'));
|
||||
$otagsgrp[] =& $mform->createElement('submit', 'addotags', get_string('add'));
|
||||
$mform->addGroup($otagsgrp, 'otagsgrp', get_string('addotags','blog'), array(' '), false);
|
||||
$mform->setType('otagsadd', PARAM_NOTAGS);
|
||||
$mform->setAdvanced('otagsgrp');
|
||||
}
|
||||
|
||||
$mform->addElement('textarea', 'ptags', get_string('ptags', 'blog'), array('cols'=>'40', 'rows'=>'5'));
|
||||
$mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
|
||||
$mform->setType('ptagsadd', PARAM_NOTAGS);
|
||||
}
|
||||
|
||||
@ -99,9 +82,6 @@ class blog_edit_form extends moodleform {
|
||||
}
|
||||
if ($otags = get_records_sql_menu('SELECT id, name from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
|
||||
$otagsselect->loadArray($otags);
|
||||
} else {
|
||||
// removing this causes errors
|
||||
//$mform->removeElement('otags');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,8 @@ if ($editing) {
|
||||
|
||||
if (!empty($tagid)) {
|
||||
$taginstance = get_record('tag', 'id', $tagid);
|
||||
} else {
|
||||
$tagid = '';
|
||||
if (!empty($tag)) {
|
||||
$taginstance = tag_id($tag);
|
||||
}
|
||||
} elseif (!empty($tag)) {
|
||||
$taginstance = tag_id($tag);
|
||||
}
|
||||
|
||||
/// navigations
|
||||
|
17
blog/lib.php
17
blog/lib.php
@ -222,22 +222,11 @@
|
||||
echo $attachedimages;
|
||||
/// Links to tags
|
||||
|
||||
/*
|
||||
if ($blogtags = get_records_sql('SELECT t.* FROM '.$CFG->prefix.'tags t, '.$CFG->prefix.'blog_tag_instance ti
|
||||
WHERE t.id = ti.tagid
|
||||
AND ti.entryid = '.$blogEntry->id)) {
|
||||
*/
|
||||
if (!empty($CFG->usetags) && ($blogtags = get_item_tags('post', $blogEntry->id))) {
|
||||
if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_csv(array('type'=>'post', 'id'=>$blogEntry->id))) ) {
|
||||
echo '<div class="tags">';
|
||||
if ($blogtags) {
|
||||
print_string('tags');
|
||||
echo ': ';
|
||||
foreach ($blogtags as $key => $blogtag) {
|
||||
//$taglist[] = '<a href="index.php?filtertype='.$filtertype.'&filterselect='.$filterselect.'&tagid='.$blogtag->id.'">'.tag_display_name($blogtag).'</a>'; // Blog tag only
|
||||
$taglist[] = '<a href="'.$CFG->wwwroot.'/tag/index.php?id='.$blogtag->id.'">'.tag_display_name($blogtag).'</a>'; // General tag link
|
||||
}
|
||||
echo implode(', ', $taglist);
|
||||
}
|
||||
print(get_string('tags', 'tag') .': '. $blogtags);
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
|
||||
$string['addnewentry'] = 'Add a new entry';
|
||||
$string['addotags'] = 'Add official tags';
|
||||
$string['addptags'] = 'Add user-defined tags';
|
||||
$string['backupblogshelp'] = 'If enabled then blogs will be included in SITE automated backups';
|
||||
$string['blockmenutitle'] = 'Blog Menu';
|
||||
$string['blocktagstitle'] = 'Blog Tags';
|
||||
@ -35,10 +33,8 @@ $string['norighttodeletetag'] = 'You have no rights to delete this tag - $a';
|
||||
$string['notallowedtoedit'] = 'You are not allowed to edit this entry';
|
||||
$string['numberofentries'] = 'Entries: $a';
|
||||
$string['numberoftags'] = 'Number of tags to display';
|
||||
$string['otags'] = 'Official tags';
|
||||
$string['pagesize'] = 'Number of blog entries per Page';
|
||||
$string['personalblogs'] = 'Users can only see their own blog';
|
||||
$string['ptags'] = 'User defined tags (Comma separated)';
|
||||
$string['publishto'] = 'Publish to';
|
||||
$string['publishtonoone'] = 'Yourself (draft)';
|
||||
$string['publishtosite'] = 'Anyone on this site';
|
||||
|
@ -153,11 +153,6 @@ define('PARAM_FILE', 0x0010);
|
||||
*/
|
||||
define('PARAM_TAG', 0x0011);
|
||||
|
||||
/**
|
||||
* PARAM_TAGLIST - list of tags separated by commas (interests, blogs, etc.)
|
||||
*/
|
||||
define('PARAM_TAGLIST', 0x0012);
|
||||
|
||||
/**
|
||||
* PARAM_PATH - safe relative path name, all dangerous chars are stripped, protects against XSS, SQL injections and directory traversals
|
||||
* note: the leading slash is not removed, window drive letter is not allowed
|
||||
@ -259,7 +254,9 @@ define ('BLOG_GLOBAL_LEVEL', 5);
|
||||
/**
|
||||
* Tag constanst
|
||||
*/
|
||||
define('TAG_MAX_LENGTH', 50);
|
||||
//To prevent problems with multibytes strings, this should not exceed the
|
||||
//length of "varchar(255) / 3 (bytes / utf-8 character) = 85".
|
||||
define('TAG_MAX_LENGTH', 50);
|
||||
|
||||
if (!defined('SORT_LOCALE_STRING')) { // PHP < 4.4.0 - TODO: remove in 2.0
|
||||
define('SORT_LOCALE_STRING', SORT_STRING);
|
||||
@ -368,7 +365,6 @@ function optional_param($parname, $default=NULL, $type=PARAM_CLEAN) {
|
||||
* @uses PARAM_PEM
|
||||
* @uses PARAM_BASE64
|
||||
* @uses PARAM_TAG
|
||||
* @uses PARAM_TAGLIST
|
||||
* @uses PARAM_SEQUENCE
|
||||
* @param mixed $param the variable we are cleaning
|
||||
* @param int $type expected format of param after cleaning.
|
||||
@ -561,35 +557,14 @@ function clean_param($param, $type) {
|
||||
}
|
||||
|
||||
case PARAM_TAG:
|
||||
//first fix whitespace
|
||||
//as long as magic_quotes_gpc is used, a backslash will be a
|
||||
//problem, so remove *all* backslash.
|
||||
$param = str_replace('\\', '', $param);
|
||||
//convert many whitespace chars into one
|
||||
$param = preg_replace('/\s+/', ' ', $param);
|
||||
//remove blacklisted ASCII ranges of chars - security FIRST - keep only ascii letters, numbers and spaces
|
||||
//the result should be safe to be used directly in html and SQL
|
||||
$param = preg_replace("/[\\000-\\x1f\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f]/", '', $param);
|
||||
//now remove some unicode ranges we do not want
|
||||
$param = preg_replace("/[\\x{80}-\\x{bf}\\x{d7}\\x{f7}]/u", '', $param);
|
||||
//cleanup the spaces
|
||||
$param = preg_replace('/ +/', ' ', $param);
|
||||
$param = trim($param);
|
||||
$textlib = textlib_get_instance();
|
||||
$param = $textlib->substr($param, 0, TAG_MAX_LENGTH);
|
||||
//numeric tags not allowed
|
||||
return is_numeric($param) ? '' : $param;
|
||||
|
||||
case PARAM_TAGLIST:
|
||||
$tags = explode(',', $param);
|
||||
$result = array();
|
||||
foreach ($tags as $tag) {
|
||||
$res = clean_param($tag, PARAM_TAG);
|
||||
if ($res != '') {
|
||||
$result[] = $res;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return implode(',', $result);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
$param = $textlib->substr(trim($param), 0, TAG_MAX_LENGTH);
|
||||
return $param;
|
||||
|
||||
default: // throw error, switched parameters in optional_param or another serious problem
|
||||
error("Unknown parameter type: $type");
|
||||
|
20
tag/edit.php
20
tag/edit.php
@ -12,9 +12,15 @@ if (empty($CFG->usetags)) {
|
||||
error(get_string('tagsaredisabled', 'tag'));
|
||||
}
|
||||
|
||||
$tagid = required_param('id', PARAM_INT); // user id
|
||||
|
||||
$tag = tag_by_id($tagid);
|
||||
$tag_id = optional_param('id', 0, PARAM_INT);
|
||||
$tag_name = optional_param('tag', '', PARAM_TAG);
|
||||
if ($tag_name) {
|
||||
$tag = array_shift(tag_get_id($tag_name, TAG_RETURN_OBJECT));
|
||||
} elseif ( $tag_id ) {
|
||||
$tag = tag_get_tag_by_id($tag_id);
|
||||
} else {
|
||||
error('A required parameter was missing');
|
||||
}
|
||||
$tagname = tag_display_name($tag);
|
||||
|
||||
//Editing a tag requires moodle/tag:edit capability
|
||||
@ -22,7 +28,8 @@ $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));
|
||||
//$tag->relatedtags = tag_names_csv(get_item_tags('tag',$tagid));
|
||||
$tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id), TAG_RETURN_TEXT);
|
||||
|
||||
if (can_use_html_editor()) {
|
||||
$options = new object();
|
||||
@ -47,9 +54,10 @@ if ($tagnew = $tagform->get_data()) {
|
||||
}
|
||||
|
||||
//updated related tags
|
||||
update_item_tags('tag', $tagnew->id, $tagnew->relatedtags);
|
||||
tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags)));
|
||||
//var_dump($tagnew); die();
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?id='.$tagnew->id);
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='.rawurlencode($tag->name)); // must use $tag here, as the name isn't in the edit form
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ function definition () {
|
||||
|
||||
$mform->addElement('html', '<br/><div id="relatedtags-autocomplete-container">');
|
||||
$mform->addElement('textarea', 'relatedtags', get_string('relatedtags','tag'), 'cols="50" rows="3"');
|
||||
$mform->setType('relatedtags', PARAM_TAGLIST);
|
||||
$mform->setType('relatedtags', PARAM_TAG);
|
||||
$mform->addElement('html', '</div>');
|
||||
$mform->addElement('html', '<div id="relatedtags-autocomplete"></div>');
|
||||
|
||||
|
@ -12,14 +12,18 @@ if (empty($CFG->usetags)) {
|
||||
error(get_string('tagsaredisabled', 'tag'));
|
||||
}
|
||||
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id
|
||||
$tagid = optional_param('id', 0, PARAM_INT); // tag id
|
||||
$tag_name = optional_param('tag', '', PARAM_TAG); // tag
|
||||
if ($tag_name) {
|
||||
$tag = tag_get_id($tag_name, TAG_RETURN_OBJECT);
|
||||
} elseif ($tagid) {
|
||||
$tag = tag_get_tag_by_id($tagid); // for backward compatibility
|
||||
}
|
||||
$edit = optional_param('edit', -1, PARAM_BOOL);
|
||||
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
|
||||
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
|
||||
$perpage = optional_param('perpage', 24, PARAM_INT);
|
||||
|
||||
$tag = tag_by_id($tagid);
|
||||
|
||||
if (!$tag) {
|
||||
if (!isset($tag) || !$tag->id) {
|
||||
redirect($CFG->wwwroot.'/tag/search.php');
|
||||
}
|
||||
|
||||
@ -32,10 +36,8 @@ if (($edit != -1) and $PAGE->user_allowed_editing()) {
|
||||
$USER->editing = $edit;
|
||||
}
|
||||
|
||||
|
||||
$PAGE->print_header();
|
||||
|
||||
|
||||
echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
|
||||
echo '<tr valign="top">';
|
||||
|
||||
@ -49,8 +51,6 @@ if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------- middle column -----------------
|
||||
|
||||
echo '<td valign="top" id="middle-column">';
|
||||
@ -59,17 +59,14 @@ $tagname = tag_display_name($tag);
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
|
||||
$tagname = '<span class="flagged-tag">' . $tagname . '</span>';
|
||||
$tagname = '<span class="flagged-tag">' . rawurlencode($tagname) . '</span>';
|
||||
}
|
||||
|
||||
print_heading($tagname, '', 2, 'headingblock header tag-heading');
|
||||
tag_print_management_box($tag);
|
||||
tag_print_description_box($tag);
|
||||
|
||||
print_tag_management_box($tag);
|
||||
|
||||
print_tag_description_box($tag);
|
||||
|
||||
|
||||
$usercount = count_items_tagged_with($tag->id,'user');
|
||||
$usercount = tag_record_count('user', $tag->id);
|
||||
|
||||
if ($usercount > 0) {
|
||||
|
||||
@ -82,16 +79,10 @@ if ($usercount > 0) {
|
||||
$baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
|
||||
|
||||
print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&', 'userpage');
|
||||
|
||||
print_tagged_users_table($tag, $userpage * $perpage, $perpage);
|
||||
|
||||
tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
|
||||
print_box_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Print last 10 blogs
|
||||
|
||||
// I was not able to use get_items_tagged_with() because it automatically
|
||||
|
118
tag/manage.php
118
tag/manage.php
@ -35,7 +35,7 @@ $notice = '';
|
||||
|
||||
// get all the possible tag types from db
|
||||
$existing_tagtypes = array();
|
||||
if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype), id FROM {$CFG->prefix}tag")) {
|
||||
if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype) FROM {$CFG->prefix}tag")) {
|
||||
foreach ($ptypes as $ptype) {
|
||||
$existing_tagtypes[$ptype->tagtype] = $ptype->tagtype;
|
||||
}
|
||||
@ -49,11 +49,9 @@ switch($action) {
|
||||
if (!data_submitted() or !confirm_sesskey()) {
|
||||
break;
|
||||
}
|
||||
$str_tagschecked = tag_name_from_string(implode($tagschecked, ','));
|
||||
$str_tagschecked = str_replace(',', ', ', $str_tagschecked);
|
||||
|
||||
tag_delete(implode($tagschecked, ','));
|
||||
|
||||
|
||||
$str_tagschecked = implode(', ', tag_get_name($tagschecked));
|
||||
tag_delete($tagschecked);
|
||||
$notice = $str_tagschecked.' -- '.get_string('deleted','tag');
|
||||
break;
|
||||
|
||||
@ -61,12 +59,9 @@ switch($action) {
|
||||
if (!data_submitted() or !confirm_sesskey()) {
|
||||
break;
|
||||
}
|
||||
$str_tagschecked = tag_name_from_string(implode($tagschecked, ','));
|
||||
$str_tagschecked = str_replace(',', ', ', $str_tagschecked);
|
||||
|
||||
tag_flag_reset(implode($tagschecked, ','));
|
||||
|
||||
$notice = $str_tagschecked.' -- '.get_string('reset','tag');
|
||||
$str_tagschecked = implode(', ', tag_get_name($tagschecked));
|
||||
tag_unset_flag($tagschecked);
|
||||
$notice = $str_tagschecked .' -- '. get_string('reset', 'tag');
|
||||
break;
|
||||
|
||||
case 'changetype':
|
||||
@ -75,7 +70,6 @@ switch($action) {
|
||||
}
|
||||
|
||||
$changed = array();
|
||||
|
||||
foreach ($tagschecked as $tag_id) {
|
||||
if (!array_key_exists($tagtypes[$tag_id], $existing_tagtypes)) {
|
||||
//can not add new types here!!
|
||||
@ -83,19 +77,14 @@ switch($action) {
|
||||
}
|
||||
|
||||
// update tag type;
|
||||
$tag = tag_by_id($tag_id);
|
||||
$tag->timemodified = time();
|
||||
$tag->tagtype = $tagtypes[$tag_id];
|
||||
|
||||
if (update_record('tag', $tag)) {
|
||||
if (tag_type_set($tag_id, $tagtypes[$tag_id])) {
|
||||
$changed[] = $tag_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed) {
|
||||
$str_changed = tag_name_from_string(implode($changed, ','));
|
||||
$str_changed = str_replace(',', ', ', $str_changed);
|
||||
$notice = $str_changed.' -- '.get_string('typechanged','tag');
|
||||
if (!empty($changed)) {
|
||||
$str_changed = implode(', ', tag_get_name($changed));
|
||||
$notice = $str_changed .' -- '. get_string('typechanged','tag');
|
||||
}
|
||||
break;
|
||||
|
||||
@ -103,12 +92,12 @@ switch($action) {
|
||||
if (!data_submitted() or !confirm_sesskey()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$tags_names_changed = array();
|
||||
|
||||
foreach ($tagschecked as $tag_id) {
|
||||
if ($newnames[$tag_id] != '') {
|
||||
if (tag_exists($newnames[$tag_id])) {
|
||||
if (! $tags_names_updated[] = tag_rename($tag_id, $newnames[$tag_id]) ) {
|
||||
// if tag already exists, or is not a valid tag name, etc.
|
||||
$err_notice .= $newnames[$tag_id]. '-- ' . get_string('namesalreadybeeingused','tag').'<br />';
|
||||
} else {
|
||||
$tags_names_changed[$tag_id] = $newnames[$tag_id];
|
||||
@ -116,14 +105,25 @@ switch($action) {
|
||||
}
|
||||
}
|
||||
|
||||
$tags_names_updated = tag_update_name($tags_names_changed);
|
||||
|
||||
//notice to inform what tags had their names effectively updated
|
||||
if ($tags_names_updated){
|
||||
$notice = implode($tags_names_updated, ', ');
|
||||
if ($tags_names_changed){
|
||||
$notice = implode($tags_names_changed, ', ');
|
||||
$notice .= ' -- ' . get_string('updated','tag');
|
||||
}
|
||||
break;
|
||||
case 'addofficialtag':
|
||||
$new_otags = explode(',', optional_param('otagsadd', '', PARAM_TAG));
|
||||
$notice = '';
|
||||
foreach ( $new_otags as $new_otag ) {
|
||||
if ( $new_otag_id = tag_get_id($new_otag) ) {
|
||||
// tag exists, change the type
|
||||
tag_set_type($new_otag_id, 'official');
|
||||
} else {
|
||||
tag_add($new_otag, 'official');
|
||||
}
|
||||
$notice .= get_string('addedotag', 'tag', $new_otag) .' ';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<br/>';
|
||||
@ -132,18 +132,27 @@ if ($err_notice) {
|
||||
notify($err_notice, 'red');
|
||||
}
|
||||
if ($notice) {
|
||||
notify($notice , 'green');
|
||||
notify($notice, 'green');
|
||||
}
|
||||
|
||||
// small form to add an official tag
|
||||
print('<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php">');
|
||||
print('<input type="hidden" name="action" value="addofficialtag">');
|
||||
print('<div class="tag-management-form generalbox"><label class="accesshide" for="id_otagsadd">'. get_string('addotags', 'tag') .'</label>'.
|
||||
'<input name="otagsadd" id="id_otagsadd" type="text">'.
|
||||
'<input name="addotags" value="'. get_string('addotags', 'tag') .'" onclick="skipClientValidation = true;" id="id_addotags" type="submit">'.
|
||||
'</div>');
|
||||
print('</form>');
|
||||
|
||||
//setup table
|
||||
|
||||
$tablecolumns = array('id','name', 'fullname', 'count', 'flag', 'timemodified', 'rawname', 'tagtype', '');
|
||||
$tableheaders = array(get_string('id' , 'tag'),
|
||||
get_string('name' , 'tag'),
|
||||
get_string('owner','tag'),
|
||||
get_string('count','tag'),
|
||||
get_string('flag','tag'),
|
||||
get_string('timemodified','tag'),
|
||||
$tablecolumns = array('id', 'name', 'fullname', 'count', 'flag', 'timemodified', 'rawname', 'tagtype', '');
|
||||
$tableheaders = array(get_string('id', 'tag'),
|
||||
get_string('name', 'tag'),
|
||||
get_string('owner', 'tag'),
|
||||
get_string('count', 'tag'),
|
||||
get_string('flag', 'tag'),
|
||||
get_string('timemodified', 'tag'),
|
||||
get_string('newname', 'tag'),
|
||||
get_string('tagtype', 'tag'),
|
||||
get_string('select', 'tag'));
|
||||
@ -174,36 +183,29 @@ TABLE_VAR_PAGE => 'spage'
|
||||
$table->setup();
|
||||
|
||||
if ($table->get_sql_sort()) {
|
||||
$sort = ' ORDER BY '.$table->get_sql_sort();
|
||||
$sort = 'ORDER BY '. $table->get_sql_sort();
|
||||
} else {
|
||||
$sort = '';
|
||||
}
|
||||
|
||||
if ($table->get_sql_where()) {
|
||||
$where = 'WHERE '.$table->get_sql_where();
|
||||
$where = 'WHERE '. $table->get_sql_where();
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT tg.id, tg.name, tg.rawname, tg.tagtype, COUNT(ti.id) AS count, u.id AS owner, tg.flag, tg.timemodified, u.firstname, u.lastname
|
||||
FROM {$CFG->prefix}tag_instance ti
|
||||
RIGHT JOIN {$CFG->prefix}tag tg ON tg.id = ti.tagid
|
||||
LEFT JOIN {$CFG->prefix}user u ON tg.userid = u.id
|
||||
{$where}
|
||||
GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, u.id, tg.flag, tg.timemodified, u.firstname, u.lastname
|
||||
{$sort}";
|
||||
$query = 'SELECT tg.id, tg.name, tg.rawname, tg.tagtype, COUNT(ti.id) AS count, u.id AS owner, tg.flag, tg.timemodified, u.firstname, u.lastname '.
|
||||
'FROM '. $CFG->prefix .'tag_instance ti RIGHT JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid LEFT JOIN '. $CFG->prefix .'user u ON tg.userid = u.id '.
|
||||
$where .' '.
|
||||
'GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, u.id, tg.flag, tg.timemodified, u.firstname, u.lastname '.
|
||||
$sort;
|
||||
|
||||
|
||||
$totalcount = count_records_sql("SELECT COUNT(DISTINCT(tg.id))
|
||||
FROM {$CFG->prefix}tag tg
|
||||
LEFT JOIN {$CFG->prefix}user u ON u.id = tg.userid
|
||||
$where");
|
||||
$totalcount = count_records_sql('SELECT COUNT(DISTINCT(tg.id)) FROM '. $CFG->prefix .'tag tg LEFT JOIN '. $CFG->prefix .'user u ON u.id = tg.userid '. $where);
|
||||
|
||||
$table->initialbars(true); // always initial bars
|
||||
$table->pagesize($perpage, $totalcount);
|
||||
|
||||
echo '<form id="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php"><div>';
|
||||
echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php"><div>';
|
||||
|
||||
//retrieve tags from DB
|
||||
if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get_page_size())) {
|
||||
@ -211,10 +213,8 @@ if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get
|
||||
$taglist = array_values($tagrecords);
|
||||
|
||||
//print_tag_cloud(array_values(get_records_sql($query)), false);
|
||||
|
||||
//populate table with data
|
||||
foreach ($taglist as $tag ){
|
||||
|
||||
$id = $tag->id;
|
||||
$name = '<a href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'">'. tag_display_name($tag) .'</a>';
|
||||
$owner = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$tag->owner.'">' . fullname($tag) . '</a>';
|
||||
@ -223,7 +223,6 @@ if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get
|
||||
$timemodified = format_time(time() - $tag->timemodified);
|
||||
$checkbox = '<input type="checkbox" name="tagschecked[]" value="'.$tag->id.'" />';
|
||||
$text = '<input type="text" name="newname['.$tag->id.']" />';
|
||||
|
||||
$tagtype = choose_from_menu($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, '', '', '0', true);
|
||||
|
||||
//if the tag if flagged, highlight it
|
||||
@ -242,7 +241,6 @@ if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get
|
||||
$table->add_data($data);
|
||||
}
|
||||
|
||||
|
||||
echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
|
||||
echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" /> ';
|
||||
@ -256,18 +254,16 @@ if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get
|
||||
</select>';
|
||||
|
||||
echo '<button id="tag-management-submit" type="submit">'. get_string('ok') .'</button>';
|
||||
|
||||
}
|
||||
|
||||
$table->print_html();
|
||||
|
||||
echo '</div></form>';
|
||||
|
||||
if ($perpage == SHOW_ALL_PAGE_SIZE) {
|
||||
echo '<div id="showall"><a href="'.$baseurl.'&perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
|
||||
echo '<div id="showall"><a href="'. $baseurl .'&perpage='. DEFAULT_PAGE_SIZE .'">'. get_string('showperpage', '', DEFAULT_PAGE_SIZE) .'</a></div>';
|
||||
|
||||
} else if ($totalcount > 0 and $perpage < $totalcount) {
|
||||
echo '<div id="showall"><a href="'.$baseurl.'&perpage='.SHOW_ALL_PAGE_SIZE.'">'.get_string('showall', '', $totalcount).'</a></div>';
|
||||
echo '<div id="showall"><a href="'. $baseurl .'&perpage='. SHOW_ALL_PAGE_SIZE .'">'. get_string('showall', '', $totalcount) .'</a></div>';
|
||||
}
|
||||
|
||||
echo '<br/>';
|
||||
|
@ -20,24 +20,24 @@ $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwro
|
||||
$navigation = build_navigation($navlinks);
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$manage_link = ' ';
|
||||
if ( has_capability('moodle/tag:manage',$systemcontext) ) {
|
||||
$manage_link = "<a href=\"{$CFG->wwwroot}/tag/manage.php\">" . get_string('managetags', 'tag') . "</a>" ;
|
||||
}
|
||||
|
||||
print_header_simple(get_string('tags', 'tag'), '', $navigation, '', '', '', $manage_link);
|
||||
|
||||
print_heading(get_string('searchtags', 'tag'), '', 2);
|
||||
|
||||
print_tag_search_box();
|
||||
tag_print_search_box();
|
||||
|
||||
if(!empty($query)) {
|
||||
print_tag_search_results($query, $page, $perpage);
|
||||
tag_print_search_results($query, $page, $perpage);
|
||||
}
|
||||
|
||||
echo '<br/><br/>';
|
||||
|
||||
print_box_start('generalbox', 'big-tag-cloud-box');
|
||||
print_tag_cloud(popular_tags_count(150), false, 170,70);
|
||||
tag_print_cloud(150, false, 170,70);
|
||||
print_box_end();
|
||||
|
||||
print_footer();
|
||||
|
@ -2971,7 +2971,7 @@ table#tag-management-list tr td{
|
||||
padding-right :4px;
|
||||
}
|
||||
|
||||
form#tag-management-form {
|
||||
.tag-management-form {
|
||||
text-align:center;
|
||||
}
|
||||
/* tag management end*/
|
||||
|
@ -61,7 +61,7 @@
|
||||
//user interests separated by commas
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
$user->interests = tag_names_csv(get_item_tags('user',$id));
|
||||
$user->interests = html_entity_decode(tag_get_tags_csv(array('type'=>'user','id'=>$id), TAG_RETURN_TEXT)); // formslib uses htmlentities itself
|
||||
}
|
||||
|
||||
//create form
|
||||
|
@ -54,8 +54,8 @@ function useredit_update_trackforums($user, $usernew) {
|
||||
}
|
||||
}
|
||||
|
||||
function useredit_update_interests($user, $cvs_tag_names) {
|
||||
update_item_tags('user', $user->id, $cvs_tag_names);
|
||||
function useredit_update_interests($user, $csv_tag_names) {
|
||||
tag_set('user', $user->id, explode(',', $csv_tag_names));
|
||||
}
|
||||
|
||||
function useredit_shared_definition(&$mform) {
|
||||
|
27
user/tag.php
27
user/tag.php
@ -4,7 +4,9 @@ require_once('../config.php');
|
||||
require_once('../tag/lib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$tag = optional_param('tag', '', PARAM_TAG);
|
||||
|
||||
require_login();
|
||||
|
||||
if (empty($CFG->usetags)) {
|
||||
@ -22,29 +24,20 @@ if (!confirm_sesskey()) {
|
||||
|
||||
switch ($action) {
|
||||
case 'addinterest':
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$name = optional_param('name', '', PARAM_TEXT);
|
||||
if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
|
||||
$tag = tag_get_name($id);
|
||||
}
|
||||
|
||||
if (empty($name) && $id) {
|
||||
$name = tag_name($id);
|
||||
}
|
||||
tag_set_add('user', $USER->id, $tag);
|
||||
|
||||
tag_an_item('user',$USER->id, $name);
|
||||
|
||||
if (!empty($name) && !$id) {
|
||||
$id = tag_id(tag_normalize($name));
|
||||
}
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?id='.$id);
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
|
||||
break;
|
||||
|
||||
case 'flaginappropriate':
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
tag_set_flag(tag_get_id($tag));
|
||||
|
||||
tag_flag_inappropriate($id);
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?id='.$id, get_string('responsiblewillbenotified','tag'));
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -381,12 +381,8 @@
|
||||
|
||||
/// Printing Interests
|
||||
if( !empty($CFG->usetags)) {
|
||||
$interests = get_item_tags('user', $user->id);
|
||||
|
||||
$instereststr = tag_links_csv($interests);
|
||||
|
||||
if ($interests) {
|
||||
print_row(get_string('interests').": ",rtrim($instereststr));
|
||||
if ( $interests = tag_get_tags_csv(array('type'=>'user', 'id'=>$user->id)) ) {
|
||||
print_row(get_string('interests') .": ", $interests);
|
||||
}
|
||||
}
|
||||
/// End of Printing Interests
|
||||
|
Loading…
x
Reference in New Issue
Block a user