structures for batch mode (Diaspora/zot)

This commit is contained in:
Friendika 2011-09-20 01:49:08 -07:00
parent 8a11cec61a
commit 9edf15d3ef
7 changed files with 75 additions and 30 deletions

View file

@ -9,7 +9,7 @@ require_once("include/pgettext.php");
define ( 'FRIENDIKA_VERSION', '2.3.1109' ); define ( 'FRIENDIKA_VERSION', '2.3.1109' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1090 ); define ( 'DB_UPDATE_VERSION', 1091 );
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' );

View file

@ -70,6 +70,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
`alias` char(255) NOT NULL, `alias` char(255) NOT NULL,
`pubkey` text NOT NULL, `pubkey` text NOT NULL,
`prvkey` text NOT NULL, `prvkey` text NOT NULL,
`batch` char(255) NOT NULL,
`request` text NOT NULL, `request` text NOT NULL,
`notify` text NOT NULL, `notify` text NOT NULL,
`poll` text NOT NULL, `poll` text NOT NULL,

View file

@ -496,8 +496,10 @@ function probe_url($url, $mode = PROBE_NORMAL) {
} }
if($diaspora && $diaspora_base && $diaspora_guid) { if($diaspora && $diaspora_base && $diaspora_guid) {
if($mode == PROBE_DIASPORA || ! $notify) if($mode == PROBE_DIASPORA || ! $notify) {
$notify = $diaspora_base . 'receive/users/' . $diaspora_guid; $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
$batch = $diaspora_base . 'receive/public' ;
}
if(strpos($url,'@')) if(strpos($url,'@'))
$addr = str_replace('acct:', '', $url); $addr = str_replace('acct:', '', $url);
} }
@ -675,6 +677,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$result['nick'] = $vcard['nick']; $result['nick'] = $vcard['nick'];
$result['url'] = $profile; $result['url'] = $profile;
$result['addr'] = $addr; $result['addr'] = $addr;
$result['batch'] = $batch;
$result['notify'] = $notify; $result['notify'] = $notify;
$result['poll'] = $poll; $result['poll'] = $poll;
$result['request'] = $request; $result['request'] = $request;

View file

@ -68,6 +68,7 @@ function diaspora_get_contact_by_handle($uid,$handle) {
} }
function find_diaspora_person_by_handle($handle) { function find_diaspora_person_by_handle($handle) {
$update = false;
$r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
dbesc($handle) dbesc($handle)
@ -75,18 +76,14 @@ function find_diaspora_person_by_handle($handle) {
if(count($r)) { if(count($r)) {
// update record occasionally so it doesn't get stale // update record occasionally so it doesn't get stale
$d = strtotime($r[0]['updated'] . ' +00:00'); $d = strtotime($r[0]['updated'] . ' +00:00');
if($d < strtotime('now - 14 days')) { if($d > strtotime('now - 14 days'))
q("delete from fcontact where id = %d limit 1",
intval($r[0]['id'])
);
}
else
return $r[0]; return $r[0];
$update = true;
} }
require_once('include/Scrape.php'); require_once('include/Scrape.php');
$r = probe_url($handle, PROBE_DIASPORA); $r = probe_url($handle, PROBE_DIASPORA);
if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) { if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
add_fcontact($r); add_fcontact($r,$update);
return ($r); return ($r);
} }
return false; return false;

View file

@ -701,24 +701,59 @@ function parse_xml_string($s,$strict = true) {
return $x; return $x;
}} }}
function add_fcontact($arr) { function add_fcontact($arr,$update = false) {
$r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`, if($update) {
`notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated` ) $r = q("UPDATE `fcontact` SET
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", `name` = '%s',
dbesc($arr['url']), `photo` = '%s',
dbesc($arr['name']), `request` = '%s',
dbesc($arr['photo']), `nick` = '%s',
dbesc($arr['request']), `addr` = '%s',
dbesc($arr['nick']), `batch` = '%s',
dbesc($arr['addr']), `notify` = '%s',
dbesc($arr['notify']), `poll` = '%s',
dbesc($arr['poll']), `confirm` = '%s',
dbesc($arr['confirm']), `alias` = '%s',
dbesc($arr['network']), `pubkey` = '%s',
dbesc($arr['alias']), `updated` = '%s'
dbesc($arr['pubkey']), WHERE `url` = '%s' AND `network` = '%s' LIMIT 1",
dbesc(datetime_convert()) dbesc($arr['name']),
); dbesc($arr['photo']),
dbesc($arr['request']),
dbesc($arr['nick']),
dbesc($arr['addr']),
dbesc($arr['batch']),
dbesc($arr['notify']),
dbesc($arr['poll']),
dbesc($arr['confirm']),
dbesc($arr['network']),
dbesc($arr['alias']),
dbesc($arr['pubkey']),
dbesc(datetime_convert()),
dbesc($arr['url']),
dbesc($arr['network'])
);
}
else {
$r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`,
`batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated` )
values('%s','%s','%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['batch']),
dbesc($arr['notify']),
dbesc($arr['poll']),
dbesc($arr['confirm']),
dbesc($arr['network']),
dbesc($arr['alias']),
dbesc($arr['pubkey']),
dbesc(datetime_convert())
);
}
return $r; return $r;
} }

View file

@ -100,14 +100,15 @@ function follow_post(&$a) {
$new_relation = CONTACT_IS_FOLLOWER; $new_relation = CONTACT_IS_FOLLOWER;
// create contact record // create contact record
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `batch`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
`writable`, `blocked`, `readonly`, `pending` ) `writable`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
intval(local_user()), intval(local_user()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($ret['url']), dbesc($ret['url']),
dbesc($ret['addr']), dbesc($ret['addr']),
dbesc($ret['alias']), dbesc($ret['alias']),
dbesc($ret['batch']),
dbesc($ret['notify']), dbesc($ret['notify']),
dbesc($ret['poll']), dbesc($ret['poll']),
dbesc($ret['name']), dbesc($ret['name']),

View file

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1090 ); define( 'UPDATE_VERSION' , 1091 );
/** /**
* *
@ -753,3 +753,11 @@ function update_1088() {
function update_1089() { function update_1089() {
q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` "); q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` ");
} }
function update_1090() {
q("ALTER TABLE `contact` ADD `batch` char(255) NOT NULL AFTER `prvkey` ");
q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' ");
}