]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
implement settings profiles (bump schema)
[tt-rss.git] / functions.php
index 5657e04c95fbba3a49d25d05ae1be6880bde693a..672d9ef1d60b6c6348c69567ff78c469a20a12dc 100644 (file)
                } else {
 
                        $result = db_query($link, "SELECT id,update_interval,auth_login,
-                               auth_pass,cache_images,update_method,hidden,last_updated
+                               auth_pass,cache_images,update_method,last_updated
                                FROM ttrss_feeds WHERE id = '$feed'");
 
                }
                        return false;
                }
 
-               $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
                $update_method = db_fetch_result($result, 0, "update_method");
                $last_updated = db_fetch_result($result, 0, "last_updated");
 
                                catchup_feed($link, $feed, false, $owner_uid);
                        }
 
-                       if (!$hidden) {
-                               if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
-                                       _debug("update_rss_feed: updating counters cache...");
-                               }
-
-                               // disabled, purge_feed() does that...
-                               //ccache_update($link, $feed, $owner_uid);
-                       }
-
                        purge_feed($link, $feed, 0);
 
                        db_query($link, "UPDATE ttrss_feeds 
                }
        }
 
-       function initialize_user_prefs($link, $uid) {
+       function initialize_user_prefs($link, $uid, $profile = false) {
 
                $uid = db_escape_string($uid);
 
+               if (!$profile) {
+                       $profile = "NULL";
+                       $profile_qpart = "profile IS NULL";
+               } else {
+                       $profile_qpart = "profile = '$profile'";
+               }
+
                db_query($link, "BEGIN");
 
                $result = db_query($link, "SELECT pref_name,def_value FROM ttrss_prefs");
                
                $u_result = db_query($link, "SELECT pref_name 
-                       FROM ttrss_user_prefs WHERE owner_uid = '$uid'");
+                       FROM ttrss_user_prefs WHERE owner_uid = '$uid' AND $profile_qpart");
 
                $active_prefs = array();
 
 //                             print "adding " . $line["pref_name"] . "<br>";
 
                                db_query($link, "INSERT INTO ttrss_user_prefs
-                                       (owner_uid,pref_name,value) VALUES 
-                                       ('$uid', '".$line["pref_name"]."','".$line["def_value"]."')");
+                                       (owner_uid,pref_name,value, profile) VALUES 
+                                       ('$uid', '".$line["pref_name"]."','".$line["def_value"]."', $profile)");
 
                        }
                }
        
                                $user_theme = get_user_theme_path($link);
        
-                               $_SESSION["theme"] = $user_theme;
                                $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
                                $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash");
        
 
                        $user_theme = get_user_theme_path($link);
        
-                       $_SESSION["theme"] = $user_theme;
                        $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
        
                        initialize_user_prefs($link, $_SESSION["uid"]);
                                        $_SESSION["language"] = $_POST["language"];
                                        $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
 
+                                       if ($_POST["profile"]) {
+
+                                               $profile = db_escape_string($_POST["profile"]);
+
+                                               $result = db_query($link, "SELECT id FROM ttrss_settings_profiles
+                                                       WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
+
+                                               if (db_num_rows($result) != 0) {
+                                                       $_SESSION["profile"] = $profile;
+                                                       $_SESSION["prefs_cache"] = array();
+                                               }
+                                       }
+
                                        header("Location: " . $_SERVER["REQUEST_URI"]);
                                        exit;
 
        }
 
        function get_user_theme_path($link) {
+               $theme_id = get_pref($link, "_THEME_ID");
+
                $result = db_query($link, "SELECT theme_path 
-                       FROM 
-                               ttrss_themes,ttrss_users
-                       WHERE ttrss_themes.id = theme_id AND ttrss_users.id = " . $_SESSION["uid"]);
+                       FROM ttrss_themes       WHERE id = '$theme_id'");
                if (db_num_rows($result) != 0) {
                        return db_fetch_result($result, 0, "theme_path");
                } else {
                        if (!$owner_uid) $owner_uid = $_SESSION['uid'];
 
                        if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
-                       
+
                                if ($cat_view) {
 
                                        if ($feed >= 0) {
                if (!$omode) $omode = "flc";
        
                getGlobalCounters($link);
-       
+               getVirtCounters($link);
+
                if (strchr($omode, "l")) getLabelCounters($link);
                if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed);
                if (strchr($omode, "t")) getTagCounters($link);
                        ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
 
                while ($line = db_fetch_assoc($result)) {
-                       $line["cat_id"] = sprintf("%d", $line["cat_id"]);
+                       $line["cat_id"] = (int) $line["cat_id"];
 
                        print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
                                $line["unread"]."\"/>";
                        $age_qpart = getMaxAgeSubquery();
 
                        $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query 
-                                       AND hidden = false
                                        AND owner_uid = " . $owner_uid);
        
                        $cat_feeds = array();
                                        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 hidden = false AND feed_id = ttrss_feeds.id
+                                       AND unread = true AND feed_id = ttrss_feeds.id
                                        AND ttrss_user_entries.owner_uid = '$owner_uid'");
 
                        $unread = db_fetch_result($result, 0, "unread");
                                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 hidden = false AND feed_id = ttrss_feeds.id
+                               AND unread = true AND feed_id = ttrss_feeds.id
                                AND ttrss_user_entries.owner_uid = '$owner_uid'");
 
                if (db_num_rows($result) != 0) {
        function getFeedArticles($link, $feed, $is_cat = false, $unread_only = false,
                $owner_uid = false) {
 
-               $n_feed = sprintf("%d", $feed);
+               $n_feed = (int) $feed;
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
 
                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 
+                               WHERE owner_uid = $owner_uid AND tag_name = '$feed'");
+                       return db_fetch_result($result, 0, "count");
+
                } else if ($n_feed == -1) {
                        $match_part = "marked = true";
                } else if ($n_feed == -2) {
 
                        $result = db_query($link, "SELECT id FROM ttrss_feeds 
                                        WHERE parent_feed = '$n_feed'
-                                       AND hidden = false
                                        AND owner_uid = " . $owner_uid);
 
                        if (db_num_rows($result) > 0) {
 
                        if ($n_feed != 0) {
                                $from_qpart = "ttrss_user_entries,ttrss_feeds,ttrss_entries";
-                               $feeds_qpart = "ttrss_feeds.hidden = false AND
-                                       ttrss_user_entries.feed_id = ttrss_feeds.id AND";
+                               $feeds_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
                        } else {
                                $from_qpart = "ttrss_user_entries,ttrss_entries";
                        }
 
        }
 
-       function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) {
-
-               $age_qpart = getMaxAgeSubquery();
-
-               if ($smart_mode) {
-                       if (!$_SESSION["lctr_last_value"]) {
-                               $_SESSION["lctr_last_value"] = array();
-                       }
-               }
+       function getVirtCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) {
 
                $ret_arr = array();
 
                                $ret_arr[$i]["counter"] = $count;
                                $ret_arr[$i]["description"] = getFeedTitle($link, $i);
                        }
-       
+               } 
+
+               return $ret_arr;
+       }
+
+       function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS, $ret_mode = false) {
+
+               $age_qpart = getMaxAgeSubquery();
+
+               if ($smart_mode) {
+                       if (!$_SESSION["lctr_last_value"]) {
+                               $_SESSION["lctr_last_value"] = array();
+                       }
                }
 
                $old_counters = $_SESSION["lctr_last_value"];
                print "</rpc-reply>";
        }
 
-       function subscribe_to_feed($link, $feed_link, $cat_id = 0, 
+       function subscribe_to_feed($link, $url, $cat_id = 0, 
                        $auth_login = '', $auth_pass = '') {
 
-               # check for feed:http://url
-               $feed_link = trim(preg_replace("/^feed:/", "", $feed_link));
+               $parts = parse_url($url);
 
-               # check for feed://URL
-               if (strpos($feed_link, "//") === 0) {
-                       $feed_link = "http:$feed_link";
-               }
+               if (!validate_feed_url($url)) return 2;
+
+               if ($parts['scheme'] == 'feed') $parts['scheme'] = 'http';
 
-               if ($feed_link == "") return;
+               $url = make_url_from_parts($parts);
 
                if ($cat_id == "0" || !$cat_id) {
                        $cat_qpart = "NULL";
        
                $result = db_query($link,
                        "SELECT id FROM ttrss_feeds 
-                       WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
+                       WHERE feed_url = '$url' AND owner_uid = ".$_SESSION["uid"]);
        
                if (db_num_rows($result) == 0) {
                        
                        $result = db_query($link,
                                "INSERT INTO ttrss_feeds 
                                        (owner_uid,feed_url,title,cat_id, auth_login,auth_pass) 
-                               VALUES ('".$_SESSION["uid"]."', '$feed_link', 
+                               VALUES ('".$_SESSION["uid"]."', '$url', 
                                '[Unknown]', $cat_qpart, '$auth_login', '$auth_pass')");
        
                        $result = db_query($link,
-                               "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link
+                               "SELECT id FROM ttrss_feeds WHERE feed_url = '$url
                                        AND owner_uid = " . $_SESSION["uid"]);
        
                        $feed_id = db_fetch_result($result, 0, "id");
        
                        if ($feed_id) {
-                               update_rss_feed($link, $feed_link, $feed_id, true);
+                               update_rss_feed($link, $url, $feed_id, true);
                        }
 
-                       return true;
+                       return 1;
                } else {
-                       return false;
+                       return 0;
                }
        }
 
                        return __("Fresh articles");
                } else if ($id == -4) {
                        return __("All articles");
-               } else if ($id == 0) {
+               } else if ($id === 0 || $id === "0") {
                        return __("Archived articles");
                } else if ($id < -10) {
                        $label_id = -$id - 11;
                                return "Unknown feed ($id)";
                        }
                } else {
-                       if (preg_match("/^-?[0-9][0-9]*$/", $id)) {
-                               return "getFeedTitle($id) failed";
-                       } else {
-                               return $id;
-                       }
+                       return $id;
                }
-
        }
 
        function get_session_cookie_name() {
                        }
                }
 
-               print "<param key=\"theme\" value=\"".$_SESSION["theme"]."\"/>";
+               print "<param key=\"theme\" value=\"".get_user_theme_path($link)."\"/>";
                print "<param key=\"daemon_enabled\" value=\"" . ENABLE_UPDATE_DAEMON . "\"/>";
                print "<param key=\"feeds_frame_refresh\" value=\"" . FEEDS_FRAME_REFRESH . "\"/>";
                print "<param key=\"daemon_refresh_only\" value=\"true\"/>";
 
                if (ENABLE_UPDATE_DAEMON) {
                        print "<param key=\"daemon_is_running\" value=\"".
-                               sprintf("%d", file_is_locked("update_daemon.lock")) . "\"/>";
+                               (int) file_is_locked("update_daemon.lock") . "\"/>";
 
                        if (time() - $_SESSION["daemon_stamp_check"] > 30) {
 
                        if ($search && $search_mode == "all_feeds") {
                                $query_strategy_part = "ttrss_entries.id > 0";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";         
+                       /* tags */
                        } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
                                $query_strategy_part = "ttrss_entries.id > 0";
                                $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
        
                        $feed_title = "";
 
-                       if ($search && $search_mode == "all_feeds") {
-                               $feed_title = __("Search results")." ($search)";
-                       } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
-                               $feed_title = __("Search results")." ($search, $feed)";
-                       } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
-                               $feed_title = $feed;
-                       } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
-       
+                       if ($search) {
+                               $feed_title = "Search results";
+                       } else {
                                if ($cat_view) {
-
-                                       if ($feed != 0) {                       
-                                               $result = db_query($link, "SELECT title FROM ttrss_feed_categories
-                                                       WHERE id = '$feed' AND owner_uid = $owner_uid");
-                                               $feed_title = db_fetch_result($result, 0, "title");
-                                       } else {
-                                               $feed_title = __("Uncategorized");
-                                       }
-
-                                       if ($search) {
-                                               $feed_title = __("Searched for")." $search ($feed_title)";
-                                       }
-
+                                       $feed_title = getCategoryTitle($link, $feed);
                                } else {
-                                       
-                                       $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds 
-                                               WHERE id = '$feed' AND owner_uid = $owner_uid");
+                                       if ((int)$feed == $feed && $feed > 0) {
+                                               $result = db_query($link, "SELECT title,site_url,last_error 
+                                                       FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = $owner_uid");
                
-                                       $feed_title = db_fetch_result($result, 0, "title");
-                                       $feed_site_url = db_fetch_result($result, 0, "site_url");
-                                       $last_error = db_fetch_result($result, 0, "last_error");
-
-                                       if ($search) {
-                                               $feed_title = __("Searched for") . " $search ($feed_title)";
-                                       }
-                               }
-       
-                       } else if ($feed == -1) {
-                               $feed_title = __("Starred articles");
-                               if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
-                       } else if ($feed == -2) {
-                               if (!$cat_view) {
-                                       $feed_title = __("Published articles");
-                                       if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
-                               } else {
-                                       $feed_title = __("Labels");
-                               }
-                       } else if ($feed == -3) {
-                               $feed_title = __("Fresh articles");
-                               if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
-                       } else if ($feed == -4) {
-                               $feed_title = __("All articles");
-                               if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
-                       } else if ($feed < -10) {
-                               $label_id = -$feed - 11;
-                               $result = db_query($link, "SELECT caption FROM ttrss_labels2
-                                       WHERE id = '$label_id'");
-                               $feed_title = db_fetch_result($result, 0, "caption");
-
-                               if ($search) {
-                                       $feed_title = __("Searched for") . " $search ($feed_title)";
+                                               $feed_title = db_fetch_result($result, 0, "title");
+                                               $feed_site_url = db_fetch_result($result, 0, "site_url");
+                                               $last_error = db_fetch_result($result, 0, "last_error");
+                                       } else {
+                                               $feed_title = getFeedTitle($link, $feed);
+                                       } 
                                }
-                       } else {
-                               $feed_title = "?";
                        }
 
                        $content_query_part = "content as content_preview,";
                                        if (!$override_order) {
                                                $order_by = "ttrss_feeds.title, $order_by";     
                                        }
-
-                                       // Special output for Fresh feed
-
-/*                                     if ($feed == -3) {
-                                               $group_limit_part = "(select count(*) from 
-                                                       ttrss_user_entries AS t1, ttrss_entries AS t2 where
-                                                               t1.ref_id = t2.id and t1.owner_uid = 2 and
-                                                               t1.feed_id = ttrss_user_entries.feed_id and
-                                                               t2.updated > ttrss_entries.updated) <= 5 AND";
-} */
                                }
 
                                if ($feed != "0") {
                                        $from_qpart = "ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part";
-                                       $feed_check_qpart = "ttrss_feeds.hidden = false AND 
-                                               ttrss_user_entries.feed_id = ttrss_feeds.id AND";
+                                       $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
 
                                } else {
                                        $from_qpart = "ttrss_entries,ttrss_user_entries$ext_tables_part
                                        $limit_query_part");    
                        }
 
-                       if (!$feed_title) $feed_title = getFeedTitle($link, $feed_id);
-
                        return array($result, $feed_title, $feed_site_url, $last_error);
-                       
+               
        }
 
        function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
                }
 
                if (get_pref($link, "STRIP_IMAGES", $owner)) {
-                       
                        $res = preg_replace('/<img[^>]+>/is', '', $res);
+               }
 
+               if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
+                       $res = preg_replace("/href=/i", "target=\"_blank\" href=", $res);
                }
 
                return $res;
                                ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id 
                                AND include_in_digest = true
                                AND $interval_query
-                               AND hidden = false
                                AND ttrss_user_entries.owner_uid = $user_id
                                AND unread = true 
                        ORDER BY ttrss_feeds.title, date_entered DESC
                                <li onclick=\"$tog_unread_link\">&nbsp;&nbsp;".__('Unread')."</li>
                                <li onclick=\"$tog_marked_link\">&nbsp;&nbsp;".__('Starred')."</li>
                                <li onclick=\"$tog_published_link\">&nbsp;&nbsp;".__('Published')."</li>
-                               <!-- <li><span class=\"insensitive\">--------</span></li> -->
-                               <li class=\"insensitive\">".__('Mark as read:')."</li>
-                               <li onclick=\"$catchup_sel_link\">&nbsp;&nbsp;".__('Selection')."</li>";
+                               <li class=\"insensitive\">".__('Selection:')."</li>
+                               <li onclick=\"$catchup_sel_link\">&nbsp;&nbsp;".__('Mark as read')."</li>";
 
-                       print "<li onclick=\"$catchup_feed_link\">&nbsp;&nbsp;".__('Entire feed').
-                               "</li>";
+//                     print "<li onclick=\"$catchup_feed_link\">&nbsp;&nbsp;".__('Entire feed').
+//                             "</li>";
 
                        if ($feed_id != "0") {
-                               print "<li class=\"insensitive\">".__('Selection:')."</li>
-                                       <li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Archive')."</li>
-                                       <li onclick=\"$delete_sel_link\">&nbsp;&nbsp;".__('Delete')."</li>";
+                               print "<li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Archive')."</li>";
                        } else {
-                               print "<li class=\"insensitive\">".__('Selection:')."</li>
-                                       <li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Move back')."</li>
-                                       <li onclick=\"$delete_sel_link\">&nbsp;&nbsp;".__('Delete')."</li>";
+                               print "<li onclick=\"$archive_sel_link\">&nbsp;&nbsp;".__('Move back')."</li>";
+                               print "<li onclick=\"$delete_sel_link\">&nbsp;&nbsp;".__('Delete')."</li>";
+
                        } 
 
                        //print "<li><span class=\"insensitive\">--------</span></li>";
                                        ON
                                                (ttrss_feeds.id = feed_id)
                                WHERE 
-                                       ttrss_feeds.hidden = false AND
                                        ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
                                ORDER BY $order_by_qpart"; 
 
                                                $collapsed = get_pref($link, "_COLLAPSED_UNCAT");
                                        }
 
-                                       $cat_id = sprintf("%d", $cat_id);
+                                       $cat_id = (int) $cat_id;
 
                                        printCategoryHeader($link, $cat_id, $collapsed, true);
 
                        foreach (array_keys($tags) as $tag) {
        
                                $unread = $tags[$tag];
-       
                                $class = "tag";
-       
-                               if ($unread > 0) {
-                                       $class .= "Unread";
-                               }
-       
+
                                printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
        
                        } 
 
                if ($result) {
 
-                       $link_target = "";
-
-                       if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
-                               $link_target = "target=\"_blank\"";
-                       }
-
                        $line = db_fetch_assoc($result);
 
                        if ($line["icon_url"]) {
                                } else {
                                        $comments_url = $line["link"];
                                }
-                               $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
+                               $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
                        } else {
                                if ($line["comments"] && $line["link"] != $line["comments"]) {
-                                       $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
+                                       $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
                                }                               
                        }
 
                        print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
 
                        if ($line["link"]) {
-                               print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" . 
+                               print "<div clear='both'><a target='_blank' href=\"" . $line["link"] . "\">" . 
                                        $line["title"] . "</a><span class='author'>$entry_author</span></div>";
                        } else {
                                print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
 
                        $article_content = sanitize_rss($link, $line["content"]);
 
-                       if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
-                               $article_content = preg_replace("/href=/i", "target=\"_blank\" href=", 
-                                       $article_content);
-                       }
-
                        print "<div id=\"POSTNOTE-$id\">";
                                if ($line['note']) {
                                        print format_article_note($id, $line['note']);
 
                                print "<div class=\"postEnclosures\">";
 
-                               if ($always_display_enclosures || !preg_match("/<img/i", $article_content)) {
-                                       foreach ($entries as $entry) {
-                                               if (preg_match("/image/", $entry["type"])) {
-                                                       print "<p><img 
-                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
-                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                               if (!get_pref($link, "STRIP_IMAGES")) {
+                                       if ($always_display_enclosures || !preg_match("/<img/i", $article_content)) {
+                                               foreach ($entries as $entry) {
+                                                       if (preg_match("/image/", $entry["type"])) {
+                                                               print "<p><img 
+                                                                       alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                                       src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                                                       }
                                                }
                                        }
                                }
                } else {
                        print "
                                <div style=\"text-align : center\">
-                               <input type=\"submit\" onclick=\"return window.close()\" 
-                               value=\"".__("Close this window")."\"></div>";
+                               <button onclick=\"return window.close()\">".
+                                       __("Close this window")."</button></div>";
                        print "</body></html>";
 
                }
 
                                        print "</span></div>";
 
-                                       if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
-                                               $line["content_preview"] = preg_replace("/href=/i", 
-                                                       "target=\"_blank\" href=", $line["content_preview"]);
-                                       }
-
                                        if ($show_excerpt) {
                                                print "<div class=\"cdmExcerpt\" id=\"CEXC-$id\"
                                                        onclick=\"cdmExpandArticle($id)\"
 
                                $always_display_enclosures = db_fetch_result($tmp_result, 0, "always_display_enclosures");
 
-                               if ($always_display_enclosures || !preg_match("/img/i", $article_content)) {
-                                       foreach ($entries as $entry) {
-                                               if (preg_match("/image/", $entry["type"])) {
-                                                       print "<p><img 
-                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
-                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                               if (!get_pref($link, "STRIP_IMAGES")) {
+                                       if ($always_display_enclosures || !preg_match("/img/i", $article_content)) {
+                                               foreach ($entries as $entry) {
+                                                       if (preg_match("/image/", $entry["type"])) {
+                                                               print "<p><img 
+                                                                       alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                                       src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                                                       }
                                                }
                                        }
                                }
                }
 
                $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
-               $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");
+               $url_path .= "/backend.php?op=publish&key=" . 
+                       get_pref($link, "_PREFS_PUBLISH_KEY", $_SESSION["uid"]);
 
                return $url_path;
        }
 
                $num_tags = 0;
 
-               if ($_SESSION["theme"] == "3pane") {
+/*             if (get_user_theme_path($link) == "3pane") {
                        $tag_limit = 3;
                } else {
                        $tag_limit = 6;
-               }
+               } */
+
+               $tag_limit = 6;
 
                $formatted_tags = array();
 
                                WHERE id = '$id'");
                        }
 
-                       db_query($link, "UPDATE ttrss_user_entries SET feed_id = NULL 
-                               WHERE feed_id = '$id' AND 
+                       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 the feed */
 
                        db_query($link, "COMMIT");
 
-                       if (file_exists(ICONS_DIR . "/$id.ico")) {
+/*                     if (file_exists(ICONS_DIR . "/$id.ico")) {
                                unlink(ICONS_DIR . "/$id.ico");
-                       }
+                       } */
 
                        ccache_remove($link, $id, $owner_uid);
 
                        return 0;
                }
        }
+
+       function make_url_from_parts($parts) {
+               $url = $parts['scheme'] . '://' . $parts['host'];
+
+               if ($parts['path']) $url .= $parts['path'];
+               if ($parts['query']) $url .= '?' . $parts['query'];
+
+               return $url;
+       }
+
+       function validate_feed_url($url) {
+               $parts = parse_url($url);
+
+               return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https');
+
+       }
+
 ?>