From d8903f09f5a6d637b4258632eee16859373e1893 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 4 Dec 2013 00:19:29 -0800 Subject: include re-organisation and more doco, post_to_red fix ampersands in categories --- include/items.php | 42 +++++++++++++++++-------------------- include/zot.php | 23 ++++++++++++++++++-- mod/channel.php | 31 ++++++++------------------- mod/post.php | 4 ++-- mod/profile.php | 17 ++++++++------- util/wp/post_to_red/post_to_red.php | 2 +- version.inc | 2 +- 7 files changed, 62 insertions(+), 59 deletions(-) diff --git a/include/items.php b/include/items.php index fa46b62a1..b6a196f4a 100755 --- a/include/items.php +++ b/include/items.php @@ -609,8 +609,8 @@ function get_item_elements($x) { // once, and after that your hub knows them. Sure some info is in the post, but it's only a transit identifier // and not enough info to be able to look you up from your hash - which is the only thing stored with the post. - if(import_author_xchan($x['author'])) - $arr['author_xchan'] = base64url_encode(hash('whirlpool',$x['author']['guid'] . $x['author']['guid_sig'], true)); + if(($xchan_hash = import_author_xchan($x['author'])) !== false) + $arr['author_xchan'] = $xchan_hash; else return array(); @@ -618,8 +618,8 @@ function get_item_elements($x) { if($arr['author_xchan'] === base64url_encode(hash('whirlpool',$x['owner']['guid'] . $x['owner']['guid_sig'], true))) $arr['owner_xchan'] = $arr['author_xchan']; else { - if(import_author_xchan($x['owner'])) - $arr['owner_xchan'] = base64url_encode(hash('whirlpool',$x['owner']['guid'] . $x['owner']['guid_sig'], true)); + if(($xchan_hash = import_author_xchan($x['owner'])) !== false) + $arr['owner_xchan'] = $xchan_hash; else return array(); } @@ -657,21 +657,18 @@ function get_item_elements($x) { function import_author_xchan($x) { - $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and (hubloc_flags & %d) limit 1", - dbesc($x['guid']), - dbesc($x['guid_sig']), - intval(HUBLOC_FLAGS_PRIMARY) - ); + $arr = array('xchan' => $x, 'xchan_hash' => ''); + call_hooks('import_author_xchan',$arr); + if($arr['xchan_hash']) + return $arr['xchan_hash']; - if($r) { - logger('import_author_xchan: in cache', LOGGER_DEBUG); - return true; + if((! array_key_exists('network', $x)) || ($x['network'] === 'zot')) { + return import_author_zot($x); } - logger('import_author_xchan: entry not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + // TODO: create xchans for other common and/or aligned networks - $them = array('hubloc_url' => $x['url'],'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); - return zot_refresh($them); + return false; } function encode_item($item) { @@ -785,6 +782,7 @@ function encode_item_xchan($xchan) { $ret['name'] = $xchan['xchan_name']; $ret['address'] = $xchan['xchan_addr']; $ret['url'] = $xchan['hubloc_url']; + $ret['network'] = $xchan['xchan_network']; $ret['photo'] = array('mimetype' => $xchan['xchan_photo_mimetype'], 'src' => $xchan['xchan_photo_m']); $ret['guid'] = $xchan['xchan_guid']; $ret['guid_sig'] = $xchan['xchan_guid_sig']; @@ -977,18 +975,16 @@ function get_mail_elements($x) { if($x['attach']) $arr['attach'] = activity_sanitise($x['attach']); - - if(import_author_xchan($x['from'])) - $arr['from_xchan'] = base64url_encode(hash('whirlpool',$x['from']['guid'] . $x['from']['guid_sig'], true)); + if(($xchan_hash = import_author_xchan($x['from'])) !== false) + $arr['from_xchan'] = $xchan_hash; else return array(); - if(import_author_xchan($x['to'])) - $arr['to_xchan'] = base64url_encode(hash('whirlpool',$x['to']['guid'] . $x['to']['guid_sig'], true)); + if(($xchan_hash = import_author_xchan($x['to'])) !== false) + $arr['to_xchan'] = $xchan_hash; else return array(); - return $arr; } @@ -998,8 +994,8 @@ 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)); + if(($xchan_hash = import_author_xchan($x['from'])) !== false) + $arr['xprof_hash'] = $xchan_hash; else return array(); diff --git a/include/zot.php b/include/zot.php index e365435e9..37373e7ad 100644 --- a/include/zot.php +++ b/include/zot.php @@ -863,8 +863,6 @@ function import_xchan($arr,$ud_flags = 1) { } } - - if($changed) { $guid = random_string() . '@' . get_app()->get_hostname(); update_modtime($xchan_hash,$guid,$arr['address'],$ud_flags); @@ -2103,3 +2101,24 @@ function get_rpost_path($observer) { } +function import_author_zot($x) { + $hash = base64url_encode(hash('whirlpool',$x['guid'] . $x['guid_sig'], true)); + $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and (hubloc_flags & %d) limit 1", + dbesc($x['guid']), + dbesc($x['guid_sig']), + intval(HUBLOC_FLAGS_PRIMARY) + ); + + if($r) { + logger('import_author_zot: in cache', LOGGER_DEBUG); + return $hash; + } + + logger('import_author_zot: entry not in cache - probing: ' . print_r($x,true), LOGGER_DEBUG); + + $them = array('hubloc_url' => $x['url'],'xchan_guid' => $x['guid'], 'xchan_guid_sig' => $x['guid_sig']); + if(zot_refresh($them)) + return $hash; + return false; +} + diff --git a/mod/channel.php b/mod/channel.php index f36636023..2014cd08b 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -1,5 +1,14 @@ profile['profile_uid']) return; @@ -64,16 +71,6 @@ function channel_content(&$a, $update = 0, $load = false) { $category = $datequery = $datequery2 = ''; - // if(argc() > 2) { - // for($x = 2; $x < argc(); $x ++) { - // if(is_a_date_arg(argv($x))) { - // if($datequery) - // $datequery2 = escape_tags(argv($x)); - // else - // $datequery = escape_tags(argv($x)); - // } - // } - // } $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); @@ -81,16 +78,6 @@ function channel_content(&$a, $update = 0, $load = false) { return login(); } - - - require_once("include/bbcode.php"); - require_once('include/security.php'); - require_once('include/conversation.php'); - require_once('include/acl_selectors.php'); - require_once('include/items.php'); - require_once('include/permissions.php'); - - $category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : ''); $groups = array(); diff --git a/mod/post.php b/mod/post.php index e65cb0968..627e13fa0 100644 --- a/mod/post.php +++ b/mod/post.php @@ -196,9 +196,9 @@ function post_init(&$a) { } else { logger('mod_zot: magic-auth failure - not authenticated: ' . $x[0]['xchan_addr']); - q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_addr = '%s'", + q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", intval(HUBLOC_RECEIVE_ERROR), - dbesc($x[0]['xchan_addr']) + intval($x[0]['hubloc_id']) ); } diff --git a/mod/profile.php b/mod/profile.php index cd5c3eeef..a307905e6 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -1,4 +1,12 @@ -name; + $cats .= htmlspecialchars_decode($term->name, ENT_COMPAT); } } diff --git a/version.inc b/version.inc index ccc8f4186..8e4f4a4dc 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2013-12-03.516 +2013-12-04.517 -- cgit v1.2.3