]> git.mxchange.org Git - friendica.git/blob - mod/community.php
move HTML to template and add an optional hint that a global community page shows...
[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 (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         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' => (Config::get('system', 'community_page_style') == CP_GLOBAL_COMMUNITY && Config::get('system', 'show_global_community_hint')),
91                 '$global_community_hint' => t("This comunity stream shows all public messages arriving on this node. They do not reflect the opinion of the nodes users.")
92         ));
93 }
94
95 function community_getitems($start, $itemspage) {
96         if (Config::get('system','community_page_style') == CP_GLOBAL_COMMUNITY) {
97                 return(community_getpublicitems($start, $itemspage));
98         }
99         $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
100                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
101                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
102                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
103                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''".
104                 item_joins()." AND `contact`.`self`
105                 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
106                 AND NOT `thread`.`private` AND `thread`.`wall`
107                 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
108         );
109
110         return dba::inArray($r);
111 }
112
113 function community_getpublicitems($start, $itemspage) {
114         $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
115                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins().
116                 "WHERE `thread`.`uid` = 0 AND `verb` = ?
117                 ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage),
118                 ACTIVITY_POST
119         );
120
121         return dba::inArray($r);
122 }