From 6322ac79a020ab584d412d782d62b2ee77d7c6cf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Apr 2013 16:23:15 +0400 Subject: [PATCH] remove $link --- backend.php | 14 +- classes/api.php | 180 ++++----- classes/article.php | 104 +++--- classes/auth/base.php | 14 +- classes/backend.php | 6 +- classes/db.php | 2 +- classes/db/pgsql.php | 4 +- classes/dbupdater.php | 16 +- classes/dlg.php | 20 +- classes/feeds.php | 134 +++---- classes/handler.php | 6 +- classes/handler/public.php | 140 +++---- classes/logger/sql.php | 2 +- classes/opml.php | 102 +++--- classes/plugin.php | 4 +- classes/pluginhost.php | 31 +- classes/pref/feeds.php | 290 +++++++-------- classes/pref/filters.php | 132 +++---- classes/pref/labels.php | 66 ++-- classes/pref/prefs.php | 56 +-- classes/pref/system.php | 8 +- classes/pref/users.php | 54 +-- classes/rpc.php | 224 +++++------ include/ccache.php | 78 ++-- include/db-prefs.php | 26 +- include/db.php | 10 +- include/digest.php | 26 +- include/feedbrowser.php | 8 +- include/functions.php | 550 ++++++++++++++-------------- include/labels.php | 82 ++--- include/rssfuncs.php | 212 +++++------ include/sanity_check.php | 14 +- include/sessions.php | 2 +- index.php | 10 +- opml.php | 10 +- plugins/af_buttersafe/init.php | 2 - plugins/af_explosm/init.php | 2 - plugins/af_gocomics/init.php | 3 - plugins/af_pennyarcade/init.php | 18 +- plugins/af_redditimgur/init.php | 3 - plugins/af_unburn/init.php | 3 - plugins/auth_internal/init.php | 31 +- plugins/auth_remote/init.php | 22 +- plugins/bookmarklets/init.php | 2 - plugins/close_button/init.php | 4 +- plugins/digest/digest_body.php | 4 +- plugins/digest/init.php | 30 +- plugins/embed_original/init.php | 6 +- plugins/example/init.php | 5 +- plugins/example_api/init.php | 2 - plugins/example_article/init.php | 2 - plugins/example_feed/init.php | 2 - plugins/example_routing/init.php | 2 - plugins/example_vfeed/init.php | 4 +- plugins/googlereaderimport/init.php | 72 ++-- plugins/googlereaderkeys/init.php | 3 - plugins/import_export/init.php | 47 ++- plugins/instances/init.php | 71 ++-- plugins/mail/init.php | 12 +- plugins/mailto/init.php | 7 +- plugins/mark_button/init.php | 4 +- plugins/mobile/article.php | 12 +- plugins/mobile/backend.php | 24 +- plugins/mobile/cat.php | 6 +- plugins/mobile/feed.php | 14 +- plugins/mobile/home.php | 8 +- plugins/mobile/index.php | 8 +- plugins/mobile/init.php | 3 - plugins/mobile/mobile-functions.php | 90 ++--- plugins/mobile/prefs.php | 14 +- plugins/note/init.php | 12 +- plugins/nsfw/init.php | 5 +- plugins/share/init.php | 16 +- plugins/swap_jk/init.php | 2 - plugins/updater/init.php | 14 +- prefs.php | 10 +- public.php | 6 +- register.php | 28 +- update.php | 49 ++- update_daemon2.php | 30 +- 80 files changed, 1624 insertions(+), 1727 deletions(-) diff --git a/backend.php b/backend.php index b583d379..b06cca2d 100644 --- a/backend.php +++ b/backend.php @@ -50,7 +50,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_plugins($link)) return; + if (!init_plugins()) return; header("Content-Type: text/json; charset=utf-8"); @@ -59,16 +59,16 @@ } if (SINGLE_USER_MODE) { - authenticate_user($link, "admin", null); + authenticate_user( "admin", null); } if ($_SESSION["uid"]) { - if (!validate_session($link)) { + if (!validate_session()) { header("Content-Type: text/json"); print json_encode(array("error" => array("code" => 6))); return; } - load_user_plugins($link, $_SESSION["uid"]); + load_user_plugins( $_SESSION["uid"]); } $purge_intervals = array( @@ -106,7 +106,7 @@ 5 => __("Power User"), 10 => __("Administrator")); - #$error = sanity_check($link); + #$error = sanity_check(); #if ($error['code'] != 0 && $op != "logout") { # print json_encode(array("error" => $error)); @@ -123,7 +123,7 @@ if ($override) { $handler = $override; } else { - $handler = new $op($link, $_REQUEST); + $handler = new $op(Db::get(), $_REQUEST); } if ($handler && implements_interface($handler, 'IHandler')) { @@ -155,5 +155,5 @@ print json_encode(array("error" => array("code" => 7))); // We close the connection to database. - db_close($link); + db_close(); ?> diff --git a/classes/api.php b/classes/api.php index 958256be..10e51191 100644 --- a/classes/api.php +++ b/classes/api.php @@ -18,7 +18,7 @@ class API extends Handler { return false; } - if ($_SESSION["uid"] && $method != "logout" && !get_pref($this->link, 'ENABLE_API_ACCESS')) { + if ($_SESSION["uid"] && $method != "logout" && !get_pref( 'ENABLE_API_ACCESS')) { print $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED')); return false; } @@ -50,13 +50,13 @@ class API extends Handler { @session_destroy(); @session_start(); - $login = db_escape_string($this->link, $_REQUEST["user"]); + $login = db_escape_string( $_REQUEST["user"]); $password = $_REQUEST["password"]; $password_base64 = base64_decode($_REQUEST["password"]); if (SINGLE_USER_MODE) $login = "admin"; - $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'"); + $result = db_query( "SELECT id FROM ttrss_users WHERE login = '$login'"); if (db_num_rows($result) != 0) { $uid = db_fetch_result($result, 0, "id"); @@ -69,11 +69,11 @@ class API extends Handler { return; } - if (get_pref($this->link, "ENABLE_API_ACCESS", $uid)) { - if (authenticate_user($this->link, $login, $password)) { // try login with normal password + if (get_pref( "ENABLE_API_ACCESS", $uid)) { + if (authenticate_user( $login, $password)) { // try login with normal password print $this->wrap(self::STATUS_OK, array("session_id" => session_id(), "api_level" => self::API_LEVEL)); - } else if (authenticate_user($this->link, $login, $password_base64)) { // else try with base64_decoded password + } else if (authenticate_user( $login, $password_base64)) { // else try with base64_decoded password print $this->wrap(self::STATUS_OK, array("session_id" => session_id(), "api_level" => self::API_LEVEL)); } else { // else we are not logged in @@ -95,29 +95,29 @@ class API extends Handler { } function getUnread() { - $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]); - $is_cat = db_escape_string($this->link, $_REQUEST["is_cat"]); + $feed_id = db_escape_string( $_REQUEST["feed_id"]); + $is_cat = db_escape_string( $_REQUEST["is_cat"]); if ($feed_id) { - print $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($this->link, $feed_id, $is_cat))); + print $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread( $feed_id, $is_cat))); } else { - print $this->wrap(self::STATUS_OK, array("unread" => getGlobalUnread($this->link))); + print $this->wrap(self::STATUS_OK, array("unread" => getGlobalUnread())); } } /* Method added for ttrss-reader for Android */ function getCounters() { - print $this->wrap(self::STATUS_OK, getAllCounters($this->link)); + print $this->wrap(self::STATUS_OK, getAllCounters()); } function getFeeds() { - $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]); + $cat_id = db_escape_string( $_REQUEST["cat_id"]); $unread_only = sql_bool_to_bool($_REQUEST["unread_only"]); - $limit = (int) db_escape_string($this->link, $_REQUEST["limit"]); - $offset = (int) db_escape_string($this->link, $_REQUEST["offset"]); + $limit = (int) db_escape_string( $_REQUEST["limit"]); + $offset = (int) db_escape_string( $_REQUEST["offset"]); $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]); - $feeds = $this->api_get_feeds($this->link, $cat_id, $unread_only, $limit, $offset, $include_nested); + $feeds = $this->api_get_feeds( $cat_id, $unread_only, $limit, $offset, $include_nested); print $this->wrap(self::STATUS_OK, $feeds); } @@ -134,7 +134,7 @@ class API extends Handler { else $nested_qpart = "true"; - $result = db_query($this->link, "SELECT + $result = db_query( "SELECT id, title, order_id, (SELECT COUNT(id) FROM ttrss_feeds WHERE ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds, @@ -149,10 +149,10 @@ class API extends Handler { while ($line = db_fetch_assoc($result)) { if ($include_empty || $line["num_feeds"] > 0 || $line["num_cats"] > 0) { - $unread = getFeedUnread($this->link, $line["id"], true); + $unread = getFeedUnread( $line["id"], true); if ($enable_nested) - $unread += getCategoryChildrenUnread($this->link, $line["id"]); + $unread += getCategoryChildrenUnread( $line["id"]); if ($unread || !$unread_only) { array_push($cats, array("id" => $line["id"], @@ -166,11 +166,11 @@ class API extends Handler { foreach (array(-2,-1,0) as $cat_id) { if ($include_empty || !$this->isCategoryEmpty($cat_id)) { - $unread = getFeedUnread($this->link, $cat_id, true); + $unread = getFeedUnread( $cat_id, true); if ($unread || !$unread_only) { array_push($cats, array("id" => $cat_id, - "title" => getCategoryTitle($this->link, $cat_id), + "title" => getCategoryTitle( $cat_id), "unread" => $unread)); } } @@ -180,22 +180,22 @@ class API extends Handler { } function getHeadlines() { - $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]); + $feed_id = db_escape_string( $_REQUEST["feed_id"]); if ($feed_id != "") { - $limit = (int)db_escape_string($this->link, $_REQUEST["limit"]); + $limit = (int)db_escape_string( $_REQUEST["limit"]); if (!$limit || $limit >= 60) $limit = 60; - $offset = (int)db_escape_string($this->link, $_REQUEST["skip"]); - $filter = db_escape_string($this->link, $_REQUEST["filter"]); + $offset = (int)db_escape_string( $_REQUEST["skip"]); + $filter = db_escape_string( $_REQUEST["filter"]); $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]); $show_excerpt = sql_bool_to_bool($_REQUEST["show_excerpt"]); $show_content = sql_bool_to_bool($_REQUEST["show_content"]); /* all_articles, unread, adaptive, marked, updated */ - $view_mode = db_escape_string($this->link, $_REQUEST["view_mode"]); + $view_mode = db_escape_string( $_REQUEST["view_mode"]); $include_attachments = sql_bool_to_bool($_REQUEST["include_attachments"]); - $since_id = (int)db_escape_string($this->link, $_REQUEST["since_id"]); + $since_id = (int)db_escape_string( $_REQUEST["since_id"]); $include_nested = sql_bool_to_bool($_REQUEST["include_nested"]); $sanitize_content = true; @@ -211,10 +211,10 @@ class API extends Handler { /* do not rely on params below */ - $search = db_escape_string($this->link, $_REQUEST["search"]); - $search_mode = db_escape_string($this->link, $_REQUEST["search_mode"]); + $search = db_escape_string( $_REQUEST["search"]); + $search_mode = db_escape_string( $_REQUEST["search_mode"]); - $headlines = $this->api_get_headlines($this->link, $feed_id, $limit, $offset, + $headlines = $this->api_get_headlines( $feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, $include_attachments, $since_id, $search, $search_mode, $include_nested, $sanitize_content); @@ -226,10 +226,10 @@ class API extends Handler { } function updateArticle() { - $article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric); - $mode = (int) db_escape_string($this->link, $_REQUEST["mode"]); - $data = db_escape_string($this->link, $_REQUEST["data"]); - $field_raw = (int)db_escape_string($this->link, $_REQUEST["field"]); + $article_ids = array_filter(explode(",", db_escape_string( $_REQUEST["article_ids"])), is_numeric); + $mode = (int) db_escape_string( $_REQUEST["mode"]); + $data = db_escape_string( $_REQUEST["data"]); + $field_raw = (int)db_escape_string( $_REQUEST["field"]); $field = ""; $set_to = ""; @@ -269,16 +269,16 @@ class API extends Handler { $article_ids = join(", ", $article_ids); - $result = db_query($this->link, "UPDATE ttrss_user_entries SET $field = $set_to $additional_fields WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]); + $result = db_query( "UPDATE ttrss_user_entries SET $field = $set_to $additional_fields WHERE ref_id IN ($article_ids) AND owner_uid = " . $_SESSION["uid"]); - $num_updated = db_affected_rows($this->link, $result); + $num_updated = db_affected_rows( $result); if ($num_updated > 0 && $field == "unread") { - $result = db_query($this->link, "SELECT DISTINCT feed_id FROM ttrss_user_entries + $result = db_query( "SELECT DISTINCT feed_id FROM ttrss_user_entries WHERE ref_id IN ($article_ids)"); while ($line = db_fetch_assoc($result)) { - ccache_update($this->link, $line["feed_id"], $_SESSION["uid"]); + ccache_update( $line["feed_id"], $_SESSION["uid"]); } } @@ -286,7 +286,7 @@ class API extends Handler { if (PUBSUBHUBBUB_HUB) { $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . - get_feed_access_key($this->link, -2, false); + get_feed_access_key( -2, false); $p = new Publisher(PUBSUBHUBBUB_HUB); $pubsub_result = $p->publish_update($rss_link); @@ -304,7 +304,7 @@ class API extends Handler { function getArticle() { - $article_id = join(",", array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_id"])), is_numeric)); + $article_id = join(",", array_filter(explode(",", db_escape_string( $_REQUEST["article_id"])), is_numeric)); $query = "SELECT id,title,link,content,cached_content,feed_id,comments,int_id, marked,unread,published,score, @@ -314,7 +314,7 @@ class API extends Handler { WHERE id IN ($article_id) AND ref_id = id AND owner_uid = " . $_SESSION["uid"] ; - $result = db_query($this->link, $query); + $result = db_query( $query); $articles = array(); @@ -322,13 +322,13 @@ class API extends Handler { while ($line = db_fetch_assoc($result)) { - $attachments = get_article_enclosures($this->link, $line['id']); + $attachments = get_article_enclosures( $line['id']); $article = array( "id" => $line["id"], "title" => $line["title"], "link" => $line["link"], - "labels" => get_article_labels($this->link, $line['id']), + "labels" => get_article_labels( $line['id']), "unread" => sql_bool_to_bool($line["unread"]), "marked" => sql_bool_to_bool($line["marked"]), "published" => sql_bool_to_bool($line["published"]), @@ -363,7 +363,7 @@ class API extends Handler { $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); - $result = db_query($this->link, "SELECT COUNT(*) AS cf FROM + $result = db_query( "SELECT COUNT(*) AS cf FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); $num_feeds = db_fetch_result($result, 0, "cf"); @@ -376,41 +376,41 @@ class API extends Handler { function updateFeed() { require_once "include/rssfuncs.php"; - $feed_id = (int) db_escape_string($this->link, $_REQUEST["feed_id"]); + $feed_id = (int) db_escape_string( $_REQUEST["feed_id"]); - update_rss_feed($this->link, $feed_id, true); + update_rss_feed( $feed_id, true); print $this->wrap(self::STATUS_OK, array("status" => "OK")); } function catchupFeed() { - $feed_id = db_escape_string($this->link, $_REQUEST["feed_id"]); - $is_cat = db_escape_string($this->link, $_REQUEST["is_cat"]); + $feed_id = db_escape_string( $_REQUEST["feed_id"]); + $is_cat = db_escape_string( $_REQUEST["is_cat"]); - catchup_feed($this->link, $feed_id, $is_cat); + catchup_feed( $feed_id, $is_cat); print $this->wrap(self::STATUS_OK, array("status" => "OK")); } function getPref() { - $pref_name = db_escape_string($this->link, $_REQUEST["pref_name"]); + $pref_name = db_escape_string( $_REQUEST["pref_name"]); - print $this->wrap(self::STATUS_OK, array("value" => get_pref($this->link, $pref_name))); + print $this->wrap(self::STATUS_OK, array("value" => get_pref( $pref_name))); } function getLabels() { - //$article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric); + //$article_ids = array_filter(explode(",", db_escape_string( $_REQUEST["article_ids"])), is_numeric); $article_id = (int)$_REQUEST['article_id']; $rv = array(); - $result = db_query($this->link, "SELECT id, caption, fg_color, bg_color + $result = db_query( "SELECT id, caption, fg_color, bg_color FROM ttrss_labels2 WHERE owner_uid = '".$_SESSION['uid']."' ORDER BY caption"); if ($article_id) - $article_labels = get_article_labels($this->link, $article_id); + $article_labels = get_article_labels( $article_id); else $article_labels = array(); @@ -437,11 +437,11 @@ class API extends Handler { function setArticleLabel() { - $article_ids = array_filter(explode(",", db_escape_string($this->link, $_REQUEST["article_ids"])), is_numeric); - $label_id = (int) db_escape_string($this->link, $_REQUEST['label_id']); - $assign = (bool) db_escape_string($this->link, $_REQUEST['assign']) == "true"; + $article_ids = array_filter(explode(",", db_escape_string( $_REQUEST["article_ids"])), is_numeric); + $label_id = (int) db_escape_string( $_REQUEST['label_id']); + $assign = (bool) db_escape_string( $_REQUEST['assign']) == "true"; - $label = db_escape_string($this->link, label_find_caption($this->link, + $label = db_escape_string( label_find_caption( $label_id, $_SESSION["uid"])); $num_updated = 0; @@ -451,9 +451,9 @@ class API extends Handler { foreach ($article_ids as $id) { if ($assign) - label_add_article($this->link, $id, $label, $_SESSION["uid"]); + label_add_article( $id, $label, $_SESSION["uid"]); else - label_remove_article($this->link, $id, $label, $_SESSION["uid"]); + label_remove_article( $id, $label, $_SESSION["uid"]); ++$num_updated; @@ -481,25 +481,25 @@ class API extends Handler { } function shareToPublished() { - $title = db_escape_string($this->link, strip_tags($_REQUEST["title"])); - $url = db_escape_string($this->link, strip_tags($_REQUEST["url"])); - $content = db_escape_string($this->link, strip_tags($_REQUEST["content"])); + $title = db_escape_string( strip_tags($_REQUEST["title"])); + $url = db_escape_string( strip_tags($_REQUEST["url"])); + $content = db_escape_string( strip_tags($_REQUEST["content"])); - if (Article::create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) { + if (Article::create_published_article( $title, $url, $content, "", $_SESSION["uid"])) { print $this->wrap(self::STATUS_OK, array("status" => 'OK')); } else { print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); } } - static function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) { + static function api_get_feeds( $cat_id, $unread_only, $limit, $offset, $include_nested = false) { $feeds = array(); /* Labels */ if ($cat_id == -4 || $cat_id == -2) { - $counters = getLabelCounters($link, true); + $counters = getLabelCounters( true); foreach (array_values($counters) as $cv) { @@ -523,10 +523,10 @@ class API extends Handler { if ($cat_id == -4 || $cat_id == -1) { foreach (array(-1, -2, -3, -4, -6, 0) as $i) { - $unread = getFeedUnread($link, $i); + $unread = getFeedUnread( $i); if ($unread || !$unread_only) { - $title = getFeedTitle($link, $i); + $title = getFeedTitle( $i); $row = array( "id" => $i, @@ -543,14 +543,14 @@ class API extends Handler { /* Child cats */ if ($include_nested && $cat_id) { - $result = db_query($link, "SELECT + $result = db_query( "SELECT id, title FROM ttrss_feed_categories WHERE parent_cat = '$cat_id' AND owner_uid = " . $_SESSION["uid"] . " ORDER BY id, title"); while ($line = db_fetch_assoc($result)) { - $unread = getFeedUnread($link, $line["id"], true) + - getCategoryChildrenUnread($link, $line["id"]); + $unread = getFeedUnread( $line["id"], true) + + getCategoryChildrenUnread( $line["id"]); if ($unread || !$unread_only) { $row = array( @@ -573,7 +573,7 @@ class API extends Handler { } if ($cat_id == -4 || $cat_id == -3) { - $result = db_query($link, "SELECT + $result = db_query( "SELECT id, feed_url, cat_id, title, order_id, ". SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] . @@ -585,7 +585,7 @@ class API extends Handler { else $cat_qpart = "cat_id IS NULL"; - $result = db_query($link, "SELECT + $result = db_query( "SELECT id, feed_url, cat_id, title, order_id, ". SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE @@ -595,7 +595,7 @@ class API extends Handler { while ($line = db_fetch_assoc($result)) { - $unread = getFeedUnread($link, $line["id"]); + $unread = getFeedUnread( $line["id"]); $has_icon = feed_has_icon($line['id']); @@ -619,13 +619,13 @@ class API extends Handler { return $feeds; } - static function api_get_headlines($link, $feed_id, $limit, $offset, + static function api_get_headlines( $feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, $search = "", $search_mode = "", $include_nested = false, $sanitize_content = true) { - $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, + $qfh_ret = queryFeedHeadlines( $feed_id, $limit, $view_mode, $is_cat, $search, $search_mode, $order, $offset, 0, false, $since_id, $include_nested); @@ -641,8 +641,8 @@ class API extends Handler { $tags = explode(",", $line["tag_cache"]); $labels = json_decode($line["label_cache"], true); - //if (!$tags) $tags = get_article_tags($link, $line["id"]); - //if (!$labels) $labels = get_article_labels($link, $line["id"]); + //if (!$tags) $tags = get_article_tags( $line["id"]); + //if (!$labels) $labels = get_article_labels( $line["id"]); $headline_row = array( "id" => (int)$line["id"], @@ -658,7 +658,7 @@ class API extends Handler { ); if ($include_attachments) - $headline_row['attachments'] = get_article_enclosures($link, + $headline_row['attachments'] = get_article_enclosures( $line['id']); if ($show_excerpt) { @@ -673,7 +673,7 @@ class API extends Handler { } if ($sanitize_content) { - $headline_row["content"] = sanitize($link, + $headline_row["content"] = sanitize( $line["content_preview"], sql_bool_to_bool($line['hide_images']), false, $line["site_url"]); @@ -709,13 +709,13 @@ class API extends Handler { } function unsubscribeFeed() { - $feed_id = (int) db_escape_string($this->link, $_REQUEST["feed_id"]); + $feed_id = (int) db_escape_string( $_REQUEST["feed_id"]); - $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + $result = db_query( "SELECT id FROM ttrss_feeds WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); if (db_num_rows($result) != 0) { - Pref_Feeds::remove_feed($this->link, $feed_id, $_SESSION["uid"]); + Pref_Feeds::remove_feed( $feed_id, $_SESSION["uid"]); print $this->wrap(self::STATUS_OK, array("status" => "OK")); } else { print $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND")); @@ -723,13 +723,13 @@ class API extends Handler { } function subscribeToFeed() { - $feed_url = db_escape_string($this->link, $_REQUEST["feed_url"]); - $category_id = (int) db_escape_string($this->link, $_REQUEST["category_id"]); - $login = db_escape_string($this->link, $_REQUEST["login"]); - $password = db_escape_string($this->link, $_REQUEST["password"]); + $feed_url = db_escape_string( $_REQUEST["feed_url"]); + $category_id = (int) db_escape_string( $_REQUEST["category_id"]); + $login = db_escape_string( $_REQUEST["login"]); + $password = db_escape_string( $_REQUEST["password"]); if ($feed_url) { - $rc = subscribe_to_feed($this->link, $feed_url, $category_id, + $rc = subscribe_to_feed( $feed_url, $category_id, $login, $password, false); print $this->wrap(self::STATUS_OK, array("status" => $rc)); @@ -741,7 +741,7 @@ class API extends Handler { function getFeedTree() { $include_empty = sql_bool_to_bool($_REQUEST['include_empty']); - $pf = new Pref_Feeds($this->link, $_REQUEST); + $pf = new Pref_Feeds( $_REQUEST); $_REQUEST['mode'] = 2; $_REQUEST['force_show_empty'] = $include_empty; @@ -760,13 +760,13 @@ class API extends Handler { private function isCategoryEmpty($id) { if ($id == -2) { - $result = db_query($this->link, "SELECT COUNT(*) AS count FROM ttrss_labels2 + $result = db_query( "SELECT COUNT(*) AS count FROM ttrss_labels2 WHERE owner_uid = " . $_SESSION["uid"]); return db_fetch_result($result, 0, "count") == 0; } else if ($id == 0) { - $result = db_query($this->link, "SELECT COUNT(*) AS count FROM ttrss_feeds + $result = db_query( "SELECT COUNT(*) AS count FROM ttrss_feeds WHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"]); return db_fetch_result($result, 0, "count") == 0; diff --git a/classes/article.php b/classes/article.php index f31a225d..9917d4d0 100644 --- a/classes/article.php +++ b/classes/article.php @@ -8,9 +8,9 @@ class Article extends Handler_Protected { } function redirect() { - $id = db_escape_string($this->link, $_REQUEST['id']); + $id = db_escape_string( $_REQUEST['id']); - $result = db_query($this->link, "SELECT link FROM ttrss_entries, ttrss_user_entries + $result = db_query( "SELECT link FROM ttrss_entries, ttrss_user_entries WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' LIMIT 1"); @@ -27,10 +27,10 @@ class Article extends Handler_Protected { } function view() { - $id = db_escape_string($this->link, $_REQUEST["id"]); - $cids = explode(",", db_escape_string($this->link, $_REQUEST["cids"])); - $mode = db_escape_string($this->link, $_REQUEST["mode"]); - $omode = db_escape_string($this->link, $_REQUEST["omode"]); + $id = db_escape_string( $_REQUEST["id"]); + $cids = explode(",", db_escape_string( $_REQUEST["cids"])); + $mode = db_escape_string( $_REQUEST["mode"]); + $omode = db_escape_string( $_REQUEST["omode"]); // in prefetch mode we only output requested cids, main article // just gets marked as read (it already exists in client cache) @@ -38,26 +38,26 @@ class Article extends Handler_Protected { $articles = array(); if ($mode == "") { - array_push($articles, format_article($this->link, $id, false)); + array_push($articles, format_article( $id, false)); } else if ($mode == "zoom") { - array_push($articles, format_article($this->link, $id, true, true)); + array_push($articles, format_article( $id, true, true)); } else if ($mode == "raw") { if ($_REQUEST['html']) { header("Content-Type: text/html"); print ''; } - $article = format_article($this->link, $id, false); + $article = format_article( $id, false); print $article['content']; return; } - $this->catchupArticleById($this->link, $id, 0); + $this->catchupArticleById( $id, 0); if (!$_SESSION["bw_limit"]) { foreach ($cids as $cid) { if ($cid) { - array_push($articles, format_article($this->link, $cid, false, false)); + array_push($articles, format_article( $cid, false, false)); } } } @@ -65,27 +65,27 @@ class Article extends Handler_Protected { print json_encode($articles); } - private function catchupArticleById($link, $id, $cmode) { + private function catchupArticleById( $id, $cmode) { if ($cmode == 0) { - db_query($link, "UPDATE ttrss_user_entries SET + db_query( "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } else if ($cmode == 1) { - db_query($link, "UPDATE ttrss_user_entries SET + db_query( "UPDATE ttrss_user_entries SET unread = true WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } else { - db_query($link, "UPDATE ttrss_user_entries SET + db_query( "UPDATE ttrss_user_entries SET unread = NOT unread,last_read = NOW() WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } - $feed_id = getArticleFeed($link, $id); - ccache_update($link, $feed_id, $_SESSION["uid"]); + $feed_id = getArticleFeed( $id); + ccache_update( $feed_id, $_SESSION["uid"]); } - static function create_published_article($link, $title, $url, $content, $labels_str, + static function create_published_article( $title, $url, $content, $labels_str, $owner_uid) { $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash @@ -104,30 +104,30 @@ class Article extends Handler_Protected { if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; - db_query($link, "BEGIN"); + db_query( "BEGIN"); // only check for our user data here, others might have shared this with different content etc - $result = db_query($link, "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE + $result = db_query( "SELECT id FROM ttrss_entries, ttrss_user_entries WHERE link = '$url' AND ref_id = id AND owner_uid = '$owner_uid' LIMIT 1"); if (db_num_rows($result) != 0) { $ref_id = db_fetch_result($result, 0, "id"); - $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE + $result = db_query( "SELECT int_id FROM ttrss_user_entries WHERE ref_id = '$ref_id' AND owner_uid = '$owner_uid' LIMIT 1"); if (db_num_rows($result) != 0) { $int_id = db_fetch_result($result, 0, "int_id"); - db_query($link, "UPDATE ttrss_entries SET + db_query( "UPDATE ttrss_entries SET content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'"); - db_query($link, "UPDATE ttrss_user_entries SET published = true, + db_query( "UPDATE ttrss_user_entries SET published = true, last_published = NOW() WHERE int_id = '$int_id' AND owner_uid = '$owner_uid'"); } else { - db_query($link, "INSERT INTO ttrss_user_entries + db_query( "INSERT INTO ttrss_user_entries (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread, last_published) VALUES @@ -136,24 +136,24 @@ class Article extends Handler_Protected { if (count($labels) != 0) { foreach ($labels as $label) { - label_add_article($link, $ref_id, trim($label), $owner_uid); + label_add_article( $ref_id, trim($label), $owner_uid); } } $rc = true; } else { - $result = db_query($link, "INSERT INTO ttrss_entries + $result = db_query( "INSERT INTO ttrss_entries (title, guid, link, updated, content, content_hash, date_entered, date_updated) VALUES ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())"); - $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'"); + $result = db_query( "SELECT id FROM ttrss_entries WHERE guid = '$guid'"); if (db_num_rows($result) != 0) { $ref_id = db_fetch_result($result, 0, "id"); - db_query($link, "INSERT INTO ttrss_user_entries + db_query( "INSERT INTO ttrss_user_entries (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread, last_published) VALUES @@ -161,7 +161,7 @@ class Article extends Handler_Protected { if (count($labels) != 0) { foreach ($labels as $label) { - label_add_article($link, $ref_id, trim($label), $owner_uid); + label_add_article( $ref_id, trim($label), $owner_uid); } } @@ -169,7 +169,7 @@ class Article extends Handler_Protected { } } - db_query($link, "COMMIT"); + db_query( "COMMIT"); return $rc; } @@ -178,9 +178,9 @@ class Article extends Handler_Protected { print __("Tags for this article (separated by commas):")."
"; - $param = db_escape_string($this->link, $_REQUEST['param']); + $param = db_escape_string( $_REQUEST['param']); - $tags = get_article_tags($this->link, db_escape_string($this->link, $param)); + $tags = get_article_tags( db_escape_string( $param)); $tags_str = join(", ", $tags); @@ -209,10 +209,10 @@ class Article extends Handler_Protected { } function setScore() { - $ids = db_escape_string($this->link, $_REQUEST['id']); - $score = (int)db_escape_string($this->link, $_REQUEST['score']); + $ids = db_escape_string( $_REQUEST['id']); + $score = (int)db_escape_string( $_REQUEST['score']); - db_query($this->link, "UPDATE ttrss_user_entries SET + db_query( "UPDATE ttrss_user_entries SET score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); print json_encode(array("id" => $id, @@ -222,14 +222,14 @@ class Article extends Handler_Protected { function setArticleTags() { - $id = db_escape_string($this->link, $_REQUEST["id"]); + $id = db_escape_string( $_REQUEST["id"]); - $tags_str = db_escape_string($this->link, $_REQUEST["tags_str"]); + $tags_str = db_escape_string( $_REQUEST["tags_str"]); $tags = array_unique(trim_array(explode(",", $tags_str))); - db_query($this->link, "BEGIN"); + db_query( "BEGIN"); - $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE + $result = db_query( "SELECT int_id FROM ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); if (db_num_rows($result) == 1) { @@ -238,7 +238,7 @@ class Article extends Handler_Protected { $int_id = db_fetch_result($result, 0, "int_id"); - db_query($this->link, "DELETE FROM ttrss_tags WHERE + db_query( "DELETE FROM ttrss_tags WHERE post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); foreach ($tags as $tag) { @@ -255,7 +255,7 @@ class Article extends Handler_Protected { // print ""; if ($tag != '') { - db_query($this->link, "INSERT INTO ttrss_tags + db_query( "INSERT INTO ttrss_tags (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); } @@ -267,14 +267,14 @@ class Article extends Handler_Protected { sort($tags_to_cache); $tags_str = join(",", $tags_to_cache); - db_query($this->link, "UPDATE ttrss_user_entries + db_query( "UPDATE ttrss_user_entries SET tag_cache = '$tags_str' WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); } - db_query($this->link, "COMMIT"); + db_query( "COMMIT"); - $tags = get_article_tags($this->link, $id); + $tags = get_article_tags( $id); $tags_str = format_tags_string($tags, $id); $tags_str_full = join(", ", $tags); @@ -286,9 +286,9 @@ class Article extends Handler_Protected { function completeTags() { - $search = db_escape_string($this->link, $_REQUEST["search"]); + $search = db_escape_string( $_REQUEST["search"]); - $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags + $result = db_query( "SELECT DISTINCT tag_name FROM ttrss_tags WHERE owner_uid = '".$_SESSION["uid"]."' AND tag_name LIKE '$search%' ORDER BY tag_name LIMIT 10"); @@ -311,10 +311,10 @@ class Article extends Handler_Protected { private function labelops($assign) { $reply = array(); - $ids = explode(",", db_escape_string($this->link, $_REQUEST["ids"])); - $label_id = db_escape_string($this->link, $_REQUEST["lid"]); + $ids = explode(",", db_escape_string( $_REQUEST["ids"])); + $label_id = db_escape_string( $_REQUEST["lid"]); - $label = db_escape_string($this->link, label_find_caption($this->link, $label_id, + $label = db_escape_string( label_find_caption( $label_id, $_SESSION["uid"])); $reply["info-for-headlines"] = array(); @@ -324,11 +324,11 @@ class Article extends Handler_Protected { foreach ($ids as $id) { if ($assign) - label_add_article($this->link, $id, $label, $_SESSION["uid"]); + label_add_article( $id, $label, $_SESSION["uid"]); else - label_remove_article($this->link, $id, $label, $_SESSION["uid"]); + label_remove_article( $id, $label, $_SESSION["uid"]); - $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); + $labels = get_article_labels( $id, $_SESSION["uid"]); array_push($reply["info-for-headlines"], array("id" => $id, "labels" => format_article_labels($labels, $id))); diff --git a/classes/auth/base.php b/classes/auth/base.php index ad7ff364..c2a6bd70 100644 --- a/classes/auth/base.php +++ b/classes/auth/base.php @@ -1,9 +1,9 @@ link = $link; + function __construct($dbh) { + $this->dbh = $dbh; } function check_password($owner_uid, $password) { @@ -21,7 +21,7 @@ class Auth_Base { $user_id = $this->find_user_by_login($login); if (!$user_id) { - $login = db_escape_string($this->link, $login); + $login = db_escape_string( $login); $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $pwd_hash = encrypt_password($password, $salt, true); @@ -29,7 +29,7 @@ class Auth_Base { (login,access_level,last_login,created,pwd_hash,salt) VALUES ('$login', 0, null, NOW(), '$pwd_hash','$salt')"; - db_query($this->link, $query); + db_query( $query); return $this->find_user_by_login($login); @@ -42,9 +42,9 @@ class Auth_Base { } function find_user_by_login($login) { - $login = db_escape_string($this->link, $login); + $login = db_escape_string( $login); - $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + $result = db_query( "SELECT id FROM ttrss_users WHERE login = '$login'"); if (db_num_rows($result) > 0) { diff --git a/classes/backend.php b/classes/backend.php index c03d583d..a0416810 100644 --- a/classes/backend.php +++ b/classes/backend.php @@ -11,7 +11,7 @@ class Backend extends Handler { require_once "digest.php"; - $rv = prepare_headlines_digest($this->link, $_SESSION['uid'], 1, 1000); + $rv = prepare_headlines_digest( $_SESSION['uid'], 1, 1000); $rv[3] = "
" . $rv[3] . "
"; @@ -19,8 +19,8 @@ class Backend extends Handler { } private function display_main_help() { - $info = get_hotkeys_info($this->link); - $imap = get_hotkeys_map($this->link); + $info = get_hotkeys_info(); + $imap = get_hotkeys_map(); $omap = array(); foreach ($imap[1] as $sequence => $action) { diff --git a/classes/db.php b/classes/db.php index c3b62709..6dc31a22 100644 --- a/classes/db.php +++ b/classes/db.php @@ -36,7 +36,7 @@ class Db implements IDb { function connect($host, $user, $pass, $db, $port) { //return $this->adapter->connect($host, $user, $pass, $db, $port); - return $this->link; + return ; } function escape_string($s, $strip_tags = true) { diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php index bafd54ab..0cb73797 100644 --- a/classes/db/pgsql.php +++ b/classes/db/pgsql.php @@ -31,11 +31,11 @@ class Db_Pgsql implements IDb { function escape_string($s, $strip_tags = true) { if ($strip_tags) $s = strip_tags($s); - return pg_escape_string($this->link, $s); + return pg_escape_string( $s); } function query($query, $die_on_error = true) { - $result = pg_query($this->link, $query); + $result = pg_query( $query); if (!$result) { $query = htmlspecialchars($query); // just in case diff --git a/classes/dbupdater.php b/classes/dbupdater.php index a9a71327..ffcac7cf 100644 --- a/classes/dbupdater.php +++ b/classes/dbupdater.php @@ -1,18 +1,18 @@ link = $link; + function __construct($dbh, $db_type, $need_version) { + $this->dbh = $dbh; $this->db_type = $db_type; $this->need_version = (int) $need_version; } function getSchemaVersion() { - $result = db_query($this->link, "SELECT schema_version FROM ttrss_version"); + $result = db_query( "SELECT schema_version FROM ttrss_version"); return (int) db_fetch_result($result, 0, "schema_version"); } @@ -37,21 +37,21 @@ class DbUpdater { if (is_array($lines)) { - db_query($this->link, "BEGIN"); + db_query( "BEGIN"); foreach ($lines as $line) { if (strpos($line, "--") !== 0 && $line) { - db_query($this->link, $line); + db_query( $line); } } $db_version = $this->getSchemaVersion(); if ($db_version == $version) { - db_query($this->link, "COMMIT"); + db_query( "COMMIT"); return true; } else { - db_query($this->link, "ROLLBACK"); + db_query( "ROLLBACK"); return false; } } else { diff --git a/classes/dlg.php b/classes/dlg.php index e56560a4..99cd7cff 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -6,7 +6,7 @@ class Dlg extends Handler_Protected { if (parent::before($method)) { header("Content-Type: text/html"); # required for iframe - $this->param = db_escape_string($this->link, $_REQUEST["param"]); + $this->param = db_escape_string( $_REQUEST["param"]); return true; } return false; @@ -18,15 +18,15 @@ class Dlg extends Handler_Protected { print "
"; $owner_uid = $_SESSION["uid"]; - db_query($this->link, "BEGIN"); + db_query( "BEGIN"); print ""; print "
"; @@ -43,7 +43,7 @@ class Dlg extends Handler_Protected { } function pubOPMLUrl() { - $url_path = Opml::opml_publish_url($this->link); + $url_path = Opml::opml_publish_url(); print __("Your Public OPML URL is:"); @@ -106,7 +106,7 @@ class Dlg extends Handler_Protected { FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." GROUP BY tag_name ORDER BY count DESC LIMIT 50"; - $result = db_query($this->link, $query); + $result = db_query( $query); $tags = array(); @@ -171,7 +171,7 @@ class Dlg extends Handler_Protected { print "