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