]>
Commit | Line | Data |
---|---|---|
30f782a2 AD |
1 | <?php |
2 | function opml_import_domxml($link, $owner_uid) { | |
3 | ||
4 | if (is_file($_FILES['opml_file']['tmp_name'])) { | |
5 | $dom = domxml_open_file($_FILES['opml_file']['tmp_name']); | |
6 | ||
c03cf250 AD |
7 | $result = db_query($link, "SELECT id FROM |
8 | ttrss_feed_categories WHERE title = 'Imported feeds' AND | |
9 | owner_uid = '$owner_uid' LIMIT 1"); | |
10 | ||
11 | if (db_num_rows($result) == 1) { | |
12 | $default_cat_id = db_fetch_result($result, 0, "id"); | |
13 | } else { | |
14 | $default_cat_id = 0; | |
15 | } | |
16 | ||
30f782a2 AD |
17 | if ($dom) { |
18 | $root = $dom->document_element(); | |
19 | ||
20 | $body = $root->get_elements_by_tagname('body'); | |
21 | ||
22 | if ($body[0]) { | |
23 | $body = $body[0]; | |
24 | ||
25 | $outlines = $body->get_elements_by_tagname('outline'); | |
26 | ||
b6a6e262 | 27 | foreach ($outlines as $outline) { |
30f782a2 | 28 | |
b6a6e262 | 29 | $feed_title = db_escape_string($outline->get_attribute('text')); |
30f782a2 | 30 | |
b6a6e262 AD |
31 | if (!$feed_title) { |
32 | $feed_title = db_escape_string($outline->get_attribute('title')); | |
33 | } | |
30f782a2 | 34 | |
b6a6e262 | 35 | $cat_title = db_escape_string($outline->get_attribute('title')); |
30f782a2 | 36 | |
b6a6e262 AD |
37 | if (!$cat_title) { |
38 | $cat_title = db_escape_string($outline->get_attribute('text')); | |
39 | } | |
30f782a2 | 40 | |
b6a6e262 AD |
41 | $feed_url = db_escape_string($outline->get_attribute('xmlUrl')); |
42 | $site_url = db_escape_string($outline->get_attribute('htmlUrl')); | |
30f782a2 | 43 | |
b6a6e262 | 44 | if ($cat_title && !$feed_url) { |
30f782a2 | 45 | |
b6a6e262 AD |
46 | db_query($link, "BEGIN"); |
47 | ||
48 | $result = db_query($link, "SELECT id FROM | |
49 | ttrss_feed_categories WHERE title = '$cat_title' AND | |
50 | owner_uid = '$owner_uid' LIMIT 1"); | |
30f782a2 | 51 | |
b6a6e262 | 52 | if (db_num_rows($result) == 0) { |
30f782a2 | 53 | |
b6a6e262 | 54 | printf(__("<li>Adding category <b>%s</b>.</li>"), $cat_title); |
30f782a2 | 55 | |
b6a6e262 AD |
56 | db_query($link, "INSERT INTO ttrss_feed_categories |
57 | (title,owner_uid) | |
58 | VALUES ('$cat_title', '$owner_uid')"); | |
30f782a2 AD |
59 | } |
60 | ||
b6a6e262 AD |
61 | db_query($link, "COMMIT"); |
62 | } | |
30f782a2 | 63 | |
b6a6e262 | 64 | // print "$active_category : $feed_title : $feed_url<br>"; |
30f782a2 | 65 | |
b6a6e262 | 66 | if (!$feed_title || !$feed_url) continue; |
30f782a2 | 67 | |
b6a6e262 | 68 | db_query($link, "BEGIN"); |
30f782a2 | 69 | |
b6a6e262 | 70 | $cat_id = null; |
30f782a2 | 71 | |
b6a6e262 | 72 | $parent_node = $outline->parent_node(); |
eb8b5c26 | 73 | |
b6a6e262 AD |
74 | if ($parent_node && $parent_node->node_name() == "outline") { |
75 | $element_category = $parent_node->get_attribute('title'); | |
76 | if (!$element_category) $element_category = $parent_node->get_attribute('text'); | |
30f782a2 | 77 | |
b6a6e262 AD |
78 | } else { |
79 | $element_category = ''; | |
80 | } | |
30f782a2 | 81 | |
b6a6e262 | 82 | if ($element_category) { |
eb8b5c26 | 83 | |
b6a6e262 | 84 | $element_category = db_escape_string($element_category); |
30f782a2 | 85 | |
b6a6e262 AD |
86 | $result = db_query($link, "SELECT id FROM |
87 | ttrss_feed_categories WHERE title = '$element_category' AND | |
88 | owner_uid = '$owner_uid' LIMIT 1"); | |
30f782a2 | 89 | |
b6a6e262 AD |
90 | if (db_num_rows($result) == 1) { |
91 | $cat_id = db_fetch_result($result, 0, "id"); | |
92 | } | |
93 | } | |
30f782a2 | 94 | |
b6a6e262 AD |
95 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE |
96 | feed_url = '$feed_url' | |
97 | AND owner_uid = '$owner_uid'"); | |
30f782a2 | 98 | |
b6a6e262 AD |
99 | print "<li><a target='_blank' href='$site_url'><b>$feed_title</b></a></b> |
100 | (<a target='_blank' href=\"$feed_url\">rss</a>) "; | |
30f782a2 | 101 | |
b6a6e262 AD |
102 | if (db_num_rows($result) > 0) { |
103 | print __("is already imported."); | |
104 | } else { | |
30f782a2 | 105 | |
b6a6e262 AD |
106 | if ($cat_id) { |
107 | $add_query = "INSERT INTO ttrss_feeds | |
108 | (title, feed_url, owner_uid, cat_id, site_url) VALUES | |
109 | ('$feed_title', '$feed_url', '$owner_uid', | |
110 | '$cat_id', '$site_url')"; | |
30f782a2 | 111 | |
b6a6e262 AD |
112 | } else { |
113 | $add_query = "INSERT INTO ttrss_feeds | |
114 | (title, feed_url, owner_uid, cat_id, site_url) VALUES | |
115 | ('$feed_title', '$feed_url', '$owner_uid', '$default_cat_id', | |
116 | '$site_url')"; | |
30f782a2 | 117 | |
30f782a2 AD |
118 | } |
119 | ||
b6a6e262 | 120 | db_query($link, $add_query); |
30f782a2 | 121 | |
b6a6e262 | 122 | print __('OK'); |
30f782a2 AD |
123 | } |
124 | ||
b6a6e262 AD |
125 | print "</li>"; |
126 | ||
127 | db_query($link, "COMMIT"); | |
128 | } | |
30f782a2 AD |
129 | |
130 | } else { | |
b6a6e262 | 131 | print_error(__("Error: can't find body element.")); |
30f782a2 AD |
132 | } |
133 | } else { | |
b6a6e262 | 134 | print_error(__("Error while parsing document.")); |
30f782a2 AD |
135 | } |
136 | ||
137 | } else { | |
b6a6e262 | 138 | print_error(__("Error: please upload OPML file.")); |
30f782a2 AD |
139 | } |
140 | ||
141 | } | |
142 | ?> |