diff options
| author | 2022-08-08 12:04:02 +0200 | |
|---|---|---|
| committer | 2022-08-08 12:04:02 +0200 | |
| commit | 82ac1d1e676f93b1567eba608c00c6edaf401a9e (patch) | |
| tree | 1b3609df25f3eb1892aa7d359f52b82d680830a7 /app/views | |
| parent | 240afa7d4dcf33de4575a1531e2db3c9f4400c1f (diff) | |
Refactor entry-to-GReader API format (#4490)
* Refactor entry to GReader API format
Some code was copied in two locations and not completely uniform.
Cleaning of related variables and functions (e.g. better types for entries and categories as objects vs. as IDs).
Usecase: I need to call the same GReader-compatible serialization from an extension
* Fixed some edge cases
* Keep summary instead of content
`summary` and `content` seems to be used interchangeably in the Google Reader API. We have been using `summary` for our client API and `content` in our export/import, so stick to that.
Diffstat (limited to 'app/views')
| -rw-r--r-- | app/views/helpers/export/articles.phtml | 49 | ||||
| -rw-r--r-- | app/views/helpers/feed/update.phtml | 2 | ||||
| -rw-r--r-- | app/views/index/normal.phtml | 4 | ||||
| -rw-r--r-- | app/views/index/reader.phtml | 8 |
4 files changed, 16 insertions, 47 deletions
diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml index ad5210968..fd95ff741 100644 --- a/app/views/helpers/export/articles.phtml +++ b/app/views/helpers/export/articles.phtml @@ -18,51 +18,20 @@ if (empty($this->entryIdsTagNames)) { $this->entryIdsTagNames = array(); } -foreach ($this->entriesRaw as $entryRaw) { - if ($entryRaw == null) { +foreach ($this->entries as $entry) { + if ($entry == null) { continue; } - $entry = FreshRSS_Entry::fromArray($entryRaw); - if (!isset($this->feed)) { - $feed = FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feed()); - if ($feed === null) { - $feed = $entry->feed(true); - } - } else { - $feed = $this->feed; - } - $article = array( - 'id' => $entry->guid(), - 'timestampUsec' => '' . $entry->id(), - 'categories' => array_values($entry->tags()), - 'title' => $entry->title(), - 'author' => $entry->authors(true), - 'published' => $entry->date(true), - 'updated' => $entry->date(true), - 'alternate' => array(array( - 'href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES), - 'type' => 'text/html', - )), - 'content' => array( - 'content' => $entry->content(), - ), - 'origin' => array( - 'streamId' => $feed == null ? '' : $feed->id(), - 'title' => $feed == null ? '' : $feed->name(), - 'htmlUrl' => $feed == null ? '' : $feed->website(), - 'feedUrl' => $feed == null ? '' : $feed->url(), - ) - ); - $article['categories'][] = $entry->isRead() ? 'user/-/state/com.google/read' : 'user/-/state/com.google/unread'; - if ($entry->isFavorite()) { - $article['categories'][] = 'user/-/state/com.google/starred'; - } - $tagNames = isset($this->entryIdsTagNames['e_' . $entry->id()]) ? $this->entryIdsTagNames['e_' . $entry->id()] : array(); - foreach ($tagNames as $tagName) { - $article['categories'][] = 'user/-/label/' . $tagName; + $feed = $this->feed ?? FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feedId()); + $entry->_feed($feed); + + if (isset($this->entryIdsTagNames['e_' . $entry->id()])) { + $entry->_tags($this->entryIdsTagNames['e_' . $entry->id()]); } + $article = $entry->toGReader('freshrss'); + $line = json_encode($article, $options); if ($line != '') { if ($first) { diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 6f6044463..1e9e9afd2 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -69,7 +69,7 @@ <div class="group-controls"> <select name="category" id="category" class="w100"> <?php foreach ($this->categories as $cat) { ?> - <option value="<?= $cat->id() ?>"<?= $cat->id() == $this->feed->category() ? ' selected="selected"' : '' ?>> + <option value="<?= $cat->id() ?>"<?= $cat->id() == $this->feed->categoryId() ? ' selected="selected"' : '' ?>> <?= $cat->name() ?> </option> <?php } ?> diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index 348a42e89..6a4cb77eb 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -37,9 +37,9 @@ $today = @strtotime('today'); $this->entry = $item; // We most likely already have the feed object in cache - $this->feed = FreshRSS_CategoryDAO::findFeed($this->categories, $this->entry->feed()); + $this->feed = FreshRSS_CategoryDAO::findFeed($this->categories, $this->entry->feedId()); if ($this->feed == null) { - $this->feed = $this->entry->feed(true); + $this->feed = $this->entry->feed(); if ($this->feed == null) { $this->feed = FreshRSS_Feed::example(); } diff --git a/app/views/index/reader.phtml b/app/views/index/reader.phtml index c9ef7fbd9..334cd4189 100644 --- a/app/views/index/reader.phtml +++ b/app/views/index/reader.phtml @@ -47,12 +47,12 @@ $MAX_TAGS_DISPLAYED = FreshRSS_Context::$user_conf->show_tags_max; } ?><div class="flux<?= !$item->isRead() ? ' not_read' : '' ?><?= $item->isFavorite() ? ' favorite' : '' ?>" id="flux_<?= $item->id() ?>"> <article class="flux_content" dir="auto"> - + <div class="content <?= $content_width ?>"> <header> <?php - $feed = FreshRSS_CategoryDAO::findFeed($this->categories, $item->feed()); //We most likely already have the feed object in cache - if (empty($feed)) $feed = $item->feed(true); + $feed = FreshRSS_CategoryDAO::findFeed($this->categories, $item->feedId()); //We most likely already have the feed object in cache + if ($feed == null) $feed = $item->feed(); $favoriteUrl = array('c' => 'entry', 'a' => 'bookmark', 'params' => array('id' => $item->id())); if ($item->isFavorite()) { $favoriteUrl['params']['is_favorite'] = 0; @@ -134,7 +134,7 @@ $MAX_TAGS_DISPLAYED = FreshRSS_Context::$user_conf->show_tags_max; </div> <?php } ?> </header> - + <div class="text"> <?= $item->content() ?> </div> |
