mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-21 08:15:18 +00:00
Merge branch 'dev' of /home/macgirvin/roadhouse into dev
This commit is contained in:
commit
1acd4fc8e2
4 changed files with 68 additions and 7 deletions
18
Zotlabs/Daemon/Cache_image.php
Normal file
18
Zotlabs/Daemon/Cache_image.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Daemon;
|
||||
|
||||
use Zotlabs\Lib\Img_cache;
|
||||
|
||||
class Cache_image {
|
||||
|
||||
static public function run($argc,$argv) {
|
||||
|
||||
cli_startup();
|
||||
|
||||
if ($argc === 3) {
|
||||
Img_cache::url_to_cache($argv[1],$argv[2]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,6 +12,11 @@ class Img_cache {
|
|||
return Hashpath::path($url,$prefix);
|
||||
}
|
||||
|
||||
// Check to see if we have this url in our cache
|
||||
// If we have it return true.
|
||||
// If we do not, or the cache file is empty or expired, return false
|
||||
// but attempt to fetch the entry in the background
|
||||
|
||||
static function check($url, $prefix = '.') {
|
||||
|
||||
if (strpos($url,z_root()) !== false) {
|
||||
|
@ -22,15 +27,16 @@ class Img_cache {
|
|||
if (file_exists($path)) {
|
||||
$t = filemtime($path);
|
||||
if ($t && time() - $t >= self::$cache_life) {
|
||||
if (self::url_to_cache($url,$path)) {
|
||||
return true;
|
||||
}
|
||||
Run::Summon( [ 'Cache_image', $url, $path ] );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
else {
|
||||
return ((filesize($path)) ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
return self::url_to_cache($url,$path);
|
||||
Run::Summon( [ 'Cache_image', $url, $path ] );
|
||||
return false;
|
||||
}
|
||||
|
||||
static function url_to_cache($url,$file) {
|
||||
|
|
|
@ -9,7 +9,7 @@ class Ca extends Controller {
|
|||
if (argc() > 1) {
|
||||
$path = 'cache/img/' . substr(argv(1),0,2) . '/' . argv(1);
|
||||
|
||||
if (file_exists($path)) {
|
||||
if (file_exists($path) && filesize($path)) {
|
||||
$x = @getimagesize($path);
|
||||
if ($x) {
|
||||
header('Content-Type: ' . $x['mime']);
|
||||
|
|
|
@ -1023,6 +1023,17 @@ function linkify($s, $me = false) {
|
|||
*/
|
||||
function sslify($s, $cache_enable = true) {
|
||||
|
||||
if (! $cache_enable) {
|
||||
|
||||
// we're fetching an old item and we are no longer
|
||||
// caching photos for it. Remove any existing cached photos.
|
||||
// Cron_weekly tasks will also remove these, but if the cache
|
||||
// entry was updated recently they might not get removed for
|
||||
// another couple of months.
|
||||
|
||||
uncache($s);
|
||||
}
|
||||
|
||||
if ((! $cache_enable) || (! intval(get_config('system','cache_images', 1)))) {
|
||||
|
||||
// if caching is prevented for whatever reason, proxy any non-SSL photos
|
||||
|
@ -1067,6 +1078,30 @@ function sslify($s, $cache_enable = true) {
|
|||
return $s;
|
||||
}
|
||||
|
||||
// clean out the image cache
|
||||
|
||||
function uncache($s) {
|
||||
|
||||
$pattern = "/\<img(.*?)src=\"(https?\:.*?)\"(.*?)\>/ism";
|
||||
|
||||
$matches = null;
|
||||
$cnt = preg_match_all($pattern,$s,$matches,PREG_SET_ORDER);
|
||||
if ($cnt) {
|
||||
foreach ($matches as $match) {
|
||||
// repeat the filename generation procedure we used when creating the cache entry
|
||||
$clean = strip_zids(strip_query_param($match[2],'f'));
|
||||
$file = Img_cache::get_filename($clean,'cache/img');
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get an array of poke verbs.
|
||||
*
|
||||
|
@ -1782,6 +1817,8 @@ function prepare_body(&$item,$attach = false,$opts = false) {
|
|||
}
|
||||
$cache_enable = ((($cache_expire) && ($item['created'] < datetime_convert('UTC','UTC', 'now - ' . $cache_expire . ' days'))) ? false : true);
|
||||
|
||||
|
||||
|
||||
if($s)
|
||||
$s = sslify($s, $cache_enable);
|
||||
if($photo)
|
||||
|
|
Loading…
Reference in a new issue