From 0c23843b615742af6d43514ca6211750567cf07b Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 17:39:29 -0700 Subject: untested forum widget --- include/widgets.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 36671e719..fe3b47353 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -980,10 +980,48 @@ function widget_rating($arr) { } // used by site ratings pages to provide a return link -function widget_pubsites() { +function widget_pubsites($arr) { if(get_app()->poi) return; return '
'; } +function widget_forums($arr) { + + $a = get_app(); + + if(! local_channel()) + return ''; + + if(! count($a->contacts)) + load_contact_links(local_channel()); + + $o = ''; + + if(is_array($arr) && array_key_exists('limit',$arr)) + $limit = " limit " . intval($limit) . " "; + else + $limit = " limit 12 "; + + $perms_sql = item_permissions_sql(local_channel()) . item_normal(); + + $r = q("select count(item_unseen) as unseen, owner_xchan, xchan.* from item left join xchan on owner_xchan = xchan_hash group by owner_xchan order by unseen desc limit item from xchan where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", + intval(local_channel()) + ); + if($r) { + $o .= '
'; + $o .= '

' . t('Forums') . '

'; + + foreach($r as $rr) { + if($a->contacts && array_key_exists($rr['owner_xchan'],$a->contacts)) + $contact = $a->contacts[$rr['owner_xchan']]; + if($contact) + $o .= '
'; + } + return $o; + +} + -- cgit v1.2.3 From 44dcbeaaa4fa58ba3bc8f535ae842089214e656f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 19:22:14 -0700 Subject: forum widget --- include/widgets.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index fe3b47353..894a2fa3b 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1006,20 +1006,20 @@ function widget_forums($arr) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - $r = q("select count(item_unseen) as unseen, owner_xchan, xchan.* from item left join xchan on owner_xchan = xchan_hash group by owner_xchan order by unseen desc limit item from xchan where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", + $r = q("select sum(item_unseen) as unseen, owner_xchan, xchan.* from xchan left join item on owner_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", intval(local_channel()) ); if($r) { $o .= '
'; - $o .= '

' . t('Forums') . '

'; + $o .= '

' . t('Forums') . '

'; + $o .= ''; } return $o; -- cgit v1.2.3 From c8e83d6edc04d5483baf9b252b36e34d5c9d0f61 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 19:27:22 -0700 Subject: set font-weight back to normal on forums widget --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 894a2fa3b..d5ee9c110 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1017,7 +1017,7 @@ function widget_forums($arr) { if($a->contacts && array_key_exists($rr['owner_xchan'],$a->contacts)) $contact = $a->contacts[$rr['owner_xchan']]; if($contact) - $o .= '
  • ' . $rr['unseen'] . ' ' . $rr['xchan_name'] . '
  • '; + $o .= '
  • ' . $rr['unseen'] . ' ' . $rr['xchan_name'] . '
  • '; } $o .= ''; } -- cgit v1.2.3 From 400d5790f3f461ebe1e35012ad8fa976fe9b2910 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 19:58:31 -0700 Subject: make sure we only get forums attached to the channel --- include/widgets.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index d5ee9c110..698326d36 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -994,9 +994,6 @@ function widget_forums($arr) { if(! local_channel()) return ''; - if(! count($a->contacts)) - load_contact_links(local_channel()); - $o = ''; if(is_array($arr) && array_key_exists('limit',$arr)) @@ -1006,7 +1003,7 @@ function widget_forums($arr) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - $r = q("select sum(item_unseen) as unseen, owner_xchan, xchan.* from xchan left join item on owner_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", + $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_channel = uid where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", intval(local_channel()) ); if($r) { @@ -1014,10 +1011,7 @@ function widget_forums($arr) { $o .= '

    ' . t('Forums') . '

    '; } -- cgit v1.2.3 From 8dd7fab38d0938f87bb3b696b946b18bb09e78af Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:16:17 -0700 Subject: order by name --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 698326d36..cfecbdc66 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1003,7 +1003,7 @@ function widget_forums($arr) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_channel = uid where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan $limit ", + $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_channel = uid where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan order by xchan_name $limit ", intval(local_channel()) ); if($r) { -- cgit v1.2.3 From 80df97e73418e910ecc583200bf2a0207e25ffe7 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:18:34 -0700 Subject: don't show '0' results, like notifications --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index cfecbdc66..0bed5ceb3 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1011,7 +1011,7 @@ function widget_forums($arr) { $o .= '

    ' . t('Forums') . '

    '; } -- cgit v1.2.3 From 89fa36ce2a0437b5a819658386bbeccc68701c6e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:24:06 -0700 Subject: wrong cid --- include/widgets.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 0bed5ceb3..25c814ba9 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1003,8 +1003,9 @@ function widget_forums($arr) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_channel = uid where xchan_pubforum = 1 and uid = %d $perms_sql group by owner_xchan order by xchan_name $limit ", - intval(local_channel()) + $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_id = %d $perms_sql group by owner_xchan order by xchan_name $limit ", + intval(local_channel()), + intval(local_channel()), ); if($r) { $o .= '
    '; -- cgit v1.2.3 From be4eb4eeb87b9eb8afd396b4dd16d0dba1765cfe Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:25:02 -0700 Subject: typo --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 25c814ba9..9d4c64b2f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1005,7 +1005,7 @@ function widget_forums($arr) { $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_id = %d $perms_sql group by owner_xchan order by xchan_name $limit ", intval(local_channel()), - intval(local_channel()), + intval(local_channel()) ); if($r) { $o .= '
    '; -- cgit v1.2.3 From 1932e726030207fd9283e6e6a796b53c5995fea4 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:25:52 -0700 Subject: arghh --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 9d4c64b2f..0e56b0e15 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1003,7 +1003,7 @@ function widget_forums($arr) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_id = %d $perms_sql group by owner_xchan order by xchan_name $limit ", + $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_channel = %d $perms_sql group by owner_xchan order by xchan_name $limit ", intval(local_channel()), intval(local_channel()) ); -- cgit v1.2.3 From b651604e8bc8895483fa388448cb5bbd8bcd35f9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 20:58:03 -0700 Subject: remove the forum limit --- include/widgets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 0e56b0e15..49470287e 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -999,7 +999,7 @@ function widget_forums($arr) { if(is_array($arr) && array_key_exists('limit',$arr)) $limit = " limit " . intval($limit) . " "; else - $limit = " limit 12 "; + $limit = ''; $perms_sql = item_permissions_sql(local_channel()) . item_normal(); -- cgit v1.2.3 From 0e8991fec2bc27f0bfab308cc9b04406e42c6dd8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 11 Aug 2015 22:23:20 -0700 Subject: more consistent output on forum widget --- include/widgets.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 49470287e..e735f5b2f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -1001,17 +1001,39 @@ function widget_forums($arr) { else $limit = ''; + $unseen = 0; + if(is_array($arr) && array_key_exists('unseen',$arr) && intval($arr['unseen'])) + $unseen = 1; + $perms_sql = item_permissions_sql(local_channel()) . item_normal(); - - $r = q("select sum(item_unseen) as unseen, owner_xchan, abook_id, xchan.* from xchan left join item on owner_xchan = xchan_hash left join abook on abook_xchan = xchan_hash where xchan_pubforum = 1 and uid = %d and abook_channel = %d $perms_sql group by owner_xchan order by xchan_name $limit ", - intval(local_channel()), + + $r1 = q("select * from abook left join xchan on abook_xchan = xchan_hash where xchan_pubforum = 1 and abook_channel = %d order by xchan_name $limit ", intval(local_channel()) ); - if($r) { + if(! $r1) + return $o; + + $str = ''; + + // Trying to cram all this into a single query with joins and the proper group by's is tough. + // There also should be a way to update this via ajax. + + for($x = 0; $x < count($r1); $x ++) { + $r = q("select sum(item_unseen) as unseen from item where owner_xchan = '%s' and uid = %d $perms_sql ", + dbesc($r1[$x]['xchan_hash']), + intval(local_channel()) + ); + if($r) + $r1[$x]['unseen'] = $r[0]['unseen']; + } + + if($r1) { $o .= '
    '; $o .= '

    ' . t('Forums') . '

    '; -- cgit v1.2.3