4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Database\DBM;
8 function community_init(App $a) {
10 unset($_SESSION['theme']);
11 unset($_SESSION['mobile-theme']);
15 function community_content(App $a, $update = 0) {
18 if (Config::get('system','block_public') && !local_user() && !remote_user()) {
19 notice(t('Public access denied.') . EOL);
23 $page_style = Config::get('system','community_page_style');
26 $content = $a->argv[1];
28 // When only the global community is allowed, we use this as default
29 $content = $page_style == CP_GLOBAL_COMMUNITY ? 'global' : 'local';
32 if (!in_array($content, ['local', 'global'])) {
33 notice(t('Community option not available.') . EOL);
37 // Check if we are allowed to display the content to visitors
39 $available = $page_style == CP_USERS_AND_GLOBAL;
42 $available = ($page_style == CP_USERS_ON_SERVER) && ($content == 'local');
46 $available = ($page_style == CP_GLOBAL_COMMUNITY) && ($content == 'global');
50 notice(t('Not available.') . EOL);
55 require_once 'include/bbcode.php';
56 require_once 'include/security.php';
57 require_once 'include/conversation.php';
60 nav_set_selected('community');
63 if (Config::get('system', 'comment_public')) {
64 // check if we serve a mobile device and get the user settings
67 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network', 20);
69 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network', 40);
72 // now that we have the user settings, see if the theme forces
73 // a maximum item number which is lower then the user choice
74 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
75 $itemspage_network = $a->force_max_items;
78 $a->set_pager_itemspage($itemspage_network);
81 $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content);
83 if (!DBM::is_result($r)) {
84 info(t('No results.') . EOL);
88 $maxpostperauthor = Config::get('system','max_author_posts_community_page');
90 if (($maxpostperauthor != 0) && ($content == 'local')) {
97 foreach ($r AS $row=>$item) {
98 if ($previousauthor == $item["author-link"]) {
103 $previousauthor = $item["author-link"];
105 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
109 if (sizeof($s) < $a->pager['itemspage']) {
110 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content);
112 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
117 $o .= conversation($a, $s, 'community', $update);
119 $o .= alt_pager($a, count($r));
121 $t = get_markup_template("community.tpl");
122 return replace_macros($t, array(
124 '$header' => $content == 'global' ? t("Global Timeline") : t("Community"),
125 '$show_global_community_hint' => ($content == 'global') && Config::get('system', 'show_global_community_hint'),
126 '$global_community_hint' => t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.")
130 function community_getitems($start, $itemspage, $content) {
131 if ($content == 'local') {
132 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
133 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
134 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
135 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
136 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''".
137 item_joins()." AND `contact`.`self`
138 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
139 AND NOT `thread`.`private` AND `thread`.`wall`
140 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
142 return dba::inArray($r);
143 } elseif ($content == 'global') {
144 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
145 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins().
146 "WHERE `thread`.`uid` = 0 AND `verb` = ?
147 ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage),
150 return dba::inArray($r);
153 // Should never happen