X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FSearch%2FIndex.php;h=93c1af7aa6d5874afb82f08d744ae4392969c893;hb=69b7923df2beed71419bc38e61ca9755fad24b12;hp=712edad0232e95ef6630ac6549158df41ede23cf;hpb=2bd1e8cf6509217eedd864c509a9bfbf67819621;p=friendica.git diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 712edad023..93c1af7aa6 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -1,6 +1,6 @@ get('system', 'block_public') && !Session::isAuthenticated()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.')); } if (DI::config()->get('system', 'local_search') && !Session::isAuthenticated()) { - $e = new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.')); - $e->httpdesc = DI::l10n()->t('Public access denied.'); - throw $e; + throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.')); } if (DI::config()->get('system', 'permit_crawling') && !Session::isAuthenticated()) { @@ -90,7 +87,7 @@ class Index extends BaseSearch $tag = false; if (!empty($_GET['tag'])) { $tag = true; - $search = '#' . Strings::escapeTags(trim(rawurldecode($_GET['tag']))); + $search = '#' . trim(rawurldecode($_GET['tag'])); } // contruct a wrapper for the search header @@ -135,7 +132,7 @@ class Index extends BaseSearch // Don't perform a fulltext or tag search on search results that look like an URL // Tags don't look like an URL and the fulltext search does only work with natural words if (parse_url($search, PHP_URL_SCHEME) && parse_url($search, PHP_URL_HOST)) { - Logger::info('Skipping tag and fulltext search since the search looks like an URL.', ['q' => $search]); + Logger::info('Skipping tag and fulltext search since the search looks like a URL.', ['q' => $search]); notice(DI::l10n()->t('No results.')); return $o; } @@ -155,28 +152,39 @@ class Index extends BaseSearch DI::config()->get('system', 'itemspage_network')); } + $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0; + $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); if ($tag) { Logger::info('Start tag search.', ['q' => $search]); - $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); + $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); $count = Tag::countByTag($search, local_user()); } else { Logger::info('Start fulltext search.', ['q' => $search]); - $uriids = ItemContent::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); - $count = ItemContent::countBySearch($search, local_user()); + $uriids = Post\Content::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); + $count = Post\Content::countBySearch($search, local_user()); } if (!empty($uriids)) { - $params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; - $items = Item::inArray(Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params)); + $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`))", 0, local_user()]; + $condition = DBA::mergeConditions($condition, ['uri-id' => $uriids]); + $params = ['order' => ['id' => true]]; + $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params)); } if (empty($items)) { - notice(DI::l10n()->t('No results.')); + if (empty($last_uriid)) { + notice(DI::l10n()->t('No results.')); + } return $o; } + if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { + $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl'); + $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]); + } + if ($tag) { $title = DI::l10n()->t('Items tagged with: %s', $search); } else { @@ -189,9 +197,14 @@ class Index extends BaseSearch Logger::info('Start Conversation.', ['q' => $search]); - $o .= conversation(DI::app(), $items, 'search', false, false, 'commented', local_user()); + $o .= DI::conversation()->create($items, 'search', false, false, 'commented', local_user()); + + if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { + $o .= HTML::scrollLoader(); + } else { + $o .= $pager->renderMinimal($count); + } - $o .= $pager->renderMinimal($count); return $o; } @@ -274,7 +287,7 @@ class Index extends BaseSearch } if (!empty($item_id)) { - $item = Item::selectFirst(['guid'], ['id' => $item_id]); + $item = Post::selectFirst(['guid'], ['id' => $item_id]); if (DBA::isResult($item)) { DI::baseUrl()->redirect('display/' . $item['guid']); }