X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=functions.php;h=3f1d72f97a4a89fe0c64030dd8cbfad562841409;hb=009646d23a166ed1bbb56d75aa27d5fcc719b5ce;hp=27efb2c48b20d1486f571090c62e08f72810f0dd;hpb=8353bd26f26723876c7cdbeb95b80535e4fc6a67;p=tt-rss.git diff --git a/functions.php b/functions.php index 27efb2c4..3f1d72f9 100644 --- a/functions.php +++ b/functions.php @@ -19,13 +19,13 @@ /** * Return available translations names. - * + * * @access public * @return array A array of available translations. */ function get_translations() { $tr = array( - "auto" => "Detect automatically", + "auto" => "Detect automatically", "ca_CA" => "Català", "en_US" => "English", "es_ES" => "Español", @@ -47,7 +47,7 @@ require_once "lib/gettext/gettext.inc"; function startup_gettext() { - + # Get locale from Accept-Language header $lang = al2gt(array_keys(get_translations()), "text/html"); @@ -55,7 +55,7 @@ $lang = _TRANSLATION_OVERRIDE_DEFAULT; } - if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") { + if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") { $lang = $_COOKIE["ttrss_lang"]; } @@ -103,13 +103,12 @@ } require_once 'db-prefs.php'; - require_once 'compat.php'; require_once 'errors.php'; require_once 'version.php'; require_once 'lib/phpmailer/class.phpmailer.php'; require_once 'lib/sphinxapi.php'; - require_once 'lib/twitteroauth/twitteroauth.php'; + require_once 'lib/tmhoauth/tmhOAuth.php'; //define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); @@ -127,14 +126,14 @@ $config = HTMLPurifier_Config::createDefault(); - $allowed = "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4"; + $allowed = "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4,s"; $config->set('HTML', 'Allowed', $allowed); $purifier = new HTMLPurifier($config); /** * Print a timestamped debug message. - * + * * @param string $msg The debug message. * @return void */ @@ -148,7 +147,7 @@ /** * Purge a feed old posts. - * + * * @param mixed $link A database connection. * @param mixed $feed_id The id of the purged feed. * @param mixed $purge_interval Olderness of purged posts. @@ -159,10 +158,10 @@ 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, + $result = db_query($link, "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); $owner_uid = false; @@ -200,41 +199,41 @@ if (preg_match("/^7\./", $pg_version) || preg_match("/^8\.0/", $pg_version)) { - $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE - ttrss_entries.id = ref_id AND - marked = false AND - feed_id = '$feed_id' AND + $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE + ttrss_entries.id = ref_id AND + marked = false AND + feed_id = '$feed_id' AND $query_limit ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); } else { - $result = db_query($link, "DELETE FROM ttrss_user_entries - USING ttrss_entries - WHERE ttrss_entries.id = ref_id AND - marked = false AND - feed_id = '$feed_id' AND + $result = db_query($link, "DELETE FROM ttrss_user_entries + USING ttrss_entries + WHERE ttrss_entries.id = ref_id AND + marked = false AND + feed_id = '$feed_id' AND $query_limit ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); } $rows = pg_affected_rows($result); - + } else { - + /* $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE marked = false AND feed_id = '$feed_id' AND - (SELECT date_updated FROM ttrss_entries WHERE + (SELECT date_updated FROM ttrss_entries WHERE id = ref_id) < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); */ - $result = db_query($link, "DELETE FROM ttrss_user_entries - USING ttrss_user_entries, ttrss_entries - WHERE ttrss_entries.id = ref_id AND - marked = false AND - feed_id = '$feed_id' AND + $result = db_query($link, "DELETE FROM ttrss_user_entries + USING ttrss_user_entries, ttrss_entries + WHERE ttrss_entries.id = ref_id AND + marked = false AND + feed_id = '$feed_id' AND $query_limit ttrss_entries.date_updated < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); - + $rows = mysql_affected_rows($link); } @@ -248,7 +247,7 @@ /** * Purge old posts from old feeds. Not used anymore, purging is done after feed update. - * + * * @param mixed $link A database connection * @param boolean $do_output Set to true to enable printed output, false by default. * @param integer $limit The maximal number of removed posts. @@ -264,9 +263,9 @@ } else { $limit_qpart = ""; } - - $result = db_query($link, - "SELECT id,purge_interval,owner_uid FROM ttrss_feeds + + $result = db_query($link, + "SELECT id,purge_interval,owner_uid FROM ttrss_feeds ORDER BY $random_qpart $limit_qpart"); while ($line = db_fetch_assoc($result)) { @@ -276,12 +275,12 @@ $owner_uid = $line["owner_uid"]; if ($purge_interval == 0) { - - $tmp_result = db_query($link, + + $tmp_result = db_query($link, "SELECT value FROM ttrss_user_prefs WHERE pref_name = 'PURGE_OLD_DAYS' AND owner_uid = '$owner_uid'"); - if (db_num_rows($tmp_result) != 0) { + if (db_num_rows($tmp_result) != 0) { $purge_interval = db_fetch_result($tmp_result, 0, "value"); } } @@ -293,7 +292,7 @@ if ($purge_interval > 0 || FORCE_ARTICLE_PURGE) { purge_feed($link, $feed_id, $purge_interval, $do_output); } - } + } purge_orphans($link, $do_output); @@ -301,14 +300,14 @@ function feed_purge_interval($link, $feed_id) { - $result = db_query($link, "SELECT purge_interval, owner_uid FROM ttrss_feeds + $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, + if ($purge_interval == 0) $purge_interval = get_pref($link, 'PURGE_OLD_DAYS', $owner_uid); return $purge_interval; @@ -321,8 +320,8 @@ function purge_old_posts($link) { $user_id = $_SESSION["uid"]; - - $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds + + $result = db_query($link, "SELECT id,purge_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'"); while ($line = db_fetch_assoc($result)) { @@ -335,7 +334,7 @@ if ($purge_interval > 0) { purge_feed($link, $feed_id, $purge_interval); } - } + } purge_orphans($link); } @@ -343,7 +342,7 @@ function purge_orphans($link, $do_output = false) { // purge orphaned posts in main content table - $result = db_query($link, "DELETE FROM ttrss_entries WHERE + $result = db_query($link, "DELETE FROM ttrss_entries WHERE (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); if ($do_output) { @@ -371,8 +370,11 @@ } } - function fetch_file_contents($url, $type = false) { - if (USE_CURL_FOR_ICONS) { + function fetch_file_contents($url, $type = false, $login = false, $pass = false) { + $login = urlencode($login); + $pass = urlencode($pass); + + if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); @@ -381,6 +383,11 @@ curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($fp, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + + if ($login && $pass) + curl_setopt($ch, CURLOPT_USERPWD, "$login:$pass"); $contents = @curl_exec($ch); if ($contents === false) { @@ -388,15 +395,26 @@ return false; } + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); - if ($type && strpos($content_type, "$type") === false) { + if ($http_code != 200 || $type && strpos($content_type, "$type") === false) { return false; } return $contents; } else { + if ($login && $pass && $updated != 3) { + $url_parts = array(); + + preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts); + + if ($url_parts[1] && $url_parts[2]) { + $url = $url_parts[1] . "://$login:$pass@" . $url_parts[2]; + } + } + return @file_get_contents($url); } @@ -406,7 +424,7 @@ * Try to determine the favicon URL for a feed. * adapted from wordpress favicon plugin by Jeff Minard (http://thecodepro.com/) * http://dev.wp-plugins.org/file/favatars/trunk/favatars.php - * + * * @param string $url A feed or page URL * @access public * @return mixed The favicon URL, or false if none was found. @@ -429,68 +447,15 @@ $favicon_url = rewrite_relative_url($url, $entry->getAttribute("href")); break; } - } + } } if (!$favicon_url) $favicon_url = rewrite_relative_url($url, "/favicon.ico"); - // Run a test to see if what we have attempted to get actually exists. - if(USE_CURL_FOR_ICONS || url_validate($favicon_url)) { - return $favicon_url; - } else { - return false; - } + return $favicon_url; } // function get_favicon_url - /** - * Check if a link is a valid and working URL. - * - * @param mixed $link A URL to check - * @access public - * @return boolean True if the URL is valid, false otherwise. - */ - function url_validate($link) { - - $url_parts = @parse_url($link); - - if ( empty( $url_parts["host"] ) ) - return false; - - if ( !empty( $url_parts["path"] ) ) { - $documentpath = $url_parts["path"]; - } else { - $documentpath = "/"; - } - - if ( !empty( $url_parts["query"] ) ) - $documentpath .= "?" . $url_parts["query"]; - - $host = $url_parts["host"]; - $port = $url_parts["port"]; - - if ( empty($port) ) - $port = "80"; - - $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); - - if ( !$socket ) - return false; - - fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); - - $http_response = fgets( $socket, 22 ); - - $responses = "/(200 OK)|(30[123])/"; - if ( preg_match($responses, $http_response) ) { - fclose($socket); - return true; - } else { - return false; - } - - } // function url_validate - function check_feed_favicon($site_url, $feed, $link) { $favicon_url = get_favicon_url($site_url); @@ -520,8 +485,8 @@ /* Update all feeds with the same URL to utilize memcache */ if ($memcache) { - $result = db_query($link, "SELECT f1.id - FROM ttrss_feeds AS f1, ttrss_feeds AS f2 + $result = db_query($link, "SELECT f1.id + FROM ttrss_feeds AS f1, ttrss_feeds AS f2 WHERE f2.feed_url = f1.feed_url AND f2.id = '$feed'"); while ($line = db_fetch_assoc($result)) { @@ -550,8 +515,8 @@ $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,update_method FROM ttrss_feeds WHERE id = '$feed' AND $updstart_thresh_qpart"); @@ -568,7 +533,7 @@ if (db_num_rows($result) == 0) { if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: feed $feed NOT FOUND/SKIPPED"); - } + } return false; } @@ -645,31 +610,32 @@ if (!is_dir(SIMPLEPIE_CACHE_DIR)) { mkdir(SIMPLEPIE_CACHE_DIR); } - + $rss = new SimplePie(); $rss->set_useragent(SELF_USER_AGENT); # $rss->set_timeout(10); $rss->set_feed_url($fetch_url); $rss->set_output_encoding('UTF-8'); - + if (SIMPLEPIE_CACHE_IMAGES && $cache_images) { + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("enabling image cache"); } - - $rss->set_image_handler('./image.php', 'i'); + + $rss->set_image_handler("image.php", 'i'); } - + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed)*60); } - + if (is_dir(SIMPLEPIE_CACHE_DIR)) { $rss->set_cache_location(SIMPLEPIE_CACHE_DIR); $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60); } - + $rss->init(); } @@ -730,8 +696,8 @@ if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: registering title: $feed_title"); } - - db_query($link, "UPDATE ttrss_feeds SET + + db_query($link, "UPDATE ttrss_feeds SET title = '$feed_title' WHERE id = '$feed'"); } @@ -741,7 +707,7 @@ } if ($site_url && $orig_site_url != db_escape_string($site_url)) { - db_query($link, "UPDATE ttrss_feeds SET + db_query($link, "UPDATE ttrss_feeds SET site_url = '$site_url' WHERE id = '$feed'"); } @@ -755,10 +721,8 @@ $icon_url = substr($icon_url, 0, 250); - if ($icon_url && $orig_icon_url != $icon_url) { - if (USE_CURL_FOR_ICONS || url_validate($icon_url)) { - db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); - } + if ($icon_url && $orig_icon_url != $icon_url) { + db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'"); } if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { @@ -767,6 +731,10 @@ $filters = load_filters($link, $feed, $owner_uid); + if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { + print_r($filters); + } + if ($use_simplepie) { $iterator = $rss->get_items(); } else { @@ -776,7 +744,7 @@ } if (!is_array($iterator)) { - /* db_query($link, "UPDATE ttrss_feeds + /* db_query($link, "UPDATE ttrss_feeds SET last_error = 'Parse error: can\'t find any articles.' WHERE id = '$feed'"); */ @@ -787,7 +755,7 @@ _debug("update_rss_feed: entry iterator is not an array, no articles?"); } - db_query($link, "UPDATE ttrss_feeds + db_query($link, "UPDATE ttrss_feeds SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); return; // no articles @@ -813,6 +781,7 @@ $entry_guid = $item["id"]; if (!$entry_guid) $entry_guid = $item["guid"]; + if (!$entry_guid) $entry_guid = $item["about"]; if (!$entry_guid) $entry_guid = $item["link"]; if (!$entry_guid) $entry_guid = make_guid_from_title($item["title"]); } @@ -890,7 +859,7 @@ if (!$entry_content) $entry_content = $item["atom_content"]; if (!$entry_content) $entry_content = $item["summary"]; - if (!$entry_content || + if (!$entry_content || strlen($entry_content) < strlen($item["description"])) { $entry_content = $item["description"]; }; @@ -899,7 +868,7 @@ if (is_array($entry_content)) { $entry_content = $entry_content["encoded"]; if (!$entry_content) $entry_content = $entry_content["escaped"]; - } + } } if ($_REQUEST["xdebug"] == 2) { @@ -920,22 +889,22 @@ } } else { $entry_comments = strip_tags($item["comments"]); - + $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); if ($item['author']) { - + if (is_array($item['author'])) { - + if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author']['name'])); } - + if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author']['email'])); } } - + if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author'])); } @@ -947,10 +916,10 @@ $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 + $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$entry_guid'"); - $entry_content = db_escape_string($entry_content); + $entry_content = db_escape_string($entry_content, false); $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); @@ -978,7 +947,7 @@ if ($use_simplepie) { $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()); @@ -1013,11 +982,11 @@ } } } - + // parse elements - + $t_ctr = $item['dc']['subject#']; - + if ($t_ctr > 0) { array_push($additional_tags, $item['dc']['subject']); @@ -1055,7 +1024,7 @@ } # sanitize content - + $entry_content = sanitize_article_content($entry_content); $entry_title = sanitize_article_content($entry_title); @@ -1074,7 +1043,7 @@ // base post entry does not exist, create it $result = db_query($link, - "INSERT INTO ttrss_entries + "INSERT INTO ttrss_entries (title, guid, link, @@ -1088,13 +1057,13 @@ num_comments, author) VALUES - ('$entry_title', - '$entry_guid', + ('$entry_title', + '$entry_guid', '$entry_link', - '$entry_timestamp_fmt', - '$entry_content', + '$entry_timestamp_fmt', + '$entry_content', '$content_hash', - $no_orig_date, + $no_orig_date, NOW(), NOW(), '$entry_comments', @@ -1114,13 +1083,13 @@ // now it should exist, if not - bad luck then - $result = db_query($link, "SELECT + $result = db_query($link, "SELECT id,content_hash,no_orig_date,title, ".SUBSTRING_FOR_DATE."(date_updated,1,19) as date_updated, ".SUBSTRING_FOR_DATE."(updated,1,19) as updated, num_comments - FROM - ttrss_entries + FROM + ttrss_entries WHERE guid = '$entry_guid'"); $entry_ref_id = 0; @@ -1136,7 +1105,7 @@ $orig_content_hash = db_fetch_result($result, 0, "content_hash"); $orig_title = db_fetch_result($result, 0, "title"); $orig_num_comments = db_fetch_result($result, 0, "num_comments"); - $orig_date_updated = strtotime(db_fetch_result($result, + $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated")); $ref_id = db_fetch_result($result, 0, "id"); @@ -1147,14 +1116,14 @@ // do we allow duplicate posts with same GUID in different feeds? if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { $dupcheck_qpart = "AND (feed_id = '$feed' OR feed_id IS NULL)"; - } else { + } else { $dupcheck_qpart = ""; } /* Collect article tags here so we could filter by them: */ - $article_filters = get_article_filters($filters, $entry_title, - $entry_content, $entry_link, $entry_timestamp, $entry_author, + $article_filters = get_article_filters($filters, $entry_title, + $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags); if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { @@ -1196,7 +1165,7 @@ } else { $unread = 'false'; $last_read_qpart = 'NOW()'; - } + } if (find_article_filter($article_filters, 'mark') || $score > 1000) { $marked = 'true'; @@ -1211,13 +1180,13 @@ } $result = db_query($link, - "INSERT INTO ttrss_user_entries - (ref_id, owner_uid, feed_id, unread, last_read, marked, - published, score, tag_cache, label_cache) + "INSERT INTO ttrss_user_entries + (ref_id, owner_uid, feed_id, unread, last_read, marked, + published, score, tag_cache, label_cache) VALUES ('$ref_id', '$owner_uid', '$feed', $unread, $last_read_qpart, $marked, $published, '$score', '', '')"); - $result = db_query($link, + $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"); @@ -1260,8 +1229,8 @@ // $post_needs_update = true; // } - // if post needs update, update it and mark all user entries - // linking to this post as updated + // if post needs update, update it and mark all user entries + // linking to this post as updated if ($post_needs_update) { if (defined('DAEMON_EXTENDED_DEBUG')) { @@ -1270,17 +1239,17 @@ // print ""; - db_query($link, "UPDATE ttrss_entries + db_query($link, "UPDATE ttrss_entries SET title = '$entry_title', content = '$entry_content', content_hash = '$content_hash', num_comments = '$num_comments' WHERE id = '$ref_id'"); if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) { - db_query($link, "UPDATE ttrss_user_entries + db_query($link, "UPDATE ttrss_user_entries SET last_read = null, unread = true WHERE ref_id = '$ref_id'"); } else { - db_query($link, "UPDATE ttrss_user_entries + db_query($link, "UPDATE ttrss_user_entries SET last_read = null WHERE ref_id = '$ref_id' AND unread = false"); } @@ -1311,7 +1280,7 @@ foreach ($encs as $e) { $e_item = array( $e->link, $e->type, $e->length); - + array_push($enclosures, $e_item); } } @@ -1406,7 +1375,7 @@ // Skip boring tags - $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, + $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); $filtered_tags = array(); @@ -1418,7 +1387,7 @@ array_push($filtered_tags, $tag); } } - } + } $filtered_tags = array_unique($filtered_tags); @@ -1430,23 +1399,23 @@ // Save article tags in the database if (count($filtered_tags) > 0) { - + db_query($link, "BEGIN"); - + foreach ($filtered_tags as $tag) { $tag = sanitize_tag($tag); $tag = db_escape_string($tag); if (!tag_is_valid($tag)) continue; - - $result = db_query($link, "SELECT id FROM ttrss_tags - WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND + + $result = db_query($link, "SELECT id FROM ttrss_tags + WHERE tag_name = '$tag' AND post_int_id = '$entry_int_id' AND owner_uid = '$owner_uid' LIMIT 1"); if ($result && db_num_rows($result) == 0) { - - db_query($link, "INSERT INTO ttrss_tags + + db_query($link, "INSERT INTO ttrss_tags (owner_uid,tag_name,post_int_id) VALUES ('$owner_uid','$tag', '$entry_int_id')"); } @@ -1455,22 +1424,22 @@ } /* update the cache */ - + $tags_to_cache = array_unique($tags_to_cache); - + $tags_str = db_escape_string(join(",", $tags_to_cache)); - db_query($link, "UPDATE ttrss_user_entries + db_query($link, "UPDATE ttrss_user_entries SET tag_cache = '$tags_str' WHERE ref_id = '$entry_ref_id' AND owner_uid = $owner_uid"); db_query($link, "COMMIT"); - } + } if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { _debug("update_rss_feed: article processed"); } - } + } if (!$last_updated) { if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) { @@ -1481,7 +1450,7 @@ purge_feed($link, $feed, 0); - db_query($link, "UPDATE ttrss_feeds + db_query($link, "UPDATE ttrss_feeds SET last_updated = NOW(), last_error = '' WHERE id = '$feed'"); // db_query($link, "COMMIT"); @@ -1500,8 +1469,8 @@ $error_msg = db_escape_string($error_msg); - db_query($link, - "UPDATE ttrss_feeds SET last_error = '$error_msg', + db_query($link, + "UPDATE ttrss_feeds SET last_error = '$error_msg', last_updated = NOW() WHERE id = '$feed'"); } @@ -1522,7 +1491,7 @@ $sel = "selected=\"1\""; else $sel = ""; - + print ""; } print ""; @@ -1535,7 +1504,7 @@ $sel = 'selected="selected"'; else $sel = ""; - + print ""; } @@ -1547,9 +1516,9 @@ if ($filters["title"]) { foreach ($filters["title"] as $filter) { - $reg_exp = $filter["reg_exp"]; - $inverse = $filter["inverse"]; - if ((!$inverse && @preg_match("/$reg_exp/i", $title)) || + $reg_exp = $filter["reg_exp"]; + $inverse = $filter["inverse"]; + if ((!$inverse && @preg_match("/$reg_exp/i", $title)) || ($inverse && !@preg_match("/$reg_exp/i", $title))) { array_push($matches, array($filter["action"], $filter["action_param"])); @@ -1562,17 +1531,17 @@ $reg_exp = $filter["reg_exp"]; $inverse = $filter["inverse"]; - if ((!$inverse && @preg_match("/$reg_exp/i", $content)) || + if ((!$inverse && @preg_match("/$reg_exp/i", $content)) || ($inverse && !@preg_match("/$reg_exp/i", $content))) { array_push($matches, array($filter["action"], $filter["action_param"])); - } + } } } if ($filters["both"]) { - foreach ($filters["both"] as $filter) { - $reg_exp = $filter["reg_exp"]; + foreach ($filters["both"] as $filter) { + $reg_exp = $filter["reg_exp"]; $inverse = $filter["inverse"]; if ($inverse) { @@ -1593,9 +1562,9 @@ $reg_exp = $filter["reg_exp"]; $inverse = $filter["inverse"]; - if ((!$inverse && @preg_match("/$reg_exp/i", $link)) || + if ((!$inverse && @preg_match("/$reg_exp/i", $link)) || ($inverse && !@preg_match("/$reg_exp/i", $link))) { - + array_push($matches, array($filter["action"], $filter["action_param"])); } } @@ -1625,13 +1594,13 @@ } } } - } + } if ($filters["author"]) { foreach ($filters["author"] as $filter) { - $reg_exp = $filter["reg_exp"]; - $inverse = $filter["inverse"]; - if ((!$inverse && @preg_match("/$reg_exp/i", $author)) || + $reg_exp = $filter["reg_exp"]; + $inverse = $filter["inverse"]; + if ((!$inverse && @preg_match("/$reg_exp/i", $author)) || ($inverse && !@preg_match("/$reg_exp/i", $author))) { array_push($matches, array($filter["action"], $filter["action_param"])); @@ -1647,11 +1616,11 @@ $reg_exp = $filter["reg_exp"]; $inverse = $filter["inverse"]; - if ((!$inverse && @preg_match("/$reg_exp/i", $tag_string)) || + if ((!$inverse && @preg_match("/$reg_exp/i", $tag_string)) || ($inverse && !@preg_match("/$reg_exp/i", $tag_string))) { array_push($matches, array($filter["action"], $filter["action_param"])); - } + } } } @@ -1694,7 +1663,7 @@ function print_radio($id, $default, $true_is, $values, $attributes = "") { foreach ($values as $v) { - + if ($v == $default) $sel = "checked"; else @@ -1705,8 +1674,8 @@ } else { $sel .= " value=\"0\""; } - - print " $v "; } @@ -1728,14 +1697,14 @@ db_query($link, "BEGIN"); $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs"); - - $u_result = db_query($link, "SELECT pref_name + + $u_result = db_query($link, "SELECT pref_name FROM ttrss_user_prefs WHERE owner_uid = '$uid' $profile_qpart"); $active_prefs = array(); while ($line = db_fetch_assoc($u_result)) { - array_push($active_prefs, $line["pref_name"]); + array_push($active_prefs, $line["pref_name"]); } while ($line = db_fetch_assoc($result)) { @@ -1744,12 +1713,12 @@ if (get_schema_version($link) < 63) { db_query($link, "INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value) VALUES + (owner_uid,pref_name,value) VALUES ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')"); } else { db_query($link, "INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value, profile) VALUES + (owner_uid,pref_name,value, profile) VALUES ('$uid', '".$line["pref_name"]."','".$line["def_value"]."', $profile)"); } @@ -1762,7 +1731,7 @@ function lookup_user_id($link, $user) { - $result = db_query($link, "SELECT id FROM ttrss_users WHERE + $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'"); if (db_num_rows($result) == 1) { @@ -1781,9 +1750,9 @@ header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"'); header('HTTP/1.0 401 Unauthorized'); exit; - + } else { - $auth_result = authenticate_user($link, + $auth_result = authenticate_user($link, $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]); if (!$auth_result) { @@ -1804,7 +1773,7 @@ $pwd_hash2 = encrypt_password($password, $login); $login = db_escape_string($login); - if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH + if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH && $_SERVER["REMOTE_USER"] && $login != "admin") { $login = db_escape_string($_SERVER["REMOTE_USER"]); @@ -1821,25 +1790,25 @@ } $result = db_query($link, $query); - + if (db_num_rows($result) == 1) { $_SESSION["uid"] = db_fetch_result($result, 0, "id"); $_SESSION["name"] = db_fetch_result($result, 0, "login"); $_SESSION["access_level"] = db_fetch_result($result, 0, "access_level"); - - db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . + + db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . $_SESSION["uid"]); - + $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); $_SESSION["last_version_check"] = time(); - + initialize_user_prefs($link, $_SESSION["uid"]); - + return true; } - + return false; } else { @@ -1848,9 +1817,9 @@ $_SESSION["name"] = "admin"; $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; - + initialize_user_prefs($link, $_SESSION["uid"]); - + return true; } } @@ -1858,14 +1827,14 @@ function make_password($length = 8) { $password = ""; - $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; - - $i = 0; - - while ($i < $length) { + $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ"; + + $i = 0; + + while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); - - if (!strstr($password, $char)) { + + if (!strstr($password, $char)) { $password .= $char; $i++; } @@ -1875,7 +1844,7 @@ // this is called after user is created to initialize default feeds, labels // or whatever else - + // user preferences are checked on every login, not here function initialize_user($link, $uid) { @@ -1901,26 +1870,35 @@ } function validate_session($link) { - if (SINGLE_USER_MODE) { - return true; - } + if (SINGLE_USER_MODE) return true; - if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) { - if ($_SESSION["ip_address"]) { - if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) { - $_SESSION["login_error_msg"] = __("Session failed to validate (incorrect IP)"); - return false; - } - } - } + $check_ip = $_SESSION['ip_address']; - if ($_SESSION["ref_schema_version"] != get_schema_version($link, true)) { + switch (SESSION_CHECK_ADDRESS) { + case 0: + $check_ip = ''; + break; + case 1: + $check_ip = substr($check_ip, 0, strrpos($check_ip, '.')+1); + break; + case 2: + $check_ip = substr($check_ip, 0, strrpos($check_ip, '.')); + $check_ip = substr($check_ip, 0, strrpos($check_ip, '.')+1); + break; + }; + + if ($check_ip && strpos($_SERVER['REMOTE_ADDR'], $check_ip) !== 0) { + $_SESSION["login_error_msg"] = + __("Session failed to validate (incorrect IP)"); return false; } + if ($_SESSION["ref_schema_version"] != get_schema_version($link, true)) + return false; + if ($_SESSION["uid"]) { - $result = db_query($link, + $result = db_query($link, "SELECT pwd_hash FROM ttrss_users WHERE id = '".$_SESSION["uid"]."'"); $pwd_hash = db_fetch_result($result, 0, "pwd_hash"); @@ -1947,7 +1925,7 @@ $login_action = $_POST["login_action"]; - # try to authenticate user if called from login form + # try to authenticate user if called from login form if ($login_action == "do_login") { $login = $_POST["login"]; $password = $_POST["password"]; @@ -1973,7 +1951,12 @@ } } - header("Location: " . $_SERVER["REQUEST_URI"]); + if ($_REQUEST['return']) { + header("Location: " . $_REQUEST['return']); + } else { + header("Location: " . $_SERVER["REQUEST_URI"]); + } + exit; return; @@ -1983,16 +1966,22 @@ } if (!$_SESSION["uid"] || !validate_session($link)) { - render_login_form($link, $mobile); - //header("Location: login.php"); - exit; + if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH + && $_SERVER["REMOTE_USER"] && defined('AUTO_LOGIN') && AUTO_LOGIN) { + authenticate_user($link,$_SERVER['REMOTE_USER'],null); + $_SESSION["ref_schema_version"] = get_schema_version($link, true); + } else { + render_login_form($link, $mobile); + //header("Location: login.php"); + exit; + } } else { /* bump login timestamp */ - db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . + db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . $_SESSION["uid"]); if ($_SESSION["language"] && SESSION_COOKIE_LIFETIME > 0) { - setcookie("ttrss_lang", $_SESSION["language"], + setcookie("ttrss_lang", $_SESSION["language"], time() + SESSION_COOKIE_LIFETIME); } } @@ -2085,7 +2074,7 @@ $time = time(); if ($t) { - print ""; if (file_exists("$t/theme.js")) { print ""; + $id = 'AUDIO-' . uniqid(); + + $entry .= ""; + + $entry .= "".__("Play").""; + + } else { + + $entry .= " + + "; } - } elseif (substr($ctype,0,6)=="video/") { - $entry .= ""; - } */ + } + $filename = substr($url, strrpos($url, "/")+1); + $entry .= " " . + $filename . " (" . $ctype . ")" . ""; return $entry; } - function outputArticleXML($link, $id, $feed_id, $mark_as_read = true, + function format_article($link, $id, $feed_id, $mark_as_read = true, $zoom_mode = false) { + $rv = array(); + + $rv['id'] = $id; + /* we can figure out feed_id from article id anyway, why do we * pass feed_id here? let's ignore the argument :( */ @@ -4497,7 +4502,9 @@ $feed_id = (int) db_fetch_result($result, 0, "feed_id"); - if (!$zoom_mode) { print "
comments"; - } + } } if ($zoom_mode) { header("Content-Type: text/html"); - print " + $rv['content'] .= " Tiny Tiny RSS - ".$line["title"]." "; } - print "
" . + $rv['content'] .= "
" . truncate_string(strip_tags($line['title']), 15) . "
"; - print "
"; - - /* print "
"; - print "
".__('View in a new tab')."
"; - print "
"; - print "
".__('Open original article')."
"; - print "
"; */ + $rv['content'] .= "
"; - print "
"; $entry_author = $line["author"]; @@ -4597,69 +4595,72 @@ $entry_author = __(" - ") . $entry_author; } - $parsed_updated = make_local_datetime($link, $line["updated"], true, + $parsed_updated = make_local_datetime($link, $line["updated"], true, false, true); - print "
$parsed_updated
"; + $rv['content'] .= "
$parsed_updated
"; if ($line["link"]) { - print ""; + $rv['content'] .= ""; } else { - print "
" . $line["title"] . "$entry_author
"; + $rv['content'] .= "
" . $line["title"] . "$entry_author
"; } $tags_str = format_tags_string(get_article_tags($link, $id), $id); if (!$entry_comments) $entry_comments = " "; # placeholder - print "
- Tags "; if (!$zoom_mode) { - print "$tags_str - $tags_str + (+)"; - print "Zoom"; - $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); + //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); - print "PubNote"; + onclick=\"editArticleNote($id)\" + alt='PubNote' title='".__('Edit article note')."'>"; if (DIGEST_ENABLE) { - print "Zoom"; } if (ENABLE_TWEET_BUTTON) { - print "Zoom"; } - print "Zoom"; } else { $tags_str = strip_tags($tags_str); - print "$tags_str"; + $rv['content'] .= "$tags_str"; } - print "
"; - print "
$entry_comments
"; + $rv['content'] .= "
"; + $rv['content'] .= "
$entry_comments
"; if ($line["orig_feed_id"]) { @@ -4668,70 +4669,69 @@ if (db_num_rows($tmp_result) != 0) { - print "
"; - print __("Originally from:"); + $rv['content'] .= "
"; + $rv['content'] .= __("Originally from:"); - print " "; + $rv['content'] .= " "; $tmp_line = db_fetch_assoc($tmp_result); - print "" . $tmp_line['title'] . ""; - print " "; + $rv['content'] .= " "; - print ""; - print ""; + $rv['content'] .= ""; + $rv['content'] .= ""; - print "
"; + $rv['content'] .= "
"; } } - print "
"; + $rv['content'] .= "
"; - print ""; - print "
"; + $rv['content'] .= "
"; + if ($line['note']) { + $rv['content'] .= format_article_note($id, $line['note']); + } + $rv['content'] .= "
"; + + $rv['content'] .= "
"; $article_content = sanitize_rss($link, $line["content"], false, false, $feed_site_url); - print "
"; - if ($line['note']) { - print format_article_note($id, $line['note']); - } - print "
"; - - print $article_content; + $rv['content'] .= $article_content; - print_article_enclosures($link, $id, $always_display_enclosures, - $article_content); + $rv['content'] .= format_article_enclosures($link, $id, + $always_display_enclosures, $article_content); - print "
"; + $rv['content'] .= "
"; - print "
"; + $rv['content'] .= ""; } - if (!$zoom_mode) { - print "]]>
"; - } else { - print " + if ($zoom_mode) { + $rv['content'] .= "
"; - print ""; - + $rv['content'] .= ""; } + return $rv; + } function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, - $next_unread_feed, $offset, $vgr_last_feed = false, + $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false) { $disable_cache = false; @@ -4755,6 +4755,10 @@ catchupArticlesById($link, $ids, $cmode); } + if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { + update_rss_feed($link, $feed, true); + } + if ($subop == "MarkAllRead") { catchup_feed($link, $feed, $cat_view); @@ -4771,12 +4775,12 @@ // FIXME: might break tag display? - if ($feed > 0 && !$cat_view) { + if ($feed > 0 && !$cat_view) { $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); - + if (db_num_rows($result) == 0) { - print "
".__('Feed not found.')."
"; + print "
".__('Feed not found.')."
"; return; } } @@ -4791,7 +4795,7 @@ } else { $rtl_content = false; } - + if ($rtl_content) { $rtl_tag = "dir=\"RTL\""; } else { @@ -4806,7 +4810,7 @@ @$search = db_escape_string($_REQUEST["query"]); - if ($search) { + if ($search) { $disable_cache = true; } @@ -4821,7 +4825,7 @@ if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info); - $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, + $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $real_offset); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); @@ -4851,7 +4855,7 @@ if (db_num_rows($result) > 0) { print_headline_subtoolbar($link, $feed_site_url, $feed_title, - $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, + $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, $last_error); // print "
"; @@ -4875,7 +4879,7 @@ while ($line = db_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; - + $id = $line["id"]; $feed_id = $line["feed_id"]; @@ -4884,28 +4888,28 @@ $labels_str = ""; $labels_str .= format_article_labels($labels, $id); $labels_str .= ""; - + if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); } if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) { - + $update_pic = "\"Updated\""; } else { - $update_pic = "\"Updated\""; } - if (sql_bool_to_bool($line["unread"]) && + if (sql_bool_to_bool($line["unread"]) && time() - strtotime($line["updated_noms"]) < $fresh_intl) { $update_pic = "\"Fresh\""; } - + if ($line["unread"] == "t" || $line["unread"] == "1") { $class .= " Unread"; ++$num_unread; @@ -4915,25 +4919,25 @@ } if ($line["marked"] == "t" || $line["marked"] == "1") { - $marked_pic = "\"Unstar"; } else { - $marked_pic = "\"Star"; } if ($line["published"] == "t" || $line["published"] == "1") { - $published_pic = "\"Unpublish"; } else { $published_pic = "\"Publish"; } @@ -4941,7 +4945,7 @@ # $content_link = "" . # $line["title"] . ""; -# $content_link = "" . # $line["title"] . ""; @@ -4949,23 +4953,23 @@ # $content_link = "" . # $line["title"] . ""; - $updated_fmt = make_local_datetime($link, $line["updated_noms"], false); + $updated_fmt = make_local_datetime($link, $line["updated_noms"], false); if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { - $content_preview = truncate_string(strip_tags($line["content_preview"]), + $content_preview = truncate_string(strip_tags($line["content_preview"]), 100); } $score = $line["score"]; - $score_pic = theme_image($link, + $score_pic = theme_image($link, "images/" . get_score_pic($score)); /* $score_title = __("(Click to change)"); - $score_pic = ""; */ - $score_pic = ""; if ($score > 500) { @@ -5010,7 +5014,7 @@ } } - $mouseover_attrs = "onmouseover='postMouseIn($id)' + $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; print "
"; @@ -5021,15 +5025,15 @@ print ""; - + print "$marked_pic"; print "$published_pic"; print "
"; - print "
"; - print "" . $line["title"]; @@ -5045,7 +5049,7 @@ print $labels_str; /* if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { - if (@$line["feed_title"]) { + if (@$line["feed_title"]) { print " (". $line["feed_title"].") @@ -5057,13 +5061,13 @@ - print "
"; + print "
"; print "$updated_fmt"; print $score_pic; if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) { - print " $feed_icon_img"; } @@ -5100,10 +5104,10 @@ $expand_cdm = get_pref($link, 'CDM_EXPANDED'); - $mouseover_attrs = "onmouseover='postMouseIn($id)' + $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; - print "
"; print "
"; @@ -5113,26 +5117,28 @@ print "$score_pic"; if (!get_pref($link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) { - print "$feed_icon_img"; } print "
$update_pic
"; print "
"; - - print ""; print "$marked_pic"; print "$published_pic"; - print " ".$line["title"]. + htmlspecialchars($line["link"])."\">". + truncate_string($line["title"], 100) . " $entry_author"; print $labels_str; @@ -5161,23 +5167,23 @@ WHERE id = ".$line["orig_feed_id"]); if (db_num_rows($tmp_result) != 0) { - + print "
"; print __("Originally from:"); - + print " "; - + $tmp_line = db_fetch_assoc($tmp_result); - - print "" . $tmp_line['title'] . ""; - + print " "; - + print ""; print ""; - + print "
"; } } @@ -5196,7 +5202,7 @@ } if ($expand_cdm) { - $article_content = sanitize_rss($link, $line["content_preview"], + $article_content = sanitize_rss($link, $line["content_preview"], false, false, $feed_site_url); if (!$article_content) $article_content = " "; @@ -5214,13 +5220,13 @@ $tmp_result = db_query($link, "SELECT always_display_enclosures FROM ttrss_feeds WHERE id = ". - (($line['feed_id'] == null) ? $line['orig_feed_id'] : + (($line['feed_id'] == null) ? $line['orig_feed_id'] : $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]); - $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result, + $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result, 0, "always_display_enclosures")); - print_article_enclosures($link, $id, $always_display_enclosures, + print format_article_enclosures($link, $id, $always_display_enclosures, $article_content); print "
"; @@ -5232,33 +5238,33 @@ print "Tags $tags_str - (+)"; print "
"; - print "Zoom"; - $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); + //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); print "PubNote"; + onclick=\"editArticleNote($id)\" + alt='PubNote' title='".__('Edit article note')."'>"; if (DIGEST_ENABLE) { - print "Zoom"; } if (ENABLE_TWEET_BUTTON) { - print "Zoom"; @@ -5276,10 +5282,10 @@ print "
"; - } - + } + ++$lnum; - } + } } else { $message = ""; @@ -5309,17 +5315,17 @@ $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); - + $last_updated = db_fetch_result($result, 0, "last_updated"); $last_updated = make_local_datetime($link, $last_updated, false); - + printf(__("Feeds last updated at %s"), $last_updated); - + $result = db_query($link, "SELECT COUNT(id) AS num_errors FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); - + $num_errors = db_fetch_result($result, 0, "num_errors"); - + if ($num_errors > 0) { print "
"; print "". @@ -5343,8 +5349,8 @@ function printTagCloud($link) { - $query = "SELECT tag_name, COUNT(post_int_id) AS count - FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." + $query = "SELECT tag_name, COUNT(post_int_id) AS count + FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." GROUP BY tag_name ORDER BY count DESC LIMIT 50"; $result = db_query($link, $query); @@ -5359,20 +5365,20 @@ $max_size = 32; // max font size in pixels $min_size = 11; // min font size in pixels - + // largest and smallest array values $max_qty = max(array_values($tags)); $min_qty = min(array_values($tags)); - + // find the range of values $spread = $max_qty - $min_qty; if ($spread == 0) { // we don't want to divide by zero $spread = 1; } - + // set the font-size increment $step = ($max_size - $min_size) / ($spread); - + // loop through the tag array foreach ($tags as $key => $value) { // calculate font-size @@ -5383,14 +5389,14 @@ $key_escaped = str_replace("'", "\\'", $key); - echo "' . $key . ' '; } } function print_checkpoint($n, $s) { - $ts = getmicrotime(); + $ts = getmicrotime(); echo sprintf("", $ts - $s); return $ts; } @@ -5400,10 +5406,10 @@ $tag = mb_strtolower($tag, 'utf-8'); - $tag = preg_replace('/[\"\+\>\<]/', "", $tag); + $tag = preg_replace('/[\"\+\>\<]/', "", $tag); -// $tag = str_replace('"', "", $tag); -// $tag = str_replace("+", " ", $tag); +// $tag = str_replace('"', "", $tag); +// $tag = str_replace("+", " ", $tag); $tag = str_replace("technorati tag: ", "", $tag); return $tag; @@ -5412,7 +5418,7 @@ function get_self_url_prefix() { $url_path = ""; - + if ($_SERVER['HTTPS'] != "on") { $url_path = "http://"; } else { @@ -5427,7 +5433,7 @@ function opml_publish_url($link){ $url_path = get_self_url_prefix(); - $url_path .= "/opml.php?op=publish&key=" . + $url_path .= "/opml.php?op=publish&key=" . get_feed_access_key($link, 'OPML:Publish', false, $_SESSION["uid"]); return $url_path; @@ -5435,7 +5441,7 @@ /** * Purge a feed contents, marked articles excepted. - * + * * @param mixed $link The database connection. * @param integer $id The id of the feed to purge. * @return void @@ -5450,7 +5456,7 @@ WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); } - $result = db_query($link, "DELETE FROM ttrss_entries WHERE + $result = db_query($link, "DELETE FROM ttrss_entries WHERE (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); ccache_update($link, $id, $_SESSION['uid']); @@ -5469,7 +5475,7 @@ /** * Encrypt a password in SHA1. - * + * * @param string $pass The password to encrypt. * @param string $login A optionnal login. * @return string The encrypted password. @@ -5487,7 +5493,7 @@ * 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. @@ -5503,7 +5509,7 @@ $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; } else { $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; - } + } } else { $login_thresh_qpart = ""; } @@ -5543,8 +5549,8 @@ // We search for feed needing update. $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid, ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, - ttrss_feeds.update_interval - FROM + ttrss_feeds.update_interval + FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE ttrss_feeds.owner_uid = ttrss_users.id @@ -5609,21 +5615,21 @@ } else { if ($action_id) $ftype_query_part = "action_id = '$action_id' AND"; - + $result = db_query($link, "SELECT reg_exp, ttrss_filter_types.name AS name, ttrss_filter_actions.name AS action, inverse, action_param, filter_param - FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE + FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE enabled = true AND $ftype_query_part owner_uid = $owner_uid AND ttrss_filter_types.id = filter_type AND ttrss_filter_actions.id = action_id AND (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp"); - + while ($line = db_fetch_assoc($result)) { if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); $filter["reg_exp"] = $line["reg_exp"]; @@ -5631,7 +5637,7 @@ $filter["action_param"] = $line["action_param"]; $filter["filter_param"] = $line["filter_param"]; $filter["inverse"] = sql_bool_to_bool($line["inverse"]); - + array_push($filters[$line["name"]], $filter); } @@ -5642,15 +5648,15 @@ } function get_score_pic($score) { - if ($score > 100) { - return "score_high.png"; - } else if ($score > 0) { + if ($score > 100) { + return "score_high.png"; + } else if ($score > 0) { return "score_half_high.png"; } else if ($score < -100) { return "score_low.png"; } else if ($score < 0) { return "score_half_low.png"; - } else { + } else { return "score_neutral.png"; } } @@ -5690,17 +5696,17 @@ function update_feedbrowser_cache($link) { $result = db_query($link, "SELECT feed_url,title, COUNT(id) AS subscribers - FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf - WHERE tf.feed_url = ttrss_feeds.feed_url - AND (private IS true OR feed_url LIKE '%:%@%/%')) + FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf + WHERE tf.feed_url = ttrss_feeds.feed_url + AND (private IS true OR feed_url LIKE '%:%@%/%')) GROUP BY feed_url, title ORDER BY subscribers DESC LIMIT 1000"); - + db_query($link, "BEGIN"); - + db_query($link, "DELETE FROM ttrss_feedbrowser_cache"); - + $count = 0; - + while ($line = db_fetch_assoc($result)) { $subscribers = db_escape_string($line["subscribers"]); $feed_url = db_escape_string($line["feed_url"]); @@ -5711,16 +5717,16 @@ if (db_num_rows($tmp_result) == 0) { - db_query($link, "INSERT INTO ttrss_feedbrowser_cache - (feed_url, title, subscribers) VALUES ('$feed_url', + db_query($link, "INSERT INTO ttrss_feedbrowser_cache + (feed_url, title, subscribers) VALUES ('$feed_url', '$title', '$subscribers')"); ++$count; } - + } - + db_query($link, "COMMIT"); return $count; @@ -5781,7 +5787,7 @@ } } - function ccache_find($link, $feed_id, $owner_uid, $is_cat = false, + function ccache_find($link, $feed_id, $owner_uid, $is_cat = false, $no_update = false) { if (!is_numeric($feed_id)) return; @@ -5789,7 +5795,7 @@ if (!$is_cat) { $table = "ttrss_counters_cache"; if ($feed_id > 0) { - $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds + $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); $owner_uid = db_fetch_result($tmp_result, 0, "owner_uid"); } @@ -5804,7 +5810,7 @@ } $result = db_query($link, "SELECT value FROM $table - WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' + WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1"); if (db_num_rows($result) == 1) { @@ -5819,13 +5825,13 @@ } - function ccache_update($link, $feed_id, $owner_uid, $is_cat = false, + function ccache_update($link, $feed_id, $owner_uid, $is_cat = false, $update_pcat = true) { if (!is_numeric($feed_id)) return; if (!$is_cat && $feed_id > 0) { - $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds + $tmp_result = db_query($link, "SELECT owner_uid FROM ttrss_feeds WHERE id = '$feed_id'"); $owner_uid = db_fetch_result($tmp_result, 0, "owner_uid"); } @@ -5862,9 +5868,9 @@ ccache_update($link, $line["id"], $owner_uid, false, false); } - $result = db_query($link, "SELECT SUM(value) AS sv - FROM ttrss_counters_cache, ttrss_feeds - WHERE id = feed_id AND $cat_qpart AND + $result = db_query($link, "SELECT SUM(value) AS sv + FROM ttrss_counters_cache, ttrss_feeds + WHERE id = feed_id AND $cat_qpart AND ttrss_feeds.owner_uid = '$owner_uid'"); $unread = (int) db_fetch_result($result, 0, "sv"); @@ -5885,8 +5891,8 @@ } else { db_query($link, "INSERT INTO $table - (feed_id, value, owner_uid, updated) - VALUES + (feed_id, value, owner_uid, updated) + VALUES ($feed_id, $unread, $owner_uid, NOW())"); } @@ -5917,8 +5923,8 @@ } function label_find_id($link, $label, $owner_uid) { - $result = db_query($link, - "SELECT id FROM ttrss_labels2 WHERE caption = '$label' + $result = db_query($link, + "SELECT id FROM ttrss_labels2 WHERE caption = '$label' AND owner_uid = '$owner_uid' LIMIT 1"); if (db_num_rows($result) == 1) { @@ -5955,11 +5961,11 @@ return $label_cache; } - $result = db_query($link, - "SELECT DISTINCT label_id,caption,fg_color,bg_color - FROM ttrss_labels2, ttrss_user_labels2 - WHERE id = label_id - AND article_id = '$id' + $result = db_query($link, + "SELECT DISTINCT label_id,caption,fg_color,bg_color + FROM ttrss_labels2, ttrss_user_labels2 + WHERE id = label_id + AND article_id = '$id' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY caption"); @@ -5970,7 +5976,7 @@ } if ($memcache) $memcache->add($obj_id, $rv, 0, 3600); - if (count($rv) > 0) + if (count($rv) > 0) label_update_cache($link, $id, $rv); else label_update_cache($link, $id, array("no-labels" => 1)); @@ -5981,8 +5987,8 @@ function label_find_caption($link, $label, $owner_uid) { - $result = db_query($link, - "SELECT caption FROM ttrss_labels2 WHERE id = '$label' + $result = db_query($link, + "SELECT caption FROM ttrss_labels2 WHERE id = '$label' AND owner_uid = '$owner_uid' LIMIT 1"); if (db_num_rows($result) == 1) { @@ -5997,7 +6003,7 @@ if ($force) label_clear_cache($link, $id); - if (!$labels) + if (!$labels) $labels = get_article_labels($link, $id); $labels = db_escape_string(json_encode($labels)); @@ -6020,9 +6026,9 @@ if (!$label_id) return; - $result = db_query($link, + $result = db_query($link, "DELETE FROM ttrss_user_labels2 - WHERE + WHERE label_id = '$label_id' AND article_id = '$id'"); @@ -6042,21 +6048,21 @@ if (!$label_id) return; - $result = db_query($link, - "SELECT + $result = db_query($link, + "SELECT article_id FROM ttrss_labels2, ttrss_user_labels2 - WHERE - label_id = id AND + WHERE + label_id = id AND label_id = '$label_id' AND article_id = '$id' AND owner_uid = '$owner_uid' LIMIT 1"); if (db_num_rows($result) == 0) { - db_query($link, "INSERT INTO ttrss_user_labels2 + db_query($link, "INSERT INTO ttrss_user_labels2 (label_id, article_id) VALUES ('$label_id', '$id')"); } - label_clear_cache($link, $id); + label_clear_cache($link, $id); } @@ -6090,7 +6096,7 @@ feed_id = '$ext_id' AND owner_uid = $owner_uid"); /* Disable filters that reference label being removed */ - + db_query($link, "UPDATE ttrss_filters SET enabled = false WHERE action_param = '$caption' AND action_id = 7 @@ -6117,7 +6123,7 @@ if (db_num_rows($result) == 0) { $result = db_query($link, - "INSERT INTO ttrss_labels2 (caption,owner_uid) + "INSERT INTO ttrss_labels2 (caption,owner_uid) VALUES ('$caption', '".$_SESSION["uid"]."')"); $result = db_affected_rows($link, $result) != 0; @@ -6141,11 +6147,11 @@ $id = $line["id"]; if ($feed_id < -10 && $feed_id == -11-$label_id) { - print ""; - } else { - print ""; } @@ -6182,7 +6188,7 @@ array_push($formatted_tags, $tag_str); $tmp_tags_str = implode(", ", $formatted_tags); - + if ($num_tags == $tag_limit || mb_strlen($tmp_tags_str) > 150) { break; } @@ -6207,7 +6213,7 @@ $labels_str = ""; foreach ($labels as $l) { - $labels_str .= sprintf("%s", $l[2], $l[3], $l[1]); } @@ -6218,15 +6224,8 @@ function format_article_note($id, $note) { - $note_escaped = htmlspecialchars($note, ENT_QUOTES); - - $str = "
"; - $str .= $note; - $str .= "
"; - $str .= "". - __('edit note').""; - $str .= "
"; - $str .= "
"; + $str = "
$note
"; return $str; } @@ -6236,7 +6235,7 @@ $mode = bool_to_sql_bool($mode); db_query($link, "UPDATE ttrss_feed_categories SET - collapsed = $mode WHERE id = '$cat_id' AND owner_uid = " . + collapsed = $mode WHERE id = '$cat_id' AND owner_uid = " . $_SESSION["uid"]); } else { $pref_name = ''; @@ -6277,14 +6276,14 @@ WHERE id = '$id'"); if (db_num_rows($result) == 0) { - db_query($link, "INSERT INTO ttrss_archived_feeds + db_query($link, "INSERT INTO ttrss_archived_feeds (id, owner_uid, title, feed_url, site_url) SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds WHERE id = '$id'"); } db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL, - orig_feed_id = '$id' WHERE feed_id = '$id' AND + orig_feed_id = '$id' WHERE feed_id = '$id' AND marked = true AND owner_uid = $owner_uid"); /* Remove access key for the feed */ @@ -6294,7 +6293,7 @@ /* remove the feed */ - db_query($link, "DELETE FROM ttrss_feeds + db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id' AND owner_uid = $owner_uid"); db_query($link, "COMMIT"); @@ -6322,9 +6321,9 @@ WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); if (db_num_rows($result) == 0) { - + $result = db_query($link, - "INSERT INTO ttrss_feed_categories (owner_uid,title) + "INSERT INTO ttrss_feed_categories (owner_uid,title) VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); db_query($link, "COMMIT"); @@ -6333,7 +6332,7 @@ } return false; - } + } function remove_feed_category($link, $id, $owner_uid) { @@ -6360,13 +6359,13 @@ WHERE id = '$feed_id'"); if (db_num_rows($result) == 0) { - db_query($link, "INSERT INTO ttrss_archived_feeds + db_query($link, "INSERT INTO ttrss_archived_feeds (id, owner_uid, title, feed_url, site_url) SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds WHERE id = '$feed_id'"); } - db_query($link, "UPDATE ttrss_user_entries + db_query($link, "UPDATE ttrss_user_entries SET orig_feed_id = feed_id, feed_id = NULL WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } @@ -6376,7 +6375,7 @@ } function getArticleFeed($link, $id) { - $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries + $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) != 0) { @@ -6434,7 +6433,7 @@ global $memcache; - $query = "SELECT * FROM ttrss_enclosures + $query = "SELECT * FROM ttrss_enclosures WHERE post_id = '$id' AND content_url != ''"; $obj_id = md5("ENCLOSURES:$id"); @@ -6469,16 +6468,16 @@ foreach (array_values($counters) as $cv) { $unread = $cv["counter"]; - + if ($unread || !$unread_only) { - + $row = array( "id" => $cv["id"], "title" => $cv["description"], "unread" => $cv["counter"], "cat_id" => -2, ); - + array_push($feeds, $row); } } @@ -6502,7 +6501,7 @@ array_push($feeds, $row); } - } + } } /* Real feeds */ @@ -6514,10 +6513,10 @@ } if ($cat_id == -4 || $cat_id == -3) { - $result = db_query($link, "SELECT + $result = db_query($link, "SELECT id, feed_url, cat_id, title, ". SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated - FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] . + FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY cat_id, title " . $limit_qpart); } else { @@ -6526,11 +6525,11 @@ else $cat_qpart = "cat_id IS NULL"; - $result = db_query($link, "SELECT + $result = db_query($link, "SELECT id, feed_url, cat_id, title, ". SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated - FROM ttrss_feeds WHERE - $cat_qpart AND owner_uid = " . $_SESSION["uid"] . + FROM ttrss_feeds WHERE + $cat_qpart AND owner_uid = " . $_SESSION["uid"] . " ORDER BY cat_id, title " . $limit_qpart); } @@ -6551,7 +6550,7 @@ "cat_id" => (int)$line["cat_id"], "last_updated" => strtotime($line["last_updated"]) ); - + array_push($feeds, $row); } } @@ -6567,8 +6566,8 @@ $search = db_escape_string($_REQUEST["search"]); $search_mode = db_escape_string($_REQUEST["search_mode"]); $match_on = db_escape_string($_REQUEST["match_on"]); - - $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, + + $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, $view_mode, $is_cat, $search, $search_mode, $match_on, $order, $offset); @@ -6578,7 +6577,7 @@ $headlines = array(); while ($line = db_fetch_assoc($result)) { - $is_updated = ($line["last_read"] == "" && + $is_updated = ($line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1")); $headline_row = array( @@ -6659,7 +6658,7 @@ function save_email_address($link, $email) { // FIXME: implement persistent storage of emails - if (!$_SESSION['stored_emails']) + if (!$_SESSION['stored_emails']) $_SESSION['stored_emails'] = array(); if (!in_array($email, $_SESSION['stored_emails'])) @@ -6671,15 +6670,15 @@ $sql_is_cat = bool_to_sql_bool($is_cat); - $result = db_query($link, "SELECT access_key FROM ttrss_access_keys - WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + $result = db_query($link, "SELECT access_key FROM ttrss_access_keys + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat AND owner_uid = " . $owner_uid); if (db_num_rows($result) == 1) { $key = db_escape_string(sha1(uniqid(rand(), true))); db_query($link, "UPDATE ttrss_access_keys SET access_key = '$key' - WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat AND owner_uid = " . $owner_uid); return $key; @@ -6695,8 +6694,8 @@ $sql_is_cat = bool_to_sql_bool($is_cat); - $result = db_query($link, "SELECT access_key FROM ttrss_access_keys - WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat + $result = db_query($link, "SELECT access_key FROM ttrss_access_keys + WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat AND owner_uid = " . $owner_uid); if (db_num_rows($result) == 1) { @@ -6704,7 +6703,7 @@ } else { $key = db_escape_string(sha1(uniqid(rand(), true))); - $result = db_query($link, "INSERT INTO ttrss_access_keys + $result = db_query($link, "INSERT INTO ttrss_access_keys (access_key, feed_id, is_cat, owner_uid) VALUES ('$key', '$feed_id', $sql_is_cat, '$owner_uid')"); @@ -6720,15 +6719,17 @@ * * @return array Array of feeds. Key is the full URL, value the title */ - function get_feeds_from_html($url) + function get_feeds_from_html($url, $login = false, $pass = false) { $url = fix_url($url); $baseUrl = substr($url, 0, strrpos($url, '/') + 1); libxml_use_internal_errors(true); + $content = @fetch_file_contents($url, false, $login, $pass); + $doc = new DOMDocument(); - $doc->loadHTMLFile($url); + $doc->loadHTML($content); $xpath = new DOMXPath($doc); $entries = $xpath->query('/html/head/link[@rel="alternate"]'); $feedUrls = array(); @@ -6754,8 +6755,9 @@ * * @return boolean True if the URL contains HTML content */ - function url_is_html($url) { - $content = substr(fetch_file_contents($url, false), 0, 1000); + function url_is_html($url, $login = false, $pass = false) { + $content = substr(fetch_file_contents($url, false, $login, $pass), 0, 1000); + if (stripos($content, '') === false && stripos($content, '"; while ($line = db_fetch_assoc($result)) { @@ -6789,70 +6791,73 @@ } - function print_article_enclosures($link, $id, $always_display_enclosures, + function format_article_enclosures($link, $id, $always_display_enclosures, $article_content) { $result = get_article_enclosures($link, $id); - + $rv = ''; + if (count($result) > 0) { - + $entries_html = array(); $entries = array(); - + foreach ($result as $line) { - + $url = $line["content_url"]; $ctype = $line["content_type"]; - + if (!$ctype) $ctype = __("unknown type"); - - $filename = substr($url, strrpos($url, "/")+1); - + +# $filename = substr($url, strrpos($url, "/")+1); + $entry = format_inline_player($link, $url, $ctype); - - $entry .= " " . - $filename . " (" . $ctype . ")" . ""; - + +# $entry .= " " . +# $filename . " (" . $ctype . ")" . ""; + array_push($entries_html, $entry); - + $entry = array(); - + $entry["type"] = $ctype; $entry["filename"] = $filename; $entry["url"] = $url; - + array_push($entries, $entry); } - - print "
"; - + + $rv .= "
"; + if (!get_pref($link, "STRIP_IMAGES")) { if ($always_display_enclosures || !preg_match("/

"; } } } } - + if (count($entries) == 1) { - print __("Attachment:") . " "; + $rv .= __("Attachment:") . " "; } else { - print __("Attachments:") . " "; + $rv .= __("Attachments:") . " "; } - - print join(", ", $entries_html); - - print "
"; + + $rv .= join(", ", $entries_html); + + $rv .= "
"; } + + return $rv; } function getLastArticleId($link) { @@ -6881,7 +6886,7 @@ function rewrite_relative_url($url, $rel_url) { if (strpos($rel_url, "://") !== false) { return $rel_url; - } else if (strpos($rel_url, "/") === 0) + } else if (strpos($rel_url, "/") === 0) { $parts = parse_url($url); $parts['path'] = $rel_url; @@ -6910,7 +6915,7 @@ $sphinxClient->SetServer('localhost', 9312); $sphinxClient->SetConnectTimeout(1); - $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, + $sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30, 'feed_title' => 20)); $sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2); @@ -6918,7 +6923,7 @@ $sphinxClient->SetLimits($offset, $limit, 1000); $sphinxClient->SetArrayResult(false); $sphinxClient->SetFilter('owner_uid', array($_SESSION['uid'])); - + $result = $sphinxClient->Query($query, SPHINX_INDEX); $ids = array(); @@ -6946,11 +6951,11 @@ while ($limit > 0) { $limit_part = 500; - $query = "SELECT ttrss_tags.id AS id - FROM ttrss_tags, ttrss_user_entries, ttrss_entries + $query = "SELECT ttrss_tags.id AS id + FROM ttrss_tags, ttrss_user_entries, ttrss_entries WHERE post_int_id = int_id AND $interval_query AND ref_id = ttrss_entries.id AND tag_cache != '' LIMIT $limit_part"; - + $result = db_query($link, $query); $ids = array(); @@ -7002,7 +7007,7 @@ $obj = array(); $feed_id = (int) $feed_id; - if (!$title) + if (!$title) $title = getFeedTitle($link, $feed_id, false); if ($unread === false) @@ -7020,25 +7025,47 @@ return $obj; } + function fetch_twitter_rss($link, $url, $owner_uid) { - $result = db_query($link, "SELECT twitter_oauth FROM ttrss_users + $result = db_query($link, "SELECT twitter_oauth FROM ttrss_users WHERE id = $owner_uid"); $access_token = json_decode(db_fetch_result($result, 0, 'twitter_oauth'), true); + $url_escaped = db_escape_string($url); if ($access_token) { - - /* Create a TwitterOauth object with consumer/user tokens. */ - $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); - - /* If method is set change API call made. Test is called by default. */ - $content = $connection->get($url); - $rss = new MagpieRSS($content, MAGPIE_OUTPUT_ENCODING, - MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); + $tmhOAuth = new tmhOAuth(array( + 'consumer_key' => CONSUMER_KEY, + 'consumer_secret' => CONSUMER_SECRET, + 'user_token' => $access_token['oauth_token'], + 'user_secret' => $access_token['oauth_token_secret'], + )); + + $code = $tmhOAuth->request('GET', $url); + + if ($code == 200) { + + $content = $tmhOAuth->response['response']; + + $rss = new MagpieRSS($content, MAGPIE_OUTPUT_ENCODING, + MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); + + return $rss; + + } else { + + db_query($link, "UPDATE ttrss_feeds + SET last_error = 'OAuth authorization failed ($code).' + WHERE feed_url = '$url_escaped' AND owner_uid = $owner_uid"); + } - return $rss; } else { + + db_query($link, "UPDATE ttrss_feeds + SET last_error = 'OAuth information not found.' + WHERE feed_url = '$url_escaped' AND owner_uid = $owner_uid"); + return false; } } @@ -7048,10 +7075,21 @@ if ($value) { print ""; } } + function rewrite_urls($line) { + global $url_regex; + + $urls = null; + + $result = preg_replace("/((?\\1", $line); + + return $result; + } + ?>