articles.phtml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. foreach ($this->entriesRaw as $entryRaw) {
  16. if (empty($entryRaw)) {
  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. 'categories' => array_values($entry->tags()),
  31. 'title' => $entry->title(),
  32. 'author' => $entry->author(),
  33. 'published' => $entry->date(true),
  34. 'updated' => $entry->date(true),
  35. 'alternate' => array(array(
  36. 'href' => $entry->link(),
  37. 'type' => 'text/html',
  38. )),
  39. 'content' => array(
  40. 'content' => $entry->content(),
  41. ),
  42. 'origin' => array(
  43. 'streamId' => $feed == null ? '' : $feed->id(),
  44. 'title' => $feed == null ? '' : $feed->name(),
  45. 'htmlUrl' => $feed == null ? '' : $feed->website(),
  46. 'feedUrl' => $feed == null ? '' : $feed->url(),
  47. )
  48. );
  49. $line = json_encode($article, $options);
  50. if ($line != '') {
  51. if ($first) {
  52. $first = false;
  53. } else {
  54. echo ",\n";
  55. }
  56. echo $line;
  57. }
  58. }
  59. echo "\n]}\n";