4 use Friendica\Core\Config;
5 use Friendica\Database\DBM;
7 function community_init(App $a) {
9 unset($_SESSION['theme']);
10 unset($_SESSION['mobile-theme']);
14 function community_content(App $a, $update = 0) {
17 if (Config::get('system','block_public') && !local_user() && !remote_user()) {
18 notice(t('Public access denied.') . EOL);
22 if (!in_array(Config::get('system','community_page_style'), [CP_USERS_ON_SERVER, CP_USERS_AND_GLOBAL])) {
23 notice(t('Not available.') . EOL);
27 require_once 'include/bbcode.php';
28 require_once 'include/security.php';
29 require_once 'include/conversation.php';
32 nav_set_selected('community');
35 if (x($a->data,'search')) {
36 $search = notags(trim($a->data['search']));
38 $search = (x($_GET,'search') ? notags(trim(rawurldecode($_GET['search']))) : '');
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
45 $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
47 if (!DBM::is_result($r)) {
48 info(t('No results.') . EOL);
52 $maxpostperauthor = Config::get('system','max_author_posts_community_page');
54 if ($maxpostperauthor != 0) {
61 foreach ($r AS $row=>$item) {
62 if ($previousauthor == $item["author-link"]) {
67 $previousauthor = $item["author-link"];
69 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
73 if (sizeof($s) < $a->pager['itemspage']) {
74 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
76 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
80 // we behave the same in message lists as the search module
82 $o .= conversation($a, $s, 'community', $update);
84 $o .= alt_pager($a, count($r));
86 $t = get_markup_template("community.tpl");
87 return replace_macros($t, array(
89 '$header' => t("Community"),
90 '$show_global_community_hint' => false,
91 '$global_community_hint' => ''
95 function community_getitems($start, $itemspage) {
96 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
97 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
98 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
99 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
100 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''".
101 item_joins()." AND `contact`.`self`
102 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
103 AND NOT `thread`.`private` AND `thread`.`wall`
104 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
107 return dba::inArray($r);