]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Make the community pages available to local users every time
[friendica.git] / mod / community.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Database\DBM;
6
7 function community_init(App $a) {
8         if (!local_user()) {
9                 unset($_SESSION['theme']);
10                 unset($_SESSION['mobile-theme']);
11         }
12 }
13
14 function community_content(App $a, $update = 0) {
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 (!local_user() && !in_array(Config::get('system','community_page_style'), [CP_USERS_ON_SERVER, CP_USERS_AND_GLOBAL])) {
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         if (!$update) {
32                 nav_set_selected('community');
33         }
34
35         if (x($a->data,'search')) {
36                 $search = notags(trim($a->data['search']));
37         } else {
38                 $search = (x($_GET,'search') ? notags(trim(rawurldecode($_GET['search']))) : '');
39         }
40
41         // Here is the way permissions work in this module...
42         // Only public posts can be shown
43         // OR your own posts if you are a logged in member
44
45         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
46
47         if (!DBM::is_result($r)) {
48                 info(t('No results.') . EOL);
49                 return $o;
50         }
51
52         $maxpostperauthor = Config::get('system','max_author_posts_community_page');
53
54         if ($maxpostperauthor != 0) {
55                 $count = 1;
56                 $previousauthor = "";
57                 $numposts = 0;
58                 $s = array();
59
60                 do {
61                         foreach ($r AS $row=>$item) {
62                                 if ($previousauthor == $item["author-link"]) {
63                                         ++$numposts;
64                                 } else {
65                                         $numposts = 0;
66                                 }
67                                 $previousauthor = $item["author-link"];
68
69                                 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
70                                         $s[] = $item;
71                                 }
72                         }
73                         if (sizeof($s) < $a->pager['itemspage']) {
74                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
75                         }
76                 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
77         } else {
78                 $s = $r;
79         }
80         // we behave the same in message lists as the search module
81
82         $o .= conversation($a, $s, 'community', $update);
83
84         $o .= alt_pager($a, count($r));
85
86         $t = get_markup_template("community.tpl");
87         return replace_macros($t, array(
88                 '$content' => $o,
89                 '$header' => t("Community"),
90                 '$show_global_community_hint' => false,
91                 '$global_community_hint' => ''
92         ));
93 }
94
95 function community_getitems($start, $itemspage) {
96         $r = dba::p("SELECT ".item_fieldlists()." 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                 item_joins()." 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 ".intval($start).", ".intval($itemspage)
105         );
106
107         return dba::inArray($r);
108 }