]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
code cleanup, test for db_escape() crazyness in DB sanity check
[tt-rss.git] / functions.php
index b373ca91c9912c1b581bccfce68bab8331187c31..48d6e3a858adb4926c7d372781be8567c4dfce6e 100644 (file)
@@ -26,6 +26,8 @@
                                        "en_US" => "English",
                                        "fr_FR" => "Français",
                                        "hu_HU" => "Magyar (Hungarian)",
+                                       "it_IT" => "Italiano",
+                                       "ja_JP" => "日本語 (Japanese)",
                                        "nb_NO" => "Norwegian bokmål",
                                        "ru_RU" => "Русский",
                                        "pt_BR" => "Portuguese/Brazil",
@@ -86,6 +88,7 @@
 
        define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
        define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
+       define('MAGPIE_CACHE_AGE', 60*15); // 15 minutes
 
        require_once "simplepie/simplepie.inc";
        require_once "magpierss/rss_fetch.inc";
                                        }
 
                                        // <media:content>
-                                       // can there be many of those? -fox
+                                       // can there be many of those? yes -fox
 
                                        $m_ctr = $item['media']['content#'];
 
                                                        $item['media']['content@length']);
 
                                                array_push($enclosures, $e_item);
-                                       }
 
-                                       // FIXME: parse more of those, if needed.
+                                               for ($i = 0; $i <= $m_ctr; $i++ ) {
+
+                                                       if ($item["media"]["content#$i@url"]) {
+                                                               $e_item = array($item["media"]["content#$i@url"],
+                                                                       $item["media"]["content#$i@medium"],
+                                                                       $item["media"]["content#$i@length"]);
+                                                               array_push($enclosures, $e_item);
+                                                       }
+                                               }
+
+                                       }
                                }
 
                                # sanitize content
                print "<select name=\"$id\" id='$id' $attributes>";
                foreach (array_keys($values) as $v) {
                        if ($v == $default)
-                               $sel = "selected";
+                               $sel = 'selected="selected"';
                         else
                                $sel = "";
                        
                print "<span $rtl_tag id=\"FEEDN-$feed_id\">$feed</span>";
 
                if ($unread != 0) {
-                       $fctr_class = "";
+                       $fctr_class = "class=\"feedCtrHasUnread\"";
                } else {
-                       $fctr_class = "class=\"invisible\"";
+                       $fctr_class = "class=\"feedCtrNoUnread\"";
                }
 
                print " <span $rtl_tag $fctr_class id=\"FEEDCTR-$feed_id\">
                        $pwd_hash2 = encrypt_password($password, $login);
 
                        if (defined('ALLOW_REMOTE_USER_AUTH') && ALLOW_REMOTE_USER_AUTH 
-                                       && $_SERVER["REMOTE_USER"]) {
+                                       && $_SERVER["REMOTE_USER"] && $login != "admin") {
 
                                $login = db_escape_string($_SERVER["REMOTE_USER"]);
 
-                               $query = "SELECT id,login,access_level
+                               $query = "SELECT id,login,access_level,pwd_hash
                    FROM ttrss_users WHERE
                                        login = '$login'";
 
                                        $_POST["password"] = "";
 
                                        $_SESSION["language"] = $_POST["language"];
+                                       $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
 
                                        header("Location: " . $_SERVER["REQUEST_URI"]);
                                        exit;
                                        setcookie("ttrss_lang", $_SESSION["language"], 
                                                time() + SESSION_COOKIE_LIFETIME);
                                }
+
+                               /* bump counters stamp since we're getting reloaded anyway */
+
+                               $_SESSION["get_all_counters_stamp"] = time();
                        }
 
                } else {
                        }
                }
 
+               if (db_escape_string("testTEST") != "testTEST") {
+                       $error_code = 12;
+               }
+
                error_reporting (DEFAULT_ERROR_LEVEL);
 
                if ($error_code != 0) {
                /* getting all counters is a resource intensive operation, so we
                 * rate limit it a little bit */
 
-               if (time() - $_SESSION["get_all_counters_stamp"] > 5) {
+
+
+               if (get_pref($link, "SYNC_COUNTERS") || 
+                               time() - $_SESSION["get_all_counters_stamp"] > 5) {
 
                        if (!$omode) $omode = "flc";
        
 
                        $last_updated = htmlspecialchars($last_updated);
 
-                       $has_img = is_file(ICONS_DIR . "/$id.ico");
+                       $has_img = feed_has_icon($id);
 
                        $tmp_result = db_query($link,
                                "SELECT ttrss_feeds.id,COUNT(unread) AS unread
                print "<param key=\"default_view_limit\" value=\"" . 
                        (int) get_pref($link, "_DEFAULT_VIEW_LIMIT") . "\"/>";
 
+               print "<param key=\"default_view_order_by\" value=\"" . 
+                       get_pref($link, "_DEFAULT_VIEW_ORDER_BY") . "\"/>";
+
                print "<param key=\"prefs_active_tab\" value=\"" . 
                        get_pref($link, "_PREFS_ACTIVE_TAB") . "\"/>";
 
                print "<param key=\"hide_feedlist\" value=\"" .
                        (int) get_pref($link, "HIDE_FEEDLIST") . "\"/>";
 
+               print "<param key=\"bw_limit\" value=\"".
+                       (int) $_SESSION["bw_limit"]."\"/>";
+
+               print "<param key=\"sync_counters\" value=\"" . 
+                       (int) get_pref($link, "SYNC_COUNTERS") . "\"/>";
+
                print "</init-params>";
        }
 
 
                if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) {
                        
-                       if ($_SESSION["last_version_check"] + 7200 < time()) {
+                       if ($_SESSION["last_version_check"] + 86400 < time()) {
                                $new_version_details = check_for_update($link);
 
                                print "<param key=\"new_version_available\" value=\"".
 
                        $view_query_part = "";
        
-                       if ($view_mode == "adaptive") {
+                       if ($view_mode == "adaptive" || $view_query_part == "noscores") {
                                if ($search) {
                                        $view_query_part = " ";
                                } else if ($feed != -1) {
                                $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
                                        WHERE id = '$label_id'");
                        
-                               $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
+                               $query_strategy_part = "(" . db_fetch_result($tmp_result, 0, "sql_exp") . ")";
 
                                if (!$query_strategy_part) {
                                        return false;
                                $order_by = "updated DESC";
                        }
 
-                       $order_by = "score DESC, $order_by";
+                       if ($view_mode != "noscores") {
+                               $order_by = "score DESC, $order_by";
+                       }
 
                        if ($override_order) {
                                $order_by = $override_order;
                                        $view_query_part
                                        $query_strategy_part ORDER BY $order_by
                                        $limit_query_part $offset_query_part";
-                                       
-                               $result = db_query($link, $query);
-       
+
                                if ($_GET["debug"]) print $query;
+
+                               $result = db_query($link, $query);
        
                        } else {
                                // browsing by tag
                if (get_pref($link, "STRIP_UNSAFE_TAGS") || $force_strip_tags) {
 
                        $res = strip_tags_long($res, 
-                               "<p><a><i><em><b><strong><blockquote><br><img><div><span><ul><ol><li>");
+                               "<p><a><i><em><b><strong><code><pre><blockquote><br><img><ul><ol><li>");
 
 //                     $res = preg_replace("/\r\n|\n|\r/", "", $res);
 //                     $res = strip_tags_long($res, "<p><a><i><em><b><strong><blockquote><br><img><div><span>");                       
                }
 
+               if (get_pref($link, "STRIP_IMAGES")) {
+                       
+                       $res = preg_replace('/<img[^>]+>/is', '', $res);
+
+               }
+
                return $res;
        }
 
                                $tid = "headlineActionsBottom";
                        }
 
-                       print "<table class=\"$class\" id=\"$tid\"
+                       print "<nobr><table class=\"$class\" id=\"$tid\"
                                width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
 
                        if ($rtl_content) {
                                $sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
                                $sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
                                $sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
+                               $sel_inv_link = "javascript:invertHeadlineSelection()";
 
                                $tog_unread_link = "javascript:selectionToggleUnread()";
                                $tog_marked_link = "javascript:selectionToggleMarked()";
                                $sel_unread_link = "javascript:cdmSelectArticles('unread')";
                                $sel_none_link = "javascript:cdmSelectArticles('none')";
 
+                               $sel_inv_link = "javascript:invertHeadlineSelection()";
+
                                $tog_unread_link = "javascript:selectionToggleUnread(true)";
                                $tog_marked_link = "javascript:selectionToggleMarked(true)";
                                $tog_published_link = "javascript:selectionTogglePublished(true)";
                                                ".__('Select:')."
                                                        <a href=\"$sel_all_link\">".__('All')."</a>,
                                                        <a href=\"$sel_unread_link\">".__('Unread')."</a>,
+                                                       <a href=\"$sel_inv_link\">".__('Invert')."</a>,
                                                        <a href=\"$sel_none_link\">".__('None')."</a></li>
                                                <li class=\"vsep\">&nbsp;</li>
                                                <li class=\"top\">".__('Actions...')."<ul>
                        print "</span>";
 
                        print "</td>";
-                       print "</tr></table>";
+                       print "</tr></table></nobr>";
 
                }
 
 
                        $catctr_class = ($cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread";
 
-                       print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
-                               <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>";
-
                        if ($can_browse) {
-                               print "<a href=\"#\" onclick=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">";
+                               $browse_cat_link = "onclick=\"javascript:viewCategory($cat_id)\"";
+                               $inner_title_class = "catTitle";
                        } else {
-                               print "<span id=\"FCAP-$cat_id\">";
+                               $browse_cat_link = "";
+                               $inner_title_class = "catTitleNL";
                        }
 
+                       if ($cat_id > 0) {
+                               $cat_class = "feedCat";
+                       } else {
+                               $cat_class = "virtCat";
+                       }
+
+                       print "<li class=\"$cat_class\" id=\"FCAT-$cat_id\">
+                               <img onclick=\"toggleCollapseCat($cat_id)\" class=\"catCollapse\"
+                                       title=\"".__('Click to collapse category')."\"
+                                       src=\"images/cat-collapse.png\"><span class=\"$inner_title_class\" 
+                                       id=\"FCATN-$cat_id\" $browse_cat_link
+                               \">$tmp_category</span>";
+
+                       print "<span id=\"FCAP-$cat_id\">";
+
                        print " <span id=\"FCATCTR-$cat_id\" 
                                class=\"$catctr_class\">($cat_unread)</span> $ellipsis";
 
-                       if ($can_browse) {
-                               print "</a>";
-                       } else {
-                               print "</span>";
-                       }
+                       print "</span>";
 
-                       print "</li>";
+                       //print "</li>";
 
                        print "<ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\" style='$holder_style'>";
 
                        "images/pub_set.gif", $link);
 
                if (get_pref($link, 'ENABLE_FEED_CATS')) {
-                       print "</ul>";
+                       print "</ul></li>";
                }
 
                if (!$tags) {
 
                        if (get_pref($link, 'ENABLE_FEED_CATS')) {
                                if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
-                                       $order_by_qpart = "category,unread DESC,title";
+                                       $order_by_qpart = "order_id,category,unread DESC,title";
                                } else {
-                                       $order_by_qpart = "category,title";
+                                       $order_by_qpart = "order_id,category,title";
                                }
                        } else {
                                if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
                                if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
                                
                                        if ($category) {
-                                               print "</ul>";
+                                               print "</ul></li>";
                                        }
                                
                                        $category = $tmp_category;
                return vsprintf(__(array_shift($args)), $args);
        }
 
-       function outputArticleXML($link, $id, $feed_id, $mark_as_read = true) {
+       function outputArticleXML($link, $id, $feed_id, $mark_as_read = true,
+               $zoom_mode = false) {
 
                /* we can figure out feed_id from article id anyway, why do we
                 * pass feed_id here? */
 
                $feed_id = db_fetch_result($result, 0, "feed_id");
 
-               print "<article id='$id'><![CDATA[";
+               if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
 
                $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
                        WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
                                }                               
                        }
 
+                       if ($zoom_mode) {
+                               header("Content-Type: text/html");
+                               print "<html><head>
+                                               <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
+                                               <title>Tiny Tiny RSS - ".$line["title"]."</title>
+                                               <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss.css\">
+                                       </head><body>";
+                       }
+
+
                        print "<div class=\"postReply\">";
 
                        print "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" 
                        $tags = get_article_tags($link, $id);
        
                        $tags_str = "";
+                       $tags_nolinks_str = "";
                        $f_tags_str = "";
 
                        $num_tags = 0;
                                
                                if ($num_tags == $tag_limit) {
                                        $tags_str .= "&hellip;";
+                                       $tags_nolinks_str .= "&hellip;";
 
                                } else if ($num_tags < $tag_limit) {
                                        $tags_str .= $tag_str;
+                                       $tags_nolinks_str .= "$tag, ";
                                }
                                $f_tags_str .= $tag_str;
                        }
 
                        $tags_str = preg_replace("/, $/", "", $tags_str);
+                       $tags_nolinks_str = preg_replace("/, $/", "", $tags_nolinks_str);
                        $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
 
                        $all_tags_div = "<span class='cdmAllTagsCtr'>&hellip;<div class='cdmAllTags'>All Tags: $f_tags_str</div></span>";
                        if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
 
                        if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
+                       if (!$tags_nolinks_str) $tags_nolinks_str = '<span class="tagList">'.__('no tags').'</span>';
 
                        print "<div style='float : right'>
-                               <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>
-                               $tags_str 
-                               <a title=\"Edit tags for this article\" 
-                                       href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
-                               <div clear='both'>$entry_comments</div>";
+                                       <img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>";
+
+                       if (!$zoom_mode) {
+                               print "$tags_str 
+                                       <a title=\"".__('Edit tags for this article')."\" 
+                                       href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a>";
+
+                               if (defined('_ENABLE_INLINE_VIEW')) {
+
+                                       print "<img src=\"images/art-inline.png\" class='tagsPic' 
+                                                       style=\"cursor : pointer\" style=\"cursor : pointer\"
+                                                       onclick=\"showOriginalArticleInline($id)\"
+                                                       alt='Inline' title='".__('Display original article content')."'>";
+
+                               }
+
+                               print "<img src=\"images/art-zoom.png\" class='tagsPic' 
+                                               style=\"cursor : pointer\" style=\"cursor : pointer\"
+                                               onclick=\"zoomToArticle($id)\"
+                                               alt='Zoom' title='".__('Show article summary in new window')."'>";
+                       } else {
+                               print "$tags_nolinks_str";
+                       }
+                       print "</div>";
+                       print "<div clear='both'>$entry_comments</div>";
 
                        print "</div>";
 
                                post_id = '$id' AND content_url != ''");
 
                        if (db_num_rows($result) > 0) {
-                               print "<div class=\"postEnclosures\">";
-
-                               if (db_num_rows($result) == 1) {
-                                       print __("Attachment:") . " ";
-                               } else {
-                                       print __("Attachments:") . " ";
-                               }
 
+                               $entries_html = array();
                                $entries = array();
 
                                while ($line = db_fetch_assoc($result)) {
 
                                        $filename = substr($url, strrpos($url, "/")+1);
 
-                                       $entry = "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
+                                       $entry = ""; 
+                                       
+                                       if (($ctype == __("audio/mpeg")) && 
+                                               (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { 
+                                       
+                                               $entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> ";
+
+                                       }
+
+                                       $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
                                                $filename . " (" . $ctype . ")" . "</a>";
 
+                                       array_push($entries_html, $entry);
+
+                                       $entry = array();
+
+                                       $entry["type"] = $ctype;
+                                       $entry["filename"] = $filename;
+                                       $entry["url"] = $url;
+
                                        array_push($entries, $entry);
                                }
 
-                               print join(", ", $entries);
+                               if (!preg_match("/img/i", $line["content"]) &&
+                                       preg_match("/image/", $entries[0]["type"])) {
+
+                               }
+
+                               print "<div class=\"postEnclosures\">";
+
+                               if (!preg_match("/img/i", $line["content"])) {
+                                       foreach ($entries as $entry) {
+                                               if (preg_match("/image/", $entry["type"])) {
+                                                       print "<p><img 
+                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                                               }
+                                       }
+                               }
+
+                               print "<div class=\"postEnclosures\">";
+
+                               if (db_num_rows($result) == 1) {
+                                       print __("Attachment:") . " ";
+                               } else {
+                                       print __("Attachments:") . " ";
+                               }
+
+                               print join(", ", $entries_html);
 
                                print "</div>";
                        }
 
                }
 
-               print "]]></article>";
+               if (!$zoom_mode) { 
+                       print "]]></article>"; 
+               } else {
+                       print "
+                               <div style=\"text-align : center\">
+                               <input type=\"submit\" onclick=\"return window.close()\" 
+                               value=\"".__("Close this window")."\"></div>";
+                       print "</body></html>";
+
+               }
 
        }
 
        function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view,
-                                       $next_unread_feed, $offset, $vgr_last_feed = false) {
+                                       $next_unread_feed, $offset, $vgr_last_feed = false, 
+                                       $override_order = false) {
 
                $disable_cache = false;
 
                if ($_GET["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
 
                $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, 
-                       $search, $search_mode, $match_on, false, $real_offset);
+                       $search, $search_mode, $match_on, $override_order, $real_offset);
 
                if ($_GET["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
 
                                        $entry_author = " - $entry_author";
                                }
 
+                               $has_feed_icon = feed_has_icon($feed_id);
+
+                               if ($has_feed_icon) {
+                                       $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
+                               } else {
+                                       //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
+                                       $feed_icon_img = "";
+                               }
+
                                if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
 
                                        if (get_pref($link, 'VFEED_GROUP_BY_FEED')) {
 
                                                        $cur_feed_title = htmlspecialchars($cur_feed_title);
 
-                                                       $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id, \"$cur_feed_title\");' href='#'>mark as read</a>)";
+                                                       $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>mark as read</a>)";
 
                                                        print "<tr class='feedTitle'><td colspan='7'>".
+                                                               "<div style=\"float : right\">$feed_icon_img</div>".
                                                                "<a href=\"javascript:viewfeed($feed_id, '', false)\">".
-                                                               $line["feed_title"]."</a> $vf_catchup_link:</td></tr>";
+                                                               $line["feed_title"]."</a> $vf_catchup_link</td></tr>";
                                                }
                                        }
 
                                                        </span>";
                                                }
                                        }
-
-
                                        print "</td>";
-                                       
+
 #                                      }
                                        
-                                       print "<td class=\"hlUpdated\" onclick='javascript:view($id,$feed_id)'><nobr>$updated_fmt&nbsp;</nobr></td>";
+                                       print "<td class=\"hlUpdated\" onclick='view($id,$feed_id)'><nobr>$updated_fmt&nbsp;</nobr></td>";
 
                                        print "<td class='hlMarkedPic'>$score_pic</td>";
-       
+
+                                       if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) {
+                                               print "<td onclick=\"viewfeed($feed_id)\" class=\"hlFeedIcon\">$feed_icon_img</td>";
+                                       }
+
                                        print "</tr>";
 
                                } else {
 
                                                        $cur_feed_title = htmlspecialchars($cur_feed_title);
 
-                                                       $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id, \"$cur_feed_title\");' href='#'>mark as read</a>)";
+                                                       $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>mark as read</a>)";
+
+                                                       $has_feed_icon = feed_has_icon($feed_id);
+
+                                                       if ($has_feed_icon) {
+                                                               $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
+                                                       } else {
+                                                               //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
+                                                       }
 
                                                        print "<div class='cdmFeedTitle'>".
+                                                               "<div style=\"float : right\">$feed_icon_img</div>".
                                                                "<a href=\"javascript:viewfeed($feed_id, '', false)\">".
                                                                $line["feed_title"]."</a> $vf_catchup_link</div>";
                                                }
 
                                        print "<div class=\"cdmHeader\">";
 
-                                       print "<div class=\"articleUpdated\">$updated_fmt $score_pic</div>";
+                                       if (!get_pref($link, "VFEED_GROUP_BY_FEED") || !$line["feed_title"]) {
+                                               $cdm_feed_icon = "<span style=\"cursor : pointer\" onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
+                                       }
+
+                                       print "<div class=\"articleUpdated\">$updated_fmt $score_pic $cdm_feed_icon
+                                               </div>";
 
                                        print "<span id=\"RTITLE-$id\" class=\"titleWrap$hlc_suffix\"><a class=\"title\" 
                                                onclick=\"javascript:toggleUnread($id, 0)\"
 
 //                                     print "<div class=\"cdmInnerContent\" id=\"CICD-$id\" $cdm_cstyle>";
 
-                                       print $line["content_preview"];
+                                       print sanitize_rss($link, $line["content_preview"]);
 
                                        $e_result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
                                                post_id = '$id' AND content_url != ''");
 
                                        if (db_num_rows($e_result) > 0) {
-                               print "<div class=\"cdmEnclosures\">";
-
-                               if (db_num_rows($e_result) == 1) {
-                                       print __("Attachment:") . " ";
-                               } else {
-                                       print __("Attachments:") . " ";
-                               }
 
+                               $entries_html = array();
                                $entries = array();
 
                                while ($e_line = db_fetch_assoc($e_result)) {
 
                                        $filename = substr($url, strrpos($url, "/")+1);
 
-                                       $entry = "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
+                                       $entry = ""; 
+                                       
+                                       if (($ctype == __("audio/mpeg")) && 
+                                               (get_pref($link, "ENABLE_FLASH_PLAYER")) ) { 
+                                               
+                                               $entry .= "<object type=\"application/x-shockwave-flash\" data=\"extras/button/musicplayer.swf?song_url=$url\" width=\"17\" height=\"17\"> <param name=\"movie\" value=\"extras/button/musicplayer.swf?song_url=$url\" /> </object> "; 
+                                       
+                                       }
+
+                                       $entry .= "<a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
                                                $filename . " (" . $ctype . ")" . "</a>";
 
+                                       array_push($entries_html, $entry);
+
+                                       $entry = array();
+
+                                       $entry["type"] = $ctype;
+                                       $entry["filename"] = $filename;
+                                       $entry["url"] = $url;
+
                                        array_push($entries, $entry);
                                }
 
-                               print join(", ", $entries);
+                               if (!preg_match("/img/i", $line["content"])) {
+                                       foreach ($entries as $entry) {
+                                               if (preg_match("/image/", $entry["type"])) {
+                                                       print "<p><img 
+                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"></p>";
+                                               }
+                                       }
+                               }
+
+                               print "<div class=\"cdmEnclosures\">";
+
+                               if (db_num_rows($e_result) == 1) {
+                                       print __("Attachment:") . " ";
+                               } else {
+                                       print __("Attachments:") . " ";
+                               }
+
+                               print join(", ", $entries_html);
 
                                print "</div>";
                        }
 
+
                                        print "<br clear='both'>";
 //                                     print "</div>";
 
 
                                        print "</span><span class='s1'>$marked_pic</span> ";
                                        print "<span class='s1'>$published_pic</span> ";
+                                       print "<span class='s1'><img src=\"images/art-zoom.png\" class='tagsPic' 
+                                               onclick=\"zoomToArticle($id)\"
+                                               style=\"cursor : pointer\"
+                                               alt='Zoom' 
+                                               title='".__('Show article summary in new window')."'></span>";
 
                                        $tags = get_article_tags($link, $id);
 
 
        function article_publish_url($link) {
 
-               $url_path = ($_SERVER['HTTPS'] != "on" ? 'http://' :  'https://') . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
+               $url_path = "";
+               
+
+               if ($_SERVER['HTTPS'] != "on") {
+                       $url_path = "http://";
+               } else {
+                       $url_path = "https://";
+               }
 
-               $url_path .= "?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");
+               $url_path .= $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
+               $url_path .= "/backend.php?op=publish&key=" . get_pref($link, "_PREFS_PUBLISH_KEY");
 
                return $url_path;
        }
        }
 
        function get_score_pic($score) {
-               if ($score > 0) { 
+               if ($score > 100) { 
                        return "score_high.png"; 
-               } else if ($score < 0) {
+               } else if ($score > 0) { 
+                       return "score_half_high.png"; 
+               } else if ($score < -100) {
                        return "score_low.png"; 
+               } else if ($score < 0) {
+                       return "score_half_low.png"; 
                } else { 
                        return "score_neutral.png"; 
                }
 
        function rounded_table_start($classname, $header = "&nbsp;") {
                print "<table width='100%' class='$classname' cellspacing='0' cellpadding='0'>";
-               print "<tr><td class='c1'>&nbsp;</td><td class='top'>$header</td><td class='c2'>&nbsp;</tr>";
+               print "<tr><td class='c1'>&nbsp;</td><td class='top'>$header</td><td class='c2'>&nbsp;</td></tr>";
                print "<tr><td class='left'>&nbsp;</td><td class='content'>";
        }
 
        function rounded_table_end($footer = "&nbsp;") {
                print "</td><td class='right'>&nbsp;</td></tr>";
-               print "<tr><td class='c4'>&nbsp;</td><td class='bottom'>$footer</td><td class='c3'>&nbsp;</tr>";
+               print "<tr><td class='c4'>&nbsp;</td><td class='bottom'>$footer</td><td class='c3'>&nbsp;</td></tr>";
                print "</table>";
        }
 
+       function print_label_dlg_common_examples() {
+
+               print __("Match ") . " ";
+
+/*             print "<select name=\"label_andor\">";
+               print "<option value=\"and\">AND</option>";
+               print "<option value=\"or\">OR</option>";
+               print "</select>"; */
+
+               print "<select name=\"label_fields\" onchange=\"labelFieldsCheck(this)\">";
+               print "<option value=\"unread\">".__("Unread articles")."</option>";
+               print "<option value=\"updated\">".__("Updated articles")."</option>";
+               print "<option value=\"kw_title\">".__("Title contains")."</option>";
+               print "<option value=\"kw_content\">".__("Content contains")."</option>";
+               print "<option value=\"scoreE\">".__("Score equals")."</option>";
+               print "<option value=\"scoreG\">".__("Score is greater than")."</option>";
+               print "<option value=\"scoreL\">".__("Score is less than")."</option>";
+               print "<option value=\"newerH\">".__("Articles newer than X hours")."</option>";
+               print "<option value=\"newerD\">".__("Articles newer than X days")."</option>";
+
+               print "</select>";
+
+               print "<input style=\"display : none\" name=\"label_fields_param\"
+                       size=\"10\">";
+
+               print " <input type=\"submit\" 
+                       onclick=\"return addLabelExample()\"
+                       value=\"".__("Add")."\">";
+       }
+
+       function feed_has_icon($id) {
+               return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
+       }
+
+       function init_connection($link) {
+               if (DB_TYPE == "pgsql") {
+                       pg_query("set client_encoding = 'UTF-8'");
+                       pg_set_client_encoding("UNICODE");
+               } else {
+                       if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+                               db_query($link, "SET NAMES " . MYSQL_CHARSET);
+       //                      db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
+                       }
+               }
+       }
 ?>