X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Ffeed%2FFeedBuilder.php;h=d5d74fd143adb105ede408865b7914681bad6ece;hb=9b8c0a4560fa1d87cab1529099b1b4677e92e265;hp=3653c32f981b360d52d556e4ea48e5ee6c1e4ab3;hpb=46d3f8162bb7950d3c7fec78ffcc2bdaf349dced;p=github%2Fshaarli%2FShaarli.git
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php
index 3653c32f..d5d74fd1 100644
--- a/application/feed/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -1,4 +1,5 @@
linkDB->search($userInput, null, false, false, true);
-
- $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput);
+ $limit = $this->getLimit($userInput);
- // Can't use array_keys() because $link is a LinkDB instance and not a real array.
- $keys = array();
- foreach ($linksToDisplay as $key => $value) {
- $keys[] = $key;
- }
+ // Optionally filter the results:
+ $searchResult = $this->linkDB->search($userInput ?? [], null, false, false, true, ['limit' => $limit]);
$pageaddr = escape(index_url($this->serverInfo));
$this->formatter->addContextData('index_url', $pageaddr);
- $linkDisplayed = array();
- for ($i = 0; $i < $nblinksToDisplay && $i < count($keys); $i++) {
- $linkDisplayed[$keys[$i]] = $this->buildItem($feedType, $linksToDisplay[$keys[$i]], $pageaddr);
+ $links = [];
+ foreach ($searchResult->getBookmarks() as $key => $bookmark) {
+ $links[$key] = $this->buildItem($feedType, $bookmark, $pageaddr);
}
$data['language'] = $this->getTypeLanguage($feedType);
$data['last_update'] = $this->getLatestDateFormatted($feedType);
$data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
- // Remove leading slash from REQUEST_URI.
- $data['self_link'] = escape(server_url($this->serverInfo))
- . escape($this->serverInfo['REQUEST_URI']);
+ // Remove leading path from REQUEST_URI (already contained in $pageaddr).
+ $requestUri = preg_replace('#(.*?/)(feed.*)#', '$2', escape($this->serverInfo['REQUEST_URI']));
+ $data['self_link'] = $pageaddr . $requestUri;
$data['index_url'] = $pageaddr;
$data['usepermalinks'] = $this->usePermalinks === true;
- $data['links'] = $linkDisplayed;
+ $data['links'] = $links;
return $data;
}
@@ -176,9 +171,9 @@ class FeedBuilder
$data = $this->formatter->format($link);
$data['guid'] = rtrim($pageaddr, '/') . '/shaare/' . $data['shorturl'];
if ($this->usePermalinks === true) {
- $permalink = ''. t('Direct link') .'';
+ $permalink = '' . t('Direct link') . '';
} else {
- $permalink = ''. t('Permalink') .'';
+ $permalink = '' . t('Permalink') . '';
}
$data['description'] .= PHP_EOL . PHP_EOL . '
— ' . $permalink;
@@ -267,19 +262,18 @@ class FeedBuilder
* If 'nb' not set or invalid, default value: $DEFAULT_NB_LINKS.
* If 'nb' is set to 'all', display all filtered bookmarks (max parameter).
*
- * @param int $max maximum number of bookmarks to display.
* @param array $userInput $_GET.
*
* @return int number of bookmarks to display.
*/
- protected function getNbLinks($max, ?array $userInput)
+ protected function getLimit(?array $userInput)
{
if (empty($userInput['nb'])) {
return self::$DEFAULT_NB_LINKS;
}
if ($userInput['nb'] == 'all') {
- return $max;
+ return null;
}
$intNb = intval($userInput['nb']);