diff options
author | Fabio Comuni <fabrix.xm@gmail.com> | 2011-07-20 10:01:12 +0200 |
---|---|---|
committer | Fabio Comuni <fabrix.xm@gmail.com> | 2011-07-20 10:01:12 +0200 |
commit | 020deefba613327a1d8875ba7f2cf9a750be42dd (patch) | |
tree | f5989c7f45b512c81cc4bec025e7c7137419d516 /include | |
parent | 1c9ed08620578bebc8af16e003a2ecef2b8a1f37 (diff) | |
parent | b27d68633be6219c3f65d830178e3dc96c1c91e9 (diff) | |
download | volse-hubzilla-020deefba613327a1d8875ba7f2cf9a750be42dd.tar.gz volse-hubzilla-020deefba613327a1d8875ba7f2cf9a750be42dd.tar.bz2 volse-hubzilla-020deefba613327a1d8875ba7f2cf9a750be42dd.zip |
Merge remote-tracking branch 'friendika/master' into newacl
Diffstat (limited to 'include')
-rw-r--r-- | include/Scrape.php | 24 | ||||
-rw-r--r-- | include/bbcode.php | 14 | ||||
-rw-r--r-- | include/nav.php | 38 | ||||
-rw-r--r-- | include/zotfns.php | 193 |
4 files changed, 249 insertions, 20 deletions
diff --git a/include/Scrape.php b/include/Scrape.php index fbfec176f..6726d0b15 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -300,6 +300,8 @@ function probe_url($url) { if(count($links)) { logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA); foreach($links as $link) { + if($link['@attributes']['rel'] === NAMESPACE_ZOT) + $zot = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === NAMESPACE_DFRN) $dfrn = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'salmon') @@ -379,6 +381,25 @@ function probe_url($url) { } } + if(strlen($zot)) { + $s = fetch_url($zot); + if($s) { + $j = json_decode($s); + if($j) { + $network = NETWORK_ZOT; + $vcard = array( + 'fn' => $j->fullname, + 'nick' => $j->nickname, + 'photo' => $j->photo + ); + $profile = $j->url; + $notify = $j->post; + $pubkey = $j->pubkey; + $poll = 'N/A'; + } + } + } + if(strlen($dfrn)) { $ret = scrape_dfrn($dfrn); if(is_array($ret) && x($ret,'dfrn-request')) { @@ -390,7 +411,7 @@ function probe_url($url) { } } - if($network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { + if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { $network = NETWORK_OSTATUS; $priority = 0; @@ -549,6 +570,7 @@ function probe_url($url) { $result['priority'] = $priority; $result['network'] = $network; $result['alias'] = $alias; + $result['pubkey'] = $pubkey; logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG); diff --git a/include/bbcode.php b/include/bbcode.php index 7fc1eac1c..3619015ca 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -3,6 +3,13 @@ require_once("include/oembed.php"); require_once('include/event.php'); + + +function stripcode_br_cb($s) { + return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]'; +} + + // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendika - Mike Macgirvin @@ -89,9 +96,16 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("(\[font=(.*?)\](.*?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text); // Declare the format for [code] layout + + $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/is",'stripcode_br_cb',$Text); + $CodeLayout = '<code>$1</code>'; // Check for [code] text $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","$CodeLayout", $Text); + + + + // Declare the format for [quote] layout $QuoteLayout = '<blockquote>$1</blockquote>'; // Check for [quote] text diff --git a/include/nav.php b/include/nav.php index 3b15c2b8a..895c321e6 100644 --- a/include/nav.php +++ b/include/nav.php @@ -30,7 +30,7 @@ function nav(&$a) { $sitelocation = $myident . substr($a->get_baseurl(),strpos($a->get_baseurl(),'//') + 2 ); - // nav links: array of array('href', 'text', 'extra css classes') + // nav links: array of array('href', 'text', 'extra css classes', 'title') $nav = Array(); /** @@ -38,10 +38,10 @@ function nav(&$a) { */ if(local_user()) { - $nav['logout'] = Array('logout',t('Logout'), ""); + $nav['logout'] = Array('logout',t('Logout'), "", t('End this session')); } else { - $nav['login'] = Array('login',t('Login'), ($a->module == 'login'?'nav-selected':'')); + $nav['login'] = Array('login',t('Login'), ($a->module == 'login'?'nav-selected':''), t('Sign in')); } @@ -52,21 +52,21 @@ function nav(&$a) { $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : ''); if(($a->module != 'home') && (! (local_user()))) - $nav['home'] = array($homelink, t('Home'), ""); + $nav['home'] = array($homelink, t('Home'), "", t('Home Page')); if(($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user())) - $nav['register'] = array('register',t('Register'), ""); + $nav['register'] = array('register',t('Register'), "", t('Create an account')); $help_url = $a->get_baseurl() . '/help'; if(! get_config('system','hide_help')) - $nav['help'] = array($help_url, t('Help'), ""); + $nav['help'] = array($help_url, t('Help'), "", t('Help and documentation')); if($a->apps) - $nav['apps'] = array('apps', t('Apps'), ""); + $nav['apps'] = array('apps', t('Apps'), "", t('Addon applications, utilities, games')); - $nav['search'] = array('search', t('Search'), ""); + $nav['search'] = array('search', t('Search'), "", t('Search site content')); $gdirpath = 'directory'; @@ -76,9 +76,9 @@ function nav(&$a) { $gdirpath = $gdir; } elseif(! get_config('system','no_community_page')) - $nav['community'] = array('community', t('Community'), ""); + $nav['community'] = array('community', t('Community'), "", t('Conversations on this site')); - $nav['directory'] = array($gdirpath, t('Directory'), ""); + $nav['directory'] = array($gdirpath, t('Directory'), "", t('People directory')); /** * @@ -88,33 +88,33 @@ function nav(&$a) { if(local_user()) { - $nav['network'] = array('network', t('Network'), ""); + $nav['network'] = array('network', t('Network'), "", t('Conversations from your friends')); - $nav['home'] = array('profile/' . $a->user['nickname'], t('Home'), ""); + $nav['home'] = array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations')); /* only show friend requests for normal pages. Other page types have automatic friendship. */ if($_SESSION['page_flags'] == PAGE_NORMAL) { - $nav['notifications'] = array('notifications', t('Notifications'), ""); + $nav['notifications'] = array('notifications', t('Notifications'), "", t('Friend requests')); } - $nav['messages'] = array('message', t('Messages'), ""); + $nav['messages'] = array('message', t('Messages'), "", t('Private mail')); if(is_array($a->identities) && count($a->identities) > 1) { - $nav['manage'] = array('manage', t('Manage'), ""); + $nav['manage'] = array('manage', t('Manage'), "", t('Manage other pages')); } - $nav['settings'] = array('settings', t('Settings'),""); - $nav['profiles'] = array('profiles', t('Profiles'),""); - $nav['contacts'] = array('contacts', t('Contacts'),""); + $nav['settings'] = array('settings', t('Settings'),"", t('Account settings')); + $nav['profiles'] = array('profiles', t('Profiles'),"", t('Manage/edit profiles')); + $nav['contacts'] = array('contacts', t('Contacts'),"", t('Manage/edit friends and contacts')); } /** * Admin page */ if (is_site_admin()){ - $nav['admin'] = array('admin/', t('Admin'), ""); + $nav['admin'] = array('admin/', t('Admin'), "", t('Site setup and configuration')); } diff --git a/include/zotfns.php b/include/zotfns.php new file mode 100644 index 000000000..b695b6fcb --- /dev/null +++ b/include/zotfns.php @@ -0,0 +1,193 @@ +<?php + + +require_once('include/salmon.php'); + +function zot_get($url,$args) { + $argstr = ''; + foreach($args as $k => $v) { + if($argstr) + $argstr .= '&'; + $argstr .= $k . '=' . $v; + } + $s = fetch_url($url . '?' . $argstr); + if($s) { + $j = json_decode($s); + if($j) + return($j); + } + return false; +} + +function zot_post($url,$args) { + $s = post_url($url,$args); + if($s) { + $j = json_decode($s); + if($j) + return($j); + } + return false; +} + + +function zot_prv_encode($s,$prvkey) { + $x = ''; + $res = openssl_private_encrypt($s,$x,$prvkey); + return base64url_encode($y); +} +function zot_pub_encode($s,$pubkey) { + $x = ''; + $res = openssl_public_encrypt($s,$x,$pubkey); + return base64url_encode($x); +} + +function zot_prv_decode($s,$prvkey) { + $s = base64url_decode($s); + $x = ''; + openssl_private_decrypt($s,$x,$prvkey); + return $x; +} + +function zot_pub_decode($s,$pubkey) { + $s = base64url_decode($s); + $x = ''; + openssl_public_decrypt($s,$x,$pubkey); + return $x; +} + + +function zot_getzid($url,$myaddress,$myprvkey) { + $ret = array(); + $j = zot_get($url,array('sender' => $myaddress)); + if($j->zid_encoded) + $ret['zid'] = zot_prv_decode($j->zid_encoded,$myprvkey); + if($j->zkey_encoded) + $ret['zkey'] = zot_prv_decode($j->zkey_encoded,$myprvkey); + return $ret; +} + +function zot_post_init($url,$zid,$myprvkey,$theirpubkey) { + $ret = array(); + + $zinit = random_string(32); + + $j = zot_get($url,array('zid' => $zid,'zinit' => $zinit)); + + $a = get_app(); + if(! $a->get_curl_code()) + return ZCURL_TIMEOUT; + if(! $j->zinit) { + logger('zot_post_init: no zinit returned.'); + return false; + } + if(zot_pub_decode($j->zinit,$thierpubkey) !== $zinit) { + logger('zot_post_init: incorrect zinit returned.'); + return false; + } + + if($j->challenge) { + $s = zot_prv_decode($j->challenge,$myprvkey); + $s1 = substr($s,0,strpos($s,'.')); + if($s1 != $zid) { + logger("zot_post_init: incorrect zid returned"); + return false; + } + $ret['result'] = substr($s,strpos($s,'.') + 1); + $ret['perms'] = $j->perms; + } + return $ret; +} + + +function zot_encrypt_data($data,&$key) { + $key = random_string(); + return aes_encrypt($data,$key); +} + + +// encrypt the data prior to calling this function so it only need be done once per message +// regardless of the number of recipients. + +function zot_post_data($url,$zid,$myprvkey,$theirpubkey,$encrypted_data,$key, $intro = false) { + $i = zot_post_init($url,$zid,$myprvkey,$theirpubkey); + if($i === ZCURL_TIMEOUT) + return ZCURL_TIMEOUT; + + if((! $i) || (! array_key_exists('perms',$i)) || (! array_key_exists('result',$i))) + return false; + if((! stristr($i['perms'],'post')) && ($intro === false)) { + logger("zot_post_data: no permission to post: url=$url zid=$zid"); + return false; + } + $p = array(); + $p['zid'] = $zid; + $p['result'] = zot_pub_encode($i['result'],$theirpubkey); + $p['aes_key'] = zot_prv_encode($key,$myprvkey); + $p['data'] = $encrypted_data; + $s = zot_post($url,$p); + $a = get_app(); + if(! $a->get_curl_code()) + return ZCURL_TIMEOUT; + + if($s) { + $j = json_decode($s); + return $j; + } + return false; +} + +function zot_deliver($recipients,$myprvkey,$data) { + + if(is_array($recipients) && count($recipients)) { + + $key = ''; + $encrypted = zot_encrypt_data($data,$key); + + + foreach($recipients as $r) { + $result = zot_post_data( + $r['post'], + $r['zid'], + $myprvkey, + $r['pubkey'], + $encrypted, + $key + ); + if($result === false) { + // post failed + logger('zot_deliver: failed: ' . print_r($r,true)); + } + elseif($result === ZCURL_TIMEOUT) { + // queue for redelivery + } + elseif($result->error) { + // failed at other end + logger('zot_deliver: remote failure: ' . $result->error . ' ' . print_r($r,true)); + } + elseif($result->success) { + logger('zot_deliver: success ' . print_r($r,true, LOGGER_DEBUG)); + } + else + logger('zot_deliver: unknown failure.'); + } + } +} + + +function zot_new_contact($user,$cc) { + + $zid = random_string(32); + $zkey = random_string(32); + + logger("zot_new_contact: zid=$zid zkey=$zkey uid={$user['uid']} " . print_r($cc,true)); + + $ret = array(); + $ret['zid_encoded'] = zot_pub_encode($zid,$cc['pubkey']); + $ret['zkey_encoded'] = zot_pub_encode($zkey,$cc['pubkey']); + return $ret; + + + + + +}
\ No newline at end of file |