X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Ffunctions.php;h=556b8a8cdf0c3c99de569c744dca99fd6e8fa62d;hb=3b96b0ed7cf8d960dd3ec2208ad8addb584bc1c9;hp=4272c649d8a131f4a2b15d39e41febc870f653a9;hpb=6bfc97da869ca180d2f5fee01c9ff503cb47b1bd;p=tt-rss.git diff --git a/include/functions.php b/include/functions.php index 4272c649..556b8a8c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,10 +1,12 @@ = 120) { + $pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"]); + + if ($pref_lang && $pref_lang != 'auto') { + $lang = $pref_lang; + } } if ($lang) { @@ -113,8 +119,6 @@ } } - startup_gettext(); - require_once 'db-prefs.php'; require_once 'version.php'; require_once 'ccache.php'; @@ -313,7 +317,12 @@ $fetch_curl_used = true; if (ini_get("safe_mode") || ini_get("open_basedir")) { - $ch = curl_init(geturl($url)); + $new_url = geturl($url); + if (!$new_url) { + // geturl has already populated $fetch_last_error + return false; + } + $ch = curl_init($new_url); } else { $ch = curl_init($url); } @@ -793,12 +802,8 @@ $_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"]) { + startup_gettext(); load_user_plugins($_SESSION["uid"]); /* cleanup ccache */ @@ -872,7 +877,7 @@ $tz_offset = $user_tz->getOffset($dt); } else { - $tz_offset = (int) $_SESSION["clientTzOffset"]; + $tz_offset = (int) -$_SESSION["clientTzOffset"]; } $user_timestamp = $dt->format('U') + $tz_offset; @@ -961,27 +966,43 @@ } function file_is_locked($filename) { - if (function_exists('flock')) { - $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r"); - if ($fp) { - if (flock($fp, LOCK_EX | LOCK_NB)) { - flock($fp, LOCK_UN); + if (file_exists(LOCK_DIRECTORY . "/$filename")) { + if (function_exists('flock')) { + $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r"); + if ($fp) { + if (flock($fp, LOCK_EX | LOCK_NB)) { + flock($fp, LOCK_UN); + fclose($fp); + return false; + } fclose($fp); + return true; + } else { return false; } - fclose($fp); - return true; - } else { - return false; } + return true; // consider the file always locked and skip the test + } else { + return false; } - return true; // consider the file always locked and skip the test } + function make_lockfile($filename) { $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); if ($fp && flock($fp, LOCK_EX | LOCK_NB)) { + $stat_h = fstat($fp); + $stat_f = stat(LOCK_DIRECTORY . "/$filename"); + + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + if ($stat_h["ino"] != $stat_f["ino"] || + $stat_h["dev"] != $stat_f["dev"]) { + + return false; + } + } + if (function_exists('posix_getpid')) { fwrite($fp, posix_getpid() . "\n"); } @@ -1162,7 +1183,7 @@ $data = array_merge($data, getVirtCounters()); $data = array_merge($data, getLabelCounters()); - $data = array_merge($data, getFeedCounters($active_feed)); + $data = array_merge($data, getFeedCounters()); $data = array_merge($data, getCategoryCounters()); return $data; @@ -1286,7 +1307,7 @@ return $unread; } else if ($cat == -1) { - return getFeedUnread(-1) + getFeedUnread($link, -2) + getFeedUnread($link, -3) + getFeedUnread($link, 0); + return getFeedUnread(-1) + getFeedUnread(-2) + getFeedUnread(-3) + getFeedUnread(0); } else if ($cat == -2) { $result = db_query(" @@ -1459,8 +1480,14 @@ $count = getFeedUnread($i); + if ($i == 0 || $i == -1 || $i == -2) + $auxctr = getFeedArticles($i, false); + else + $auxctr = 0; + $cv = array("id" => $i, - "counter" => (int) $count); + "counter" => (int) $count, + "auxcounter" => $auxctr); // if (get_pref('EXTENDED_FEEDLIST')) // $cv["xmsg"] = getFeedArticles($i)." ".__("total"); @@ -1487,11 +1514,13 @@ $owner_uid = $_SESSION["uid"]; - $result = db_query("SELECT id,caption,COUNT(unread) AS unread + $result = db_query("SELECT id,caption,COUNT(u1.unread) AS unread,COUNT(u2.unread) AS total FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON (ttrss_labels2.id = label_id) - LEFT JOIN ttrss_user_entries ON (ref_id = article_id AND unread = true - AND ttrss_user_entries.owner_uid = $owner_uid) + LEFT JOIN ttrss_user_entries AS u1 ON (u1.ref_id = article_id AND u1.unread = true + AND u1.owner_uid = $owner_uid) + LEFT JOIN ttrss_user_entries AS u2 ON (u2.ref_id = article_id AND u2.unread = false + AND u2.owner_uid = $owner_uid) WHERE ttrss_labels2.owner_uid = $owner_uid GROUP BY ttrss_labels2.id, ttrss_labels2.caption"); @@ -1499,17 +1528,12 @@ $id = label_to_feed_id($line["id"]); - $label_name = $line["caption"]; - $count = $line["unread"]; - $cv = array("id" => $id, - "counter" => (int) $count); + "counter" => (int) $line["unread"], + "auxcounter" => (int) $line["total"]); if ($descriptions) - $cv["description"] = $label_name; - -// if (get_pref('EXTENDED_FEEDLIST')) -// $cv["xmsg"] = getFeedArticles($id)." ".__("total"); + $cv["description"] = $line["caption"]; array_push($ret_arr, $cv); } @@ -1726,7 +1750,8 @@ } if (!$root_id) { - $is_selected = ($default_id == "CAT:0") ? "selected=\"1\"" : ""; + $default_is_cat = ($default_id == "CAT:0"); + $is_selected = $default_is_cat ? "selected=\"1\"" : ""; printf("", __("Uncategorized")); @@ -1941,7 +1966,6 @@ $params["max_feed_id"] = (int) $max_feed_id; $params["num_feeds"] = (int) $num_feeds; - $params["collapsed_feedlist"] = (int) get_pref("_COLLAPSED_FEEDLIST"); $params["hotkeys"] = get_hotkeys_map(); $params["csrf_token"] = $_SESSION["csrf_token"]; @@ -2327,8 +2351,10 @@ $filter_query_part = filter_to_sql($filter, $owner_uid); // Try to check if SQL regexp implementation chokes on a valid regexp + + $result = db_query("SELECT true AS true_val FROM ttrss_entries, - ttrss_user_entries, ttrss_feeds, ttrss_feed_categories + ttrss_user_entries, ttrss_feeds WHERE $filter_query_part LIMIT 1", false); if ($result) { @@ -2552,7 +2578,9 @@ } } - $content_query_part = "content as content_preview, cached_content, "; + + $content_query_part = "content, content AS content_preview, cached_content, "; + if (is_numeric($feed)) { @@ -2844,8 +2872,7 @@ if ($version_data) { $version_data = json_decode($version_data, true); if ($version_data && $version_data['version']) { - - if (version_compare(VERSION, $version_data['version']) == -1) { + if (version_compare(VERSION_STATIC, $version_data['version']) == -1) { return $version_data; } } @@ -2902,7 +2929,6 @@ ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name"; - $obj_id = md5("TAGS:$owner_uid:$id"); $tags = array(); /* check cache first */ @@ -3012,7 +3038,7 @@ if ($_SESSION["hasAudio"] && (strpos($ctype, "ogg") !== false || $_SESSION["hasMp3"])) { - $entry .= "