From 10b237829f6465f0e5cb0c505584aa11de7ab6e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 7 Jan 2018 22:07:16 +0000 Subject: [PATCH 1/3] We now can follow hash tags --- mod/network.php | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/mod/network.php b/mod/network.php index f54ee06f04..d2d7cb0413 100644 --- a/mod/network.php +++ b/mod/network.php @@ -740,9 +740,12 @@ function networkThreadedView(App $a, $update = 0) { $pager_sql = networkPager($a, $update); + $last_date = ''; + switch ($order_mode) { case 'received': if ($last_received != '') { + $last_date = $last_received; $sql_extra3 .= 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'])); @@ -750,6 +753,7 @@ function networkThreadedView(App $a, $update = 0) { break; case 'commented': if ($last_commented != '') { + $last_date = $last_commented; $sql_extra3 .= 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'])); @@ -757,6 +761,7 @@ function networkThreadedView(App $a, $update = 0) { break; case 'created': if ($last_created != '') { + $last_date = $last_created; $sql_extra3 .= 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'])); @@ -778,8 +783,7 @@ function networkThreadedView(App $a, $update = 0) { } 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 @@ -789,7 +793,7 @@ function networkThreadedView(App $a, $update = 0) { 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` @@ -800,6 +804,31 @@ function networkThreadedView(App $a, $update = 0) { ); } + if (count($r) > 0) { + $top_limit = current($r)['order_date']; + $bottom_limit = end($r)['order_date']; + + 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.' - '.$last_date); + + // ToDo: Doppelte URI rausfiltern + $r = array_merge($r, $data); + } + } + // Then fetch all the children of the parents that are on this page $parents_arr = array(); @@ -825,10 +854,8 @@ function networkThreadedView(App $a, $update = 0) { } foreach ($parents_arr AS $parents) { - $thread_items = dba::p(item_query() . " AND `item`.`uid` = ? - AND `item`.`parent` = ? + $thread_items = dba::p(item_query() . " AND `item`.`parent` = ? ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1), - local_user(), $parents ); From e2ed1fb426a2692250d8af2c3c2bc0f639898513 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 8 Jan 2018 06:57:51 +0000 Subject: [PATCH 2/3] Only show tagged items when there is no filter active --- mod/network.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mod/network.php b/mod/network.php index d2d7cb0413..fba775ab50 100644 --- a/mod/network.php +++ b/mod/network.php @@ -735,7 +735,9 @@ function networkThreadedView(App $a, $update = 0) { } if (x($_GET, 'offset')) { - $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); + $sql_range = sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); + } else { + $sql_range = ''; } $pager_sql = networkPager($a, $update); @@ -746,7 +748,7 @@ function networkThreadedView(App $a, $update = 0) { case 'received': if ($last_received != '') { $last_date = $last_received; - $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($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'])); } @@ -754,7 +756,7 @@ function networkThreadedView(App $a, $update = 0) { case 'commented': if ($last_commented != '') { $last_date = $last_commented; - $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($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'])); } @@ -762,14 +764,14 @@ function networkThreadedView(App $a, $update = 0) { case 'created': if ($last_created != '') { $last_date = $last_created; - $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($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'])); } @@ -788,8 +790,8 @@ function networkThreadedView(App $a, $update = 0) { 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 { @@ -798,16 +800,23 @@ function networkThreadedView(App $a, $update = 0) { 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()) ); } - if (count($r) > 0) { + // Only show it when unfiltered (no groups, no networks, ...) + if ((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; } @@ -822,9 +831,7 @@ function networkThreadedView(App $a, $update = 0) { $data = dba::inArray($items); if (count($data) > 0) { - logger('Tagged items: '.count($data).' - '.$bottom_limit." - ".$top_limit.' - '.$last_date); - - // ToDo: Doppelte URI rausfiltern + logger('Tagged items: '.count($data).' - '.$bottom_limit." - ".$top_limit.' - '.local_user()); //$last_date); $r = array_merge($r, $data); } } From b007823bcaa81649e471acaa8c48b4c93cd89810 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 8 Jan 2018 06:59:49 +0000 Subject: [PATCH 3/3] Only do it when public commenting is enabled --- mod/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/network.php b/mod/network.php index fba775ab50..8cebe73175 100644 --- a/mod/network.php +++ b/mod/network.php @@ -807,7 +807,7 @@ function networkThreadedView(App $a, $update = 0) { } // Only show it when unfiltered (no groups, no networks, ...) - if ((count($r) > 0) && (strlen($sql_extra . $sql_extra2 . $sql_extra3 . $sql_extra4 . $sql_nets) == 0)) { + 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'];