X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fcommunity.php;h=d1432b7bbbf5c19dbd780a6f7eecbc59e7123063;hb=7c73e8634c954cc2bd0d1138729459d7d5090f62;hp=5f0bd34a1389f5709d84e5b3d3cfc4e1ebbc2d02;hpb=824262b8248701b9f0bd33168e73108eb457c464;p=friendica.git diff --git a/mod/community.php b/mod/community.php index 5f0bd34a13..d1432b7bbb 100644 --- a/mod/community.php +++ b/mod/community.php @@ -5,11 +5,12 @@ use Friendica\App; use Friendica\Content\Nav; -use Friendica\Core\Acl; +use Friendica\Core\ACL; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; -use Friendica\Database\DBM; +use Friendica\Database\DBA; +use Friendica\Model\Contact; function community_init(App $a) { @@ -30,6 +31,30 @@ function community_content(App $a, $update = 0) $page_style = Config::get('system', 'community_page_style'); + if ($page_style == CP_NO_INTERNAL_COMMUNITY) { + notice(L10n::t('Access denied.') . EOL); + return; + } + + $accounttype = null; + + if ($a->argc > 2) { + switch ($a->argv[2]) { + case 'person': + $accounttype = Contact::ACCOUNT_TYPE_PERSON; + break; + case 'organisation': + $accounttype = Contact::ACCOUNT_TYPE_ORGANISATION; + break; + case 'news': + $accounttype = Contact::ACCOUNT_TYPE_NEWS; + break; + case 'community': + $accounttype = Contact::ACCOUNT_TYPE_COMMUNITY; + break; + } + } + if ($a->argc > 1) { $content = $a->argv[1]; } else { @@ -106,7 +131,7 @@ function community_content(App $a, $update = 0) 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'), - 'acl' => Acl::getFullSelectorHTML($a->user, true), + 'acl' => ACL::getFullSelectorHTML($a->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), @@ -128,11 +153,11 @@ function community_content(App $a, $update = 0) $itemspage_network = $a->force_max_items; } - $a->set_pager_itemspage($itemspage_network); + $a->setPagerItemsPage($itemspage_network); - $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content); + $r = community_getitems($a->pager['start'], $a->pager['itemspage'], $content, $accounttype); - if (!DBM::is_result($r)) { + if (!DBA::isResult($r)) { info(L10n::t('No results.') . EOL); return $o; } @@ -159,14 +184,14 @@ function community_content(App $a, $update = 0) } } if (count($s) < $a->pager['itemspage']) { - $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content); + $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage'], $content, $accounttype); } } while ((count($s) < $a->pager['itemspage']) && ( ++$count < 50) && (count($r) > 0)); } else { $s = $r; } - $o .= conversation($a, $s, 'community', $update); + $o .= conversation($a, $s, 'community', $update, false, 'commented', local_user()); if (!$update) { $o .= alt_pager($a, count($r)); @@ -181,24 +206,41 @@ function community_content(App $a, $update = 0) ]); } -function community_getitems($start, $itemspage, $content) +function community_getitems($start, $itemspage, $content, $accounttype) { if ($content == 'local') { - $r = dba::p("SELECT `item`.`uri`, `item`.`author-link` FROM `thread` + if (!is_null($accounttype)) { + $sql_accounttype = " AND `user`.`account-type` = ?"; + $values = [$accounttype, $start, $itemspage]; + } else { + $sql_accounttype = ""; + $values = [$start, $itemspage]; + } + + $r = DBA::p("SELECT `item`.`uri`, `author`.`url` AS `author-link` FROM `thread` INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` - AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin` - ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage) - ); - return dba::inArray($r); + AND NOT `thread`.`private` AND `thread`.`wall` AND `thread`.`origin` $sql_accounttype + ORDER BY `thread`.`commented` DESC LIMIT ?, ?", $values); + return DBA::toArray($r); } elseif ($content == 'global') { - $r = dba::p("SELECT `uri` FROM `thread` + if (!is_null($accounttype)) { + $sql_accounttype = " AND `owner`.`contact-type` = ?"; + $values = [$accounttype, $start, $itemspage]; + } else { + $sql_accounttype = ""; + $values = [$start, $itemspage]; + } + + $r = DBA::p("SELECT `uri` FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` - INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` - WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked` - ORDER BY `thread`.`commented` DESC LIMIT " . intval($start) . ", " . intval($itemspage)); - return dba::inArray($r); + INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` + INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` + WHERE `thread`.`uid` = 0 AND NOT `author`.`hidden` AND NOT `author`.`blocked` $sql_accounttype + ORDER BY `thread`.`commented` DESC LIMIT ?, ?", $values); + return DBA::toArray($r); } // Should never happen