articles.phtml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /** @var FreshRSS_View $this */
  3. $username = Minz_Session::param('currentUser', '_');
  4. $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
  5. $articles = array(
  6. 'id' => 'user/' . str_replace('/', '', $username) . '/state/org.freshrss/' . $this->type,
  7. 'title' => $this->list_title,
  8. 'author' => $username,
  9. 'items' => array(),
  10. );
  11. echo rtrim(json_encode($articles, $options), " ]}\n\r\t"), "\n";
  12. $first = true;
  13. if (empty($this->entryIdsTagNames)) {
  14. $this->entryIdsTagNames = array();
  15. }
  16. foreach ($this->entriesRaw as $entryRaw) {
  17. if ($entryRaw == null) {
  18. continue;
  19. }
  20. $entry = FreshRSS_EntryDAO::daoToEntry($entryRaw);
  21. if (!isset($this->feed)) {
  22. $feed = FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feed());
  23. if ($feed === null) {
  24. $feed = $entry->feed(true);
  25. }
  26. } else {
  27. $feed = $this->feed;
  28. }
  29. $article = array(
  30. 'id' => $entry->guid(),
  31. 'timestampUsec' => '' . $entry->id(),
  32. 'categories' => array_values($entry->tags()),
  33. 'title' => $entry->title(),
  34. 'author' => $entry->authors(true),
  35. 'published' => $entry->date(true),
  36. 'updated' => $entry->date(true),
  37. 'alternate' => array(array(
  38. 'href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES),
  39. 'type' => 'text/html',
  40. )),
  41. 'content' => array(
  42. 'content' => $entry->content(),
  43. ),
  44. 'origin' => array(
  45. 'streamId' => $feed == null ? '' : $feed->id(),
  46. 'title' => $feed == null ? '' : $feed->name(),
  47. 'htmlUrl' => $feed == null ? '' : $feed->website(),
  48. 'feedUrl' => $feed == null ? '' : $feed->url(),
  49. )
  50. );
  51. $article['categories'][] = $entry->isRead() ? 'user/-/state/com.google/read' : 'user/-/state/com.google/unread';
  52. if ($entry->isFavorite()) {
  53. $article['categories'][] = 'user/-/state/com.google/starred';
  54. }
  55. $tagNames = isset($this->entryIdsTagNames['e_' . $entry->id()]) ? $this->entryIdsTagNames['e_' . $entry->id()] : array();
  56. foreach ($tagNames as $tagName) {
  57. $article['categories'][] = 'user/-/label/' . $tagName;
  58. }
  59. $line = json_encode($article, $options);
  60. if ($line != '') {
  61. if ($first) {
  62. $first = false;
  63. } else {
  64. echo ",\n";
  65. }
  66. echo $line;
  67. }
  68. }
  69. echo "\n]}\n";