]> git.mxchange.org Git - friendica.git/commitdiff
fill and expire fcontact cache
authorFriendika <info@friendika.com>
Thu, 18 Aug 2011 11:20:30 +0000 (04:20 -0700)
committerFriendika <info@friendika.com>
Thu, 18 Aug 2011 11:20:30 +0000 (04:20 -0700)
boot.php
database.sql
include/diaspora.php
include/network.php
update.php

index 38ebd1f67ecb23921d13fbb677cfee1019a09bc4..af99ed07081fb6ce3a116fcaa5fa7f58cf757fbb 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -9,7 +9,7 @@ require_once("include/pgettext.php");
 
 define ( 'FRIENDIKA_VERSION',      '2.2.1075' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.21'    );
-define ( 'DB_UPDATE_VERSION',      1080      );
+define ( 'DB_UPDATE_VERSION',      1081      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
index ae036fc74a8b7bfbe5199899d136be6285e9fd6e..605433e6e2044b75491484ff80be8f2f05408099 100644 (file)
@@ -531,6 +531,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
 `network` CHAR( 32 ) NOT NULL ,
 `alias` CHAR( 255 ) NOT NULL ,
 `pubkey` TEXT NOT NULL ,
+`updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
 INDEX ( `addr` ),
 INDEX ( `network` )
 ) ENGINE = MYISAM DEFAULT CHARSET=utf8;
index 9987c213930f130a6b2c83776f6dd44a04742a6a..81e335dd43f0571aa0c241f10f109c0841e36415 100644 (file)
@@ -4,25 +4,11 @@ require_once('include/crypto.php');
 require_once('include/items.php');
 
 function get_diaspora_key($uri) {
-       $key = '';
-
        logger('Fetching diaspora key for: ' . $uri);
 
-       $arr = lrdd($uri);
-
-       if(is_array($arr)) {
-               foreach($arr as $a) {
-                       if($a['@attributes']['rel'] === 'diaspora-public-key') {
-                               $key = base64_decode($a['@attributes']['href']);
-                       }
-               }
-       }
-       else {
-               return '';
-       }
-
-       if($key)
-               return rsatopem($key);
+       $r = find_diaspora_person_by_handle($uri);
+       if($r)
+               return $r['pubkey'];
        return '';
 }
 
@@ -218,7 +204,7 @@ function diaspora_decode($importer,$xml) {
        $encoding = $base->encoding;
        $alg = $base->alg;
 
-       // Diaspora devs: I can't even begin to tell you how sucky this is. Read the freaking spec.
+       // Diaspora devs: I can't even begin to tell you how sucky this is. Please read the spec.
 
        $signed_data = $data  . (($data[-1] != "\n") ? "\n" : '') . '.' . base64url_encode($type) . "\n" . '.' . base64url_encode($encoding) . "\n" . '.' . base64url_encode($alg) . "\n";
 
@@ -278,28 +264,33 @@ function diaspora_get_contact_by_handle($uid,$handle) {
        return false;
 }
 
-function find_person_by_handle($handle) {
-               $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
-                       dbesc(NETWORK_DIASPORA),
-                       dbesc($handle)
-               );
-               if(count($r))
-                       return $r[0];
-
-               // we don't care about the uid, we just want to save an expensive webfinger probe
-               $r = q("select * from contact where network = '%s' and addr = '%s' LIMIT 1",
-                       dbesc(NETWORK_DIASPORA),
-                       dbesc($handle)
-               );
-               if(count($r))
+function find_diaspora_person_by_handle($handle) {
+       $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
+               dbesc(NETWORK_DIASPORA),
+               dbesc($handle)
+       );
+       if(count($r)) {
+               // update record occasionally so it doesn't get stale
+               $d = strtotime($r[0]['updated'] . ' +00:00');
+               if($d < strtotime('now - 14 days')) {
+                       q("delete from fcontact where id = %d limit 1",
+                               intval($r[0]['id'])
+                       );
+               }
+               else
                        return $r[0];
-               $r = probe_url($handle);
-               // need to cached this, perhaps in fcontact
-               if(count($r))
-                       return ($r);
-               return false;
+       }
+       require_once('include/Scrape.php');
+       $r = probe_url($handle, PROBE_DIASPORA);
+       if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
+               add_fcontact($r);
+               return ($r);
+       }
+       return false;
 }
 
+       
+
 function diaspora_request($importer,$xml) {
 
        $sender_handle = unxmlify($xml->sender_handle);
@@ -504,7 +495,7 @@ function diaspora_comment($importer,$xml,$msg) {
                $key = $msg['key'];
        }
        else {
-               $person = find_person_by_handle($diaspora_handle);      
+               $person = find_diaspora_person_by_handle($diaspora_handle);     
 
                if(is_array($person) && x($person,'pubkey'))
                        $key = $person['pubkey'];
@@ -661,7 +652,7 @@ function diaspora_like($importer,$xml,$msg) {
                $key = $msg['key'];
        }
        else {
-               $person = find_person_by_handle($diaspora_handle);      
+               $person = find_diaspora_person_by_handle($diaspora_handle);     
                if(is_array($person) && x($person,'pubkey'))
                        $key = $person['pubkey'];
                else {
index bbf1d6a63e6ef17244649fce5e9802a15b22aa48..ade8a40ac49a5090487e632852acc93385309ed3 100644 (file)
@@ -693,3 +693,24 @@ function parse_xml_string($s,$strict = true) {
        }
        return $x;
 }}
+
+function add_fcontact($arr) {
+
+       $r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`,
+               `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey` )
+               values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
+               dbesc($arr['url']),
+               dbesc($arr['name']),
+               dbesc($arr['photo']),
+               dbesc($arr['request']),
+               dbesc($arr['nick']),
+               dbesc($arr['addr']),
+               dbesc($arr['notify']),
+               dbesc($arr['poll']),
+               dbesc($arr['confirm']),
+               dbesc($arr['network']),
+               dbesc($arr['alias']),
+               dbesc($arr['pubkey'])
+       );
+       return $r;
+}
index 3586aa5fd2c46a6a42e7ae8783998998c780cdb2..adfb5fe0288e74a6989a640df11b3afb59760d53 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1080 );
+define( 'UPDATE_VERSION' , 1081 );
 
 /**
  *
@@ -671,3 +671,6 @@ function update_1079() {
 
 }
 
+function update_1080() {
+       q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
+}
\ No newline at end of file