mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
fix for MDL-7099, do not share user tags (better interface, now using a new text
field with comma separated value). Prevented the same text for both official and personal tag (tag text is unique). Fixed capability check for removing personal tags. Changed GUI so that new personal tags will be picked up from the text field.
This commit is contained in:
parent
29ca8b882d
commit
91e568534e
@ -109,19 +109,38 @@
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<select name="ptags[]" multiple="multiple" size="8">
|
||||
<?php
|
||||
$ptags = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'personal\' ORDER by text ASC');
|
||||
foreach ($ptags as $ptag) {
|
||||
if (in_array($ptag->id, $usedtags)) {
|
||||
echo '<option value="'.$ptag->id.'" selected="selected">'.$ptag->text.'</option>';
|
||||
} else {
|
||||
echo '<option value="'.$ptag->id.'">'.$ptag->text.'</option>';
|
||||
if (!empty($post->id)) {
|
||||
$idsql = " AND bti.entryid = {$post->id}";
|
||||
} else {
|
||||
$idsql = " AND bti.entryid = 0";
|
||||
}
|
||||
|
||||
$pptag = '';
|
||||
if ($ptags = get_records_sql("SELECT t.* FROM
|
||||
{$CFG->prefix}tags t,
|
||||
{$CFG->prefix}blog_tag_instance bti
|
||||
WHERE t.id = bti.tagid
|
||||
AND t.type = 'personal'
|
||||
$idsql")) {
|
||||
|
||||
foreach ($ptags as $ptag) {
|
||||
$pptag .= $ptag->text.',';
|
||||
}
|
||||
$pptag = rtrim($pptag, ",");
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<input type="text" name="ptags" value="<?php echo $pptag;?>"/>
|
||||
<?php
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
// only make sense to link if the user has capablity
|
||||
if (has_capability('moodle/blog:managepersonaltags', $sitecontext) || has_capability('moodle/blog:manageofficialtags', $sitecontext)) {
|
||||
echo "<br/>";
|
||||
link_to_popup_window("/blog/tags.php",'popup',get_string('tagmanagement'));
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php link_to_popup_window("/blog/tags.php",'popup',get_string('tagmanagement')); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -52,7 +52,7 @@ $post = new object(); // editing form data
|
||||
$usehtmleditor = can_use_richtext_editor();
|
||||
$strblogs = get_string('blogs','blog');
|
||||
|
||||
|
||||
/// Main switch for processing blog entry
|
||||
switch ($action) {
|
||||
|
||||
case 'add':
|
||||
@ -143,7 +143,6 @@ print_footer();
|
||||
|
||||
die;
|
||||
|
||||
|
||||
/***************************** edit.php functions ***************************/
|
||||
/*
|
||||
* Delete blog post from database
|
||||
@ -192,7 +191,6 @@ function do_add(&$post, &$errors) {
|
||||
$post->lastmodified = time();
|
||||
$post->created = time();
|
||||
|
||||
|
||||
// Insert the new blog entry.
|
||||
if ($id = insert_record('post', $post)) {
|
||||
$post->id = $id;
|
||||
@ -239,7 +237,9 @@ function do_edit(&$post, &$errors) {
|
||||
|
||||
// update record
|
||||
if (update_record('post', $post)) {
|
||||
// delete all tags associated with this entry
|
||||
delete_records('blog_tag_instance', 'entryid', $post->id);
|
||||
// add them back
|
||||
add_tags_info($post->id);
|
||||
add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);
|
||||
|
||||
@ -249,26 +249,50 @@ function do_edit(&$post, &$errors) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* function to attach tags into a post
|
||||
* @param int postid - id of the blog
|
||||
*/
|
||||
function add_tags_info($postid) {
|
||||
|
||||
global $USER;
|
||||
|
||||
$post = get_record('post', 'id', $postid);
|
||||
|
||||
$tag = new object();
|
||||
$tag->entryid = $post->id;
|
||||
$tag->userid = $post->userid;
|
||||
$tag->timemodified = time();
|
||||
$tag->timemodified = time();
|
||||
|
||||
/// Add tags information
|
||||
if ($otags = optional_param('otags','', PARAM_INT)) {
|
||||
foreach ($otags as $otag) {
|
||||
$tag->tagid = $otag;
|
||||
/// Attach official tags
|
||||
if ($otags = optional_param('otags','', PARAM_INT)) {
|
||||
foreach ($otags as $otag) {
|
||||
$tag->tagid = $otag;
|
||||
insert_record('blog_tag_instance', $tag);
|
||||
}
|
||||
}
|
||||
|
||||
if ($ptags = optional_param('ptags','', PARAM_INT)) {
|
||||
/// Attach Personal Tags
|
||||
if ($ptags = optional_param('ptags','', PARAM_NOTAGS)) {
|
||||
$ptags = explode(',',$ptags);
|
||||
foreach ($ptags as $ptag) {
|
||||
$tag->tagid = $ptag;
|
||||
insert_record('blog_tag_instance', $tag);
|
||||
$ptag = trim($ptag);
|
||||
// check for existance
|
||||
// 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 = get_record('tags', 'text', $ptag)) {
|
||||
$tag->tagid = $ctag->id;
|
||||
insert_record('blog_tag_instance', $tag);
|
||||
} else { // create a personal tag
|
||||
$ctag = new object;
|
||||
$ctag->userid = $USER->id;
|
||||
$ctag->text = $ptag;
|
||||
$ctag->type = 'personal';
|
||||
if ($tagid = insert_record('tags', $ctag)) {
|
||||
$tag->tagid = $tagid;
|
||||
insert_record('blog_tag_instance', $tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ print_heading(get_string('tagmanagement'));
|
||||
<?php
|
||||
|
||||
$ptags = array();
|
||||
|
||||
|
||||
// Not sure if this sowring is needed anymore
|
||||
if (!empty($ptags1)) { // user's own tag exists
|
||||
if (!empty($ptags2)) { // user's own tags, and other users tags exist, we merge
|
||||
$ptags = array_merge($ptags1, $ptags2);
|
||||
@ -87,13 +88,6 @@ print_heading(get_string('tagmanagement'));
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<form action="tags.php" method="POST">
|
||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
||||
<?php print_string('addptags','blog');?><br/>
|
||||
<input type="text" name="ptag" />
|
||||
<input type="submit" value="<?php print_string('add');?>" />
|
||||
<input type="hidden" name="action" value="addpersonal" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
require_once('../config.php');
|
||||
|
||||
/// main switch for form processing to perform, add/delete etc
|
||||
$action = optional_param('action','',PARAM_ALPHA);
|
||||
|
||||
require_login();
|
||||
|
||||
/// blogs could be disabled altogether
|
||||
if (empty($CFG->bloglevel)) {
|
||||
error('Blogging is disabled!');
|
||||
}
|
||||
@ -13,29 +15,44 @@ if (isguest()) {
|
||||
error(get_string('noguestpost', 'blog'));
|
||||
}
|
||||
|
||||
/// blogs are site level
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
|
||||
$error = '';
|
||||
|
||||
switch ($action) {
|
||||
/// Adding an official tag from submitted value
|
||||
case 'addofficial':
|
||||
// only approved uses can add official tags
|
||||
// Double check to make sure user has capability
|
||||
if (!has_capability('moodle/blog:manageofficialtags', $sitecontext)) {
|
||||
error('Can not add official tags tags');
|
||||
}
|
||||
if (data_submitted() and confirm_sesskey()) {
|
||||
|
||||
$otag = trim(required_param('otag', PARAM_NOTAGS));
|
||||
// When adding ofical tag, we see if there's already a personal tag
|
||||
// With the same Name, if there is, we just change the type
|
||||
if ($tag = get_record('tags', 'text', $otag)) {
|
||||
if ($tag->type == 'official') {
|
||||
// official tag already exist
|
||||
$error = get_string('tagalready');
|
||||
break;
|
||||
} else {
|
||||
$tag->type = 'official';
|
||||
update_record('tags', $tag);
|
||||
$tagid = $tag->id;
|
||||
}
|
||||
|
||||
} else { // Brand new offical tag
|
||||
|
||||
if (get_record('tags', 'text', $otag)) {
|
||||
$error = get_string('tagalready');
|
||||
break;
|
||||
}
|
||||
$tag = new object();
|
||||
$tag->userid = $USER->id;
|
||||
$tag->text = $otag;
|
||||
$tag->type = 'official';
|
||||
if (!$tagid = insert_record('tags', $tag)) {
|
||||
error('Can not create tag!');
|
||||
$tag = new object();
|
||||
$tag->userid = $USER->id;
|
||||
$tag->text = $otag;
|
||||
$tag->type = 'official';
|
||||
|
||||
if (!$tagid = insert_record('tags', $tag)) {
|
||||
error('Can not create tag!');
|
||||
}
|
||||
}
|
||||
|
||||
/// Write newly added tags back into window opener.
|
||||
@ -48,41 +65,10 @@ switch ($action) {
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'addpersonal':
|
||||
/// Everyone can add personal tags as long as they can write blog entries.
|
||||
if (!has_capability('moodle/blog:manageofficialtags', $sitecontext)
|
||||
and !has_capability('moodle/blog:create', $sitecontext)) {
|
||||
error('Can not add personal tags');
|
||||
}
|
||||
if (data_submitted() and confirm_sesskey()) {
|
||||
$ptag = trim(required_param('ptag', PARAM_NOTAGS));
|
||||
|
||||
if (get_record('tags', 'text', $ptag)) {
|
||||
$error = get_string('tagalready');
|
||||
break;
|
||||
}
|
||||
$tag = new object();
|
||||
$tag->userid = $USER->id;
|
||||
$tag->text = $ptag;
|
||||
$tag->type = 'personal';
|
||||
if (!$tagid = insert_record('tags', $tag)) {
|
||||
error('Can not create tag!');
|
||||
}
|
||||
|
||||
/// Write newly added tags back into window opener.
|
||||
echo '<script language="JavaScript" type="text/javascript">
|
||||
var o = opener.document.createElement("option");
|
||||
o.innerHTML = "<option>'.$tag->text.'</option>";
|
||||
o.value = '.$tagid.';
|
||||
opener.document.entry[\'ptags[]\'].insertBefore(o, null);
|
||||
</script>';
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
/// Deletes a tag.
|
||||
case 'delete':
|
||||
/// Delete a tag.
|
||||
|
||||
if (data_submitted() and confirm_sesskey()) {
|
||||
$tagids = optional_param('tags', array(), PARAM_INT);
|
||||
|
||||
@ -103,19 +89,17 @@ switch ($action) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($tag->type == 'personal') {
|
||||
if (has_capability('moodle/blog:managepersonaltags', $sitecontext)) {
|
||||
//ok - can delete any personal tag
|
||||
} else if (!has_capability('moodle/blog:create', $sitecontext) or $USER->id != $tag->userid) {
|
||||
// no delete - you must own the tag and be able to create blog entries
|
||||
continue;
|
||||
}
|
||||
if ($tag->type == 'personal' and !has_capability('moodle/blog:managepersonaltags', $sitecontext)) {
|
||||
//can not delete
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Delete the tag itself
|
||||
if (!delete_records('tags', 'id', $tagid)) {
|
||||
error('Can not delete tag');
|
||||
}
|
||||
|
||||
// Deleteing all references to this tag
|
||||
if (!delete_records('blog_tag_instance', 'tagid', $tagid)) {
|
||||
error('Can not delete blog tag instances');
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ $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';
|
||||
$string['ptags'] = 'User defined tags (Comma separated)';
|
||||
$string['publishto'] = 'Publish to';
|
||||
$string['publishtonoone'] = 'Yourself (draft)';
|
||||
$string['publishtosite'] = 'Anyone on this site';
|
||||
|
Loading…
x
Reference in New Issue
Block a user