articles.phtml 2.1 KB

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