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 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);
28 require_once 'include/bbcode.php';
29 require_once 'include/security.php';
30 require_once 'include/conversation.php';
33 nav_set_selected('community');
36 if (Config::get('system', 'comment_public')) {
37 // check if we serve a mobile device and get the user settings
40 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network', 20);
42 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network', 40);
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;
51 $a->set_pager_itemspage($itemspage_network);
54 $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
56 if (!DBM::is_result($r)) {
57 info(t('No results.') . EOL);
61 $maxpostperauthor = Config::get('system','max_author_posts_community_page');
63 if ($maxpostperauthor != 0) {
70 foreach ($r AS $row=>$item) {
71 if ($previousauthor == $item["author-link"]) {
76 $previousauthor = $item["author-link"];
78 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
82 if (sizeof($s) < $a->pager['itemspage']) {
83 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
85 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
90 $o .= conversation($a, $s, 'community', $update);
92 $o .= alt_pager($a, count($r));
94 $t = get_markup_template("community.tpl");
95 return replace_macros($t, array(
97 '$header' => t("Community"),
98 '$show_global_community_hint' => false,
99 '$global_community_hint' => ''
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)
115 return dba::inArray($r);