Skip to content

Commit

Permalink
fix(comments): unifies behavior after adding new comment/discussion r…
Browse files Browse the repository at this point in the history
…eply

We forward to either the comment/reply URL or to the activity page if it
was posted from there.

If returning to the activity page, the new comment/reply is jumped to and
highlighted as it would be on the object/topic page.

Fixes #8130
  • Loading branch information
mrclay committed Mar 5, 2016
1 parent 86a1a44 commit 8ff2b29
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
12 changes: 8 additions & 4 deletions actions/comment/save.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
$entity_guid = (int) get_input('entity_guid', 0, false); $entity_guid = (int) get_input('entity_guid', 0, false);
$comment_guid = (int) get_input('comment_guid', 0, false); $comment_guid = (int) get_input('comment_guid', 0, false);
$comment_text = get_input('generic_comment'); $comment_text = get_input('generic_comment');
$is_edit_page = (bool) get_input('is_edit_page', false, false);


if (empty($comment_text)) { if (empty($comment_text)) {
register_error(elgg_echo("generic_comment:blank")); register_error(elgg_echo("generic_comment:blank"));
Expand Down Expand Up @@ -100,8 +99,13 @@
system_message(elgg_echo('generic_comment:posted')); system_message(elgg_echo('generic_comment:posted'));
} }


if ($is_edit_page) { // return to activity page if posted from there
forward($comment->getURL()); if (!empty($_SERVER['HTTP_REFERER'])) {
// don't redirect to URLs from client without verifying within site
$site_url = preg_quote(elgg_get_site_url(), '~');
if (preg_match("~^{$site_url}activity(/|\\z)~", $_SERVER['HTTP_REFERER'], $m)) {
forward("{$m[0]}#elgg-object-{$comment->guid}");
}
} }


forward(REFERER); forward($comment->getURL());
3 changes: 2 additions & 1 deletion mod/aalborg_theme/views/default/elements/components.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@
} }


/* Comment highlighting that automatically fades away */ /* Comment highlighting that automatically fades away */
.elgg-comments .elgg-state-highlight { .elgg-comments .elgg-state-highlight,
.elgg-river-comments .elgg-state-highlight {
-webkit-animation: comment-highlight 5s; /* Chrome, Safari, Opera */ -webkit-animation: comment-highlight 5s; /* Chrome, Safari, Opera */
animation: comment-highlight 5s; animation: comment-highlight 5s;
} }
Expand Down
11 changes: 10 additions & 1 deletion mod/discussions/actions/discussion/reply/save.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@
system_message(elgg_echo('discussion:post:success')); system_message(elgg_echo('discussion:post:success'));
} }


forward(REFERER); // return to activity page if posted from there
if (!empty($_SERVER['HTTP_REFERER'])) {
// don't redirect to URLs from client without verifying within site
$site_url = preg_quote(elgg_get_site_url(), '~');
if (preg_match("~^{$site_url}activity(/|\\z)~", $_SERVER['HTTP_REFERER'], $m)) {
forward("{$m[0]}#elgg-object-{$reply->guid}");
}
}

forward($reply->getURL());
3 changes: 2 additions & 1 deletion views/default/elements/components.css.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
} }


/* Comment highlighting that automatically fades away */ /* Comment highlighting that automatically fades away */
.elgg-comments .elgg-state-highlight { .elgg-comments .elgg-state-highlight,
.elgg-river-comments .elgg-state-highlight {
-webkit-animation: comment-highlight 5s; /* Chrome, Safari, Opera */ -webkit-animation: comment-highlight 5s; /* Chrome, Safari, Opera */
animation: comment-highlight 5s; animation: comment-highlight 5s;
} }
Expand Down
14 changes: 3 additions & 11 deletions views/default/forms/comment/save.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* *
* @package Elgg * @package Elgg
* *
* @uses ElggEntity $vars['entity'] The entity being commented * @uses ElggEntity $vars['entity'] The entity being commented
* @uses ElggComment $vars['comment'] The comment being edited * @uses ElggComment $vars['comment'] The comment being edited
* @uses bool $vars['inline'] Show a single line version of the form? * @uses bool $vars['inline'] Show a single line version of the form?
* @uses bool $vars['is_edit_page'] Is this form on its own page?
*/ */


if (!elgg_is_logged_in()) { if (!elgg_is_logged_in()) {
Expand All @@ -21,7 +20,6 @@
/* @var ElggComment $comment */ /* @var ElggComment $comment */


$inline = elgg_extract('inline', $vars, false); $inline = elgg_extract('inline', $vars, false);
$is_edit_page = elgg_extract('is_edit_page', $vars, false);


$entity_guid_input = ''; $entity_guid_input = '';
if ($entity) { if ($entity) {
Expand Down Expand Up @@ -71,18 +69,12 @@
'required' => true 'required' => true
)); ));


$is_edit_page_input = elgg_view('input/hidden', array(
'name' => 'is_edit_page',
'value' => (int)$is_edit_page,
));

echo <<<FORM echo <<<FORM
<div> <div>
<label>$comment_label</label> <label>$comment_label</label>
$comment_input $comment_input
</div> </div>
<div class="elgg-foot"> <div class="elgg-foot">
$is_edit_page_input
$comment_guid_input $comment_guid_input
$entity_guid_input $entity_guid_input
$submit_input $cancel_button $submit_input $cancel_button
Expand Down
1 change: 0 additions & 1 deletion views/default/resources/comments/edit.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
$params = array( $params = array(
'entity' => $target, 'entity' => $target,
'comment' => $comment, 'comment' => $comment,
'is_edit_page' => true,
); );
$content = elgg_view_form('comment/save', null, $params); $content = elgg_view_form('comment/save', null, $params);


Expand Down

0 comments on commit 8ff2b29

Please sign in to comment.