diff options
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/Entry.php | 9 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 13 |
2 files changed, 15 insertions, 7 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 7da27e409..b70e7e2ab 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -846,12 +846,12 @@ HTML; /** * N.B.: To avoid expensive lookups, ensure to set `$entry->_feed($feed)` before calling this function. - * N.B.: You might have to populate `$entry->_tags()` prior to calling this function. * @param string $mode Set to `'compat'` to use an alternative Unicode representation for problematic HTML special characters not decoded by some clients; * set to `'freshrss'` for using FreshRSS additions for internal use (e.g. export/import). + * @param array<string> $labels List of labels associated to this entry. * @return array<string,mixed> A representation of this entry in a format compatible with Google Reader API */ - public function toGReader(string $mode = ''): array { + public function toGReader(string $mode = '', array $labels = []): array { $feed = $this->feed(); $category = $feed == null ? null : $feed->category(); @@ -935,8 +935,11 @@ HTML; if ($this->isFavorite()) { $item['categories'][] = 'user/-/state/com.google/starred'; } + foreach ($labels as $labelName) { + $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($labelName, ENT_QUOTES); + } foreach ($this->tags() as $tagName) { - $item['categories'][] = 'user/-/label/' . htmlspecialchars_decode($tagName, ENT_QUOTES); + $item['categories'][] = htmlspecialchars_decode($tagName, ENT_QUOTES); } return $item; } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 0704fd9f7..80a0e7688 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -383,7 +383,11 @@ SQL; // Split a query with too many variables parameters $idsChunks = array_chunk($entries, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER); foreach ($idsChunks as $idsChunk) { - $values += $this->getTagsForEntries($idsChunk); + $valuesChunk = $this->getTagsForEntries($idsChunk); + if (!is_array($valuesChunk)) { + return false; + } + $values = array_merge($values, $valuesChunk); } return $values; } @@ -419,9 +423,10 @@ SQL; } /** - * For API - * @param array<FreshRSS_Entry|numeric-string> $entries - * @return array<string,array<string>> + * Produces an array: for each entry ID (prefixed by `e_`), associate a list of labels. + * Used by API and by JSON export, to speed up queries (would be very expensive to perform a label look-up on each entry individually). + * @param array<FreshRSS_Entry|numeric-string> $entries the list of entries for which to retrieve the labels. + * @return array<string,array<string>> An array of the shape `[e_id_entry => ["label 1", "label 2"]]` */ public function getEntryIdsTagNames(array $entries): array { $result = []; |
