From 02e0a58f8907c66a0dbe7241621e5ad0bb264426 Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 7 Jun 2010 22:40:58 +0000 Subject: Minimal attempt to bring riverdashboard up to code standards. Fixed comment count in +N more string. Added ajax grabbing of all comments when clicking more link. git-svn-id: http://code.elgg.org/elgg/trunk@6389 36083f99-b078-4883-b0ff-0f9b5a30f544 --- .../views/default/river/item/list.php | 10 ++ .../views/default/river/item/wrapper.php | 111 +++++++++++---------- .../views/default/riverdashboard/js.php | 25 ++++- 3 files changed, 91 insertions(+), 55 deletions(-) (limited to 'mod/riverdashboard/views/default') diff --git a/mod/riverdashboard/views/default/river/item/list.php b/mod/riverdashboard/views/default/river/item/list.php index bddb2f5e4..e980f5dbd 100644 --- a/mod/riverdashboard/views/default/river/item/list.php +++ b/mod/riverdashboard/views/default/river/item/list.php @@ -51,3 +51,13 @@ if ($vars['pagination'] !== false) { echo ''; } } + +?> + + \ No newline at end of file diff --git a/mod/riverdashboard/views/default/river/item/wrapper.php b/mod/riverdashboard/views/default/river/item/wrapper.php index b90b00f99..a2bc10c54 100644 --- a/mod/riverdashboard/views/default/river/item/wrapper.php +++ b/mod/riverdashboard/views/default/river/item/wrapper.php @@ -2,13 +2,19 @@ /** * Elgg river item wrapper. * Wraps all river items. + * + * @todo: Clean up this logic. + * It looks like this only will allow comments on non user and non group forum + * topic entities. + * + * Different chunks are used depending on if comments exist or not. + * + * */ -//set required variables $object = get_entity($vars['item']->object_guid); -//get object url $object_url = $object->getURL(); -$numoflikes = elgg_count_likes($object); +$likes_count = elgg_count_likes($object); //user //if displaying on the profile get the object owner, else the subject_guid @@ -18,110 +24,113 @@ if (get_context() == 'profile' && $object->getSubtype() == 'thewire') { $user = get_entity($vars['item']->subject_guid); } -//count comment annotations -$comment_count = count_annotations($vars['item']->object_guid, $vars['item']->type, $vars['item']->subtype, $annotation_comment); - -//get last three comments display -$get_comments = get_annotations($vars['item']->object_guid, "", "", 'generic_comment', "", "", 3, 0, "desc"); - -if ($get_comments){ - //reverse the array so we can display comments in the right order - $get_comments = array_reverse($get_comments); +// get last three comments display +// want the 3 most recent comments (order by time_created desc = 3 2 1) +// but will display them with the newest at the bottom (1 2 3) +if ($comments = get_annotations($vars['item']->object_guid, "", "", 'generic_comment', "", "", 3, 0, "desc")) { + $comments = array_reverse($comments); } -//minus 3 off the comment total as we display 3 by default +// for displaying "+N more" +// -3 from the count because the 3 displayed don't count in the "more" +$comment_count = count_annotations($vars['item']->object_guid, $vars['item']->type, $vars['item']->subtype, 'generic_comment'); if ($comment_count < 3) { - $num_comments = 0; + $more_comments_count = 0; } else { - $num_comments = $comment_count - 3; + $more_comments_count = $comment_count - 3; } + ?> -
+
$user, 'size' => 'small')); ?> +
- "; + echo "" . elgg_echo('comments') . ''; - if ($comment_count <= 3) { - echo "Comments"; - } - - //display 'more comments' if there are any - if ($num_comments != 0) { - echo "Comments (+{$num_comments} more)"; - } - - if ($numoflikes != 0) { + if ($likes_count != 0) { echo elgg_view('likes/forms/display', array('entity' => $object)); } + echo "
"; // close river_comments_tabs echo "
"; - if ($numoflikes != 0) { + if ($likes_count != 0) { //show the users who liked the object echo ""; } - foreach ($get_comments as $gc) { + echo "
"; + // display appropriate comment link + if ($more_comments_count > 0) { + echo "" . + sprintf(elgg_echo('riverdashbardo:n_more_comments'), $more_comments_count) . ''; + } + echo "
"; + foreach ($comments as $comment) { //get the comment owner - $comment_owner = get_user($gc->owner_guid); + $comment_owner = get_user($comment->owner_guid); //get the comment owner's profile url $comment_owner_url = $comment_owner->getURL(); // color-code each of the 3 comments + // @todo this isn't used in CSS... if( ($counter == 2 && $comment_count >= 4) || ($counter == 1 && $comment_count == 2) || ($counter == 0 && $comment_count == 1) || ($counter == 2 && $comment_count == 3) ) { $alt = 'latest'; } else if( ($counter == 1 && $comment_count >= 4) || ($counter == 0 && $comment_count == 2) || ($counter == 1 && $comment_count == 3) ) { - $alt = 'penultimate'; + $alt = 'penultimate'; } //display comment - echo "
"; + echo "
"; echo ""; echo elgg_view("profile/icon", array('entity' => $comment_owner, 'size' => 'tiny')); echo ""; - //truncate comment to 150 characters - if (strlen($gc->value) > 150) { - $gc->value = substr($gc->value, 0, strpos($gc->value, ' ', 150)) . "…"; - } - $contents = strip_tags($gc->value); + + //truncate comment to 150 characters and strip tags + $contents = elgg_make_excerpt($comment->value, 150); + echo "
"; echo "" . $comment_owner->name . " " . parse_urls($contents); - echo "" . friendly_time($gc->time_created) . ""; + echo "" . friendly_time($comment->time_created) . ""; echo "
"; $counter++; } echo elgg_make_river_comment($object); - echo "
"; // close river_comments + + echo '
'; // close comments_list. + + echo "
"; // close comments_container and river_comments } else { // tab bar nav - for users that liked object - $numoflikes = elgg_count_likes($object); - - if ($vars['item']->type != 'user' && $numoflikes != 0) { + if ($vars['item']->type != 'user' && $likes_count != 0) { echo "
"; } - if ($numoflikes != 0) { + + if ($likes_count != 0) { echo elgg_view('likes/forms/display', array('entity' => $object)); } - if ($vars['item']->type != 'user' && $numoflikes != 0) { + + if ($vars['item']->type != 'user' && $likes_count != 0) { echo "
"; // close river_comments_tabs } if ($vars['item']->type != 'user') { echo "
"; } - if ($numoflikes != 0) { + if ($likes_count != 0) { //show the users who liked the object echo ""; } } -echo "
"; // close river_item_contents ?> +
\ No newline at end of file diff --git a/mod/riverdashboard/views/default/riverdashboard/js.php b/mod/riverdashboard/views/default/riverdashboard/js.php index 1e97a510a..37de3ad04 100644 --- a/mod/riverdashboard/views/default/riverdashboard/js.php +++ b/mod/riverdashboard/views/default/riverdashboard/js.php @@ -8,7 +8,7 @@ var myParent = $(this).closest('.river_item'); if (myParent.find('.likes_list').css('display') == 'none') { // hide comments - myParent.find('.river_comment').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 }); + myParent.find('.comments_container').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 }); // change selected tab myParent.find('.show_comments_button').addClass('off'); myParent.find('.likes_user_list_button').removeClass('off'); @@ -19,16 +19,33 @@ $('.show_comments_button').click(function() { var myParent = $(this).closest('.river_item'); - if (myParent.find('.river_comment').css('display') == 'none') { - // hide comments + if (myParent.find('.comments_container').css('display') == 'none') { + // hide likes myParent.find('.likes_list').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 }); // change selected tab myParent.find('.show_comments_button').removeClass('off'); myParent.find('.likes_user_list_button').addClass('off'); // show users that liked object - elgg_slide_toggle(this, '.river_item', '.river_comment'); + elgg_slide_toggle(this, '.river_item', '.comments_container'); } }); + // grab more comments + $('.river_show_more_comments').click(function() { + var riverItem = $(this).closest('.river_item'); + var guid = riverItem.attr('id').replace('river_entity_', ''); + var commentsList = riverItem.find('.comments_list'); + var numComments = riverItem.find('.river_comment').length; + + var params = { + 'entity_guid': guid, + 'offset': numComments + } + + $.post('mod/riverdashboard/endpoint/get_comments.php', params, function(data) { + commentsList.prepend(data); + commentsList.prev('.river_show_more_comments').hide(); + }); + }); }); \ No newline at end of file -- cgit v1.2.3