diff options
author | Heiko Adams <[email protected]> | 2013-04-02 13:38:42 +0200 |
---|---|---|
committer | Heiko Adams <[email protected]> | 2013-04-02 13:38:42 +0200 |
commit | 127585a05cba0f9d5d79ed5cf83394f04a7138d4 (patch) | |
tree | da04bcc463b90efa34c6763bd3fc7399a9dcff90 /classes | |
parent | 58f42816c56a8ea82f1fabe1ba83794005f1c7d6 (diff) | |
parent | 4b7726f0b44db36ad12c0a0918a9129c8cbb1caa (diff) |
Merge branch 'master' of https://github.com/HeikoAdams/Tiny-Tiny-RSS
Diffstat (limited to 'classes')
-rw-r--r-- | classes/article.php | 136 | ||||
-rw-r--r-- | classes/pref/feeds.php | 86 | ||||
-rw-r--r-- | classes/rpc.php | 289 |
3 files changed, 220 insertions, 291 deletions
diff --git a/classes/article.php b/classes/article.php index 79c94f59b..9a0970140 100644 --- a/classes/article.php +++ b/classes/article.php @@ -185,7 +185,7 @@ class Article extends Handler_Protected { $tags_str = join(", ", $tags); print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$param\">"; - print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"article\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">"; print "<table width='100%'><tr><td>"; @@ -208,5 +208,139 @@ class Article extends Handler_Protected { } + function setScore() { + $ids = db_escape_string($this->link, $_REQUEST['id']); + $score = (int)db_escape_string($this->link, $_REQUEST['score']); + + db_query($this->link, "UPDATE ttrss_user_entries SET + score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); + + print json_encode(array("id" => $id, + "score_pic" => get_score_pic($score))); + } + + + function setArticleTags() { + + $id = db_escape_string($this->link, $_REQUEST["id"]); + + $tags_str = db_escape_string($this->link, $_REQUEST["tags_str"]); + $tags = array_unique(trim_array(explode(",", $tags_str))); + + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); + + if (db_num_rows($result) == 1) { + + $tags_to_cache = array(); + + $int_id = db_fetch_result($result, 0, "int_id"); + + db_query($this->link, "DELETE FROM ttrss_tags WHERE + 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 != '') { + db_query($this->link, "INSERT INTO ttrss_tags + (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); + + db_query($this->link, "UPDATE ttrss_user_entries + SET tag_cache = '$tags_str' WHERE ref_id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } + + db_query($this->link, "COMMIT"); + + $tags = get_article_tags($this->link, $id); + $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)); + } + + + function completeTags() { + $search = db_escape_string($this->link, $_REQUEST["search"]); + + $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags + WHERE owner_uid = '".$_SESSION["uid"]."' AND + tag_name LIKE '$search%' ORDER BY tag_name + LIMIT 10"); + + print "<ul>"; + while ($line = db_fetch_assoc($result)) { + print "<li>" . $line["tag_name"] . "</li>"; + } + print "</ul>"; + } + + function assigntolabel() { + return $this->labelops(true); + } + + function removefromlabel() { + return $this->labelops(false); + } + + private function labelops($assign) { + $reply = array(); + + $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); + $label_id = db_escape_string($this->link, $_REQUEST["lid"]); + + $label = db_escape_string($this->link, label_find_caption($this->link, $label_id, + $_SESSION["uid"])); + + $reply["info-for-headlines"] = array(); + + if ($label) { + + foreach ($ids as $id) { + + if ($assign) + label_add_article($this->link, $id, $label, $_SESSION["uid"]); + else + label_remove_article($this->link, $id, $label, $_SESSION["uid"]); + + $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); + + array_push($reply["info-for-headlines"], + array("id" => $id, "labels" => format_article_labels($labels, $id))); + + } + } + + $reply["message"] = "UPDATE_COUNTERS"; + + print json_encode($reply); + } + + } diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index eda03d126..7fb64623e 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1751,7 +1751,7 @@ class Pref_Feeds extends Handler_Protected { } function batchSubscribe() { - print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">"; print "<table width='100%'><tr><td> @@ -1798,6 +1798,90 @@ class Pref_Feeds extends Handler_Protected { </div>"; } + function batchAddFeeds() { + $cat_id = db_escape_string($this->link, $_REQUEST['cat']); + $feeds = explode("\n", db_escape_string($this->link, $_REQUEST['feeds'])); + $login = db_escape_string($this->link, $_REQUEST['login']); + $pass = db_escape_string($this->link, $_REQUEST['pass']); + + foreach ($feeds as $feed) { + $feed = trim($feed); + + if (validate_feed_url($feed)) { + + db_query($this->link, "BEGIN"); + + if ($cat_id == "0" || !$cat_id) { + $cat_qpart = "NULL"; + } else { + $cat_qpart = "'$cat_id'"; + } + + $result = db_query($this->link, + "SELECT id FROM ttrss_feeds + WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + $result = db_query($this->link, + "INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method) + VALUES ('".$_SESSION["uid"]."', '$feed', + '[Unknown]', $cat_qpart, '$login', '$pass', 0)"); + } + + db_query($this->link, "COMMIT"); + } + } + } + + function regenOPMLKey() { + $this->update_feed_access_key($this->link, 'OPML:Publish', + false, $_SESSION["uid"]); + + $new_link = Opml::opml_publish_url($this->link); + + print json_encode(array("link" => $new_link)); + } + + function regenFeedKey() { + $feed_id = db_escape_string($this->link, $_REQUEST['id']); + $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true"; + + $new_key = $this->update_feed_access_key($this->link, $feed_id, $is_cat); + + print json_encode(array("link" => $new_key)); + } + + + private function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) { + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + + $sql_is_cat = bool_to_sql_bool($is_cat); + + $result = db_query($link, "SELECT access_key FROM ttrss_access_keys + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + AND owner_uid = " . $owner_uid); + + if (db_num_rows($result) == 1) { + $key = db_escape_string($this->link, sha1(uniqid(rand(), true))); + + db_query($link, "UPDATE ttrss_access_keys SET access_key = '$key' + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + AND owner_uid = " . $owner_uid); + + return $key; + + } else { + return get_feed_access_key($link, $feed_id, $is_cat, $owner_uid); + } + } + + // Silent + function clearKeys() { + db_query($this->link, "DELETE FROM ttrss_access_keys WHERE + owner_uid = " . $_SESSION["uid"]); + } + } ?> diff --git a/classes/rpc.php b/classes/rpc.php index 34f623b06..a63392095 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -347,79 +347,6 @@ class RPC extends Handler_Protected { print json_encode($reply); } - function setArticleTags() { - - $id = db_escape_string($this->link, $_REQUEST["id"]); - - $tags_str = db_escape_string($this->link, $_REQUEST["tags_str"]); - $tags = array_unique(trim_array(explode(",", $tags_str))); - - db_query($this->link, "BEGIN"); - - $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE - ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); - - if (db_num_rows($result) == 1) { - - $tags_to_cache = array(); - - $int_id = db_fetch_result($result, 0, "int_id"); - - db_query($this->link, "DELETE FROM ttrss_tags WHERE - 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 != '') { - db_query($this->link, "INSERT INTO ttrss_tags - (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); - - db_query($this->link, "UPDATE ttrss_user_entries - SET tag_cache = '$tags_str' WHERE ref_id = '$id' - AND owner_uid = " . $_SESSION["uid"]); - } - - db_query($this->link, "COMMIT"); - - $tags = get_article_tags($this->link, $id); - $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)); - } - - function regenOPMLKey() { - $this->update_feed_access_key($this->link, 'OPML:Publish', - false, $_SESSION["uid"]); - - $new_link = Opml::opml_publish_url($this->link); - - print json_encode(array("link" => $new_link)); - } - function completeLabels() { $search = db_escape_string($this->link, $_REQUEST["search"]); @@ -436,22 +363,6 @@ class RPC extends Handler_Protected { print "</ul>"; } - - function completeTags() { - $search = db_escape_string($this->link, $_REQUEST["search"]); - - $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags - WHERE owner_uid = '".$_SESSION["uid"]."' AND - tag_name LIKE '$search%' ORDER BY tag_name - LIMIT 10"); - - print "<ul>"; - while ($line = db_fetch_assoc($result)) { - print "<li>" . $line["tag_name"] . "</li>"; - } - print "</ul>"; - } - function purge() { $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); $days = sprintf("%d", $_REQUEST["days"]); @@ -467,68 +378,6 @@ class RPC extends Handler_Protected { } } - function getArticles() { - $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); - $articles = array(); - - foreach ($ids as $id) { - if ($id) { - array_push($articles, format_article($this->link, $id, 0, false)); - } - } - - print json_encode($articles); - } - - function checkDate() { - $date = db_escape_string($this->link, $_REQUEST["date"]); - $date_parsed = strtotime($date); - - print json_encode(array("result" => (bool)$date_parsed, - "date" => date("c", $date_parsed))); - } - - function assigntolabel() { - return $this->labelops(true); - } - - function removefromlabel() { - return $this->labelops(false); - } - - function labelops($assign) { - $reply = array(); - - $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); - $label_id = db_escape_string($this->link, $_REQUEST["lid"]); - - $label = db_escape_string($this->link, label_find_caption($this->link, $label_id, - $_SESSION["uid"])); - - $reply["info-for-headlines"] = array(); - - if ($label) { - - foreach ($ids as $id) { - - if ($assign) - label_add_article($this->link, $id, $label, $_SESSION["uid"]); - else - label_remove_article($this->link, $id, $label, $_SESSION["uid"]); - - $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); - - array_push($reply["info-for-headlines"], - array("id" => $id, "labels" => format_article_labels($labels, $id))); - - } - } - - $reply["message"] = "UPDATE_COUNTERS"; - - print json_encode($reply); - } - function updateFeedBrowser() { $search = db_escape_string($this->link, $_REQUEST["search"]); $limit = db_escape_string($this->link, $_REQUEST["limit"]); @@ -617,21 +466,6 @@ class RPC extends Handler_Protected { print_feed_cat_select($this->link, "cat_id", $id); } - function regenFeedKey() { - $feed_id = db_escape_string($this->link, $_REQUEST['id']); - $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true"; - - $new_key = $this->update_feed_access_key($this->link, $feed_id, $is_cat); - - print json_encode(array("link" => $new_key)); - } - - // Silent - function clearKeys() { - db_query($this->link, "DELETE FROM ttrss_access_keys WHERE - owner_uid = " . $_SESSION["uid"]); - } - // Silent function clearArticleKeys() { db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE @@ -640,79 +474,6 @@ class RPC extends Handler_Protected { return; } - function verifyRegexp() { - $reg_exp = $_REQUEST["reg_exp"]; - - $status = @preg_match("/$reg_exp/i", "TEST") !== false; - - print json_encode(array("status" => $status)); - } - - /* function buttonPlugin() { - $pclass = "button_" . basename($_REQUEST['plugin']); - $method = $_REQUEST['plugin_method']; - - if (class_exists($pclass)) { - $plugin = new $pclass($this->link); - if (method_exists($plugin, $method)) { - return $plugin->$method(); - } - } - } */ - - function genHash() { - $hash = sha1(uniqid(rand(), true)); - - print json_encode(array("hash" => $hash)); - } - - function batchAddFeeds() { - $cat_id = db_escape_string($this->link, $_REQUEST['cat']); - $feeds = explode("\n", db_escape_string($this->link, $_REQUEST['feeds'])); - $login = db_escape_string($this->link, $_REQUEST['login']); - $pass = db_escape_string($this->link, $_REQUEST['pass']); - - foreach ($feeds as $feed) { - $feed = trim($feed); - - if (validate_feed_url($feed)) { - - db_query($this->link, "BEGIN"); - - if ($cat_id == "0" || !$cat_id) { - $cat_qpart = "NULL"; - } else { - $cat_qpart = "'$cat_id'"; - } - - $result = db_query($this->link, - "SELECT id FROM ttrss_feeds - WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - $result = db_query($this->link, - "INSERT INTO ttrss_feeds - (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method) - VALUES ('".$_SESSION["uid"]."', '$feed', - '[Unknown]', $cat_qpart, '$login', '$pass', 0)"); - } - - db_query($this->link, "COMMIT"); - } - } - } - - function setScore() { - $ids = db_escape_string($this->link, $_REQUEST['id']); - $score = (int)db_escape_string($this->link, $_REQUEST['score']); - - db_query($this->link, "UPDATE ttrss_user_entries SET - score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); - - print json_encode(array("id" => $id, - "score_pic" => get_score_pic($score))); - } - function setpanelmode() { $wide = (int) $_REQUEST["wide"]; @@ -797,29 +558,6 @@ class RPC extends Handler_Protected { } - function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) { - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; - - $sql_is_cat = bool_to_sql_bool($is_cat); - - $result = db_query($link, "SELECT access_key FROM ttrss_access_keys - WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat - AND owner_uid = " . $owner_uid); - - if (db_num_rows($result) == 1) { - $key = db_escape_string($this->link, sha1(uniqid(rand(), true))); - - db_query($link, "UPDATE ttrss_access_keys SET access_key = '$key' - WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat - AND owner_uid = " . $owner_uid); - - return $key; - - } else { - return get_feed_access_key($link, $feed_id, $is_cat, $owner_uid); - } - } - private function markArticlesById($link, $ids, $cmode) { $tmp_ids = array(); @@ -896,32 +634,5 @@ class RPC extends Handler_Protected { } } - function cdmArticlePreview() { - $id = db_escape_string($this->link, $_REQUEST['id']); - - $result = db_query($this->link, "SELECT link, - ttrss_entries.title, content, feed_url - FROM - ttrss_entries, ttrss_user_entries - LEFT JOIN ttrss_feeds ON (ttrss_user_entries.feed_id = ttrss_feeds.id) - WHERE ref_id = '$id' AND ref_id = ttrss_entries.id AND - ttrss_user_entries.owner_uid = ". $_SESSION["uid"]); - - if (db_num_rows($result) != 0) { - $link = db_fetch_result($result, 0, "link"); - $title = db_fetch_result($result, 0, "title"); - $feed_url = db_fetch_result($result, 0, "feed_url"); - - $content = sanitize($this->link, - db_fetch_result($result, 0, "content"), false, false, $feed_url); - - print "<div class='content'>".$content."</content>"; - - } else { - print "Article not found."; - } - - } - } ?> |