]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement filter import
authorAndrew Dolgov <fox@fakecake.org>
Tue, 27 Dec 2011 14:37:07 +0000 (18:37 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Tue, 27 Dec 2011 14:37:07 +0000 (18:37 +0400)
classes/dlg.php
js/prefs.js
opml.php

index 9565dff8721dc88f9d2ddf6ca9671a005e2f26e3..bd18f54dce207adbf2338b20b38be0ebf73e9750 100644 (file)
@@ -19,6 +19,8 @@ class Dlg extends Protected_Handler {
        function importOpml() {
                header("Content-Type: text/html"); # required for iframe
 
+               print __("If you have imported labels and/or filters, you might need to reload preferences to see your new data.") . "</p>";
+
                print "<div class=\"prefFeedOPMLHolder\">";
                $owner_uid = $_SESSION["uid"];
 
@@ -41,7 +43,6 @@ class Dlg extends Protected_Handler {
                /* Handle OPML import by DOMXML/DOMDocument */
 
                print "<ul class='nomarks'>";
-               print "<li>".__("Importing using DOMDocument.")."</li>";
                require_once "opml.php";
                opml_import_domdoc($this->link, $owner_uid);
                print "</ul>";
@@ -49,7 +50,7 @@ class Dlg extends Protected_Handler {
 
                print "<div align='center'>";
                print "<button dojoType=\"dijit.form.Button\"
-                       onclick=\"dijit.byId('opmlImportDlg').hide()\">".
+                       onclick=\"dijit.byId('opmlImportDlg').execute()\">".
                        __('Close this window')."</button>";
                print "</div>";
 
index bd3866991950c63eb25aef75f447044a1d659772..27598285ced611c2830e28a5a18b26578f399401 100644 (file)
@@ -767,6 +767,14 @@ function opmlImportComplete(iframe) {
                        style: "width: 600px",
                        onCancel: function() {
                                updateFeedList();
+                               updateFilterList();
+                               updateLabelList();
+                       },
+                       execute: function() {
+                               updateFeedList();
+                               updateFilterList();
+                               updateLabelList();
+                               this.hide();
                        },
                        content: content});
 
index 2190b5652618d3ebc5f0b066aff15b24f9323596..9f4fd97ad1e6bc22f182485f2f396624b04b48af 100644 (file)
--- a/opml.php
+++ b/opml.php
                                                                $bg_color = db_escape_string($attributes->getNamedItem('label-bg-color')->nodeValue);
 
                                                                if (!label_find_id($link, $label_name, $_SESSION['uid'])) {
-                                                                       printf("<li>".__("Adding label %s")."</li>", $label_name);
+                                                                       printf("<li>".__("Adding label %s")."</li>", htmlspecialchars($label_name));
                                                                        label_create($link, $label_name, $fg_color, $bg_color);
                                                                } else {
-                                                                       printf("<li>".__("Duplicate label: %s")."</li>", $label_name);
+                                                                       printf("<li>".__("Duplicate label: %s")."</li>",
+                                                                               htmlspecialchars($label_name));
                                                                }
                                                        }
                                                }
                                                                $filter = json_decode($outline->nodeValue, true);
 
                                                                if ($filter) {
-                                                                       /////
-
-
+                                                                       $reg_exp = db_escape_string($filter['reg_exp']);
+                                                                       $filter_type = (int)$filter['filter_type'];
+                                                                       $action_id = (int)$filter['action_id'];
+
+                                                                       $result = db_query($link, "SELECT id FROM ttrss_filters WHERE
+                                                                               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) {
+                                                                               $enabled = bool_to_sql_bool($filter['enabled']);
+                                                                               $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']);
+                                                                               $cat_title = db_escape_string($filter['cat_title']);
+
+                                                                               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+                                                                                       feed_url = '$feed_url' AND owner_uid = ".$_SESSION['uid']);
+
+                                                                               if (db_num_rows($result) != 0) {
+                                                                                       $feed_id = db_fetch_result($result, 0, "id");
+                                                                               } else {
+                                                                                       $feed_id = "NULL";
+                                                                               }
+
+                                                                               $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
+                                                                                       title = '$cat_title' AND  owner_uid = ".$_SESSION['uid']);
+
+                                                                               if (db_num_rows($result) != 0) {
+                                                                                       $cat_id = db_fetch_result($result, 0, "id");
+                                                                               } else {
+                                                                                       $cat_id = "NULL";
+                                                                               }
+
+                                                                               printf("<li>".__("Adding filter %s")."</li>", htmlspecialchars($reg_exp));
+
+                                                                               $query = "INSERT INTO ttrss_filters (filter_type, action_id,
+                                                                                               enabled, inverse, action_param, filter_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($link, $query);
+
+                                                                       } else {
+                                                                               printf("<li>".__("Duplicate filter %s")."</li>", htmlspecialchars($reg_exp));
+
+                                                                       }
                                                                }
                                                        }
                                                }