4 use Friendica\Core\Config;
6 function community_init(App $a) {
8 unset($_SESSION['theme']);
9 unset($_SESSION['mobile-theme']);
13 function community_content(App $a, $update = 0) {
16 if ((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
17 notice( t('Public access denied.') . EOL);
21 if (Config::get('system','community_page_style') == CP_NO_COMMUNITY_PAGE) {
22 notice( t('Not available.') . EOL);
26 require_once("include/bbcode.php");
27 require_once('include/security.php');
28 require_once('include/conversation.php');
31 $o .= '<h3>' . t('Community') . '</h3>';
33 nav_set_selected('community');
36 if (x($a->data,'search')) {
37 $search = notags(trim($a->data['search']));
39 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
42 // Here is the way permissions work in this module...
43 // Only public posts can be shown
44 // OR your own posts if you are a logged in member
46 $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
48 if (! dbm::is_result($r)) {
49 info( t('No results.') . EOL);
53 $maxpostperauthor = Config::get('system','max_author_posts_community_page');
55 if ($maxpostperauthor != 0) {
62 foreach ($r AS $row=>$item) {
63 if ($previousauthor == $item["author-link"]) {
68 $previousauthor = $item["author-link"];
70 if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
74 if ((sizeof($s) < $a->pager['itemspage'])) {
75 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
77 } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
81 // we behave the same in message lists as the search module
83 $o .= conversation($a, $s, 'community', $update);
85 $o .= alt_pager($a, count($r));
90 function community_getitems($start, $itemspage) {
91 if (Config::get('system','community_page_style') == CP_GLOBAL_COMMUNITY) {
92 return(community_getpublicitems($start, $itemspage));
94 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
95 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall`
96 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
97 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
98 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''".
99 item_joins()." AND `contact`.`self`
100 WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
101 AND NOT `thread`.`private` AND `thread`.`wall`
102 ORDER BY `thread`.`received` DESC LIMIT ".intval($start).", ".intval($itemspage)
105 return dba::inArray($r);
108 function community_getpublicitems($start, $itemspage) {
109 $r = dba::p("SELECT ".item_fieldlists()." FROM `thread`
110 INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins().
111 "WHERE `thread`.`uid` = 0 AND `verb` = ?
112 ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage),
116 return dba::inArray($r);