]>
Commit | Line | Data |
---|---|---|
30f782a2 AD |
1 | <?php |
2 | function opml_import_domdoc($link, $owner_uid) { | |
3 | ||
4 | if (is_file($_FILES['opml_file']['tmp_name'])) { | |
5 | $doc = DOMDocument::load($_FILES['opml_file']['tmp_name']); | |
6 | ||
7 | if ($doc) { | |
8 | $body = $doc->getElementsByTagName('body'); | |
9 | ||
10 | $xpath = new DOMXpath($doc); | |
11 | $query = "/opml/body//outline"; | |
12 | ||
13 | $outlines = $xpath->query($query); | |
14 | ||
15 | print "<table>"; | |
16 | ||
17 | foreach ($outlines as $outline) { | |
18 | ||
19 | $feed_title = db_escape_string($outline->attributes->getNamedItem('text')->nodeValue); | |
20 | ||
21 | if (!$feed_title) { | |
22 | $feed_title = db_escape_string($outline->attributes->getNamedItem('title')->nodeValue); | |
23 | } | |
24 | ||
25 | $cat_title = db_escape_string($outline->attributes->getNamedItem('title')->nodeValue); | |
26 | ||
27 | if (!$cat_title) { | |
28 | $cat_title = db_escape_string($outline->attributes->getNamedItem('text')->nodeValue); | |
29 | } | |
30 | ||
31 | $feed_url = db_escape_string($outline->attributes->getNamedItem('xmlUrl')->nodeValue); | |
32 | $site_url = db_escape_string($outline->attributes->getNamedItem('htmlUrl')->nodeValue); | |
33 | ||
34 | if ($cat_title && !$feed_url) { | |
35 | ||
36 | db_query($link, "BEGIN"); | |
37 | ||
38 | $result = db_query($link, "SELECT id FROM | |
39 | ttrss_feed_categories WHERE title = '$cat_title' AND | |
40 | owner_uid = '$owner_uid' LIMIT 1"); | |
41 | ||
42 | if (db_num_rows($result) == 0) { | |
43 | ||
44 | print "Adding category <b>$cat_title</b>...<br>"; | |
45 | ||
46 | db_query($link, "INSERT INTO ttrss_feed_categories | |
47 | (title,owner_uid) | |
48 | VALUES ('$cat_title', '$owner_uid')"); | |
49 | } | |
50 | ||
51 | db_query($link, "COMMIT"); | |
52 | } | |
53 | ||
54 | // print "$active_category : $feed_title : $feed_url<br>"; | |
55 | ||
56 | if (!$feed_title || !$feed_url) continue; | |
57 | ||
58 | db_query($link, "BEGIN"); | |
59 | ||
60 | $cat_id = null; | |
61 | ||
62 | $parent_node = $outline->parentNode; | |
63 | ||
64 | if ($parent_node && $parent_node->nodeName == "outline") { | |
65 | $element_category = $parent_node->attributes->getNamedItem('title')->nodeValue; | |
66 | } else { | |
67 | $element_category = ''; | |
68 | } | |
69 | ||
70 | if ($element_category) { | |
71 | ||
72 | $result = db_query($link, "SELECT id FROM | |
73 | ttrss_feed_categories WHERE title = '$element_category' AND | |
74 | owner_uid = '$owner_uid' LIMIT 1"); | |
75 | ||
76 | if (db_num_rows($result) == 1) { | |
77 | $cat_id = db_fetch_result($result, 0, "id"); | |
78 | } | |
79 | } | |
80 | ||
81 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
82 | (title = '$feed_title' OR feed_url = '$feed_url') | |
83 | AND owner_uid = '$owner_uid'"); | |
84 | ||
ef59e6e8 AD |
85 | print "<tr><td><a target='_new' href='$site_url'><b>$feed_title</b></a></b> |
86 | (<a target='_new' href=\"$feed_url\">rss</a>)</td>"; | |
30f782a2 AD |
87 | |
88 | if (db_num_rows($result) > 0) { | |
89 | print "<td>Already imported.</td>"; | |
90 | } else { | |
91 | ||
92 | if ($cat_id) { | |
93 | $add_query = "INSERT INTO ttrss_feeds | |
94 | (title, feed_url, owner_uid, cat_id, site_url) VALUES | |
95 | ('$feed_title', '$feed_url', '$owner_uid', | |
96 | '$cat_id', '$site_url')"; | |
97 | ||
98 | } else { | |
99 | $add_query = "INSERT INTO ttrss_feeds | |
100 | (title, feed_url, owner_uid, site_url) VALUES | |
101 | ('$feed_title', '$feed_url', '$owner_uid', '$site_url')"; | |
102 | ||
103 | } | |
104 | ||
105 | db_query($link, $add_query); | |
106 | ||
107 | print "<td><b>Done.</b></td>"; | |
108 | } | |
109 | ||
110 | print "</tr>"; | |
111 | ||
112 | db_query($link, "COMMIT"); | |
113 | } | |
114 | ||
115 | print "</table>"; | |
116 | ||
117 | } else { | |
118 | print "<div class=\"error\">Error while parsing document.</div>"; | |
119 | } | |
120 | ||
121 | } else { | |
122 | print "<div class=\"error\">Error: please upload OPML file.</div>"; | |
123 | } | |
124 | ||
125 | ||
126 | } | |
127 | ?> |