]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/googlereaderimport/init.php
af_sort_bayes: move to -attic repo, not really suitable for production use
[tt-rss.git] / plugins / googlereaderimport / init.php
index 8986f469c99927f5f5c6fec0699da405ccd06176..dcb335a0da7ca0e4aee494393bd1ea543b0c41ed 100644 (file)
@@ -30,11 +30,11 @@ class GoogleReaderImport extends Plugin {
 
                _debug("please enter your username:");
 
-               $username = db_escape_string( trim(read_stdin()));
+               $username = db_escape_string(trim(read_stdin()));
 
                _debug("looking up user: $username...");
 
-               $result = db_query( "SELECT id FROM ttrss_users
+               $result = db_query("SELECT id FROM ttrss_users
                        WHERE login = '$username'");
 
                if (db_num_rows($result) == 0) {
@@ -111,19 +111,20 @@ class GoogleReaderImport extends Plugin {
                                foreach ($doc['items'] as $item) {
 //                                     print_r($item);
 
-                                       $guid = db_escape_string( mb_substr($item['id'], 0, 250));
-                                       $title = db_escape_string( $item['title']);
+                                       $guid = db_escape_string(mb_substr($item['id'], 0, 250));
+                                       $title = db_escape_string($item['title']);
                                        $updated = date('Y-m-d h:i:s', $item['updated']);
+                                       $last_marked = date('Y-m-d h:i:s', mb_substr($item['crawlTimeMsec'], 0, 10));
                                        $link = '';
                                        $content = '';
-                                       $author = db_escape_string( $item['author']);
+                                       $author = db_escape_string($item['author']);
                                        $tags = array();
                                        $orig_feed_data = array();
 
                                        if (is_array($item['alternate'])) {
                                                foreach ($item['alternate'] as $alt) {
                                                        if (isset($alt['type']) && $alt['type'] == 'text/html') {
-                                                               $link = db_escape_string( $alt['href']);
+                                                               $link = db_escape_string($alt['href']);
                                                        }
                                                }
                                        }
@@ -164,8 +165,8 @@ class GoogleReaderImport extends Plugin {
                                        $processed++;
 
                                        $imported += (int) $this->create_article($owner_uid, $guid, $title,
-                                               $updated,  $content, $author, $sql_set_marked, $tags,
-                                               $orig_feed_data);
+                                               $link, $updated,  $content, $author, $sql_set_marked, $tags,
+                                               $orig_feed_data, $last_marked);
 
                                        if ($file && $processed % 25 == 0) {
                                                _debug("processed $processed articles...");
@@ -196,7 +197,7 @@ class GoogleReaderImport extends Plugin {
        }
 
        // expects ESCAPED data
-       private function create_article($owner_uid, $guid, $title, $updated,  $content, $author, $marked, $tags, $orig_feed_data) {
+       private function create_article($owner_uid, $guid, $title, $link, $updated,  $content, $author, $marked, $tags, $orig_feed_data, $last_marked) {
 
                if (!$guid) $guid = sha1($link);
 
@@ -206,9 +207,9 @@ class GoogleReaderImport extends Plugin {
 
                $content_hash = sha1($content);
 
-               if (filter_var( FILTER_VALIDATE_URL) === FALSE) return false;
+               if (filter_var(FILTER_VALIDATE_URL) === FALSE) return false;
 
-               db_query( "BEGIN");
+               db_query("BEGIN");
 
                $feed_id = 'NULL';
 
@@ -254,18 +255,18 @@ class GoogleReaderImport extends Plugin {
                        // locate archived entry to file entries in, we don't want to file them in actual feeds because of purging
                        // maybe file marked in real feeds because eh
 
-                       $result = db_query( "SELECT id FROM ttrss_archived_feeds WHERE
+                       $result = db_query("SELECT id FROM ttrss_archived_feeds WHERE
                                feed_url = '".$orig_feed_data['feed_url']."' AND owner_uid = $owner_uid");
 
                        if (db_num_rows($result) != 0) {
                                $orig_feed_id = db_fetch_result($result, 0, "id");
                        } else {
-                               db_query( "INSERT INTO ttrss_archived_feeds
+                               db_query("INSERT INTO ttrss_archived_feeds
                                                (id, owner_uid, title, feed_url, site_url)
                                                SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds
                                                        WHERE id = '$feed_id'");
 
-                               $result = db_query( "SELECT id FROM ttrss_archived_feeds WHERE
+                               $result = db_query("SELECT id FROM ttrss_archived_feeds WHERE
                                        feed_url = '".$orig_feed_data['feed_url']."' AND owner_uid = $owner_uid");
 
                                if (db_num_rows($result) != 0) {
@@ -276,32 +277,32 @@ class GoogleReaderImport extends Plugin {
 
                // delete temporarily inserted feed
                if ($feed_id && $feed_inserted) {
-                               db_query( "DELETE FROM ttrss_feeds WHERE id = $feed_id");
+                               db_query("DELETE FROM ttrss_feeds WHERE id = $feed_id");
                }
 
                if (!$orig_feed_id) $orig_feed_id = 'NULL';
 
-               $result = db_query( "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
+               $result = db_query("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
                        guid = '$guid' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1");
 
                if (db_num_rows($result) == 0) {
-                       $result = db_query( "INSERT INTO ttrss_entries
+                       $result = db_query("INSERT INTO ttrss_entries
                                (title, guid, link, updated, content, content_hash, date_entered, date_updated, author)
                                VALUES
                                ('$title', '$guid', '$link', '$updated', '$content', '$content_hash', NOW(), NOW(), '$author')");
 
-                       $result = db_query( "SELECT id FROM ttrss_entries WHERE guid = '$guid'");
+                       $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '$guid'");
 
                        if (db_num_rows($result) != 0) {
                                $ref_id = db_fetch_result($result, 0, "id");
 
-                               db_query( "INSERT INTO ttrss_user_entries
+                               db_query("INSERT INTO ttrss_user_entries
                                        (ref_id, uuid, feed_id, orig_feed_id, owner_uid, marked, tag_cache, label_cache,
                                                last_read, note, unread, last_marked)
                                        VALUES
-                                       ('$ref_id', '', NULL, $orig_feed_id, $owner_uid, $marked, '', '', NOW(), '', false, NOW())");
+                                       ('$ref_id', '', NULL, $orig_feed_id, $owner_uid, $marked, '', '', '$last_marked', '', false, '$last_marked')");
 
-                               $result = db_query( "SELECT int_id FROM ttrss_user_entries, ttrss_entries
+                               $result = db_query("SELECT int_id FROM ttrss_user_entries, ttrss_entries
                                        WHERE owner_uid = $owner_uid AND ref_id = id AND ref_id = $ref_id");
 
                                if (db_num_rows($result) != 0 && is_array($tags)) {
@@ -311,16 +312,16 @@ class GoogleReaderImport extends Plugin {
 
                                        foreach ($tags as $tag) {
 
-                                               $tag = db_escape_string( sanitize_tag($tag));
+                                               $tag = db_escape_string(sanitize_tag($tag));
 
                                                if (!tag_is_valid($tag)) continue;
 
-                                               $result = db_query( "SELECT id FROM ttrss_tags
+                                               $result = db_query("SELECT id FROM ttrss_tags
                                                        WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND
                                                        owner_uid = '$owner_uid' LIMIT 1");
 
                                                        if ($result && db_num_rows($result) == 0) {
-                                                               db_query( "INSERT INTO ttrss_tags
+                                                               db_query("INSERT INTO ttrss_tags
                                                                        (owner_uid,tag_name,post_int_id)
                                                                        VALUES ('$owner_uid','$tag', '$entry_int_id')");
                                                        }
@@ -331,9 +332,9 @@ class GoogleReaderImport extends Plugin {
                                        /* update the cache */
 
                                        $tags_to_cache = array_unique($tags_to_cache);
-                                       $tags_str = db_escape_string( join(",", $tags_to_cache));
+                                       $tags_str = db_escape_string(join(",", $tags_to_cache));
 
-                                       db_query( "UPDATE ttrss_user_entries
+                                       db_query("UPDATE ttrss_user_entries
                                                SET tag_cache = '$tags_str' WHERE ref_id = '$ref_id'
                                                AND owner_uid = $owner_uid");
                                }
@@ -342,7 +343,7 @@ class GoogleReaderImport extends Plugin {
                        }
                }
 
-               db_query( "COMMIT");
+               db_query("COMMIT");
 
                return $rc;
        }
@@ -374,5 +375,10 @@ class GoogleReaderImport extends Plugin {
 
                print "</div>"; #pane
        }
+
+       function api_version() {
+               return 2;
+       }
+
 }
 ?>