provide backend storage and declaration of directory realm

This commit is contained in:
friendica 2014-08-16 16:10:35 -07:00
parent ba0bf596b5
commit 20bdcb037f
7 changed files with 35 additions and 31 deletions

View File

@ -47,7 +47,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' );
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 ); define ( 'ZOT_REVISION', 1 );
define ( 'DB_UPDATE_VERSION', 1121 ); define ( 'DB_UPDATE_VERSION', 1122 );
define ( 'EOL', '<br />' . "\r\n" ); define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
@ -2040,3 +2040,8 @@ function head_get_icon() {
return $icon; return $icon;
} }
function get_directory_realm() {
if($x = get_config('system','directory_realm'))
return $x;
return DIRECTORY_REALM;
}

View File

@ -116,29 +116,15 @@ function diaspora_handle_from_contact($contact_id) {
); );
if($r) { if($r) {
$contact = $r[0]; $contact = $r[0];
//fixme
// logger("diaspora_handle_from_contact: contact 'self' = " . $contact['self'] . " 'url' = " . $contact['url'], LOGGER_DEBUG);
if($contact['xchan_network'] === 'diaspora') {
$handle = $contact['addr'];
// logger("diaspora_handle_from_contact: contact id is a Diaspora person, handle = " . $handle, LOGGER_DEBUG);
} }
elseif(($contact['xchan_network'] === 'zot') || ($contact['abook_flags'] & ABOOK_FLAG_SELF)) {
$handle = $contact['xchan_addr']; $handle = $contact['xchan_addr'];
// logger("diaspora_handle_from_contact: contact id is a redmatrix person, handle = " . $handle, LOGGER_DEBUG);
}
}
return $handle; return $handle;
} }
function diaspora_get_contact_by_handle($uid,$handle) { function diaspora_get_contact_by_handle($uid,$handle) {
$r = q("SELECT * FROM xchan where xchan_addr = '%s' limit 1", $r = q("SELECT * FROM abook left join xchan on xchan_hash = abook_xchan where xchan_addr = '%s' and abook_channel = %d limit 1",
dbesc($handle) dbesc($handle),
intval($uid)
); );
if($r) if($r)
return $r[0]; return $r[0];
@ -155,11 +141,10 @@ function find_diaspora_person_by_handle($handle) {
$maxloops = 10; $maxloops = 10;
do { do {
$r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", $r = q("select * from xchan where xchan_addr = '%s' limit 1",
dbesc(NETWORK_DIASPORA),
dbesc($handle) dbesc($handle)
); );
if(count($r)) { if($r) {
$person = $r[0]; $person = $r[0];
logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG); logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
@ -559,7 +544,7 @@ function diaspora_request($importer,$xml) {
if(! $sender_handle || ! $recipient_handle) if(! $sender_handle || ! $recipient_handle)
return; return;
$contact = diaspora_get_contact_by_handle($importer['uid'],$sender_handle); $contact = diaspora_get_contact_by_handle($importer['channel_id'],$sender_handle);
if($contact) { if($contact) {
@ -643,7 +628,6 @@ function diaspora_request($importer,$xml) {
$batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public'); $batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public');
$r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`) $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ", VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
intval($importer['uid']), intval($importer['uid']),
@ -779,7 +763,7 @@ function diaspora_post($importer,$xml,$msg) {
return 202; return 202;
} }
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle); $contact = diaspora_get_contact_by_handle($importer['channel_id'],$diaspora_handle);
if(! $contact) if(! $contact)
return; return;
@ -1211,7 +1195,7 @@ function diaspora_comment($importer,$xml,$msg) {
$parent_author_signature = (($xml->parent_author_signature) ? notags(unxmlify($xml->parent_author_signature)) : ''); $parent_author_signature = (($xml->parent_author_signature) ? notags(unxmlify($xml->parent_author_signature)) : '');
$contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']); $contact = diaspora_get_contact_by_handle($importer['channel_id'],$msg['author']);
if(! $contact) { if(! $contact) {
logger('diaspora_comment: cannot find contact: ' . $msg['author']); logger('diaspora_comment: cannot find contact: ' . $msg['author']);
return; return;

View File

@ -2016,6 +2016,7 @@ function import_site($arr,$pubkey) {
$url = htmlspecialchars($arr['url'],ENT_COMPAT,'UTF-8',false); $url = htmlspecialchars($arr['url'],ENT_COMPAT,'UTF-8',false);
$sellpage = htmlspecialchars($arr['sellpage'],ENT_COMPAT,'UTF-8',false); $sellpage = htmlspecialchars($arr['sellpage'],ENT_COMPAT,'UTF-8',false);
$site_location = htmlspecialchars($arr['location'],ENT_COMPAT,'UTF-8',false); $site_location = htmlspecialchars($arr['location'],ENT_COMPAT,'UTF-8',false);
$site_realm = htmlspecialchars($arr['realm'],ENT_COMPAT,'UTF-8',false);
if($exists) { if($exists) {
if(($siterecord['site_flags'] != $site_directory) if(($siterecord['site_flags'] != $site_directory)
@ -2023,13 +2024,14 @@ function import_site($arr,$pubkey) {
|| ($siterecord['site_directory'] != $directory_url) || ($siterecord['site_directory'] != $directory_url)
|| ($siterecord['site_sellpage'] != $sellpage) || ($siterecord['site_sellpage'] != $sellpage)
|| ($siterecord['site_location'] != $site_location) || ($siterecord['site_location'] != $site_location)
|| ($siterecord['site_register'] != $register_policy)) { || ($siterecord['site_register'] != $register_policy)
|| ($siterecord['site_realm'] != $site_realm)) {
$update = true; $update = true;
// logger('import_site: input: ' . print_r($arr,true)); // logger('import_site: input: ' . print_r($arr,true));
// logger('import_site: stored: ' . print_r($siterecord,true)); // logger('import_site: stored: ' . print_r($siterecord,true));
$r = q("update site set site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s' $r = q("update site set site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s'
where site_url = '%s' limit 1", where site_url = '%s' limit 1",
dbesc($site_location), dbesc($site_location),
intval($site_directory), intval($site_directory),
@ -2038,6 +2040,7 @@ function import_site($arr,$pubkey) {
intval($register_policy), intval($register_policy),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($sellpage), dbesc($sellpage),
dbesc($site_realm),
dbesc($url) dbesc($url)
); );
if(! $r) { if(! $r) {

View File

@ -945,13 +945,15 @@ CREATE TABLE IF NOT EXISTS `site` (
`site_register` int(11) NOT NULL DEFAULT '0', `site_register` int(11) NOT NULL DEFAULT '0',
`site_sellpage` char(255) NOT NULL DEFAULT '', `site_sellpage` char(255) NOT NULL DEFAULT '',
`site_location` char(255) NOT NULL DEFAULT '', `site_location` char(255) NOT NULL DEFAULT '',
`site_realm` char(255) NOT NULL DEFAULT '',
PRIMARY KEY (`site_url`), PRIMARY KEY (`site_url`),
KEY `site_flags` (`site_flags`), KEY `site_flags` (`site_flags`),
KEY `site_update` (`site_update`), KEY `site_update` (`site_update`),
KEY `site_directory` (`site_directory`), KEY `site_directory` (`site_directory`),
KEY `site_register` (`site_register`), KEY `site_register` (`site_register`),
KEY `site_access` (`site_access`), KEY `site_access` (`site_access`),
KEY `site_sellpage` (`site_sellpage`) KEY `site_sellpage` (`site_sellpage`),
KEY `site_realm` (`site_realm`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `source` ( CREATE TABLE IF NOT EXISTS `source` (

View File

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1121 ); define( 'UPDATE_VERSION' , 1122 );
/** /**
* *
@ -1360,3 +1360,12 @@ ADD INDEX ( `public_policy` )");
} }
function update_r1121() {
$r = q("ALTER TABLE `site` ADD `site_realm` CHAR( 255 ) NOT NULL DEFAULT '',
ADD INDEX ( `site_realm` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}

View File

@ -297,6 +297,7 @@ function zfinger_init(&$a) {
$ret['site']['sitename'] = get_config('system','sitename'); $ret['site']['sitename'] = get_config('system','sitename');
$ret['site']['sellpage'] = get_config('system','sellpage'); $ret['site']['sellpage'] = get_config('system','sellpage');
$ret['site']['location'] = get_config('system','site_location'); $ret['site']['location'] = get_config('system','site_location');
$ret['site']['realm'] = get_directory_realm();
} }
call_hooks('zot_finger',$ret); call_hooks('zot_finger',$ret);

View File

@ -1 +1 @@
2014-08-15.768 2014-08-16.769