2013-02-21 15:58:06 +01:00
|
|
|
<?php
|
|
|
|
class Article extends Handler_Protected {
|
|
|
|
|
|
|
|
function csrf_ignore($method) {
|
2013-04-01 09:14:27 +02:00
|
|
|
$csrf_ignored = array("redirect", "editarticletags");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
return array_search($method, $csrf_ignored) !== false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirect() {
|
2013-04-17 18:12:14 +02:00
|
|
|
$id = $this->dbh->escape_string($_REQUEST['id']);
|
2013-02-21 15:58:06 +01:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$result = $this->dbh->query("SELECT link FROM ttrss_entries, ttrss_user_entries
|
2013-02-21 15:58:06 +01:00
|
|
|
WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'
|
|
|
|
LIMIT 1");
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
if ($this->dbh->num_rows($result) == 1) {
|
|
|
|
$article_url = $this->dbh->fetch_result($result, 0, 'link');
|
2013-02-21 15:58:06 +01:00
|
|
|
$article_url = str_replace("\n", "", $article_url);
|
|
|
|
|
|
|
|
header("Location: $article_url");
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
print_error(__("Article not found."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function view() {
|
2013-04-17 18:12:14 +02:00
|
|
|
$id = $this->dbh->escape_string($_REQUEST["id"]);
|
|
|
|
$cids = explode(",", $this->dbh->escape_string($_REQUEST["cids"]));
|
|
|
|
$mode = $this->dbh->escape_string($_REQUEST["mode"]);
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
// in prefetch mode we only output requested cids, main article
|
|
|
|
// just gets marked as read (it already exists in client cache)
|
|
|
|
|
|
|
|
$articles = array();
|
|
|
|
|
|
|
|
if ($mode == "") {
|
2013-04-17 16:34:18 +02:00
|
|
|
array_push($articles, format_article($id, false));
|
2013-02-21 15:58:06 +01:00
|
|
|
} else if ($mode == "zoom") {
|
2013-04-17 16:34:18 +02:00
|
|
|
array_push($articles, format_article($id, true, true));
|
2013-02-21 15:58:06 +01:00
|
|
|
} else if ($mode == "raw") {
|
2015-09-11 12:05:08 +02:00
|
|
|
if (isset($_REQUEST['html'])) {
|
2013-02-21 15:58:06 +01:00
|
|
|
header("Content-Type: text/html");
|
2013-05-19 19:22:01 +02:00
|
|
|
print '<link rel="stylesheet" type="text/css" href="css/tt-rss.css"/>';
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
|
2015-09-11 12:05:08 +02:00
|
|
|
$article = format_article($id, false, isset($_REQUEST["zoom"]));
|
2013-02-21 15:58:06 +01:00
|
|
|
print $article['content'];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$this->catchupArticleById($id, 0);
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
if (!$_SESSION["bw_limit"]) {
|
|
|
|
foreach ($cids as $cid) {
|
|
|
|
if ($cid) {
|
2013-04-17 16:34:18 +02:00
|
|
|
array_push($articles, format_article($cid, false, false));
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print json_encode($articles);
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
private function catchupArticleById($id, $cmode) {
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
if ($cmode == 0) {
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("UPDATE ttrss_user_entries SET
|
2013-02-21 15:58:06 +01:00
|
|
|
unread = false,last_read = NOW()
|
|
|
|
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
} else if ($cmode == 1) {
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("UPDATE ttrss_user_entries SET
|
2013-02-21 15:58:06 +01:00
|
|
|
unread = true
|
|
|
|
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
} else {
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("UPDATE ttrss_user_entries SET
|
2013-02-21 15:58:06 +01:00
|
|
|
unread = NOT unread,last_read = NOW()
|
|
|
|
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$feed_id = getArticleFeed($id);
|
|
|
|
ccache_update($feed_id, $_SESSION["uid"]);
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
static function create_published_article($title, $url, $content, $labels_str,
|
2013-02-21 15:58:06 +01:00
|
|
|
$owner_uid) {
|
|
|
|
|
2013-04-15 17:28:11 +02:00
|
|
|
$guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash
|
2013-02-21 15:58:06 +01:00
|
|
|
$content_hash = sha1($content);
|
|
|
|
|
|
|
|
if ($labels_str != "") {
|
|
|
|
$labels = explode(",", $labels_str);
|
|
|
|
} else {
|
|
|
|
$labels = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$rc = false;
|
|
|
|
|
|
|
|
if (!$title) $title = $url;
|
|
|
|
if (!$title && !$url) return false;
|
|
|
|
|
|
|
|
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false;
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("BEGIN");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
// only check for our user data here, others might have shared this with different content etc
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
|
2014-07-16 22:39:13 +02:00
|
|
|
guid = '$guid' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
$ref_id = db_fetch_result($result, 0, "id");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT int_id FROM ttrss_user_entries WHERE
|
2013-02-21 15:58:06 +01:00
|
|
|
ref_id = '$ref_id' AND owner_uid = '$owner_uid' LIMIT 1");
|
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
$int_id = db_fetch_result($result, 0, "int_id");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("UPDATE ttrss_entries SET
|
2013-02-21 15:58:06 +01:00
|
|
|
content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("UPDATE ttrss_user_entries SET published = true,
|
2013-03-25 07:30:01 +01:00
|
|
|
last_published = NOW() WHERE
|
2013-02-21 15:58:06 +01:00
|
|
|
int_id = '$int_id' AND owner_uid = '$owner_uid'");
|
|
|
|
} else {
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("INSERT INTO ttrss_user_entries
|
2013-03-25 07:30:01 +01:00
|
|
|
(ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
|
|
|
|
last_read, note, unread, last_published)
|
2013-02-21 15:58:06 +01:00
|
|
|
VALUES
|
2013-03-25 07:30:01 +01:00
|
|
|
('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())");
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count($labels) != 0) {
|
|
|
|
foreach ($labels as $label) {
|
2013-04-17 16:34:18 +02:00
|
|
|
label_add_article($ref_id, trim($label), $owner_uid);
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rc = true;
|
|
|
|
|
|
|
|
} else {
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("INSERT INTO ttrss_entries
|
2013-02-21 15:58:06 +01:00
|
|
|
(title, guid, link, updated, content, content_hash, date_entered, date_updated)
|
|
|
|
VALUES
|
|
|
|
('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$result = db_query("SELECT id FROM ttrss_entries WHERE guid = '$guid'");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
if (db_num_rows($result) != 0) {
|
|
|
|
$ref_id = db_fetch_result($result, 0, "id");
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("INSERT INTO ttrss_user_entries
|
2013-03-25 07:30:01 +01:00
|
|
|
(ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
|
|
|
|
last_read, note, unread, last_published)
|
2013-02-21 15:58:06 +01:00
|
|
|
VALUES
|
2013-03-25 07:30:01 +01:00
|
|
|
('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false, NOW())");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
if (count($labels) != 0) {
|
|
|
|
foreach ($labels as $label) {
|
2013-04-17 16:34:18 +02:00
|
|
|
label_add_article($ref_id, trim($label), $owner_uid);
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$rc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
db_query("COMMIT");
|
2013-02-21 15:58:06 +01:00
|
|
|
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
2013-04-01 09:14:27 +02:00
|
|
|
function editArticleTags() {
|
|
|
|
|
|
|
|
print __("Tags for this article (separated by commas):")."<br>";
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$param = $this->dbh->escape_string($_REQUEST['param']);
|
2013-04-01 09:14:27 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$tags = get_article_tags($this->dbh->escape_string($param));
|
2013-04-01 09:14:27 +02:00
|
|
|
|
|
|
|
$tags_str = join(", ", $tags);
|
|
|
|
|
|
|
|
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$param\">";
|
2013-04-02 12:52:21 +02:00
|
|
|
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"article\">";
|
2013-04-01 09:14:27 +02:00
|
|
|
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">";
|
|
|
|
|
|
|
|
print "<table width='100%'><tr><td>";
|
|
|
|
|
|
|
|
print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
|
2015-08-11 17:44:07 +02:00
|
|
|
style='font-size : 12px; width : 98%' id=\"tags_str\"
|
2013-04-01 09:14:27 +02:00
|
|
|
name='tags_str'>$tags_str</textarea>
|
|
|
|
<div class=\"autocomplete\" id=\"tags_choices\"
|
|
|
|
style=\"display:none\"></div>";
|
|
|
|
|
|
|
|
print "</td></tr></table>";
|
|
|
|
|
|
|
|
print "<div class='dlgButtons'>";
|
|
|
|
|
|
|
|
print "<button dojoType=\"dijit.form.Button\"
|
|
|
|
onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> ";
|
|
|
|
print "<button dojoType=\"dijit.form.Button\"
|
|
|
|
onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>";
|
|
|
|
print "</div>";
|
|
|
|
|
|
|
|
}
|
2013-02-21 15:58:06 +01:00
|
|
|
|
2013-04-02 12:41:41 +02:00
|
|
|
function setScore() {
|
2013-04-17 18:12:14 +02:00
|
|
|
$ids = $this->dbh->escape_string($_REQUEST['id']);
|
|
|
|
$score = (int)$this->dbh->escape_string($_REQUEST['score']);
|
2013-04-02 12:41:41 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("UPDATE ttrss_user_entries SET
|
2013-04-02 12:41:41 +02:00
|
|
|
score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
|
2013-05-07 09:35:10 +02:00
|
|
|
print json_encode(array("id" => $ids,
|
2015-06-17 21:04:32 +02:00
|
|
|
"score" => (int)$score,
|
|
|
|
"score_pic" => get_score_pic($score)));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScore() {
|
|
|
|
$id = $this->dbh->escape_string($_REQUEST['id']);
|
|
|
|
|
|
|
|
$result = $this->dbh->query("SELECT score FROM ttrss_user_entries WHERE ref_id = $id AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
$score = $this->dbh->fetch_result($result, 0, "score");
|
|
|
|
|
|
|
|
print json_encode(array("id" => $id,
|
|
|
|
"score" => (int)$score,
|
2013-04-02 12:41:41 +02:00
|
|
|
"score_pic" => get_score_pic($score)));
|
|
|
|
}
|
|
|
|
|
2013-02-21 15:58:06 +01:00
|
|
|
|
2013-04-02 12:52:21 +02:00
|
|
|
function setArticleTags() {
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$id = $this->dbh->escape_string($_REQUEST["id"]);
|
2013-04-02 12:52:21 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$tags_str = $this->dbh->escape_string($_REQUEST["tags_str"]);
|
2013-04-02 12:52:21 +02:00
|
|
|
$tags = array_unique(trim_array(explode(",", $tags_str)));
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("BEGIN");
|
2013-04-02 12:52:21 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$result = $this->dbh->query("SELECT int_id FROM ttrss_user_entries WHERE
|
2013-04-02 12:52:21 +02:00
|
|
|
ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
if ($this->dbh->num_rows($result) == 1) {
|
2013-04-02 12:52:21 +02:00
|
|
|
|
|
|
|
$tags_to_cache = array();
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$int_id = $this->dbh->fetch_result($result, 0, "int_id");
|
2013-04-02 12:52:21 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("DELETE FROM ttrss_tags WHERE
|
2013-04-02 12:52:21 +02:00
|
|
|
post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
|
|
|
|
|
|
|
|
foreach ($tags as $tag) {
|
|
|
|
$tag = sanitize_tag($tag);
|
|
|
|
|
|
|
|
if (!tag_is_valid($tag)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match("/^[0-9]*$/", $tag)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print "<!-- $id : $int_id : $tag -->";
|
|
|
|
|
|
|
|
if ($tag != '') {
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("INSERT INTO ttrss_tags
|
2013-04-02 12:52:21 +02:00
|
|
|
(post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($tags_to_cache, $tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update tag cache */
|
|
|
|
|
|
|
|
sort($tags_to_cache);
|
|
|
|
$tags_str = join(",", $tags_to_cache);
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("UPDATE ttrss_user_entries
|
2013-04-02 12:52:21 +02:00
|
|
|
SET tag_cache = '$tags_str' WHERE ref_id = '$id'
|
|
|
|
AND owner_uid = " . $_SESSION["uid"]);
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$this->dbh->query("COMMIT");
|
2013-04-02 12:52:21 +02:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$tags = get_article_tags($id);
|
2013-04-02 12:52:21 +02:00
|
|
|
$tags_str = format_tags_string($tags, $id);
|
|
|
|
$tags_str_full = join(", ", $tags);
|
|
|
|
|
|
|
|
if (!$tags_str_full) $tags_str_full = __("no tags");
|
|
|
|
|
|
|
|
print json_encode(array("id" => (int)$id,
|
|
|
|
"content" => $tags_str, "content_full" => $tags_str_full));
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:53:36 +02:00
|
|
|
|
|
|
|
function completeTags() {
|
2013-04-17 18:12:14 +02:00
|
|
|
$search = $this->dbh->escape_string($_REQUEST["search"]);
|
2013-04-02 12:53:36 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$result = $this->dbh->query("SELECT DISTINCT tag_name FROM ttrss_tags
|
2013-04-02 12:53:36 +02:00
|
|
|
WHERE owner_uid = '".$_SESSION["uid"]."' AND
|
|
|
|
tag_name LIKE '$search%' ORDER BY tag_name
|
|
|
|
LIMIT 10");
|
|
|
|
|
|
|
|
print "<ul>";
|
2013-04-17 18:12:14 +02:00
|
|
|
while ($line = $this->dbh->fetch_assoc($result)) {
|
2013-04-02 12:53:36 +02:00
|
|
|
print "<li>" . $line["tag_name"] . "</li>";
|
|
|
|
}
|
|
|
|
print "</ul>";
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:56:08 +02:00
|
|
|
function assigntolabel() {
|
|
|
|
return $this->labelops(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removefromlabel() {
|
|
|
|
return $this->labelops(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function labelops($assign) {
|
|
|
|
$reply = array();
|
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"]));
|
|
|
|
$label_id = $this->dbh->escape_string($_REQUEST["lid"]);
|
2013-04-02 12:56:08 +02:00
|
|
|
|
2013-04-17 18:12:14 +02:00
|
|
|
$label = $this->dbh->escape_string(label_find_caption($label_id,
|
2013-04-02 12:56:08 +02:00
|
|
|
$_SESSION["uid"]));
|
|
|
|
|
|
|
|
$reply["info-for-headlines"] = array();
|
|
|
|
|
|
|
|
if ($label) {
|
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
|
|
|
|
if ($assign)
|
2013-04-17 16:34:18 +02:00
|
|
|
label_add_article($id, $label, $_SESSION["uid"]);
|
2013-04-02 12:56:08 +02:00
|
|
|
else
|
2013-04-17 16:34:18 +02:00
|
|
|
label_remove_article($id, $label, $_SESSION["uid"]);
|
2013-04-02 12:56:08 +02:00
|
|
|
|
2013-04-17 16:34:18 +02:00
|
|
|
$labels = get_article_labels($id, $_SESSION["uid"]);
|
2013-04-02 12:56:08 +02:00
|
|
|
|
|
|
|
array_push($reply["info-for-headlines"],
|
|
|
|
array("id" => $id, "labels" => format_article_labels($labels, $id)));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$reply["message"] = "UPDATE_COUNTERS";
|
|
|
|
|
|
|
|
print json_encode($reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 12:53:36 +02:00
|
|
|
|
2013-02-21 15:58:06 +01:00
|
|
|
}
|