From 50832719563627e958f92ba2a2b7b8c2b4fed47e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 22 Jan 2013 22:36:16 +0400 Subject: [PATCH] move some more functions out of functions.php; fix opml.php failing due to redeclared autoload --- classes/api.php | 2 +- classes/article.php | 87 ++++++++++++++++++++++++++++++++++ classes/dlg.php | 2 +- classes/handler/public.php | 2 +- classes/opml.php | 10 ++++ classes/rpc.php | 2 +- include/functions.php | 95 -------------------------------------- opml.php | 7 --- 8 files changed, 101 insertions(+), 106 deletions(-) diff --git a/classes/api.php b/classes/api.php index 04be5c7a..9b9a5bbe 100644 --- a/classes/api.php +++ b/classes/api.php @@ -439,7 +439,7 @@ class API extends Handler { $url = db_escape_string(strip_tags($_REQUEST["url"])); $content = db_escape_string(strip_tags($_REQUEST["content"])); - if (create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) { + if (Article::create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) { print $this->wrap(self::STATUS_OK, array("status" => 'OK')); } else { print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); diff --git a/classes/article.php b/classes/article.php index 0cb7073b..ec027640 100644 --- a/classes/article.php +++ b/classes/article.php @@ -85,5 +85,92 @@ class Article extends Handler_Protected { ccache_update($link, $feed_id, $_SESSION["uid"]); } + static function create_published_article($link, $title, $url, $content, $labels_str, + $owner_uid) { + + $guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash + $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; + + db_query($link, "BEGIN"); + + // only check for our user data here, others might have shared this with different content etc + $result = db_query($link, "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE + link = '$url' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) != 0) { + $ref_id = db_fetch_result($result, 0, "id"); + + $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE + 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"); + + db_query($link, "UPDATE ttrss_entries SET + content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'"); + + db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE + int_id = '$int_id' AND owner_uid = '$owner_uid'"); + } else { + + db_query($link, "INSERT INTO ttrss_user_entries + (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread) + VALUES + ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)"); + } + + if (count($labels) != 0) { + foreach ($labels as $label) { + label_add_article($link, $ref_id, trim($label), $owner_uid); + } + } + + $rc = true; + + } else { + $result = db_query($link, "INSERT INTO ttrss_entries + (title, guid, link, updated, content, content_hash, date_entered, date_updated) + VALUES + ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())"); + + $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'"); + + if (db_num_rows($result) != 0) { + $ref_id = db_fetch_result($result, 0, "id"); + + db_query($link, "INSERT INTO ttrss_user_entries + (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread) + VALUES + ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)"); + + if (count($labels) != 0) { + foreach ($labels as $label) { + label_add_article($link, $ref_id, trim($label), $owner_uid); + } + } + + $rc = true; + } + } + + db_query($link, "COMMIT"); + + return $rc; + } + + } diff --git a/classes/dlg.php b/classes/dlg.php index 3a980ec8..30dfa1ce 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -168,7 +168,7 @@ class Dlg extends Handler_Protected { print "".__('Public OPML URL').""; print "link); + $url_path = Opml::opml_publish_url($this->link); print __("Your Public OPML URL is:"); diff --git a/classes/handler/public.php b/classes/handler/public.php index 3bc8d3b7..3d2beccc 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -376,7 +376,7 @@ class Handler_Public extends Handler { $content = db_escape_string(strip_tags($_REQUEST["content"])); $labels = db_escape_string(strip_tags($_REQUEST["labels"])); - create_published_article($this->link, $title, $url, $content, $labels, + Article::create_published_article($this->link, $title, $url, $content, $labels, $_SESSION["uid"]); print "