mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
relocate the cache class
This commit is contained in:
parent
2a32713dfc
commit
e5c66d94f2
5 changed files with 52 additions and 73 deletions
46
Zotlabs/Lib/Cache.php
Normal file
46
Zotlabs/Lib/Cache.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php /** @file */
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
/**
|
||||
* cache api
|
||||
*/
|
||||
|
||||
class Cache {
|
||||
public static function get($key) {
|
||||
$r = q("SELECT v FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
if ($r)
|
||||
return $r[0]['v'];
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function set($key,$value) {
|
||||
|
||||
$r = q("SELECT * FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($key)
|
||||
);
|
||||
if($r) {
|
||||
q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'",
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($key));
|
||||
}
|
||||
else {
|
||||
q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')",
|
||||
dbesc($key),
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function clear() {
|
||||
q("DELETE FROM cache WHERE updated < '%s'",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
|
||||
}
|
||||
|
||||
}
|
||||
|
1
boot.php
1
boot.php
|
@ -34,7 +34,6 @@ require_once('include/text.php');
|
|||
require_once('include/datetime.php');
|
||||
require_once('include/language.php');
|
||||
require_once('include/nav.php');
|
||||
require_once('include/cache.php');
|
||||
require_once('include/permissions.php');
|
||||
require_once('library/Mobile_Detect/Mobile_Detect.php');
|
||||
require_once('include/features.php');
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
<?php /** @file */
|
||||
|
||||
/**
|
||||
* cache api
|
||||
*/
|
||||
|
||||
class Cache {
|
||||
public static function get($key){
|
||||
$r = q("SELECT v FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
if ($r)
|
||||
return $r[0]['v'];
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function set($key,$value) {
|
||||
|
||||
$r = q("SELECT * FROM cache WHERE k = '%s' limit 1",
|
||||
dbesc($key)
|
||||
);
|
||||
if($r) {
|
||||
q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'",
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($key));
|
||||
}
|
||||
else {
|
||||
q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')",
|
||||
dbesc($key),
|
||||
dbesc($value),
|
||||
dbesc(datetime_convert()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function clear(){
|
||||
q("DELETE FROM cache WHERE updated < '%s'",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
<?php /** @file */
|
||||
|
||||
|
||||
use Zotlabs\Lib as Zlib;
|
||||
|
||||
function oembed_replacecb($matches){
|
||||
|
||||
$embedurl=$matches[1];
|
||||
|
@ -130,7 +132,7 @@ function oembed_fetch_url($embedurl){
|
|||
$txt = null;
|
||||
|
||||
if($action !== 'block') {
|
||||
$txt = Cache::get(App::$videowidth . $embedurl);
|
||||
$txt = Zlib\Cache::get('[' . App::$videowidth . '] ' . $embedurl);
|
||||
|
||||
if(strstr($txt,'youtu') && strstr(z_root(),'https:')) {
|
||||
$txt = str_replace('http:','https:',$txt);
|
||||
|
@ -199,7 +201,7 @@ function oembed_fetch_url($embedurl){
|
|||
//save in cache
|
||||
|
||||
if(! get_config('system','oembed_cache_disable'))
|
||||
Cache::set(App::$videowidth . $embedurl,$txt);
|
||||
Zlib\Cache::set('[' . App::$videowidth . '] ' . $embedurl,$txt);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -376,30 +376,6 @@ function unxmlify($s) {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper, reverse the operation "bin2hex"
|
||||
* This is a built-in function in php >= 5.4
|
||||
*
|
||||
* @FIXME We already have php >= 5.4 requirements, so can we remove this?
|
||||
*/
|
||||
if(! function_exists('hex2bin')) {
|
||||
function hex2bin($s) {
|
||||
if(! (is_string($s) && strlen($s)))
|
||||
return '';
|
||||
|
||||
if(strlen($s) & 1) {
|
||||
logger('hex2bin: illegal hex string: ' . $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
if(! ctype_xdigit($s)) {
|
||||
return($s);
|
||||
}
|
||||
|
||||
return(pack("H*",$s));
|
||||
}}
|
||||
|
||||
|
||||
// Automatic pagination.
|
||||
// To use, get the count of total items.
|
||||
// Then call App::set_pager_total($number_items);
|
||||
|
@ -1283,7 +1259,7 @@ function normalise_link($url) {
|
|||
* is https and the other isn't, or if one is www.something and the other
|
||||
* isn't - and also ignore case differences.
|
||||
*
|
||||
* @see normalis_link()
|
||||
* @see normalise_link()
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
|
@ -1635,7 +1611,7 @@ function prepare_text($text, $content_type = 'text/bbcode', $cache = false) {
|
|||
|
||||
function create_export_photo_body(&$item) {
|
||||
if(($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) {
|
||||
$j = json_decode($item['object'],true);
|
||||
$j = json_decode($item['obj'],true);
|
||||
if($j) {
|
||||
$item['body'] .= "\n\n" . (($j['body']) ? $j['body'] : $j['bbcode']);
|
||||
$item['sig'] = '';
|
||||
|
|
Loading…
Reference in a new issue