0) {
if ($line["comments"]) {
- $comments_url = $line["comments"];
+ $comments_url = htmlspecialchars($line["comments"]);
} else {
- $comments_url = $line["link"];
+ $comments_url = htmlspecialchars($line["link"]);
}
$entry_comments = "$num_comments comments";
} else {
if ($line["comments"] && $line["link"] != $line["comments"]) {
- $entry_comments = "comments";
+ $entry_comments = "comments";
}
}
@@ -3345,7 +3191,7 @@
";
}
- $title_escaped = db_escape_string($line['title']);
+ $title_escaped = htmlspecialchars($line['title']);
$rv['content'] .= "" .
truncate_string(strip_tags($line['title']), 15) . "
";
@@ -3370,14 +3216,14 @@
$rv['content'] .= "$parsed_updated
";
if ($line["link"]) {
- $rv['content'] .= "";
} else {
- $rv['content'] .= "" . $line["title"] . "$entry_author
";
+ $rv['content'] .= "" . $line["title"] . "$entry_author
";
}
$tag_cache = $line["tag_cache"];
@@ -3412,15 +3258,10 @@
onclick=\"postOpenInNewTab(event, $id)\"
alt='Zoom' title='".__('Open article in new tab')."'>";
- $button_plugins = explode(",", ARTICLE_BUTTON_PLUGINS);
+ global $pluginhost;
- foreach ($button_plugins as $p) {
- $pclass = trim("button_${p}");
-
- if (class_exists($pclass)) {
- $plugin = new $pclass($link);
- $rv['content'] .= $plugin->render($id, $line);
- }
+ foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
+ $rv['content'] .= $p->hook_article_button($line);
}
$rv['content'] .= "/", "", $text);
- return $text;
- }
-
function load_filters($link, $feed_id, $owner_uid, $action_id = false) {
$filters = array();
@@ -3622,6 +3464,10 @@
$result = db_query($link, "SELECT * FROM ttrss_filters2 WHERE
owner_uid = $owner_uid AND enabled = true");
+ $check_cats = join(",", array_merge(
+ getParentCategories($link, $cat_id, $owner_uid),
+ array($cat_id)));
+
while ($line = db_fetch_assoc($result)) {
$filter_id = $line["id"];
@@ -3630,7 +3476,7 @@
FROM ttrss_filters2_rules AS r,
ttrss_filter_types AS t
WHERE
- (cat_id IS NULL OR cat_id = '$cat_id') AND
+ (cat_id IS NULL OR cat_id IN ($check_cats)) AND
(feed_id IS NULL OR feed_id = '$feed_id') AND
filter_type = t.id AND filter_id = '$filter_id'");
@@ -3710,6 +3556,12 @@
db_query($link, "SET NAMES " . MYSQL_CHARSET);
}
}
+
+ global $pluginhost;
+
+ $pluginhost = new PluginHost($link);
+ $pluginhost->load(PLUGINS);
+
return true;
} else {
print "Unable to connect to database:" . db_last_error();
@@ -3950,24 +3802,26 @@
}
}
- function get_article_labels($link, $id) {
+ function get_article_labels($link, $id, $owner_uid = false) {
$rv = array();
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
$result = db_query($link, "SELECT label_cache FROM
ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
- $_SESSION["uid"]);
-
- $label_cache = db_fetch_result($result, 0, "label_cache");
+ $owner_uid);
- if ($label_cache) {
+ if (db_num_rows($result) > 0) {
+ $label_cache = db_fetch_result($result, 0, "label_cache");
- $label_cache = json_decode($label_cache, true);
+ if ($label_cache) {
+ $label_cache = json_decode($label_cache, true);
- if ($label_cache["no-labels"] == 1)
- return $rv;
- else
- return $label_cache;
+ if ($label_cache["no-labels"] == 1)
+ return $rv;
+ else
+ return $label_cache;
+ }
}
$result = db_query($link,
@@ -3975,7 +3829,7 @@
FROM ttrss_labels2, ttrss_user_labels2
WHERE id = label_id
AND article_id = '$id'
- AND owner_uid = ".$_SESSION["uid"] . "
+ AND owner_uid = ". $owner_uid . "
ORDER BY caption");
while ($line = db_fetch_assoc($result)) {
@@ -3985,9 +3839,9 @@
}
if (count($rv) > 0)
- label_update_cache($link, $id, $rv);
+ label_update_cache($link, $owner_uid, $id, $rv);
else
- label_update_cache($link, $id, array("no-labels" => 1));
+ label_update_cache($link, $owner_uid, $id, array("no-labels" => 1));
return $rv;
}
@@ -4005,7 +3859,19 @@
}
}
- function label_update_cache($link, $id, $labels = false, $force = false) {
+ function get_all_labels($link, $owner_uid) {
+ $rv = array();
+
+ $result = db_query($link, "SELECT fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = " . $owner_uid);
+
+ while ($line = db_fetch_assoc($result)) {
+ array_push($rv, $line);
+ }
+
+ return $rv;
+ }
+
+ function label_update_cache($link, $owner_uid, $id, $labels = false, $force = false) {
if ($force)
label_clear_cache($link, $id);
@@ -4016,7 +3882,7 @@
$labels = db_escape_string(json_encode($labels));
db_query($link, "UPDATE ttrss_user_entries SET
- label_cache = '$labels' WHERE ref_id = '$id'");
+ label_cache = '$labels' WHERE ref_id = '$id' AND owner_uid = '$owner_uid'");
}
@@ -4432,7 +4298,7 @@
return $rv;
}
- function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset) {
+ function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) {
$feeds = array();
@@ -4462,7 +4328,7 @@
/* Virtual feeds */
if ($cat_id == -4 || $cat_id == -1) {
- foreach (array(-1, -2, -3, -4, 0) as $i) {
+ foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
$unread = getFeedUnread($link, $i);
if ($unread || !$unread_only) {
@@ -4480,6 +4346,30 @@
}
}
+ /* Child cats */
+
+ if ($include_nested && $cat_id) {
+ $result = db_query($link, "SELECT
+ id, title FROM ttrss_feed_categories
+ WHERE parent_cat = '$cat_id' AND owner_uid = " . $_SESSION["uid"] .
+ " ORDER BY id, title");
+
+ while ($line = db_fetch_assoc($result)) {
+ $unread = getFeedUnread($link, $line["id"], true) +
+ getCategoryChildrenUnread($link, $line["id"]);
+
+ if ($unread || !$unread_only) {
+ $row = array(
+ "id" => $line["id"],
+ "title" => $line["title"],
+ "unread" => $unread,
+ "is_cat" => true,
+ );
+ array_push($feeds, $row);
+ }
+ }
+ }
+
/* Real feeds */
if ($limit) {
@@ -4538,11 +4428,12 @@
function api_get_headlines($link, $feed_id, $limit, $offset,
$filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
$include_attachments, $since_id,
- $search = "", $search_mode = "", $match_on = "") {
+ $search = "", $search_mode = "", $match_on = "",
+ $include_nested = false, $sanitize_content = true) {
$qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
$view_mode, $is_cat, $search, $search_mode, $match_on,
- $order, $offset, 0, false, $since_id);
+ $order, $offset, 0, false, $since_id, $include_nested);
$result = $qfh_ret[0];
$feed_title = $qfh_ret[1];
@@ -4582,7 +4473,17 @@
}
if ($show_content) {
- $headline_row["content"] = $line["content_preview"];
+
+ if ($line["cached_content"] != "") {
+ $line["content_preview"] =& $line["cached_content"];
+ }
+
+ if ($sanitize_content) {
+ $headline_row["content"] = sanitize($link,
+ $line["content_preview"], false, false, $line["site_url"]);
+ } else {
+ $headline_row["content"] = $line["content_preview"];
+ }
}
// unify label output to ease parsing
@@ -4592,6 +4493,11 @@
$headline_row["feed_title"] = $line["feed_title"];
+ $headline_row["comments_count"] = (int)$line["num_comments"];
+ $headline_row["comments_link"] = $line["comments"];
+
+ $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
+
array_push($headlines, $headline_row);
}
@@ -4712,22 +4618,13 @@
return false;
}
- /**
- * Extracts RSS/Atom feed URLs from the given HTML URL.
- *
- * @param string $url HTML page URL
- *
- * @return array Array of feeds. Key is the full URL, value the title
- */
- function get_feeds_from_html($url, $login = false, $pass = false)
+ function get_feeds_from_html($url, $content)
{
$url = fix_url($url);
$baseUrl = substr($url, 0, strrpos($url, '/') + 1);
libxml_use_internal_errors(true);
- $content = @fetch_file_contents($url, false, $login, $pass);
-
$doc = new DOMDocument();
$doc->loadHTML($content);
$xpath = new DOMXPath($doc);
@@ -4748,23 +4645,12 @@
return $feedUrls;
}
- /**
- * Checks if the content behind the given URL is a HTML file
- *
- * @param string $url URL to check
- *
- * @return boolean True if the URL contains HTML content
- */
- function url_is_html($url, $login = false, $pass = false) {
- $content = substr(fetch_file_contents($url, false, $login, $pass), 0, 1000);
-
- if (stripos($content, '') === false
- && stripos($content, ' 0) {
+ $children = getChildCategories($link, $rule["cat_id"], $owner_uid);
+ array_push($children, $rule["cat_id"]);
+
+ $children = join(",", $children);
+
+ $cat_qpart = "cat_id IN ($children)";
+ } else {
+ $cat_qpart = "cat_id IS NULL";
+ }
+
+ $qpart .= " AND $cat_qpart";
}
array_push($query, "($qpart)");
@@ -5165,6 +5063,12 @@
if ($feeds) {
if ($feeds['error']) {
$status = $feeds['error']['code'] + 10;
+
+ // access denied
+ if ($status == 16) {
+ db_query($link, "DELETE FROM ttrss_linked_feeds
+ WHERE instance_id = '$id'");
+ }
} else {
$status = 1;
@@ -5586,4 +5490,94 @@
}
+ function create_published_article($link, $title, $url, $content, $labels_str,
+ $owner_uid) {
+
+ $guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash
+ $content_hash = sha1($content);
+
+ if ($labels_str != "") {
+ $labels = explode(",", $labels_str);
+ } else {
+ $labels = array();
+ }
+
+ $rc = false;
+
+ if (!$title) $title = $url;
+ if (!$title && !$url) return false;
+
+ if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false;
+
+ db_query($link, "BEGIN");
+
+ // only check for our user data here, others might have shared this with different content etc
+ $result = db_query($link, "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
+ link = '$url' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1");
+
+ if (db_num_rows($result) != 0) {
+ $ref_id = db_fetch_result($result, 0, "id");
+
+ $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
+ ref_id = '$ref_id' AND owner_uid = '$owner_uid' LIMIT 1");
+
+ if (db_num_rows($result) != 0) {
+ $int_id = db_fetch_result($result, 0, "int_id");
+
+ db_query($link, "UPDATE ttrss_entries SET
+ content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'");
+
+ db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE
+ int_id = '$int_id' AND owner_uid = '$owner_uid'");
+ } else {
+
+ db_query($link, "INSERT INTO ttrss_user_entries
+ (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+ VALUES
+ ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+ }
+
+ if (count($labels) != 0) {
+ foreach ($labels as $label) {
+ label_add_article($link, $ref_id, trim($label), $owner_uid);
+ }
+ }
+
+ $rc = true;
+
+ } else {
+ $result = db_query($link, "INSERT INTO ttrss_entries
+ (title, guid, link, updated, content, content_hash, date_entered, date_updated)
+ VALUES
+ ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");
+
+ $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'");
+
+ if (db_num_rows($result) != 0) {
+ $ref_id = db_fetch_result($result, 0, "id");
+
+ db_query($link, "INSERT INTO ttrss_user_entries
+ (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+ VALUES
+ ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+
+ if (count($labels) != 0) {
+ foreach ($labels as $label) {
+ label_add_article($link, $ref_id, trim($label), $owner_uid);
+ }
+ }
+
+ $rc = true;
+ }
+ }
+
+ db_query($link, "COMMIT");
+
+ return $rc;
+ }
+
+ function implements_interface($class, $interface) {
+ return in_array($interface, class_implements($class));
+ }
+
?>