Exemplo n.º 1
0
 function addLabel()
 {
     $caption = db_escape_string($_REQUEST["caption"]);
     if ($caption != "") {
         label_create($caption);
         $id = label_find_id($caption, $_SESSION["uid"]);
         return array(API::STATUS_OK, label_to_feed_id($id));
     } else {
         return array(API::STATUS_ERR, array("error" => 'INCORRECT_USAGE'));
     }
 }
 function hook_article_filter($article)
 {
     $wpm = 180;
     // arbitrary value, based on adult averages
     $word_count = str_word_count($article["content"]);
     $minutes = round($word_count / $wpm);
     $minimum_time_bucket = 5;
     // minutes
     $time_label = $this->minutes_to_time_label($minutes, $minimum_time_bucket);
     _debug("estimated reading time: {$minutes} min ({$time_label}), based on {$word_count} words at {$wpm} WPM");
     $owner_uid = $article["owner_uid"];
     if (!label_find_id($time_label, $owner_uid)) {
         label_create($time_label);
     }
     $guid = $article["guid"];
     $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '{$guid}'");
     if (db_num_rows($result) != 0) {
         $ref_id = db_fetch_result($result, 0, "id");
         label_add_article($ref_id, $time_label, $owner_uid);
     }
     return $article;
 }
Exemplo n.º 3
0
 private function opml_import_label($doc, $node, $owner_uid)
 {
     $attrs = $node->attributes;
     $label_name = db_escape_string($attrs->getNamedItem('label-name')->nodeValue);
     if ($label_name) {
         $fg_color = db_escape_string($attrs->getNamedItem('label-fg-color')->nodeValue);
         $bg_color = db_escape_string($attrs->getNamedItem('label-bg-color')->nodeValue);
         if (!label_find_id($this->link, $label_name, $_SESSION['uid'])) {
             $this->opml_notice(T_sprintf("Adding label %s", htmlspecialchars($label_name)));
             label_create($this->link, $label_name, $fg_color, $bg_color, $owner_uid);
         } else {
             $this->opml_notice(T_sprintf("Duplicate label: %s", htmlspecialchars($label_name)));
         }
     }
 }
 function add()
 {
     $caption = db_escape_string($_REQUEST["caption"]);
     $output = db_escape_string($_REQUEST["output"]);
     if ($caption) {
         if (label_create($this->link, $caption)) {
             if (!$output) {
                 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
             }
         }
         if ($output == "select") {
             header("Content-Type: text/xml");
             print "<rpc-reply><payload>";
             print_label_select($this->link, "select_label", $caption, "");
             print "</payload></rpc-reply>";
         }
     }
     return;
 }
Exemplo n.º 5
0
function module_pref_labels($link)
{
    $subop = $_REQUEST["subop"];
    if ($subop == "edit") {
        $label_id = db_escape_string($_REQUEST['id']);
        $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE\n\t\t\t\tid = '{$label_id}' AND owner_uid = " . $_SESSION["uid"]);
        $line = db_fetch_assoc($result);
        #			print "<form id=\"label_edit_form\" name=\"label_edit_form\"
        #				onsubmit=\"return false;\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$label_id}\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">";
        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save\">";
        print "<div class=\"dlgSec\">" . __("Caption") . "</div>";
        print "<div class=\"dlgSecCont\">";
        $fg_color = $line['fg_color'];
        $bg_color = $line['bg_color'];
        print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : {$fg_color}; background-color : {$bg_color}; margin-bottom : 4px; margin-right : 4px'>&alpha;</span>";
        print "<input style=\"font-size : 16px\" name=\"caption\" \n\t\t\t\tdojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\trequired=\"true\"\n\t\t\t\tvalue=\"" . htmlspecialchars($line['caption']) . "\">";
        print "</div>";
        print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
        print "<div class=\"dlgSecCont\">";
        print "<table cellspacing=\"0\">";
        print "<tr><td>" . __("Foreground:") . "</td><td>" . __("Background:") . "</td></tr>";
        print "<tr><td style='padding-right : 10px'>";
        print "<input dojoType=\"dijit.form.TextBox\" \n\t\t\t\tstyle=\"display : none\" id=\"labelEdit_fgColor\"\n\t\t\t\tname=\"fg_color\" value=\"{$fg_color}\">";
        print "<input dojoType=\"dijit.form.TextBox\" \n\t\t\t\tstyle=\"display : none\" id=\"labelEdit_bgColor\"\n\t\t\t\tname=\"bg_color\" value=\"{$bg_color}\">";
        print "<div dojoType=\"dijit.ColorPalette\">\n\t\t\t\t<script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">\n\t\t\t\t\tdijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);\n\t\t\t\t\t\$('label-editor-indicator').setStyle({color: fg_color});\n\t\t\t\t</script>\n\t\t\t</div>";
        print "</div>";
        print "</td><td>";
        print "<div dojoType=\"dijit.ColorPalette\">\n\t\t\t\t<script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">\n\t\t\t\t\tdijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);\n\t\t\t\t\t\$('label-editor-indicator').setStyle({backgroundColor: bg_color});\n\t\t\t\t</script>\n\t\t\t</div>";
        print "</div>";
        print "</td></tr></table>";
        print "</div>";
        #			print "</form>";
        print "<div class=\"dlgButtons\">";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">" . __('Save') . "</button>";
        print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">" . __('Cancel') . "</button>";
        print "</div>";
        return;
    }
    if ($subop == "getlabeltree") {
        $root = array();
        $root['id'] = 'root';
        $root['name'] = __('Labels');
        $root['items'] = array();
        $result = db_query($link, "SELECT *\n\t\t\t\tFROM ttrss_labels2\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY caption");
        while ($line = db_fetch_assoc($result)) {
            $label = array();
            $label['id'] = 'LABEL:' . $line['id'];
            $label['bare_id'] = $line['id'];
            $label['name'] = $line['caption'];
            $label['fg_color'] = $line['fg_color'];
            $label['bg_color'] = $line['bg_color'];
            $label['type'] = 'label';
            $label['checkbox'] = false;
            array_push($root['items'], $label);
        }
        $fl = array();
        $fl['identifier'] = 'id';
        $fl['label'] = 'name';
        $fl['items'] = array($root);
        print json_encode($fl);
        return;
    }
    if ($subop == "color-set") {
        $kind = db_escape_string($_REQUEST["kind"]);
        $ids = split(',', db_escape_string($_REQUEST["ids"]));
        $color = db_escape_string($_REQUEST["color"]);
        $fg = db_escape_string($_REQUEST["fg"]);
        $bg = db_escape_string($_REQUEST["bg"]);
        foreach ($ids as $id) {
            if ($kind == "fg" || $kind == "bg") {
                db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t{$kind}_color = '{$color}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
            } else {
                db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\tfg_color = '{$fg}', bg_color = '{$bg}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
            }
            $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
            /* Remove cached data */
            db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''\n\t\t\t\t\tWHERE label_cache LIKE '%{$caption}%' AND owner_uid = " . $_SESSION["uid"]);
        }
        return;
    }
    if ($subop == "color-reset") {
        $ids = split(',', db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\tfg_color = '', bg_color = '' WHERE id = '{$id}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
            $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
            /* Remove cached data */
            db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''\n\t\t\t\t\tWHERE label_cache LIKE '%{$caption}%' AND owner_uid = " . $_SESSION["uid"]);
        }
    }
    if ($subop == "save") {
        $id = db_escape_string($_REQUEST["id"]);
        $caption = db_escape_string(trim($_REQUEST["caption"]));
        db_query($link, "BEGIN");
        $result = db_query($link, "SELECT caption FROM ttrss_labels2\n\t\t\t\tWHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) != 0) {
            $old_caption = db_fetch_result($result, 0, "caption");
            $result = db_query($link, "SELECT id FROM ttrss_labels2\n\t\t\t\t\tWHERE caption = '{$caption}' AND owner_uid = " . $_SESSION["uid"]);
            if (db_num_rows($result) == 0) {
                if ($caption) {
                    $result = db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t\tcaption = '{$caption}' WHERE id = '{$id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                    /* Update filters that reference label being renamed */
                    $old_caption = db_escape_string($old_caption);
                    db_query($link, "UPDATE ttrss_filters SET\n\t\t\t\t\t\t\taction_param = '{$caption}' WHERE action_param = '{$old_caption}'\n\t\t\t\t\t\t\tAND action_id = 7\n\t\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                    print $_REQUEST["value"];
                } else {
                    print $old_caption;
                }
            } else {
                print $old_caption;
            }
        }
        db_query($link, "COMMIT");
        return;
    }
    if ($subop == "remove") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            label_remove($link, $id, $_SESSION["uid"]);
        }
    }
    if ($subop == "add") {
        $caption = db_escape_string($_REQUEST["caption"]);
        $output = db_escape_string($_REQUEST["output"]);
        if ($caption) {
            if (label_create($link, $caption)) {
                if (!$output) {
                    print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
                }
            }
            if ($output == "select") {
                header("Content-Type: text/xml");
                print "<rpc-reply><payload>";
                print_label_select($link, "select_label", $caption, "");
                print "</payload></rpc-reply>";
            }
        }
        return;
    }
    $sort = db_escape_string($_REQUEST["sort"]);
    if (!$sort || $sort == "undefined") {
        $sort = "caption";
    }
    $label_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_label_search"] = $label_search;
    } else {
        $label_search = $_SESSION["prefs_label_search"];
    }
    print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
    print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
    print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
    print "<div dojoType=\"dijit.form.DropDownButton\">" . "<span>" . __('Select') . "</span>";
    print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
    print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" \n\t\t\tdojoType=\"dijit.MenuItem\">" . __('All') . "</div>";
    print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" \n\t\t\tdojoType=\"dijit.MenuItem\">" . __('None') . "</div>";
    print "</div></div>";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">" . __('Create label') . "</button dojoType=\"dijit.form.Button\"> ";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">" . __('Remove') . "</button dojoType=\"dijit.form.Button\"> ";
    print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">" . __('Clear colors') . "</button dojoType=\"dijit.form.Button\">";
    print "</div>";
    #toolbar
    print "</div>";
    #pane
    print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
    print "<div id=\"labellistLoading\">\n\t\t<img src='images/indicator_tiny.gif'>" . __("Loading, please wait...") . "</div>";
    print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" \n\t\t\turl=\"backend.php?op=pref-labels&subop=getlabeltree\">\n\t\t</div>\n\t\t<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"\n\t\tquery=\"{id:'root'}\" rootId=\"root\"\n\t\t\tchildrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">\n\t\t</div>\n\t\t<div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\" \n\t\t\tmodel=\"labelModel\" openOnClick=\"true\">\n\t\t<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">\n\t\t\tElement.hide(\"labellistLoading\");\n\t\t</script>\n\t\t<script type=\"dojo/method\" event=\"onClick\" args=\"item\">\n\t\t\tvar id = String(item.id);\n\t\t\tvar bare_id = id.substr(id.indexOf(':')+1);\n\n\t\t\tif (id.match('LABEL:')) {\n\t\t\t\teditLabel(bare_id);\n\t\t\t}\t\t\t\n\t\t</script>\n\t\t</div>";
    print "</div>";
    #pane
    print "</div>";
    #container
}
Exemplo n.º 6
0
 function perform_data_import($filename, $owner_uid)
 {
     $num_imported = 0;
     $num_processed = 0;
     $num_feeds_created = 0;
     libxml_disable_entity_loader(false);
     $doc = @DOMDocument::load($filename);
     if (!$doc) {
         $contents = file_get_contents($filename);
         if ($contents) {
             $data = @gzuncompress($contents);
         }
         if (!$data) {
             $data = @gzdecode($contents);
         }
         if ($data) {
             $doc = DOMDocument::loadXML($data);
         }
     }
     libxml_disable_entity_loader(true);
     if ($doc) {
         $xpath = new DOMXpath($doc);
         $container = $doc->firstChild;
         if ($container && $container->hasAttribute('schema-version')) {
             $schema_version = $container->getAttribute('schema-version');
             if ($schema_version != SCHEMA_VERSION) {
                 print "<p>" . __("Could not import: incorrect schema version.") . "</p>";
                 return;
             }
         } else {
             print "<p>" . __("Could not import: unrecognized document format.") . "</p>";
             return;
         }
         $articles = $xpath->query("//article");
         foreach ($articles as $article_node) {
             if ($article_node->childNodes) {
                 $ref_id = 0;
                 $article = array();
                 foreach ($article_node->childNodes as $child) {
                     if ($child->nodeName != 'label_cache') {
                         $article[$child->nodeName] = db_escape_string($child->nodeValue);
                     } else {
                         $article[$child->nodeName] = $child->nodeValue;
                     }
                 }
                 //print_r($article);
                 if ($article['guid']) {
                     ++$num_processed;
                     //db_query("BEGIN");
                     //print 'GUID:' . $article['guid'] . "\n";
                     $result = db_query("SELECT id FROM ttrss_entries\n\t\t\t\t\t\t\tWHERE guid = '" . $article['guid'] . "'");
                     if (db_num_rows($result) == 0) {
                         $result = db_query("INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t\t('" . $article['title'] . "',\n\t\t\t\t\t\t\t\t\t'" . $article['guid'] . "',\n\t\t\t\t\t\t\t\t\t'" . $article['link'] . "',\n\t\t\t\t\t\t\t\t\t'" . $article['updated'] . "',\n\t\t\t\t\t\t\t\t\t'" . $article['content'] . "',\n\t\t\t\t\t\t\t\t\t'" . sha1($article['content']) . "',\n\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t\t'')");
                         $result = db_query("SELECT id FROM ttrss_entries\n\t\t\t\t\t\t\t\tWHERE guid = '" . $article['guid'] . "'");
                         if (db_num_rows($result) != 0) {
                             $ref_id = db_fetch_result($result, 0, "id");
                         }
                     } else {
                         $ref_id = db_fetch_result($result, 0, "id");
                     }
                     //print "Got ref ID: $ref_id\n";
                     if ($ref_id) {
                         $feed_url = $article['feed_url'];
                         $feed_title = $article['feed_title'];
                         $feed = 'NULL';
                         if ($feed_url && $feed_title) {
                             $result = db_query("SELECT id FROM ttrss_feeds\n\t\t\t\t\t\t\t\t\tWHERE feed_url = '{$feed_url}' AND owner_uid = '{$owner_uid}'");
                             if (db_num_rows($result) != 0) {
                                 $feed = db_fetch_result($result, 0, "id");
                             } else {
                                 // try autocreating feed in Uncategorized...
                                 $result = db_query("INSERT INTO ttrss_feeds (owner_uid,\n\t\t\t\t\t\t\t\t\t\tfeed_url, title) VALUES ({$owner_uid}, '{$feed_url}', '{$feed_title}')");
                                 $result = db_query("SELECT id FROM ttrss_feeds\n\t\t\t\t\t\t\t\t\t\tWHERE feed_url = '{$feed_url}' AND owner_uid = '{$owner_uid}'");
                                 if (db_num_rows($result) != 0) {
                                     ++$num_feeds_created;
                                     $feed = db_fetch_result($result, 0, "id");
                                 }
                             }
                         }
                         if ($feed != 'NULL') {
                             $feed_qpart = "feed_id = {$feed}";
                         } else {
                             $feed_qpart = "feed_id IS NULL";
                         }
                         //print "$ref_id / $feed / " . $article['title'] . "\n";
                         $result = db_query("SELECT int_id FROM ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND {$feed_qpart}");
                         if (db_num_rows($result) == 0) {
                             $marked = bool_to_sql_bool(sql_bool_to_bool($article['marked']));
                             $published = bool_to_sql_bool(sql_bool_to_bool($article['published']));
                             $score = (int) $article['score'];
                             $tag_cache = $article['tag_cache'];
                             $label_cache = db_escape_string($article['label_cache']);
                             $note = $article['note'];
                             //print "Importing " . $article['title'] . "<br/>";
                             ++$num_imported;
                             $result = db_query("INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid, note)\n\t\t\t\t\t\t\t\t\tVALUES ({$ref_id}, {$owner_uid}, {$feed}, false,\n\t\t\t\t\t\t\t\t\t\tNULL, {$marked}, {$published}, {$score}, '{$tag_cache}',\n\t\t\t\t\t\t\t\t\t\t\t'{$label_cache}', '', '{$note}')");
                             $label_cache = json_decode($label_cache, true);
                             if (is_array($label_cache) && $label_cache["no-labels"] != 1) {
                                 foreach ($label_cache as $label) {
                                     label_create($label[1], $label[2], $label[3], $owner_uid);
                                     label_add_article($ref_id, $label[1], $owner_uid);
                                 }
                             }
                             //db_query("COMMIT");
                         }
                     }
                 }
             }
         }
         print "<p>" . __("Finished: ") . vsprintf(_ngettext("%d article processed, ", "%d articles processed, ", $num_processed), $num_processed) . vsprintf(_ngettext("%d imported, ", "%d imported, ", $num_imported), $num_imported) . vsprintf(_ngettext("%d feed created.", "%d feeds created.", $num_feeds_created), $num_feeds_created) . "</p>";
     } else {
         print "<p>" . __("Could not load XML document.") . "</p>";
     }
 }
Exemplo n.º 7
0
function module_pref_labels($link)
{
    $subop = $_REQUEST["subop"];
    if ($subop == "color-set") {
        $kind = db_escape_string($_REQUEST["kind"]);
        $ids = split(',', db_escape_string($_REQUEST["ids"]));
        $color = db_escape_string($_REQUEST["color"]);
        $fg = db_escape_string($_REQUEST["fg"]);
        $bg = db_escape_string($_REQUEST["bg"]);
        foreach ($ids as $id) {
            if ($kind == "fg" || $kind == "bg") {
                db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t{$kind}_color = '{$color}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
            } else {
                db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\tfg_color = '{$fg}', bg_color = '{$bg}' WHERE id = '{$id}'\n\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
            }
        }
        return;
    }
    if ($subop == "color-reset") {
        $ids = split(',', db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\tfg_color = '', bg_color = '' WHERE id = '{$id}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
        }
    }
    if ($subop == "save") {
        $id = db_escape_string($_REQUEST["id"]);
        $caption = db_escape_string(trim($_REQUEST["value"]));
        db_query($link, "BEGIN");
        $result = db_query($link, "SELECT caption FROM ttrss_labels2\n\t\t\t\tWHERE id = '{$id}' AND owner_uid = " . $_SESSION["uid"]);
        if (db_num_rows($result) != 0) {
            $old_caption = db_fetch_result($result, 0, "caption");
            $result = db_query($link, "SELECT id FROM ttrss_labels2\n\t\t\t\t\tWHERE caption = '{$caption}' AND owner_uid = " . $_SESSION["uid"]);
            if (db_num_rows($result) == 0) {
                if ($caption) {
                    $result = db_query($link, "UPDATE ttrss_labels2 SET\n\t\t\t\t\t\t\tcaption = '{$caption}' WHERE id = '{$id}' AND\n\t\t\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
                    /* Update filters that reference label being renamed */
                    $old_caption = db_escape_string($old_caption);
                    db_query($link, "UPDATE ttrss_filters SET\n\t\t\t\t\t\t\taction_param = '{$caption}' WHERE action_param = '{$old_caption}'\n\t\t\t\t\t\t\tAND action_id = 7\n\t\t\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]);
                    print $_REQUEST["value"];
                } else {
                    print $old_caption;
                }
            } else {
                print $old_caption;
            }
        }
        db_query($link, "COMMIT");
        return;
    }
    if ($subop == "remove") {
        $ids = split(",", db_escape_string($_REQUEST["ids"]));
        foreach ($ids as $id) {
            label_remove($link, $id, $_SESSION["uid"]);
        }
    }
    if ($subop == "add") {
        $caption = db_escape_string($_REQUEST["caption"]);
        if ($caption) {
            if (label_create($link, $caption)) {
                print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
            }
        }
        return;
    }
    set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
    $sort = db_escape_string($_REQUEST["sort"]);
    if (!$sort || $sort == "undefined") {
        $sort = "caption";
    }
    $label_search = db_escape_string($_REQUEST["search"]);
    if (array_key_exists("search", $_REQUEST)) {
        $_SESSION["prefs_label_search"] = $label_search;
    } else {
        $label_search = $_SESSION["prefs_label_search"];
    }
    print "<div style='float : right'>\n\t\t\t<input id=\"label_search\" size=\"20\" type=\"search\"\n\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\tonchange=\"javascript:updateLabelList()\" value=\"{$label_search}\">\n\t\t\t<button onclick=\"javascript:updateLabelList()\">" . __('Search') . "</button>\n\t\t\t</div>";
    print "<div class=\"prefGenericAddBox\">";
    print "<button onclick=\"return addLabel()\">" . __('Create label') . "</button> ";
    print "<button onclick=\"javascript:removeSelectedLabels()\">" . __('Remove') . "</button> ";
    print "<button onclick=\"labelColorReset()\">" . __('Clear colors') . "</button>";
    print "</div>";
    if ($label_search) {
        $label_search = split(" ", $label_search);
        $tokens = array();
        foreach ($label_search as $token) {
            $token = trim($token);
            array_push($tokens, "(UPPER(caption) LIKE UPPER('%{$token}%'))");
        }
        $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
    } else {
        $label_search_query = "";
    }
    $result = db_query($link, "SELECT \n\t\t\t\t*\n\t\t\tFROM \n\t\t\t\tttrss_labels2\n\t\t\tWHERE \n\t\t\t\t{$label_search_query}\n\t\t\t\towner_uid = " . $_SESSION["uid"] . "\n\t\t\tORDER BY {$sort}");
    //		print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
    if (db_num_rows($result) != 0) {
        print "<p><table width=\"100%\" cellspacing=\"0\" \n\t\t\t\tclass=\"prefLabelList\" id=\"prefLabelList\">";
        print "<tr><td class=\"selectPrompt\" colspan=\"8\">\n\t\t\t\t" . __('Select:') . " \n\t\t\t\t\t<a href=\"javascript:selectPrefRows('label', true)\">" . __('All') . "</a>,\n\t\t\t\t\t<a href=\"javascript:selectPrefRows('label', false)\">" . __('None') . "</a>\n\t\t\t\t</td</tr>";
        /*			print "<tr class=\"title\">
        					<td width=\"5%\">&nbsp;</td>
        					<td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
        					</td>
        					</tr>"; */
        $lnum = 0;
        while ($line = db_fetch_assoc($result)) {
            $class = $lnum % 2 ? "even" : "odd";
            $label_id = $line["id"];
            $this_row_id = "id=\"LILRR-{$label_id}\"";
            print "<tr class=\"{$class}\" {$this_row_id}>";
            $line["caption"] = htmlspecialchars($line["caption"]);
            $fg_color = $line["fg_color"];
            $bg_color = $line["bg_color"];
            if (!$fg_color) {
                $fg_color = "";
            }
            if (!$bg_color) {
                $bg_color = "";
            }
            print "<td width='5%' align='center'><input \n\t\t\t\t\tonclick='toggleSelectPrefRow(this, \"label\");' \n\t\t\t\t\ttype=\"checkbox\" id=\"LICHK-" . $line["id"] . "\"></td>";
            $id = $line['id'];
            print "<td>";
            print "<div class='labelColorIndicator' id='LICID-{$id}' \n\t\t\t\t\tstyle='color : {$fg_color}; background-color : {$bg_color}'\n\t\t\t\t\ttitle='" . __('Click to change color') . "'\n\t\t\t\t\tonclick=\"colorPicker('{$id}', '{$fg_color}', '{$bg_color}')\">&alpha;";
            print_color_picker($id);
            print "</div>";
            print "<span class='prefsLabelEntry' \n\t\t\t\t\tid=\"LILT-" . $line["id"] . "\">" . $line["caption"] . "</span>";
            print "</td>";
            print "</tr>";
            ++$lnum;
        }
        print "</table>";
    } else {
        print "<p>";
        if (!$label_search) {
            print_warning(__('No labels defined.'));
        } else {
            print_warning(__('No matching labels found.'));
        }
        print "</p>";
    }
}
Exemplo n.º 8
0
function opml_import_domdoc($link, $owner_uid)
{
    if (is_file($_FILES['opml_file']['tmp_name'])) {
        $doc = DOMDocument::load($_FILES['opml_file']['tmp_name']);
        $result = db_query($link, "SELECT id FROM\n\t\t\t\tttrss_feed_categories WHERE title = 'Imported feeds' AND\n\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
        if (db_num_rows($result) == 1) {
            $default_cat_id = db_fetch_result($result, 0, "id");
        } else {
            $default_cat_id = 0;
        }
        // Keep imported categories in order, after any pre-existing ones.
        $new_cat_order_id = 0;
        // Get the highest category order_id in use.
        $result = db_query($link, "SELECT order_id FROM\n\t\t\t\tttrss_feed_categories WHERE owner_uid = '{$owner_uid}'\n\t\t\t\tORDER BY order_id DESC LIMIT 1");
        if (db_num_rows($result) == 1) {
            $new_cat_order_id = db_fetch_result($result, 0, "order_id");
        }
        if ($doc) {
            $body = $doc->getElementsByTagName('body');
            $xpath = new DOMXpath($doc);
            $query = "/opml/body//outline";
            $outlines = $xpath->query($query);
            foreach ($outlines as $outline) {
                $attributes = $outline->attributes;
                $feed_title = db_escape_string($attributes->getNamedItem('text')->nodeValue);
                if (!$feed_title) {
                    $feed_title = db_escape_string($attributes->getNamedItem('title')->nodeValue);
                }
                $cat_title = db_escape_string($attributes->getNamedItem('title')->nodeValue);
                if (!$cat_title) {
                    $cat_title = db_escape_string($attributes->getNamedItem('text')->nodeValue);
                }
                $feed_url = db_escape_string($attributes->getNamedItem('xmlUrl')->nodeValue);
                if (!$feed_url) {
                    $feed_url = db_escape_string($attributes->getNamedItem('xmlURL')->nodeValue);
                }
                $site_url = db_escape_string($attributes->getNamedItem('htmlUrl')->nodeValue);
                $pref_name = db_escape_string($attributes->getNamedItem('pref-name')->nodeValue);
                $label_name = db_escape_string($attributes->getNamedItem('label-name')->nodeValue);
                $filter_name = db_escape_string($attributes->getNamedItem('filter-name')->nodeValue);
                if ($cat_title && !$feed_url) {
                    if ($cat_title != "tt-rss-prefs" && $cat_title != 'tt-rss-labels' && $cat_title != 'tt-rss-filters') {
                        db_query($link, "BEGIN");
                        $result = db_query($link, "SELECT id FROM\n\t\t\t\t\t\t\t\t\tttrss_feed_categories WHERE title = '{$cat_title}' AND\n\t\t\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                        if (db_num_rows($result) == 0) {
                            $cat_order_id = ++$new_cat_order_id;
                            printf(__("<li>Adding category <b>%s</b>.</li>"), $cat_title);
                            db_query($link, "INSERT INTO ttrss_feed_categories\n\t\t\t\t\t\t\t\t\t\t(title,owner_uid,order_id)\n\t\t\t\t\t\t\t\t\t\tVALUES ('{$cat_title}', '{$owner_uid}', '{$cat_order_id}')");
                        }
                        db_query($link, "COMMIT");
                    }
                }
                //						print "$active_category : $feed_title : $feed_url<br>";
                if ($pref_name) {
                    $parent_node = $outline->parentNode;
                    if ($parent_node && $parent_node->nodeName == "outline") {
                        $cat_check = $parent_node->attributes->getNamedItem('title')->nodeValue;
                        if ($cat_check == "tt-rss-prefs") {
                            $pref_value = db_escape_string($outline->attributes->getNamedItem('value')->nodeValue);
                            printf("<li>" . __("Setting preference key %s to %s") . "</li>", $pref_name, $pref_value);
                            set_pref($link, $pref_name, $pref_value);
                        }
                    }
                }
                if ($label_name) {
                    $parent_node = $outline->parentNode;
                    if ($parent_node && $parent_node->nodeName == "outline") {
                        $cat_check = $parent_node->attributes->getNamedItem('title')->nodeValue;
                        if ($cat_check == "tt-rss-labels") {
                            $fg_color = db_escape_string($attributes->getNamedItem('label-fg-color')->nodeValue);
                            $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>", htmlspecialchars($label_name));
                                label_create($link, $label_name, $fg_color, $bg_color);
                            } else {
                                printf("<li>" . __("Duplicate label: %s") . "</li>", htmlspecialchars($label_name));
                            }
                        }
                    }
                }
                if ($filter_name) {
                    $parent_node = $outline->parentNode;
                    if ($parent_node && $parent_node->nodeName == "outline") {
                        $cat_check = $parent_node->attributes->getNamedItem('title')->nodeValue;
                        if ($cat_check == "tt-rss-filters") {
                            $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\n\t\t\t\t\t\t\t\t\t\treg_exp = '{$reg_exp}' AND\n\t\t\t\t\t\t\t\t\t\tfilter_type = '{$filter_type}' AND\n\t\t\t\t\t\t\t\t\t\taction_id = '{$action_id}' AND\n\t\t\t\t\t\t\t\t\t\towner_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\n\t\t\t\t\t\t\t\t\t\t\tfeed_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\n\t\t\t\t\t\t\t\t\t\t\ttitle = '{$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,\n\t\t\t\t\t\t\t\t\t\t\t\tenabled, inverse, action_param, filter_param,\n\t\t\t\t\t\t\t\t\t\t\t\tcat_filter, feed_id,\n\t\t\t\t\t\t\t\t\t\t\t\tcat_id, reg_exp,\n\t\t\t\t\t\t\t\t\t\t\t\towner_uid)\n\t\t\t\t\t\t\t\t\t\t\tVALUES ({$filter_type}, {$action_id},\n\t\t\t\t\t\t\t\t\t\t\t\t{$enabled}, {$inverse}, '{$action_param}', '{$filter_param}',\n\t\t\t\t\t\t\t\t\t\t\t\t{$cat_filter}, {$feed_id},\n\t\t\t\t\t\t\t\t\t\t\t\t{$cat_id}, '{$reg_exp}', " . $_SESSION['uid'] . ")";
                                    db_query($link, $query);
                                } else {
                                    printf("<li>" . __("Duplicate filter %s") . "</li>", htmlspecialchars($reg_exp));
                                }
                            }
                        }
                    }
                }
                if (!$feed_title || !$feed_url) {
                    continue;
                }
                db_query($link, "BEGIN");
                $cat_id = null;
                $parent_node = $outline->parentNode;
                if ($parent_node && $parent_node->nodeName == "outline") {
                    $element_category = $parent_node->attributes->getNamedItem('title')->nodeValue;
                    if (!$element_category) {
                        $element_category = $parent_node->attributes->getNamedItem('text')->nodeValue;
                    }
                } else {
                    $element_category = '';
                }
                if ($element_category) {
                    $element_category = db_escape_string($element_category);
                    $result = db_query($link, "SELECT id FROM\n\t\t\t\t\t\t\t\tttrss_feed_categories WHERE title = '{$element_category}' AND\n\t\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $cat_id = db_fetch_result($result, 0, "id");
                    }
                }
                $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE\n\t\t\t\t\t\t\tfeed_url = '{$feed_url}'\n\t\t\t\t\t\t\tAND owner_uid = '{$owner_uid}'");
                print "<li><a target='_blank' href='{$site_url}'><b>{$feed_title}</b></a></b>\n\t\t\t\t\t\t(<a target='_blank' href=\"{$feed_url}\">rss</a>)&nbsp;";
                if (db_num_rows($result) > 0) {
                    print __('is already imported.');
                } else {
                    // Get max order_id already in use. Increment.
                    $new_feed_order_id = 0;
                    // these start at zero
                    $cat_id_qpart = $cat_id ? "cat_id = '{$cat_id}'" : "cat_id = '{$default_cat_id}'";
                    $result = db_query($link, "SELECT order_id FROM\n\t\t\t\t\t\t\tttrss_feeds WHERE owner_uid = '{$owner_uid}' AND {$cat_id_qpart}\n\t\t\t\t\t\t\tORDER BY order_id DESC LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $new_feed_order_id = db_fetch_result($result, 0, "order_id");
                        $new_feed_order_id++;
                    }
                    if ($cat_id) {
                        $add_query = "INSERT INTO ttrss_feeds\n\t\t\t\t\t\t\t\t(title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES\n\t\t\t\t\t\t\t\t('{$feed_title}', '{$feed_url}', '{$owner_uid}',\n\t\t\t\t\t\t\t\t '{$cat_id}', '{$site_url}', '{$new_feed_order_id}')";
                    } else {
                        $add_query = "INSERT INTO ttrss_feeds\n\t\t\t\t\t\t\t\t(title, feed_url, owner_uid, cat_id, site_url, order_id) VALUES\n\t\t\t\t\t\t\t\t('{$feed_title}', '{$feed_url}', '{$owner_uid}', '{$default_cat_id}',\n\t\t\t\t\t\t\t\t\t'{$site_url}', '{$new_feed_order_id}')";
                    }
                    //print $add_query;
                    db_query($link, $add_query);
                    print __('OK');
                }
                print "</li>";
                db_query($link, "COMMIT");
            }
        } else {
            print_error(__('Error while parsing document.'));
        }
    } else {
        print_error(__('Error: please upload OPML file.'));
    }
}