]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Use network paging
[friendica.git] / mod / community.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Database\DBM;
7
8 function community_init(App $a) {
9         if (!local_user()) {
10                 unset($_SESSION['theme']);
11                 unset($_SESSION['mobile-theme']);
12         }
13 }
14
15 function community_content(App $a, $update = 0) {
16         $o = '';
17
18         if (Config::get('system','block_public') && !local_user() && !remote_user()) {
19                 notice(t('Public access denied.') . EOL);
20                 return;
21         }
22
23         if (!local_user() && !in_array(Config::get('system','community_page_style'), [CP_USERS_ON_SERVER, CP_USERS_AND_GLOBAL])) {
24                 notice(t('Not available.') . EOL);
25                 return;
26         }
27
28         require_once 'include/bbcode.php';
29         require_once 'include/security.php';
30         require_once 'include/conversation.php';
31
32         if (!$update) {
33                 nav_set_selected('community');
34         }
35
36         if (Config::get('system', 'comment_public')) {
37                 // check if we serve a mobile device and get the user settings
38                 // accordingly
39                 if ($a->is_mobile) {
40                         $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network', 20);
41                 } else {
42                         $itemspage_network = PConfig::get(local_user(),'system','itemspage_network', 40);
43                 }
44
45                 // now that we have the user settings, see if the theme forces
46                 // a maximum item number which is lower then the user choice
47                 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
48                         $itemspage_network = $a->force_max_items;
49                 }
50
51                 $a->set_pager_itemspage($itemspage_network);
52         }
53
54         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
55
56         if (!DBM::is_result($r)) {
57                 info(t('No results.') . EOL);
58                 return $o;
59         }
60
61         $maxpostperauthor = Config::get('system','max_author_posts_community_page');
62
63         if ($maxpostperauthor != 0) {
64                 $count = 1;
65                 $previousauthor = "";
66                 $numposts = 0;
67                 $s = array();
68
69                 do {
70                         foreach ($r AS $row=>$item) {
71                                 if ($previousauthor == $item["author-link"]) {
72                                         ++$numposts;
73                                 } else {
74                                         $numposts = 0;
75                                 }
76                                 $previousauthor = $item["author-link"];
77
78                                 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
79                                         $s[] = $item;
80                                 }
81                         }
82                         if (sizeof($s) < $a->pager['itemspage']) {
83                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
84                         }
85                 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
86         } else {
87                 $s = $r;
88         }
89
90         $o .= conversation($a, $s, 'community', $update);
91
92         $o .= alt_pager($a, count($r));
93
94         $t = get_markup_template("community.tpl");
95         return replace_macros($t, array(
96                 '$content' => $o,
97                 '$header' => t("Community"),
98                 '$show_global_community_hint' => false,
99                 '$global_community_hint' => ''
100         ));
101 }
102
103 function community_getitems($start, $itemspage) {
104         $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
105                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
106                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
107                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
108                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''".
109                 item_joins()." AND `contact`.`self`
110                 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
111                 AND NOT `thread`.`private` AND `thread`.`wall`
112                 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
113         );
114
115         return dba::inArray($r);
116 }