summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ccache.php1
-rw-r--r--include/functions.php7
-rw-r--r--include/functions2.php137
-rw-r--r--include/rssfuncs.php72
-rw-r--r--include/sanity_config.php4
-rw-r--r--include/sessions.php8
-rw-r--r--include/version.php4
7 files changed, 138 insertions, 95 deletions
diff --git a/include/ccache.php b/include/ccache.php
index 406dec81d..b938b8664 100644
--- a/include/ccache.php
+++ b/include/ccache.php
@@ -139,6 +139,7 @@
$result = db_query("SELECT SUM(value) AS sv
FROM ttrss_counters_cache, ttrss_feeds
WHERE id = feed_id AND $cat_qpart AND
+ ttrss_counters_cache.owner_uid = $owner_uid AND
ttrss_feeds.owner_uid = '$owner_uid'");
$unread = (int) db_fetch_result($result, 0, "sv");
diff --git a/include/functions.php b/include/functions.php
index 2f3daea10..0d4c8ed09 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 126);
+ define('SCHEMA_VERSION', 127);
define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -67,6 +67,7 @@
$tr = array(
"auto" => "Detect automatically",
"ar_SA" => "العربيّة (Arabic)",
+ "bg_BG" => "Bulgarian",
"da_DA" => "Dansk",
"ca_CA" => "Català",
"cs_CZ" => "Česky",
@@ -806,10 +807,6 @@
function initialize_user($uid) {
db_query("insert into ttrss_feeds (owner_uid,title,feed_url)
- values ('$uid', 'Tiny Tiny RSS: New Releases',
- 'http://tt-rss.org/releases.rss')");
-
- db_query("insert into ttrss_feeds (owner_uid,title,feed_url)
values ('$uid', 'Tiny Tiny RSS: Forum',
'http://tt-rss.org/forum/rss.php')");
}
diff --git a/include/functions2.php b/include/functions2.php
index 669bbe038..27b1933d0 100644
--- a/include/functions2.php
+++ b/include/functions2.php
@@ -203,6 +203,26 @@
return array($prefixes, $hotkeys);
}
+ function check_for_update() {
+ if (defined("GIT_VERSION_TIMESTAMP")) {
+ $content = @fetch_file_contents("http://tt-rss.org/version.json");
+
+ if ($content) {
+ $content = json_decode($content, true);
+
+ if ($content && isset($content["changeset"])) {
+ if ((int)GIT_VERSION_TIMESTAMP < (int)$content["changeset"]["timestamp"] &&
+ GIT_VERSION_HEAD != $content["changeset"]["id"]) {
+
+ return $content["changeset"]["id"];
+ }
+ }
+ }
+ }
+
+ return "";
+ }
+
function make_runtime_info() {
$data = array();
@@ -221,6 +241,15 @@
$data['dep_ts'] = calculate_dep_timestamp();
$data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE');
+
+ if (CHECK_FOR_UPDATES && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
+ $update_result = @check_for_update();
+
+ $data["update_result"] = $update_result;
+
+ $_SESSION["last_version_check"] = time();
+ }
+
if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
$data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
@@ -248,15 +277,6 @@
}
}
- if ($_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
- $new_version_details = @check_for_update();
-
- $data['new_version_available'] = (int) ($new_version_details != false);
-
- $_SESSION["last_version_check"] = time();
- $_SESSION["version_data"] = $new_version_details;
- }
-
return $data;
}
@@ -340,6 +360,19 @@
if (!$not) array_push($search_words, $k);
}
break;
+ case "unread":
+ if ($commandpair[1]) {
+ if ($commandpair[1] == "true")
+ array_push($query_keywords, "($not (unread = true))");
+ else
+ array_push($query_keywords, "($not (unread = false))");
+
+ } else {
+ array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
+ OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+ if (!$not) array_push($search_words, $k);
+ }
+ break;
default:
if (strpos($k, "@") === 0) {
@@ -632,10 +665,6 @@
$order_by = "score DESC, date_entered DESC, updated DESC";
- if ($view_mode == "unread_first") {
- $order_by = "unread DESC, $order_by";
- }
-
if ($override_order) {
$order_by = $override_order;
}
@@ -880,7 +909,7 @@
$cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png';
if (file_exists($cached_filename)) {
- $src = SELF_URL_PATH . '/image.php?hash=' . sha1($src);
+ $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src);
}
$entry->setAttribute('src', $src);
@@ -1019,25 +1048,6 @@
return $doc;
}
- function check_for_update() {
- if (CHECK_FOR_NEW_VERSION && $_SESSION['access_level'] >= 10) {
- $version_url = "http://tt-rss.org/version.php?ver=" . VERSION .
- "&iid=" . sha1(SELF_URL_PATH);
-
- $version_data = @fetch_file_contents($version_url);
-
- if ($version_data) {
- $version_data = json_decode($version_data, true);
- if ($version_data && $version_data['version']) {
- if (version_compare(VERSION_STATIC, $version_data['version']) == -1) {
- return $version_data;
- }
- }
- }
- }
- return false;
- }
-
function catchupArticlesById($ids, $cmode, $owner_uid = false) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
@@ -1930,28 +1940,37 @@
foreach ($entries as $entry) {
- if (preg_match("/image/", $entry["type"]) ||
- preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
-
- if (!$hide_images) {
- $encsize = '';
- if ($entry['height'] > 0)
- $encsize .= ' height="' . intval($entry['width']) . '"';
- if ($entry['width'] > 0)
- $encsize .= ' width="' . intval($entry['height']) . '"';
- $rv .= "<p><img
- alt=\"".htmlspecialchars($entry["filename"])."\"
- src=\"" .htmlspecialchars($entry["url"]) . "\"
- " . $encsize . " /></p>";
- } else {
- $rv .= "<p><a target=\"_blank\"
- href=\"".htmlspecialchars($entry["url"])."\"
- >" .htmlspecialchars($entry["url"]) . "</a></p>";
- }
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin)
+ $retval = $plugin->hook_render_enclosure($entry, $hide_images);
- if ($entry['title']) {
- $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
- }
+
+ if ($retval) {
+ $rv .= $retval;
+ } else {
+
+ if (preg_match("/image/", $entry["type"]) ||
+ preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
+
+ if (!$hide_images) {
+ $encsize = '';
+ if ($entry['height'] > 0)
+ $encsize .= ' height="' . intval($entry['width']) . '"';
+ if ($entry['width'] > 0)
+ $encsize .= ' width="' . intval($entry['height']) . '"';
+ $rv .= "<p><img
+ alt=\"".htmlspecialchars($entry["filename"])."\"
+ src=\"" .htmlspecialchars($entry["url"]) . "\"
+ " . $encsize . " /></p>";
+ } else {
+ $rv .= "<p><a target=\"_blank\"
+ href=\"".htmlspecialchars($entry["url"])."\"
+ >" .htmlspecialchars($entry["url"]) . "</a></p>";
+ }
+
+ if ($entry['title']) {
+ $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
+ }
+ }
}
}
}
@@ -2442,4 +2461,14 @@
return false;
}
+
+ function error_json($code) {
+ require_once "errors.php";
+
+ @$message = $ERRORS[$code];
+
+ return json_encode(array("error" =>
+ array("code" => $code, "message" => $message)));
+
+ }
?>
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index 4cd0f6888..a27a91747 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -671,9 +671,11 @@
if (db_num_rows($result) != 0) {
$base_entry_id = db_fetch_result($result, 0, "id");
$entry_stored_hash = db_fetch_result($result, 0, "content_hash");
+ $article_labels = get_article_labels($base_entry_id, $owner_uid);
} else {
$base_entry_id = false;
$entry_stored_hash = "";
+ $article_labels = array();
}
$article = array("owner_uid" => $owner_uid, // read only
@@ -681,8 +683,10 @@
"title" => $entry_title,
"content" => $entry_content,
"link" => $entry_link,
+ "labels" => $article_labels, // current limitation: can add labels to article, can't remove them
"tags" => $entry_tags,
"author" => $entry_author,
+ "force_catchup" => false, // ugly hack for the time being
"language" => $entry_language, // read only
"feed" => array("id" => $feed,
"fetch_url" => $fetch_url,
@@ -737,6 +741,15 @@
$entry_author = db_escape_string($article["author"]);
$entry_link = db_escape_string($article["link"]);
$entry_content = $article["content"]; // escaped below
+ $entry_force_catchup = $article["force_catchup"];
+ $article_labels = $article["labels"];
+
+ if ($debug_enabled) {
+ _debug("article labels:", $debug_enabled);
+ print_r($article_labels);
+ }
+
+ _debug("force catchup: $entry_force_catchup");
if ($cache_images && is_writable(CACHE_DIR . '/images'))
cache_images($entry_content, $site_url, $debug_enabled);
@@ -786,12 +799,8 @@
'$entry_language',
'$entry_author')");
- $article_labels = array();
-
} else {
$base_entry_id = db_fetch_result($result, 0, "id");
-
- $article_labels = get_article_labels($base_entry_id, $owner_uid);
}
// now it should exist, if not - bad luck then
@@ -861,7 +870,7 @@
_debug("user record not found, creating...", $debug_enabled);
- if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) {
+ if ($score >= -500 && !find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
$unread = 'true';
$last_read_qpart = 'NULL';
} else {
@@ -883,7 +892,7 @@
// N-grams
- if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
+ /* if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
$result = db_query("SELECT COUNT(*) AS similar FROM
ttrss_entries,ttrss_user_entries
@@ -898,7 +907,7 @@
if ($ngram_similar > 0) {
$unread = 'false';
}
- }
+ } */
$last_marked = ($marked == 'true') ? 'NOW()' : 'NULL';
$last_published = ($published == 'true') ? 'NOW()' : 'NULL';
@@ -958,7 +967,13 @@
db_query("COMMIT");
- _debug("assigning labels...", $debug_enabled);
+ _debug("assigning labels [other]...", $debug_enabled);
+
+ foreach ($article_labels as $label) {
+ label_add_article($entry_ref_id, $label[1], $owner_uid);
+ }
+
+ _debug("assigning labels [filters]...", $debug_enabled);
assign_article_to_label_filters($entry_ref_id, $article_filters,
$owner_uid, $article_labels);
@@ -1087,20 +1102,6 @@
db_query("COMMIT");
}
- if (get_pref("AUTO_ASSIGN_LABELS", $owner_uid, false)) {
- _debug("auto-assigning labels...", $debug_enabled);
-
- foreach ($labels as $label) {
- $caption = preg_quote($label["caption"]);
-
- if ($caption && preg_match("/\b$caption\b/i", "$tags_str " . strip_tags($entry_content) . " $entry_title")) {
- if (!labels_contains_caption($article_labels, $caption)) {
- label_add_article($entry_ref_id, $caption, $owner_uid);
- }
- }
- }
- }
-
_debug("article processed", $debug_enabled);
}
@@ -1165,16 +1166,8 @@
file_put_contents($local_filename, $file_content);
}
}
-
- /* if (file_exists($local_filename)) {
- $entry->setAttribute('src', SELF_URL_PATH . '/image.php?url=' .
- base64_encode($src));
- } */
}
}
-
- //$node = $doc->getElementsByTagName('body')->item(0);
- //return $doc->saveXML($node);
}
function expire_error_log($debug) {
@@ -1400,6 +1393,24 @@
return $error;
} */
+ function cleanup_counters_cache($debug) {
+ $result = db_query("DELETE FROM ttrss_counters_cache
+ WHERE feed_id > 0 AND
+ (SELECT COUNT(id) FROM ttrss_feeds WHERE
+ id = feed_id AND
+ ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid) = 0");
+ $frows = db_affected_rows($result);
+
+ $result = db_query("DELETE FROM ttrss_cat_counters_cache
+ WHERE feed_id > 0 AND
+ (SELECT COUNT(id) FROM ttrss_feed_categories WHERE
+ id = feed_id AND
+ ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid) = 0");
+ $crows = db_affected_rows($result);
+
+ _debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries.");
+ }
+
function housekeeping_common($debug) {
expire_cached_files($debug);
expire_lock_files($debug);
@@ -1409,6 +1420,7 @@
_debug("Feedbrowser updated, $count feeds processed.");
purge_orphans( true);
+ cleanup_counters_cache($debug);
$rc = cleanup_tags( 14, 50000);
_debug("Cleaned $rc cached tags.");
diff --git a/include/sanity_config.php b/include/sanity_config.php
index 76fba4b81..6120e5fe0 100644
--- a/include/sanity_config.php
+++ b/include/sanity_config.php
@@ -1,3 +1,3 @@
-<?php # This file has been generated at: Fri Sep 27 13:42:37 MSK 2013
+<?php # This file has been generated at: Tue Feb 3 14:45:46 MSK 2015
define('GENERATED_CONFIG_CHECK', 26);
-$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'SMTP_SECURE', 'CHECK_FOR_NEW_VERSION', 'DETECT_ARTICLE_LANGUAGE', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION'); ?>
+$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_SERVER', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'SMTP_SECURE', 'CHECK_FOR_UPDATES', 'DETECT_ARTICLE_LANGUAGE', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION'); ?>
diff --git a/include/sessions.php b/include/sessions.php
index 66214afe7..30d502641 100644
--- a/include/sessions.php
+++ b/include/sessions.php
@@ -39,7 +39,7 @@
function validate_session() {
if (SINGLE_USER_MODE) return true;
- if (VERSION_STATIC != $_SESSION["version"]) return false;
+ //if (VERSION_STATIC != $_SESSION["version"]) return false;
$check_ip = $_SESSION['ip_address'];
@@ -62,17 +62,17 @@
return false;
}
- if ($_SESSION["ref_schema_version"] != session_get_schema_version(true)) {
+ if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version(true)) {
$_SESSION["login_error_msg"] =
__("Session failed to validate (schema version changed)");
return false;
}
- if (sha1($_SERVER['HTTP_USER_AGENT']) != $_SESSION["user_agent"]) {
+ /* if (sha1($_SERVER['HTTP_USER_AGENT']) != $_SESSION["user_agent"]) {
$_SESSION["login_error_msg"] =
__("Session failed to validate (user agent changed)");
return false;
- }
+ } */
if ($_SESSION["uid"]) {
$result = Db::get()->query(
diff --git a/include/version.php b/include/version.php
index a7ca8a32b..34c11e6e7 100644
--- a/include/version.php
+++ b/include/version.php
@@ -8,6 +8,10 @@
if (is_dir("$root_dir/.git") && file_exists("$root_dir/.git/refs/heads/master")) {
$suffix = substr(trim(file_get_contents("$root_dir/.git/refs/heads/master")), 0, 7);
+ $timestamp = filemtime("$root_dir/.git/refs/heads/master");
+
+ define("GIT_VERSION_HEAD", $suffix);
+ define("GIT_VERSION_TIMESTAMP", $timestamp);
return VERSION_STATIC . ".$suffix";
} else {