]> git.wh0rd.org - tt-rss.git/commitdiff
Merge branch 'master' of github.com:gothfox/Tiny-Tiny-RSS
authorAndrew Dolgov <fox@fakecake.org>
Sun, 2 Sep 2012 09:46:05 +0000 (13:46 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Sun, 2 Sep 2012 09:46:05 +0000 (13:46 +0400)
1  2 
classes/opml.php

diff --combined classes/opml.php
index e76f16bbe380b38d139474138909361068145a52,815ae883b9f6b7665a27ba0d32203a08099d2199..9abbeebaafd430d8d27ae9b3379e360034daea1a
@@@ -165,7 -165,7 +165,7 @@@ class Opml extends Handler_Protected 
                                WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY id");
  
                        while ($line = db_fetch_assoc($result)) {
-                               foreach (array('enabled', 'inverse', 'cat_filter') as $b) {
+                               foreach (array('enabled', 'match_any_rule') as $b) {
                                        $line[$b] = sql_bool_to_bool($line[$b]);
                                }
  
                                                $tmp_line["feed"] = "";
                                        }
  
+                                       $tmp_line["cat_filter"] = sql_bool_to_bool($tmp_line["cat_filter"]);
                                        unset($tmp_line["feed_id"]);
                                        unset($tmp_line["cat_id"]);
  
                }
        }
  
 -      /* private function opml_import_filter($doc, $node, $owner_uid) {
 +      private function opml_import_filter($doc, $node, $owner_uid) {
                $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) {
 -
 -              $filter = json_decode($node->nodeValue, true);
 +              if ($filter_type == '2') {
 +                      $filter = json_decode($node->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($this->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($this->link, "SELECT id FROM ttrss_feeds WHERE
 -                                              feed_url = '$feed_url' AND owner_uid = $owner_uid");
 -
 -                                      if (db_num_rows($result) != 0) {
 -                                              $feed_id = db_fetch_result($result, 0, "id");
 -                                      } else {
 -                                              $feed_id = "NULL";
 -                                      }
 +                              $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]);
 +                              $enabled = bool_to_sql_bool($filter["enabled"]);
  
 -                                      $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
 -                                              title = '$cat_title' AND  owner_uid = $owner_uid");
 +                              db_query($this->link, "BEGIN");
  
 -                                      if (db_num_rows($result) != 0) {
 -                                              $cat_id = db_fetch_result($result, 0, "id");
 -                                      } else {
 +                              db_query($this->link, "INSERT INTO ttrss_filters2 (match_any_rule,enabled,owner_uid)
 +                                      VALUES ($match_any_rule, $enabled,".$_SESSION["uid"].")");
 +
 +                              $result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2 WHERE
 +                                      owner_uid = ".$_SESSION["uid"]);
 +                              $filter_id = db_fetch_result($result, 0, "id");
 +
 +                              if ($filter_id) {
 +                                      $this->opml_notice(T_sprintf("Adding filter..."));
 +
 +                                      foreach ($filter["rules"] as $rule) {
 +                                              $feed_id = "NULL";
                                                $cat_id = "NULL";
 -                                      }
  
 -                                      $this->opml_notice(T_sprintf("Adding filter %s", htmlspecialchars($reg_exp)));
 +                                              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)");
 +                                      }
  
 -                                      $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'].")";
 +                                      foreach ($filter["actions"] as $action) {
  
 -                                      db_query($this->link, $query);
 +                                              $action_id = (int)$action["action_id"];
 +                                              $action_param = db_escape_string($action["action_param"]);
  
 -                              } else {
 -                                      $this->opml_notice(T_sprintf("Duplicate filter %s", htmlspecialchars($reg_exp)));
 +                                              db_query($this->link, "INSERT INTO ttrss_filters2_actions (filter_id,action_id,action_param)
 +                                                      VALUES ($filter_id, $action_id, '$action_param')");
 +                                      }
                                }
 +
 +                              db_query($this->link, "COMMIT");
                        }
                }
 -      } */
 +      }
  
        private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
                $body = $doc->getElementsByTagName('body');
                                                $this->opml_import_label($doc, $node, $owner_uid);
                                                break;
                                        case "tt-rss-filters":
 -                                              //$this->opml_import_filter($doc, $node, $owner_uid);
 +                                              $this->opml_import_filter($doc, $node, $owner_uid);
                                                break;
                                        default:
                                                $this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid);
                $debug = isset($_REQUEST["debug"]);
                $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'])) {
                        $doc = DOMDocument::load($_FILES['opml_file']['tmp_name']);