]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Merge remote-tracking branch 'upstream/develop' into dba-2
[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         $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) && (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']) && (++$count < 50) && (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 = dba::p("SELECT ".item_fieldlists()." FROM `thread`
95                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
96                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
97                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
98                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''".
99                 item_joins()." AND `contact`.`self`
100                 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
101                 AND NOT `thread`.`private` AND `thread`.`wall`
102                 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
103         );
104
105         return dba::inArray($r);
106 }
107
108 function community_getpublicitems($start, $itemspage) {
109         $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
110                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins().
111                 "WHERE `thread`.`uid` = 0 AND `verb` = ?
112                 ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage),
113                 ACTIVITY_POST
114         );
115
116         return dba::inArray($r);
117 }