]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Minimal attempt to bring riverdashboard up to code standards.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 7 Jun 2010 22:40:58 +0000 (22:40 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 7 Jun 2010 22:40:58 +0000 (22:40 +0000)
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

mod/riverdashboard/endpoint/get_comments.php [new file with mode: 0644]
mod/riverdashboard/index.php
mod/riverdashboard/languages/en.php
mod/riverdashboard/start.php
mod/riverdashboard/views/default/river/item/list.php
mod/riverdashboard/views/default/river/item/wrapper.php
mod/riverdashboard/views/default/riverdashboard/js.php

diff --git a/mod/riverdashboard/endpoint/get_comments.php b/mod/riverdashboard/endpoint/get_comments.php
new file mode 100644 (file)
index 0000000..59ff3d7
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Grabs more comments to display.
+ */
+
+require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");
+
+$limit = get_input('limit', 25);
+// 3 are displayed by default.
+$offset = get_input('offset', 3);
+$entity_guid = get_input('entity_guid');
+if (!$entity = get_entity($entity_guid)) {
+       exit;
+}
+
+// same deal as the main view...get the newest $limit, but reverse it to put the newest at the bottom.
+if ($comments = get_annotations($entity_guid, "", "", 'generic_comment', "", "", $limit, $offset, "desc")) {
+       $comments = array_reverse($comments);
+}
+
+foreach ($comments as $comment) {
+       //get the comment owner
+       $comment_owner = get_user($comment->owner_guid);
+       //get the comment owner's profile url
+       $comment_owner_url = $comment_owner->getURL();
+
+       //display comment
+       echo "<div class='river_comment clearfloat'>";
+       echo "<span class='river_comment_owner_icon'>";
+       echo elgg_view("profile/icon", array('entity' => $comment_owner, 'size' => 'tiny'));
+       echo "</span>";
+
+       //truncate comment to 150 characters and strip tags
+       $contents = elgg_make_excerpt($comment->value, 150);
+
+       echo "<div class='river_comment_contents'>";
+       echo "<a href=\"{$comment_owner_url}\">" . $comment_owner->name . "</a> " . parse_urls($contents);
+       echo "<span class='entity_subtext'>" . friendly_time($comment->time_created) . "</span>";
+       echo "</div></div>";
+}
\ No newline at end of file
index a5e61057b3b25f927de78c707723ade7be5b2cff..e656233a8dfe8c0434f012d628a754a0c77f2123 100644 (file)
@@ -6,8 +6,6 @@
 
 require_once(dirname(dirname(dirname(__FILE__))) . '/engine/start.php');
 
-gatekeeper();
-
 $type = get_input('type');
 $subtype = get_input('subtype');
 $orient = get_input('display');
@@ -43,7 +41,7 @@ switch($orient) {
 
 $title = elgg_view_title($title_wording);
 
-$river = elgg_view_river_items($subject_guid, 0, $relationship_type, $type, $subtype, '', 20, 0, 0, true, false);
+$river = elgg_view_river_items($subject_guid, 0, $relationship_type, $type, $subtype, '', 20, 0, 0, TRUE, FALSE);
 
 // Replacing callback calls in the nav with something meaningless
 $river = str_replace('callback=true', 'replaced=88,334', $river);
index d0ab70e5926becb8de0ec57635ba17476ee70ba9..6386ce214b8ea8043440ccaa9499a83d715bac0b 100644 (file)
@@ -9,7 +9,6 @@ $english = array(
        /**
         * Site messages
         **/
-
        'sitemessages:announcements' => "Site announcements",
        'sitemessages:posted' => "Posted",
        'sitemessages:river:created' => "Site admin, %s,",
@@ -39,6 +38,9 @@ $english = array(
        'option:icon' => 'Icons',
        'option:avatar' => 'Avatars',
 
+       // likes and comments
+       'riverdashbardo:n_more_comments' => '+%s more',
+
        // ecml
        'riverdashboard:ecml:desc:activity' => 'Recent Activity',
        'riverdashboard:ecml:desc:usage' => '[activity user=username limit=limit type=type subtype=subtype]'
index dfce1572934caa2643ec1b473271ac36cd786d76..3f4c8da5613dffba851cd614c0c4070c743e4b8e 100644 (file)
@@ -27,7 +27,7 @@ function riverdashboard_init() {
  */
 function riverdashboard_page_handler($page){
        include(dirname(__FILE__) . "/index.php");
-       return true;
+       return TRUE;
 }
 
 /**
@@ -38,7 +38,7 @@ function riverdashboard_page_handler($page){
  */
 function elgg_make_river_comment($entity){
        if (!($entity instanceof ElggEntity)) {
-               return false;
+               return FALSE;
        } else {
                //display the comment form
                $comments = elgg_view('riverdashboard/rivercomment', array('entity' => $entity));
index bddb2f5e45ab592ee66d2aba6bedabbcca1f3511..e980f5dbdc2cf680d8f792294634b75c53dc4335 100644 (file)
@@ -51,3 +51,13 @@ if ($vars['pagination'] !== false) {
                echo '<div class="pagination clearfloat">'.$nav.'</div>';
        }
 }
+
+?>
+
+<script type="text/javascript">
+
+// pull in extra comments and likes with ajax
+$(function() {
+
+});
+</script>
\ No newline at end of file
index b90b00f99af5d82fdc9d2fa1183ce7bcdce440f8..a2bc10c54c490faf6027bcc01c653602abfcd363 100644 (file)
@@ -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;
 }
+
 ?>
-<div class="river_item riverdashboard">
+<div class="river_item riverdashboard" id="river_entity_<?php echo $object->guid; ?>">
        <span class="river_item_useravatar">
                <?php echo elgg_view("profile/icon",array('entity' => $user, 'size' => 'small')); ?>
        </span>
+
        <div class="river_item_contents clearfloat">
-       <?php
-               // body contents, generated by the river view in each plugin
-               echo $vars['body'];
+<?php
 
-//display latest 3 comments if there are any
-if ($get_comments){
+// body contents, generated by the river view in each plugin
+echo $vars['body'];
+
+// display latest 3 comments if there are any
+if ($comments){
        $counter = 0;
-       //$background = "";
 
        echo "<div class='river_comments_tabs clearfloat'>";
+       echo "<a class='river_more_comments show_comments_button link'>" . elgg_echo('comments') . '</a>';
 
-       if ($comment_count <= 3) {
-               echo "<a class='river_more_comments show_comments_button link'>Comments</a>";
-       }
-
-       //display 'more comments' if there are any
-       if ($num_comments != 0) {
-               echo "<a class='river_more_comments show_comments_button link'>Comments (+{$num_comments} more)</a>";
-       }
-
-       if ($numoflikes != 0) {
+       if ($likes_count != 0) {
                echo elgg_view('likes/forms/display', array('entity' => $object));
        }
+
        echo "</div>"; // close river_comments_tabs
 
        echo "<div class='river_comments'>";
 
-       if ($numoflikes != 0) {
+       if ($likes_count != 0) {
                //show the users who liked the object
                echo "<div class='likes_list hidden'>";
                echo list_annotations($object->getGUID(), 'likes', 99);
                echo "</div>";
        }
 
-       foreach ($get_comments as $gc) {
+       echo "<div class=\"comments_container\">";
+       // display appropriate comment link
+       if ($more_comments_count > 0) {
+               echo "<a class=\"river_show_more_comments link\">" .
+               sprintf(elgg_echo('riverdashbardo:n_more_comments'), $more_comments_count) . '</a>';
+       }
+       echo "<div class=\"comments_list\">";
+       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 "<div class='river_comment {$alt} clearfloat'>";
+               echo "<div class='river_comment $alt clearfloat'>";
                echo "<span class='river_comment_owner_icon'>";
                echo elgg_view("profile/icon", array('entity' => $comment_owner, 'size' => 'tiny'));
                echo "</span>";
-               //truncate comment to 150 characters
-               if (strlen($gc->value) > 150) {
-                       $gc->value = substr($gc->value, 0, strpos($gc->value, ' ', 150)) . "&hellip;";
-               }
-               $contents = strip_tags($gc->value);
+
+               //truncate comment to 150 characters and strip tags
+               $contents = elgg_make_excerpt($comment->value, 150);
+
                echo "<div class='river_comment_contents'>";
                echo "<a href=\"{$comment_owner_url}\">" . $comment_owner->name . "</a> " . parse_urls($contents);
-               echo "<span class='entity_subtext'>" . friendly_time($gc->time_created) . "</span>";
+               echo "<span class='entity_subtext'>" . friendly_time($comment->time_created) . "</span>";
                echo "</div></div>";
                $counter++;
        }
        echo elgg_make_river_comment($object);
-       echo "</div>"; // close river_comments
+
+       echo '</div>'; // close comments_list.
+
+       echo "</div></div>"; // 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 "<div class='river_comments_tabs clearfloat'>";
        }
-       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 "</div>"; // close river_comments_tabs
        }
 
        if ($vars['item']->type != 'user') {
                echo "<div class='river_comments'>";
        }
-       if ($numoflikes != 0) {
+       if ($likes_count != 0) {
                //show the users who liked the object
                echo "<div class='likes_list hidden'>";
                echo list_annotations($object->getGUID(), 'likes', 99);
@@ -137,6 +146,6 @@ if ($get_comments){
                echo "</div>";
        }
 }
-echo "</div>"; // close river_item_contents
 ?>
+       </div>
 </div>
\ No newline at end of file
index 1e97a510a46f7c77d9b06d6cf65181cb3a03acd2..37de3ad049f5b6ce27dee3ef453f3214c87d5236 100644 (file)
@@ -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');
 
                $('.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('<?php echo $vars['url'];?>mod/riverdashboard/endpoint/get_comments.php', params, function(data) {
+                               commentsList.prepend(data);
+                               commentsList.prev('.river_show_more_comments').hide();
+                       });
+               });
        });
 </script>
\ No newline at end of file