]> git.wh0rd.org Git - tt-rss.git/commitdiff
move some more functions out of functions.php; fix opml.php failing due to redeclared...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 22 Jan 2013 18:36:16 +0000 (22:36 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 22 Jan 2013 18:36:16 +0000 (22:36 +0400)
classes/api.php
classes/article.php
classes/dlg.php
classes/handler/public.php
classes/opml.php
classes/rpc.php
include/functions.php
opml.php

index 04be5c7a819c5917f1c05ab75d67be45effd1379..9b9a5bbe500b02e26366411b1c8d946e19d4b909 100644 (file)
@@ -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'));
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
index 3a980ec8bb7de006c477c680190b818e8d209a4a..30dfa1ce1572cfe61389382132ed5126db315e51 100644 (file)
@@ -168,7 +168,7 @@ class Dlg extends Handler_Protected {
                print "<title>".__('Public OPML URL')."</title>";
                print "<content><![CDATA[";
 
-               $url_path = opml_publish_url($this->link);
+               $url_path = Opml::opml_publish_url($this->link);
 
                print __("Your Public OPML URL is:");
 
index 3bc8d3b794e91732dc227e312d0744c11e99f83a..3d2becccde04c0c5d4ac4fb94c50e3515373d336 100644 (file)
@@ -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 "<script type='text/javascript'>";
index 10967c171713958909d0a2d1578679e2f868df61..b91e395d1129d4108bd3dc18a66fae796fc7323b 100644 (file)
@@ -479,5 +479,15 @@ class Opml extends Handler_Protected {
                print "$msg<br/>";
        }
 
+       static function opml_publish_url($link){
+
+               $url_path = get_self_url_prefix();
+               $url_path .= "/opml.php?op=publish&key=" .
+                       get_feed_access_key($link, 'OPML:Publish', false, $_SESSION["uid"]);
+
+               return $url_path;
+       }
+
+
 }
 ?>
index 0e6fa3379e8514f9319d66bcb8327ebe57244afb..d529e496c99bf8b04cdc798f722dc5b7e8e8ff93 100644 (file)
@@ -370,7 +370,7 @@ class RPC extends Handler_Protected {
                $this->update_feed_access_key($this->link, 'OPML:Publish',
                false, $_SESSION["uid"]);
 
-               $new_link = opml_publish_url($this->link);
+               $new_link = Opml::opml_publish_url($this->link);
 
                print json_encode(array("link" => $new_link));
        }
index 5ff0dd49f2ba8cd3bf57621d52da869af304f6a0..59a3e29cf445f1abb37e64c91d0d7d94769432a0 100644 (file)
                }
        }
 
-       function opml_publish_url($link){
-
-               $url_path = get_self_url_prefix();
-               $url_path .= "/opml.php?op=publish&key=" .
-                       get_feed_access_key($link, 'OPML:Publish', false, $_SESSION["uid"]);
-
-               return $url_path;
-       }
-
        /**
         * Compute the Mozilla Firefox feed adding URL from server HOST and REQUEST_URI.
         *
 
        }
 
-       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;
-       }
-
        function implements_interface($class, $interface) {
                return in_array($interface, class_implements($class));
        }
index a997be89b2be080091e9026a6c47b2c313d42e07..623913631e6b75e1d8f8743c1c80e6500274c064 100644 (file)
--- a/opml.php
+++ b/opml.php
@@ -2,13 +2,6 @@
        set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
                get_include_path());
 
-       function __autoload($class) {
-               $file = "classes/".strtolower(basename($class)).".php";
-               if (file_exists($file)) {
-                       require $file;
-               }
-       }
-
        require_once "functions.php";
        require_once "sessions.php";
        require_once "sanity_check.php";