X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=functions.php;h=9bd98795b646009b0126868ee3efd06ecf7218ab;hb=02008cb19ac99727889cca05c7eddfbeef30d684;hp=ab03832b0cb94d3b2d9b3b5e1991885fad07233c;hpb=163a295e514cceffa8bcb6d027e3458127f0a779;p=tt-rss.git diff --git a/functions.php b/functions.php index ab03832b..9bd98795 100644 --- a/functions.php +++ b/functions.php @@ -13,6 +13,7 @@ "auto" => "Detect automatically", "en_US" => "English", "fr_FR" => "Français", + "nb_NO" => "Norsk Bokmål", "ru_RU" => "Русский", "pt_BR" => "Portuguese/Brazil", "zh_CN" => "Simplified Chinese"); @@ -81,8 +82,26 @@ function purge_feed($link, $feed_id, $purge_interval, $debug = false) { + if (!$purge_interval) $purge_interval = feed_purge_interval($link, $feed_id); + $rows = -1; + $result = db_query($link, + "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); + + $owner_uid = false; + + if (db_num_rows($result) == 1) { + $owner_uid = db_fetch_result($result, 0, "owner_uid"); + } + + if (!$owner_uid) return; + + $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES", + $owner_uid, false); + + if (!$purge_unread) $query_limit = " unread = false AND "; + if (DB_TYPE == "pgsql") { /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE marked = false AND feed_id = '$feed_id' AND @@ -97,6 +116,7 @@ ttrss_entries.id = ref_id AND marked = false AND feed_id = '$feed_id' AND + $query_limit ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); } else { @@ -106,6 +126,7 @@ WHERE ttrss_entries.id = ref_id AND marked = false AND feed_id = '$feed_id' AND + $query_limit ttrss_entries.date_entered < NOW() - INTERVAL '$purge_interval days'"); } @@ -123,6 +144,7 @@ WHERE ttrss_entries.id = ref_id AND marked = false AND feed_id = '$feed_id' AND + $query_limit ttrss_entries.date_entered < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); $rows = mysql_affected_rows($link); @@ -185,6 +207,25 @@ } + function feed_purge_interval($link, $feed_id) { + + $result = db_query($link, "SELECT purge_interval, owner_uid FROM ttrss_feeds + WHERE id = '$feed_id'"); + + if (db_num_rows($result) == 1) { + $purge_interval = db_fetch_result($result, 0, "purge_interval"); + $owner_uid = db_fetch_result($result, 0, "owner_uid"); + + if ($purge_interval == 0) $purge_interval = get_pref($link, + 'PURGE_OLD_DAYS', $user_id); + + return $purge_interval; + + } else { + return -1; + } + } + function purge_old_posts($link) { $user_id = $_SESSION["uid"]; @@ -427,16 +468,26 @@ _debug("update_rss_feed: start"); } - $result = db_query($link, "SELECT id,update_interval,auth_login,auth_pass,cache_images - FROM ttrss_feeds WHERE id = '$feed'"); + if (DB_TYPE == "pgsql") { + $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started >= NOW() - INTERVAL '120 seconds')"; + } else { + $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started >= DATE_SUB(NOW(), INTERVAL 120 SECOND))"; + } + + $result = db_query($link, "SELECT id,update_interval,auth_login, + auth_pass,cache_images + FROM ttrss_feeds WHERE id = '$feed' AND $updstart_thresh_qpart"); if (db_num_rows($result) == 0) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { - _debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND"); + _debug("update_rss_feed: feed $feed [$feed_url] NOT FOUND/SKIPPED"); } return; } + db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW() + WHERE id = '$feed'"); + $auth_login = db_fetch_result($result, 0, "auth_login"); $auth_pass = db_fetch_result($result, 0, "auth_pass"); @@ -653,6 +704,11 @@ foreach ($iterator as $item) { + if ($_GET['xdebug']) { + print_r($item); + + } + if (ENABLE_SIMPLEPIE) { $entry_guid = $item->get_id(); if (!$entry_guid) $entry_guid = $item->get_link(); @@ -730,6 +786,10 @@ if (!$entry_content) $entry_content = $item["content:encoded"]; if (!$entry_content) $entry_content = $item["content"]; + + // Magpie bugs are getting ridiculous + if (trim($entry_content) == "Array") $entry_content = false; + if (!$entry_content) $entry_content = $item["atom_content"]; if (!$entry_content) $entry_content = $item["summary"]; if (!$entry_content) $entry_content = $item["description"]; @@ -738,12 +798,13 @@ if (is_array($entry_content)) { $entry_content = $entry_content["encoded"]; if (!$entry_content) $entry_content = $entry_content["escaped"]; - } + } } -// print_r($item); -// print_r(htmlspecialchars($entry_content)); -// print "
"; + if ($_GET["xdebug"]) { + print "update_rss_feed: content: "; + print_r(htmlspecialchars($entry_content)); + } $entry_content_unescaped = $entry_content; @@ -780,6 +841,7 @@ if (preg_match('/^[\t\n\r ]*$/', $entry_author)) $entry_author = ''; $entry_guid = db_escape_string(strip_tags($entry_guid)); + $entry_guid = mb_substr($entry_guid, 0, 250); $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$entry_guid'"); @@ -807,7 +869,7 @@ $additional_tags = array(); $additional_tags_src = $item->get_categories(); - + if (is_array($additional_tags_src)) { foreach ($additional_tags_src as $tobj) { array_push($additional_tags, $tobj->get_term()); @@ -827,14 +889,21 @@ if ($t_ctr == 0) { $additional_tags = false; - } else if ($t_ctr == 1) { + } else if ($t_ctr > 0) { $additional_tags = array($item['category']); - } else { - $additional_tags = array(); + + if ($item['category@term']) { + array_push($additional_tags, $item['category@term']); + } + for ($i = 0; $i <= $t_ctr; $i++ ) { if ($item["category#$i"]) { array_push($additional_tags, $item["category#$i"]); } + + if ($item["category#$i@term"]) { + array_push($additional_tags, $item["category#$i@term"]); + } } } @@ -842,10 +911,9 @@ $t_ctr = $item['dc']['subject#']; - if ($t_ctr == 1) { + if ($t_ctr > 0) { $additional_tags = array($item['dc']['subject']); - } else if ($t_ctr > 1) { - $additional_tags = array(); + for ($i = 0; $i <= $t_ctr; $i++ ) { if ($item['dc']["subject#$i"]) { array_push($additional_tags, $item['dc']["subject#$i"]); @@ -854,6 +922,45 @@ } } + // enclosures + + $enclosures = array(); + + if (ENABLE_SIMPLEPIE) { + $encs = $item->get_enclosures(); + + if (is_array($encs)) { + foreach ($encs as $e) { + $e_item = array( + $e->link, $e->type, $e->length); + + array_push($enclosures, $e_item); + } + } + + } else { + $e_ctr = $item['enclosure#']; + + if ($e_ctr > 0) { + $e_item = array($item['enclosure@url'], + $item['enclosure@type'], + $item['enclosure@length']); + + array_push($enclosures, $e_item); + + for ($i = 0; $i <= $e_ctr; $i++ ) { + + if ($item["enclosure#$i@url"]) { + $e_item = array($item["enclosure#$i@url"], + $item["enclosure#$i@type"], + $item["enclosure#$i@length"]); + array_push($enclosures, $e_item); + } + } + } + + } + # sanitize content // $entry_content = sanitize_rss($entry_content); @@ -920,6 +1027,9 @@ ttrss_entries WHERE guid = '$entry_guid'"); + $entry_ref_id = 0; + $entry_int_id = 0; + if (db_num_rows($result) == 1) { if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { @@ -934,6 +1044,7 @@ 0, "date_entered")); $ref_id = db_fetch_result($result, 0, "id"); + $entry_ref_id = $ref_id; // check for user post link to main table @@ -963,7 +1074,7 @@ // error_reporting (DEFAULT_ERROR_LEVEL); $result = db_query($link, - "SELECT ref_id FROM ttrss_user_entries WHERE + "SELECT ref_id, int_id FROM ttrss_user_entries WHERE ref_id = '$ref_id' AND owner_uid = '$owner_uid' $dupcheck_qpart"); @@ -999,8 +1110,24 @@ (ref_id, owner_uid, feed_id, unread, last_read, marked, published) VALUES ('$ref_id', '$owner_uid', '$feed', $unread, $last_read_qpart, $marked, $published)"); + + $result = db_query($link, + "SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND + feed_id = '$feed' LIMIT 1"); + + if (db_num_rows($result) == 1) { + $entry_int_id = db_fetch_result($result, 0, "int_id"); + } + } else { + $entry_ref_id = db_fetch_result($result, 0, "ref_id"); + $entry_int_id = db_fetch_result($result, 0, "int_id"); } - + + if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + _debug("update_rss_feed: RID: $entry_ref_id, IID: $entry_int_id"); + } + $post_needs_update = false; if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && @@ -1052,6 +1179,33 @@ db_query($link, "COMMIT"); + if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + _debug("update_rss_feed: looking for enclosures..."); + } + + if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { + print_r($enclosures); + } + + db_query($link, "BEGIN"); + + foreach ($enclosures as $enc) { + $enc_url = db_escape_string($enc[0]); + $enc_type = db_escape_string($enc[1]); + $enc_dur = db_escape_string($enc[2]); + + $result = db_query($link, "SELECT id FROM ttrss_enclosures + WHERE content_url = '$enc_url' AND post_id = '$entry_ref_id'"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_enclosures + (content_url, content_type, title, duration, post_id) VALUES + ('$enc_url', '$enc_type', '', '$enc_dur', '$entry_ref_id')"); + } + } + + db_query($link, "COMMIT"); + if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) { _debug("update_rss_feed: looking for tags..."); } @@ -1107,17 +1261,6 @@ db_query($link, "BEGIN"); - $result = db_query($link, "SELECT id,int_id - FROM ttrss_entries,ttrss_user_entries - WHERE guid = '$entry_guid' - AND feed_id = '$feed' AND ref_id = id - AND owner_uid = '$owner_uid'"); - - if (db_num_rows($result) == 1) { - - $entry_id = db_fetch_result($result, 0, "id"); - $entry_int_id = db_fetch_result($result, 0, "int_id"); - foreach ($entry_tags as $tag) { $tag = sanitize_tag($tag); @@ -1138,7 +1281,7 @@ VALUES ('$owner_uid','$tag', '$entry_int_id')"); } } - } + db_query($link, "COMMIT"); } @@ -1431,10 +1574,15 @@ $pwd_hash1 = encrypt_password($password); $pwd_hash2 = encrypt_password($password, $login); - if ($force_auth && defined('_DEBUG_USER_SWITCH')) { + if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH + && $_SERVER["REMOTE_USER"]) { + + $login = db_escape_string($_SERVER["REMOTE_USER"]); + $query = "SELECT id,login,access_level FROM ttrss_users WHERE - login = '$login'"; + login = '$login'"; + } else { $query = "SELECT id,login,access_level,pwd_hash FROM ttrss_users WHERE @@ -1511,7 +1659,7 @@ db_query($link, "insert into ttrss_labels (owner_uid,sql_exp,description) values ('$uid','last_read is null and unread = false', 'Updated articles')"); - + db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url) values ('$uid', 'Tiny Tiny RSS: New Releases', 'http://tt-rss.spb.ru/releases.rss')"); @@ -1627,7 +1775,7 @@ function truncate_string($str, $max_len) { if (mb_strlen($str, "utf-8") > $max_len - 3) { - return mb_substr($str, 0, $max_len, "utf-8") . "..."; + return mb_substr($str, 0, $max_len, "utf-8") . "…"; } else { return $str; } @@ -1721,7 +1869,7 @@ function file_is_locked($filename) { if (function_exists('flock')) { error_reporting(0); - $fp = fopen($filename, "r"); + $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); error_reporting(DEFAULT_ERROR_LEVEL); if ($fp) { if (flock($fp, LOCK_EX | LOCK_NB)) { @@ -1737,7 +1885,7 @@ } function make_lockfile($filename) { - $fp = fopen($filename, "w"); + $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); if (flock($fp, LOCK_EX | LOCK_NB)) { return $fp; @@ -1747,7 +1895,7 @@ } function make_stampfile($filename) { - $fp = fopen($filename, "w"); + $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); if (flock($fp, LOCK_EX | LOCK_NB)) { fwrite($fp, time() . "\n"); @@ -1762,7 +1910,7 @@ function read_stampfile($filename) { error_reporting(0); - $fp = fopen($filename, "r"); + $fp = fopen(LOCK_DIRECTORY . "/$filename", "r"); error_reporting (DEFAULT_ERROR_LEVEL); if (flock($fp, LOCK_EX)) { @@ -2664,6 +2812,7 @@ } } + print ""; print ""; print ""; print ""; @@ -2702,11 +2851,15 @@ print ""; + print ""; + print ""; } function print_runtime_info($link) { print ""; + if (ENABLE_UPDATE_DAEMON) { print ""; @@ -3002,6 +3155,8 @@ if ($feed < -10) error_reporting (0); + $content_query_part = "content as content_preview,"; + if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { if ($feed >= 0) { @@ -3010,8 +3165,6 @@ $feed_kind = "Labels"; } - $content_query_part = "content as content_preview,"; - if ($limit_query_part) { $offset_query_part = "OFFSET $offset"; } @@ -3591,7 +3744,7 @@
  • ".__('Published')."
  •  
  • -
  • ".__('Mark as read')."