aboutsummaryrefslogtreecommitdiff
path: root/app/views/helpers/export/articles.phtml
blob: 2d1fcd1339e5d3a69fcd80e7c505f03e479c832e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$username = Minz_Session::param('currentUser', '_');

$options = 0;
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
	$options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
}

$articles = array(
	'id' => 'user/' . str_replace('/', '', $username) . '/state/org.freshrss/' . $this->type,
	'title' => $this->list_title,
	'author' => $username,
	'items' => array(),
);

echo rtrim(json_encode($articles, $options), " ]}\n\r\t"), "\n";
$first = true;

if (empty($this->entryIdsTagNames)) {
	$this->entryIdsTagNames = array();
}

foreach ($this->entriesRaw as $entryRaw) {
	if ($entryRaw == null) {
		continue;
	}
	$entry = FreshRSS_EntryDAO::daoToEntry($entryRaw);
	if (!isset($this->feed)) {
		$feed = FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feed());
		if ($feed === null) {
			$feed = $entry->feed(true);
		}
	} else {
		$feed = $this->feed;
	}

	$article = array(
		'id' => $entry->guid(),
		'timestampUsec' => '' . $entry->id(),
		'categories' => array_values($entry->tags()),
		'title' => $entry->title(),
		'author' => $entry->authors(true),
		'published' => $entry->date(true),
		'updated' => $entry->date(true),
		'alternate' => array(array(
			'href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES),
			'type' => 'text/html',
		)),
		'content' => array(
			'content' => $entry->content(),
		),
		'origin' => array(
			'streamId' => $feed == null ? '' : $feed->id(),
			'title' => $feed == null ? '' : $feed->name(),
			'htmlUrl' => $feed == null ? '' : $feed->website(),
			'feedUrl' => $feed == null ? '' : $feed->url(),
		)
	);
	$article['categories'][] = $entry->isRead() ? 'user/-/state/com.google/read' : 'user/-/state/com.google/unread';
	if ($entry->isFavorite()) {
		$article['categories'][] = 'user/-/state/com.google/starred';
	}
	$tagNames = isset($this->entryIdsTagNames['e_' . $entry->id()]) ? $this->entryIdsTagNames['e_' . $entry->id()] : array();
	foreach ($tagNames as $tagName) {
		$article['categories'][] = 'user/-/label/' . $tagName;
	}

	$line = json_encode($article, $options);
	if ($line != '') {
		if ($first) {
			$first = false;
		} else {
			echo ",\n";
		}
		echo $line;
	}
}

echo "\n]}\n";