implement OPML filter import
This commit is contained in:
parent
fd994f1a48
commit
3b003f6396
100
classes/opml.php
100
classes/opml.php
|
@ -310,75 +310,71 @@ class Opml extends Handler_Protected {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private function opml_import_filter($doc, $node, $owner_uid) {
|
private function opml_import_filter($doc, $node, $owner_uid) {
|
||||||
$attrs = $node->attributes;
|
$attrs = $node->attributes;
|
||||||
|
|
||||||
$filter_name = db_escape_string($attrs->getNamedItem('filter-name')->nodeValue);
|
$filter_type = db_escape_string($attrs->getNamedItem('filter-type')->nodeValue);
|
||||||
|
|
||||||
if ($filter_name) {
|
if ($filter_type == '2') {
|
||||||
|
$filter = json_decode($node->nodeValue, true);
|
||||||
$filter = json_decode($node->nodeValue, true);
|
|
||||||
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$reg_exp = db_escape_string($filter['reg_exp']);
|
$match_any_rule = bool_to_sql_bool($filter["match_any_rule"]);
|
||||||
$filter_type = (int)$filter['filter_type'];
|
$enabled = bool_to_sql_bool($filter["enabled"]);
|
||||||
$action_id = (int)$filter['action_id'];
|
|
||||||
|
|
||||||
$result = db_query($this->link, "SELECT id FROM ttrss_filters WHERE
|
db_query($this->link, "BEGIN");
|
||||||
reg_exp = '$reg_exp' AND
|
|
||||||
filter_type = '$filter_type' AND
|
|
||||||
action_id = '$action_id' AND
|
|
||||||
owner_uid = " .$_SESSION['uid']);
|
|
||||||
|
|
||||||
if (db_num_rows($result) == 0) {
|
db_query($this->link, "INSERT INTO ttrss_filters2 (match_any_rule,enabled,owner_uid)
|
||||||
$enabled = bool_to_sql_bool($filter['enabled']);
|
VALUES ($match_any_rule, $enabled,".$_SESSION["uid"].")");
|
||||||
$action_param = db_escape_string($filter['action_param']);
|
|
||||||
$inverse = bool_to_sql_bool($filter['inverse']);
|
|
||||||
$filter_param = db_escape_string($filter['filter_param']);
|
|
||||||
$cat_filter = bool_to_sql_bool($filter['cat_filter']);
|
|
||||||
|
|
||||||
$feed_url = db_escape_string($filter['feed_url']);
|
$result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2 WHERE
|
||||||
$cat_title = db_escape_string($filter['cat_title']);
|
owner_uid = ".$_SESSION["uid"]);
|
||||||
|
$filter_id = db_fetch_result($result, 0, "id");
|
||||||
|
|
||||||
$result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
|
if ($filter_id) {
|
||||||
feed_url = '$feed_url' AND owner_uid = $owner_uid");
|
$this->opml_notice(T_sprintf("Adding filter..."));
|
||||||
|
|
||||||
if (db_num_rows($result) != 0) {
|
foreach ($filter["rules"] as $rule) {
|
||||||
$feed_id = db_fetch_result($result, 0, "id");
|
|
||||||
} else {
|
|
||||||
$feed_id = "NULL";
|
$feed_id = "NULL";
|
||||||
}
|
|
||||||
|
|
||||||
$result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
|
|
||||||
title = '$cat_title' AND owner_uid = $owner_uid");
|
|
||||||
|
|
||||||
if (db_num_rows($result) != 0) {
|
|
||||||
$cat_id = db_fetch_result($result, 0, "id");
|
|
||||||
} else {
|
|
||||||
$cat_id = "NULL";
|
$cat_id = "NULL";
|
||||||
|
|
||||||
|
if (!$rule["cat_filter"]) {
|
||||||
|
$tmp_result = db_query($this->link, "SELECT id FROM ttrss_feeds
|
||||||
|
WHERE title = '".db_escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
|
||||||
|
if (db_num_rows($tmp_result) > 0) {
|
||||||
|
$feed_id = db_fetch_result($tmp_result, 0, "id");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tmp_result = db_query($this->link, "SELECT id FROM ttrss_feed_categories
|
||||||
|
WHERE title = '".db_escape_string($rule["feed"])."' AND owner_uid = ".$_SESSION["uid"]);
|
||||||
|
|
||||||
|
if (db_num_rows($tmp_result) > 0) {
|
||||||
|
$cat_id = db_fetch_result($tmp_result, 0, "id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cat_filter = bool_to_sql_bool($rule["cat_filter"]);
|
||||||
|
$reg_exp = db_escape_string($rule["reg_exp"]);
|
||||||
|
$filter_type = (int)$rule["filter_type"];
|
||||||
|
|
||||||
|
db_query($this->link, "INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter)
|
||||||
|
VALUES ($feed_id, $cat_id, $filter_id, $filter_type, '$reg_exp', $cat_filter)");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->opml_notice(T_sprintf("Adding filter %s", htmlspecialchars($reg_exp)));
|
foreach ($filter["actions"] as $action) {
|
||||||
|
|
||||||
$query = "INSERT INTO ttrss_filters (filter_type, action_id,
|
$action_id = (int)$action["action_id"];
|
||||||
enabled, inverse, action_param, filter_param,
|
$action_param = db_escape_string($action["action_param"]);
|
||||||
cat_filter, feed_id,
|
|
||||||
cat_id, reg_exp,
|
|
||||||
owner_uid)
|
|
||||||
VALUES ($filter_type, $action_id,
|
|
||||||
$enabled, $inverse, '$action_param', '$filter_param',
|
|
||||||
$cat_filter, $feed_id,
|
|
||||||
$cat_id, '$reg_exp', ".
|
|
||||||
$_SESSION['uid'].")";
|
|
||||||
|
|
||||||
db_query($this->link, $query);
|
db_query($this->link, "INSERT INTO ttrss_filters2_actions (filter_id,action_id,action_param)
|
||||||
|
VALUES ($filter_id, $action_id, '$action_param')");
|
||||||
} else {
|
}
|
||||||
$this->opml_notice(T_sprintf("Duplicate filter %s", htmlspecialchars($reg_exp)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db_query($this->link, "COMMIT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
|
|
||||||
private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
|
private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
|
||||||
$body = $doc->getElementsByTagName('body');
|
$body = $doc->getElementsByTagName('body');
|
||||||
|
@ -436,7 +432,7 @@ class Opml extends Handler_Protected {
|
||||||
$this->opml_import_label($doc, $node, $owner_uid);
|
$this->opml_import_label($doc, $node, $owner_uid);
|
||||||
break;
|
break;
|
||||||
case "tt-rss-filters":
|
case "tt-rss-filters":
|
||||||
//$this->opml_import_filter($doc, $node, $owner_uid);
|
$this->opml_import_filter($doc, $node, $owner_uid);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid);
|
$this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid);
|
||||||
|
@ -452,7 +448,7 @@ class Opml extends Handler_Protected {
|
||||||
$debug = isset($_REQUEST["debug"]);
|
$debug = isset($_REQUEST["debug"]);
|
||||||
$doc = false;
|
$doc = false;
|
||||||
|
|
||||||
#if ($debug) $doc = DOMDocument::load("/tmp/test.opml");
|
if ($debug) $doc = DOMDocument::load("/tmp/test.opml");
|
||||||
|
|
||||||
if (is_file($_FILES['opml_file']['tmp_name'])) {
|
if (is_file($_FILES['opml_file']['tmp_name'])) {
|
||||||
$doc = DOMDocument::load($_FILES['opml_file']['tmp_name']);
|
$doc = DOMDocument::load($_FILES['opml_file']['tmp_name']);
|
||||||
|
|
Loading…
Reference in New Issue