articles.phtml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. $tagDAO = FreshRSS_Factory::createTagDao();
  16. $entryIdsTagNames = $tagDAO->getEntryIdsTagNames($this->entriesRaw);
  17. if ($entryIdsTagNames == false) {
  18. $entryIdsTagNames = array();
  19. }
  20. foreach ($this->entriesRaw as $entryRaw) {
  21. if (empty($entryRaw)) {
  22. continue;
  23. }
  24. $entry = FreshRSS_EntryDAO::daoToEntry($entryRaw);
  25. if (!isset($this->feed)) {
  26. $feed = FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feed());
  27. if ($feed === null) {
  28. $feed = $entry->feed(true);
  29. }
  30. } else {
  31. $feed = $this->feed;
  32. }
  33. $article = array(
  34. 'id' => $entry->guid(),
  35. 'timestampUsec' => '' . $entry->id(),
  36. 'categories' => array_values($entry->tags()),
  37. 'title' => $entry->title(),
  38. 'author' => $entry->authors(true),
  39. 'published' => $entry->date(true),
  40. 'updated' => $entry->date(true),
  41. 'alternate' => array(array(
  42. 'href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES),
  43. 'type' => 'text/html',
  44. )),
  45. 'content' => array(
  46. 'content' => $entry->content(),
  47. ),
  48. 'origin' => array(
  49. 'streamId' => $feed == null ? '' : $feed->id(),
  50. 'title' => $feed == null ? '' : $feed->name(),
  51. 'htmlUrl' => $feed == null ? '' : $feed->website(),
  52. 'feedUrl' => $feed == null ? '' : $feed->url(),
  53. )
  54. );
  55. if ($entry->isFavorite()) {
  56. $article['categories'][] = 'user/-/state/com.google/starred';
  57. }
  58. $tagNames = isset($entryIdsTagNames['e_' . $entry->id()]) ? $entryIdsTagNames['e_' . $entry->id()] : array();
  59. foreach ($tagNames as $tagName) {
  60. $article['categories'][] = 'user/-/label/' . $tagName;
  61. }
  62. $line = json_encode($article, $options);
  63. if ($line != '') {
  64. if ($first) {
  65. $first = false;
  66. } else {
  67. echo ",\n";
  68. }
  69. echo $line;
  70. }
  71. }
  72. echo "\n]}\n";