<?php
-
+/**
+ * @file mod/network.php
+ */
use Friendica\App;
+use Friendica\Content\Feature;
+use Friendica\Content\ForumManager;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
-use Friendica\Object\Contact;
+use Friendica\Model\Contact;
+use Friendica\Model\Group;
+use Friendica\Module\Login;
require_once 'include/conversation.php';
-require_once 'include/group.php';
require_once 'include/contact_widgets.php';
require_once 'include/items.php';
-require_once 'include/ForumManager.php';
require_once 'include/acl_selectors.php';
function network_init(App $a) {
}
$is_a_date_query = false;
+
+ $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
+
+ $cid = 0;
if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
$cid = $_GET['cid'];
$_GET['nets'] = 'all';
-
+ $group_id = 0;
}
+ PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
+
if ($a->argc > 1) {
for ($x = 1; $x < $a->argc; $x ++) {
if (is_a_date_arg($a->argv[$x])) {
unset($_GET['nets']);
}
- $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
-
- PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
if (!x($a->page, 'aside')) {
$a->page['aside'] = '';
}
- $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
- $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
+ $a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? Group::sidebarWidget('network/0','network','standard',$group_id) : '');
+ $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
$a->page['aside'] .= posted_date_widget('network',local_user(),false);
$a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
$a->page['aside'] .= saved_searches($search);
function saved_searches($search) {
- if (!feature_enabled(local_user(),'savedsearch')) {
+ if (!Feature::isEnabled(local_user(),'savedsearch')) {
return '';
}
// Set this so that the conversation function can find out contact info for our wall-wall items
$a->page_contact = $a->contact;
- $o .= conversation($a, $items, $mode, $update);
+ $o = conversation($a, $items, $mode, $update);
if (!$update) {
if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
function network_content(App $a, $update = 0) {
if (!local_user()) {
- $_SESSION['return_url'] = $a->query_string;
- return login(false);
+ return Login::form();
}
/// @TODO Is this really necessary? $a is already available to hooks
'bang' => '',
'visitor' => 'block',
'profile_uid' => local_user(),
- 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
'content' => '',
);
- $o .= status_editor($a,$x);
+ $o .= status_editor($a, $x);
if (!Config::get('theme','hide_eventlist')) {
$o .= get_birthdays();
$o .= $tabs;
if ($group) {
- if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
- notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
+ if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
+ notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
"Warning: This group contains %s members from a network that doesn't allow non public messages.",
- $t), $t).EOL);
+ $t) . EOL);
notice(t("Messages in this group won't be send to these receivers.").EOL);
}
}
if ($cid) {
// If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
- $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
- $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
+ $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
+ $contact = dba::selectFirst('contact', ['addr', 'nick'], $condition);
if (DBM::is_result($contact)) {
if ($contact["addr"] != '') {
$content = "!".$contact["addr"];
'bang' => (($group || $cid || $nets) ? '!' : ''),
'visitor' => 'block',
'profile_uid' => local_user(),
- 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
'content' => $content,
);
- $o .= status_editor($a,$x);
-
+ $o .= status_editor($a, $x);
}
// We don't have to deal with ACLs on this page. You're looking at everything
$sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
if ($group) {
- $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
+ $r = dba::selectFirst('group', ['name'], ['id' => $group, 'uid' => $_SESSION['uid']]);
if (!DBM::is_result($r)) {
if ($update)
killme();
// NOTREACHED
}
- $contacts = expand_groups(array($group));
+ $contacts = Group::expand(array($group));
if ((is_array($contacts)) && count($contacts)) {
$contact_str_self = "";
$contact_str = implode(',',$contacts);
- $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
+ $self = dba::selectFirst('contact', ['id'], ['uid' => $_SESSION['uid'], 'self' => true]);
if (DBM::is_result($self)) {
$contact_str_self = $self["id"];
}
}
$o = replace_macros(get_markup_template("section_title.tpl"),array(
- '$title' => sprintf(t('Group: %s'), $r['name'])
+ '$title' => t('Group: %s', $r['name'])
)) . $o;
} elseif ($cid) {
- $fields = array('id', 'name', 'network', 'writable', 'nurl',
- 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
- $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
- $r = dba::select('contact', $fields, $condition, array('limit' => 1));
+ $fields = ['id', 'name', 'network', 'writable', 'nurl',
+ 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
+ $condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
+ $r = dba::selectFirst('contact', $fields, $condition);
if (DBM::is_result($r)) {
$sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
$sql_order = "";
$order_mode = "received";
- if (strlen($file)) {
- $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
- dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
- $sql_order = "`item`.`id`";
- $order_mode = "id";
- }
-
if ($conv) {
$sql_extra3 .= " AND $sql_table.`mention`";
}
$sql_order = "$sql_table.$ordering";
}
- if (($_GET["offset"] != "")) {
- $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
+ if (x($_GET, 'offset')) {
+ $sql_range = sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
+ } else {
+ $sql_range = '';
}
$pager_sql = networkPager($a, $update);
+ $last_date = '';
+
switch ($order_mode) {
case 'received':
if ($last_received != '') {
- $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
+ $last_date = $last_received;
+ $sql_range .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
$a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
}
break;
case 'commented':
if ($last_commented != '') {
- $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
+ $last_date = $last_commented;
+ $sql_range .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
$a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
}
break;
case 'created':
if ($last_created != '') {
- $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
+ $last_date = $last_created;
+ $sql_range .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
$a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
}
break;
case 'id':
if (($last_id > 0) && ($sql_table == "`thread`")) {
- $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
+ $sql_range .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
$a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
}
} else {
$sql_extra4 = "";
}
-
- $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
+ $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`, $sql_order AS `order_date`
FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
AND NOT `item`.`moderated` AND `item`.`unseen`
- $sql_extra3 $sql_extra $sql_nets
- ORDER BY `item_id` DESC LIMIT 100",
+ $sql_extra3 $sql_extra $sql_range $sql_nets
+ ORDER BY `order_date` DESC LIMIT 100",
intval(local_user())
);
} else {
- $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
+ $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`, $sql_order AS `order_date`
FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
AND NOT `thread`.`moderated`
- $sql_extra2 $sql_extra3 $sql_extra $sql_nets
+ $sql_extra2 $sql_extra3 $sql_range $sql_extra $sql_nets
ORDER BY $sql_order DESC $pager_sql",
intval(local_user())
);
}
+ // Only show it when unfiltered (no groups, no networks, ...)
+ if (Config::get('system', 'comment_public') && (count($r) > 0) && (strlen($sql_extra . $sql_extra2 . $sql_extra3 . $sql_extra4 . $sql_nets) == 0)) {
+ $top_limit = current($r)['order_date'];
+ $bottom_limit = end($r)['order_date'];
+
+ // When checking for updates we need to fetch from the newest date to the newest date before
+ if ($update && !empty($_SESSION['network_last_date']) && ($bottom_limit > $_SESSION['network_last_date'])) {
+ $bottom_limit = $_SESSION['network_last_date'];
+ }
+ $_SESSION['network_last_date'] = $top_limit;
+
+ if ($last_date > $top_limit) {
+ $top_limit = $last_date;
+ }
+
+ $items = dba::p("SELECT `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` FROM `item`
+ INNER JOIN (SELECT `oid` FROM `term` WHERE `term` IN
+ (SELECT SUBSTR(`term`, 2) FROM `search` WHERE `uid` = ? AND `term` LIKE '#%') AND `otype` = ? AND `type` = ? AND `uid` = 0) AS `term`
+ ON `item`.`id` = `term`.`oid`
+ INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+ WHERE `item`.`uid` = 0 AND `item`.$ordering < ? AND `item`.$ordering > ?",
+ local_user(), TERM_OBJ_POST, TERM_HASHTAG, $top_limit, $bottom_limit);
+ $data = dba::inArray($items);
+
+ if (count($data) > 0) {
+ logger('Tagged items: '.count($data).' - '.$bottom_limit." - ".$top_limit.' - '.local_user()); //$last_date);
+ $r = array_merge($r, $data);
+ }
+ }
+
// Then fetch all the children of the parents that are on this page
$parents_arr = array();
$parents_str = '';
$date_offset = "";
+ $items = array();
if (DBM::is_result($r)) {
foreach ($r as $rr) {
- if (!in_array($rr['item_id'],$parents_arr)) {
+ if (!in_array($rr['item_id'], $parents_arr)) {
$parents_arr[] = $rr['item_id'];
}
}
$max_comments = 100;
}
- $items = array();
-
foreach ($parents_arr AS $parents) {
- $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
- AND `item`.`parent` = ?
- ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
- local_user(),
+ $thread_items = dba::p(item_query() . " AND `item`.`parent` = ?
+ ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1),
$parents
);
$items = array_merge($items, dba::inArray($thread_items));
}
}
- $items = conv_sort($items,$ordering);
- } else {
- $items = array();
+ $items = conv_sort($items, $ordering);
}
- if ($_GET["offset"] == "") {
+ if (x($_GET, 'offset')) {
+ $date_offset = $_GET["offset"];
+ } elseif(count($items)) {
$date_offset = $items[0][$order_mode];
} else {
- $date_offset = $_GET["offset"];
+ $date_offset = '';
}
$a->page_offset = $date_offset;
* @param App $a The global App
* @return string Html of the networktab
*/
-function network_tabs(App $a) {
+function network_tabs(App $a)
+{
// item filter tabs
/// @TODO fix this logic, reduce duplication
/// $a->page['content'] .= '<div class="tabs-wrapper">';
-
list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
+
// if no tabs are selected, defaults to comments
- if ($no_active=='active') $all_active='active';
+ if ($no_active == 'active') {
+ $all_active = 'active';
+ }
- $cmd = (($datequery) ? '' : $a->cmd);
- $len_naked_cmd = strlen(str_replace('/new','',$cmd));
+ $cmd = $a->cmd;
// tabs
$tabs = array(
),
);
- if (feature_enabled(local_user(),'personal_tab')) {
+ if (Feature::isEnabled(local_user(),'personal_tab')) {
$tabs[] = array(
'label' => t('Personal'),
'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
);
}
- if (feature_enabled(local_user(),'new_tab')) {
+ if (Feature::isEnabled(local_user(),'new_tab')) {
$tabs[] = array(
'label' => t('New'),
'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
);
}
- if (feature_enabled(local_user(),'link_tab')) {
+ if (Feature::isEnabled(local_user(),'link_tab')) {
$tabs[] = array(
'label' => t('Shared Links'),
'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
);
}
- if (feature_enabled(local_user(),'star_posts')) {
+ if (Feature::isEnabled(local_user(),'star_posts')) {
$tabs[] = array(
'label' => t('Starred'),
'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',