aboutsummaryrefslogtreecommitdiff
path: root/mod/riverdashboard/views/default/river/item/wrapper.php
blob: 0413775d616c5e95f72923c8f1817b319d9bc2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
 * 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.
 *
 *
 */

$object = get_entity($vars['item']->object_guid);
$object_url = $object->getURL();
$likes_count = elgg_count_likes($object);

//user
//if displaying on the profile get the object owner, else the subject_guid
if (elgg_get_context() == 'profile' && $object->getSubtype() ==  'thewire') {
	$user = get_entity($object->owner_guid);
} else {
	$user = get_entity($vars['item']->subject_guid);
}

// get last three comments display
// want the 3 most recent comments (order by time_created desc = 3 2 1 limit 3)
// 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);
}

// 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) {
	$more_comments_count = 0;
} else {
	$more_comments_count = $comment_count - 3;
}

?>
<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 clearfix">
<?php

// 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;

	echo "<div class='river_comments_tabs clearfix'>";
	echo "<a class='river_more_comments show_comments_button link'>" . elgg_echo('comments') . '</a>';

	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 ($likes_count != 0) {
		//show the users who liked the object
		// this is loaded via ajax to avoid pounding the server with avatar requests.
		echo "<div class='likes_list hidden'></div>";
	}

	echo "<div class=\"comments_container\">";
	// display appropriate comment link
	if ($more_comments_count > 0) {
		echo "<a class=\"river_more_comments show_more_button link\">" .
		elgg_echo('riverdashboard:n_more_comments', array($more_comments_count)) . '</a>';

		echo "<a style=\"display: none\" class=\"river_more_comments show_less_button link\">" . elgg_echo('riverdashboard:show_less') . '</a>';
	}
	echo "<div class=\"comments_list\">";
	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();
		// 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';
		}
		//display comment
		echo "<div class='river_comment $alt clearfix'>";
		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_get_excerpt($comment->value, 150);

		echo "<div class='river_comment_contents'>";
		echo "<a href=\"{$comment_owner_url}\">" . $comment_owner->name . '</a>&nbsp;<span class="elgg_excerpt">' . parse_urls($contents) . '</span>';
		echo "<span class='entity_subtext'>" . elgg_view_friendly_time($comment->time_created) . "</span>";
		echo "</div></div>";
		$counter++;
	}

	// close comments_list, comments_container and river_comments
	echo '</div></div>' . elgg_make_river_comment($object) . '</div>';
} else {
	// tab bar nav - for users that liked object
	if ($vars['item']->type != 'user' && $likes_count != 0) {
		echo "<div class='river_comments_tabs clearfix'>";
	}

	if ($likes_count != 0) {
		echo elgg_view('likes/forms/display', array('entity' => $object));
	}

	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 ($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>";
	}

	// if there are no comments to display
	// and this is not a user - include the inline comment form
	if ($vars['item']->type != 'user') {
		echo elgg_make_river_comment($object);
	}
	if ($vars['item']->type != 'user') {
		echo "</div>";
	}
}
?>
	</div>
</div>