X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=classes%2Fhandler%2Fpublic.php;h=383654df3f7ac5e77c3d436f41c307c3d2c2036f;hb=f97b56a3c9189da54763c4c03cb9c634ad6112b7;hp=5af416adc429cc6fdeef604a211c96633f041643;hpb=a42c55f02b7e313ab61bf826794d0888f2dceae1;p=tt-rss.git diff --git a/classes/handler/public.php b/classes/handler/public.php index 5af416ad..383654df 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -3,7 +3,7 @@ class Handler_Public extends Handler { private function generate_syndicated_feed($owner_uid, $feed, $is_cat, $limit, $offset, $search, $search_mode, - $view_mode = false, $format = 'atom') { + $view_mode = false, $format = 'atom', $order = false, $orig_guid = false) { require_once "lib/MiniTemplator.class.php"; @@ -15,11 +15,27 @@ class Handler_Public extends Handler { if (!$limit) $limit = 60; $date_sort_field = "date_entered DESC, updated DESC"; + $date_check_field = "date_entered"; - if ($feed == -2) + if ($feed == -2 && !$is_cat) { $date_sort_field = "last_published DESC"; - else if ($feed == -1) + $date_check_field = "last_published"; + } else if ($feed == -1 && !$is_cat) { $date_sort_field = "last_marked DESC"; + $date_check_field = "last_marked"; + } + + switch ($order) { + case "title": + $date_sort_field = "ttrss_entries.title"; + break; + case "date_reverse": + $date_sort_field = "date_entered, updated"; + break; + case "feed_dates": + $date_sort_field = "updated DESC"; + break; + } $qfh_ret = queryFeedHeadlines($feed, 1, $view_mode, $is_cat, $search, $search_mode, @@ -28,8 +44,9 @@ class Handler_Public extends Handler { $result = $qfh_ret[0]; - if (db_num_rows($result) != 0) { - $ts = strtotime(db_fetch_result($result, 0, "date_entered")); + if ($this->dbh->num_rows($result) != 0) { + + $ts = strtotime($this->dbh->fetch_result($result, 0, $date_check_field)); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) { @@ -50,11 +67,11 @@ class Handler_Public extends Handler { $result = $qfh_ret[0]; $feed_title = htmlspecialchars($qfh_ret[1]); $feed_site_url = $qfh_ret[2]; - $last_error = $qfh_ret[3]; + /* $last_error = $qfh_ret[3]; */ $feed_self_url = get_self_url_prefix() . - "/public.php?op=rss&id=-2&key=" . - get_feed_access_key(-2, false, $owner_uid); + "/public.php?op=rss&id=$feed&key=" . + get_feed_access_key($feed, false, $owner_uid); if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); @@ -73,16 +90,22 @@ class Handler_Public extends Handler { } $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); + while ($line = $this->dbh->fetch_assoc($result)) { + $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...'); - while ($line = db_fetch_assoc($result)) { + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { + $line = $p->hook_query_headlines($line); + } - $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true); + $tpl->setVariable('ARTICLE_ID', + htmlspecialchars($orig_guid ? $line['link'] : + get_self_url_prefix() . + "/public.php?url=" . urlencode($line['link'])), true); $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); - $tpl->setVariable('ARTICLE_EXCERPT', - truncate_string(strip_tags($line["content_preview"]), 100, '...'), true); + $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); - $content = sanitize($line["content_preview"], false, $owner_uid); + $content = sanitize($line["content"], false, $owner_uid); if ($line['note']) { $content = "
Article note: " . $line['note'] . "
" . @@ -99,6 +122,9 @@ class Handler_Public extends Handler { $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); + $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true); + $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); + $tags = get_article_tags($line["id"], $owner_uid); foreach ($tags as $tag) { @@ -151,14 +177,18 @@ class Handler_Public extends Handler { $feed['articles'] = array(); - while ($line = db_fetch_assoc($result)) { + while ($line = $this->dbh->fetch_assoc($result)) { + $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...'); + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { + $line = $p->hook_query_headlines($line, 100); + } $article = array(); $article['id'] = $line['link']; $article['link'] = $line['link']; $article['title'] = $line['title']; - $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...'); - $article['content'] = sanitize($line["content_preview"], false, $owner_uid); + $article['excerpt'] = $line["content_preview"]; + $article['content'] = sanitize($line["content"], false, $owner_uid); $article['updated'] = date('c', strtotime($line["updated"])); if ($line['note']) $article['note'] = $line['note']; @@ -201,13 +231,13 @@ class Handler_Public extends Handler { } function getUnread() { - $login = db_escape_string($_REQUEST["login"]); + $login = $this->dbh->escape_string($_REQUEST["login"]); $fresh = $_REQUEST["fresh"] == "1"; - $result = db_query("SELECT id FROM ttrss_users WHERE login = '$login'"); + $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'"); - if (db_num_rows($result) == 1) { - $uid = db_fetch_result($result, 0, "id"); + if ($this->dbh->num_rows($result) == 1) { + $uid = $this->dbh->fetch_result($result, 0, "id"); print getGlobalUnread($uid); @@ -223,16 +253,16 @@ class Handler_Public extends Handler { } function getProfiles() { - $login = db_escape_string($_REQUEST["login"]); + $login = $this->dbh->escape_string($_REQUEST["login"]); - $result = db_query("SELECT * FROM ttrss_settings_profiles,ttrss_users + $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title"); print ""> - - - - @@ -509,11 +539,9 @@ class Handler_Public extends Handler { } function login() { - $_SESSION["prefs_cache"] = array(); - if (!SINGLE_USER_MODE) { - $login = db_escape_string($_POST["login"]); + $login = $this->dbh->escape_string($_POST["login"]); $password = $_POST["password"]; $remember_me = $_POST["remember_me"]; @@ -528,24 +556,27 @@ class Handler_Public extends Handler { if (authenticate_user($login, $password)) { $_POST["password"] = ""; - $_SESSION["language"] = $_POST["language"]; + if (get_schema_version() >= 120) { + $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); + } + $_SESSION["ref_schema_version"] = get_schema_version(true); $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; if ($_POST["profile"]) { - $profile = db_escape_string($_POST["profile"]); + $profile = $this->dbh->escape_string($_POST["profile"]); - $result = db_query("SELECT id FROM ttrss_settings_profiles + $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]); - if (db_num_rows($result) != 0) { + if ($this->dbh->num_rows($result) != 0) { $_SESSION["profile"] = $profile; - $_SESSION["prefs_cache"] = array(); } } } else { $_SESSION["login_error_msg"] = __("Incorrect username or password"); + user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); } if ($_REQUEST['return']) { @@ -563,14 +594,17 @@ class Handler_Public extends Handler { if ($_SESSION["uid"]) { - $feed_url = db_escape_string(trim($_REQUEST["feed_url"])); + $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"])); header('Content-Type: text/html; charset=utf-8'); print " Tiny Tiny RSS - + + + + dbh->query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); - $feed_id = db_fetch_result($result, 0, "id"); + $feed_id = $this->dbh->fetch_result($result, 0, "id"); } else { $feed_id = 0; } @@ -656,14 +690,15 @@ class Handler_Public extends Handler { } function subscribe2() { - $feed_url = db_escape_string(trim($_REQUEST["feed_url"])); - $cat_id = db_escape_string($_REQUEST["cat_id"]); - $from = db_escape_string($_REQUEST["from"]); + $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"])); + $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]); + /* $from = $this->dbh->escape_string($_REQUEST["from"]); */ + $feed_urls = array(); /* only read authentication information from POST */ - $auth_login = db_escape_string(trim($_POST["auth_login"])); - $auth_pass = db_escape_string(trim($_POST["auth_pass"])); + $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"])); + $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"])); $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass); @@ -682,8 +717,10 @@ class Handler_Public extends Handler { break; case 4: print_notice(__("Multiple feed URLs found.")); - - $feed_urls = get_feeds_from_html($feed_url); + $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); + if (is_html($contents)) { + $feed_urls = get_feeds_from_html($url, $contents); + } break; case 5: print_error(T_sprintf("Could not subscribe to %s.
Can't download the Feed URL.", $feed_url)); @@ -712,10 +749,10 @@ class Handler_Public extends Handler { $tt_uri = get_self_url_prefix(); if ($rc <= 2){ - $result = db_query("SELECT id FROM ttrss_feeds WHERE + $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); - $feed_id = db_fetch_result($result, 0, "id"); + $feed_id = $this->dbh->fetch_result($result, 0, "id"); } else { $feed_id = 0; } @@ -745,11 +782,15 @@ class Handler_Public extends Handler { } function forgotpass() { + startup_gettext(); + header('Content-Type: text/html; charset=utf-8'); - print "Tiny Tiny RSS"; + print "Tiny Tiny RSS + + "; - print stylesheet_tag("utility.css"); - print javascript_tag("lib/prototype.js"); + echo stylesheet_tag("css/utility.css"); + echo javascript_tag("lib/prototype.js"); print " "; @@ -788,9 +829,9 @@ class Handler_Public extends Handler { print ""; } else if ($method == 'do') { - $login = db_escape_string($_POST["login"]); - $email = db_escape_string($_POST["email"]); - $test = db_escape_string($_POST["test"]); + $login = $this->dbh->escape_string($_POST["login"]); + $email = $this->dbh->escape_string($_POST["email"]); + $test = $this->dbh->escape_string($_POST["test"]); if (($test != 4 && $test != 'four') || !$email || !$login) { print_error(__('Some of the required form parameters are missing or incorrect.')); @@ -802,11 +843,11 @@ class Handler_Public extends Handler { } else { - $result = db_query("SELECT id FROM ttrss_users + $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login' AND email = '$email'"); - if (db_num_rows($result) != 0) { - $id = db_fetch_result($result, 0, "id"); + if ($this->dbh->num_rows($result) != 0) { + $id = $this->dbh->fetch_result($result, 0, "id"); Pref_Users::resetUserPassword($id, false); @@ -838,6 +879,8 @@ class Handler_Public extends Handler { } function dbupdate() { + startup_gettext(); + if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); render_login_form(); @@ -848,7 +891,9 @@ class Handler_Public extends Handler { Database Updater - + + +