From 3ffea2cd2cb0ed9a5283bc285e521aaf74789e80 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 Jan 2018 13:27:43 +0000 Subject: [PATCH] We now have a global page for all global entries from the network. --- boot.php | 3 +- include/nav.php | 11 +- index.php | 10 +- mod/admin.php | 3 +- mod/community.php | 69 ++------- src/Module/Global.php | 164 ++++++++++++++++++++++ src/Object/Post.php | 6 + view/templates/nav.tpl | 3 + view/theme/duepuntozero/templates/nav.tpl | 3 + view/theme/frio/js/theme.js | 13 ++ view/theme/frio/templates/nav.tpl | 4 + view/theme/frost-mobile/templates/nav.tpl | 6 + view/theme/frost/templates/nav.tpl | 6 + view/theme/quattro/templates/nav.tpl | 17 ++- view/theme/smoothly/templates/nav.tpl | 10 +- view/theme/vier/templates/nav.tpl | 7 + 16 files changed, 264 insertions(+), 71 deletions(-) create mode 100644 src/Module/Global.php diff --git a/boot.php b/boot.php index 73a1ef100..3af6b7645 100644 --- a/boot.php +++ b/boot.php @@ -228,9 +228,10 @@ define('ACCOUNT_TYPE_COMMUNITY', 3); * Type of the community page * @{ */ -define('CP_NO_COMMUNITY_PAGE', -1); +define('CP_NO_COMMUNITY_PAGE', -1); define('CP_USERS_ON_SERVER', 0); define('CP_GLOBAL_COMMUNITY', 1); +define('CP_USERS_AND_GLOBAL', 2); /** * @} */ diff --git a/include/nav.php b/include/nav.php index 58ec150e7..3a32c8e7d 100644 --- a/include/nav.php +++ b/include/nav.php @@ -147,10 +147,14 @@ function nav_info(App $a) if (strlen($gdir)) { $gdirpath = zrl($gdir, true); } - } elseif (Config::get('system', 'community_page_style') == CP_USERS_ON_SERVER) { + } + + if (in_array(Config::get('system', 'community_page_style'), [CP_USERS_ON_SERVER, CP_USERS_AND_GLOBAL])) { $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 (in_array(Config::get('system', 'community_page_style'), [CP_GLOBAL_COMMUNITY, CP_USERS_AND_GLOBAL])) { + $nav['global'] = array('global', t('Global Timeline'), '', t('Conversations on the network')); } if (local_user()) { @@ -230,6 +234,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, diff --git a/index.php b/index.php index a20646cb0..e1995016b 100644 --- a/index.php +++ b/index.php @@ -253,9 +253,13 @@ if (strlen($a->module)) { } // Controller class routing - if (! $a->module_loaded && class_exists('Friendica\\Module\\' . ucfirst($a->module))) { - $a->module_class = 'Friendica\\Module\\' . ucfirst($a->module); - $a->module_loaded = true; + $classes = ['Friendica\\Module\\' . ucfirst($a->module), 'Friendica\\Module\\' . ucfirst($a->module) . 'Module']; + foreach ($classes as $class) { + if (!$a->module_loaded && class_exists($class)) { + $a->module_class = $class; + $a->module_loaded = true; + break; + } } /** diff --git a/mod/admin.php b/mod/admin.php index 9408aa31c..bef912cd5 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1176,7 +1176,8 @@ function admin_page_site(App $a) $community_page_style_choices = array( CP_NO_COMMUNITY_PAGE => t("No community page"), CP_USERS_ON_SERVER => t("Public postings from users of this site"), - CP_GLOBAL_COMMUNITY => t("Global community page") + CP_GLOBAL_COMMUNITY => t("Global community page"), + CP_USERS_AND_GLOBAL => t("Public user postings and global postings") ); /* OStatus conversation poll choices */ diff --git a/mod/community.php b/mod/community.php index 10852b49e..1a110a3b0 100644 --- a/mod/community.php +++ b/mod/community.php @@ -5,7 +5,7 @@ use Friendica\Core\Config; use Friendica\Database\DBM; function community_init(App $a) { - if (! local_user()) { + if (!local_user()) { unset($_SESSION['theme']); unset($_SESSION['mobile-theme']); } @@ -14,28 +14,28 @@ function community_init(App $a) { function community_content(App $a, $update = 0) { $o = ''; - if ((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) { - notice( t('Public access denied.') . EOL); + if (Config::get('system','block_public') && !local_user() && !remote_user()) { + notice(t('Public access denied.') . EOL); return; } - if (Config::get('system','community_page_style') == CP_NO_COMMUNITY_PAGE) { - notice( t('Not available.') . EOL); + if (!in_array(Config::get('system','community_page_style'), [CP_USERS_ON_SERVER, CP_USERS_AND_GLOBAL])) { + notice(t('Not available.') . EOL); return; } - require_once("include/bbcode.php"); - require_once('include/security.php'); - require_once('include/conversation.php'); + require_once 'include/bbcode.php'; + require_once 'include/security.php'; + require_once 'include/conversation.php'; - if (! $update) { + if (!$update) { nav_set_selected('community'); } if (x($a->data,'search')) { $search = notags(trim($a->data['search'])); } else { - $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); + $search = (x($_GET,'search') ? notags(trim(rawurldecode($_GET['search']))) : ''); } // Here is the way permissions work in this module... @@ -44,8 +44,8 @@ function community_content(App $a, $update = 0) { $r = community_getitems($a->pager['start'], $a->pager['itemspage']); - if (! DBM::is_result($r)) { - info( t('No results.') . EOL); + if (!DBM::is_result($r)) { + info(t('No results.') . EOL); return $o; } @@ -70,7 +70,7 @@ function community_content(App $a, $update = 0) { $s[] = $item; } } - if ((sizeof($s) < $a->pager['itemspage'])) { + if (sizeof($s) < $a->pager['itemspage']) { $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']); } } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0)); @@ -87,15 +87,12 @@ function community_content(App $a, $update = 0) { return replace_macros($t, array( '$content' => $o, '$header' => t("Community"), - '$show_global_community_hint' => (Config::get('system', 'community_page_style') == CP_GLOBAL_COMMUNITY && Config::get('system', 'show_global_community_hint')), - '$global_community_hint' => t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.") + '$show_global_community_hint' => false, + '$global_community_hint' => '' )); } function community_getitems($start, $itemspage) { - if (Config::get('system','community_page_style') == CP_GLOBAL_COMMUNITY) { - return(community_getpublicitems($start, $itemspage)); - } $r = dba::p("SELECT ".item_fieldlists()." FROM `thread` INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` @@ -109,39 +106,3 @@ function community_getitems($start, $itemspage) { return dba::inArray($r); } - -function community_getpublicitems($start, $itemspage) { - $r = dba::p("SELECT ".item_fieldlists()." FROM `thread` - INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins(). - "WHERE `thread`.`uid` = 0 AND `verb` = ? - ORDER BY `thread`.`commented` DESC LIMIT ".intval($start).", ".intval($itemspage), - ACTIVITY_POST - ); - - while ($rr = dba::fetch($r)) { - if (!in_array($rr['item_id'], $parents_arr)) { - $parents_arr[] = $rr['item_id']; - } - } - - dba::close(); - - $max_comments = Config::get("system", "max_comments", 100); - - $items = array(); - - foreach ($parents_arr AS $parents) { - $thread_items = dba::p(item_query()." AND `item`.`uid` = 0 - AND `item`.`parent` = ? - ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), - $parents - ); - - if (DBM::is_result($thread_items)) { - $items = array_merge($items, dba::inArray($thread_items)); - } - } - $items = conv_sort($items, "`commented`"); - - return $items; -} diff --git a/src/Module/Global.php b/src/Module/Global.php new file mode 100644 index 000000000..f5470c293 --- /dev/null +++ b/src/Module/Global.php @@ -0,0 +1,164 @@ +data,'search')) { + $search = notags(trim($a->data['search'])); + } else { + $search = (x($_GET,'search') ? notags(trim(rawurldecode($_GET['search']))) : ''); + } + + // Here is the way permissions work in this module... + // Only public posts can be shown + // OR your own posts if you are a logged in member + + $r = self::getPublicItems($a->pager['start'], $a->pager['itemspage']); + + if (!DBM::is_result($r)) { + info(t('No results.') . EOL); + return $o; + } + + $maxpostperauthor = Config::get('system','max_author_posts_community_page'); + + if ($maxpostperauthor != 0) { + $count = 1; + $previousauthor = ""; + $numposts = 0; + $s = array(); + + do { + foreach ($r AS $row=>$item) { + if ($previousauthor == $item["author-link"]) { + ++$numposts; + } else { + $numposts = 0; + } + $previousauthor = $item["author-link"]; + + if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) { + $s[] = $item; + } + } + if (sizeof($s) < $a->pager['itemspage']) { + $r = self::getPublicItems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']); + } + } while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0)); + } else { + $s = $r; + } + // we behave the same in message lists as the search module + + $o .= conversation($a, $s, 'community', $update); + + $o .= alt_pager($a, count($r)); + + $t = get_markup_template("community.tpl"); + return replace_macros($t, array( + '$content' => $o, + '$header' => t("Global Timeline"), + '$show_global_community_hint' => Config::get('system', 'show_global_community_hint'), + '$global_community_hint' => t("This community stream shows all public posts received by this node. They may not reflect the opinions of this node’s users.") + )); + } + + private static function getPublicItems($start, $itemspage) { + $r = dba::p("SELECT ".item_fieldlists()." FROM `thread` + INNER JOIN `item` ON `item`.`id` = `thread`.`iid` ".item_joins(). + "WHERE `thread`.`uid` = 0 AND `verb` = ? + ORDER BY `thread`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage), + ACTIVITY_POST + ); + + return dba::inArray($r); + + // Currently deactivated + $parents_arr = []; + + while ($rr = dba::fetch($r)) { + if (!in_array($rr['item_id'], $parents_arr)) { + $parents_arr[] = $rr['item_id']; + } + } + + dba::close($r); + + $max_comments = Config::get("system", "max_comments", 100); + + $items = array(); + + foreach ($parents_arr AS $parents) { + $thread_items = dba::p(item_query()." AND `item`.`uid` = 0 + AND `item`.`parent` = ? + ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), + $parents + ); + + if (DBM::is_result($thread_items)) { + $items = array_merge($items, dba::inArray($thread_items)); + } + } + + foreach ($items as $index => $item) { + $items[$index]['writable'] = in_array($item['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS]); + if ($item['network'] == NETWORK_DFRN) { + $fields = ['id', 'writable', 'self']; + $condition = ['nurl' => normalise_link($item['author-link']), 'uid' => local_user()]; + $contact = dba::select('contact', $fields, $condition, ['limit' => 1]); + if (DBM::is_result($contact)) { + $items[$index]['contact-id'] = $contact['id']; + $items[$index]['cid'] = $contact['id']; + $items[$index]['writable'] = $contact['writable']; + $items[$index]['self'] = $contact['self']; + } + } + } + + $items = conv_sort($items, "`commented`"); + + return $items; + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index dd32fc3e3..7048414b4 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -322,6 +322,12 @@ class Post extends BaseObject unset($buttons["like"]); } + // If a contact isn't writable, we cannot send a like or dislike to it + if (!$item['writable']) { + unset($buttons["like"]); + unset($buttons["dislike"]); + } + $tmp_item = array( 'template' => $this->getTemplate(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), diff --git a/view/templates/nav.tpl b/view/templates/nav.tpl index b6513e0fe..35611ca10 100644 --- a/view/templates/nav.tpl +++ b/view/templates/nav.tpl @@ -31,6 +31,9 @@ {{if $nav.community}} {{$nav.community.1}} {{/if}} + {{if $nav.global}} + {{$nav.global.1}} + {{/if}} {{if $nav.introductions}} {{$nav.introductions.1}} diff --git a/view/theme/duepuntozero/templates/nav.tpl b/view/theme/duepuntozero/templates/nav.tpl index a47dca390..84462b070 100644 --- a/view/theme/duepuntozero/templates/nav.tpl +++ b/view/theme/duepuntozero/templates/nav.tpl @@ -31,6 +31,9 @@ {{if $nav.community}} {{$nav.community.1}} {{/if}} + {{if $nav.global}} + {{$nav.global.1}} + {{/if}} {{if $nav.introductions}} {{$nav.introductions.1}} diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index 819a7c75c..aa6db99c1 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -206,6 +206,19 @@ $(document).ready(function(){ $("#topbar-second > .container > #tabmenu").append(newText); } + if( $(".global-content-wrapper").length) { + // get the heading element + var heading = $(".global-content-wrapper > h3").first(); + // get the text of the heading + var headingContent = heading.text(); + // create a new element with the content of the heading + var newText = '

'+headingContent+'

'; + // remove the old heading element + heading.remove(), + // put the new element to the second nav bar + $("#topbar-second > .container > #tabmenu").append(newText); + } + // Dropdown menus with the class "dropdown-head" will display the active tab // as button text $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){ diff --git a/view/theme/frio/templates/nav.tpl b/view/theme/frio/templates/nav.tpl index 2fab62353..b9c8d36c5 100644 --- a/view/theme/frio/templates/nav.tpl +++ b/view/theme/frio/templates/nav.tpl @@ -50,6 +50,10 @@ {{if $nav.community}} {{/if}} + + {{if $nav.global}} + + {{/if}} {{/if}} + + {{if $nav.global}} +
  • + {{$nav.global.1}} +
  • + {{/if}} diff --git a/view/theme/frost/templates/nav.tpl b/view/theme/frost/templates/nav.tpl index cc9110a27..e3edf59e8 100644 --- a/view/theme/frost/templates/nav.tpl +++ b/view/theme/frost/templates/nav.tpl @@ -130,6 +130,12 @@ {{$nav.community.1}} {{/if}} + + {{if $nav.global}} +
  • + {{$nav.global.1}} +
  • + {{/if}} diff --git a/view/theme/quattro/templates/nav.tpl b/view/theme/quattro/templates/nav.tpl index eb0cbbac6..cfc46f1d5 100644 --- a/view/theme/quattro/templates/nav.tpl +++ b/view/theme/quattro/templates/nav.tpl @@ -19,26 +19,33 @@ {{/if}} - + + {{if $nav.global}} + + {{/if}} + {{if $nav.community}} {{/if}} - + {{if $nav.network}} {{/if}} + {{if $nav.home}} {{/if}} - + {{if $nav.introductions}} {{/if}} - + {{if $nav.messages}} {{/if}} - - {{if $nav.notifications}}
  • {{$nav.network.1}}
  • {{/if}} - {{if $nav.community}} -
  • {{$nav.community.1}}
  • - {{/if}} + {{if $nav.community}} +
  • {{$nav.community.1}}
  • + {{/if}} + + {{if $nav.global}} +
  • {{$nav.global.1}}
  • + {{/if}}
  • {{$nav.search.1}}
  • {{$nav.directory.1}}
  • diff --git a/view/theme/vier/templates/nav.tpl b/view/theme/vier/templates/nav.tpl index 281714e3e..5adcff7e2 100644 --- a/view/theme/vier/templates/nav.tpl +++ b/view/theme/vier/templates/nav.tpl @@ -39,6 +39,13 @@ {{/if}} + {{if $nav.global}} + + {{/if}} +