Commit 78601c36 authored by webchick's avatar webchick

#754760 by sun, chx, dmitrig01, manarth, EvanDonovan, derjochenmeyer, joachim:...

#754760 by sun, chx, dmitrig01, manarth, EvanDonovan, derjochenmeyer, joachim: Fixed all possible problems with comment links, using new generatePermutations testing function.
parent 8ae6dc4b
......@@ -611,15 +611,13 @@ function theme_comment_block() {
function comment_node_view($node, $view_mode) {
$links = array();
if ($node->comment) {
if ($node->comment != COMMENT_NODE_HIDDEN) {
if ($view_mode == 'rss') {
if ($node->comment != COMMENT_NODE_HIDDEN) {
// Add a comments RSS element which is a URL to the comments of this node.
$node->rss_elements[] = array(
'key' => 'comments',
'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))
);
}
// Add a comments RSS element which is a URL to the comments of this node.
$node->rss_elements[] = array(
'key' => 'comments',
'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))
);
}
elseif ($view_mode == 'teaser') {
// Teaser view: display the number of comments that have been posted,
......@@ -634,9 +632,8 @@ function comment_node_view($node, $view_mode) {
'fragment' => 'comments',
'html' => TRUE,
);
$new = comment_num_new($node->nid);
if ($new) {
// Show a link to the first new comment.
if ($new = comment_num_new($node->nid)) {
$links['comment-new-comments'] = array(
'title' => format_plural($new, '1 new comment', '@count new comments'),
'href' => "node/$node->nid",
......@@ -647,21 +644,21 @@ function comment_node_view($node, $view_mode) {
);
}
}
}
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$links['comment-add'] = array(
'title' => t('Add new comment'),
'href' => "comment/reply/$node->nid",
'attributes' => array('title' => t('Add a new comment to this page.')),
'fragment' => 'comment-form',
);
}
else {
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$links['comment-add'] = array(
'title' => t('Add new comment'),
'href' => "comment/reply/$node->nid",
'attributes' => array('title' => t('Add a new comment to this page.')),
'fragment' => 'comment-form',
'html' => TRUE,
);
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));
}
}
$links['comment_forbidden'] = array(
'title' => theme('comment_post_forbidden', array('node' => $node)),
'html' => TRUE,
);
}
}
}
......@@ -671,30 +668,31 @@ function comment_node_view($node, $view_mode) {
// But we don't want this link if we're building the node for search
// indexing or constructing a search result excerpt.
if ($node->comment == COMMENT_NODE_OPEN) {
$comment_form_location = variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW);
if (user_access('post comments')) {
$links['comment-add'] = array(
'title' => t('Add new comment'),
'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
'fragment' => 'comment-form',
'html' => TRUE,
);
if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
$links['comment-add']['href'] = "comment/reply/$node->nid";
}
else {
$links['comment-add']['href'] = "node/$node->nid";
// Show the "post comment" link if the form is on another page, or
// if there are existing comments that the link will skip past.
if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE || (!empty($node->comment_count) && user_access('access comments'))) {
$links['comment-add'] = array(
'title' => t('Add new comment'),
'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
'href' => "node/$node->nid",
'fragment' => 'comment-form',
);
if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) {
$links['comment-add']['href'] = "comment/reply/$node->nid";
}
}
}
else {
$links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));
$links['comment_forbidden'] = array(
'title' => theme('comment_post_forbidden', array('node' => $node)),
'html' => TRUE,
);
}
}
}
if (isset($links['comment_forbidden'])) {
$links['comment_forbidden']['html'] = TRUE;
}
$node->content['links']['comment'] = array(
'#theme' => 'links__node__comment',
'#links' => $links,
......@@ -705,7 +703,7 @@ function comment_node_view($node, $view_mode) {
// page. We compare $node and $page_node to ensure that comments are not
// appended to other nodes shown on the page, for example a node_reference
// displayed in 'full' view mode within another node.
if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview) && user_access('access comments')) {
if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
$node->content['comments'] = comment_node_page_additions($node);
}
}
......@@ -723,7 +721,7 @@ function comment_node_page_additions($node) {
// Only attempt to render comments if the node has visible comments.
// Unpublished comments are not included in $node->comment_count, so show
// comments unconditionally if the user is an administrator.
if ($node->comment_count || user_access('administer comments')) {
if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
......@@ -2340,7 +2338,7 @@ function theme_comment_post_forbidden($variables) {
if (!isset($authenticated_post_comments)) {
// We only output a link if we are certain that users will get permission
// to post comments by logging in.
$comment_roles = user_roles(TRUE, 'post comments') + user_roles(TRUE, 'skip comment approval');
$comment_roles = user_roles(TRUE, 'post comments');
$authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
}
......
......@@ -33,26 +33,26 @@ function comment_reply($node, $pid = NULL) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
$build = array();
if (user_access('access comments')) {
// The user is previewing a comment prior to submitting it.
if ($op == t('Preview')) {
if (user_access('post comments')) {
$build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) array('pid' => $pid, 'nid' => $node->nid));
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_goto("node/$node->nid");
}
// The user is previewing a comment prior to submitting it.
if ($op == t('Preview')) {
if (user_access('post comments')) {
$build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) array('pid' => $pid, 'nid' => $node->nid));
}
else {
// $pid indicates that this is a reply to a comment.
if ($pid) {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_goto("node/$node->nid");
}
}
else {
// $pid indicates that this is a reply to a comment.
if ($pid) {
if (user_access('access comments')) {
// Load the comment whose cid = $pid
$comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
':cid' => $pid,
':status' => COMMENT_PUBLISHED,
))->fetchObject();
if ( $comment ) {
if ($comment) {
// 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) {
......@@ -71,29 +71,29 @@ function comment_reply($node, $pid = NULL) {
drupal_goto("node/$node->nid");
}
}
// This is the case where the comment is in response to a node. Display the node.
elseif (user_access('access content')) {
$build['comment_node'] = node_view($node);
}
// Should we show the reply box?
if ($node->comment != COMMENT_NODE_OPEN) {
drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
drupal_goto("node/$node->nid");
}
elseif (user_access('post comments')) {
$edit = array('nid' => $node->nid, 'pid' => $pid);
$build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) $edit);
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_set_message(t('You are not authorized to view comments.'), 'error');
drupal_goto("node/$node->nid");
}
}
}
else {
drupal_set_message(t('You are not authorized to view comments.'), 'error');
drupal_goto("node/$node->nid");
// This is the case where the comment is in response to a node. Display the node.
elseif (user_access('access content')) {
$build['comment_node'] = node_view($node);
}
// Should we show the reply box?
if ($node->comment != COMMENT_NODE_OPEN) {
drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error');
drupal_goto("node/$node->nid");
}
elseif (user_access('post comments')) {
$edit = array('nid' => $node->nid, 'pid' => $pid);
$build['comment_form'] = drupal_get_form("comment_node_{$node->type}_form", (object) $edit);
}
else {
drupal_set_message(t('You are not authorized to post comments.'), 'error');
drupal_goto("node/$node->nid");
}
}
return $build;
......
This diff is collapsed.
......@@ -578,6 +578,55 @@ public static function randomName($length = 8) {
}
return $str;
}
/**
* Converts a list of possible parameters into a stack of permutations.
*
* Takes a list of parameters containing possible values, and converts all of
* them into a list of items containing every possible permutation.
*
* Example:
* @code
* $parameters = array(
* 'one' => array(0, 1),
* 'two' => array(2, 3),
* );
* $permutations = $this->permute($parameters);
* // Result:
* $permutations == array(
* array('one' => 0, 'two' => 2),
* array('one' => 1, 'two' => 2),
* array('one' => 0, 'two' => 3),
* array('one' => 1, 'two' => 3),
* )
* @endcode
*
* @param $parameters
* An associative array of parameters, keyed by parameter name, and whose
* values are arrays of parameter values.
*
* @return
* A list of permutations, which is an array of arrays. Each inner array
* contains the full list of parameters that have been passed, but with a
* single value only.
*/
public static function generatePermutations($parameters) {
$all_permutations = array(array());
foreach ($parameters as $parameter => $values) {
$new_permutations = array();
// Iterate over all values of the parameter.
foreach ($values as $value) {
// Iterate over all existing permutations.
foreach ($all_permutations as $permutation) {
// Add the new parameter value to existing permutations.
$new_permutations[] = $permutation + array($parameter => $value);
}
}
// Replace the old permutations with the new permutations.
$all_permutations = $new_permutations;
}
return $all_permutations;
}
}
/**
......
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