cache oembed request

2022.09-rc
Fabio Comuni 2011-01-31 17:23:55 +01:00
rodzic 3dbca2a804
commit bdbbfe17b0
1 zmienionych plików z 14 dodań i 2 usunięć

Wyświetl plik

@ -1,8 +1,20 @@
<?php <?php
function oembed_replacecb($matches){ function oembed_replacecb($matches){
$embedurl=$matches[1]; $embedurl=$matches[1];
$ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl);
$txt = fetch_url($ourl); $r = q("SELECT v FROM `cache` WHERE k='%s'",
dbesc($embedurl));
if(count($r)){
$txt = $r[0]['v'];
} else {
$ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl);
$txt = fetch_url($ourl);
//save in cache
q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
dbesc($embedurl),
dbesc($txt),
dbesc(datetime_convert()));
}
$j = json_decode($txt); $j = json_decode($txt);
$ret="<span class='oembed'>"; $ret="<span class='oembed'>";
switch ($j->type) { switch ($j->type) {