]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Merge pull request #3112 from Quix0r/rewrites/coding-convention
[friendica.git] / mod / community.php
1 <?php
2
3 function community_init(App $a) {
4         if (! local_user()) {
5                 unset($_SESSION['theme']);
6                 unset($_SESSION['mobile-theme']);
7         }
8
9
10 }
11
12
13 function community_content(App $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         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
52
53         if (! dbm::is_result($r)) {
54                 info( t('No results.') . EOL);
55                 return $o;
56         }
57
58         $maxpostperauthor = get_config('system','max_author_posts_community_page');
59
60         if ($maxpostperauthor != 0) {
61                 $count = 1;
62                 $previousauthor = "";
63                 $numposts = 0;
64                 $s = array();
65
66                 do {
67                         foreach ($r AS $row=>$item) {
68                                 if ($previousauthor == $item["author-link"])
69                                         ++$numposts;
70                                 else
71                                         $numposts = 0;
72
73                                 $previousauthor = $item["author-link"];
74
75                                 if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage']))
76                                         $s[] = $item;
77                         }
78                         if ((sizeof($s) < $a->pager['itemspage']))
79                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
80
81                 } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
82         } else {
83                 $s = $r;
84         }
85
86         // we behave the same in message lists as the search module
87
88         $o .= conversation($a, $s, 'community', $update);
89
90         $o .= alt_pager($a, count($r));
91
92         return $o;
93 }
94
95 function community_getitems($start, $itemspage) {
96         if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY)
97                 return(community_getpublicitems($start, $itemspage));
98
99         $r = qu("SELECT %s
100                 FROM `thread`
101                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
102                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
103                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
104                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
105                 %s AND `contact`.`self`
106                 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
107                 AND NOT `thread`.`private` AND `thread`.`wall`
108                 ORDER BY `thread`.`received` DESC LIMIT %d, %d",
109                 item_fieldlists(), item_joins(),
110                 intval($start), intval($itemspage)
111         );
112
113         return($r);
114
115 }
116
117 function community_getpublicitems($start, $itemspage) {
118
119         $r = qu("SELECT %s
120                 FROM `thread`
121                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s
122                 WHERE `thread`.`uid` = 0
123                 ORDER BY `thread`.`created` DESC LIMIT %d, %d",
124                 item_fieldlists(), item_joins(),
125                 intval($start), intval($itemspage)
126         );
127
128         return($r);
129 }