]>
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 | ||
27 | print "<table>"; | |
28 | ||
29 | foreach ($outlines as $outline) { | |
30 | ||
31 | $feed_title = db_escape_string($outline->get_attribute('text')); | |
32 | ||
33 | if (!$feed_title) { | |
34 | $feed_title = db_escape_string($outline->get_attribute('title')); | |
35 | } | |
36 | ||
37 | $cat_title = db_escape_string($outline->get_attribute('title')); | |
38 | ||
39 | if (!$cat_title) { | |
40 | $cat_title = db_escape_string($outline->get_attribute('text')); | |
41 | } | |
42 | ||
43 | $feed_url = db_escape_string($outline->get_attribute('xmlUrl')); | |
44 | $site_url = db_escape_string($outline->get_attribute('htmlUrl')); | |
45 | ||
46 | if ($cat_title && !$feed_url) { | |
47 | ||
48 | db_query($link, "BEGIN"); | |
49 | ||
50 | $result = db_query($link, "SELECT id FROM | |
51 | ttrss_feed_categories WHERE title = '$cat_title' AND | |
52 | owner_uid = '$owner_uid' LIMIT 1"); | |
53 | ||
54 | if (db_num_rows($result) == 0) { | |
55 | ||
1025ad87 | 56 | printf(__("Adding category <b>%s</b>."), $cat_title); |
30f782a2 AD |
57 | print "<br>"; |
58 | ||
59 | db_query($link, "INSERT INTO ttrss_feed_categories | |
60 | (title,owner_uid) | |
61 | VALUES ('$cat_title', '$owner_uid')"); | |
62 | } | |
63 | ||
64 | db_query($link, "COMMIT"); | |
65 | } | |
66 | ||
67 | // print "$active_category : $feed_title : $feed_url<br>"; | |
68 | ||
69 | if (!$feed_title || !$feed_url) continue; | |
70 | ||
71 | db_query($link, "BEGIN"); | |
72 | ||
73 | $cat_id = null; | |
74 | ||
75 | $parent_node = $outline->parent_node(); | |
76 | ||
77 | if ($parent_node && $parent_node->node_name() == "outline") { | |
78 | $element_category = $parent_node->get_attribute('title'); | |
eb8b5c26 AD |
79 | if (!$element_category) $element_category = $parent_node->get_attribute('text'); |
80 | ||
30f782a2 AD |
81 | } else { |
82 | $element_category = ''; | |
83 | } | |
84 | ||
85 | if ($element_category) { | |
86 | ||
eb8b5c26 AD |
87 | $element_category = db_escape_string($element_category); |
88 | ||
30f782a2 AD |
89 | $result = db_query($link, "SELECT id FROM |
90 | ttrss_feed_categories WHERE title = '$element_category' AND | |
91 | owner_uid = '$owner_uid' LIMIT 1"); | |
92 | ||
93 | if (db_num_rows($result) == 1) { | |
94 | $cat_id = db_fetch_result($result, 0, "id"); | |
95 | } | |
96 | } | |
97 | ||
98 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
f0053c6a | 99 | feed_url = '$feed_url |
30f782a2 AD |
100 | AND owner_uid = '$owner_uid'"); |
101 | ||
ef59e6e8 AD |
102 | print "<tr><td><a target='_new' href='$site_url'><b>$feed_title</b></a></b> |
103 | (<a target='_new' href=\"$feed_url\">rss</a>)</td>"; | |
30f782a2 AD |
104 | |
105 | if (db_num_rows($result) > 0) { | |
1025ad87 | 106 | print "<td>".__("Already imported.")."</td>"; |
30f782a2 AD |
107 | } else { |
108 | ||
109 | if ($cat_id) { | |
110 | $add_query = "INSERT INTO ttrss_feeds | |
111 | (title, feed_url, owner_uid, cat_id, site_url) VALUES | |
112 | ('$feed_title', '$feed_url', '$owner_uid', | |
113 | '$cat_id', '$site_url')"; | |
114 | ||
115 | } else { | |
116 | $add_query = "INSERT INTO ttrss_feeds | |
c03cf250 AD |
117 | (title, feed_url, owner_uid, cat_id, site_url) VALUES |
118 | ('$feed_title', '$feed_url', '$owner_uid', '$default_cat_id', | |
119 | '$site_url')"; | |
30f782a2 AD |
120 | |
121 | } | |
122 | ||
123 | db_query($link, $add_query); | |
124 | ||
1025ad87 | 125 | print "<td><b>".__('Done.')."</b></td>"; |
30f782a2 AD |
126 | } |
127 | ||
128 | print "</tr>"; | |
129 | ||
130 | db_query($link, "COMMIT"); | |
131 | } | |
132 | ||
133 | print "</table>"; | |
134 | ||
135 | } else { | |
1025ad87 | 136 | print "<div class=\"error\">".__("Error: can't find body element.")."</div>"; |
30f782a2 AD |
137 | } |
138 | } else { | |
1025ad87 | 139 | print "<div class=\"error\">".__("Error while parsing document.")."</div>"; |
30f782a2 AD |
140 | } |
141 | ||
142 | } else { | |
1025ad87 | 143 | print "<div class=\"error\">".__("Error: please upload OPML file.")."</div>"; |
30f782a2 AD |
144 | } |
145 | ||
146 | } | |
147 | ?> |