private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { $body = $doc->getElementsByTagName('body'); $default_cat_id = (int) get_feed_category($this->link, 'Imported feeds', false); if ($root_node) { $cat_title = db_escape_string($root_node->attributes->getNamedItem('text')->nodeValue); if (!$cat_title) { $cat_title = db_escape_string($root_node->attributes->getNamedItem('title')->nodeValue); } if (!in_array($cat_title, array("tt-rss-filters", "tt-rss-labels", "tt-rss-prefs"))) { $cat_id = get_feed_category($this->link, $cat_title, $parent_id); db_query($this->link, "BEGIN"); if ($cat_id === false) { add_feed_category($this->link, $cat_title, $parent_id); $cat_id = get_feed_category($this->link, $cat_title, $parent_id); } db_query($this->link, "COMMIT"); } else { $cat_id = 0; } $outlines = $root_node->childNodes; } else { $xpath = new DOMXpath($doc); $outlines = $xpath->query("//opml/body/outline"); $cat_id = 0; } #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); $this->opml_notice(T_sprintf("Processing category: %s", $cat_title ? $cat_title : __("Uncategorized"))); foreach ($outlines as $node) { if ($node->hasAttributes() && strtolower($node->tagName) == "outline") { $attrs = $node->attributes; $node_cat_title = db_escape_string($attrs->getNamedItem('text')->nodeValue); if (!$node_cat_title) { $node_cat_title = db_escape_string($attrs->getNamedItem('title')->nodeValue); } $node_feed_url = db_escape_string($attrs->getNamedItem('xmlUrl')->nodeValue); if ($node_cat_title && !$node_feed_url) { $this->opml_import_category($doc, $node, $owner_uid, $cat_id); } else { if (!$cat_id) { $dst_cat_id = $default_cat_id; } else { $dst_cat_id = $cat_id; } switch ($cat_title) { case "tt-rss-prefs": $this->opml_import_preference($doc, $node, $owner_uid); break; case "tt-rss-labels": $this->opml_import_label($doc, $node, $owner_uid); break; case "tt-rss-filters": $this->opml_import_filter($doc, $node, $owner_uid); break; default: $this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid); } } } } }
function addCategory() { $caption = db_escape_string($_REQUEST["caption"]); $parent_id = (int) db_escape_string($_REQUEST["parent_id"]); if ($caption != "") { if ($parent_id != "") { add_feed_category($caption, $parent_id); } else { add_feed_category($caption); } return array(API::STATUS_OK, get_feed_category($caption)); } else { return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); } }