]> git.wh0rd.org Git - tt-rss.git/commitdiff
add support for enclosures (closes #165)
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 17 Nov 2007 12:13:08 +0000 (13:13 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 17 Nov 2007 12:13:08 +0000 (13:13 +0100)
functions.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/26.sql
schema/versions/pgsql/26.sql
tt-rss.css

index 613641b318356c40469d9bebfafd5c0696035e6b..6f45a7fe516ddfb77be3dbe82805384b5b58fcce 100644 (file)
                                        }
                                }
 
+                               // enclosures
+
+                               $enclosures = array();
+
+                               if (ENABLE_SIMPLEPIE) {
+                                       $encs = $item->get_enclosures();
+
+                                       foreach ($encs as $e) {
+                                               $e_item = array(
+                                                       $e->link, $e->type, $e->length);
+
+                                               array_push($enclosures, $e_item);
+                                       }
+
+                               } else {
+                                       $e_ctr = $item['enclosure#'];
+
+                                       if ($e_ctr > 0) {
+                                               $e_item = array($item['enclosure@url'],
+                                                       $item['enclosure@type'],
+                                                       $item['enclosure@length']);
+
+                                               array_push($enclosures, $e_item);
+
+                                               for ($i = 2; $i <= $e_ctr; $i++ ) {
+                                                       $e_item = array($item["enclosure#$i@url"],
+                                                               $item["enclosure#$i@type"],
+                                                               $item["enclosure#$i@length"]);
+                                                       array_push($enclosures, $e_item);
+                                               }
+                                       }
+
+                               }
+
                                # sanitize content
                                
 //                             $entry_content = sanitize_rss($entry_content);
                                                ttrss_entries 
                                        WHERE guid = '$entry_guid'");
 
+                               $entry_ref_id = 0;
+                               $entry_int_id = 0;
+
                                if (db_num_rows($result) == 1) {
 
                                        if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
                                                0, "date_entered"));
 
                                        $ref_id = db_fetch_result($result, 0, "id");
+                                       $entry_ref_id = $ref_id;
 
                                        // check for user post link to main table
 
 //                                     error_reporting (DEFAULT_ERROR_LEVEL);
 
                                        $result = db_query($link,
-                                               "SELECT ref_id FROM ttrss_user_entries WHERE
+                                               "SELECT ref_id, int_id FROM ttrss_user_entries WHERE
                                                        ref_id = '$ref_id' AND owner_uid = '$owner_uid'
                                                        $dupcheck_qpart");
 
                                                                (ref_id, owner_uid, feed_id, unread, last_read, marked, published) 
                                                        VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
                                                                $last_read_qpart, $marked, $published)");
+
+                                               $result = db_query($link, 
+                                                       "SELECT int_id FROM ttrss_user_entries WHERE
+                                                               ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND
+                                                               feed_id = '$feed' LIMIT 1");
+
+                                               if (db_num_rows($result) == 1) {
+                                                       $entry_int_id = db_fetch_result($result, 0, "int_id");
+                                               }
+                                       } else {
+                                               $entry_ref_id = db_fetch_result($result, 0, "ref_id");
+                                               $entry_int_id = db_fetch_result($result, 0, "int_id");
                                        }
-                                       
+
+                                       if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+                                               _debug("update_rss_feed: RID: $entry_ref_id, IID: $entry_int_id");
+                                       }
+
                                        $post_needs_update = false;
 
                                        if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) &&
 
                                db_query($link, "COMMIT");
 
+                               if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+                                       _debug("update_rss_feed: looking for enclosures...");
+                               }
+
+                               if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+                                       print_r($enclosures);
+                               }
+
+                               db_query($link, "BEGIN");
+
+                               foreach ($enclosures as $enc) {
+                                       $enc_url = db_escape_string($enc[0]);
+                                       $enc_type = db_escape_string($enc[1]);
+                                       $enc_dur = db_escape_string($enc[2]);
+
+                                       $result = db_query($link, "SELECT id FROM ttrss_enclosures
+                                               WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'");
+
+                                       if (db_num_rows($result) == 0) {
+                                               db_query($link, "INSERT INTO ttrss_enclosures
+                                                       (content_url, content_type, title, duration, post_id) VALUES
+                                                       ('$enc_url', '$enc_type', '', '$enc_dur', '$entry_ref_id')");
+                                       }
+                               }
+
+                               db_query($link, "COMMIT");
+
                                if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
                                        _debug("update_rss_feed: looking for tags...");
                                }
                                
                                        db_query($link, "BEGIN");
                        
-                                       $result = db_query($link, "SELECT id,int_id 
-                                               FROM ttrss_entries,ttrss_user_entries 
-                                               WHERE guid = '$entry_guid' 
-                                               AND feed_id = '$feed' AND ref_id = id
-                                               AND owner_uid = '$owner_uid'");
-
-                                       if (db_num_rows($result) == 1) {
-
-                                               $entry_id = db_fetch_result($result, 0, "id");
-                                               $entry_int_id = db_fetch_result($result, 0, "int_id");
-                                               
                                                foreach ($entry_tags as $tag) {
 
                                                        $tag = sanitize_tag($tag);
                                                                        VALUES ('$owner_uid','$tag', '$entry_int_id')");
                                                        }                                                       
                                                }
-                                       }
+
                                        db_query($link, "COMMIT");
                                } 
 
                                $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
                        }
 
-                       print $line["content"] . "</div>";
+                       print $line["content"];
+
+                       $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
+                               post_id = '$id'");
+
+                       if (db_num_rows($result) > 0) {
+                               print "<div class=\"postEnclosures\">";
+
+                               if (db_num_rows($result) == 1) {
+                                       print __("Attachment:") . " ";
+                               } else {
+                                       print __("Attachments:") . " ";
+                               }
+
+                               $entries = array();
+
+                               while ($line = db_fetch_assoc($result)) {
+
+                                       $url = $line["content_url"];
+
+                                       $filename = substr($url, strrpos($url, "/")+1);
+
+                                       $entry = "<a href=\"" . htmlspecialchars($url) . "\">" .
+                                               $filename . " (" . $line["content_type"] . ")" . "</a>";
+
+                                       array_push($entries, $entry);
+                               }
+
+                               print join(", ", $entries);
+
+                               print "</div>";
+                       }
+               
+                       print "</div>";
                        
                        print "</div>";
 
index c239d6d084416d8f6fbc5cd9e891b7109e2264c2..18f7e0c613fc7d16c45bdad4b166edb681d9b816 100644 (file)
@@ -209,6 +209,7 @@ create table ttrss_enclosures (id serial not null primary key,
        content_type varchar(250) not null,
        post_id integer not null,
        title text not null,
+       duration text not null,
        index (post_id),
        foreign key (post_id) references ttrss_entries(id) ON DELETE cascade);
 
index 0b9eda212b83804ab0cb4769c5b01ec6177380e1..dfb32ca1506bf921609c6e3d37063ce3db99f34f 100644 (file)
@@ -187,6 +187,7 @@ create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
        content_type varchar(250) not null,
        title text not null,
+       duration text not null,
        post_id integer references ttrss_entries(id) ON DELETE cascade NOT NULL);
 
 create table ttrss_prefs_types (id integer not null primary key, 
index 75fe245825c73c3da084e29bddf82f4797e3cf87..14d62b8c022853221b771127ea6a14ee02d4998c 100644 (file)
@@ -8,6 +8,7 @@ create table ttrss_enclosures (id serial not null primary key,
    content_type varchar(250) not null,
    post_id integer not null, 
        title text not null,
+       duration text not null,
    index (post_id),
    foreign key (post_id) references ttrss_entries(id) ON DELETE cascade);
 
index fa1c812ed54d60434b6f6691802cf0e044aa35bd..c7c1be6913ba020a4deeace1de841f58431d142a 100644 (file)
@@ -7,6 +7,7 @@ create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
        content_type varchar(250) not null,
        title text not null,
+       duration text not null,
        post_id integer references ttrss_entries(id) ON DELETE cascade NOT NULL);
 
 update ttrss_version set schema_version = 26;
index f1580b0336fbe898aa02d0ddb4dc0ec8dbe4cceb..cd33911d4beb4355d3be7f5306c45b1dd641c77d 100644 (file)
@@ -56,6 +56,16 @@ div.postReply div.postIcon {
        margin : 10px 0px 10px 10px;
 }
 
+div.postReply div.postEnclosures {
+       border-width : 1px 0px 0px 0px;
+       border-style : dotted;
+       border-color : #c0c0c0;
+       font-size : 8pt;
+       margin-top : 1em;
+       padding-top : 0.2em;
+       color : gray;
+}
+
 div.postReply img.tagsPic {
        width : 16px;
        height : 16px;