Commit 8cc4aaee authored by Dries's avatar Dries

- Patch #258171 by Senpai: code cleanup.

parent 11aeff60
......@@ -2,7 +2,7 @@
// $Id$
/**
* @file comment-folded.tpl.php
* @file
* Default theme implementation for folded comments.
*
* Available variables:
......
......@@ -2,7 +2,7 @@
// $Id$
/**
* @file comment-wrapper.tpl.php
* @file
* Default theme implementation to wrap comments.
*
* Available variables:
......
......@@ -26,7 +26,7 @@ function comment_admin($type = 'new') {
* @param $type
* Not used.
* @param $arg
* Current path's fourth component deciding the form type (Published comments/Approval queue)
* Current path's fourth component deciding the form type (Published comments/Approval queue).
* @return
* The form structure.
* @ingroup forms
......@@ -35,53 +35,79 @@ function comment_admin($type = 'new') {
* @see theme_comment_admin_overview()
*/
function comment_admin_overview($type = 'new', $arg) {
// build an 'Update options' form
// Build an 'Update options' form.
$form['options'] = array(
'#type' => 'fieldset', '#title' => t('Update options'),
'#prefix' => '<div class="container-inline">', '#suffix' => '</div>'
'#type' => 'fieldset',
'#title' => t('Update options'),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$options = array();
foreach (comment_operations($arg == 'approval' ? 'publish' : 'unpublish') as $key => $value) {
$options[$key] = $value[0];
}
$form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'publish');
$form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
$form['options']['operation'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => 'publish',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
// load the comments that we want to display
// Load the comments that need to be displayed.
$status = ($arg == 'approval') ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED;
$form['header'] = array('#type' => 'value', '#value' => array(
theme('table_select_header_cell'),
array('data' => t('Subject'), 'field' => 'subject'),
array('data' => t('Author'), 'field' => 'name'),
array('data' => t('Posted in'), 'field' => 'node_title'),
array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'),
array('data' => t('Operations'))
$form['header'] = array(
'#type' => 'value',
'#value' => array(
theme('table_select_header_cell'),
array('data' => t('Subject'), 'field' => 'subject'),
array('data' => t('Author'), 'field' => 'name'),
array('data' => t('Posted in'), 'field' => 'node_title'),
array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'),
array('data' => t('Operations')),
));
$result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, n.title as node_title FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.status = %d' . tablesort_sql($form['header']['#value']), 50, 0, NULL, $status);
// build a table listing the appropriate comments
// Build a table listing the appropriate comments.
$destination = drupal_get_destination();
while ($comment = db_fetch_object($result)) {
$comments[$comment->cid] = '';
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$form['subject'][$comment->cid] = array('#value' => l($comment->subject, 'node/' . $comment->nid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid)));
$form['username'][$comment->cid] = array('#value' => theme('username', $comment));
$form['node_title'][$comment->cid] = array('#value' => l($comment->node_title, 'node/' . $comment->nid));
$form['timestamp'][$comment->cid] = array('#value' => format_date($comment->timestamp, 'small'));
$form['operations'][$comment->cid] = array('#value' => l(t('edit'), 'comment/edit/' . $comment->cid, array('query' => $destination)));
$form['subject'][$comment->cid] = array(
'#value' => l($comment->subject, 'node/' . $comment->nid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-' . $comment->cid))
);
$form['username'][$comment->cid] = array(
'#value' => theme('username', $comment)
);
$form['node_title'][$comment->cid] = array(
'#value' => l($comment->node_title, 'node/' . $comment->nid)
);
$form['timestamp'][$comment->cid] = array(
'#value' => format_date($comment->timestamp, 'small')
);
$form['operations'][$comment->cid] = array(
'#value' => l(t('edit'), 'comment/edit/' . $comment->cid, array('query' => $destination))
);
}
$form['comments'] = array('#type' => 'checkboxes', '#options' => isset($comments) ? $comments: array());
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
$form['comments'] = array(
'#type' => 'checkboxes',
'#options' => isset($comments) ? $comments: array()
);
$form['pager'] = array(
'#value' => theme('pager', NULL, 50, 0)
);
return $form;
}
/**
* Validate comment_admin_overview form submissions.
*
* We can't execute any 'Update options' if no comments were selected.
*/
function comment_admin_overview_validate($form, &$form_state) {
$form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
// We can't execute any 'Update options' if no comments were selected.
if (count($form_state['values']['comments']) == 0) {
form_set_error('', t('Please select one or more comments to perform the update on.'));
drupal_goto('admin/content/comment');
......@@ -97,11 +123,11 @@ function comment_admin_overview_validate($form, &$form_state) {
function comment_admin_overview_submit($form, &$form_state) {
$operations = comment_operations();
if ($operations[$form_state['values']['operation']][1]) {
// extract the appropriate database query operation
// Extract the appropriate database query operation.
$query = $operations[$form_state['values']['operation']][1];
foreach ($form_state['values']['comments'] as $cid => $value) {
if ($value) {
// perform the update action, then refresh node statistics
// Perform the update action, then refresh node statistics.
db_query($query, $cid);
$comment = comment_load($cid);
_comment_update_node_statistics($comment->nid);
......@@ -153,8 +179,7 @@ function theme_comment_admin_overview($form) {
}
/**
* List the selected comments and verify that the admin really wants to delete
* them.
* List the selected comments and verify that the admin wants to delete them.
*
* @param $form_state
* An associative array containing the current state of the form.
......@@ -166,8 +191,12 @@ function theme_comment_admin_overview($form) {
function comment_multiple_delete_confirm(&$form_state) {
$edit = $form_state['post'];
$form['comments'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
// array_filter() returns only elements with actual values
$form['comments'] = array(
'#prefix' => '<ul>',
'#suffix' => '</ul>',
'#tree' => TRUE,
);
// array_filter() returns only elements with actual values.
$comment_counter = 0;
foreach (array_filter($edit['comments']) as $cid => $value) {
$comment = comment_load($cid);
......@@ -180,7 +209,7 @@ function comment_multiple_delete_confirm(&$form_state) {
$form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
if (!$comment_counter) {
drupal_set_message(t('There do not appear to be any comments to delete or your selected comment was deleted by another administrator.'));
drupal_set_message(t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
drupal_goto('admin/content/comment');
}
else {
......@@ -193,13 +222,12 @@ function comment_multiple_delete_confirm(&$form_state) {
/**
* Process comment_multiple_delete_confirm form submissions.
*
* Perform the actual comment deletion.
*/
function comment_multiple_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
foreach ($form_state['values']['comments'] as $cid => $value) {
$comment = comment_load($cid);
// Perform the actual comment deletion.
_comment_delete_thread($comment);
_comment_update_node_statistics($comment->nid);
}
......@@ -213,12 +241,11 @@ function comment_multiple_delete_confirm_submit($form, &$form_state) {
* Menu callback; delete a comment.
*
* @param $cid
* The comment do be deleted.
* The comment to be deleted.
*/
function comment_delete($cid = NULL) {
$comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$output = '';
if (is_object($comment) && is_numeric($comment->cid)) {
......@@ -255,14 +282,10 @@ function comment_confirm_delete(&$form_state, $comment) {
*/
function comment_confirm_delete_submit($form, &$form_state) {
drupal_set_message(t('The comment and all its replies have been deleted.'));
$comment = $form['#comment'];
// Delete comment and its replies.
// Delete the comment and its replies.
_comment_delete_thread($comment);
_comment_update_node_statistics($comment->nid);
// Clear the cache so an anonymous user sees that his comment was deleted.
cache_clear_all();
......@@ -278,16 +301,16 @@ function comment_confirm_delete_submit($form, &$form_state) {
function _comment_delete_thread($comment) {
if (!is_object($comment) || !is_numeric($comment->cid)) {
watchdog('content', 'Cannot delete non-existent comment.', array(), WATCHDOG_WARNING);
return;
}
// Delete the comment:
// Delete the comment.
db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject));
comment_invoke_comment($comment, 'delete');
// Delete the comment's replies
// Delete the comment's replies.
$result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
......
; $Id$
name = Comment
description = Allows users to comment on and discuss published content.
package = Core - optional
......
......@@ -13,19 +13,21 @@ function comment_enable() {
* Changed node_comment_statistics to use node->changed to avoid future timestamps.
*/
function comment_update_1() {
// Change any future last comment timestamps to now.
// Change any future last comment timestamps to current time.
db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', time(), time());
// Unstuck node indexing timestamp if needed.
if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
variable_set('node_cron_last', min(time(), $last));
}
return array();
}
function comment_update_6001() {
$ret[] = update_sql("ALTER TABLE {comments} DROP score");
$ret[] = update_sql("ALTER TABLE {comments} DROP users");
return $ret;
}
......@@ -64,6 +66,7 @@ function comment_update_6002() {
function comment_update_6003() {
$ret = array();
db_add_index($ret, 'comments', 'pid', array('pid'));
return $ret;
}
......
// $Id$
Drupal.behaviors.comment = function (context) {
Drupal.behaviors.comment = function(context) {
var parts = new Array("name", "homepage", "mail");
var cookie = '';
for (i=0;i<3;i++) {
......
This diff is collapsed.
......@@ -15,10 +15,10 @@
*/
function comment_edit($cid) {
global $user;
$comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid));
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) {
return comment_form_box((array)$comment);
}
......@@ -52,7 +52,6 @@ function comment_reply($node, $pid = NULL) {
// Set the breadcrumb trail.
drupal_set_breadcrumb(array(l(t('Home'), NULL), l($node->title, 'node/' . $node->nid)));
$op = isset($_POST['op']) ? $_POST['op'] : '';
$output = '';
if (user_access('access comments')) {
......@@ -69,10 +68,10 @@ function comment_reply($node, $pid = NULL) {
else {
// $pid indicates that this is a reply to a comment.
if ($pid) {
// load the comment whose cid = $pid
// Load the comment whose cid = $pid
if ($comment = db_fetch_object(db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = %d', $pid, COMMENT_PUBLISHED))) {
// If that comment exists, make sure that the current comment and the parent comment both
// belong to the same parent node.
// If that comment exists, make sure that the current comment and the
// parent comment both belong to the same parent node.
if ($comment->nid != $node->nid) {
// Attempting to reply to a comment not belonging to the current nid.
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
......
......@@ -207,26 +207,30 @@ class CommentTestCase extends DrupalWebTestCase {
$edit = array();
$edit['subject'] = $subject;
$edit['comment'] = $comment;
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
if ($node !== NULL) {
$this->drupalGet('comment/reply/'. $node->nid);
}
if ($preview) {
$this->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found.
$this->drupalPost(NULL, $edit, t('Preview'));
}
$this->drupalPost(NULL, $edit, t('Save'));
$match = array();
// Get comment ID
preg_match('/#comment-([^"]+)/', $this->getURL(), $match);
// get comment
// Get comment.
if ($contact !== TRUE) { // If true then attempting to find error message.
$this->assertText($subject, 'Comment posted.');
$this->assertTrue((!empty($match) && !empty($match[1])), t('Comment id found.'));
}
if (isset($match[1])) {
return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
}
......@@ -247,6 +251,7 @@ class CommentTestCase extends DrupalWebTestCase {
$regex .= $comment->subject .'(.*?)'; // Match subject.
$regex .= $comment->comment .'(.*?)'; // Match comment.
$regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div.
return preg_match($regex, $this->drupalGetContent());
}
else {
......@@ -257,7 +262,8 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Delete comment.
*
* @param object $comment Comment to delete.
* @param object $comment
* Comment to delete.
*/
function deleteComment($comment) {
$this->drupalPost('comment/delete/'. $comment->id, array(), t('Delete'));
......@@ -267,7 +273,8 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set comment subject setting.
*
* @param boolean $enabled Subject value.
* @param boolean $enabled
* Subject value.
*/
function setCommentSubject($enabled) {
$this->setCommentSettings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject '. ($enabled ? 'enabled' : 'disabled') .'.');
......@@ -276,7 +283,8 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set comment preview setting.
*
* @param boolean $required Preview value.
* @param boolean $required
* Preview value.
*/
function setCommentPreview($required) {
$this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview '. ($required ? 'required' : 'optional') .'.');
......@@ -285,7 +293,8 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set comment form setting.
*
* @param boolean $enabled Form value.
* @param boolean $enabled
* Form value.
*/
function setCommentForm($enabled) {
$this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls '. ($enabled ? 'enabled' : 'disabled') .'.');
......@@ -294,7 +303,8 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set comment anonymous level setting.
*
* @param integer $level Anonymous level.
* @param integer $level
* Anonymous level.
*/
function setCommentAnonymous($level) {
$this->setCommentSettings('comment_anonymous', $level, 'Anonymous commenting set to level '. $level .'.');
......@@ -303,9 +313,12 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set comment setting for story content type.
*
* @param string $name Name of variable.
* @param string $vale Value of variable.
* @param string $message Status message to display.
* @param string $name
* Name of variable.
* @param string $value
* Value of variable.
* @param string $message
* Status message to display.
*/
function setCommentSettings($name, $value, $message) {
variable_set($name .'_story', $value);
......@@ -315,8 +328,10 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Set anonymous comment setting.
*
* @param boolean $enabled Allow anonymous commenting.
* @param boolean $without_approval Allow anonymous commenting without approval.
* @param boolean $enabled
* Allow anonymous commenting.
* @param boolean $without_approval
* Allow anonymous commenting without approval.
*/
function setAnonymousUserComment($enabled, $without_approval) {
$edit = array();
......@@ -330,7 +345,7 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Check for contact info.
*
* @return boolean Contact info is avialable.
* @return boolean Contact info is available.
*/
function commentContactInfoAvailable() {
return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent());
......@@ -339,9 +354,12 @@ class CommentTestCase extends DrupalWebTestCase {
/**
* Perform the specified operation on the specified comment.
*
* @param object $comment Comment to perform operation on.
* @param string $operation Operation to perform.
* @param boolean $aproval Operation is found on approval page.
* @param object $comment
* Comment to perform operation on.
* @param string $operation
* Operation to perform.
* @param boolean $aproval
* Operation is found on approval page.
*/
function performCommentOperation($comment, $operation, $approval = FALSE) {
$edit = array();
......@@ -359,14 +377,17 @@ class CommentTestCase extends DrupalWebTestCase {
}
/**
* Get the comment id for an unaproved comment.
* Get the comment ID for an unaproved comment.
*
* @param string $subject Comment subject to find.
* @return integer Comment id.
* @param string $subject
* Comment subject to find.
* @return integer
* Comment id.
*/
function getUnaprovedComment($subject) {
$this->drupalGet('admin/content/comment/approval');
preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>('. $subject .')/', $this->drupalGetContent(), $match);
return $match[2];
}
}
......@@ -2,7 +2,7 @@
// $Id$
/**
* @file comment.tpl.php
* @file
* Default theme implementation for comments.
*
* Available variables:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment