<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 118);
+ define('SCHEMA_VERSION', 120);
define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128);
+ define('COOKIE_LIFETIME_LONG', 86400*365);
+
$fetch_last_error = false;
$fetch_last_error_code = false;
$fetch_last_content_type = false;
$fetch_curl_used = false;
- $pluginhost = false;
mb_internal_encoding("UTF-8");
date_default_timezone_set('UTC');
$lang = _TRANSLATION_OVERRIDE_DEFAULT;
}
- if ($_SESSION["language"] && $_SESSION["language"] != "auto") {
- $lang = $_SESSION["language"];
+ if ($_SESSION["uid"] && get_schema_version() >= 120) {
+ $pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
+
+ if ($pref_lang) {
+ $lang = $pref_lang;
+ }
}
if ($lang) {
}
}
- startup_gettext();
-
require_once 'db-prefs.php';
require_once 'version.php';
require_once 'ccache.php';
require_once 'lib/pubsubhubbub/publisher.php';
- $tz_offset = -1;
- $utc_tz = new DateTimeZone('UTC');
$schema_version = false;
/**
* @param string $msg The debug message.
* @return void
*/
- function _debug($msg) {
+ function _debug($msg, $show = true) {
+
$ts = strftime("%H:%M:%S", time());
if (function_exists('posix_getpid')) {
$ts = "$ts/" . posix_getpid();
}
- if (!(defined('QUIET') && QUIET)) {
+ if ($show && !(defined('QUIET') && QUIET)) {
print "[$ts] $msg\n";
}
$ch = curl_init($url);
}
- if ($timestamp) {
+ if ($timestamp && !$post_query) {
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T', $timestamp)));
}
}
}
- $data = @file_get_contents($url);
+ if (!$post_query && $timestamp) {
+ $context = stream_context_create(array(
+ 'http' => array(
+ 'method' => 'GET',
+ 'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp)
+ )));
+ } else {
+ $context = NULL;
+ }
+
+ $old_error = error_get_last();
+
+ $data = @file_get_contents($url, false, $context);
$fetch_last_content_type = false; // reset if no type was sent from server
- foreach ($http_response_header as $h) {
- if (substr(strtolower($h), 0, 13) == 'content-type:') {
- $fetch_last_content_type = substr($h, 14);
- // don't abort here b/c there might be more than one
- // e.g. if we were being redirected -- last one is the right one
+ if (isset($http_response_header) && is_array($http_response_header)) {
+ foreach ($http_response_header as $h) {
+ if (substr(strtolower($h), 0, 13) == 'content-type:') {
+ $fetch_last_content_type = substr($h, 14);
+ // don't abort here b/c there might be more than one
+ // e.g. if we were being redirected -- last one is the right one
+ }
+
+ if (substr(strtolower($h), 0, 7) == 'http/1.') {
+ $fetch_last_error_code = (int) substr($h, 9, 3);
+ }
}
}
- if (!$data && function_exists('error_get_last')) {
+ if (!$data) {
$error = error_get_last();
- $fetch_last_error = $error["message"];
+
+ if ($error['message'] != $old_error['message']) {
+ $fetch_last_error = $error["message"];
+ } else {
+ $fetch_last_error = "HTTP Code: $fetch_last_error_code";
+ }
}
return $data;
}
if (!SINGLE_USER_MODE) {
$user_id = false;
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_AUTH_USER) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_AUTH_USER) as $plugin) {
$user_id = (int) $plugin->authenticate($login, $password);
@session_start();
$_SESSION["uid"] = $user_id;
- $_SESSION["version"] = VERSION;
+ $_SESSION["version"] = VERSION_STATIC;
$result = db_query("SELECT login,access_level,pwd_hash FROM ttrss_users
WHERE id = '$user_id'");
if ($owner_uid) {
$plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
- global $pluginhost;
- $pluginhost->load($plugins, $pluginhost::KIND_USER, $owner_uid);
+ PluginHost::getInstance()->load($plugins, PluginHost::KIND_USER, $owner_uid);
if (get_schema_version() > 100) {
- $pluginhost->load_data();
+ PluginHost::getInstance()->load_data();
}
}
}
function login_sequence() {
- $_SESSION["prefs_cache"] = false;
-
if (SINGLE_USER_MODE) {
@session_start();
authenticate_user("admin", null);
- cache_prefs();
load_user_plugins($_SESSION["uid"]);
} else {
if (!validate_session()) $_SESSION["uid"] = false;
$_SESSION["last_login_update"] = time();
}
- if ($_SESSION["uid"] && $_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) {
- setcookie("ttrss_lang", $_SESSION["language"],
- time() + SESSION_COOKIE_LIFETIME);
- }
-
if ($_SESSION["uid"]) {
- cache_prefs();
+ startup_gettext();
load_user_plugins($_SESSION["uid"]);
/* cleanup ccache */
if (!$timestamp) $timestamp = '1970-01-01 0:00';
global $utc_tz;
- global $tz_offset;
+ global $user_tz;
+
+ if (!$utc_tz) $utc_tz = new DateTimeZone('UTC');
+
+ $timestamp = substr($timestamp, 0, 19);
# We store date in UTC internally
$dt = new DateTime($timestamp, $utc_tz);
- if ($tz_offset == -1) {
+ $user_tz_string = get_pref('USER_TIMEZONE', $owner_uid);
- $user_tz_string = get_pref('USER_TIMEZONE', $owner_uid);
+ if ($user_tz_string != 'Automatic') {
try {
- $user_tz = new DateTimeZone($user_tz_string);
+ if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
} catch (Exception $e) {
$user_tz = $utc_tz;
}
$tz_offset = $user_tz->getOffset($dt);
+ } else {
+ $tz_offset = (int) -$_SESSION["clientTzOffset"];
}
$user_timestamp = $dt->format('U') + $tz_offset;
function get_schema_version($nocache = false) {
global $schema_version;
- if (!$schema_version) {
+ if (!$schema_version && !$nocache) {
$result = db_query("SELECT schema_version FROM ttrss_version");
$version = db_fetch_result($result, 0, "schema_version");
$schema_version = $version;
array_push($ret_arr, $cv);
}
- global $pluginhost;
-
- if ($pluginhost) {
- $feeds = $pluginhost->get_feeds(-1);
-
- if (is_array($feeds)) {
- foreach ($feeds as $feed) {
- $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
- "counter" => $feed['sender']->get_unread($feed['id']));
+ $feeds = PluginHost::getInstance()->get_feeds(-1);
+ if (is_array($feeds)) {
+ foreach ($feeds as $feed) {
+ $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
+ "counter" => $feed['sender']->get_unread($feed['id']));
array_push($ret_arr, $cv);
- }
}
}
* Here you should call extractfeedurls in rpc-backend
* to get all possible feeds.
* 5 - Couldn't download the URL content.
+ * 6 - Content is an invalid XML.
*/
function subscribe_to_feed($url, $cat_id = 0,
$auth_login = '', $auth_pass = '') {
$url = key($feedUrls);
}
+ /* libxml_use_internal_errors(true);
+ $doc = new DOMDocument();
+ $doc->loadXML($contents);
+ $error = libxml_get_last_error();
+ libxml_clear_errors();
+
+ if ($error) {
+ $error_message = format_libxml_error($error);
+
+ return array("code" => 6, "message" => $error_message);
+ } */
+
if ($cat_id == "0" || !$cat_id) {
$cat_qpart = "NULL";
} else {
"help_dialog" => __("Show help dialog"))
);
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_INFO) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_INFO) as $plugin) {
$hotkeys = $plugin->hook_hotkey_info($hotkeys);
}
$hotkeys["^(40)|Ctrl-down"] = "next_article_noscroll";
}
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_MAP) as $plugin) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HOTKEY_MAP) as $plugin) {
$hotkeys = $plugin->hook_hotkey_map($hotkeys);
}
$feed_title = getCategoryTitle($feed);
} else {
if (is_numeric($feed) && $feed > 0) {
- $result = db_query("SELECT title,site_url,last_error
+ $result = db_query("SELECT title,site_url,last_error,last_updated
FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = $owner_uid");
$feed_title = db_fetch_result($result, 0, "title");
$feed_site_url = db_fetch_result($result, 0, "site_url");
$last_error = db_fetch_result($result, 0, "last_error");
+ $last_updated = db_fetch_result($result, 0, "last_updated");
} else {
$feed_title = getFeedTitle($feed);
}
$result = db_query($select_qpart . $from_qpart . $where_qpart);
}
- return array($result, $feed_title, $feed_site_url, $last_error);
+ return array($result, $feed_title, $feed_site_url, $last_error, $last_updated);
}
$disallowed_attributes = array('id', 'style', 'class');
- global $pluginhost;
-
- if (isset($pluginhost)) {
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_SANITIZE) as $plugin) {
- $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes);
- if (is_array($retval)) {
- $doc = $retval[0];
- $allowed_elements = $retval[1];
- $disallowed_attributes = $retval[2];
- } else {
- $doc = $retval;
- }
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
+ $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes);
+ if (is_array($retval)) {
+ $doc = $retval[0];
+ $allowed_elements = $retval[1];
+ $disallowed_attributes = $retval[2];
+ } else {
+ $doc = $retval;
}
}
}
function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) {
- $entries = $doc->getElementsByTagName("*");
+ $xpath = new DOMXPath($doc);
+ $entries = $xpath->query('//*');
foreach ($entries as $entry) {
if (!in_array($entry->nodeName, $allowed_elements)) {
function format_warning($msg, $id = "") {
global $link;
return "<div class=\"warning\" id=\"$id\">
- <img src=\"images/sign_excl.svg\"><div class='inner'>$msg</div></div>";
+ <span><img src=\"images/sign_excl.svg\"></span><span>$msg</span></div>";
}
function format_notice($msg, $id = "") {
global $link;
return "<div class=\"notice\" id=\"$id\">
- <img src=\"images/sign_info.svg\"><div class='inner'>$msg</div></div>";
+ <span><img src=\"images/sign_info.svg\"></span><span>$msg</span></div>";
}
function format_error($msg, $id = "") {
global $link;
return "<div class=\"error\" id=\"$id\">
- <img src=\"images/sign_excl.svg\"><div class='inner'>$msg</div></div>";
+ <span><img src=\"images/sign_excl.svg\"></span><span>$msg</span></div>";
}
function print_notice($msg) {
$line["content"] = sanitize($line["content"], false, $owner_uid, $line["site_url"]);
- global $pluginhost;
-
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
$line = $p->hook_render_article($line);
}
id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
position=\"below\">$tags_str_full</div>";
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
$rv['content'] .= $p->hook_article_button($line);
}
$rv['content'] .= "</div>";
$rv['content'] .= "<div clear='both'>";
- global $pluginhost;
- foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
$rv['content'] .= $p->hook_article_left_button($line);
}
}
function init_plugins() {
- global $pluginhost;
-
- $pluginhost = new PluginHost(Db::get());
- $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+ PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL);
return true;
}
function format_article_labels($labels, $id) {
- if (is_array($labels)) return '';
+ if (!is_array($labels)) return '';
$labels_str = "";
return LABEL_BASE_INDEX - 1 + abs($feed);
}
+ function format_libxml_error($error) {
+ return T_sprintf("LibXML error %s at line %d (column %d): %s",
+ $error->code, $error->line, $error->column,
+ $error->message);
+ }
+
?>