diff options
-rw-r--r-- | addon/poormancron/poormancron.php | 16 | ||||
-rw-r--r-- | boot.php | 36 | ||||
-rw-r--r-- | database.sql | 1 | ||||
-rw-r--r-- | include/Scrape.php | 111 | ||||
-rw-r--r-- | include/diaspora.php | 87 | ||||
-rw-r--r-- | include/network.php | 21 | ||||
-rw-r--r-- | mod/hcard.php | 13 | ||||
-rw-r--r-- | mod/profile.php | 13 | ||||
-rw-r--r-- | update.php | 5 | ||||
-rw-r--r-- | view/profile_vcard.tpl | 3 |
10 files changed, 210 insertions, 96 deletions
diff --git a/addon/poormancron/poormancron.php b/addon/poormancron/poormancron.php index e09182f99..bbe023cd7 100644 --- a/addon/poormancron/poormancron.php +++ b/addon/poormancron/poormancron.php @@ -7,6 +7,21 @@ */ function poormancron_install() { + // check for command line php + $a = get_app(); + $ex = Array(); + $ex[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + $ex[1] = dirname(dirname(dirname(__file__)))."/testargs.php"; + $ex[2] = "test"; + $out = exec(implode(" ", $ex)); + if ($out==="test") { + set_config('poormancron','usecli',1); + logger("poormancron will use cli php"); + } else { + set_config('poormancron','usecli',0); + logger("poormancron will NOT use cli php"); + } + register_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook'); register_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun'); logger("installed poormancron"); @@ -32,6 +47,7 @@ function poormancron_hook(&$a,&$b) { } function poormancron_procrun(&$a, &$arr) { + if (get_config('poormancron','usecli')==1) return; $argv = $arr['args']; $arr['run_cmd'] = false; logger("poormancron procrun ".implode(", ",$argv)); @@ -9,7 +9,7 @@ require_once("include/pgettext.php"); define ( 'FRIENDIKA_VERSION', '2.2.1075' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); -define ( 'DB_UPDATE_VERSION', 1080 ); +define ( 'DB_UPDATE_VERSION', 1081 ); define ( 'EOL', "<br />\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -803,8 +803,12 @@ function profile_load(&$a, $nickname, $profile = 0) { if(! (x($a->page,'aside'))) $a->page['aside'] = ''; - $a->page['aside'] .= profile_sidebar($a->profile); - $a->page['aside'] .= contact_block(); + $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); + + $a->page['aside'] .= profile_sidebar($a->profile, $block); + + if(! $block) + $a->page['aside'] .= contact_block(); return; }} @@ -827,7 +831,7 @@ function profile_load(&$a, $nickname, $profile = 0) { if(! function_exists('profile_sidebar')) { -function profile_sidebar($profile) { +function profile_sidebar($profile, $block = 0) { $a = get_app(); @@ -846,10 +850,9 @@ function profile_sidebar($profile) { $tabs = ''; - $photo = '<div id="profile-photo-wrapper"><img class="photo" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>'; + $photo = '<div id="profile-photo-wrapper"><img class="photo" width="175" height="175" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>'; // don't show connect link to yourself - $connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : ''); // don't show connect link to authenticated visitors either @@ -877,6 +880,7 @@ function profile_sidebar($profile) { } + $gender = ((x($profile,'gender') == 1) ? '<div class="mf"><span class="gender-label">' . t('Gender:') . '</span> <span class="x-gender">' . $profile['gender'] . '</span></div><div class="profile-clear"></div>' : ''); $pubkey = ((x($profile,'pubkey') == 1) ? '<div class="key" style="display:none;">' . $profile['pubkey'] . '</div>' : ''); @@ -885,13 +889,13 @@ function profile_sidebar($profile) { $homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div><div class="profile-clear"></div>' : ''); - if($profile['hidewall'] && (! local_user()) && (! remote_user())) { - $location = $gender = $marital = $homepage = ''; + if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { + $location = $pdesc = $connect = $gender = $marital = $homepage = ''; } $podloc = $a->get_baseurl(); $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ); - $nickname = $profile['nick']; + $nickname = $profile['nickname']; $photo300 = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'; $photo100 = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'; $photo50 = $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'; @@ -902,13 +906,19 @@ function profile_sidebar($profile) { <dl class='entity_nickname'> <dt>Nickname</dt> <dd> -<a class="nickname url uid" href="$podloc" rel="me">$nickname</a> +<a class="nickname url uid" href="$podloc/" rel="me">$nickname</a> +</dd> +</dl> +<dl class='entity_fn'> +<dt>Full name</dt> +<dd> +<span class='fn'>$fullname</span> </dd> </dl> <dl class="entity_url"> <dt>URL</dt> <dd> -<a class="url" href="$podloc" id="pod_location" rel="me">$podloc</a> +<a class="url" href="$podloc/" id="pod_location" rel="me">$podloc/</a> </dd> </dl> <dl class="entity_photo"> @@ -929,10 +939,10 @@ function profile_sidebar($profile) { <img class="photo avatar" height="50px" width="50px" src="$photo50"> </dd> </dl> -<dl class='entity_searchable'> +<dl class="entity_searchable"> <dt>Searchable</dt> <dd> -<span class='searchable'>$searchable</span> +<span class="searchable">$searchable</span> </dd> </dl> </div> diff --git a/database.sql b/database.sql index ae036fc74..605433e6e 100644 --- a/database.sql +++ b/database.sql @@ -531,6 +531,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` ( `network` CHAR( 32 ) NOT NULL , `alias` CHAR( 255 ) NOT NULL , `pubkey` TEXT NOT NULL , +`updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', INDEX ( `addr` ), INDEX ( `network` ) ) ENGINE = MYISAM DEFAULT CHARSET=utf8; diff --git a/include/Scrape.php b/include/Scrape.php index dbd98c9ec..1c9fe7d45 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -44,8 +44,9 @@ function scrape_dfrn($url) { $x = $item->getAttribute('rel'); if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) $ret['feed_atom'] = $item->getAttribute('href'); - if(substr($x,0,5) == "dfrn-") + if(substr($x,0,5) == "dfrn-") { $ret[$x] = $item->getAttribute('href'); + } if($x === 'lrdd') { $decoded = urldecode($item->getAttribute('href')); if(preg_match('/acct:([^@]*)@/',$decoded,$matches)) @@ -55,17 +56,28 @@ function scrape_dfrn($url) { // Pull out hCard profile elements + $largest_photo = 0; + $items = $dom->getElementsByTagName('*'); foreach($items as $item) { if(attribute_contains($item->getAttribute('class'), 'vcard')) { $level2 = $item->getElementsByTagName('*'); foreach($level2 as $x) { - if(attribute_contains($x->getAttribute('class'),'fn')) + if(attribute_contains($x->getAttribute('class'),'fn')) { $ret['fn'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'photo')) - $ret['photo'] = $x->getAttribute('src'); - if(attribute_contains($x->getAttribute('class'),'key')) + } + if((attribute_contains($x->getAttribute('class'),'photo')) + || (attribute_contains($x->getAttribute('class'),'avatar'))) { + $size = intval($x->getAttribute('width')); + // dfrn prefers 175, so if we find this, we set largest_size so it can't be topped. + if(($size > $largest_photo) || ($size == 175) || (! $largest_photo)) { + $ret['photo'] = $x->getAttribute('src'); + $largest_photo = (($size == 175) ? 9999 : $size); + } + } + if(attribute_contains($x->getAttribute('class'),'key')) { $ret['key'] = $x->textContent; + } } } } @@ -190,8 +202,9 @@ function scrape_vcard($url) { } } if((attribute_contains($x->getAttribute('class'),'nickname')) - || (attribute_contains($x->getAttribute('class'),'uid'))) + || (attribute_contains($x->getAttribute('class'),'uid'))) { $ret['nick'] = $x->textContent; + } } } } @@ -289,7 +302,29 @@ function scrape_feed($url) { }} -function probe_url($url) { +/** + * + * Probe a network address to discover what kind of protocols we need to communicate with it. + * + * Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow. + * Edit with care. + * + */ + +/** + * + * PROBE_DIASPORA has a bias towards returning Diaspora information + * while PROBE_NORMAL has a bias towards dfrn/zot - in the case where + * an address (such as a Friendika address) supports more than one type + * of network. + * + */ + + +define ( 'PROBE_NORMAL', 0); +define ( 'PROBE_DIASPORA', 1); + +function probe_url($url, $mode = PROBE_NORMAL) { require_once('include/email.php'); $result = array(); @@ -366,7 +401,7 @@ function probe_url($url) { } } } - else { + elseif($mode == PROBE_NORMAL) { // Check email @@ -411,38 +446,46 @@ 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($mode == PROBE_NORMAL) { + 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')) { - $network = NETWORK_DFRN; - $request = $ret['dfrn-request']; - $confirm = $ret['dfrn-confirm']; - $notify = $ret['dfrn-notify']; - $poll = $ret['dfrn-poll']; + if(strlen($dfrn)) { + $ret = scrape_dfrn($dfrn); + if(is_array($ret) && x($ret,'dfrn-request')) { + $network = NETWORK_DFRN; + $request = $ret['dfrn-request']; + $confirm = $ret['dfrn-confirm']; + $notify = $ret['dfrn-notify']; + $poll = $ret['dfrn-poll']; + + $vcard = array(); + $vcard['fn'] = $ret['fn']; + $vcard['nick'] = $ret['nick']; + $vcard['photo'] = $ret['photo']; + } } } if($diaspora && $diaspora_base && $diaspora_guid) { - $notify = $diaspora_base . 'receive/post/' . $diaspora_guid; + if($mode == PROBE_DIASPORA || ! $notify) + $notify = $diaspora_base . 'receive/post/' . $diaspora_guid; if(strpos($url,'@')) $addr = str_replace('acct:', '', $url); } @@ -454,7 +497,7 @@ function probe_url($url) { $network = NETWORK_OSTATUS; $priority = 0; - if($hcard) { + if($hcard && ! $vcard) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos diff --git a/include/diaspora.php b/include/diaspora.php index e089e3f04..6fe08dcd0 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -4,25 +4,11 @@ require_once('include/crypto.php'); require_once('include/items.php'); function get_diaspora_key($uri) { - $key = ''; - logger('Fetching diaspora key for: ' . $uri); - $arr = lrdd($uri); - - if(is_array($arr)) { - foreach($arr as $a) { - if($a['@attributes']['rel'] === 'diaspora-public-key') { - $key = base64_decode($a['@attributes']['href']); - } - } - } - else { - return ''; - } - - if($key) - return rsatopem($key); + $r = find_diaspora_person_by_handle($uri); + if($r) + return $r['pubkey']; return ''; } @@ -218,7 +204,7 @@ function diaspora_decode($importer,$xml) { $encoding = $base->encoding; $alg = $base->alg; - // Diaspora devs: I can't even begin to tell you how sucky this is. Read the freaking spec. + // Diaspora devs: I can't even begin to tell you how sucky this is. Please read the spec. $signed_data = $data . (($data[-1] != "\n") ? "\n" : '') . '.' . base64url_encode($type) . "\n" . '.' . base64url_encode($encoding) . "\n" . '.' . base64url_encode($alg) . "\n"; @@ -278,21 +264,33 @@ function diaspora_get_contact_by_handle($uid,$handle) { return false; } -function find_person_by_handle($handle) { - // we don't care about the uid, we just want to save an expensive webfinger probe - $r = q("select * from contact where network = '%s' and addr = '%s' LIMIT 1", - dbesc(NETWORK_DIASPORA), - dbesc($handle) - ); - if(count($r)) +function find_diaspora_person_by_handle($handle) { + $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", + dbesc(NETWORK_DIASPORA), + dbesc($handle) + ); + if(count($r)) { + // update record occasionally so it doesn't get stale + $d = strtotime($r[0]['updated'] . ' +00:00'); + if($d < strtotime('now - 14 days')) { + q("delete from fcontact where id = %d limit 1", + intval($r[0]['id']) + ); + } + else return $r[0]; - $r = probe_url($handle); - // need to cached this, perhaps in fcontact - if(count($r)) - return ($r); - return false; + } + require_once('include/Scrape.php'); + $r = probe_url($handle, PROBE_DIASPORA); + if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) { + add_fcontact($r); + return ($r); + } + return false; } + + function diaspora_request($importer,$xml) { $sender_handle = unxmlify($xml->sender_handle); @@ -497,7 +495,7 @@ function diaspora_comment($importer,$xml,$msg) { $key = $msg['key']; } else { - $person = find_person_by_handle($diaspora_handle); + $person = find_diaspora_person_by_handle($diaspora_handle); if(is_array($person) && x($person,'pubkey')) $key = $person['pubkey']; @@ -512,6 +510,7 @@ function diaspora_comment($importer,$xml,$msg) { return; } + if($parent_author_signature) { $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $msg['author']; @@ -578,8 +577,18 @@ function diaspora_comment($importer,$xml,$msg) { $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); $datarray['body'] = $body; - item_store($datarray); + $message_id = item_store($datarray); + if(! $parent_author_signature) { + q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", + intval($message_id), + dbesc($author_signed_data), + dbesc(base64_encode($author_signature)), + dbesc($diaspora_handle) + ); + } + + // notify others return; } @@ -654,7 +663,7 @@ function diaspora_like($importer,$xml,$msg) { $key = $msg['key']; } else { - $person = find_person_by_handle($diaspora_handle); + $person = find_diaspora_person_by_handle($diaspora_handle); if(is_array($person) && x($person,'pubkey')) $key = $person['pubkey']; else { @@ -736,12 +745,20 @@ EOT; $arr['unseen'] = 1; $arr['last-child'] = 0; - $post_id = item_store($arr); + $message_id = item_store($arr); + if(! $parent_author_signature) { + q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", + intval($message_id), + dbesc($author_signed_data), + dbesc(base64_encode($author_signature)), + dbesc($diaspora_handle) + ); + } // FIXME send notification - + return; } function diaspora_retraction($importer,$xml) { diff --git a/include/network.php b/include/network.php index bbf1d6a63..ade8a40ac 100644 --- a/include/network.php +++ b/include/network.php @@ -693,3 +693,24 @@ function parse_xml_string($s,$strict = true) { } return $x; }} + +function add_fcontact($arr) { + + $r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`, + `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey` ) + values('%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['notify']), + dbesc($arr['poll']), + dbesc($arr['confirm']), + dbesc($arr['network']), + dbesc($arr['alias']), + dbesc($arr['pubkey']) + ); + return $r; +} diff --git a/mod/hcard.php b/mod/hcard.php index 5505ca08e..19e649dcb 100644 --- a/mod/hcard.php +++ b/mod/hcard.php @@ -2,8 +2,7 @@ function hcard_init(&$a) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) - return; + $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); if($a->argc > 1) $which = $a->argv[1]; @@ -31,10 +30,12 @@ function hcard_init(&$a) { $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n"; } - $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); - $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); - if(strlen($keywords)) - $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ; + if(! $blocked) { + $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); + $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); + if(strlen($keywords)) + $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ; + } $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ; $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ; diff --git a/mod/profile.php b/mod/profile.php index a4c6ea710..2dd5df758 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -2,8 +2,7 @@ function profile_init(&$a) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) - return; + $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); if($a->argc > 1) $which = $a->argv[1]; @@ -31,10 +30,12 @@ function profile_init(&$a) { $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n"; } - $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); - $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); - if(strlen($keywords)) - $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ; + if(! $blocked) { + $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); + $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); + if(strlen($keywords)) + $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ; + } $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ; $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ; diff --git a/update.php b/update.php index 3586aa5fd..adfb5fe02 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ <?php -define( 'UPDATE_VERSION' , 1080 ); +define( 'UPDATE_VERSION' , 1081 ); /** * @@ -671,3 +671,6 @@ function update_1079() { } +function update_1080() { + q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'"); +}
\ No newline at end of file diff --git a/view/profile_vcard.tpl b/view/profile_vcard.tpl index 86655951d..34f265ee6 100644 --- a/view/profile_vcard.tpl +++ b/view/profile_vcard.tpl @@ -18,11 +18,12 @@ $pubkey +$diaspora + </div> $marital $homepage -$diaspora |