]>
Commit | Line | Data |
---|---|---|
6afcbcd1 AD |
1 | <?php |
2 | class Article extends Handler_Protected { | |
3 | ||
4 | function csrf_ignore($method) { | |
1c9bda91 | 5 | $csrf_ignored = array("redirect", "editarticletags"); |
6afcbcd1 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
10 | function redirect() { | |
d9c85e0f | 11 | $id = $this->dbh->escape_string($_REQUEST['id']); |
6afcbcd1 | 12 | |
d9c85e0f | 13 | $result = $this->dbh->query("SELECT link FROM ttrss_entries, ttrss_user_entries |
6afcbcd1 AD |
14 | WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' |
15 | LIMIT 1"); | |
16 | ||
d9c85e0f AD |
17 | if ($this->dbh->num_rows($result) == 1) { |
18 | $article_url = $this->dbh->fetch_result($result, 0, 'link'); | |
6afcbcd1 AD |
19 | $article_url = str_replace("\n", "", $article_url); |
20 | ||
21 | header("Location: $article_url"); | |
22 | return; | |
23 | ||
24 | } else { | |
25 | print_error(__("Article not found.")); | |
26 | } | |
27 | } | |
28 | ||
29 | function view() { | |
d9c85e0f AD |
30 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
31 | $cids = explode(",", $this->dbh->escape_string($_REQUEST["cids"])); | |
32 | $mode = $this->dbh->escape_string($_REQUEST["mode"]); | |
6afcbcd1 AD |
33 | |
34 | // in prefetch mode we only output requested cids, main article | |
35 | // just gets marked as read (it already exists in client cache) | |
36 | ||
37 | $articles = array(); | |
38 | ||
39 | if ($mode == "") { | |
a42c55f0 | 40 | array_push($articles, format_article($id, false)); |
6afcbcd1 | 41 | } else if ($mode == "zoom") { |
a42c55f0 | 42 | array_push($articles, format_article($id, true, true)); |
6afcbcd1 AD |
43 | } else if ($mode == "raw") { |
44 | if ($_REQUEST['html']) { | |
45 | header("Content-Type: text/html"); | |
5bbc4bb4 | 46 | print '<link rel="stylesheet" type="text/css" href="css/tt-rss.css"/>'; |
6afcbcd1 AD |
47 | } |
48 | ||
a42c55f0 | 49 | $article = format_article($id, false); |
6afcbcd1 AD |
50 | print $article['content']; |
51 | return; | |
52 | } | |
53 | ||
a42c55f0 | 54 | $this->catchupArticleById($id, 0); |
6afcbcd1 AD |
55 | |
56 | if (!$_SESSION["bw_limit"]) { | |
57 | foreach ($cids as $cid) { | |
58 | if ($cid) { | |
a42c55f0 | 59 | array_push($articles, format_article($cid, false, false)); |
6afcbcd1 AD |
60 | } |
61 | } | |
62 | } | |
63 | ||
64 | print json_encode($articles); | |
65 | } | |
66 | ||
a42c55f0 | 67 | private function catchupArticleById($id, $cmode) { |
6afcbcd1 AD |
68 | |
69 | if ($cmode == 0) { | |
d9c85e0f | 70 | $this->dbh->query("UPDATE ttrss_user_entries SET |
6afcbcd1 AD |
71 | unread = false,last_read = NOW() |
72 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
73 | } else if ($cmode == 1) { | |
d9c85e0f | 74 | $this->dbh->query("UPDATE ttrss_user_entries SET |
6afcbcd1 AD |
75 | unread = true |
76 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
77 | } else { | |
d9c85e0f | 78 | $this->dbh->query("UPDATE ttrss_user_entries SET |
6afcbcd1 AD |
79 | unread = NOT unread,last_read = NOW() |
80 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
81 | } | |
82 | ||
a42c55f0 AD |
83 | $feed_id = getArticleFeed($id); |
84 | ccache_update($feed_id, $_SESSION["uid"]); | |
6afcbcd1 AD |
85 | } |
86 | ||
a42c55f0 | 87 | static function create_published_article($title, $url, $content, $labels_str, |
6afcbcd1 AD |
88 | $owner_uid) { |
89 | ||
5e3d5480 | 90 | $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash |
6afcbcd1 AD |
91 | $content_hash = sha1($content); |
92 | ||
93 | if ($labels_str != "") { | |
94 | $labels = explode(",", $labels_str); | |
95 | } else { | |
96 | $labels = array(); | |
97 | } | |
98 | ||
99 | $rc = false; | |
100 | ||
101 | if (!$title) $title = $url; | |
102 | if (!$title && !$url) return false; | |
103 | ||
104 | if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; | |
105 | ||
a42c55f0 | 106 | db_query("BEGIN"); |
6afcbcd1 AD |
107 | |
108 | // only check for our user data here, others might have shared this with different content etc | |
a42c55f0 | 109 | $result = db_query("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
74163057 | 110 | guid = '$guid' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1"); |
6afcbcd1 AD |
111 | |
112 | if (db_num_rows($result) != 0) { | |
113 | $ref_id = db_fetch_result($result, 0, "id"); | |
114 | ||
a42c55f0 | 115 | $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE |
6afcbcd1 AD |
116 | ref_id = '$ref_id' AND owner_uid = '$owner_uid' LIMIT 1"); |
117 | ||
118 | if (db_num_rows($result) != 0) { | |
119 | $int_id = db_fetch_result($result, 0, "int_id"); | |
120 | ||
a42c55f0 | 121 | db_query("UPDATE ttrss_entries SET |
6afcbcd1 AD |
122 | content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'"); |
123 | ||
a42c55f0 | 124 | db_query("UPDATE ttrss_user_entries SET published = true, |
d2888e88 | 125 | last_published = NOW() WHERE |
6afcbcd1 AD |
126 | int_id = '$int_id' AND owner_uid = '$owner_uid'"); |
127 | } else { | |
128 | ||
a42c55f0 | 129 | db_query("INSERT INTO ttrss_user_entries |
d2888e88 AD |
130 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
131 | last_read, note, unread, last_published) | |
6afcbcd1 | 132 | VALUES |
d2888e88 | 133 | ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())"); |
6afcbcd1 AD |
134 | } |
135 | ||
136 | if (count($labels) != 0) { | |
137 | foreach ($labels as $label) { | |
a42c55f0 | 138 | label_add_article($ref_id, trim($label), $owner_uid); |
6afcbcd1 AD |
139 | } |
140 | } | |
141 | ||
142 | $rc = true; | |
143 | ||
144 | } else { | |
a42c55f0 | 145 | $result = db_query("INSERT INTO ttrss_entries |
6afcbcd1 AD |
146 | (title, guid, link, updated, content, content_hash, date_entered, date_updated) |
147 | VALUES | |
148 | ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())"); | |
149 | ||
a42c55f0 | 150 | $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '$guid'"); |
6afcbcd1 AD |
151 | |
152 | if (db_num_rows($result) != 0) { | |
153 | $ref_id = db_fetch_result($result, 0, "id"); | |
154 | ||
a42c55f0 | 155 | db_query("INSERT INTO ttrss_user_entries |
d2888e88 AD |
156 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
157 | last_read, note, unread, last_published) | |
6afcbcd1 | 158 | VALUES |
d2888e88 | 159 | ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())"); |
6afcbcd1 AD |
160 | |
161 | if (count($labels) != 0) { | |
162 | foreach ($labels as $label) { | |
a42c55f0 | 163 | label_add_article($ref_id, trim($label), $owner_uid); |
6afcbcd1 AD |
164 | } |
165 | } | |
166 | ||
167 | $rc = true; | |
168 | } | |
169 | } | |
170 | ||
a42c55f0 | 171 | db_query("COMMIT"); |
6afcbcd1 AD |
172 | |
173 | return $rc; | |
174 | } | |
175 | ||
1c9bda91 AD |
176 | function editArticleTags() { |
177 | ||
178 | print __("Tags for this article (separated by commas):")."<br>"; | |
179 | ||
d9c85e0f | 180 | $param = $this->dbh->escape_string($_REQUEST['param']); |
1c9bda91 | 181 | |
d9c85e0f | 182 | $tags = get_article_tags($this->dbh->escape_string($param)); |
1c9bda91 AD |
183 | |
184 | $tags_str = join(", ", $tags); | |
185 | ||
186 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$param\">"; | |
5df8be5c | 187 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"article\">"; |
1c9bda91 AD |
188 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">"; |
189 | ||
190 | print "<table width='100%'><tr><td>"; | |
191 | ||
192 | print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4' | |
fb8a032a | 193 | style='font-size : 12px; width : 98%' id=\"tags_str\" |
1c9bda91 AD |
194 | name='tags_str'>$tags_str</textarea> |
195 | <div class=\"autocomplete\" id=\"tags_choices\" | |
196 | style=\"display:none\"></div>"; | |
197 | ||
198 | print "</td></tr></table>"; | |
199 | ||
200 | print "<div class='dlgButtons'>"; | |
201 | ||
202 | print "<button dojoType=\"dijit.form.Button\" | |
203 | onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; | |
204 | print "<button dojoType=\"dijit.form.Button\" | |
205 | onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; | |
206 | print "</div>"; | |
207 | ||
208 | } | |
6afcbcd1 | 209 | |
d719b062 | 210 | function setScore() { |
d9c85e0f AD |
211 | $ids = $this->dbh->escape_string($_REQUEST['id']); |
212 | $score = (int)$this->dbh->escape_string($_REQUEST['score']); | |
d719b062 | 213 | |
d9c85e0f | 214 | $this->dbh->query("UPDATE ttrss_user_entries SET |
d719b062 AD |
215 | score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); |
216 | ||
6f7798b6 | 217 | print json_encode(array("id" => $ids, |
a72cd54c AD |
218 | "score" => (int)$score, |
219 | "score_pic" => get_score_pic($score))); | |
220 | } | |
221 | ||
222 | function getScore() { | |
223 | $id = $this->dbh->escape_string($_REQUEST['id']); | |
224 | ||
225 | $result = $this->dbh->query("SELECT score FROM ttrss_user_entries WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]); | |
226 | $score = $this->dbh->fetch_result($result, 0, "score"); | |
227 | ||
228 | print json_encode(array("id" => $id, | |
229 | "score" => (int)$score, | |
d719b062 AD |
230 | "score_pic" => get_score_pic($score))); |
231 | } | |
232 | ||
6afcbcd1 | 233 | |
5df8be5c AD |
234 | function setArticleTags() { |
235 | ||
d9c85e0f | 236 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
5df8be5c | 237 | |
d9c85e0f | 238 | $tags_str = $this->dbh->escape_string($_REQUEST["tags_str"]); |
5df8be5c AD |
239 | $tags = array_unique(trim_array(explode(",", $tags_str))); |
240 | ||
d9c85e0f | 241 | $this->dbh->query("BEGIN"); |
5df8be5c | 242 | |
d9c85e0f | 243 | $result = $this->dbh->query("SELECT int_id FROM ttrss_user_entries WHERE |
5df8be5c AD |
244 | ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); |
245 | ||
d9c85e0f | 246 | if ($this->dbh->num_rows($result) == 1) { |
5df8be5c AD |
247 | |
248 | $tags_to_cache = array(); | |
249 | ||
d9c85e0f | 250 | $int_id = $this->dbh->fetch_result($result, 0, "int_id"); |
5df8be5c | 251 | |
d9c85e0f | 252 | $this->dbh->query("DELETE FROM ttrss_tags WHERE |
5df8be5c AD |
253 | post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); |
254 | ||
255 | foreach ($tags as $tag) { | |
256 | $tag = sanitize_tag($tag); | |
257 | ||
258 | if (!tag_is_valid($tag)) { | |
259 | continue; | |
260 | } | |
261 | ||
262 | if (preg_match("/^[0-9]*$/", $tag)) { | |
263 | continue; | |
264 | } | |
265 | ||
266 | // print "<!-- $id : $int_id : $tag -->"; | |
267 | ||
268 | if ($tag != '') { | |
d9c85e0f | 269 | $this->dbh->query("INSERT INTO ttrss_tags |
5df8be5c AD |
270 | (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); |
271 | } | |
272 | ||
273 | array_push($tags_to_cache, $tag); | |
274 | } | |
275 | ||
276 | /* update tag cache */ | |
277 | ||
278 | sort($tags_to_cache); | |
279 | $tags_str = join(",", $tags_to_cache); | |
280 | ||
d9c85e0f | 281 | $this->dbh->query("UPDATE ttrss_user_entries |
5df8be5c AD |
282 | SET tag_cache = '$tags_str' WHERE ref_id = '$id' |
283 | AND owner_uid = " . $_SESSION["uid"]); | |
284 | } | |
285 | ||
d9c85e0f | 286 | $this->dbh->query("COMMIT"); |
5df8be5c | 287 | |
a42c55f0 | 288 | $tags = get_article_tags($id); |
5df8be5c AD |
289 | $tags_str = format_tags_string($tags, $id); |
290 | $tags_str_full = join(", ", $tags); | |
291 | ||
292 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
293 | ||
294 | print json_encode(array("id" => (int)$id, | |
295 | "content" => $tags_str, "content_full" => $tags_str_full)); | |
296 | } | |
297 | ||
c83554bd AD |
298 | |
299 | function completeTags() { | |
d9c85e0f | 300 | $search = $this->dbh->escape_string($_REQUEST["search"]); |
c83554bd | 301 | |
d9c85e0f | 302 | $result = $this->dbh->query("SELECT DISTINCT tag_name FROM ttrss_tags |
c83554bd AD |
303 | WHERE owner_uid = '".$_SESSION["uid"]."' AND |
304 | tag_name LIKE '$search%' ORDER BY tag_name | |
305 | LIMIT 10"); | |
306 | ||
307 | print "<ul>"; | |
d9c85e0f | 308 | while ($line = $this->dbh->fetch_assoc($result)) { |
c83554bd AD |
309 | print "<li>" . $line["tag_name"] . "</li>"; |
310 | } | |
311 | print "</ul>"; | |
312 | } | |
313 | ||
4b7726f0 AD |
314 | function assigntolabel() { |
315 | return $this->labelops(true); | |
316 | } | |
317 | ||
318 | function removefromlabel() { | |
319 | return $this->labelops(false); | |
320 | } | |
321 | ||
322 | private function labelops($assign) { | |
323 | $reply = array(); | |
324 | ||
d9c85e0f AD |
325 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
326 | $label_id = $this->dbh->escape_string($_REQUEST["lid"]); | |
4b7726f0 | 327 | |
d9c85e0f | 328 | $label = $this->dbh->escape_string(label_find_caption($label_id, |
4b7726f0 AD |
329 | $_SESSION["uid"])); |
330 | ||
331 | $reply["info-for-headlines"] = array(); | |
332 | ||
333 | if ($label) { | |
334 | ||
335 | foreach ($ids as $id) { | |
336 | ||
337 | if ($assign) | |
a42c55f0 | 338 | label_add_article($id, $label, $_SESSION["uid"]); |
4b7726f0 | 339 | else |
a42c55f0 | 340 | label_remove_article($id, $label, $_SESSION["uid"]); |
4b7726f0 | 341 | |
a42c55f0 | 342 | $labels = get_article_labels($id, $_SESSION["uid"]); |
4b7726f0 AD |
343 | |
344 | array_push($reply["info-for-headlines"], | |
345 | array("id" => $id, "labels" => format_article_labels($labels, $id))); | |
346 | ||
347 | } | |
348 | } | |
349 | ||
350 | $reply["message"] = "UPDATE_COUNTERS"; | |
351 | ||
352 | print json_encode($reply); | |
353 | } | |
354 | ||
355 | ||
c83554bd | 356 | |
6afcbcd1 | 357 | } |