diff --git a/.gitignore b/.gitignore
index fa09c4ee6..2c5b9fc2e 100755
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ addon/
widget/
custom/
/store/
+cache/
# site apps
apps/
!doc/context/*/apps
diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php
index 315089f67..c5f7ccbb9 100644
--- a/Zotlabs/Daemon/Cron_weekly.php
+++ b/Zotlabs/Daemon/Cron_weekly.php
@@ -50,7 +50,24 @@ class Cron_weekly {
// Check for dead sites
Master::Summon(array('Checksites'));
-
+
+
+ // clean up image cache - use site expiration or 180 days if not set
+
+ $files = glob('cache/img/*/*');
+ $expire_days = intval(get_config('system','default_expire_days', 180);
+ $now = time();
+
+ if ($files) {
+ foreach ($files as $file) {
+ if (is_file($file)) {
+ if ($now - filemtime($file) >= 60 * 60 * 24 * $expire_days) {
+ unlink($file);
+ }
+ }
+ }
+ }
+
// update searchable doc indexes
// disabled until help system regenerated
// Master::Summon(array('Importdoc'));
diff --git a/Zotlabs/Module/Ca.php b/Zotlabs/Module/Ca.php
new file mode 100644
index 000000000..a38f5d2b2
--- /dev/null
+++ b/Zotlabs/Module/Ca.php
@@ -0,0 +1,30 @@
+ 1) {
+ $path = 'cache/img/' . substr(argv(1),0,2) . '/' . argv(1);
+
+ if (file_exists($path)) {
+ $x = @getimagesize($path);
+ if ($x) {
+ header('Content-Type: ' . $x['mime']);
+ }
+ $infile = fopen($path,'rb');
+ $outfile = fopen('php://output','wb');
+ pipe_streams($infile,$outfile);
+ fclose($infile);
+ fclose($outfile);
+ killme();
+ }
+ if ($_GET['url']) {
+ goaway($url);
+ }
+ }
+ http_status_exit(404,'Not found');
+ }
+}
\ No newline at end of file
diff --git a/include/text.php b/include/text.php
index 56d065553..a5171c626 100644
--- a/include/text.php
+++ b/include/text.php
@@ -993,18 +993,38 @@ function linkify($s, $me = false) {
}
/**
- * @brief Replace media element using http url with https to a local redirector
- * if using https locally.
+ * @brief implement image caching
*
- * Looks for HTML tags containing src elements that are http when we're viewing an https page
- * Typically this throws an insecure content violation in the browser. So we redirect them
- * to a local redirector which uses https and which redirects to the selected content
+ * Note: This is named sslify because the old behaviour was only to proxy image fetches to
+ * non-SSL resources. Now all images are cached.
*
* @param string $s
* @returns string
*/
function sslify($s) {
+ if (! intval(get_config('system','cache_images', 1))) {
+
+ if (strpos(z_root(),'https:') === false) {
+ return $s;
+ }
+
+ // we'll only sslify img tags because media files will probably choke.
+
+ $pattern = "/\/";
+
+ $matches = null;
+ $cnt = preg_match_all($pattern,$s,$matches,PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $match) {
+ $filename = basename( parse_url($match[2], PHP_URL_PATH) );
+ $s = str_replace($match[2],z_root() . '/sslify/' . $filename . '?f=&url=' . urlencode($match[2]),$s);
+ }
+ }
+
+ return $s;
+ }
+
$pattern = "/\/ism";
$matches = null;
@@ -1016,7 +1036,7 @@ function sslify($s) {
}
$cached = Img_cache::check($match[2],'cache/img');
if ($cached) {
- $s = str_replace($match[2],z_root() . '/' . Img_cache::get_filename($match[2],'cache/img') . '?url=' . urlencode($match[2]),$s);
+ $s = str_replace($match[2],z_root() . '/ca/' . basename(Img_cache::get_filename($match[2],'cache/img')) . '?url=' . urlencode($match[2]),$s);
}
}
}
diff --git a/install/INSTALL.txt b/install/INSTALL.txt
index 20bb5f766..9bb864e15 100644
--- a/install/INSTALL.txt
+++ b/install/INSTALL.txt
@@ -105,9 +105,10 @@ web server platforms.
- make sure folders *cache/smarty3* and *store* exist and are
writable by the webserver
+ mkdir -p "store"
mkdir -p "cache/smarty3"
-
- chmod -R 777 store
+
+ chmod -R 777 store cache
[This permission (777) is very dangerous and if you have sufficient
privilege and knowledge you should make these directories writeable