| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 56 |
printf(__("Adding category <b>%s</b>."), $cat_title); |
|---|
| 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 |
|
|---|
| 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 |
$parent_node && $parent_node->node_name() == "outline") { |
|---|
| 78 |
$element_category = $parent_node->get_attribute('title'); |
|---|
| 79 |
$element_category) $element_category = $parent_node->get_attribute('text'); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$element_category = ''; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$element_category) { |
|---|
| 86 |
|
|---|
| 87 |
$element_category = db_escape_string($element_category); |
|---|
| 88 |
|
|---|
| 89 |
$result = db_query($link, "SELECT id FROM |
|---|
| 90 |
|
|---|
| 91 |
); |
|---|
| 92 |
|
|---|
| 93 |
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 |
|---|
| 99 |
|
|---|
| 100 |
); |
|---|
| 101 |
|
|---|
| 102 |
"<tr><td><a target='_blank' href='$site_url'><b>$feed_title</b></a></b> |
|---|
| 103 |
; |
|---|
| 104 |
|
|---|
| 105 |
db_num_rows($result) > 0) { |
|---|
| 106 |
"<td>".__("Already imported.")."</td>"; |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
$cat_id) { |
|---|
| 110 |
$add_query = "INSERT INTO ttrss_feeds |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
; |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
$add_query = "INSERT INTO ttrss_feeds |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
; |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
db_query($link, $add_query); |
|---|
| 124 |
|
|---|
| 125 |
"<td><b>".__('Done.')."</b></td>"; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
"</tr>"; |
|---|
| 129 |
|
|---|
| 130 |
db_query($link, "COMMIT"); |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
"</table>"; |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
"<div class=\"error\">".__("Error: can't find body element.")."</div>"; |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
"<div class=\"error\">".__("Error while parsing document.")."</div>"; |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
"<div class=\"error\">".__("Error: please upload OPML file.")."</div>"; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
?> |
|---|
| 148 |
|
|---|