]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into 1501-global-contacts
authorMichael Vogel <icarus@dabo.de>
Sun, 25 Jan 2015 07:44:42 +0000 (08:44 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 25 Jan 2015 07:44:42 +0000 (08:44 +0100)
boot.php
include/dbstructure.php
include/items.php
include/socgraph.php
mod/poco.php
update.php

index 72cb8a3418bcab7141f23773b784c8a4558c4d33..b09da9c17fe2ec992b0559a9e3d2a45bb5a57f60 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Ginger');
 define ( 'FRIENDICA_VERSION',      '3.3.2' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1177      );
+define ( 'DB_UPDATE_VERSION',      1178      );
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
 
index d0a7324e27b6d54dd6cf2f7d7365f1ab88acdd7e..bd4ecb789d0d6b2466cef650584a3e363f653970 100644 (file)
@@ -619,6 +619,8 @@ function db_definition() {
                                        "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                        "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                        "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
+                                       "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
+                                       "about" => array("type" => "text", "not null" => "1"),
                                        "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
                                        ),
                        "indexes" => array(
index 77337fe0d9a9a0eb635cc1aef69aef31a11ed476..9927223514c483447396d2b5a6f02b0ee6a2ce66 100644 (file)
@@ -1350,6 +1350,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                return 0;
        }
 
+       // Store the unescaped version
+       $unescaped = $arr;
+
        dbesc_array($arr);
 
        logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
@@ -1360,10 +1363,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                        . implode("', '", array_values($arr))
                        . "')" );
 
-       // find the item we just created
+       // And restore it
+       $arr = $unescaped;
 
+       // find the item we just created
        $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ",
-               $arr['uri'],           // already dbesc'd
+               dbesc($arr['uri']),
                intval($arr['uid'])
        );
 
@@ -1374,8 +1379,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                // Add every contact to the global contact table
                // Contacts from the statusnet connector are also added since you could add them in OStatus as well.
                if (!$arr['private'] AND in_array($arr["network"],
-                       array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, "")))
-                       poco_check($arr["author-link"], $arr["author-name"], $arr["network"], $arr["author-avatar"], "", $arr["received"], $arr['contact-id'], $arr['uid']);
+                       array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, ""))) {
+                       poco_check($arr["author-link"], $arr["author-name"], $arr["network"], $arr["author-avatar"], "", "", "", $arr["received"], $arr["contact-id"], $arr["uid"]);
+
+                       // Maybe its a body with a shared item? Then extract a global contact from it.
+                       poco_contact_from_body($arr["body"], $arr["received"], $arr["contact-id"], $arr["uid"]);
+               }
 
                // Set "success_update" to the date of the last time we heard from this contact
                // This can be used to filter for inactive contacts and poco.
@@ -1437,7 +1446,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        if(count($r) > 1) {
                logger('item_store: duplicated post occurred. Removing duplicates.');
                q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ",
-                       $arr['uri'],
+                       dbesc($arr['uri']),
                        intval($arr['uid']),
                        intval($current_post)
                );
index 0a8503790175ebec875046c1a2f88812dda07ce4..e50474fd38964c8ed06fd1549cc4d5449ea75ca8 100644 (file)
@@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
        if(! $url)
                return;
 
-       $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network' : '?fields=displayName,urls,photos,updated,network') ;
+       $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation') ;
 
        logger('poco_load: ' . $url, LOGGER_DEBUG);
 
@@ -69,6 +69,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
                $name = '';
                $network = '';
                $updated = '0000-00-00 00:00:00';
+               $location = '';
+               $about = '';
 
                $name = $entry->displayName;
 
@@ -99,7 +101,19 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
                if(isset($entry->network))
                        $network = $entry->network;
 
-               poco_check($profile_url, $name, $network, $profile_photo, $connect_url, $updated, $cid, $uid, $zcid);
+               if(isset($entry->currentLocation))
+                       $location = $entry->currentLocation;
+
+               if(isset($entry->aboutMe))
+                       $about = $entry->aboutMe;
+
+               poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $connect_url, $updated, $cid, $uid, $zcid);
+
+               if (($location != "") OR ($about != ""))
+                       q("UPDATE `contact` SET `location` = '%s', `about` = '%s' WHERE `nurl` = '%s' AND NOT `self`",
+                               dbesc($location),
+                               dbesc($about),
+                               dbesc(normalise_link($profile_url)));
 
        }
        logger("poco_load: loaded $total entries",LOGGER_DEBUG);
@@ -112,10 +126,25 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
 
 }
 
-function poco_check($profile_url, $name, $network, $profile_photo, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) {
+function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) {
        $gcid = "";
 
-       if (($profile_url == "") OR ($name == "") OR ($profile_photo == ""))
+       if ($profile_url == "")
+               return $gcid;
+
+       if (($network == "") OR ($name == "") OR ($profile_photo == "")) {
+               require_once("include/Scrape.php");
+
+               $data = probe_url($profile_url, PROBE_DIASPORA);
+               $network = $data["network"];
+               $name = $data["name"];
+               $profile_photo = $data["photo"];
+       }
+
+       if (!in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_STATUSNET)))
+               return $gcid;
+
+       if (($name == "") OR ($profile_photo == ""))
                return $gcid;
 
        logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
@@ -127,8 +156,14 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
        if(count($x)) {
                $gcid = $x[0]['id'];
 
+               if (($location == "") AND ($x[0]['location'] != ""))
+                       $location = $x[0]['location'];
+
+               if (($about == "") AND ($x[0]['about'] != ""))
+                       $about = $x[0]['about'];
+
                if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
-                       q("update gcontact set `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
+                       q("update gcontact set `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s', `location` = '%s', `about` = '%s'
                                where `nurl` = '%s'",
                                dbesc($name),
                                dbesc($network),
@@ -136,11 +171,13 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
                                dbesc($connect_url),
                                dbesc($profile_url),
                                dbesc($updated),
+                               dbesc($location),
+                               dbesc($about),
                                dbesc(normalise_link($profile_url))
                        );
                }
        } else {
-               q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`)
+               q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`, `location`, `about`)
                        values ('%s', '%s', '%s', '%s', '%s','%s', '%s')",
                        dbesc($name),
                        dbesc($network),
@@ -148,7 +185,9 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
                        dbesc(normalise_link($profile_url)),
                        dbesc($profile_photo),
                        dbesc($connect_url),
-                       dbesc($updated)
+                       dbesc($updated),
+                       dbesc($location),
+                       dbesc($about)
                );
                $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
                        dbesc(normalise_link($profile_url))
@@ -194,6 +233,30 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
        return $gcid;
 }
 
+function poco_contact_from_body($body, $created, $cid, $uid) {
+       preg_replace_callback("/\[share(.*?)\].*?\[\/share\]/ism",
+               function ($match) use ($created, $cid, $uid){
+                       return(sub_poco_from_share($match, $created, $cid, $uid));
+               }, $body);
+}
+
+function sub_poco_from_share($share, $created, $cid, $uid) {
+        $profile = "";
+        preg_match("/profile='(.*?)'/ism", $share[1], $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+        preg_match('/profile="(.*?)"/ism', $share[1], $matches);
+        if ($matches[1] != "")
+                $profile = $matches[1];
+
+       if ($profile == "")
+               return;
+
+       logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG);
+        poco_check($profile, "", "", "", "", "", "", $created, $cid, $uid);
+}
+
 function count_common_friends($uid,$cid) {
 
        $r = q("SELECT count(*) as `total`
index 154f13c7ec202eae6936b36f54fc58fe39d633ca..e7302a9621ced1e61d88a2dffefdb53f5a0cbcb6 100644 (file)
@@ -83,8 +83,9 @@ function poco_init(&$a) {
 
 
        if($system_mode) {
-               $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
-                       AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
+               $r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation` FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
+                       WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
+                       AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
                        dbesc(NETWORK_DFRN),
                        dbesc(NETWORK_DIASPORA),
                        dbesc(NETWORK_OSTATUS),
@@ -143,6 +144,12 @@ function poco_init(&$a) {
        if(is_array($r)) {
                if(count($r)) {
                        foreach($r as $rr) {
+                               if (($rr['about'] == "") AND isset($rr['pabout']))
+                                       $rr['about'] = $rr['pabout'];
+
+                               if (($rr['location'] == "") AND isset($rr['plocation']))
+                                       $rr['location'] = $rr['plocation'];
+
                                $entry = array();
                                if($fields_ret['id'])
                                        $entry['id'] = $rr['id'];
index b4fb64048662efd187888c50033a53fe2a2e2622..019e4cad343a64c947cf25c7ac4bc89f5d3de9b4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1177 );
+define( 'UPDATE_VERSION' , 1178 );
 
 /**
  *