From ce0d38969614fbc1c7e3d9d54d974962a1014357 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 22 Dec 2012 04:33:32 -0800 Subject: profile messages for directory synchronisation --- include/items.php | 43 +++++++++++++++++++++++++++++++++ include/zot.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c2688a9cd..4e656d059 100755 --- a/include/items.php +++ b/include/items.php @@ -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) { diff --git a/include/zot.php b/include/zot.php index 049cf004b..ade35f0f1 100644 --- a/include/zot.php +++ b/include/zot.php @@ -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) + ); + } + } + + +} \ No newline at end of file -- cgit v1.2.3