]> git.wh0rd.org - tt-rss.git/blobdiff - classes/article.php
move some more functions out of functions.php; fix opml.php failing due to redeclared...
[tt-rss.git] / classes / article.php
index 0cb7073b510c220870e6602f57ae8e43ad211157..ec02764060557a9d76026680f7e6221e08cc4681 100644 (file)
@@ -85,5 +85,92 @@ class Article extends Handler_Protected {
                ccache_update($link, $feed_id, $_SESSION["uid"]);\r
        }\r
 \r
+       static function create_published_article($link, $title, $url, $content, $labels_str,\r
+                       $owner_uid) {\r
+\r
+               $guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash\r
+               $content_hash = sha1($content);\r
+\r
+               if ($labels_str != "") {\r
+                       $labels = explode(",", $labels_str);\r
+               } else {\r
+                       $labels = array();\r
+               }\r
+\r
+               $rc = false;\r
+\r
+               if (!$title) $title = $url;\r
+               if (!$title && !$url) return false;\r
+\r
+               if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false;\r
+\r
+               db_query($link, "BEGIN");\r
+\r
+               // only check for our user data here, others might have shared this with different content etc\r
+               $result = db_query($link, "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE\r
+                       link = '$url' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1");\r
+\r
+               if (db_num_rows($result) != 0) {\r
+                       $ref_id = db_fetch_result($result, 0, "id");\r
+\r
+                       $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\r
+                               ref_id = '$ref_id' AND owner_uid = '$owner_uid' LIMIT 1");\r
+\r
+                       if (db_num_rows($result) != 0) {\r
+                               $int_id = db_fetch_result($result, 0, "int_id");\r
+\r
+                               db_query($link, "UPDATE ttrss_entries SET\r
+                                       content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'");\r
+\r
+                               db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE\r
+                                               int_id = '$int_id' AND owner_uid = '$owner_uid'");\r
+                       } else {\r
+\r
+                               db_query($link, "INSERT INTO ttrss_user_entries\r
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)\r
+                                       VALUES\r
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");\r
+                       }\r
+\r
+                       if (count($labels) != 0) {\r
+                               foreach ($labels as $label) {\r
+                                       label_add_article($link, $ref_id, trim($label), $owner_uid);\r
+                               }\r
+                       }\r
+\r
+                       $rc = true;\r
+\r
+               } else {\r
+                       $result = db_query($link, "INSERT INTO ttrss_entries\r
+                               (title, guid, link, updated, content, content_hash, date_entered, date_updated)\r
+                               VALUES\r
+                               ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");\r
+\r
+                       $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'");\r
+\r
+                       if (db_num_rows($result) != 0) {\r
+                               $ref_id = db_fetch_result($result, 0, "id");\r
+\r
+                               db_query($link, "INSERT INTO ttrss_user_entries\r
+                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)\r
+                                       VALUES\r
+                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");\r
+\r
+                               if (count($labels) != 0) {\r
+                                       foreach ($labels as $label) {\r
+                                               label_add_article($link, $ref_id, trim($label), $owner_uid);\r
+                                       }\r
+                               }\r
+\r
+                               $rc = true;\r
+                       }\r
+               }\r
+\r
+               db_query($link, "COMMIT");\r
+\r
+               return $rc;\r
+       }\r
+\r
+\r
 \r
 }\r