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 label_add_article($link, $id, $label, $owner_uid) { $label_id = label_find_id($link, $label, $owner_uid); if (!$label_id) { return; } $result = db_query($link, "SELECT\n\t\t\t\tarticle_id FROM ttrss_labels2, ttrss_user_labels2\n\t\t\tWHERE\n\t\t\t\tlabel_id = id AND\n\t\t\t\tlabel_id = '{$label_id}' AND\n\t\t\t\tarticle_id = '{$id}' AND owner_uid = '{$owner_uid}'\n\t\t\tLIMIT 1"); if (db_num_rows($result) == 0) { db_query($link, "INSERT INTO ttrss_user_labels2\n\t\t\t\t(label_id, article_id) VALUES ('{$label_id}', '{$id}')"); } label_clear_cache($link, $id); }
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; }
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 label_add_article($link, $id, $label, $owner_uid) { global $memcache; if ($memcache) { $obj_id = md5("LABELS:{$id}:{$owner_uid}"); $memcache->delete($obj_id); } $label_id = label_find_id($link, $label, $owner_uid); if (!$label_id) { return; } $result = db_query($link, "SELECT \n\t\t\t\tarticle_id FROM ttrss_labels2, ttrss_user_labels2\n\t\t\tWHERE \n\t\t\t\tlabel_id = id AND \n\t\t\t\tlabel_id = '{$label_id}' AND\n\t\t\t\tarticle_id = '{$id}' AND owner_uid = '{$owner_uid}'\n\t\t\tLIMIT 1"); if (db_num_rows($result) == 0) { db_query($link, "INSERT INTO ttrss_user_labels2 \n\t\t\t\t(label_id, article_id) VALUES ('{$label_id}', '{$id}')"); } }
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>) "; 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.')); } }