diff --git a/admin/configuration.php b/admin/configuration.php
index bd7858ca8..a0df63190 100644
--- a/admin/configuration.php
+++ b/admin/configuration.php
@@ -69,6 +69,10 @@ $comments_checkboxes = array(
'comments_validation',
'email_admin_on_comment',
'email_admin_on_comment_validation',
+ 'user_can_delete_comment',
+ 'user_can_edit_comment',
+ 'email_admin_on_comment_edition',
+ 'email_admin_on_comment_deletion'
);
//------------------------------ verification and registration of modifications
diff --git a/admin/template/goto/configuration.tpl b/admin/template/goto/configuration.tpl
index 95d2518d4..9f335d36c 100644
--- a/admin/template/goto/configuration.tpl
+++ b/admin/template/goto/configuration.tpl
@@ -143,6 +143,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{/if}
diff --git a/comments.php b/comments.php
index 0c813face..048e8d692 100644
--- a/comments.php
+++ b/comments.php
@@ -26,6 +26,7 @@
// +-----------------------------------------------------------------------+
define('PHPWG_ROOT_PATH','./');
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
+include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok |
@@ -142,14 +143,9 @@ $page['where_clauses'][] = get_sql_condition_FandF
// | comments management |
// +-----------------------------------------------------------------------+
if (isset($_GET['delete']) and is_numeric($_GET['delete'])
- and !is_adviser() )
+ and (is_admin() || $conf['user_can_delete_comment']))
{// comments deletion
- check_status(ACCESS_ADMINISTRATOR);
- $query = '
-DELETE FROM '.COMMENTS_TABLE.'
- WHERE id='.$_GET['delete'].'
-;';
- pwg_query($query);
+ delete_user_comment($_GET['delete']);
}
if (isset($_GET['validate']) and is_numeric($_GET['validate'])
@@ -165,6 +161,25 @@ UPDATE '.COMMENTS_TABLE.'
pwg_query($query);
}
+if (isset($_GET['edit']) and is_numeric($_GET['edit'])
+ and (is_admin() || $conf['user_can_edit_comment']))
+{
+ if (!empty($_POST['content']))
+ {
+ update_user_comment(array('comment_id' => $_GET['edit'],
+ 'image_id' => $_POST['image_id'],
+ 'content' => $_POST['content']),
+ $_POST['key']
+ );
+
+ $edit_comment = null;
+ }
+ else
+ {
+ $edit_comment = $_GET['edit'];
+ }
+}
+
// +-----------------------------------------------------------------------+
// | page header and options |
// +-----------------------------------------------------------------------+
@@ -367,20 +382,40 @@ SELECT id, name, permalink, uppercats
'CONTENT'=>trigger_event('render_comment_content',$comment['content']),
);
- if ( is_admin() )
+ if (can_manage_comment('delete', $comment['author']))
{
- $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate'));
- $tpl_comment['U_DELETE'] = add_url_params($url,
- array('delete'=>$comment['comment_id'])
- );
-
- if ($comment['validated'] != 'true')
+ $url = get_root_url().'comments.php'
+ .get_query_string_diff(array('delete','validate','edit'));
+ $tpl_comment['U_DELETE'] =
+ add_url_params($url,
+ array('delete'=>$comment['comment_id'])
+ );
+ }
+ if (can_manage_comment('edit', $comment['author']))
+ {
+ $url = get_root_url().'comments.php'
+ .get_query_string_diff(array('edit', 'delete','validate'));
+ $tpl_comment['U_EDIT'] =
+ add_url_params($url,
+ array('edit'=>$comment['comment_id'])
+ );
+ if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment))
{
- $tpl_comment['U_VALIDATE'] = add_url_params($url,
- array('validate'=>$comment['comment_id'])
- );
+ $tpl_comment['IN_EDIT'] = true;
+ $key = get_comment_post_key($comment['image_id']);
+ $tpl_comment['KEY'] = $key;
+ $tpl_comment['IMAGE_ID'] = $comment['image_id'];
+ $tpl_comment['CONTENT'] = $comment['content'];
}
}
+
+ if ( is_admin() && $comment['validated'] != 'true')
+ {
+ $tpl_comment['U_VALIDATE'] =
+ add_url_params($url,
+ array('validate'=>$comment['comment_id'])
+ );
+ }
$template->append('comments', $tpl_comment);
}
}
diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php
index c8dd6f3e0..fb421d39b 100644
--- a/include/functions_comment.inc.php
+++ b/include/functions_comment.inc.php
@@ -205,4 +205,134 @@ INSERT INTO '.COMMENTS_TABLE.'
return $comment_action;
}
+/**
+ * Tries to delete a user comment in the database
+ * only admin can delete all comments
+ * other users can delete their own comments
+ * so to avoid a new sql request we add author in where clause
+ *
+ * @param comment_id
+ */
+
+function delete_user_comment($comment_id) {
+ $user_where_clause = '';
+ if (!is_admin())
+ {
+ $user_where_clause = ' AND author = \''.$GLOBALS['user']['username'].'\'';
+ }
+ $query = '
+DELETE FROM '.COMMENTS_TABLE.'
+ WHERE id = '.$comment_id.
+$user_where_clause.'
+;';
+ $result = pwg_query($query);
+ if ($result) {
+ email_admin('delete', array('author' => $GLOBALS['user']['username']));
+ }
+}
+
+/**
+ * Tries to update a user comment in the database
+ * only admin can update all comments
+ * users can edit their own comments if admin allow them
+ * so to avoid a new sql request we add author in where clause
+ *
+ * @param comment_id
+ * @param post_key
+ * @param content
+ */
+
+function update_user_comment($comment, $post_key) {
+ global $conf;
+
+ $comment_action = 'validate';
+
+ $key = explode( ':', $post_key );
+ if ( count($key)!=2
+ or $key[0]>time()-2 // page must have been retrieved more than 2 sec ago
+ or $key[0]