]> git.wh0rd.org Git - tt-rss.git/commitdiff
drop BACKEND_RSS_TYPE from update_rss_feed, support detection of dc:subject as tags...
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 25 Dec 2006 07:53:57 +0000 (08:53 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 25 Dec 2006 07:53:57 +0000 (08:53 +0100)
functions.php

index 527a34d054788c2f2edcf11f97df4050bdb925f8..e4400cad48508dfd2c094cf36a4cd290dc1c0034 100644 (file)
 
                        foreach ($iterator as $item) {
 
-                               if (RSS_BACKEND_TYPE == "magpie") {
-                               
-                                       $entry_guid = $item["id"];
-               
-                                       if (!$entry_guid) $entry_guid = $item["guid"];
-                                       if (!$entry_guid) $entry_guid = $item["link"];
-                                       if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]);
-
-                                       if (!$entry_guid) continue;
-       
-                                       $entry_timestamp = "";
+                               $entry_guid = $item["id"];
        
-                                       $rss_2_date = $item['pubdate'];
-                                       $rss_1_date = $item['dc']['date'];
-                                       $atom_date = $item['issued'];
-                                       if (!$atom_date) $atom_date = $item['updated'];
+                               if (!$entry_guid) $entry_guid = $item["guid"];
+                               if (!$entry_guid) $entry_guid = $item["link"];
+                               if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]);
+
+                               if (!$entry_guid) continue;
+
+                               $entry_timestamp = "";
+
+                               $rss_2_date = $item['pubdate'];
+                               $rss_1_date = $item['dc']['date'];
+                               $atom_date = $item['issued'];
+                               if (!$atom_date) $atom_date = $item['updated'];
+                       
+                               if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
+                               if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
+                               if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
                                
-                                       if ($atom_date != "") $entry_timestamp = parse_w3cdtf($atom_date);
-                                       if ($rss_1_date != "") $entry_timestamp = parse_w3cdtf($rss_1_date);
-                                       if ($rss_2_date != "") $entry_timestamp = strtotime($rss_2_date);
-                                       
-                                       if ($entry_timestamp == "") {
-                                               $entry_timestamp = time();
-                                               $no_orig_date = 'true';
-                                       } else {
-                                               $no_orig_date = 'false';
-                                       }
-       
-                                       $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
-       
-                                       $entry_title = trim(strip_tags($item["title"]));
-       
-                                       // strange Magpie workaround
-                                       $entry_link = $item["link_"];
-                                       if (!$entry_link) $entry_link = $item["link"];
-       
-                                       if (!$entry_title) continue;
+                               if ($entry_timestamp == "") {
+                                       $entry_timestamp = time();
+                                       $no_orig_date = 'true';
+                               } else {
+                                       $no_orig_date = 'false';
+                               }
+
+                               $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
+
+                               $entry_title = trim(strip_tags($item["title"]));
+
+                               // strange Magpie workaround
+                               $entry_link = $item["link_"];
+                               if (!$entry_link) $entry_link = $item["link"];
+
+                               if (!$entry_title) continue;
 #                                      if (!$entry_link) continue;
 
-                                       $entry_link = strip_tags($entry_link);
+                               $entry_link = strip_tags($entry_link);
 
-                                       $entry_content = $item["content:escaped"];
-       
-                                       if (!$entry_content) $entry_content = $item["content:encoded"];
-                                       if (!$entry_content) $entry_content = $item["content"];
-                                       if (!$entry_content) $entry_content = $item["atom_content"];
-                                       if (!$entry_content) $entry_content = $item["summary"];
-                                       if (!$entry_content) $entry_content = $item["description"];
-       
-       //                              if (!$entry_content) continue;
-       
-                                       // WTF
-                                       if (is_array($entry_content)) {
-                                               $entry_content = $entry_content["encoded"];
-                                               if (!$entry_content) $entry_content = $entry_content["escaped"];
-                                       }
-       
-       //                              print_r($item);
-       //                              print_r(htmlspecialchars($entry_content));
-       //                              print "<br>";
-       
-                                       $entry_content_unescaped = $entry_content;
-                                       $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
-       
-                                       $entry_comments = strip_tags($item["comments"]);
+                               $entry_content = $item["content:escaped"];
 
-                                       $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
+                               if (!$entry_content) $entry_content = $item["content:encoded"];
+                               if (!$entry_content) $entry_content = $item["content"];
+                               if (!$entry_content) $entry_content = $item["atom_content"];
+                               if (!$entry_content) $entry_content = $item["summary"];
+                               if (!$entry_content) $entry_content = $item["description"];
 
-                                       if (!$entry_author) {
-                                               $entry_author = db_escape_string(strip_tags($item['author']));
-                                       }
+//                             if (!$entry_content) continue;
 
-                                       $entry_guid = db_escape_string(strip_tags($entry_guid));
-       
-                                       $result = db_query($link, "SELECT id FROM       ttrss_entries 
-                                               WHERE guid = '$entry_guid'");
-       
-                                       $entry_content = db_escape_string($entry_content);
-                                       $entry_title = db_escape_string($entry_title);
-                                       $entry_link = db_escape_string($entry_link);
-                                       $entry_comments = db_escape_string($entry_comments);
-       
-                                       $num_comments = db_escape_string($item["slash"]["comments"]);
-       
-                                       if (!$num_comments) $num_comments = 0;
+                               // WTF
+                               if (is_array($entry_content)) {
+                                       $entry_content = $entry_content["encoded"];
+                                       if (!$entry_content) $entry_content = $entry_content["escaped"];
+                               }
+
+//                             print_r($item);
+//                             print_r(htmlspecialchars($entry_content));
+//                             print "<br>";
+
+                               $entry_content_unescaped = $entry_content;
+                               $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
+
+                               $entry_comments = strip_tags($item["comments"]);
+
+                               $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
+
+                               if (!$entry_author) {
+                                       $entry_author = db_escape_string(strip_tags($item['author']));
+                               }
+
+                               $entry_guid = db_escape_string(strip_tags($entry_guid));
+
+                               $result = db_query($link, "SELECT id FROM       ttrss_entries 
+                                       WHERE guid = '$entry_guid'");
+
+                               $entry_content = db_escape_string($entry_content);
+                               $entry_title = db_escape_string($entry_title);
+                               $entry_link = db_escape_string($entry_link);
+                               $entry_comments = db_escape_string($entry_comments);
+
+                               $num_comments = db_escape_string($item["slash"]["comments"]);
+
+                               if (!$num_comments) $num_comments = 0;
+
+                               $dc_subject = $item['dc']['subject'];
+
+                               $subject_tags = false;
+
+                               if (is_array($dc_subject)) {
+                                       $subject_tags = $dc_subject;
+                               } else if ($dc_subject) {
+                                       $subject_tags = array($dc_subject);
                                }
 
                                # sanitize content
 
                                        $manual_tags = trim_array(split(",", $filter_param));
 
-                                       foreach ($manual_tags as $tag) {
-                                               if (!preg_match("/^[0-9]*$/", $tag) && $tag != '') {
+                                       foreach ($manual_tags as $tag) {                                        
+                                               if (tag_is_valid($tag)) {
+                                                       array_push($entry_tags, $tag);
+                                               }
+                                       }
+                               }
+
+                               if ($subject_tags) {
+                                       foreach ($subject_tags as $tag) {
+                                               if (tag_is_valid($tag)) {
                                                        array_push($entry_tags, $tag);
                                                }
                                        }
                return $tmp;
        }
 
+       function tag_is_valid($tag) {
+               return ($tag !='' && !preg_match("/^[0-9]*$/", $tag));
+       }
+
 ?>