forked from glacjay/mreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmr-item.php
176 lines (155 loc) · 4.51 KB
/
mr-item.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
require_once 'mr-common.php';
require_once 'mr-oauth.php';
if (!isset($_SESSION['access_token']))
logout();
$url = "https://www.google.com/reader/api/0/user-info";
list($http_code, $result) = requestOAuth($url);
if ($http_code != 200)
logout();
$json = json_decode($result, true);
if ($json['userEmail'] != $email)
logout();
function redirectToOldestItem()
{
global $db;
$stmt = $db->query('select id from item order by time limit 1');
if ($stmt === false)
dieOnDb();
else
{
$result = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
$id = urlencode($result[0]);
die("<meta http-equiv='Refresh' content='0; url=mr-item.php?id=$id' />");
}
}
if (! isset($_GET['id']))
redirectToOldestItem();
$id = $_GET['id'];
if (isset($_GET['action']) &&
($_GET['action'] == 'next' || $_GET['action'] == 'star' || $_GET['action'] == 'later'))
{
$prev = $_GET['id'];
$items = getItem($prev);
$item = $items['items'][0];
$stream = $item['origin']['streamId'];
if ($_GET['action'] == 'star')
markStar($prev, $stream);
if ($_GET['action'] == 'later')
markLater($prev, $stream);
markRead($prev, $stream);
$quoted_prev = $db->quote($prev);
$db->exec("delete from item where id=$quoted_prev");
redirectToOldestItem();
}
$count = 0;
$stmt = $db->query('select count(*) from item');
if ($stmt === false)
dieOnDb();
else
{
$result = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
$count = $result[0];
}
$stmt = $db->query('select time from item order by time desc limit 1');
if ($stmt === false)
dieOnDb();
else
{
$result = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
$newest = date('Y-m-d H:i:s', $result[0] / 1000);
}
$items = getItem($id);
$item = $items['items'][0];
$src = $items['title'];
$time = date('Y-m-d H:i:s', $item['crawlTimeMsec'] / 1000);
$origin = $item['alternate'][0]['href'];
if (isset($item['title']))
$title = $item['title'];
else
$title = '(title unknown)';
if (isset($item['author']))
$author = $item['author'];
else
$author = '(someone)';
if (isset($item['content']))
$content = $item['content']['content'];
elseif (isset($item['summary']))
$content = $item['summary']['content'];
else
$content = 'There is no content?!';
$id = urlencode($id);
$stream = urlencode(base64_encode($item['origin']['streamId']));
$next_url = "mr-item.php?id=$id&action=next";
$star_url = "mr-item.php?id=$id&action=star";
$later_url = "mr-item.php?id=$id&action=later";
if (ignoreItem($item))
{
$quoted_prev = $db->quote($item['id']);
$db->exec("delete from item where id=$quoted_prev");
redirectToOldestItem();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title><?php echo $title; ?></title>
<style type="text/css">
.title { background-color: #ddddff; }
.src { color: green; }
a.button {
display: inline-block;
text-decoration: none;
margin: 2px;
padding: 5px 20px;
border: solid 1px blue;
color: DarkBlue;
text-align: center;
background: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, white),
color-stop(1, LightBlue)
);
}
a.button:active {
background: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, LightBlue),
color-stop(1, white)
);
}
</style>
</head>
<body>
<a class="button" href="<?php echo $origin; ?>">origin</a>
<a class="button" href="<?php echo $later_url; ?>">later</a>
<a class="button" href="<?php echo $star_url; ?>">star</a>
<a class="button" href="<?php echo $next_url; ?>">next</a>
<hr />
<div id="logo">
Status: (<?php echo $count; ?>) <?php echo $newest; ?>
</div>
<div class="title">
<?php echo $title; ?><br />
<?php echo "by " . $author . " at " . $time; ?>
</div>
<div class="src"><?php echo $src; ?></div>
<br />
<div class="content">
<?php echo $content; ?>
</div>
<hr />
<a class="button" href="<?php echo $origin; ?>">origin</a>
<a class="button" href="<?php echo $later_url; ?>">later</a>
<a class="button" href="<?php echo $star_url; ?>">star</a>
<a class="button" href="<?php echo $next_url; ?>">next</a>
</body>
</html>