]> git.mxchange.org Git - friendica.git/commitdiff
name change continued, social graph tools and stuctures, fix for spanish province...
authorFriendika <info@friendika.com>
Tue, 1 Nov 2011 03:39:04 +0000 (20:39 -0700)
committerFriendika <info@friendika.com>
Tue, 1 Nov 2011 03:39:04 +0000 (20:39 -0700)
boot.php
database.sql
include/Scrape.php
include/poller.php
include/socgraph.php [new file with mode: 0644]
js/country.js
mod/dfrn_request.php
mod/follow.php
mod/poco.php
mod/profile.php
update.php

index f75913162f5931104e5fd64f7020068c5d998f45..3e1706725b98c67c43bc06d2dce21b5212c7d037 100644 (file)
--- 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',                    "<br />\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
index ead3637955434099e5f2247649f03c46325cde09..02701b740c79572203dd4ee7726c2b7e473fc0bb 100644 (file)
@@ -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;
index f5b15c82fbeb7eafef5c0dc58a2e1502f59db89e..e42d22afc64c9e0a792a90bc8abcd0a6c7a8930d 100644 (file)
@@ -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;
index a19f0716f6758e7c23e0506c51cb49c06b02cc50..f81e879b424f4653a20cf376f434e74180f96240 100644 (file)
@@ -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 (file)
index 0000000..56de83a
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+
+
+
+/*
+ * poco_load
+ *
+ * Given a contact-id (minimum), load the PortableContacts friend list for that contact,
+ * and add the entries to the gcontact (Global Contact) table, or update existing entries
+ * if anything (name or photo) has changed.
+ * We use normalised urls for comparison which ignore http vs https and www.domain vs domain
+ *
+ * Once the global contact is stored add (if necessary) the contact linkage which associates
+ * the given uid, cid to the global contact entry. There can be many uid/cid combinations
+ * pointing to the same global contact id. 
+ *
+ */
+
+
+
+function poco_load($cid,$uid = 0,$url = null) {
+       $a = get_app();
+       if((! $url) || (! $uid)) {
+               $r = q("select `poco`, `uid` from `contact` where `id` = %d limit 1",
+                       intval($cid)
+               );
+               if(count($r)) {
+                       $url = $r[0]['poco'];
+                       $uid = $r[0]['uid'];
+               }
+       }
+       if((! $url) || (! $uid))
+               return;
+       $s = fetch_url($url . '/@me/@all?fields=displayName,urls,photos');
+
+       if(($a->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
index 07ab29ba6acb01e5f462a9bc096e9061a8d64a47..b18a529d1c78eaf532aec4e3dba7db6c73daa429 100644 (file)
@@ -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";\r
 aStates[209]="|Eastern Cape|Free State|Gauteng|KwaZulu-Natal|Mpumalanga|North-West|Northern Cape|Northern Province|Western Cape";\r
 aStates[210]="|Bird Island|Bristol Island|Clerke Rocks|Montagu Island|Saunders Island|South Georgia|Southern Thule|Traversay Islands";\r
-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";\r
+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";\r
 aStates[212]="|Spratly Islands";\r
 aStates[213]="|Central|Eastern|North Central|North Eastern|North Western|Northern|Sabaragamuwa|Southern|Uva|Western";\r
 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";\r
index 5d789f480bb31cd34ddf3472004351eb1faf2321..af4a5aece50fb013eedc18dbdd1684e0567eb3ac 100644 (file)
@@ -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'),
index 77c8ae18f3e796cf1c30dcd0c227e1990c789c40..4328e7fe043a3aaeb3f92cedd09f6d62402f7d5b 100644 (file)
@@ -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']),
index 2c2aeb656ccfd1d82c1a6632d35e9d1f4cd331ca..21ee4df695906291e2e3cad07c1e0b8f101dbff1 100644 (file)
@@ -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;
                        }
                }
index 6d67ab74b2e651e5d1b68945e90e6a3434dfc54d..f68006af54620bfd1bc4b5ca28abc31e9a95f98f 100644 (file)
@@ -46,6 +46,7 @@ function profile_init(&$a) {
        $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
        foreach($dfrn_pages as $dfrn)
                $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
+       $a->page['htmlhead'] .= "<link rel=\"dfrn-poco\" href=\"".$a->get_baseurl()."/poco/{$which}\" />\r\n";
 
 }
 
index 8f1cee75b4c65fffefd23123d49c89b5fb6126ed..1ddae33d405e44ab715aa4c7ecc72cabb42fd214 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1099 );
+define( 'UPDATE_VERSION' , 1100 );
 
 /**
  *
@@ -822,8 +822,29 @@ function update_1098() {
        ");
 }
 
+function update_1099() {
+       q("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
+       ) ENGINE = MYISAM ");
+
+       q("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,
+       ) ENGINE = MYISAM ");
+
+       q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) ");
+       q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) ");
 
+       q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` "); 
 
+}