From 5afedb28d4387eef580f7a6602016cc676d8d9e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Dec 2017 07:33:51 +0000 Subject: [PATCH 01/18] You can now comment on the community page --- include/conversation.php | 12 +++++++----- mod/community.php | 29 +++++++++++++++++++++++++++-- src/Object/Thread.php | 4 ++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index ee68d8f5c9..0fc6a418d7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -574,10 +574,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { } } elseif ($mode === 'community') { $profile_owner = 0; - if (!$update) { - $live_update_div = '
' . "\r\n" - . "\r\n"; - } +// if (!$update) { +// $live_update_div = '
' . "\r\n" +// . "\r\n"; +// } } elseif ($mode === 'search') { $live_update_div = '' . "\r\n"; } @@ -617,8 +617,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { } else { $writable = false; } + $writable = true; - if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if ($mode === 'network-new' || $mode === 'search') { +// || $mode === 'community') { /* * "New Item View" on network page or search page results diff --git a/mod/community.php b/mod/community.php index df21263278..10852b49e2 100644 --- a/mod/community.php +++ b/mod/community.php @@ -114,9 +114,34 @@ 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`.`created` DESC LIMIT ".intval($start).", ".intval($itemspage), + ORDER BY `thread`.`commented` DESC LIMIT ".intval($start).", ".intval($itemspage), ACTIVITY_POST ); - return dba::inArray($r); + 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/Object/Thread.php b/src/Object/Thread.php index 2872fe4a02..a03bae6e9d 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -66,6 +66,10 @@ class Thread extends BaseObject $this->profile_owner = $a->profile['uid']; $this->writable = can_write_wall($a, $this->profile_owner) || $writable; break; + case 'community': + $this->profile_owner = local_user(); + $this->writable = $writable; + break; default: logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); return false; From 3ffea2cd2cb0ed9a5283bc285e521aaf74789e80 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 Jan 2018 13:27:43 +0000 Subject: [PATCH 02/18] 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 73a1ef1007..3af6b76451 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 58ec150e7a..3a32c8e7d8 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 a20646cb0f..e1995016ba 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 9408aa31c6..bef912cd50 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 10852b49e2..1a110a3b05 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 0000000000..f5470c2935 --- /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 dd32fc3e3e..7048414b49 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 b6513e0fe8..35611ca10a 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 a47dca3902..84462b0701 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 819a7c75c3..aa6db99c15 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 2fab623530..b9c8d36c5d 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 cc9110a27f..e3edf59e8f 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 eb0cbbac65..cfc46f1d5a 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 281714e3ed..5adcff7e29 100644 --- a/view/theme/vier/templates/nav.tpl +++ b/view/theme/vier/templates/nav.tpl @@ -39,6 +39,13 @@ {{/if}} + {{if $nav.global}} + + {{/if}} + {{/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 cfc46f1d5a..f0aacd4261 100644 --- a/view/theme/quattro/templates/nav.tpl +++ b/view/theme/quattro/templates/nav.tpl @@ -20,12 +20,6 @@ {{/if}} - {{if $nav.global}} - - {{/if}} - {{if $nav.community}} {{/if}} - {{if $nav.global}} - - {{/if}} -