]> git.mxchange.org Git - friendica.git/blob - mod/community.php
6d318a539ee7ac33f5fa6a17e0a7b3d1c83fa7d6
[friendica.git] / mod / community.php
1 <?php
2
3 use Friendica\Core\Config;
4
5 function community_init(App $a) {
6         if (! local_user()) {
7                 unset($_SESSION['theme']);
8                 unset($_SESSION['mobile-theme']);
9         }
10 }
11
12 function community_content(App $a, $update = 0) {
13
14         $o = '';
15
16         if ((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
17                 notice( t('Public access denied.') . EOL);
18                 return;
19         }
20
21         if (Config::get('system','community_page_style') == CP_NO_COMMUNITY_PAGE) {
22                 notice( t('Not available.') . EOL);
23                 return;
24         }
25
26         require_once("include/bbcode.php");
27         require_once('include/security.php');
28         require_once('include/conversation.php');
29
30
31         $o .= '<h3>' . t('Community') . '</h3>';
32         if (! $update) {
33                 nav_set_selected('community');
34         }
35
36         if (x($a->data,'search')) {
37                 $search = notags(trim($a->data['search']));
38         } else {
39                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
40         }
41
42         // Here is the way permissions work in this module...
43         // Only public posts can be shown
44         // OR your own posts if you are a logged in member
45
46         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
47
48         if (! dbm::is_result($r)) {
49                 info( t('No results.') . EOL);
50                 return $o;
51         }
52
53         $maxpostperauthor = Config::get('system','max_author_posts_community_page');
54
55         if ($maxpostperauthor != 0) {
56                 $count = 1;
57                 $previousauthor = "";
58                 $numposts = 0;
59                 $s = array();
60
61                 do {
62                         foreach ($r AS $row=>$item) {
63                                 if ($previousauthor == $item["author-link"]) {
64                                         ++$numposts;
65                                 } else {
66                                         $numposts = 0;
67                                 }
68                                 $previousauthor = $item["author-link"];
69
70                                 if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage'])) {
71                                         $s[] = $item;
72                                 }
73                         }
74                         if ((sizeof($s) < $a->pager['itemspage'])) {
75                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
76                         }
77                 } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
78         } else {
79                 $s = $r;
80         }
81         // we behave the same in message lists as the search module
82
83         $o .= conversation($a, $s, 'community', $update);
84
85         $o .= alt_pager($a, count($r));
86
87         return $o;
88 }
89
90 function community_getitems($start, $itemspage) {
91         if (Config::get('system','community_page_style') == CP_GLOBAL_COMMUNITY) {
92                 return(community_getpublicitems($start, $itemspage));
93         }
94         $r = qu("SELECT %s
95                 FROM `thread`
96                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
97                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
98                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
99                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
100                 %s AND `contact`.`self`
101                 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
102                 AND NOT `thread`.`private` AND `thread`.`wall`
103                 ORDER BY `thread`.`received` DESC LIMIT %d, %d",
104                 item_fieldlists(), item_joins(),
105                 intval($start), intval($itemspage)
106         );
107
108         return($r);
109
110 }
111
112 function community_getpublicitems($start, $itemspage) {
113
114         $r = qu("SELECT %s
115                 FROM `thread`
116                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s
117                 WHERE `thread`.`uid` = 0
118                 ORDER BY `thread`.`created` DESC LIMIT %d, %d",
119                 item_fieldlists(), item_joins(),
120                 intval($start), intval($itemspage)
121         );
122
123         return($r);
124 }