Browse Source

count unread forum items for forumlist widget (ping.php)

tags/3.4.3
rabuzarus 3 years ago
parent
commit
ddf3589fc5

+ 28
- 0
include/forums.php View File

@@ -87,6 +87,7 @@ function widget_forumlist($a) {
87 87
 				'url' => $a->get_baseurl() . '/network?f=&cid=' . $contact['id'],
88 88
 				'external_url' => $a->get_baseurl() . '/redir/' . $contact['id'],
89 89
 				'name' => $contact['name'],
90
+				'cid' => $contact['id'],
90 91
 				'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
91 92
 				'id' => ++$id,
92 93
 			);
@@ -147,3 +148,30 @@ function forumlist_profile_advanced($uid) {
147 148
 		$o .= $forumlist;
148 149
 		return $o;
149 150
 }
151
+
152
+/**
153
+ * @brief count unread forum items
154
+ *
155
+ * Count unread items of connected forums and private groups
156
+ * 
157
+ * @return array
158
+ *	id = contact id
159
+ *	name = contact name
160
+ *	count = counted unseen items
161
+ * 
162
+ */
163
+
164
+function forums_count_unseen() {
165
+	$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(`item`.`unseen`) AS `count` FROM `item`
166
+			INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
167
+			WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
168
+			AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
169
+			AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
170
+			AND NOT `contact`.`pending` AND NOT `contact`.`archive`
171
+			AND `contact`.`success_update` > `failure_update`
172
+			GROUP BY `contact`.`id` ",
173
+		intval(local_user())
174
+	);
175
+
176
+	return $r;
177
+}

+ 7
- 0
js/main.js View File

@@ -210,6 +210,13 @@
210 210
 				$(".group-"+gid+" .notify").addClass("show").text(gcount);
211 211
 			});
212 212
 
213
+			$(".forum-widget-entry .notify").removeClass("show");
214
+			$(data).find("forum").each(function() {
215
+				var fid = this.id;
216
+				var fcount = this.innerHTML;
217
+				$(".forum-"+fid+" .notify").addClass("show").text(fcount);
218
+			});
219
+
213 220
 
214 221
 			var eNotif = $(data).find('notif')
215 222
 

+ 15
- 0
mod/ping.php View File

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
 require_once("include/datetime.php");
3 3
 require_once('include/bbcode.php');
4
+require_once('include/forums.php');
4 5
 require_once("mod/proxy.php");
5 6
 
6 7
 function ping_init(&$a) {
@@ -34,6 +35,7 @@ function ping_init(&$a) {
34 35
 		$home = 0;
35 36
 		$network = 0;
36 37
 		$network_group = array();
38
+		$forums_unseen = array();
37 39
 
38 40
 		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
39 41
 				`item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
@@ -99,6 +101,10 @@ function ping_init(&$a) {
99 101
 			#echo '<SQL id="' . intval(local_user()) . '">' . $sql . '</SQL>';
100 102
 			$network_group = q($sql, intval(local_user()), intval(local_user()));
101 103
 			#echo '<COUNT R="' . count($network_group) . '"/>';
104
+
105
+			if(intval(feature_enabled(local_user(),'forumlist_widget'))) {
106
+				$forums_unseen = forums_count_unseen();
107
+			}
102 108
 		}
103 109
 
104 110
 		$intros1 = q("SELECT  `intro`.`id`, `intro`.`datetime`,
@@ -219,6 +225,7 @@ function ping_init(&$a) {
219 225
 				<net>$network</net>
220 226
 				<home>$home</home>\r\n";
221 227
 		if ($register!=0) echo "<register>$register</register>";
228
+
222 229
 		if ( count($network_group) ) {
223 230
 			echo '<groups>';
224 231
 			foreach ($network_group as $it) {
@@ -227,6 +234,14 @@ function ping_init(&$a) {
227 234
 			echo "</groups>";
228 235
 		}
229 236
 
237
+		if ( count($forums_unseen) ) {
238
+			echo '<forums>';
239
+			foreach ($forums_unseen as $it) {
240
+				echo '<forum id="' . $it['id'] . '">' . $it['count'] . "</forum>";
241
+			}
242
+			echo "</forums>";
243
+		}
244
+
230 245
 		echo "<all-events>$all_events</all-events>
231 246
 			<all-events-today>$all_events_today</all-events-today>
232 247
 			<events>$events</events>

+ 8
- 20
view/global.css View File

@@ -288,28 +288,16 @@ ul.credits li {
288 288
 }
289 289
 
290 290
 /* forumlist widget */
291
-#hide-forum-list {
292
-  opacity: 0.3;
293
-  filter:alpha(opacity=30);
294
-}
295
-
296
-#hide-forum-list:hover {
297
-  opacity: 1.0;
298
-  filter:alpha(opacity=100);
299
-}
300
-
301
-
302
-#forumlist-settings-label, #forumlist-random-label, #forumlist-profile-label, #forumlist-network-label {
303
-  float: left;
304
-  width: 200px;
305
-  margin-bottom: 25px;
291
+.forumlist-img {
292
+  height: 20px;
293
+  width: 20px;
294
+  vertical-align: middle;
306 295
 }
307 296
 
308
-#forumlist-max-forumlists, #forumlist-random, #forumlist-profile, #forumlist-network {
309
-  float: left;
297
+#forum-widget-collapse {
298
+  opacity: 0.3;
310 299
 }
311 300
 
312
-.forumlist-img {
313
-  height: 20px;
314
-  width: 20px;
301
+#forum-widget-collapse:hover {
302
+  opacity: 1.0;
315 303
 }

+ 19
- 18
view/templates/widget_forumlist.tpl View File

@@ -1,45 +1,46 @@
1 1
 <script>
2 2
 
3 3
 function showHideForumlist() {
4
-	if( $("div[id^='forum-widget-entry-extended-']").is(':visible')) {
5
-		$("div[id^='forum-widget-entry-extended-']").hide();
6
-		$('#forum-widget-collapse').html(window.showMore);
4
+	if( $("li[id^='forum-widget-entry-extended-']").is(':visible')) {
5
+		$("li[id^='forum-widget-entry-extended-']").hide();
6
+		$("li#forum-widget-collapse").html(window.showMore);
7 7
 
8 8
 	}
9 9
 	else {
10
-		$("div[id^='forum-widget-entry-extended-']").show();
11
-		$('#forum-widget-collapse').html(window.showFewer);
12
-	}
10
+		$("li[id^='forum-widget-entry-extended-']").show();
11
+		$("li#forum-widget-collapse").html(window.showFewer);
13 12
 	}
13
+}
14 14
 </script>
15 15
 
16 16
 <div id="forumlist-sidebar" class="widget">
17 17
 	<h3 id="forumlist">{{$title}}</h3>
18 18
 
19
-	{{foreach $forums as $forum}}
19
+	<ul id="forumlist-sidbar-ul" role="menu">
20
+		{{foreach $forums as $forum}}
20 21
 		{{if $forum.id <= $visible_forums}}
21
-		<div class="forum-widget-entry" id="forum-widget-entry-{{$forum.id}}" role="menuitem">
22
+		<li class="forum-widget-entry forum-{{$forum.cid}}" id="forum-widget-entry-{{$forum.id}}" role="menuitem">
23
+			<span class="notify badge pull-right"></span>
22 24
 			<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
23 25
 				<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
24 26
 			</a>
25 27
 			<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
26
-		</div>
28
+		</li>
27 29
 		{{/if}}
28 30
 	
29 31
 		{{if $forum.id > $visible_forums}}
30
-		<div class="forum-widget-entry" id="forum-widget-entry-extended-{{$forum.id}}" role="menuitem" style="display: none;">
32
+		<li class="forum-widget-entry forum-{{$forum.cid}}" id="forum-widget-entry-extended-{{$forum.id}}" role="menuitem" style="display: none;">
33
+			<span class="notify badge pull-right"></span>
31 34
 			<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
32 35
 				<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
33 36
 			</a>
34 37
 			<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
35
-		</div>
38
+		</li>
36 39
 		{{/if}}
37
-	{{/foreach}}
38
-
39
-	{{if $total > $visible_forums }}
40
-	<div id="forum-widget-showmore" class="forum-widget-entry" role="menuitem">
41
-		<a onclick="showHideForumlist(); return false;" id="forum-widget-collapse" class="forum-widget-link">{{$showmore}}</a>
42
-	</div>
43
-	{{/if}}
40
+		{{/foreach}}
44 41
 
42
+		{{if $total > $visible_forums }}
43
+		<li onclick="showHideForumlist(); return false;" id="forum-widget-collapse" class="forum-widget-link fakelink tool">{{$showmore}}</li>
44
+		{{/if}}
45
+	</ul>
45 46
 </div>

+ 6
- 2
view/theme/duepuntozero/style.css View File

@@ -2039,7 +2039,7 @@ a.mail-list-link {
2039 2039
 #sidebar-group-list ul {
2040 2040
 	list-style-type: none;
2041 2041
 }
2042
-.sidebar-group-li .notify {
2042
+.sidebar-group-li .notify, .forum-widget-entry .notify {
2043 2043
 	display: none;
2044 2044
 	font-size: 9px;
2045 2045
 	border: 1px solid rgb(221, 221, 221);
@@ -2047,7 +2047,7 @@ a.mail-list-link {
2047 2047
 	float: right;
2048 2048
 	background-color: #BABDB6;
2049 2049
 }
2050
-.sidebar-group-li .notify.show {
2050
+.sidebar-group-li .notify.show, .forum-widget-entry .notify.show {
2051 2051
 	display: block;
2052 2052
 }
2053 2053
 
@@ -2061,6 +2061,10 @@ a.mail-list-link {
2061 2061
 	margin-top: 10px;
2062 2062
 }
2063 2063
 
2064
+#forumlist-sidebar ul {
2065
+	list-style: none;
2066
+}
2067
+
2064 2068
 .nets-ul, .fileas-ul, .categories-ul, .datebrowse-ul {
2065 2069
 	list-style-type: none;
2066 2070
 }

+ 10
- 0
view/theme/frost/style.css View File

@@ -2357,6 +2357,16 @@ a.mail-list-link {
2357 2357
 	margin-top: 10px;
2358 2358
 }
2359 2359
 
2360
+#forumlist-sidebar ul {
2361
+	list-style: none;
2362
+}
2363
+
2364
+.forumlist-img {
2365
+	height: 20px;
2366
+	width: 20px;
2367
+	vertical-align: middle;
2368
+}
2369
+
2360 2370
 .nets-ul, .fileas-ul, .categories-ul, .datebrowse-ul {
2361 2371
 	list-style-type: none;
2362 2372
 }

+ 7
- 0
view/theme/quattro/js/quattro.js View File

@@ -11,6 +11,13 @@ $(document).ready(function(){
11 11
 			$(".group-"+gid+" .notify").addClass("on").text(gcount);
12 12
 		});
13 13
 
14
+		$(".forum-widget-entry .notify").removeClass("on");
15
+		$(data).find("forum").each(function() {
16
+			var fid = this.id;
17
+			var fcount = this.innerHTML;
18
+			$(".forum-"+fid+" .notify").addClass("on").text(fcount);
19
+		});
20
+
14 21
 		console.log(intro,mail);
15 22
 
16 23
 		if (notifCount > 0 ) {

+ 30
- 6
view/theme/vier/style.css View File

@@ -343,6 +343,22 @@ code {
343 343
   margin-top: 20px;
344 344
   max-width: 640px;
345 345
 }
346
+.badge {
347
+  display: inline-block;
348
+  min-width: 10px;
349
+  padding: 3px 7px;
350
+  font-size: 12px;
351
+  font-weight: 700;
352
+  line-height: 1;
353
+  color: #fff;
354
+  text-align: center;
355
+  white-space: nowrap;
356
+  vertical-align: baseline;
357
+  /* background-color: #737373*/;
358
+  background-color: #36C;
359
+  border-radius: 4px;
360
+  opacity: 0.3;
361
+}
346 362
 #panel {
347 363
   position: absolute;
348 364
   width: 10em;
@@ -386,7 +402,7 @@ code {
386 402
 .tool a {
387 403
 /*  color: #000; */
388 404
 }
389
-.tool a:hover, .widget a:hover, #nets-sidear a:hover, #hide-forum-list:hover, .admin.link a:hover, aside h4 a:hover, right_aside h4 a:hover {
405
+.tool a:hover, .widget a:hover, #nets-sidear a:hover, #forum-widget-collapse:hover, .admin.link a:hover, aside h4 a:hover, right_aside h4 a:hover {
390 406
   /* text-decoration: underline; */
391 407
   text-decoration: none;
392 408
   color: black;
@@ -400,8 +416,8 @@ code {
400 416
   opacity: 1;
401 417
 }
402 418
 
403
-.sidebar-group-li:hover, #sidebar-new-group:hover, #hide-forum-list:hover,
404
-#sidebar-ungrouped:hover, .side-link:hover, .nets-ul li:hover, #forumlist-sidebar div:hover, #forum-list-right div:hover,
419
+.sidebar-group-li:hover, #sidebar-new-group:hover, #forum-widget-collapse:hover,
420
+#sidebar-ungrouped:hover, .side-link:hover, .nets-ul li:hover, #forumlist-sidebar li:hover, #forumlist-sidebar-right li:hover,
405 421
 .nets-all:hover, .saved-search-li:hover, li.tool:hover, .admin.link:hover, aside h4 a:hover, right_aside h4 a:hover, #message-new:hover {
406 422
   /* background-color: #ddd; */
407 423
 /*  background-color: #e5e5e5; */
@@ -420,7 +436,7 @@ code {
420 436
   font-weight: bold;
421 437
 }
422 438
 
423
-#forum-widget-showmore, #sidebar-new-group, #hide-forum-list, #forum-list-right, #sidebar-ungrouped,
439
+#forum-widget-showmore, #sidebar-new-group, #forum-widget-collapse, #forumlist-rsidebar-right, #sidebar-ungrouped,
424 440
 .side-link, #peoplefind-desc, #connect-desc, .nets-all, .admin.link, #message-new {
425 441
   padding-left: 10px;
426 442
   padding-top: 3px;
@@ -440,6 +456,14 @@ code {
440 456
   padding-right: 5px;
441 457
 }
442 458
 
459
+#forumlist-sidebar .notify, #forumlist-sidebar-right .notify {
460
+  display: none;
461
+}
462
+
463
+#forumlist-sidebar .notify.show, #forumlist-sidebar-right .notify.show {
464
+  display: inline-block;
465
+}
466
+
443 467
 a.nets-link, .side-link a, #sidebar-new-group a, a.savedsearchterm, a.fileas-link, aside h4 a, right_aside h4 a {
444 468
   display: block;
445 469
   color: #737373;
@@ -467,11 +491,11 @@ a.sidebar-group-element {
467 491
   color: black;
468 492
 }
469 493
 
470
-#forumlist-sidebar a, #forum-list-right a, .tool a, .admin.link a {
494
+#forumlist-sidebar a, #forumlist-sidebar-right a, .tool a, .admin.link a {
471 495
   color: #737373;
472 496
 }
473 497
 
474
-#forumlist-sidebar, #forum-list-right {
498
+#forumlist-sidebar, #forumlist-sidebar-right {
475 499
   margin-top: 2px;
476 500
 }
477 501
 

+ 47
- 0
view/theme/vier/templates/widget_forumlist_right.tpl View File

@@ -0,0 +1,47 @@
1
+<script>
2
+
3
+function showHideForumlist() {
4
+	if( $("li[id^='forum-widget-entry-extended-']").is(':visible')) {
5
+		$("li[id^='forum-widget-entry-extended-']").hide();
6
+		$("li#forum-widget-collapse").html(window.showMore);
7
+
8
+	}
9
+	else {
10
+		$("li[id^='forum-widget-entry-extended-']").show();
11
+		$("li#forum-widget-collapse").html(window.showFewer);
12
+	}
13
+}
14
+</script>
15
+
16
+<div id="forumlist-sidebar-right" class="widget">
17
+	<h3 id="forumlist">{{$title}}</h3>
18
+
19
+	<ul id="forumlist-sidbar-ul" role="menu">
20
+		{{foreach $forums as $forum}}
21
+		{{if $forum.id <= $visible_forums}}
22
+		<li class="forum-widget-entry forum-{{$forum.cid}}" id="forum-widget-entry-{{$forum.id}}" role="menuitem">
23
+			<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
24
+				<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
25
+			</a>
26
+			<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
27
+			<span class="notify badge pull-right"></span>
28
+		</li>
29
+		{{/if}}
30
+	
31
+		{{if $forum.id > $visible_forums}}
32
+		<li class="forum-widget-entry forum-{{$forum.cid}}" id="forum-widget-entry-extended-{{$forum.id}}" role="menuitem" style="display: none;">
33
+			<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
34
+				<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
35
+			</a>
36
+			<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
37
+			<span class="notify padge pull-right"></span>
38
+		</li>
39
+		{{/if}}
40
+		{{/foreach}}
41
+
42
+		{{if $total > $visible_forums }}
43
+		<li onclick="showHideForumlist(); return false;" id="forum-widget-collapse" class="forum-widget-link tool fakelink">{{$showmore}}</li>
44
+		{{/if}}
45
+	</ul>
46
+
47
+</div>

+ 30
- 21
view/theme/vier/theme.php View File

@@ -220,35 +220,44 @@ function vier_community_info() {
220 220
 	//Community_Pages at right_aside
221 221
 	if($show_pages AND local_user()) {
222 222
 
223
-		$pagelist = array();
223
+		require_once('include/forums.php');
224 224
 
225
-		$contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact`
226
-				WHERE `network`= '%s' AND `uid` = %d AND (`forum` OR `prv`) AND
227
-					NOT `hidden` AND NOT `blocked` AND
228
-					NOT `archive` AND NOT `pending` AND
229
-					`success_update` > `failure_update`
230
-				ORDER BY `name` ASC",
231
-				dbesc(NETWORK_DFRN), intval($a->user['uid']));
225
+		//sort by last updated item
226
+		$lastitem = true;
232 227
 
233
-		$pageD = array();
228
+		$contacts = get_forumlist($a->user['uid'],true,$lastitem, true);
229
+		$total = count($contacts);
230
+		$visible_forums = 10;
234 231
 
235
-		// Look if the profile is a community page
236
-		foreach($contacts as $contact) {
237
-			$pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
238
-		};
232
+		if(count($contacts)) {
239 233
 
240
-		$contacts = $pageD;
241
-
242
-		if ($contacts) {
243
-			$page = '
244
-				<h3>'.t("Community Pages").'</h3>
245
-				<div id="forum-list-right">';
234
+			$id = 0;
246 235
 
247 236
 			foreach($contacts as $contact) {
248
-				$page .= '<div role="menuitem"><a href="' . $a->get_baseurl() . '/redir/' . $contact["id"] . '" title="'.t('External link to forum').'" class="label sparkle" target="_blank"><img class="forumlist-img" height="20" width="20" src="' . $contact['micro'] .'" alt="'.t('External link to forum').'" /></a> <a href="' . $a->get_baseurl() . '/network?f=&cid=' . $contact['id'] . '" >' . $contact["name"]."</a></div>";
237
+
238
+				$entry = array(
239
+					'url' => $a->get_baseurl() . '/network?f=&cid=' . $contact['id'],
240
+					'external_url' => $a->get_baseurl() . '/redir/' . $contact['id'],
241
+					'name' => $contact['name'],
242
+					'cid' => $contact['id'],
243
+					'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
244
+					'id' => ++$id,
245
+				);
246
+				$entries[] = $entry;
249 247
 			}
250 248
 
251
-			$page .= '</div>';
249
+
250
+			$tpl = get_markup_template('widget_forumlist_right.tpl');
251
+
252
+			$page .= replace_macros($tpl,array(
253
+				'$title'	=> t('Forums'),
254
+				'$forums'	=> $entries,
255
+				'$link_desc'	=> t('External link to forum'),
256
+				'$total'	=> $total,
257
+				'$visible_forums' => $visible_forums,
258
+				'$showmore'	=> t('show more'),
259
+			));
260
+
252 261
 			$aside['$page'] = $page;
253 262
 		}
254 263
 	}

Loading…
Cancel
Save