]> git.mxchange.org Git - friendica.git/commitdiff
cache oembed request
authorFabio Comuni <fabrix.xm@gmail.com>
Mon, 31 Jan 2011 16:23:55 +0000 (17:23 +0100)
committerFabio Comuni <fabrix.xm@gmail.com>
Mon, 31 Jan 2011 16:23:55 +0000 (17:23 +0100)
include/oembed.php

index f9441b370944fb54627e4767f2acf70075911c93..a130357abf75dff3d78f32b39cd221426ce818c3 100644 (file)
@@ -1,8 +1,20 @@
 <?php
 function oembed_replacecb($matches){
   $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);
   $ret="<span class='oembed'>";
   switch ($j->type) {