]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Merge pull request #2441 from rabuzarus/0704_doxygen_forum
[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         // Currently the community page isn't able to handle update requests
18         if ($update)
19                 return;
20
21         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
22                 notice( t('Public access denied.') . EOL);
23                 return;
24         }
25
26         if(get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) {
27                 notice( t('Not available.') . EOL);
28                 return;
29         }
30
31         require_once("include/bbcode.php");
32         require_once('include/security.php');
33         require_once('include/conversation.php');
34
35
36         $o .= '<h3>' . t('Community') . '</h3>';
37         if(! $update) {
38                 nav_set_selected('community');
39         }
40
41         if(x($a->data,'search'))
42                 $search = notags(trim($a->data['search']));
43         else
44                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
45
46
47         // Here is the way permissions work in this module...
48         // Only public posts can be shown
49         // OR your own posts if you are a logged in member
50
51         if(get_config('system', 'old_pager')) {
52                 $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`
53                         FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
54                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
55                         INNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0
56                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
57                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
58                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
59                         AND `item`.`private` = 0 AND `item`.`wall` = 1"
60                 );
61
62                 if(count($r))
63                         $a->set_pager_total($r[0]['total']);
64
65                 if(! $r[0]['total']) {
66                         info( t('No results.') . EOL);
67                         return $o;
68                 }
69
70         }
71
72         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
73
74         if(! count($r)) {
75                 info( t('No results.') . EOL);
76                 return $o;
77         }
78
79         $maxpostperauthor = get_config('system','max_author_posts_community_page');
80
81         if ($maxpostperauthor != 0) {
82                 $count = 1;
83                 $previousauthor = "";
84                 $numposts = 0;
85                 $s = array();
86
87                 do {
88                         foreach ($r AS $row=>$item) {
89                                 if ($previousauthor == $item["author-link"])
90                                         ++$numposts;
91                                 else
92                                         $numposts = 0;
93
94                                 $previousauthor = $item["author-link"];
95
96                                 if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage']))
97                                         $s[] = $item;
98                         }
99                         if ((sizeof($s) < $a->pager['itemspage']))
100                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
101
102                 } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
103         } else
104                 $s = $r;
105
106         // we behave the same in message lists as the search module
107
108         $o .= conversation($a,$s,'community',$update);
109
110         if(!get_config('system', 'old_pager')) {
111                 $o .= alt_pager($a,count($r));
112         } else {
113                 $o .= paginate($a);
114         }
115
116         return $o;
117 }
118
119 function community_getitems($start, $itemspage) {
120         if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY)
121                 return(community_getpublicitems($start, $itemspage));
122
123         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
124                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
125                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
126                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
127                 `user`.`nickname`, `user`.`hidewall`
128                 FROM `thread` FORCE INDEX (`wall_private_received`)
129                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
130                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
131                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
132                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
133                 INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
134                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
135                 WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
136                 AND `thread`.`private` = 0 AND `thread`.`wall` = 1
137                 ORDER BY `thread`.`received` DESC LIMIT %d, %d ",
138                 intval($start),
139                 intval($itemspage)
140         );
141
142         return($r);
143
144 }
145
146 function community_getpublicitems($start, $itemspage) {
147         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
148                         `author-name` AS `name`, `owner-avatar` AS `photo`,
149                         `owner-link` AS `url`, `owner-avatar` AS `thumb`
150                 FROM `thread`
151                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
152                 WHERE `thread`.`uid` = 0
153                 ORDER BY `thread`.`created` DESC LIMIT %d, %d",
154                 intval($start),
155                 intval($itemspage)
156         );
157
158         return($r);
159 }