]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Merge pull request #472 from pixelroot/master
[friendica.git] / mod / community.php
1 <?php
2
3 function community_init(&$a) {
4         if(! local_user()) {
5                 unset($_SESSION['theme']);
6                 unset($_SESSION['mobile-theme']);
7         }
8
9
10 }
11
12
13 function community_content(&$a, $update = 0) {
14
15         $o = '';
16
17         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
18                 notice( t('Public access denied.') . EOL);
19                 return;
20         }
21
22         if(get_config('system','no_community_page')) {
23                 notice( t('Not available.') . EOL);
24                 return;
25         }
26
27         require_once("include/bbcode.php");
28         require_once('include/security.php');
29         require_once('include/conversation.php');
30
31
32         $o .= '<h3>' . t('Community') . '</h3>';
33         if(! $update) {
34                 nav_set_selected('community');
35                 $o .= '<div id="live-community"></div>' . "\r\n";
36                 $o .= "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
37         }
38
39         if(x($a->data,'search'))
40                 $search = notags(trim($a->data['search']));
41         else
42                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
43
44
45         // Here is the way permissions work in this module...
46         // Only public posts can be shown
47         // OR your own posts if you are a logged in member
48
49         if(! get_pconfig(local_user(),'system','alt_pager')) {
50                 $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`
51                         FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
52                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
53                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' 
54                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
55                         AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0 
56                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0"
57                 );
58
59                 if(count($r))
60                         $a->set_pager_total($r[0]['total']);
61
62                 if(! $r[0]['total']) {
63                         info( t('No results.') . EOL);
64                         return $o;
65                 }
66
67         }
68
69         $r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`, 
70                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
71                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
72                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
73                 `user`.`nickname`, `user`.`hidewall`
74                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
75                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
76                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
77                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
78                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' 
79                 AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
80                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 group by `item`.`uri`
81                 ORDER BY `received` DESC LIMIT %d, %d ",
82                 intval($a->pager['start']),
83                 intval($a->pager['itemspage'])
84
85         );
86
87         if(! count($r)) {
88                 info( t('No results.') . EOL);
89                 return $o;
90         }
91
92         // we behave the same in message lists as the search module
93
94         $o .= conversation($a,$r,'community',$update);
95
96         if(! get_pconfig(local_user(),'system','alt_pager')) {
97                 $o .= paginate($a);
98         }
99         else {
100                 $o .= alt_pager($a,count($r));
101         }
102
103         return $o;
104 }
105