]> git.wh0rd.org Git - tt-rss.git/commitdiff
enable caching of images
authorAndrew Dolgov <fox@bah.spb.su>
Sun, 26 Aug 2007 04:00:30 +0000 (05:00 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sun, 26 Aug 2007 04:00:30 +0000 (05:00 +0100)
config.php-dist
functions.php
image.php
modules/pref-feeds.php
tt-rss.css

index 3664254e5ca71c1f75f17b111e59e05a79b8c883..ecacf202879a6b8199d4a922b7cf92426bc3491c 100644 (file)
        // Cache directory for RSS feeds when using SimplePie
 
        define('SIMPLEPIE_CACHE_IMAGES', false);
-       // Ignore this option for now on, it doesn't work yet.
-
-       // Cache feed images when using SimplePie. This will allow you to
-       // see images in feeds when originating server uses some sort of
-       // hotlink prevention at the expense of local bandwidth and
-       // disk space.
-
+       // Allow caching feed images when using SimplePie, to bypass hotlink
+       // prevention and such at expense of local disk space and bandwidth.
+       // Note that you (or your users) also have to enable image caching 
+       // in feed editor.
+       
        define('COUNTERS_MAX_AGE', 365);
        // Hard limit for unread counters calculation. Try tweaking this
        // parameter to speed up tt-rss when having a huge number of articles
index d2f04216afe24e78f331792e057c165c91c0d458..c321f9b4fd10e2ae397d66acdf69f21d135c8c3d 100644 (file)
                        _debug("update_rss_feed: start");
                }
 
-               $result = db_query($link, "SELECT update_interval,auth_login,auth_pass  
+               $result = db_query($link, "SELECT update_interval,auth_login,auth_pass,cache_images
                        FROM ttrss_feeds WHERE id = '$feed'");
 
                $auth_login = db_fetch_result($result, 0, "auth_login");
                $auth_pass = db_fetch_result($result, 0, "auth_pass");
 
                $update_interval = db_fetch_result($result, 0, "update_interval");
+               $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
 
                if ($update_interval < 0) { return; }
 
                        $rss->set_feed_url($fetch_url);
                        $rss->set_output_encoding('UTF-8');
 
-/*                     if (SIMPLEPIE_CACHE_IMAGES) {
+                       if (SIMPLEPIE_CACHE_IMAGES && $cache_images) {
+                               if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
+                                       _debug("enabling image cache");
+                               }
+
                                $rss->set_image_handler('./image.php', 'i');
-                       } */
+                       }
 
                        if (defined('DAEMON_EXTENDED_DEBUG') || $_GET['xdebug']) {
                                _debug("feed update interval (sec): " .
index 49c3ec89b2bca4e93256a68cb9307641864d46e9..6bed38b7cfff93620f420cc6daf21ce62a76281c 100644 (file)
--- a/image.php
+++ b/image.php
@@ -1,6 +1,6 @@
 <?php
-// This should be modifed as your own use warrants.
+       require_once "config.php";
+       require_once "simplepie/simplepie.inc";
 
-require_once('../simplepie.inc');
-SimplePie_Misc::display_cached_file($_GET['i'], './cache', 'spi');
+       SimplePie_Misc::display_cached_file($_GET['i'], SIMPLEPIE_CACHE_DIR, 'spi');
 ?>
index af7f772c5ac3fcc261232ce3ff4f7295eb972461..f0081a097d7aac83da2e067e096b5416a30f84aa 100644 (file)
                                name=\"include_in_digest\"
                                $checked><label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
 
+                       $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
+
+                       if ($cache_images) {
+                               $checked = "checked";
+                       } else {
+                               $checked = "";
+                       }
+
+                       if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
+                               $disabled = "";
+                               $label_class = "";
+                       } else {
+                               $disabled = "disabled";
+                               $label_class = "class='insensitive'";
+                       }
+
+                       print "<br><input type=\"checkbox\" id=\"cache_images\" 
+                               name=\"cache_images\" $disabled
+                               $checked><label $label_class for=\"cache_images\">".
+                               __('Cache images locally')."</label>";
+
                        print "</td></tr>";
 
                        print "</table>";
                        $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
                        $include_in_digest = checkbox_to_sql_bool(
                                db_escape_string($_POST["include_in_digest"]));
+                       $cache_images = checkbox_to_sql_bool(
+                               db_escape_string($_POST["cache_images"]));
 
                        if (get_pref($link, 'ENABLE_FEED_CATS')) {                      
                                if ($cat_id && $cat_id != 0) {
                                $parent_qpart = 'parent_feed = NULL';
                        }
 
+                       if (ENABLE_SIMPLEPIE && SIMPLEPIE_CACHE_IMAGES) {
+                               $cache_images_qpart = "cache_images = $cache_images,";
+                       } else {
+                               $cache_images_qpart = "";
+                       }
+
                        $result = db_query($link, "UPDATE ttrss_feeds SET 
                                $category_qpart $parent_qpart,
                                title = '$feed_title', feed_url = '$feed_link',
                                private = $private,
                                rtl_content = $rtl_content,
                                hidden = $hidden,
+                               $cache_images_qpart
                                include_in_digest = $include_in_digest
                                WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
index 5d71070875fbb2b07e5bdfed0de1d38846c17d15..a6b2d3b60d69ed4786186adcf2af913f9c9b347f 100644 (file)
@@ -668,7 +668,7 @@ span.feed_error {
        color : red;
 }
 
-span.insensitive, div.insensitive, li.insensitive {
+span.insensitive, div.insensitive, li.insensitive, label.insensitive {
        color : gray;
 }