mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 01:15:13 +00:00
profile messages for directory synchronisation
This commit is contained in:
parent
91932ac5a8
commit
ce0d389696
2 changed files with 114 additions and 1 deletions
|
@ -644,6 +644,8 @@ function decode_tags($t) {
|
|||
|
||||
}
|
||||
|
||||
// santise a potentially complex array
|
||||
|
||||
function activity_sanitise($arr) {
|
||||
if($arr) {
|
||||
$ret = array();
|
||||
|
@ -658,6 +660,19 @@ function activity_sanitise($arr) {
|
|||
return '';
|
||||
}
|
||||
|
||||
// sanitise a simple linear array
|
||||
|
||||
function array_sanitise($arr) {
|
||||
if($arr) {
|
||||
$ret = array();
|
||||
foreach($arr as $x) {
|
||||
$ret[] = htmlentities($x, ENT_COMPAT,'UTF-8');
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function encode_item_flags($item) {
|
||||
|
||||
// most of item_flags and item_restrict are local settings which don't apply when transmitted.
|
||||
|
@ -726,6 +741,34 @@ function get_mail_elements($x) {
|
|||
}
|
||||
|
||||
|
||||
function get_profile_elements($x) {
|
||||
|
||||
$arr = array();
|
||||
|
||||
if(import_author_xchan($x['from']))
|
||||
$arr['xprof_hash'] = base64url_encode(hash('whirlpool',$x['from']['guid'] . $x['from']['guid_sig'], true));
|
||||
else
|
||||
return array();
|
||||
|
||||
$arr['desc'] = (($x['title']) ? htmlentities($x['title'],ENT_COMPAT,'UTF-8') : '');
|
||||
|
||||
$arr['dob'] = datetime_convert('UTC','UTC',$x['birthday'],'Y-m-d');
|
||||
|
||||
$arr['gender'] = (($x['gender']) ? htmlentities($x['gender'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['marital'] = (($x['marital']) ? htmlentities($x['marital'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['sexual'] = (($x['sexual']) ? htmlentities($x['sexual'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['locale'] = (($x['locale']) ? htmlentities($x['locale'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['region'] = (($x['region']) ? htmlentities($x['region'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['postcode'] = (($x['postcode']) ? htmlentities($x['postcode'], ENT_COMPAT,'UTF-8') : '');
|
||||
$arr['country'] = (($x['country']) ? htmlentities($x['country'], ENT_COMPAT,'UTF-8') : '');
|
||||
|
||||
$arr['keywords'] = (($x['keywords'] && is_array($x['keywords'])) ? array_sanitise($x['keywords']) : array());
|
||||
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function get_atom_elements($feed,$item) {
|
||||
|
||||
|
|
|
@ -722,8 +722,16 @@ function zot_import($arr) {
|
|||
process_mail_delivery($i['notify']['sender'],$arr,$deliveries);
|
||||
|
||||
}
|
||||
}
|
||||
elseif($i['message']['type'] === 'profile') {
|
||||
$arr = get_profile_elements($i['message']);
|
||||
|
||||
logger('Profile received: ' . print_r($arr,true));
|
||||
logger('Profile recipients: ' . print_r($deliveries,true));
|
||||
|
||||
process_profile_delivery($i['notify']['sender'],$arr,$deliveries);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -901,3 +909,65 @@ function process_mail_delivery($sender,$arr,$deliveries) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function process_profile_delivery($sender,$arr,$deliveries) {
|
||||
|
||||
// deliveries is irrelevant
|
||||
|
||||
$r = q("select * from xprof where xprof_hash = '%s' limit 1",
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
if(! $r) {
|
||||
$x = q("insert into xprof ( xprof_hash, xprof_desc, xprof_dob, xprof_gender, xprof_marital, xprof_sexual,
|
||||
xprof_locale, xprof_region, xprof_postcode, xprof_country ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
dbesc($sender['hash']),
|
||||
dbesc($arr['desc']),
|
||||
dbesc($arr['dob']),
|
||||
dbesc($arr['gender']),
|
||||
dbesc($arr['marital']),
|
||||
dbesc($arr['sexual']),
|
||||
dbesc($arr['locale']),
|
||||
dbesc($arr['region']),
|
||||
dbesc($arr['postcode']),
|
||||
dbesc($arr['country'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
$x = q("update xprof set
|
||||
xprof_desc = '%s'
|
||||
xprof_dob = '%s',
|
||||
xprof_gender = '%s',
|
||||
xprof_marital = '%s',
|
||||
xprof_sexual = '%s',
|
||||
xprof_locale = '%s',
|
||||
xprof_region = '%s',
|
||||
xprof_postcode = '%s',
|
||||
xprof_country = '%s'
|
||||
where xprof_hash = '%s' limit 1",
|
||||
dbesc($arr['desc']),
|
||||
dbesc($arr['dob']),
|
||||
dbesc($arr['gender']),
|
||||
dbesc($arr['marital']),
|
||||
dbesc($arr['sexual']),
|
||||
dbesc($arr['locale']),
|
||||
dbesc($arr['region']),
|
||||
dbesc($arr['postcode']),
|
||||
dbesc($arr['country']),
|
||||
dbesc($sender['hash'])
|
||||
);
|
||||
}
|
||||
|
||||
// optimise this, get existing tags and check which still exist and which don't!!!
|
||||
|
||||
$x = q("delete from xtag where xtag_hash = '%s'");
|
||||
if($arr['keywords']) {
|
||||
foreach($arr['keywords'] as $tag) {
|
||||
$r = q("insert into xtag ( xtag_hash, xtag_term ) values ( '%s', '%s' )",
|
||||
dbesc($sender['hash']),
|
||||
dbesc($tag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue