]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
add special indication for categories having unread items in child categories
[tt-rss.git] / include / functions.php
index 918192cd37ccddcfbb67c450d1fe222f2af970c8..b2319e6e1efabcad01d2897be89443af7306de32 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+       define('EXPECTED_CONFIG_VERSION', 25);
+       define('SCHEMA_VERSION', 93);
+
+       mb_internal_encoding("UTF-8");
        date_default_timezone_set('UTC');
        if (defined('E_DEPRECATED')) {
                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
 
        startup_gettext();
 
-       if (defined('MEMCACHE_SERVER')) {
-               $memcache = new Memcache;
-               $memcache->connect(MEMCACHE_SERVER, 11211);
-       }
-
        require_once 'db-prefs.php';
        require_once 'version.php';
 
 
        require_once 'lib/pubsubhubbub/publisher.php';
 
+       $purifier = false;
+
        $tz_offset = -1;
        $utc_tz = new DateTimeZone('UTC');
        $schema_version = false;
         * @return void
         */
        function _debug($msg) {
+               if (defined('QUIET') && QUIET) {
+                       return;
+               }
                $ts = strftime("%H:%M:%S", time());
                if (function_exists('posix_getpid')) {
                        $ts = "$ts/" . posix_getpid();
 
                array_push($ret_arr, $cv);
 
-               $age_qpart = getMaxAgeSubquery();
-
-               $result = db_query($link, "SELECT id AS cat_id, value AS unread
+               $result = db_query($link, "SELECT id AS cat_id, value AS unread,
+                       (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
+                               WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
                        FROM ttrss_feed_categories, ttrss_cat_counters_cache
                        WHERE ttrss_cat_counters_cache.feed_id = id AND
                        ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
                while ($line = db_fetch_assoc($result)) {
                        $line["cat_id"] = (int) $line["cat_id"];
 
+                       if ($line["num_children"] > 0) {
+                               $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]);
+                       } else {
+                               $child_counter = 0;
+                       }
+
                        $cv = array("id" => $line["cat_id"], "kind" => "cat",
+                               "child_counter" => $child_counter,
                                "counter" => $line["unread"]);
 
                        array_push($ret_arr, $cv);
                return $ret_arr;
        }
 
+       // only accepts real cats (>= 0)
+       function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) {
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+               $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat'
+                               AND owner_uid = $owner_uid");
+
+               $unread = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+                       $unread += getCategoryUnread($link, $line["id"], $owner_uid);
+                       $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid);
+               }
+
+               return $unread;
+       }
+
        function getCategoryUnread($link, $cat, $owner_uid = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
                                $cat_query = "cat_id IS NULL";
                        }
 
-                       $age_qpart = getMaxAgeSubquery();
-
                        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query
                                        AND owner_uid = " . $owner_uid);
 
                        $match_part = implode(" OR ", $cat_feeds);
 
                        $result = db_query($link, "SELECT COUNT(int_id) AS unread
-                               FROM ttrss_user_entries,ttrss_entries
-                               WHERE   unread = true AND ($match_part) AND id = ref_id
-                               AND $age_qpart AND owner_uid = " . $owner_uid);
+                               FROM ttrss_user_entries
+                               WHERE   unread = true AND ($match_part)
+                               AND owner_uid = " . $owner_uid);
 
                        $unread = 0;
 
 
                        $result = db_query($link, "
                                SELECT COUNT(unread) AS unread FROM
-                                       ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
-                               WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
-                                       ttrss_labels2.owner_uid = '$owner_uid'
-                                       AND unread = true AND feed_id = ttrss_feeds.id
+                                       ttrss_user_entries, ttrss_user_labels2
+                               WHERE article_id = ref_id AND unread = true
                                        AND ttrss_user_entries.owner_uid = '$owner_uid'");
 
                        $unread = db_fetch_result($result, 0, "unread");
                }
        }
 
-       function getMaxAgeSubquery($days = COUNTERS_MAX_AGE) {
-               if (DB_TYPE == "pgsql") {
-                       return "ttrss_entries.date_updated >
-                               NOW() - INTERVAL '$days days'";
-               } else {
-                       return "ttrss_entries.date_updated >
-                               DATE_SUB(NOW(), INTERVAL $days DAY)";
-               }
-       }
-
        function getFeedUnread($link, $feed, $is_cat = false) {
                return getFeedArticles($link, $feed, $is_cat, true, $_SESSION["uid"]);
        }
        function getLabelUnread($link, $label_id, $owner_uid = false) {
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
-               $result = db_query($link, "
-                       SELECT COUNT(unread) AS unread FROM
-                               ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds
-                       WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND
-                               ttrss_labels2.owner_uid = '$owner_uid' AND ttrss_labels2.id = '$label_id'
-                               AND unread = true AND feed_id = ttrss_feeds.id
-                               AND ttrss_user_entries.owner_uid = '$owner_uid'");
+               $result = db_query($link, "SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
+                       WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id");
 
                if (db_num_rows($result) != 0) {
                        return db_fetch_result($result, 0, "unread");
                $owner_uid = false) {
 
                $n_feed = (int) $feed;
+               $need_entries = false;
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                        $unread_qpart = "true";
                }
 
-               $age_qpart = getMaxAgeSubquery();
-
                if ($is_cat) {
                        return getCategoryUnread($link, $n_feed, $owner_uid);
                } if ($feed != "0" && $n_feed == 0) {
 
                        $result = db_query($link, "SELECT SUM((SELECT COUNT(int_id)
                                FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
-                                       AND ref_id = id AND $age_qpart
-                                       AND $unread_qpart)) AS count FROM ttrss_tags
+                                       AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
                                WHERE owner_uid = $owner_uid AND tag_name = '$feed'");
                        return db_fetch_result($result, 0, "count");
 
                        } else {
                                $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
                        }
+
+                       $need_entries = true;
+
                } else if ($n_feed == -4) {
                        $match_part = "true";
                } else if ($n_feed >= 0) {
 
                if ($match_part) {
 
-                       if ($n_feed != 0) {
-                               $from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries";
-                               $feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
-                       } else {
+                       if ($need_entries) {
                                $from_qpart = "ttrss_user_entries,ttrss_entries";
-                               $feeds_qpart = '';
+                               $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND";
+                       } else {
+                               $from_qpart = "ttrss_user_entries";
                        }
 
                        $query = "SELECT count(int_id) AS unread
                                FROM $from_qpart WHERE
-                               ttrss_user_entries.ref_id = ttrss_entries.id AND
-                               $age_qpart AND
-                               $feeds_qpart
-                               $unread_qpart AND ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
+                               $unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = $owner_uid";
+
+                       //echo "[$feed/$query]\n";
 
                        $result = db_query($link, $query);
 
                        $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
                                FROM ttrss_tags,ttrss_user_entries,ttrss_entries
                                WHERE tag_name = '$feed' AND post_int_id = int_id AND ref_id = ttrss_entries.id
-                               AND $unread_qpart AND $age_qpart AND
-                                       ttrss_tags.owner_uid = " . $owner_uid);
+                               AND $unread_qpart AND ttrss_tags.owner_uid = " . $owner_uid);
                }
 
                $unread = db_fetch_result($result, 0, "unread");
 
                $ret_arr = array();
 
-               $age_qpart = getMaxAgeSubquery();
-
                $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 $age_qpart
-                               AND unread = true)) AS count FROM ttrss_tags
+                               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");
 
 
                $ret_arr = array();
 
-               $age_qpart = getMaxAgeSubquery();
-
                $owner_uid = $_SESSION["uid"];
 
                $result = db_query($link, "SELECT id, caption FROM ttrss_labels2
 
                $ret_arr = array();
 
-               $age_qpart = getMaxAgeSubquery();
-
                $query = "SELECT ttrss_feeds.id,
                                ttrss_feeds.title,
                                ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
        }
 
        function sanitize($link, $str, $force_strip_tags = false, $owner = false, $site_url = false) {
+               global $purifier;
+
                if (!$owner) $owner = $_SESSION["uid"];
 
                $res = trim($str); if (!$res) return '';
 
-               // TODO implement better HTML tag stripping and XSS protection
+               // create global Purifier object if needed
+               if (!$purifier) {
+                       require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php';
+
+                       $config = HTMLPurifier_Config::createDefault();
+
+                       $allowed = "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title|align|hspace],ul,ol,li,h1,h2,h3,h4,s,object[classid|type|id|name|width|height|codebase],param[name|value],table,tr,td,span[class]";
 
-               if (function_exists('filter_var')) {
-                       $res = filter_var($res, FILTER_SANITIZE_STRING);
+                       $config->set('HTML.SafeObject', true);
+                       @$config->set('HTML', 'Allowed', $allowed);
+                       $config->set('Output.FlashCompat', true);
+                       $config->set('Attr.EnableID', true);
+                       if (!defined('MOBILE_VERSION')) {
+                               @$config->set('Cache', 'SerializerPath', CACHE_DIR . "/htmlpurifier");
+                       } else {
+                               @$config->set('Cache', 'SerializerPath', "../" . CACHE_DIR . "/htmlpurifier");
+                       }
+
+                       $config->set('Filter.YouTube', true);
+
+                       $purifier = new HTMLPurifier($config);
                }
 
-               $res = strip_tags($str, "<p><a><i><em><b><strong><code><pre><blockquote><br><img><ul><ol><li><h1><h2><h3><h4><s><object><param><table><tr><td><span>");
+               $res = $purifier->purify($res);
 
                if (get_pref($link, "STRIP_IMAGES", $owner)) {
                        $res = preg_replace('/<img[^>]+>/is', '', $res);
 
                $result = db_query($link, "SELECT ttrss_entries.title,
                                ttrss_feeds.title AS feed_title,
-                               ttrss_feed_categories.title AS cat_title,
+                               COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS cat_title,
                                date_updated,
                                ttrss_user_entries.ref_id,
                                link,
                        } */
 
                        if (get_pref($link, 'ENABLE_FEED_CATS', $user_id)) {
-                               if (!$line['cat_title']) $line['cat_title'] = __("Uncategorized");
-
                                $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title'];
                        }
 
 
        function get_article_tags($link, $id, $owner_uid = 0, $tag_cache = false) {
 
-               global $memcache;
-
                $a_id = db_escape_string($id);
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
                $obj_id = md5("TAGS:$owner_uid:$id");
                $tags = array();
 
-               if ($memcache && $obj = $memcache->get($obj_id)) {
-                       $tags = $obj;
-               } else {
-                       /* check cache first */
+               /* check cache first */
 
-                       if ($tag_cache === false) {
-                               $result = db_query($link, "SELECT tag_cache FROM ttrss_user_entries
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+               if ($tag_cache === false) {
+                       $result = db_query($link, "SELECT tag_cache FROM ttrss_user_entries
+                               WHERE ref_id = '$id' AND owner_uid = $owner_uid");
 
-                               $tag_cache = db_fetch_result($result, 0, "tag_cache");
-                       }
+                       $tag_cache = db_fetch_result($result, 0, "tag_cache");
+               }
 
-                       if ($tag_cache) {
-                               $tags = explode(",", $tag_cache);
-                       } else {
+               if ($tag_cache) {
+                       $tags = explode(",", $tag_cache);
+               } else {
 
-                               /* do it the hard way */
+                       /* do it the hard way */
 
-                               $tmp_result = db_query($link, $query);
+                       $tmp_result = db_query($link, $query);
 
-                               while ($tmp_line = db_fetch_assoc($tmp_result)) {
-                                       array_push($tags, $tmp_line["tag_name"]);
-                               }
+                       while ($tmp_line = db_fetch_assoc($tmp_result)) {
+                               array_push($tags, $tmp_line["tag_name"]);
+                       }
 
-                               /* update the cache */
+                       /* update the cache */
 
-                               $tags_str = db_escape_string(join(",", $tags));
+                       $tags_str = db_escape_string(join(",", $tags));
 
-                               db_query($link, "UPDATE ttrss_user_entries
-                                       SET tag_cache = '$tags_str' WHERE ref_id = '$id'
-                                       AND owner_uid = " . $_SESSION["uid"]);
-                       }
-
-                       if ($memcache) $memcache->add($obj_id, $tags, 0, 3600);
+                       db_query($link, "UPDATE ttrss_user_entries
+                               SET tag_cache = '$tags_str' WHERE ref_id = '$id'
+                               AND owner_uid = $owner_uid");
                }
 
                return $tags;
                return $entry;
        }
 
-       function format_article($link, $id, $mark_as_read = true, $zoom_mode = false) {
+       function format_article($link, $id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
+
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                $rv = array();
 
                //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
 
                $result = db_query($link, "SELECT rtl_content, always_display_enclosures FROM ttrss_feeds
-                       WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
+                       WHERE id = '$feed_id' AND owner_uid = $owner_uid");
 
                if (db_num_rows($result) == 1) {
                        $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
                if ($mark_as_read) {
                        $result = db_query($link, "UPDATE ttrss_user_entries
                                SET unread = false,last_read = NOW()
-                               WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+                               WHERE ref_id = '$id' AND owner_uid = $owner_uid");
 
-                       ccache_update($link, $feed_id, $_SESSION["uid"]);
+                       ccache_update($link, $feed_id, $owner_uid);
                }
 
                $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
                        orig_feed_id,
                        note
                        FROM ttrss_entries,ttrss_user_entries
-                       WHERE   id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
+                       WHERE   id = '$id' AND ref_id = id AND owner_uid = $owner_uid");
 
                if ($result) {
 
                                        </head><body>";
                        }
 
+                       $title_escaped = db_escape_string($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)\"
                        }
 
                        $parsed_updated = make_local_datetime($link, $line["updated"], true,
-                               false, true);
+                               $owner_uid, true);
 
                        $rv['content'] .= "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
 
                        if ($line["link"]) {
-                               $rv['content'] .= "<div clear='both'><a target='_blank'
+                               $rv['content'] .= "<div class='postTitle' clear='both'><a target='_blank'
                                        title=\"".htmlspecialchars($line['title'])."\"
                                        href=\"" .
                                        $line["link"] . "\">" .
                                        truncate_string($line["title"], 100) .
                                        "<span class='author'>$entry_author</span></a></div>";
                        } else {
-                               $rv['content'] .= "<div clear='both'>" . $line["title"] . "$entry_author</div>";
+                               $rv['content'] .= "<div class='postTitle' clear='both'>" . $line["title"] . "$entry_author</div>";
                        }
 
                        $tag_cache = $line["tag_cache"];
 
                        if (!$tag_cache)
-                               $tags = get_article_tags($link, $id);
+                               $tags = get_article_tags($link, $id, $owner_uid);
                        else
                                $tags = explode(",", $tag_cache);
 
 
                        if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
 
-                       $rv['content'] .= "<div style='float : right'>
+                       $rv['content'] .= "<div class='postTags' style='float : right'>
                                <img src='".theme_image($link, 'images/tag.png')."'
                                class='tagsPic' alt='Tags' title='Tags'>&nbsp;";
 
 
                        $rv['content'] .= "<div class=\"postContent\">";
 
-                       $article_content = sanitize($link, $line["content"], false, false,
+                       // N-grams
+
+                       if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_RELATED_THRESHOLD')) {
+
+                               $ngram_result = db_query($link, "SELECT id,title FROM
+                                               ttrss_entries,ttrss_user_entries
+                                       WHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'
+                                               AND similarity(title, '$title_escaped') >= "._NGRAM_TITLE_RELATED_THRESHOLD."
+                                               AND title != '$title_escaped'
+                                               AND owner_uid = $owner_uid");
+
+                               if (db_num_rows($ngram_result) > 0) {
+                                       $rv['content'] .= "<div dojoType=\"dijit.form.DropDownButton\">".
+                                               "<span>" . __('Related')."</span>";
+                                       $rv['content'] .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+
+                                       while ($nline = db_fetch_assoc($ngram_result)) {
+                                               $rv['content'] .= "<div onclick=\"hlOpenInNewTab(null,".$nline['id'].")\"
+                                                       dojoType=\"dijit.MenuItem\">".$nline['title']."</div>";
+
+                                       }
+                                       $rv['content'] .= "</div></div><br/";
+                               }
+                       }
+
+                       $article_content = sanitize($link, $line["content"], false, $owner_uid,
                                $feed_site_url);
 
                        $rv['content'] .= $article_content;
        function load_filters($link, $feed, $owner_uid, $action_id = false) {
                $filters = array();
 
-               global $memcache;
-
-               $obj_id = md5("FILTER:$feed:$owner_uid:$action_id");
-
-               if ($memcache && $obj = $memcache->get($obj_id)) {
-
-                       return $obj;
 
-               } else {
+               if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
 
-                       if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
-
-                       $result = db_query($link, "SELECT reg_exp,
-                               ttrss_filter_types.name AS name,
-                               ttrss_filter_actions.name AS action,
-                               inverse,
-                               action_param,
-                               filter_param
-                               FROM ttrss_filters
-                                       LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'),
-                                       ttrss_filter_types,ttrss_filter_actions
-                               WHERE
-                                       enabled = true AND
-                                       $ftype_query_part
-                                       ttrss_filters.owner_uid = $owner_uid AND
-                                       ttrss_filter_types.id = filter_type AND
-                                       ttrss_filter_actions.id = action_id AND
-                                       ((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR
-                                       (cat_filter = true AND ttrss_feeds.cat_id IS NULL AND
-                                               ttrss_filters.cat_id IS NULL) OR
-                                       (cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed')))
-                               ORDER BY reg_exp");
+               $result = db_query($link, "SELECT reg_exp,
+                       ttrss_filter_types.name AS name,
+                       ttrss_filter_actions.name AS action,
+                       inverse,
+                       action_param,
+                       filter_param
+                       FROM ttrss_filters
+                               LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'),
+                               ttrss_filter_types,ttrss_filter_actions
+                       WHERE
+                               enabled = true AND
+                               $ftype_query_part
+                               ttrss_filters.owner_uid = $owner_uid AND
+                               ttrss_filter_types.id = filter_type AND
+                               ttrss_filter_actions.id = action_id AND
+                               ((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR
+                               (cat_filter = true AND ttrss_feeds.cat_id IS NULL AND
+                                       ttrss_filters.cat_id IS NULL) OR
+                               (cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed')))
+                       ORDER BY reg_exp");
 
-                       while ($line = db_fetch_assoc($result)) {
+               while ($line = db_fetch_assoc($result)) {
 
-                               if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
-                                       $filter["reg_exp"] = $line["reg_exp"];
-                                       $filter["action"] = $line["action"];
-                                       $filter["action_param"] = $line["action_param"];
-                                       $filter["filter_param"] = $line["filter_param"];
-                                       $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
+                       if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
+                               $filter["reg_exp"] = $line["reg_exp"];
+                               $filter["action"] = $line["action"];
+                               $filter["action_param"] = $line["action_param"];
+                               $filter["filter_param"] = $line["filter_param"];
+                               $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
 
-                                       array_push($filters[$line["name"]], $filter);
-                               }
+                               array_push($filters[$line["name"]], $filter);
+                       }
 
-                       if ($memcache) $memcache->add($obj_id, $filters, 0, 3600*8);
 
-                       return $filters;
-               }
+               return $filters;
        }
 
        function get_score_pic($score) {
        }
 
        function get_article_labels($link, $id) {
-               global $memcache;
-
-               $obj_id = md5("LABELS:$id:" . $_SESSION["uid"]);
-
                $rv = array();
 
-               if ($memcache && $obj = $memcache->get($obj_id)) {
-                       return $obj;
-               } else {
-
-                       $result = db_query($link, "SELECT label_cache FROM
-                               ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
-                               $_SESSION["uid"]);
 
-                       $label_cache = db_fetch_result($result, 0, "label_cache");
+               $result = db_query($link, "SELECT label_cache FROM
+                       ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
+                       $_SESSION["uid"]);
 
-                       if ($label_cache) {
+               $label_cache = db_fetch_result($result, 0, "label_cache");
 
-                               $label_cache = json_decode($label_cache, true);
+               if ($label_cache) {
 
-                               if ($label_cache["no-labels"] == 1)
-                                       return $rv;
-                               else
-                                       return $label_cache;
-                       }
+                       $label_cache = json_decode($label_cache, true);
 
-                       $result = db_query($link,
-                               "SELECT DISTINCT label_id,caption,fg_color,bg_color
-                                       FROM ttrss_labels2, ttrss_user_labels2
-                               WHERE id = label_id
-                                       AND article_id = '$id'
-                                       AND owner_uid = ".$_SESSION["uid"] . "
-                               ORDER BY caption");
+                       if ($label_cache["no-labels"] == 1)
+                               return $rv;
+                       else
+                               return $label_cache;
+               }
 
-                       while ($line = db_fetch_assoc($result)) {
-                               $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
-                                       $line["bg_color"]);
-                               array_push($rv, $rk);
-                       }
-                       if ($memcache) $memcache->add($obj_id, $rv, 0, 3600);
+               $result = db_query($link,
+                       "SELECT DISTINCT label_id,caption,fg_color,bg_color
+                               FROM ttrss_labels2, ttrss_user_labels2
+                       WHERE id = label_id
+                               AND article_id = '$id'
+                               AND owner_uid = ".$_SESSION["uid"] . "
+                       ORDER BY caption");
 
-                       if (count($rv) > 0)
-                               label_update_cache($link, $id, $rv);
-                       else
-                               label_update_cache($link, $id, array("no-labels" => 1));
+               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, $id, $rv);
+               else
+                       label_update_cache($link, $id, array("no-labels" => 1));
+
                return $rv;
        }
 
 
        function label_add_article($link, $id, $label, $owner_uid) {
 
-               global $memcache;
-
-               if ($memcache) {
-                       $obj_id = md5("LABELS:$id:$owner_uid");
-                       $memcache->delete($obj_id);
-               }
-
                $label_id = label_find_id($link, $label, $owner_uid);
 
                if (!$label_id) return;
        }
 
        function label_remove($link, $id, $owner_uid) {
-               global $memcache;
-
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
-               if ($memcache) {
-                       $obj_id = md5("LABELS:$id:$owner_uid");
-                       $memcache->delete($obj_id);
-               }
-
                db_query($link, "BEGIN");
 
                $result = db_query($link, "SELECT caption FROM ttrss_labels2
 
        function get_article_enclosures($link, $id) {
 
-               global $memcache;
-
                $query = "SELECT * FROM ttrss_enclosures
                        WHERE post_id = '$id' AND content_url != ''";
 
-               $obj_id = md5("ENCLOSURES:$id");
-
                $rv = array();
 
-               if ($memcache && $obj = $memcache->get($obj_id)) {
-                       $rv = $obj;
-               } else {
-                       $result = db_query($link, $query);
+               $result = db_query($link, $query);
 
-                       if (db_num_rows($result) > 0) {
-                               while ($line = db_fetch_assoc($result)) {
-                                       array_push($rv, $line);
-                               }
-                               if ($memcache) $memcache->add($obj_id, $rv, 0, 3600);
+               if (db_num_rows($result) > 0) {
+                       while ($line = db_fetch_assoc($result)) {
+                               array_push($rv, $line);
                        }
                }
 
 
                                if (!$ctype) $ctype = __("unknown type");
 
-#                              $filename = substr($url, strrpos($url, "/")+1);
+                               $filename = substr($url, strrpos($url, "/")+1);
 
-                               $entry = format_inline_player($link, $url, $ctype);
+#                              $player = format_inline_player($link, $url, $ctype);
 
 #                              $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
 #                                      $filename . " (" . $ctype . ")" . "</a>";
 
+                               $entry = "<div onclick=\"window.open('".htmlspecialchars($url)."')\"
+                                       dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>";
+
                                array_push($entries_html, $entry);
 
                                $entry = array();
                                array_push($entries, $entry);
                        }
 
-                       $rv .= "<div class=\"postEnclosures\">";
-
                        if (!get_pref($link, "STRIP_IMAGES")) {
                                if ($always_display_enclosures ||
                                                        !preg_match("/<img/i", $article_content)) {
                                                                $rv .= "<p><img
                                                                alt=\"".htmlspecialchars($entry["filename"])."\"
                                                                src=\"" .htmlspecialchars($entry["url"]) . "\"/></p>";
+
                                                }
                                        }
                                }
                        }
 
-                       if (count($entries) == 1) {
-                               $rv .= __("Attachment:") . " ";
-                       } else {
-                               $rv .= __("Attachments:") . " ";
-                       }
+                       $rv .= "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Attachments')."</span>";
+                       $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
 
-                       $rv .= join(", ", $entries_html);
+                       foreach ($entries_html as $entry) { $rv .= $entry; };
 
-                       $rv .= "</div>";
+                       $rv .= "</div></div>";
                }
 
                return $rv;
                        return $rel_url;
                } else if (strpos($rel_url, "://") !== false) {
                        return $rel_url;
+               } else if (strpos($rel_url, "//") === 0) {
+                       # protocol-relative URL (rare but they exist)
+                       return $rel_url;
                } else if (strpos($rel_url, "/") === 0)
                {
                        $parts = parse_url($url);
                        return $output;
                }
        }
+
+       function read_stdin() {
+               $fp = fopen("php://stdin", "r");
+
+               if ($fp) {
+                       $line = trim(fgets($fp));
+                       fclose($fp);
+                       return $line;
+               }
+
+               return null;
+       }
 ?>