From d4644d73392f335a3cc488fbd8935068a567edcf Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 31 Oct 2011 20:39:04 -0700 Subject: [PATCH] name change continued, social graph tools and stuctures, fix for spanish province name --- boot.php | 8 +-- database.sql | 21 ++++++++ include/Scrape.php | 3 ++ include/poller.php | 7 +++ include/socgraph.php | 125 +++++++++++++++++++++++++++++++++++++++++++ js/country.js | 2 +- mod/dfrn_request.php | 14 ++--- mod/follow.php | 5 +- mod/poco.php | 4 +- mod/profile.php | 1 + update.php | 27 ++++++++-- 11 files changed, 199 insertions(+), 18 deletions(-) create mode 100644 include/socgraph.php diff --git a/boot.php b/boot.php index f75913162f..3e1706725b 100644 --- a/boot.php +++ b/boot.php @@ -8,10 +8,10 @@ require_once("include/pgettext.php"); require_once('include/nav.php'); require_once('include/cache.php'); -define ( 'FRIENDIKA_PLATFORM', 'Free Friendika'); +define ( 'FRIENDIKA_PLATFORM', 'Friendica'); define ( 'FRIENDIKA_VERSION', '2.3.1151' ); -define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); -define ( 'DB_UPDATE_VERSION', 1099 ); +define ( 'DFRN_PROTOCOL_VERSION', '2.22' ); +define ( 'DB_UPDATE_VERSION', 1100 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -94,7 +94,7 @@ define ( 'PAGE_FREELOVE', 3 ); */ define ( 'NETWORK_ZOT', 'zot!'); // Zot! -define ( 'NETWORK_DFRN', 'dfrn'); // Friendika, Mistpark, other DFRN implementations +define ( 'NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations define ( 'NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol define ( 'NETWORK_DIASPORA', 'dspr'); // Diaspora diff --git a/database.sql b/database.sql index ead3637955..02701b740c 100644 --- a/database.sql +++ b/database.sql @@ -75,6 +75,7 @@ CREATE TABLE IF NOT EXISTS `contact` ( `notify` text NOT NULL, `poll` text NOT NULL, `confirm` text NOT NULL, + `poco` text NOT NULL, `aes_allow` tinyint(1) NOT NULL DEFAULT '0', `ret-aes` tinyint(1) NOT NULL DEFAULT '0', `usehub` tinyint(1) NOT NULL DEFAULT '0', @@ -658,3 +659,23 @@ CREATE TABLE IF NOT EXISTS `fserver` ( INDEX ( `server` ) ) ENGINE = MyISAM DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `gcontact` ( +`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , +`name` CHAR( 255 ) NOT NULL , +`url` CHAR( 255 ) NOT NULL , +`nurl` CHAR( 255 ) NOT NULL , +`photo` CHAR( 255 ) NOT NULL, +INDEX ( `nurl` ), +) ENGINE = MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `glink` ( +`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , +`cid` INT NOT NULL , +`uid` INT NOT NULL , +`gcid` INT NOT NULL, +`updated` DATETIME NOT NULL, +INDEX ( `cid` ), +INDEX ( `uid` ), +INDEX ( `gcid` ), +INDEX ( `updated` ) +) ENGINE = MyISAM DEFAULT CHARSET=utf8; diff --git a/include/Scrape.php b/include/Scrape.php index f5b15c82fb..e42d22afc6 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -369,6 +369,8 @@ function probe_url($url, $mode = PROBE_NORMAL) { $hcard = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') $profile = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') + $poco = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; @@ -684,6 +686,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; + $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network; diff --git a/include/poller.php b/include/poller.php index a19f0716f6..f81e879b42 100644 --- a/include/poller.php +++ b/include/poller.php @@ -298,6 +298,13 @@ function poller_run($argv, $argc){ if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) continue; + if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) { + q("update contact set poco = '%s' where id = %d limit 1", + dbesc(str_replace('/profile/','/poco/', $contact['url'])), + intval($contact['id']) + ); + } + $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); diff --git a/include/socgraph.php b/include/socgraph.php new file mode 100644 index 0000000000..56de83af07 --- /dev/null +++ b/include/socgraph.php @@ -0,0 +1,125 @@ +get_curl_code() > 299) || (! $s)) + return; + $j = json_decode($s); + foreach($j->entry as $entry) { + + $profile_url = ''; + $profile_photo = ''; + $name = ''; + + $name = $entry->displayName; + + foreach($entry->urls as $url) { + if($url->type == 'profile') { + $profile_url = $url->value; + break; + } + } + foreach($entry->photos as $photo) { + if($photo->type == 'profile') { + $profile_photo = $photo->value; + break; + } + } + + if((! $name) || (! $profile_url) || (! $profile_photo)) + continue; + + $x = q("select * from `gcontact` where `nurl` = '%s' limit 1", + dbesc(normalise_link($profile_url)) + ); + if(count($x)) { + $gcid = $x[0]['id']; + + if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) { + q("update gcontact set `name` = '%s', `photo` = '%s' where + `nurl` = '%s' limit 1", + dbesc($name), + dbesc($profile_photo), + dbesc(normalise_link($profile_url)) + ); + } + } + else { + q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`) + values ( '%s', '%s', '%s', '%s') ", + dbesc($name), + dbesc($profile_url), + dbesc(normalise_link($profile_url)), + dbesc($profile_photo) + ); + $x = q("select * from `gcontact` where `nurl` = '%s' limit 1", + dbesc(normalise_link($profile_url)) + ); + if(count($x)) + $gcid = $x[0]['id']; + } + if(! $gcid) + return; + + $r = q("select * from glink where `cid` = %d and `uid` = %d and `gcid` = %d limit 1", + intval($cid), + intval($uid), + intval($gcid) + ); + if(! count($r)) { + q("insert into glink ( `cid`,`uid`,`gcid`,`updated`) values (%d,%d,%d,'%s') ", + intval($cid), + intval($uid), + intval($gcid), + dbesc(datetime_convert()) + ); + } + else { + q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d limit 1", + dbesc(datetime_convert()), + intval($cid), + intval($uid), + intval($gcid) + ); + } + + } + + q("delete from gcid where `cid` = %d and `uid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY", + intval($cid), + intval($uid) + ); + +} \ No newline at end of file diff --git a/js/country.js b/js/country.js index 07ab29ba6a..b18a529d1c 100644 --- a/js/country.js +++ b/js/country.js @@ -233,7 +233,7 @@ aStates[207]="|Bellona|Central|Choiseul (Lauru)|Guadalcanal|Honiara|Isabel|Makir aStates[208]="|Awdal|Bakool|Banaadir|Bari|Bay|Galguduud|Gedo|Hiiraan|Jubbada Dhexe|Jubbada Hoose|Mudug|Nugaal|Sanaag|Shabeellaha Dhexe|Shabeellaha Hoose|Sool|Togdheer|Woqooyi Galbeed"; aStates[209]="|Eastern Cape|Free State|Gauteng|KwaZulu-Natal|Mpumalanga|North-West|Northern Cape|Northern Province|Western Cape"; aStates[210]="|Bird Island|Bristol Island|Clerke Rocks|Montagu Island|Saunders Island|South Georgia|Southern Thule|Traversay Islands"; -aStates[211]="|Andalucia|Aragon|Asturias|Baleares (Balearic Islands)|Canarias (Canary Islands)|Cantabria|Castilla y Leon|Castilla-La Mancha|Cataluna|Ceuta|Communidad Valencian|Extremadura|Galicia|Islas Chafarinas|La Rioja|Madrid|Melilla|Murcia|Navarra|Pais Vasco (Basque Country)|Penon de Alhucemas|Penon de Velez de la Gomera"; +aStates[211]="|Andalucia|Aragon|Asturias|Baleares (Balearic Islands)|Canarias (Canary Islands)|Cantabria|Castilla y Leon|Castilla-La Mancha|Catalunya|Ceuta|Communidad Valencian|Extremadura|Galicia|Islas Chafarinas|La Rioja|Madrid|Melilla|Murcia|Navarra|Pais Vasco (Basque Country)|Penon de Alhucemas|Penon de Velez de la Gomera"; aStates[212]="|Spratly Islands"; aStates[213]="|Central|Eastern|North Central|North Eastern|North Western|Northern|Sabaragamuwa|Southern|Uva|Western"; aStates[214]="|A'ali an Nil|Al Bahr al Ahmar|Al Buhayrat|Al Jazirah|Al Khartum|Al Qadarif|Al Wahdah|An Nil al Abyad|An Nil al Azraq|Ash Shamaliyah|Bahr al Jabal|Gharb al Istiwa'iyah|Gharb Bahr al Ghazal|Gharb Darfur|Gharb Kurdufan|Janub Darfur|Janub Kurdufan|Junqali|Kassala|Nahr an Nil|Shamal Bahr al Ghazal|Shamal Darfur|Shamal Kurdufan|Sharq al Istiwa'iyah|Sinnar|Warab"; diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 5d789f480b..af4a5aece5 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -143,8 +143,8 @@ function dfrn_request_post(&$a) { */ $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `name`, `nick`, `photo`, `site-pubkey`, - `request`, `confirm`, `notify`, `poll`, `network`, `aes_allow`) - VALUES ( %d, '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`) + VALUES ( %d, '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", intval(local_user()), datetime_convert(), dbesc($dfrn_url), @@ -156,6 +156,7 @@ function dfrn_request_post(&$a) { $parms['dfrn-confirm'], $parms['dfrn-notify'], $parms['dfrn-poll'], + $parms['dfrn-poco'], dbesc(NETWORK_DFRN), intval($aes_allow) ); @@ -371,8 +372,8 @@ function dfrn_request_post(&$a) { dbesc_array($parms); $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`, - `request`, `confirm`, `notify`, `poll`, `network` ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", + `request`, `confirm`, `notify`, `poll`, `poco`, `network` ) + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", intval($uid), datetime_convert(), $parms['url'], @@ -385,6 +386,7 @@ function dfrn_request_post(&$a) { $parms['dfrn-confirm'], $parms['dfrn-notify'], $parms['dfrn-poll'], + $parms['dfrn-poco'], dbesc(NETWORK_DFRN) ); @@ -635,14 +637,14 @@ function dfrn_request_content(&$a) { $o .= replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), - '$desc' => t('Examples: jojo@demo.friendika.com, http://demo.friendika.com/profile/jojo, testuser@identi.ca'), + '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), '$pls_answer' => t('Please answer the following:'), '$does_know' => sprintf( t('Does %s know you?'),$a->profile['name']), '$yes' => t('Yes'), '$no' => t('No'), '$add_note' => t('Add a personal note:'), '$page_desc' => $page_desc, - '$friendika' => t('Friendika'), + '$friendika' => t('Friendica'), '$statusnet' => t('StatusNet/Federated Social Web'), '$diaspora' => t('Diaspora'), '$diasnote' => t('- please share from your own site as noted above'), diff --git a/mod/follow.php b/mod/follow.php index 77c8ae18f3..4328e7fe04 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -100,9 +100,9 @@ function follow_post(&$a) { $new_relation = CONTACT_IS_FOLLOWER; // create contact record - $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `batch`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, + $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, `writable`, `blocked`, `readonly`, `pending` ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", intval(local_user()), dbesc(datetime_convert()), dbesc($ret['url']), @@ -111,6 +111,7 @@ function follow_post(&$a) { dbesc($ret['batch']), dbesc($ret['notify']), dbesc($ret['poll']), + dbesc($ret['poco']), dbesc($ret['name']), dbesc($ret['nick']), dbesc($ret['photo']), diff --git a/mod/poco.php b/mod/poco.php index 2c2aeb656c..21ee4df695 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -98,11 +98,11 @@ function poco_init(&$a) { if($fields_ret['displayName']) $entry['displayName'] = $rr['name']; if($fields_ret['urls']) - $entry['urls'] = array('value' => $rr['url'], 'type' => 'profile'); + $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); if($fields_ret['preferredUsername']) $entry['preferredUsername'] = $rr['nick']; if($fields_ret['photos']) - $entry['photos'] = array('value' => $rr['photo'], 'type' => 'profile'); + $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); $ret['entry'][] = $entry; } } diff --git a/mod/profile.php b/mod/profile.php index 6d67ab74b2..f68006af54 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -46,6 +46,7 @@ function profile_init(&$a) { $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); foreach($dfrn_pages as $dfrn) $a->page['htmlhead'] .= "get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n"; + $a->page['htmlhead'] .= "get_baseurl()."/poco/{$which}\" />\r\n"; } diff --git a/update.php b/update.php index 8f1cee75b4..1ddae33d40 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@