From c0b8e63a3fe600326e0f18c03207ba9fd30c8126 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 18 Jul 2011 18:13:46 -0700 Subject: [PATCH] basic diaspora discovery --- boot.php | 14 +++++++++++++- database.sql | 1 + mod/register.php | 5 +++-- mod/xrd.php | 15 +++++++++++++++ update.php | 25 ++++++++++++++++++++++++- view/xrd_diaspora.tpl | 3 +++ view/xrd_person.tpl | 1 + 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 view/xrd_diaspora.tpl diff --git a/boot.php b/boot.php index 0bf92c99e1..abb043036b 100644 --- a/boot.php +++ b/boot.php @@ -2,7 +2,7 @@ define ( 'FRIENDIKA_VERSION', '2.2.1045' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); -define ( 'DB_UPDATE_VERSION', 1075 ); +define ( 'DB_UPDATE_VERSION', 1076 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -2957,3 +2957,15 @@ function return_bytes ($size_str) { } }} +function generate_guid() { + $found = true; + do { + $guid = substr(random_string(),0,16); + $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", + dbesc($guid) + ); + if(! count($x)) + $found = false; + } while ($found == true ); + return $guid; +} \ No newline at end of file diff --git a/database.sql b/database.sql index 8ea3e42de7..50697845a3 100644 --- a/database.sql +++ b/database.sql @@ -379,6 +379,7 @@ CREATE TABLE IF NOT EXISTS `session` ( CREATE TABLE IF NOT EXISTS `user` ( `uid` int(11) NOT NULL AUTO_INCREMENT, + `guid` char(16) NOT NULL, `username` char(255) NOT NULL, `password` char(255) NOT NULL, `nickname` char(255) NOT NULL, diff --git a/mod/register.php b/mod/register.php index 549d07a918..94eac7a14e 100644 --- a/mod/register.php +++ b/mod/register.php @@ -198,9 +198,10 @@ function register_post(&$a) { $spkey = openssl_pkey_get_details($sres); $spubkey = $spkey["key"]; - $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`, + $r = q("INSERT INTO `user` ( `guid`, `username`, `password`, `email`, `openid`, `nickname`, `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` ) - VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", + VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", + dbesc(generate_guid()), dbesc($username), dbesc($new_password_encoded), dbesc($email), diff --git a/mod/xrd.php b/mod/xrd.php index de0c20ea5d..accc2f68ef 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -27,6 +27,20 @@ function xrd_content(&$a) { header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); + $dspr_enabled = get_config('system','diaspora_enabled'); + + if($dspr_enabled) { + $tpl = file_get_contents('view/xrd_diaspora.tpl'); + $dspr = replace_macros($tpl,array( + '$baseurl' => $a->get_baseurl(), + '$dspr_guid' => $r[0]['guid'], + '$dspr_key' => base64_encode($r[0]['pubkey']) + )); + } + else + $dspr = ''; + + $tpl = file_get_contents('view/xrd_person.tpl'); $o = replace_macros($tpl, array( @@ -34,6 +48,7 @@ function xrd_content(&$a) { '$profile_url' => $a->get_baseurl() . '/profile/' . $r[0]['nickname'], '$atom' => $a->get_baseurl() . '/dfrn_poll/' . $r[0]['nickname'], '$photo' => $a->get_baseurl() . '/photo/profile/' . $r[0]['uid'] . '.jpg', + '$dspr' => $dspr, '$salmon' => $a->get_baseurl() . '/salmon/' . $r[0]['nickname'], '$salmen' => $a->get_baseurl() . '/salmon/' . $r[0]['nickname'] . '/mention', '$modexp' => 'data:application/magic-public-key,' . $salmon_key diff --git a/update.php b/update.php index f2cd5573f5..9c55f15cf5 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ + + diff --git a/view/xrd_person.tpl b/view/xrd_person.tpl index b99f7c1fce..0dabaa5a31 100644 --- a/view/xrd_person.tpl +++ b/view/xrd_person.tpl @@ -19,6 +19,7 @@ + $dspr