Merge pull request #4160 from annando/community

We now are having a global items page
This commit is contained in:
Hypolite Petovan 2018-01-04 11:50:45 -05:00 committed by GitHub
commit 6e71a84075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 213 additions and 76 deletions

View file

@ -490,7 +490,6 @@ function item_condition() {
*
*/
function conversation(App $a, $items, $mode, $update, $preview = false) {
require_once 'include/bbcode.php';
require_once 'mod/proxy.php';
@ -575,10 +574,14 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
. " var profile_page = 1; </script>";
}
} elseif ($mode === 'community') {
if (!$community_readonly) {
$items = community_add_items($items);
}
$profile_owner = 0;
if (!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
. "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
} elseif ($mode === 'search') {
$live_update_div = '<div id="live-search"></div>' . "\r\n";
@ -613,14 +616,25 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$page_template = get_markup_template("conversation.tpl");
if ($items && count($items)) {
$community_readonly = ($mode === 'community');
// Currently behind a config value. This allows the commenting and sharing of every public item.
if (Config::get('system', 'comment_public') && local_user()) {
$writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA));
if (Config::get('system', 'comment_public')) {
if ($mode === 'community') {
$community_readonly = false;
$writable = true;
} else {
$writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA));
}
} else {
$writable = false;
}
if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
if (!local_user()) {
$writable = false;
}
if ($mode === 'network-new' || $mode === 'search' || $community_readonly) {
/*
* "New Item View" on network page or search page results
@ -891,6 +905,55 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
return $o;
}
/**
* @brief Add comments to top level entries that had been fetched before
*
* The system will fetch the comments for the local user whenever possible.
* This behaviour is currently needed to allow commenting on Friendica posts.
*
* @param array $parents Parent items
*
* @return array items with parents and comments
*/
function community_add_items($parents) {
$max_comments = Config::get("system", "max_comments", 100);
$items = array();
foreach ($parents AS $parent) {
$thread_items = dba::p(item_query()." AND `item`.`uid` = ?
AND `item`.`parent-uri` = ?
ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
local_user(),
$parent['uri']
);
$comments = dba::inArray($thread_items);
if (count($comments) == 0) {
$thread_items = dba::p(item_query()." AND `item`.`uid` = 0
AND `item`.`parent-uri` = ?
ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
$parent['uri']
);
$comments = dba::inArray($thread_items);
}
if (count($comments) != 0) {
$items = array_merge($items, $comments);
}
}
foreach ($items as $index => $item) {
if ($item['uid'] == 0) {
$items[$index]['writable'] = in_array($item['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS]);
}
}
$items = conv_sort($items, "`commented`");
return $items;
}
function best_link_url($item, &$sparkle, $url = '') {
$best_url = '';

View file

@ -147,10 +147,10 @@ function nav_info(App $a)
if (strlen($gdir)) {
$gdirpath = zrl($gdir, true);
}
} elseif (Config::get('system', 'community_page_style') == CP_USERS_ON_SERVER) {
$nav['community'] = array('community', t('Community'), '', t('Conversations on this site'));
} elseif (Config::get('system', 'community_page_style') == CP_GLOBAL_COMMUNITY) {
$nav['community'] = array('community', t('Community'), '', t('Conversations on the network'));
}
if (local_user() || Config::get('system', 'community_page_style') != CP_NO_COMMUNITY_PAGE) {
$nav['community'] = array('community', t('Community'), '', t('Conversations on this and other servers'));
}
if (local_user()) {
@ -230,6 +230,7 @@ function nav_info(App $a)
function nav_set_selected($item){
$a = get_app();
$a->nav_sel = array(
'global' => null,
'community' => null,
'network' => null,
'home' => null,