fix various issues reported by static analysis

update gitlab-ci config
This commit is contained in:
Andrew Dolgov 2017-04-26 15:29:22 +03:00
parent b49bb441f4
commit 7b55001eee
20 changed files with 142 additions and 160 deletions

View file

@ -11,6 +11,6 @@ jobs:
when: manual when: manual
stage: test stage: test
script: script:
- phpmd include text utils/gitlab-ci/phpmd-ruleset.xml - phpmd include text utils/gitlab-ci/phpmd-ruleset.xml
- phpmd classes text utils/gitlab-ci/phpmd-ruleset.xml - phpmd classes text utils/gitlab-ci/phpmd-ruleset.xml
- FILES=$(ls -dm *.php | sed "s/ //g") && phpmd $FILES text utils/gitlab-ci/phpmd-ruleset.xml

View file

@ -1,5 +1,4 @@
<?php <?php
class API extends Handler { class API extends Handler {
const API_LEVEL = 14; const API_LEVEL = 14;
@ -309,7 +308,7 @@ class API extends Handler {
get_feed_access_key(-2, false); get_feed_access_key(-2, false);
$p = new pubsubhubbub\publisher\Publisher(PUBSUBHUBBUB_HUB); $p = new pubsubhubbub\publisher\Publisher(PUBSUBHUBBUB_HUB);
$pubsub_result = $p->publish_update($rss_link); $p->publish_update($rss_link);
} }
} }
@ -418,7 +417,7 @@ class API extends Handler {
$feed_id = (int) $this->dbh->escape_string($_REQUEST["feed_id"]); $feed_id = (int) $this->dbh->escape_string($_REQUEST["feed_id"]);
if (!ini_get("open_basedir")) { if (!ini_get("open_basedir")) {
update_rss_feed($feed_id, true); update_rss_feed($feed_id);
} }
$this->wrap(self::STATUS_OK, array("status" => "OK")); $this->wrap(self::STATUS_OK, array("status" => "OK"));
@ -658,6 +657,9 @@ class API extends Handler {
return $feeds; return $feeds;
} }
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
static function api_get_headlines($feed_id, $limit, $offset, static function api_get_headlines($feed_id, $limit, $offset,
$filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
$include_attachments, $since_id, $include_attachments, $since_id,
@ -677,7 +679,7 @@ class API extends Handler {
if (!$cache_images && time() - $last_updated > 120) { if (!$cache_images && time() - $last_updated > 120) {
include "rssfuncs.php"; include "rssfuncs.php";
update_rss_feed($feed_id, true, true); update_rss_feed($feed_id, true);
} else { } else {
db_query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' db_query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
WHERE id = '$feed_id'"); WHERE id = '$feed_id'");

View file

@ -361,7 +361,7 @@ class Article extends Handler_Protected {
$labels = get_article_labels($id, $_SESSION["uid"]); $labels = get_article_labels($id, $_SESSION["uid"]);
array_push($reply["info-for-headlines"], array_push($reply["info-for-headlines"],
array("id" => $id, "labels" => format_article_labels($labels, $id))); array("id" => $id, "labels" => format_article_labels($labels)));
} }
} }

View file

@ -6,10 +6,16 @@ class Auth_Base {
$this->dbh = Db::get(); $this->dbh = Db::get();
} }
/**
* @SuppressWarnings(unused)
*/
function check_password($owner_uid, $password) { function check_password($owner_uid, $password) {
return false; return false;
} }
/**
* @SuppressWarnings(unused)
*/
function authenticate($login, $password) { function authenticate($login, $password) {
return false; return false;
} }

View file

@ -23,8 +23,6 @@ class Db_Prefs {
} }
function cache() { function cache() {
$profile = false;
$user_id = $_SESSION["uid"]; $user_id = $_SESSION["uid"];
@$profile = $_SESSION["profile"]; @$profile = $_SESSION["profile"];
@ -129,7 +127,6 @@ class Db_Prefs {
@$profile = $_SESSION["profile"]; @$profile = $_SESSION["profile"];
} else { } else {
$user_id = sprintf("%d", $user_id); $user_id = sprintf("%d", $user_id);
$prefs_cache = false;
} }
if ($profile) { if ($profile) {

View file

@ -13,7 +13,7 @@ class Feeds extends Handler_Protected {
private function format_headline_subtoolbar($feed_site_url, $feed_title, private function format_headline_subtoolbar($feed_site_url, $feed_title,
$feed_id, $is_cat, $search, $feed_id, $is_cat, $search,
$view_mode, $error, $feed_last_updated) { $error, $feed_last_updated) {
$catchup_sel_link = "catchupSelection()"; $catchup_sel_link = "catchupSelection()";
@ -153,7 +153,7 @@ class Feeds extends Handler_Protected {
} }
private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
$next_unread_feed, $offset, $vgr_last_feed = false, $offset, $vgr_last_feed = false,
$override_order = false, $include_children = false, $check_first_id = false, $override_order = false, $include_children = false, $check_first_id = false,
$skip_first_id_check = false) { $skip_first_id_check = false) {
@ -203,7 +203,7 @@ class Feeds extends Handler_Protected {
if (!$cache_images && time() - $last_updated > 120) { if (!$cache_images && time() - $last_updated > 120) {
include "rssfuncs.php"; include "rssfuncs.php";
update_rss_feed($feed, true, true); update_rss_feed($feed, true);
} else { } else {
$this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' $this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
WHERE id = '$feed'"); WHERE id = '$feed'");
@ -306,7 +306,7 @@ class Feeds extends Handler_Protected {
$reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
$feed_title, $feed_title,
$feed, $cat_view, $search, $view_mode, $feed, $cat_view, $search,
$last_error, $last_updated); $last_error, $last_updated);
$headlines_count = is_numeric($result) ? 0 : $this->dbh->num_rows($result); $headlines_count = is_numeric($result) ? 0 : $this->dbh->num_rows($result);
@ -361,7 +361,7 @@ class Feeds extends Handler_Protected {
if (!is_array($labels)) $labels = get_article_labels($id); if (!is_array($labels)) $labels = get_article_labels($id);
$labels_str = "<span class=\"HLLCTR-$id\">"; $labels_str = "<span class=\"HLLCTR-$id\">";
$labels_str .= format_article_labels($labels, $id); $labels_str .= format_article_labels($labels);
$labels_str .= "</span>"; $labels_str .= "</span>";
if (count($topmost_article_ids) < 3) { if (count($topmost_article_ids) < 3) {
@ -937,7 +937,7 @@ class Feeds extends Handler_Protected {
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
$ret = $this->format_headlines_list($feed, $method, $ret = $this->format_headlines_list($feed, $method,
$view_mode, $limit, $cat_view, $next_unread_feed, $offset, $view_mode, $limit, $cat_view, $offset,
$vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check); $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check);
//$topmost_article_ids = $ret[0]; //$topmost_article_ids = $ret[0];
@ -1231,7 +1231,7 @@ class Feeds extends Handler_Protected {
if ($do_update) { if ($do_update) {
include "rssfuncs.php"; include "rssfuncs.php";
update_rss_feed($feed_id, true, true); update_rss_feed($feed_id, true);
} }
?></pre> ?></pre>

View file

@ -1,6 +1,9 @@
<?php <?php
class Logger_Syslog { class Logger_Syslog {
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function log_error($errno, $errstr, $file, $line, $context) { function log_error($errno, $errstr, $file, $line, $context) {
switch ($errno) { switch ($errno) {

View file

@ -251,7 +251,7 @@ class Opml extends Handler_Protected {
// Import // Import
private function opml_import_feed($doc, $node, $cat_id, $owner_uid) { private function opml_import_feed($node, $cat_id, $owner_uid) {
$attrs = $node->attributes; $attrs = $node->attributes;
$feed_title = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250)); $feed_title = $this->dbh->escape_string(mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250));
@ -284,7 +284,7 @@ class Opml extends Handler_Protected {
} }
} }
private function opml_import_label($doc, $node, $owner_uid) { private function opml_import_label($node, $owner_uid) {
$attrs = $node->attributes; $attrs = $node->attributes;
$label_name = $this->dbh->escape_string($attrs->getNamedItem('label-name')->nodeValue); $label_name = $this->dbh->escape_string($attrs->getNamedItem('label-name')->nodeValue);
@ -301,7 +301,7 @@ class Opml extends Handler_Protected {
} }
} }
private function opml_import_preference($doc, $node, $owner_uid) { private function opml_import_preference($node) {
$attrs = $node->attributes; $attrs = $node->attributes;
$pref_name = $this->dbh->escape_string($attrs->getNamedItem('pref-name')->nodeValue); $pref_name = $this->dbh->escape_string($attrs->getNamedItem('pref-name')->nodeValue);
@ -315,7 +315,7 @@ class Opml extends Handler_Protected {
} }
} }
private function opml_import_filter($doc, $node, $owner_uid) { private function opml_import_filter($node) {
$attrs = $node->attributes; $attrs = $node->attributes;
$filter_type = $this->dbh->escape_string($attrs->getNamedItem('filter-type')->nodeValue); $filter_type = $this->dbh->escape_string($attrs->getNamedItem('filter-type')->nodeValue);
@ -386,8 +386,6 @@ class Opml extends Handler_Protected {
} }
private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) { private function opml_import_category($doc, $root_node, $owner_uid, $parent_id) {
$body = $doc->getElementsByTagName('body');
$default_cat_id = (int) get_feed_category('Imported feeds', false); $default_cat_id = (int) get_feed_category('Imported feeds', false);
if ($root_node) { if ($root_node) {
@ -442,16 +440,16 @@ class Opml extends Handler_Protected {
switch ($cat_title) { switch ($cat_title) {
case "tt-rss-prefs": case "tt-rss-prefs":
$this->opml_import_preference($doc, $node, $owner_uid); $this->opml_import_preference($node);
break; break;
case "tt-rss-labels": case "tt-rss-labels":
$this->opml_import_label($doc, $node, $owner_uid); $this->opml_import_label($node, $owner_uid);
break; break;
case "tt-rss-filters": case "tt-rss-filters":
$this->opml_import_filter($doc, $node, $owner_uid); $this->opml_import_filter($node);
break; break;
default: default:
$this->opml_import_feed($doc, $node, $dst_cat_id, $owner_uid); $this->opml_import_feed($node, $dst_cat_id, $owner_uid);
} }
} }
} }
@ -461,19 +459,14 @@ class Opml extends Handler_Protected {
function opml_import($owner_uid) { function opml_import($owner_uid) {
if (!$owner_uid) return; if (!$owner_uid) return;
$debug = isset($_REQUEST["debug"]);
$doc = false; $doc = false;
# if ($debug) $doc = DOMDocument::load("/tmp/test.opml");
if ($_FILES['opml_file']['error'] != 0) { if ($_FILES['opml_file']['error'] != 0) {
print_error(T_sprintf("Upload failed with error code %d", print_error(T_sprintf("Upload failed with error code %d",
$_FILES['opml_file']['error'])); $_FILES['opml_file']['error']));
return; return;
} }
$tmp_file = false;
if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
$tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml');

View file

@ -22,6 +22,9 @@ class Plugin {
return array(); return array();
} }
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function is_public_method($method) { function is_public_method($method) {
return false; return false;
} }

View file

@ -288,7 +288,7 @@ class PluginHost {
} }
} }
function load_data($force = false) { function load_data() {
if ($this->owner_uid) { if ($this->owner_uid) {
$result = $this->dbh->query("SELECT name, content FROM ttrss_plugin_storage $result = $this->dbh->query("SELECT name, content FROM ttrss_plugin_storage
WHERE owner_uid = '".$this->owner_uid."'"); WHERE owner_uid = '".$this->owner_uid."'");

View file

@ -130,7 +130,7 @@ class Pref_Filters extends Handler_Protected {
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
$rc = get_article_filters(array($filter), $line['title'], $line['content'], $line['link'], $rc = get_article_filters(array($filter), $line['title'], $line['content'], $line['link'],
false, $line['author'], explode(",", $line['tag_cache'])); $line['author'], explode(",", $line['tag_cache']));
if (count($rc) > 0) { if (count($rc) > 0) {

View file

@ -251,7 +251,6 @@ class Pref_Users extends Handler_Protected {
$login = db_fetch_result($result, 0, "login"); $login = db_fetch_result($result, 0, "login");
$email = db_fetch_result($result, 0, "email"); $email = db_fetch_result($result, 0, "email");
$salt = db_fetch_result($result, 0, "salt");
$new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
$tmp_user_pwd = make_password(8); $tmp_user_pwd = make_password(8);

View file

@ -453,7 +453,7 @@ class RPC extends Handler_Protected {
$search_query = $this->dbh->escape_string($_REQUEST['search_query']); $search_query = $this->dbh->escape_string($_REQUEST['search_query']);
$search_lang = $this->dbh->escape_string($_REQUEST['search_lang']); $search_lang = $this->dbh->escape_string($_REQUEST['search_lang']);
catchup_feed($feed_id, $is_cat, false, false, $mode, [$search_query, $search_lang]); catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
print json_encode(array("message" => "UPDATE_COUNTERS")); print json_encode(array("message" => "UPDATE_COUNTERS"));
} }

View file

@ -32,8 +32,6 @@ function format_backtrace($trace) {
} }
function ttrss_error_handler($errno, $errstr, $file, $line, $context) { function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
global $logger;
if (error_reporting() == 0 || !$errno) return false; if (error_reporting() == 0 || !$errno) return false;
$file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1);
@ -46,7 +44,6 @@ function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
} }
function ttrss_fatal_handler() { function ttrss_fatal_handler() {
global $logger;
global $last_query; global $last_query;
$error = error_get_last(); $error = error_get_last();

View file

@ -1163,7 +1163,7 @@
} }
} }
function catchup_feed($feed, $cat_view, $owner_uid = false, $max_id = false, $mode = 'all', $search = false) { function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
if (!$owner_uid) $owner_uid = $_SESSION['uid']; if (!$owner_uid) $owner_uid = $_SESSION['uid'];
@ -1746,7 +1746,6 @@
global $fetch_last_error; global $fetch_last_error;
global $fetch_last_error_content; global $fetch_last_error_content;
global $fetch_last_error_code;
require_once "include/rssfuncs.php"; require_once "include/rssfuncs.php";
@ -2066,5 +2065,3 @@
// TODO: less dumb splitting // TODO: less dumb splitting
require_once "functions2.php"; require_once "functions2.php";
?>

View file

@ -1557,7 +1557,7 @@
} }
} // function encrypt_password } // function encrypt_password
function load_filters($feed_id, $owner_uid, $action_id = false) { function load_filters($feed_id, $owner_uid) {
$filters = array(); $filters = array();
$cat_id = (int)getFeedCategory($feed_id); $cat_id = (int)getFeedCategory($feed_id);
@ -1655,7 +1655,7 @@
return true; return true;
} }
function format_tags_string($tags, $id) { function format_tags_string($tags) {
if (!is_array($tags) || count($tags) == 0) { if (!is_array($tags) || count($tags) == 0) {
return __("no tags"); return __("no tags");
} else { } else {
@ -1675,7 +1675,7 @@
} }
} }
function format_article_labels($labels, $id) { function format_article_labels($labels) {
if (!is_array($labels)) return ''; if (!is_array($labels)) return '';
@ -2484,6 +2484,9 @@
return false; return false;
} }
/**
* @SuppressWarnings(unused)
*/
function error_json($code) { function error_json($code) {
require_once "errors.php"; require_once "errors.php";

View file

@ -60,20 +60,7 @@
} }
function update_daemon_common($limit = DAEMON_FEED_LIMIT, $debug = true) {
/**
* Update a feed batch.
* Used by daemons to update n feeds by run.
* Only update feed needing a update, and not being processed
* by another process.
*
* @param mixed $link Database link
* @param integer $limit Maximum number of feeds in update batch. Default to DAEMON_FEED_LIMIT.
* @param boolean $from_http Set to true if you call this function from http to disable cli specific code.
* @param boolean $debug Set to false to disable debug output. Default to true.
* @return void
*/
function update_daemon_common($limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) {
// Process all other feeds using last_updated and interval parameters // Process all other feeds using last_updated and interval parameters
$schema_version = get_schema_version(); $schema_version = get_schema_version();
@ -200,8 +187,6 @@
ORDER BY ttrss_feeds.id $query_limit"); ORDER BY ttrss_feeds.id $query_limit");
if (db_num_rows($tmp_result) > 0) { if (db_num_rows($tmp_result) > 0) {
$rss = false;
while ($tline = db_fetch_assoc($tmp_result)) { while ($tline = db_fetch_assoc($tmp_result)) {
if($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); if($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]);
@ -209,7 +194,7 @@
array_push($batch_owners, $tline["owner_uid"]); array_push($batch_owners, $tline["owner_uid"]);
$fstarted = microtime(true); $fstarted = microtime(true);
$rss = update_rss_feed($tline["id"], true, false); update_rss_feed($tline["id"], true, false);
_debug_suppress(false); _debug_suppress(false);
_debug(sprintf(" %.4f (sec)", microtime(true) - $fstarted)); _debug(sprintf(" %.4f (sec)", microtime(true) - $fstarted));
@ -237,7 +222,7 @@
return $nf; return $nf;
} // function update_daemon_common }
// this is used when subscribing // this is used when subscribing
function set_basic_feed_info($feed) { function set_basic_feed_info($feed) {
@ -300,8 +285,10 @@
} }
} }
// ignore_daemon is not used /**
function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false, $rss = false) { * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function update_rss_feed($feed, $no_cache = false) {
$debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']; $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
@ -370,94 +357,90 @@
$pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
$pluginhost->load_data(); $pluginhost->load_data();
if ($rss && is_object($rss) && get_class($rss) == "FeedParser") { $rss_hash = false;
_debug("using previously initialized parser object");
$force_refetch = isset($_REQUEST["force_refetch"]);
$feed_data = "";
foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
$feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass);
}
// try cache
if (!$feed_data &&
file_exists($cache_filename) &&
is_readable($cache_filename) &&
!$auth_login && !$auth_pass &&
filemtime($cache_filename) > time() - 30) {
_debug("using local cache [$cache_filename].", $debug_enabled);
@$feed_data = file_get_contents($cache_filename);
if ($feed_data) {
$rss_hash = sha1($feed_data);
}
} else { } else {
$rss_hash = false; _debug("local cache will not be used for this feed", $debug_enabled);
}
$force_refetch = isset($_REQUEST["force_refetch"]); // fetch feed from source
$feed_data = ""; if (!$feed_data) {
_debug("fetching [$fetch_url]...", $debug_enabled);
foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { if (ini_get("open_basedir") && function_exists("curl_init")) {
$feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, 0, $auth_login, $auth_pass); _debug("not using CURL due to open_basedir restrictions");
} }
// try cache $feed_data = fetch_file_contents($fetch_url, false,
if (!$feed_data && $auth_login, $auth_pass, false,
file_exists($cache_filename) && $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
is_readable($cache_filename) && 0);
!$auth_login && !$auth_pass &&
filemtime($cache_filename) > time() - 30) {
_debug("using local cache [$cache_filename].", $debug_enabled); global $fetch_curl_used;
@$feed_data = file_get_contents($cache_filename); if (!$fetch_curl_used) {
$tmp = @gzdecode($feed_data);
if ($feed_data) { if ($tmp) $feed_data = $tmp;
$rss_hash = sha1($feed_data); }
$feed_data = trim($feed_data);
_debug("fetch done.", $debug_enabled);
// cache vanilla feed data for re-use
if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
$new_rss_hash = sha1($feed_data);
if ($new_rss_hash != $rss_hash) {
_debug("saving $cache_filename", $debug_enabled);
@file_put_contents($cache_filename, $feed_data);
} }
}
}
if (!$feed_data) {
global $fetch_last_error;
global $fetch_last_error_code;
_debug("unable to fetch: $fetch_last_error [$fetch_last_error_code]", $debug_enabled);
$error_escaped = '';
// If-Modified-Since
if ($fetch_last_error_code != 304) {
$error_escaped = db_escape_string($fetch_last_error);
} else { } else {
_debug("local cache will not be used for this feed", $debug_enabled); _debug("source claims data not modified, nothing to do.", $debug_enabled);
} }
// fetch feed from source db_query(
if (!$feed_data) { "UPDATE ttrss_feeds SET last_error = '$error_escaped',
_debug("fetching [$fetch_url]...", $debug_enabled); last_updated = NOW() WHERE id = '$feed'");
if (ini_get("open_basedir") && function_exists("curl_init")) { return;
_debug("not using CURL due to open_basedir restrictions");
}
$feed_data = fetch_file_contents($fetch_url, false,
$auth_login, $auth_pass, false,
$no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT,
0);
global $fetch_curl_used;
if (!$fetch_curl_used) {
$tmp = @gzdecode($feed_data);
if ($tmp) $feed_data = $tmp;
}
$feed_data = trim($feed_data);
_debug("fetch done.", $debug_enabled);
// cache vanilla feed data for re-use
if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
$new_rss_hash = sha1($feed_data);
if ($new_rss_hash != $rss_hash) {
_debug("saving $cache_filename", $debug_enabled);
@file_put_contents($cache_filename, $feed_data);
}
}
}
if (!$feed_data) {
global $fetch_last_error;
global $fetch_last_error_code;
_debug("unable to fetch: $fetch_last_error [$fetch_last_error_code]", $debug_enabled);
$error_escaped = '';
// If-Modified-Since
if ($fetch_last_error_code != 304) {
$error_escaped = db_escape_string($fetch_last_error);
} else {
_debug("source claims data not modified, nothing to do.", $debug_enabled);
}
db_query(
"UPDATE ttrss_feeds SET last_error = '$error_escaped',
last_updated = NOW() WHERE id = '$feed'");
return;
}
} }
foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
@ -797,7 +780,7 @@
$matched_rules = array(); $matched_rules = array();
$article_filters = get_article_filters($filters, $article["title"], $article_filters = get_article_filters($filters, $article["title"],
$article["content"], $article["link"], 0, $article["author"], $article["content"], $article["link"], $article["author"],
$article["tags"], $matched_rules); $article["tags"], $matched_rules);
if ($debug_enabled) { if ($debug_enabled) {
@ -1224,11 +1207,12 @@
last_updated = NOW() WHERE id = '$feed'"); last_updated = NOW() WHERE id = '$feed'");
unset($rss); unset($rss);
return;
} }
_debug("done", $debug_enabled); _debug("done", $debug_enabled);
return $rss; return true;
} }
function cache_enclosures($enclosures, $site_url, $debug) { function cache_enclosures($enclosures, $site_url, $debug) {
@ -1369,7 +1353,7 @@
return $params; return $params;
} }
function get_article_filters($filters, $title, $content, $link, $timestamp, $author, $tags, &$matched_rules = false) { function get_article_filters($filters, $title, $content, $link, $author, $tags, &$matched_rules = false) {
$matches = array(); $matches = array();
foreach ($filters as $filter) { foreach ($filters as $filter) {
@ -1505,15 +1489,6 @@
mb_strtolower(strip_tags($title), 'utf-8')); mb_strtolower(strip_tags($title), 'utf-8'));
} }
/* function verify_feed_xml($feed_data) {
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadXML($feed_data);
$error = libxml_get_last_error();
libxml_clear_errors();
return $error;
} */
function cleanup_counters_cache($debug) { function cleanup_counters_cache($debug) {
$result = db_query("DELETE FROM ttrss_counters_cache $result = db_query("DELETE FROM ttrss_counters_cache
WHERE feed_id > 0 AND WHERE feed_id > 0 AND
@ -1529,7 +1504,7 @@
ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0"); ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0");
$crows = db_affected_rows($result); $crows = db_affected_rows($result);
_debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries."); if ($debug) _debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries.");
} }
function housekeeping_user($owner_uid) { function housekeeping_user($owner_uid) {

View file

@ -1,6 +1,5 @@
<?php <?php
/* /* WARNING!
* WARNING!
* *
* If you modify this file, you are ON YOUR OWN! * If you modify this file, you are ON YOUR OWN!
* *
@ -21,6 +20,9 @@
return $url_path; return $url_path;
} }
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
function initial_sanity_check() { function initial_sanity_check() {
$errors = array(); $errors = array();

View file

@ -23,7 +23,7 @@
ini_set("session.gc_maxlifetime", $session_expire); ini_set("session.gc_maxlifetime", $session_expire);
ini_set("session.cookie_lifetime", min(0, SESSION_COOKIE_LIFETIME)); ini_set("session.cookie_lifetime", min(0, SESSION_COOKIE_LIFETIME));
function session_get_schema_version($nocache = false) { function session_get_schema_version() {
global $schema_version; global $schema_version;
if (!$schema_version) { if (!$schema_version) {
@ -39,7 +39,7 @@
function validate_session() { function validate_session() {
if (SINGLE_USER_MODE) return true; if (SINGLE_USER_MODE) return true;
if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version(true)) { if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) {
$_SESSION["login_error_msg"] = $_SESSION["login_error_msg"] =
__("Session failed to validate (schema version changed)"); __("Session failed to validate (schema version changed)");
return false; return false;
@ -72,7 +72,9 @@
return true; return true;
} }
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function ttrss_open ($s, $n) { function ttrss_open ($s, $n) {
return true; return true;
} }
@ -117,6 +119,9 @@
return true; return true;
} }
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function ttrss_gc ($expire) { function ttrss_gc ($expire) {
Db::get()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); Db::get()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());

View file

@ -401,7 +401,7 @@
$_REQUEST['xdebug'] = 1; $_REQUEST['xdebug'] = 1;
$rc = is_object(update_rss_feed($feed)) ? 0 : 1; $rc = update_rss_feed($feed) != false ? 0 : 1;
exit($rc); exit($rc);
} }