articles.phtml 2.1 KB

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