]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
remove nonworking article zoom buttons (closes #535)
[tt-rss.git] / include / functions.php
index 14b3af517848dc33702fa580345b3cfbadf2ea6d..7409ec76a688fa0d910932ea1a1d6a38d5f869cb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 99);
+       define('SCHEMA_VERSION', 102);
 
        $fetch_last_error = false;
        $pluginhost = false;
@@ -63,6 +63,7 @@
        require_once "lib/accept-to-gettext.php";
        require_once "lib/gettext/gettext.inc";
 
+
        function startup_gettext() {
 
                # Get locale from Accept-Language header
@@ -75,7 +76,7 @@
                /* In login action of mobile version */
                if ($_POST["language"] && defined('MOBILE_VERSION')) {
                        $lang = $_POST["language"];
-               } else {
+               } else if ($_SESSION["language"] && $_SESSION["language"] != "auto") {
                        $lang = $_SESSION["language"];
                }
 
 
        require_once 'db-prefs.php';
        require_once 'version.php';
+       require_once 'ccache.php';
+       require_once 'labels.php';
 
        ini_set('user_agent', SELF_USER_AGENT);
 
                if (!SINGLE_USER_MODE) {
 
                        $user_id = false;
-                       $modules = explode(",", AUTH_MODULES);
 
-                       foreach ($modules as $module) {
-                               $module_class = "auth_$module";
-                               if (class_exists($module_class)) {
-                                       $authenticator = new $module_class($link);
-
-                                       $user_id = (int) $authenticator->authenticate($login, $password);
+                       global $pluginhost;
+                       foreach ($pluginhost->get_hooks($pluginhost::HOOK_AUTH_USER) as $plugin) {
 
-                                       if ($user_id) {
-                                               $_SESSION["auth_module"] = $module;
-                                               break;
-                                       }
+                               $user_id = (int) $plugin->authenticate($login, $password);
 
-                               } else {
-                                       print T_sprintf("Fatal: authentication module %s not found.", $module);
-                                       die;
+                               if ($user_id) {
+                                       $_SESSION["auth_module"] = strtolower(get_class($plugin));
+                                       break;
                                }
                        }
 
                return true;
        }
 
+       function load_user_plugins($link, $owner_uid) {
+               if ($owner_uid) {
+                       $plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
+
+                       global $pluginhost;
+                       $pluginhost->load($plugins, $pluginhost::KIND_USER, $owner_uid);
+
+                       if (get_schema_version($link) > 100) {
+                               $pluginhost->load_data();
+                       }
+               }
+       }
+
        function login_sequence($link, $login_form = 0) {
+               $_SESSION["prefs_cache"] = false;
+
                if (SINGLE_USER_MODE) {
-                       return authenticate_user($link, "admin", null);
+                       authenticate_user($link, "admin", null);
+                       load_user_plugins($link, $_SESSION["uid"]);
                } else {
                        if (!$_SESSION["uid"] || !validate_session($link)) {
 
                                setcookie("ttrss_lang", $_SESSION["language"],
                                        time() + SESSION_COOKIE_LIFETIME);
                        }
+
+                       if ($_SESSION["uid"]) {
+                               load_user_plugins($link, $_SESSION["uid"]);
+                       }
                }
        }
 
                }
        }
 
+       // Deprecated, TODO: remove
        function theme_image($link, $filename) {
-               if ($link) {
-                       $theme_path = get_user_theme_path($link);
-
-                       if ($theme_path && is_file($theme_path.$filename)) {
-                               return $theme_path.$filename;
-                       } else {
-                               return $filename;
-                       }
-               } else {
-                       return $filename;
-               }
-       }
-
-       function get_user_theme($link) {
-
-               if (get_schema_version($link) >= 63 && $_SESSION["uid"]) {
-                       $theme_name = get_pref($link, "_THEME_ID");
-                       if (is_dir("themes/$theme_name")) {
-                               return $theme_name;
-                       } else {
-                               return '';
-                       }
-               } else {
-                       return '';
-               }
-
-       }
-
-       function get_user_theme_path($link) {
-               $theme_path = '';
-
-               if (get_schema_version($link) >= 63 && $_SESSION["uid"]) {
-                       $theme_name = get_pref($link, "_THEME_ID");
-
-                       if ($theme_name && is_dir("themes/$theme_name")) {
-                               $theme_path = "themes/$theme_name/";
-                       } else {
-                               $theme_name = '';
-                       }
-               } else {
-                       $theme_path = '';
-               }
-
-               if ($theme_path) {
-                       if (is_file("$theme_path/theme.ini")) {
-                               $ini = parse_ini_file("$theme_path/theme.ini", true);
-                               if ($ini['theme']['version'] >= THEME_VERSION_REQUIRED) {
-                                       return $theme_path;
-                               }
-                       }
-               }
-               return '';
-       }
-
-       function get_user_theme_options($link) {
-               $t = get_user_theme_path($link);
-
-               if ($t) {
-                       if (is_file("$t/theme.ini")) {
-                               $ini = parse_ini_file("$t/theme.ini", true);
-                               if ($ini['theme']['version']) {
-                                       return $ini['theme']['options'];
-                               }
-                       }
-               }
-               return '';
-       }
-
-       function print_theme_includes($link) {
-
-               $t = get_user_theme_path($link);
-               $time = time();
-
-               if ($t) {
-                       print "<link rel=\"stylesheet\" type=\"text/css\"
-                               href=\"$t/theme.css?$time \">";
-                       if (file_exists("$t/theme.js")) {
-                               print "<script type=\"text/javascript\" src=\"$t/theme.js?$time\">
-                                       </script>";
-                       }
-               }
-       }
-
-       function get_all_themes() {
-               $themes = glob("themes/*");
-
-               asort($themes);
-
-               $rv = array();
-
-               foreach ($themes as $t) {
-                       if (is_file("$t/theme.ini")) {
-                               $ini = parse_ini_file("$t/theme.ini", true);
-                               if ($ini['theme']['version'] >= THEME_VERSION_REQUIRED &&
-                                                       !$ini['theme']['disabled']) {
-                                       $entry = array();
-                                       $entry["path"] = $t;
-                                       $entry["base"] = basename($t);
-                                       $entry["name"] = $ini['theme']['name'];
-                                       $entry["version"] = $ini['theme']['version'];
-                                       $entry["author"] = $ini['theme']['author'];
-                                       $entry["options"] = $ini['theme']['options'];
-                                       array_push($rv, $entry);
-                               }
-                       }
-               }
-
-               return $rv;
+               return $filename;
        }
 
        function convert_timestamp($timestamp, $source_tz, $dest_tz) {
                        }
        }
 
-       function getAllCounters($link, $omode = "flc", $active_feed = false) {
-
-               if (!$omode) $omode = "flc";
-
+       function getAllCounters($link) {
                $data = getGlobalCounters($link);
 
                $data = array_merge($data, getVirtCounters($link));
-
-               if (strchr($omode, "l")) $data = array_merge($data, getLabelCounters($link));
-               if (strchr($omode, "f")) $data = array_merge($data, getFeedCounters($link, $active_feed));
-               if (strchr($omode, "t")) $data = array_merge($data, getTagCounters($link));
-               if (strchr($omode, "c")) $data = array_merge($data, getCategoryCounters($link));
+               $data = array_merge($data, getLabelCounters($link));
+               $data = array_merge($data, getFeedCounters($link, $active_feed));
+               $data = array_merge($data, getCategoryCounters($link));
 
                return $data;
        }
                return $ret_arr;
        }
 
-       function getTagCounters($link) {
-
-               $ret_arr = array();
-
-               $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
-                       FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
-                               AND ref_id = id AND unread = true)) AS count FROM ttrss_tags
-                               WHERE owner_uid = ".$_SESSION['uid']." GROUP BY tag_name
-                               ORDER BY count DESC LIMIT 55");
-
-               $tags = array();
-
-               while ($line = db_fetch_assoc($result)) {
-                       $tags[$line["tag_name"]] += $line["count"];
-               }
-
-               foreach (array_keys($tags) as $tag) {
-                       $unread = $tags[$tag];
-                       $tag = htmlspecialchars($tag);
-
-                       $cv = array("id" => $tag,
-                               "kind" => "tag",
-                               "counter" => $unread);
-
-                       array_push($ret_arr, $cv);
-               }
-
-               return $ret_arr;
-       }
-
        function getVirtCounters($link) {
 
                $ret_arr = array();
                        return "images/archive.png";
                        break;
                case -1:
-                       return "images/mark_set.png";
+                       return "images/mark_set.svg";
                        break;
                case -2:
-                       return "images/pub_set.png";
+                       return "images/pub_set.svg";
                        break;
                case -3:
                        return "images/fresh.png";
        function make_init_params($link) {
                $params = array();
 
-               $params["theme"] = get_user_theme($link);
-               $params["theme_options"] = get_user_theme_options($link);
-
                $params["sign_progress"] = theme_image($link, "images/indicator_white.gif");
                $params["sign_progress_tiny"] = theme_image($link, "images/indicator_tiny.gif");
-               $params["sign_excl"] = theme_image($link, "images/sign_excl.png");
-               $params["sign_info"] = theme_image($link, "images/sign_info.png");
+               $params["sign_excl"] = theme_image($link, "images/sign_excl.svg");
+               $params["sign_info"] = theme_image($link, "images/sign_info.svg");
 
                foreach (array("ON_CATCHUP_SHOW_NEXT_FEED", "HIDE_READ_FEEDS",
                        "ENABLE_FEED_CATS", "FEEDS_SORT_BY_UNREAD", "CONFIRM_FEED_CATCHUP",
                $params["num_feeds"] = (int) $num_feeds;
 
                $params["collapsed_feedlist"] = (int) get_pref($link, "_COLLAPSED_FEEDLIST");
+               $params["hotkeys"] = get_hotkeys_map($link);
 
                $params["csrf_token"] = $_SESSION["csrf_token"];
+               $params["widescreen"] = (int) $_SESSION["widescreen"];
+
+               $params['simple_update'] = defined('SIMPLE_UPDATE_MODE') && SIMPLE_UPDATE_MODE;
 
                return $params;
        }
 
+       function get_hotkeys_info($link) {
+               $hotkeys = array(
+                       __("Navigation") => array(
+                               "next_feed" => __("Open next feed"),
+                               "prev_feed" => __("Open previous feed"),
+                               "next_article" => __("Open next article"),
+                               "prev_article" => __("Open previous article"),
+                               "search_dialog" => __("Show search dialog")),
+                       __("Article") => array(
+                               "toggle_mark" => __("Toggle starred"),
+                               "toggle_publ" => __("Toggle published"),
+                               "toggle_unread" => __("Toggle unread"),
+                               "edit_tags" => __("Edit tags"),
+                               "dismiss_selected" => __("Dismiss selected"),
+                               "dismiss_read" => __("Dismiss read"),
+                               "open_in_new_window" => __("Open in new window"),
+                               "catchup_below" => __("Mark below as read"),
+                               "catchup_above" => __("Mark above as read"),
+                               "article_scroll_down" => __("Scroll down"),
+                               "article_scroll_up" => __("Scroll up"),
+                               "select_article_cursor" => __("Select article under cursor"),
+                               "email_article" => __("Email article"),
+                               "close_article" => __("Close article"),
+                               "toggle_widescreen" => __("Toggle widescreen mode")),
+                       __("Article selection") => array(
+                               "select_all" => __("Select all articles"),
+                               "select_unread" => __("Select unread"),
+                               "select_marked" => __("Select starred"),
+                               "select_published" => __("Select published"),
+                               "select_invert" => __("Invert selection"),
+                               "select_none" => __("Deselect everything")),
+                       __("Feed") => array(
+                               "feed_refresh" => __("Refresh current feed"),
+                               "feed_unhide_read" => __("Un/hide read feeds"),
+                               "feed_subscribe" => __("Subscribe to feed"),
+                               "feed_edit" => __("Edit feed"),
+                               "feed_catchup" => __("Mark as read"),
+                               "feed_reverse" => __("Reverse headlines"),
+                               "feed_debug_update" => __("Debug feed update"),
+                               "catchup_all" => __("Mark all feeds as read"),
+                               "cat_toggle_collapse" => __("Un/collapse current category")),
+                       __("Go to") => array(
+                               "goto_all" => __("All articles"),
+                               "goto_fresh" => __("Fresh"),
+                               "goto_marked" => __("Starred"),
+                               "goto_published" => __("Published"),
+                               "goto_tagcloud" => __("Tag cloud"),
+                               "goto_prefs" => __("Preferences")),
+                       __("Other") => array(
+                               "create_label" => __("Create label"),
+                               "create_filter" => __("Create filter"),
+                               "collapse_sidebar" => __("Un/collapse sidebar"),
+                               "help_dialog" => __("Show help dialog"))
+                       );
+
+               return $hotkeys;
+       }
+
+       function get_hotkeys_map($link) {
+               $hotkeys = array(
+//                     "navigation" => array(
+                               "k" => "next_feed",
+                               "j" => "prev_feed",
+                               "n" => "next_article",
+                               "p" => "prev_article",
+                               "(38)|up" => "prev_article",
+                               "(40)|down" => "next_article",
+                               "(191)|/" => "search_dialog",
+//                     "article" => array(
+                               "s" => "toggle_mark",
+                               "S" => "toggle_publ",
+                               "u" => "toggle_unread",
+                               "T" => "edit_tags",
+                               "D" => "dismiss_selected",
+                               "X" => "dismiss_read",
+                               "o" => "open_in_new_window",
+                               "c p" => "catchup_below",
+                               "c n" => "catchup_above",
+                               "N" => "article_scroll_down",
+                               "P" => "article_scroll_up",
+                               "a W" => "toggle_widescreen",
+                               "e" => "email_article",
+                               "a q" => "close_article",
+//                     "article_selection" => array(
+                               "a a" => "select_all",
+                               "a u" => "select_unread",
+                               "a U" => "select_marked",
+                               "a p" => "select_published",
+                               "a i" => "select_invert",
+                               "a n" => "select_none",
+//                     "feed" => array(
+                               "f r" => "feed_refresh",
+                               "f a" => "feed_unhide_read",
+                               "f s" => "feed_subscribe",
+                               "f e" => "feed_edit",
+                               "f q" => "feed_catchup",
+                               "f x" => "feed_reverse",
+                               "f D" => "feed_debug_update",
+                               "Q" => "catchup_all",
+                               "x" => "cat_toggle_collapse",
+//                     "goto" => array(
+                               "g a" => "goto_all",
+                               "g f" => "goto_fresh",
+                               "g s" => "goto_marked",
+                               "g p" => "goto_published",
+                               "g t" => "goto_tagcloud",
+                               "g P" => "goto_prefs",
+//                     "other" => array(
+                               "(9)|Tab" => "select_article_cursor", // tab
+                               "c l" => "create_label",
+                               "c f" => "create_filter",
+                               "c s" => "collapse_sidebar",
+                               "^(191)|Ctrl+/" => "help_dialog",
+                       );
+
+               global $pluginhost;
+               foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_MAP) as $plugin) {
+                       $hotkeys = $plugin->hook_hotkey_map($hotkeys);
+               }
+
+               $prefixes = array();
+
+               foreach (array_keys($hotkeys) as $hotkey) {
+                       $pair = explode(" ", $hotkey, 2);
+
+                       if (count($pair) > 1 && !in_array($pair[0], $prefixes)) {
+                               array_push($prefixes, $pair[0]);
+                       }
+               }
+
+               return array($prefixes, $hotkeys);
+       }
+
        function make_runtime_info($link) {
                $data = array();
 
                return $rv;
        }
 
-       function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false) {
+       function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                                $filter_query_part = filter_to_sql($link, $filter, $owner_uid);
 
                                // Try to check if SQL regexp implementation chokes on a valid regexp
-                               $result = db_query($link, "SELECT true AS true FROM ttrss_entries,
+                               $result = db_query($link, "SELECT true AS true_val FROM ttrss_entries,
                                        ttrss_user_entries, ttrss_feeds, ttrss_feed_categories
                                        WHERE $filter_query_part LIMIT 1", false);
 
-                               $test = db_fetch_result($result, 0, "true");
+                               $test = db_fetch_result($result, 0, "true_val");
 
                                if (!$test) {
                                        $filter_query_part = "false AND";
                                }
 
                                // proper override_order applied above
-                               if ($vfeed_query_part && get_pref($link, 'VFEED_GROUP_BY_FEED', $owner_uid)) {
+                               if ($vfeed_query_part && !$ignore_vfeed_group && get_pref($link, 'VFEED_GROUP_BY_FEED', $owner_uid)) {
                                        if (!$override_order) {
                                                $order_by = "ttrss_feeds.title, $order_by";
                                        } else {
 
                $res = trim($str); if (!$res) return '';
 
-               $config = array('safe' => 1, 'deny_attribute' => 'style, width, height, class, id', 'comment' => 1, 'cdata' => 1);
+               $config = array('safe' => 1, 'deny_attribute' => 'style, width, height, class, id', 'comment' => 1, 'cdata' => 1, 'balance' => 0);
                $res = htmLawed($res, $config);
 
                if (get_pref($link, "STRIP_IMAGES", $owner)) {
 
                $node = $doc->getElementsByTagName('body')->item(0);
 
+               // http://tt-rss.org/redmine/issues/357
                return $doc->saveXML($node, LIBXML_NOEMPTYTAG);
        }
 
                return false;
        }
 
-       function markArticlesById($link, $ids, $cmode) {
-
-               $tmp_ids = array();
-
-               foreach ($ids as $id) {
-                       array_push($tmp_ids, "ref_id = '$id'");
-               }
-
-               $ids_qpart = join(" OR ", $tmp_ids);
-
-               if ($cmode == 0) {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = false,last_read = NOW()
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               } else if ($cmode == 1) {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = true
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               } else {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       marked = NOT marked,last_read = NOW()
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               }
-       }
-
-       function publishArticlesById($link, $ids, $cmode) {
-
-               $tmp_ids = array();
-
-               foreach ($ids as $id) {
-                       array_push($tmp_ids, "ref_id = '$id'");
-               }
-
-               $ids_qpart = join(" OR ", $tmp_ids);
-
-               if ($cmode == 0) {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       published = false,last_read = NOW()
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               } else if ($cmode == 1) {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       published = true,last_read = NOW()
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               } else {
-                       db_query($link, "UPDATE ttrss_user_entries SET
-                       published = NOT published,last_read = NOW()
-                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
-               }
-
-               if (PUBSUBHUBBUB_HUB) {
-                       $rss_link = get_self_url_prefix() .
-                               "/public.php?op=rss&id=-2&key=" .
-                               get_feed_access_key($link, -2, false);
-
-                       $p = new Publisher(PUBSUBHUBBUB_HUB);
-
-                       $pubsub_result = $p->publish_update($rss_link);
-               }
-       }
-
        function catchupArticlesById($link, $ids, $cmode, $owner_uid = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
                }
        }
 
-       function catchupArticleById($link, $id, $cmode) {
-
-               if ($cmode == 0) {
-                       db_query($link, "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
-                       unread = true
-                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-               } else {
-                       db_query($link, "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"]);
-       }
-
-       function make_guid_from_title($title) {
-               return preg_replace("/[ \"\',.:;]/", "-",
-                       mb_strtolower(strip_tags($title), 'utf-8'));
-       }
-
        function get_article_tags($link, $id, $owner_uid = 0, $tag_cache = false) {
 
                $a_id = db_escape_string($id);
        function format_warning($msg, $id = "") {
                global $link;
                return "<div class=\"warning\" id=\"$id\">
-                       <img src=\"".theme_image($link, "images/sign_excl.png")."\">$msg</div>";
+                       <img src=\"".theme_image($link, "images/sign_excl.svg")."\">$msg</div>";
        }
 
        function format_notice($msg, $id = "") {
                global $link;
                return "<div class=\"notice\" id=\"$id\">
-                       <img src=\"".theme_image($link, "images/sign_info.png")."\">$msg</div>";
+                       <img src=\"".theme_image($link, "images/sign_info.svg")."\">$msg</div>";
        }
 
        function format_error($msg, $id = "") {
                global $link;
                return "<div class=\"error\" id=\"$id\">
-                       <img src=\"".theme_image($link, "images/sign_excl.png")."\">$msg</div>";
+                       <img src=\"".theme_image($link, "images/sign_excl.svg")."\">$msg</div>";
        }
 
        function print_notice($msg) {
 
                                $id = 'AUDIO-' . uniqid();
 
-                               $entry .= "<audio id=\"$id\"\">
-                                       <source src=\"$url\"></source>
+                               $entry .= "<audio id=\"$id\"\" controls>
+                                       <source type=\"$ctype\" src=\"$url\"></source>
                                        </audio>";
 
                                $entry .= "<span onclick=\"player(this)\"
                                                value=\"lib/button/musicplayer.swf?song_url=$url\" />
                                        </object>";
                        }
+
+                       if ($entry) $entry .= "&nbsp;" . basename($url);
+
+                       return $entry;
+
                }
 
-               $filename = substr($url, strrpos($url, "/")+1);
+               return "";
+
+/*             $filename = substr($url, strrpos($url, "/")+1);
 
                $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
-                       $filename . " (" . $ctype . ")" . "</a>";
+                       $filename . " (" . $ctype . ")" . "</a>"; */
 
-               return $entry;
        }
 
        function format_article($link, $id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
 
                $result = db_query($link, "SELECT id,title,link,content,feed_id,comments,int_id,
                        ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
-                       (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
                        (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
                        num_comments,
                        tag_cache,
 
                        $line = db_fetch_assoc($result);
 
-                       if ($line["icon_url"]) {
-                               $feed_icon = "<img src=\"" . $line["icon_url"] . "\">";
-                       } else {
-                               $feed_icon = "&nbsp;";
-                       }
-
                        $feed_site_url = $line['site_url'];
 
                        $num_comments = $line["num_comments"];
 
                        $title_escaped = htmlspecialchars($line['title']);
 
-                       $rv['content'] .= "<div id=\"PTITLE-$id\" style=\"display : none\">" .
-                               truncate_string(strip_tags($line['title']), 15) . "</div>";
-
                        $rv['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
                                strip_tags($line['title']) . "</div>";
 
                        $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">";
 
-                       $rv['content'] .= "<div onclick=\"return postClicked(event, $id)\"
-                               class=\"postHeader\" id=\"POSTHDR-$id\">";
+                       $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-$id\">";
 
                        $entry_author = $line["author"];
 
                                        id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
                                        position=\"below\">$tags_str_full</div>";
 
-                               $rv['content'] .= "<img src=\"".theme_image($link, 'images/art-zoom.png')."\"
-                                               class='tagsPic' style=\"cursor : pointer\"
-                                               onclick=\"postOpenInNewTab(event, $id)\"
-                                               alt='Zoom' title='".__('Open article in new tab')."'>";
-
                                global $pluginhost;
 
                                foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
                                        $rv['content'] .= $p->hook_article_button($line);
                                }
 
-                               $rv['content'] .= "<img src=\"".theme_image($link, 'images/digest_checkbox.png')."\"
-                                               class='tagsPic' style=\"cursor : pointer\"
-                                               onclick=\"closeArticlePanel($id)\"
-                                               title='".__('Close article')."'>";
 
                        } else {
                                $tags_str = strip_tags($tags_str);
                                        $rv['content'] .= "&nbsp;";
 
                                        $rv['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
-                                       $rv['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
+                                       $rv['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.svg'></a>";
 
                                        $rv['content'] .= "</div>";
                                }
 
                        $rv['content'] .= "<div id=\"POSTNOTE-$id\">";
                                if ($line['note']) {
-                                       $rv['content'] .= format_article_note($id, $line['note']);
+                                       $rv['content'] .= format_article_note($id, $line['note'], !$zoom_mode);
                                }
                        $rv['content'] .= "</div>";
 
-                       $rv['content'] .= "<div class=\"postIcon\">" .
-                               "<a target=\"_blank\" title=\"".__("Visit the website")."\"$
-                               href=\"".htmlspecialchars($feed_site_url)."\">".
-                               $feed_icon . "</a></div>";
-
                        $rv['content'] .= "<div class=\"postContent\">";
 
                        // N-grams
                }
        }
 
-       function opml_publish_url($link){
-
-               $url_path = get_self_url_prefix();
-               $url_path .= "/opml.php?op=publish&key=" .
-                       get_feed_access_key($link, 'OPML:Publish', false, $_SESSION["uid"]);
-
-               return $url_path;
-       }
-
-       /**
-        * 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
-        */
-       function clear_feed_articles($link, $id) {
-
-               if ($id != 0) {
-                       $result = db_query($link, "DELETE FROM ttrss_user_entries
-                       WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
-               } else {
-                       $result = db_query($link, "DELETE FROM ttrss_user_entries
-                       WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
-               }
-
-               $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']);
-       } // function clear_feed_articles
-
        /**
         * Compute the Mozilla Firefox feed adding URL from server HOST and REQUEST_URI.
         *
                        global $pluginhost;
 
                        $pluginhost = new PluginHost($link);
-                       $pluginhost->load(PLUGINS);
+                       $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
 
                        return true;
                } else {
                }
        }
 
-       /* function ccache_zero($link, $feed_id, $owner_uid) {
-               db_query($link, "UPDATE ttrss_counters_cache SET
-                       value = 0, updated = NOW() WHERE
-                       feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
-       } */
-
-       function ccache_zero_all($link, $owner_uid) {
-               db_query($link, "UPDATE ttrss_counters_cache SET
-                       value = 0 WHERE owner_uid = '$owner_uid'");
-
-               db_query($link, "UPDATE ttrss_cat_counters_cache SET
-                       value = 0 WHERE owner_uid = '$owner_uid'");
-       }
-
-       function ccache_remove($link, $feed_id, $owner_uid, $is_cat = false) {
-
-               if (!$is_cat) {
-                       $table = "ttrss_counters_cache";
-               } else {
-                       $table = "ttrss_cat_counters_cache";
-               }
+       function format_tags_string($tags, $id) {
 
-               db_query($link, "DELETE FROM $table WHERE
-                       feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
+               $tags_str = "";
+               $tags_nolinks_str = "";
 
-       }
+               $num_tags = 0;
 
-       function ccache_update_all($link, $owner_uid) {
+               $tag_limit = 6;
 
-               if (get_pref($link, 'ENABLE_FEED_CATS', $owner_uid)) {
+               $formatted_tags = array();
 
-                       $result = db_query($link, "SELECT feed_id FROM ttrss_cat_counters_cache
-                               WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
+               foreach ($tags as $tag) {
+                       $num_tags++;
+                       $tag_escaped = str_replace("'", "\\'", $tag);
 
-                       while ($line = db_fetch_assoc($result)) {
-                               ccache_update($link, $line["feed_id"], $owner_uid, true);
+                       if (mb_strlen($tag) > 30) {
+                               $tag = truncate_string($tag, 30);
                        }
 
-                       /* We have to manually include category 0 */
-
-                       ccache_update($link, 0, $owner_uid, true);
+                       $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>";
 
-               } else {
-                       $result = db_query($link, "SELECT feed_id FROM ttrss_counters_cache
-                               WHERE feed_id > 0 AND owner_uid = '$owner_uid'");
+                       array_push($formatted_tags, $tag_str);
 
-                       while ($line = db_fetch_assoc($result)) {
-                               print ccache_update($link, $line["feed_id"], $owner_uid);
+                       $tmp_tags_str = implode(", ", $formatted_tags);
 
+                       if ($num_tags == $tag_limit || mb_strlen($tmp_tags_str) > 150) {
+                               break;
                        }
-
                }
-       }
-
-       function ccache_find($link, $feed_id, $owner_uid, $is_cat = false,
-               $no_update = false) {
 
-               if (!is_numeric($feed_id)) return;
+               $tags_str = implode(", ", $formatted_tags);
 
-               if (!$is_cat) {
-                       $table = "ttrss_counters_cache";
-                       if ($feed_id > 0) {
-                               $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");
-                       }
-               } else {
-                       $table = "ttrss_cat_counters_cache";
+               if ($num_tags < count($tags)) {
+                       $tags_str .= ", &hellip;";
                }
 
-               if (DB_TYPE == "pgsql") {
-                       $date_qpart = "updated > NOW() - INTERVAL '15 minutes'";
-               } else if (DB_TYPE == "mysql") {
-                       $date_qpart = "updated > DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
+               if ($num_tags == 0) {
+                       $tags_str = __("no tags");
                }
 
-               $result = db_query($link, "SELECT value FROM $table
-                       WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id'
-                       LIMIT 1");
-
-               if (db_num_rows($result) == 1) {
-                       return db_fetch_result($result, 0, "value");
-               } else {
-                       if ($no_update) {
-                               return -1;
-                       } else {
-                               return ccache_update($link, $feed_id, $owner_uid, $is_cat);
-                       }
-               }
+               return $tags_str;
 
        }
 
-       function ccache_update($link, $feed_id, $owner_uid, $is_cat = false,
-               $update_pcat = true) {
+       function format_article_labels($labels, $id) {
 
-               if (!is_numeric($feed_id)) return;
+               $labels_str = "";
 
-               if (!$is_cat && $feed_id > 0) {
-                       $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");
-               }
+               foreach ($labels as $l) {
+                       $labels_str .= sprintf("<span class='hlLabelRef'
+                               style='color : %s; background-color : %s'>%s</span>",
+                                       $l[2], $l[3], $l[1]);
+                       }
 
-               $prev_unread = ccache_find($link, $feed_id, $owner_uid, $is_cat, true);
+               return $labels_str;
 
-               /* When updating a label, all we need to do is recalculate feed counters
-                * because labels are not cached */
+       }
 
-               if ($feed_id < 0) {
-                       ccache_update_all($link, $owner_uid);
-                       return;
-               }
+       function format_article_note($id, $note, $allow_edit = true) {
 
-               if (!$is_cat) {
-                       $table = "ttrss_counters_cache";
-               } else {
-                       $table = "ttrss_cat_counters_cache";
-               }
+               $str = "<div class='articleNote'        onclick=\"editArticleNote($id)\">
+                       <div class='noteEdit' onclick=\"editArticleNote($id)\">".
+                       ($allow_edit ? __('(edit note)') : "")."</div>$note</div>";
 
-               if ($is_cat && $feed_id >= 0) {
-                       if ($feed_id != 0) {
-                               $cat_qpart = "cat_id = '$feed_id'";
-                       } else {
-                               $cat_qpart = "cat_id IS NULL";
-                       }
+               return $str;
+       }
 
-                       /* Recalculate counters for child feeds */
+       function toggle_collapse_cat($link, $cat_id, $mode) {
+               if ($cat_id > 0) {
+                       $mode = bool_to_sql_bool($mode);
 
-                       $result = db_query($link, "SELECT id FROM ttrss_feeds
-                                               WHERE owner_uid = '$owner_uid' AND $cat_qpart");
-
-                       while ($line = db_fetch_assoc($result)) {
-                               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
-                               ttrss_feeds.owner_uid = '$owner_uid'");
-
-                       $unread = (int) db_fetch_result($result, 0, "sv");
-
-               } else {
-                       $unread = (int) getFeedArticles($link, $feed_id, $is_cat, true, $owner_uid);
-               }
-
-               db_query($link, "BEGIN");
-
-               $result = db_query($link, "SELECT feed_id FROM $table
-                       WHERE owner_uid = '$owner_uid' AND feed_id = '$feed_id' LIMIT 1");
-
-               if (db_num_rows($result) == 1) {
-                       db_query($link, "UPDATE $table SET
-                               value = '$unread', updated = NOW() WHERE
-                               feed_id = '$feed_id' AND owner_uid = '$owner_uid'");
-
-               } else {
-                       db_query($link, "INSERT INTO $table
-                               (feed_id, value, owner_uid, updated)
-                               VALUES
-                               ($feed_id, $unread, $owner_uid, NOW())");
-               }
-
-               db_query($link, "COMMIT");
-
-               if ($feed_id > 0 && $prev_unread != $unread) {
-
-                       if (!$is_cat) {
-
-                               /* Update parent category */
-
-                               if ($update_pcat) {
-
-                                       $result = db_query($link, "SELECT cat_id FROM ttrss_feeds
-                                               WHERE owner_uid = '$owner_uid' AND id = '$feed_id'");
-
-                                       $cat_id = (int) db_fetch_result($result, 0, "cat_id");
-
-                                       ccache_update($link, $cat_id, $owner_uid, true);
-
-                               }
-                       }
-               } else if ($feed_id < 0) {
-                       ccache_update_all($link, $owner_uid);
-               }
-
-               return $unread;
-       }
-
-       /* function ccache_cleanup($link, $owner_uid) {
-
-               if (DB_TYPE == "pgsql") {
-                       db_query($link, "DELETE FROM ttrss_counters_cache AS c1 WHERE
-                               (SELECT count(*) FROM ttrss_counters_cache AS c2
-                                       WHERE c1.feed_id = c2.feed_id AND c2.owner_uid = c1.owner_uid) > 1
-                                       AND owner_uid = '$owner_uid'");
-
-                       db_query($link, "DELETE FROM ttrss_cat_counters_cache AS c1 WHERE
-                               (SELECT count(*) FROM ttrss_cat_counters_cache AS c2
-                                       WHERE c1.feed_id = c2.feed_id AND c2.owner_uid = c1.owner_uid) > 1
-                                       AND owner_uid = '$owner_uid'");
-               } else {
-                       db_query($link, "DELETE c1 FROM
-                                       ttrss_counters_cache AS c1,
-                                       ttrss_counters_cache AS c2
-                               WHERE
-                                       c1.owner_uid = '$owner_uid' AND
-                                       c1.owner_uid = c2.owner_uid AND
-                                       c1.feed_id = c2.feed_id");
-
-                       db_query($link, "DELETE c1 FROM
-                                       ttrss_cat_counters_cache AS c1,
-                                       ttrss_cat_counters_cache AS c2
-                               WHERE
-                                       c1.owner_uid = '$owner_uid' AND
-                                       c1.owner_uid = c2.owner_uid AND
-                                       c1.feed_id = c2.feed_id");
-
-               }
-       } */
-
-       function label_find_id($link, $label, $owner_uid) {
-               $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) {
-                       return db_fetch_result($result, 0, "id");
-               } else {
-                       return 0;
-               }
-       }
-
-       function get_article_labels($link, $id, $owner_uid = false) {
-               $rv = array();
-
-               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
-
-               $result = db_query($link, "SELECT label_cache FROM
-                       ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
-                       $owner_uid);
-
-               if (db_num_rows($result) > 0) {
-                       $label_cache = db_fetch_result($result, 0, "label_cache");
-
-                       if ($label_cache) {
-                               $label_cache = json_decode($label_cache, true);
-
-                               if ($label_cache["no-labels"] == 1)
-                                       return $rv;
-                               else
-                                       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'
-                               AND owner_uid = ". $owner_uid . "
-                       ORDER BY caption");
-
-               while ($line = db_fetch_assoc($result)) {
-                       $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
-                               $line["bg_color"]);
-                       array_push($rv, $rk);
-               }
-
-               if (count($rv) > 0)
-                       label_update_cache($link, $owner_uid, $id, $rv);
-               else
-                       label_update_cache($link, $owner_uid, $id, array("no-labels" => 1));
-
-               return $rv;
-       }
-
-
-       function label_find_caption($link, $label, $owner_uid) {
-               $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) {
-                       return db_fetch_result($result, 0, "caption");
-               } else {
-                       return "";
-               }
-       }
-
-       function get_all_labels($link, $owner_uid) {
-               $rv = array();
-
-               $result = db_query($link, "SELECT fg_color, bg_color, caption FROM ttrss_labels2 WHERE owner_uid = " . $owner_uid);
-
-               while ($line = db_fetch_assoc($result)) {
-                       array_push($rv, $line);
-               }
-
-               return $rv;
-       }
-
-       function label_update_cache($link, $owner_uid, $id, $labels = false, $force = false) {
-
-               if ($force)
-                       label_clear_cache($link, $id);
-
-               if (!$labels)
-                       $labels = get_article_labels($link, $id);
-
-               $labels = db_escape_string(json_encode($labels));
-
-               db_query($link, "UPDATE ttrss_user_entries SET
-                       label_cache = '$labels' WHERE ref_id = '$id' AND  owner_uid = '$owner_uid'");
-
-       }
-
-       function label_clear_cache($link, $id) {
-
-               db_query($link, "UPDATE ttrss_user_entries SET
-                       label_cache = '' WHERE ref_id = '$id'");
-
-       }
-
-       function label_remove_article($link, $id, $label, $owner_uid) {
-
-               $label_id = label_find_id($link, $label, $owner_uid);
-
-               if (!$label_id) return;
-
-               $result = db_query($link,
-                       "DELETE FROM ttrss_user_labels2
-                       WHERE
-                               label_id = '$label_id' AND
-                               article_id = '$id'");
-
-               label_clear_cache($link, $id);
-       }
-
-       function label_add_article($link, $id, $label, $owner_uid) {
-
-               $label_id = label_find_id($link, $label, $owner_uid);
-
-               if (!$label_id) return;
-
-               $result = db_query($link,
-                       "SELECT
-                               article_id FROM ttrss_labels2, ttrss_user_labels2
-                       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
-                               (label_id, article_id) VALUES ('$label_id', '$id')");
-               }
-
-               label_clear_cache($link, $id);
-
-       }
-
-       function label_remove($link, $id, $owner_uid) {
-               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
-
-               db_query($link, "BEGIN");
-
-               $result = db_query($link, "SELECT caption FROM ttrss_labels2
-                       WHERE id = '$id'");
-
-               $caption = db_fetch_result($result, 0, "caption");
-
-               $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id'
-                       AND owner_uid = " . $owner_uid);
-
-               if (db_affected_rows($link, $result) != 0 && $caption) {
-
-                       /* Remove access key for the label */
-
-                       $ext_id = -11 - $id;
-
-                       db_query($link, "DELETE FROM ttrss_access_keys WHERE
-                               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
-                                       AND owner_uid = " . $owner_uid);
-
-                       /* Remove cached data */
-
-                       db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
-                               WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $owner_uid);
-
-               }
-
-               db_query($link, "COMMIT");
-       }
-
-       function label_create($link, $caption, $fg_color = '', $bg_color = '', $owner_uid) {
-
-               if (!$owner_uid) $owner_uid = $_SESSION['uid'];
-
-               db_query($link, "BEGIN");
-
-               $result = false;
-
-               $result = db_query($link, "SELECT id FROM ttrss_labels2
-                       WHERE caption = '$caption' AND owner_uid = $owner_uid");
-
-               if (db_num_rows($result) == 0) {
-                       $result = db_query($link,
-                               "INSERT INTO ttrss_labels2 (caption,owner_uid,fg_color,bg_color)
-                                       VALUES ('$caption', '$owner_uid', '$fg_color', '$bg_color')");
-
-                       $result = db_affected_rows($link, $result) != 0;
-               }
-
-               db_query($link, "COMMIT");
-
-               return $result;
-       }
-
-       function format_tags_string($tags, $id) {
-
-               $tags_str = "";
-               $tags_nolinks_str = "";
-
-               $num_tags = 0;
-
-               $tag_limit = 6;
-
-               $formatted_tags = array();
-
-               foreach ($tags as $tag) {
-                       $num_tags++;
-                       $tag_escaped = str_replace("'", "\\'", $tag);
-
-                       if (mb_strlen($tag) > 30) {
-                               $tag = truncate_string($tag, 30);
-                       }
-
-                       $tag_str = "<a href=\"javascript:viewfeed('$tag_escaped')\">$tag</a>";
-
-                       array_push($formatted_tags, $tag_str);
-
-                       $tmp_tags_str = implode(", ", $formatted_tags);
-
-                       if ($num_tags == $tag_limit || mb_strlen($tmp_tags_str) > 150) {
-                               break;
-                       }
-               }
-
-               $tags_str = implode(", ", $formatted_tags);
-
-               if ($num_tags < count($tags)) {
-                       $tags_str .= ", &hellip;";
-               }
-
-               if ($num_tags == 0) {
-                       $tags_str = __("no tags");
-               }
-
-               return $tags_str;
-
-       }
-
-       function format_article_labels($labels, $id) {
-
-               $labels_str = "";
-
-               foreach ($labels as $l) {
-                       $labels_str .= sprintf("<span class='hlLabelRef'
-                               style='color : %s; background-color : %s'>%s</span>",
-                                       $l[2], $l[3], $l[1]);
-                       }
-
-               return $labels_str;
-
-       }
-
-       function format_article_note($id, $note) {
-
-               $str = "<div class='articleNote'        onclick=\"editArticleNote($id)\">
-                       <div class='noteEdit' onclick=\"editArticleNote($id)\">".
-                       __('(edit note)')."</div>$note</div>";
-
-               return $str;
-       }
-
-       function toggle_collapse_cat($link, $cat_id, $mode) {
-               if ($cat_id > 0) {
-                       $mode = bool_to_sql_bool($mode);
-
-                       db_query($link, "UPDATE ttrss_feed_categories SET
-                               collapsed = $mode WHERE id = '$cat_id' AND owner_uid = " .
-                               $_SESSION["uid"]);
-               } else {
-                       $pref_name = '';
+                       db_query($link, "UPDATE ttrss_feed_categories SET
+                               collapsed = $mode WHERE id = '$cat_id' AND owner_uid = " .
+                               $_SESSION["uid"]);
+               } else {
+                       $pref_name = '';
 
                        switch ($cat_id) {
                        case -1:
                }
        }
 
-       function remove_feed($link, $id, $owner_uid) {
-
-               if ($id > 0) {
-
-                       /* save starred articles in Archived feed */
-
-                       db_query($link, "BEGIN");
-
-                       /* prepare feed if necessary */
-
-                       $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
-                               WHERE id = '$id'");
-
-                       if (db_num_rows($result) == 0) {
-                               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
-                                       marked = true AND owner_uid = $owner_uid");
-
-                       /* Remove access key for the feed */
-
-                       db_query($link, "DELETE FROM ttrss_access_keys WHERE
-                               feed_id = '$id' AND owner_uid = $owner_uid");
-
-                       /* remove the feed */
-
-                       db_query($link, "DELETE FROM ttrss_feeds
-                                       WHERE id = '$id' AND owner_uid = $owner_uid");
-
-                       db_query($link, "COMMIT");
-
-                       if (file_exists(ICONS_DIR . "/$id.ico")) {
-                               unlink(ICONS_DIR . "/$id.ico");
-                       }
-
-                       ccache_remove($link, $id, $owner_uid);
-
-               } else {
-                       label_remove($link, -11-$id, $owner_uid);
-                       ccache_remove($link, -11-$id, $owner_uid);
-               }
-       }
 
        function get_feed_category($link, $feed_cat, $parent_cat_id = false) {
                if ($parent_cat_id) {
                return false;
        }
 
-       function remove_feed_category($link, $id, $owner_uid) {
-
-               db_query($link, "DELETE FROM ttrss_feed_categories
-                       WHERE id = '$id' AND owner_uid = $owner_uid");
-
-               ccache_remove($link, $id, $owner_uid, true);
-       }
-
-       function archive_article($link, $id, $owner_uid) {
-               db_query($link, "BEGIN");
-
-               $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
-                       WHERE ref_id = '$id' AND owner_uid = $owner_uid");
-
-               if (db_num_rows($result) != 0) {
-
-                       /* prepare the archived table */
-
-                       $feed_id = (int) db_fetch_result($result, 0, "feed_id");
-
-                       if ($feed_id) {
-                               $result = db_query($link, "SELECT id FROM ttrss_archived_feeds
-                                       WHERE id = '$feed_id'");
-
-                               if (db_num_rows($result) == 0) {
-                                       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
-                                       SET orig_feed_id = feed_id, feed_id = NULL
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                       }
-               }
-
-               db_query($link, "COMMIT");
-       }
-
        function getArticleFeed($link, $id) {
                $result = db_query($link, "SELECT feed_id FROM ttrss_user_entries
                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
                return $rv;
        }
 
-       function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset, $include_nested = false) {
-
-                       $feeds = array();
-
-                       /* Labels */
-
-                       if ($cat_id == -4 || $cat_id == -2) {
-                               $counters = getLabelCounters($link, true);
-
-                               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);
-                                       }
-                               }
-                       }
-
-                       /* Virtual feeds */
-
-                       if ($cat_id == -4 || $cat_id == -1) {
-                               foreach (array(-1, -2, -3, -4, -6, 0) as $i) {
-                                       $unread = getFeedUnread($link, $i);
-
-                                       if ($unread || !$unread_only) {
-                                               $title = getFeedTitle($link, $i);
-
-                                               $row = array(
-                                                               "id" => $i,
-                                                               "title" => $title,
-                                                               "unread" => $unread,
-                                                               "cat_id" => -1,
-                                                       );
-                                               array_push($feeds, $row);
-                                       }
-
-                               }
-                       }
-
-                       /* Child cats */
-
-                       if ($include_nested && $cat_id) {
-                               $result = db_query($link, "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"]);
-
-                                       if ($unread || !$unread_only) {
-                                               $row = array(
-                                                               "id" => $line["id"],
-                                                               "title" => $line["title"],
-                                                               "unread" => $unread,
-                                                               "is_cat" => true,
-                                                       );
-                                               array_push($feeds, $row);
-                                       }
-                               }
-                       }
-
-                       /* Real feeds */
-
-                       if ($limit) {
-                               $limit_qpart = "LIMIT $limit OFFSET $offset";
-                       } else {
-                               $limit_qpart = "";
-                       }
-
-                       if ($cat_id == -4 || $cat_id == -3) {
-                               $result = db_query($link, "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"] .
-                                               " ORDER BY cat_id, title " . $limit_qpart);
-                       } else {
-
-                               if ($cat_id)
-                                       $cat_qpart = "cat_id = '$cat_id'";
-                               else
-                                       $cat_qpart = "cat_id IS NULL";
-
-                               $result = db_query($link, "SELECT
-                                       id, feed_url, cat_id, title, order_id, ".
-                                               SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
-                                               FROM ttrss_feeds WHERE
-                                               $cat_qpart AND owner_uid = " . $_SESSION["uid"] .
-                                               " ORDER BY cat_id, title " . $limit_qpart);
-                       }
-
-                       while ($line = db_fetch_assoc($result)) {
-
-                               $unread = getFeedUnread($link, $line["id"]);
-
-                               $has_icon = feed_has_icon($line['id']);
-
-                               if ($unread || !$unread_only) {
-
-                                       $row = array(
-                                                       "feed_url" => $line["feed_url"],
-                                                       "title" => $line["title"],
-                                                       "id" => (int)$line["id"],
-                                                       "unread" => (int)$unread,
-                                                       "has_icon" => $has_icon,
-                                                       "cat_id" => (int)$line["cat_id"],
-                                                       "last_updated" => strtotime($line["last_updated"]),
-                                                       "order_id" => (int) $line["order_id"],
-                                               );
-
-                                       array_push($feeds, $row);
-                               }
-                       }
-
-               return $feeds;
-       }
-
-       function api_get_headlines($link, $feed_id, $limit, $offset,
-                               $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order,
-                               $include_attachments, $since_id,
-                               $search = "", $search_mode = "", $match_on = "",
-                               $include_nested = false, $sanitize_content = true) {
-
-                       $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
-                               $view_mode, $is_cat, $search, $search_mode, $match_on,
-                               $order, $offset, 0, false, $since_id, $include_nested);
-
-                       $result = $qfh_ret[0];
-                       $feed_title = $qfh_ret[1];
-
-                       $headlines = array();
-
-                       while ($line = db_fetch_assoc($result)) {
-                               $is_updated = ($line["last_read"] == "" &&
-                                       ($line["unread"] != "t" && $line["unread"] != "1"));
-
-                               $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"]);
-
-                               $headline_row = array(
-                                               "id" => (int)$line["id"],
-                                               "unread" => sql_bool_to_bool($line["unread"]),
-                                               "marked" => sql_bool_to_bool($line["marked"]),
-                                               "published" => sql_bool_to_bool($line["published"]),
-                                               "updated" => strtotime($line["updated"]),
-                                               "is_updated" => $is_updated,
-                                               "title" => $line["title"],
-                                               "link" => $line["link"],
-                                               "feed_id" => $line["feed_id"],
-                                               "tags" => $tags,
-                                       );
-
-                                       if ($include_attachments)
-                                               $headline_row['attachments'] = get_article_enclosures($link,
-                                                       $line['id']);
-
-                               if ($show_excerpt) {
-                                       $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
-                                       $headline_row["excerpt"] = $excerpt;
-                               }
-
-                               if ($show_content) {
-
-                                       if ($line["cached_content"] != "") {
-                                               $line["content_preview"] =& $line["cached_content"];
-                                       }
-
-                                       if ($sanitize_content) {
-                                               $headline_row["content"] = sanitize($link,
-                                                       $line["content_preview"], false, false, $line["site_url"]);
-                                       } else {
-                                               $headline_row["content"] = $line["content_preview"];
-                                       }
-                               }
-
-                               // unify label output to ease parsing
-                               if ($labels["no-labels"] == 1) $labels = array();
-
-                               $headline_row["labels"] = $labels;
-
-                               $headline_row["feed_title"] = $line["feed_title"];
-
-                               $headline_row["comments_count"] = (int)$line["num_comments"];
-                               $headline_row["comments_link"] = $line["comments"];
-
-                               $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
-
-                               array_push($headlines, $headline_row);
-                       }
-
-                       return $headlines;
-       }
-
-       function generate_error_feed($link, $error) {
-               $reply = array();
-
-               $reply['headlines']['id'] = -6;
-               $reply['headlines']['is_cat'] = false;
-
-               $reply['headlines']['toolbar'] = '';
-               $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
-
-               $reply['headlines-info'] = array("count" => 0,
-                       "vgroup_last_feed" => '',
-                       "unread" => 0,
-                       "disable_cache" => true);
-
-               return $reply;
-       }
-
-
-       function generate_dashboard_feed($link) {
-               $reply = array();
-
-               $reply['headlines']['id'] = -5;
-               $reply['headlines']['is_cat'] = false;
-
-               $reply['headlines']['toolbar'] = '';
-               $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
-
-               $reply['headlines']['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
-
-               $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);
-
-               $reply['headlines']['content'] .= sprintf(__("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) {
-                       $reply['headlines']['content'] .= "<br/>";
-                       $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
-                               __('Some feeds have update errors (click for details)')."</a>";
-               }
-               $reply['headlines']['content'] .= "</span></p>";
-
-               $reply['headlines-info'] = array("count" => 0,
-                       "vgroup_last_feed" => '',
-                       "unread" => 0,
-                       "disable_cache" => true);
-
-               return $reply;
-       }
-
        function save_email_address($link, $email) {
                // FIXME: implement persistent storage of emails
 
                        array_push($_SESSION['stored_emails'], $email);
        }
 
-       function update_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) {
-               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
-
-               $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
-                       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
-                               AND owner_uid = " . $owner_uid);
-
-                       return $key;
-
-               } else {
-                       return get_feed_access_key($link, $feed_id, $is_cat, $owner_uid);
-               }
-       }
 
        function get_feed_access_key($link, $feed_id, $is_cat, $owner_uid = false) {
 
 
                        $entries_html = array();
                        $entries = array();
+                       $entries_inline = array();
 
                        foreach ($result as $line) {
 
 
                                $filename = substr($url, strrpos($url, "/")+1);
 
-#                              $player = format_inline_player($link, $url, $ctype);
+                               $player = format_inline_player($link, $url, $ctype);
+
+                               if ($player) array_push($entries_inline, $player);
 
 #                              $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
 #                                      $filename . " (" . $ctype . ")" . "</a>";
                                }
                        }
 
+                       if (count($entries_inline) > 0) {
+                               $rv .= "<hr clear='both'/>";
+                               foreach ($entries_inline as $entry) { $rv .= $entry; };
+                               $rv .= "<hr clear='both'/>";
+                       }
+
                        $rv .= "<br/><div dojoType=\"dijit.form.DropDownButton\">".
                                "<span>" . __('Attachments')."</span>";
                        $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
 
        }
 
-/*     function rewrite_urls($line) {
-               global $url_regex;
-
-               $urls = null;
-
-               $result = preg_replace("/((?<!=.)((http|https|ftp)+):\/\/[^ ,!]+)/i",
-                       "<a target=\"_blank\" href=\"\\1\">\\1</a>", $line);
-
-               return $result;
-       } */
-
        function rewrite_urls($html) {
                libxml_use_internal_errors(true);
 
 
        }
 
-       function create_published_article($link, $title, $url, $content, $labels_str,
-                       $owner_uid) {
-
-               $guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash
-               $content_hash = sha1($content);
-
-               if ($labels_str != "") {
-                       $labels = explode(",", $labels_str);
-               } else {
-                       $labels = array();
-               }
-
-               $rc = false;
-
-               if (!$title) $title = $url;
-               if (!$title && !$url) return false;
-
-               if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false;
-
-               db_query($link, "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
-                       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
-                               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
-                                       content = '$content', content_hash = '$content_hash' WHERE id = '$ref_id'");
-
-                               db_query($link, "UPDATE ttrss_user_entries SET published = true WHERE
-                                               int_id = '$int_id' AND owner_uid = '$owner_uid'");
-                       } else {
-
-                               db_query($link, "INSERT INTO ttrss_user_entries
-                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
-                                       VALUES
-                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
-                       }
-
-                       if (count($labels) != 0) {
-                               foreach ($labels as $label) {
-                                       label_add_article($link, $ref_id, trim($label), $owner_uid);
-                               }
-                       }
-
-                       $rc = true;
-
-               } else {
-                       $result = db_query($link, "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'");
-
-                       if (db_num_rows($result) != 0) {
-                               $ref_id = db_fetch_result($result, 0, "id");
-
-                               db_query($link, "INSERT INTO ttrss_user_entries
-                                       (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
-                                       VALUES
-                                       ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
-
-                               if (count($labels) != 0) {
-                                       foreach ($labels as $label) {
-                                               label_add_article($link, $ref_id, trim($label), $owner_uid);
-                                       }
-                               }
-
-                               $rc = true;
-                       }
-               }
-
-               db_query($link, "COMMIT");
-
-               return $rc;
-       }
-
        function implements_interface($class, $interface) {
                return in_array($interface, class_implements($class));
        }