Merge pull request #1318 from annando/1501-global-contacts

Many enhacenments to the global contacts
This commit is contained in:
Tobias Diekershoff 2015-01-27 08:25:30 +01:00
commit cd7d29d13e
9 changed files with 292 additions and 47 deletions

View file

@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Ginger'); define ( 'FRIENDICA_CODENAME', 'Ginger');
define ( 'FRIENDICA_VERSION', '3.3.2' ); define ( 'FRIENDICA_VERSION', '3.3.2' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1177 ); define ( 'DB_UPDATE_VERSION', 1178 );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View file

@ -345,7 +345,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$result = Cache::get("probe_url:".$mode.":".$url); $result = Cache::get("probe_url:".$mode.":".$url);
if (!is_null($result)) { if (!is_null($result)) {
$result = unserialize($result); $result = unserialize($result);
return $result; return $result;
} }
@ -356,6 +356,23 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$diaspora_key = ''; $diaspora_key = '';
$has_lrdd = false; $has_lrdd = false;
$email_conversant = false; $email_conversant = false;
$connectornetworks = false;
$appnet = false;
if (strpos($url,'twitter.com')) {
$connectornetworks = true;
$network = NETWORK_TWITTER;
}
if (strpos($url,'www.facebook.com')) {
$connectornetworks = true;
$network = NETWORK_FACEBOOK;
}
if (strpos($url,'alpha.app.net')) {
$appnet = true;
$network = NETWORK_APPNET;
}
// Twitter is deactivated since twitter closed its old API // Twitter is deactivated since twitter closed its old API
//$twitter = ((strpos($url,'twitter.com') !== false) ? true : false); //$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
@ -363,7 +380,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$at_addr = ((strpos($url,'@') !== false) ? true : false); $at_addr = ((strpos($url,'@') !== false) ? true : false);
if((! $twitter) && (! $lastfm)) { if((!$appnet) && (!$lastfm) && !$connectornetworks) {
if(strpos($url,'mailto:') !== false && $at_addr) { if(strpos($url,'mailto:') !== false && $at_addr) {
$url = str_replace('mailto:','',$url); $url = str_replace('mailto:','',$url);
@ -606,13 +623,16 @@ function probe_url($url, $mode = PROBE_NORMAL) {
// Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links // Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links
} }
if($twitter || ! $poll) if($appnet || ! $poll)
$check_feed = true; $check_feed = true;
if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile)) if((! isset($vcard)) || (! x($vcard,'fn')) || (! $profile))
$check_feed = true; $check_feed = true;
if(($at_addr) && (! count($links))) if(($at_addr) && (! count($links)))
$check_feed = false; $check_feed = false;
if ($connectornetworks)
$check_feed = false;
if($check_feed) { if($check_feed) {
$feedret = scrape_feed(($poll) ? $poll : $url); $feedret = scrape_feed(($poll) ? $poll : $url);

View file

@ -415,6 +415,8 @@ function db_definition() {
"nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"about" => array("type" => "text", "not null" => "1"), "about" => array("type" => "text", "not null" => "1"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => array("type" => "text", "not null" => "1"), "photo" => array("type" => "text", "not null" => "1"),
"thumb" => array("type" => "text", "not null" => "1"), "thumb" => array("type" => "text", "not null" => "1"),
@ -619,6 +621,10 @@ function db_definition() {
"photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"connect" => 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"), "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"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
), ),
"indexes" => array( "indexes" => array(

View file

@ -2252,7 +2252,19 @@ function diaspora_profile($importer,$xml,$msg) {
$birthday = unxmlify($xml->birthday); $birthday = unxmlify($xml->birthday);
$location = diaspora2bb(unxmlify($xml->location)); $location = diaspora2bb(unxmlify($xml->location));
$about = diaspora2bb(unxmlify($xml->bio)); $about = diaspora2bb(unxmlify($xml->bio));
$gender = unxmlify($xml->gender);
$tags = unxmlify($xml->tag_string);
$tags = explode("#", $tags);
$keywords = array();
foreach ($tags as $tag) {
$tag = trim(strtolower($tag));
if ($tag != "")
$keywords[] = $tag;
}
$keywords = implode(", ", $keywords);
$handle_parts = explode("@", $diaspora_handle); $handle_parts = explode("@", $diaspora_handle);
if($name === '') { if($name === '') {
@ -2288,7 +2300,7 @@ function diaspora_profile($importer,$xml,$msg) {
// TODO: update name on item['author-name'] if the name changed. See consume_feed() // TODO: update name on item['author-name'] if the name changed. See consume_feed()
// Not doing this currently because D* protocol is scheduled for revision soon. // Not doing this currently because D* protocol is scheduled for revision soon.
$r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s' WHERE `id` = %d AND `uid` = %d", $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($name), dbesc($name),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($images[0]), dbesc($images[0]),
@ -2298,10 +2310,18 @@ function diaspora_profile($importer,$xml,$msg) {
dbesc($birthday), dbesc($birthday),
dbesc($location), dbesc($location),
dbesc($about), dbesc($about),
dbesc($keywords),
dbesc($gender),
intval($contact['id']), intval($contact['id']),
intval($importer['uid']) intval($importer['uid'])
); );
if (unxmlify($xml->searchable) == "true") {
require_once('include/socgraph.php');
poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "",
datetime_convert(), $contact['id'], $importer['uid']);
}
$profileurl = ""; $profileurl = "";
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($contact['url']))); dbesc(normalise_link($contact['url'])));

View file

@ -1350,6 +1350,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
return 0; return 0;
} }
// Store the unescaped version
$unescaped = $arr;
dbesc_array($arr); dbesc_array($arr);
logger('item_store: ' . print_r($arr,true), LOGGER_DATA); 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)) . 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 ", $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']) 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 // 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. // 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"], if (!$arr['private'] AND in_array($arr["network"],
array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, ""))) 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']); 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 // 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. // 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) { if(count($r) > 1) {
logger('item_store: duplicated post occurred. Removing duplicates.'); logger('item_store: duplicated post occurred. Removing duplicates.');
q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ", q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ",
$arr['uri'], dbesc($arr['uri']),
intval($arr['uid']), intval($arr['uid']),
intval($current_post) intval($current_post)
); );

View file

@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(! $url) if(! $url)
return; 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,tags,gender' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender') ;
logger('poco_load: ' . $url, LOGGER_DEBUG); logger('poco_load: ' . $url, LOGGER_DEBUG);
@ -69,6 +69,10 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
$name = ''; $name = '';
$network = ''; $network = '';
$updated = '0000-00-00 00:00:00'; $updated = '0000-00-00 00:00:00';
$location = '';
$about = '';
$keywords = '';
$gender = '';
$name = $entry->displayName; $name = $entry->displayName;
@ -99,8 +103,31 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(isset($entry->network)) if(isset($entry->network))
$network = $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;
if(isset($entry->gender))
$gender = $entry->gender;
if(isset($entry->tags))
foreach($entry->tags as $tag)
$keywords = implode(", ", $tag);
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $cid, $uid, $zcid);
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender),
dbesc(normalise_link($profile_url)),
dbesc(NETWORK_DFRN));
} }
logger("poco_load: loaded $total entries",LOGGER_DEBUG); logger("poco_load: loaded $total entries",LOGGER_DEBUG);
@ -112,23 +139,60 @@ 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, $gender, $keywords, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) {
$gcid = ""; $gcid = "";
if (($profile_url == "") OR ($name == "") OR ($profile_photo == "")) if ($profile_url == "")
return $gcid; return $gcid;
logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
); );
if(count($x))
$network = $x[0]["network"];
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 (count($x) AND ($x[0]["network"] == "") AND ($network != "")) {
q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'",
dbesc($network),
dbesc(normalise_link($profile_url))
);
}
if (($name == "") OR ($profile_photo == ""))
return $gcid;
if (!in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_STATUSNET)))
return $gcid;
logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
if(count($x)) { if(count($x)) {
$gcid = $x[0]['id']; $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 (($gender == "") AND ($x[0]['gender'] != ""))
$gender = $x[0]['gender'];
if (($keywords == "") AND ($x[0]['keywords'] != ""))
$keywords = $x[0]['keywords'];
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) { 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', `keywords` = '%s', `gender` = '%s'
where `nurl` = '%s'", where `nurl` = '%s'",
dbesc($name), dbesc($name),
dbesc($network), dbesc($network),
@ -136,19 +200,27 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
dbesc($connect_url), dbesc($connect_url),
dbesc($profile_url), dbesc($profile_url),
dbesc($updated), dbesc($updated),
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender),
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
); );
} }
} else { } 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`, `keywords`, `gender`)
values ('%s', '%s', '%s', '%s', '%s','%s', '%s')", values ('%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s')",
dbesc($name), dbesc($name),
dbesc($network), dbesc($network),
dbesc($profile_url), dbesc($profile_url),
dbesc(normalise_link($profile_url)), dbesc(normalise_link($profile_url)),
dbesc($profile_photo), dbesc($profile_photo),
dbesc($connect_url), dbesc($connect_url),
dbesc($updated) dbesc($updated),
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender)
); );
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
@ -194,6 +266,30 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url,
return $gcid; 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) { function count_common_friends($uid,$cid) {
$r = q("SELECT count(*) as `total` $r = q("SELECT count(*) as `total`

View file

@ -22,7 +22,12 @@ function poco_init(&$a) {
$format = (($_GET['format']) ? $_GET['format'] : 'json'); $format = (($_GET['format']) ? $_GET['format'] : 'json');
$justme = false; $justme = false;
$global = false;
if($a->argc > 1 && $a->argv[1] === '@global') {
$global = true;
$update_limit = date("Y-m-d H:i:s", time() - 30 * 86400);
}
if($a->argc > 2 && $a->argv[2] === '@me') if($a->argc > 2 && $a->argv[2] === '@me')
$justme = true; $justme = true;
if($a->argc > 3 && $a->argv[3] === '@all') if($a->argc > 3 && $a->argv[3] === '@all')
@ -33,7 +38,7 @@ function poco_init(&$a) {
$cid = intval($a->argv[4]); $cid = intval($a->argv[4]);
if(! $system_mode) { if(!$system_mode AND !$global) {
$r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1", where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
dbesc($user) dbesc($user)
@ -46,13 +51,21 @@ function poco_init(&$a) {
if($justme) if($justme)
$sql_extra = " AND `contact`.`self` = 1 "; $sql_extra = " AND `contact`.`self` = 1 ";
else // else
$sql_extra = " AND `contact`.`self` = 0 "; // $sql_extra = " AND `contact`.`self` = 0 ";
if($cid) if($cid)
$sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid)); $sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid));
if($system_mode) { if(x($_GET,'updatedSince'))
$update_limit = date("Y-m-d H:i:s",strtotime($_GET['updatedSince']));
if ($global) {
$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `network` IN ('%s')",
dbesc($update_limit),
dbesc(NETWORK_DFRN)
);
} elseif($system_mode) {
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') $r = q("SELECT count(*) AS `total` 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) ", AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
@ -60,8 +73,7 @@ function poco_init(&$a) {
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_STATUSNET) dbesc(NETWORK_STATUSNET)
); );
} } else {
else {
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra", AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra",
intval($user['uid']), intval($user['uid']),
@ -82,9 +94,18 @@ function poco_init(&$a) {
$itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults); $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
if($system_mode) { if ($global) {
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') $r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s') LIMIT %d, %d",
AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", dbesc($update_limit),
dbesc(NETWORK_DFRN),
intval($startIndex),
intval($itemsPerPage)
);
} elseif($system_mode) {
$r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, `profile`.`gender` AS `pgender`
FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') AND `profile`.`is-default`
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_DFRN),
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
@ -92,8 +113,7 @@ function poco_init(&$a) {
intval($startIndex), intval($startIndex),
intval($itemsPerPage) intval($itemsPerPage)
); );
} } else {
else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d", AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
intval($user['uid']), intval($user['uid']),
@ -105,13 +125,14 @@ function poco_init(&$a) {
intval($itemsPerPage) intval($itemsPerPage)
); );
} }
$ret = array(); $ret = array();
if(x($_GET,'sorted')) if(x($_GET,'sorted'))
$ret['sorted'] = 'false'; $ret['sorted'] = false;
if(x($_GET,'filtered')) if(x($_GET,'filtered'))
$ret['filtered'] = 'false'; $ret['filtered'] = false;
if(x($_GET,'updatedSince')) if(x($_GET,'updatedSince') AND !$global)
$ret['updateSince'] = 'false'; $ret['updatedSince'] = false;
$ret['startIndex'] = (string) $startIndex; $ret['startIndex'] = (string) $startIndex;
$ret['itemsPerPage'] = (string) $itemsPerPage; $ret['itemsPerPage'] = (string) $itemsPerPage;
@ -128,7 +149,9 @@ function poco_init(&$a) {
'photos' => false, 'photos' => false,
'aboutMe' => false, 'aboutMe' => false,
'currentLocation' => false, 'currentLocation' => false,
'network' => false 'network' => false,
'gender' => false,
'tags' => false
); );
if((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
@ -143,6 +166,18 @@ function poco_init(&$a) {
if(is_array($r)) { if(is_array($r)) {
if(count($r)) { if(count($r)) {
foreach($r as $rr) { 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'];
if (($rr['gender'] == "") AND isset($rr['pgender']))
$rr['gender'] = $rr['pgender'];
if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
$rr['keywords'] = $rr['pub_keywords'];
$entry = array(); $entry = array();
if($fields_ret['id']) if($fields_ret['id'])
$entry['id'] = $rr['id']; $entry['id'] = $rr['id'];
@ -152,6 +187,8 @@ function poco_init(&$a) {
$entry['aboutMe'] = bbcode($rr['about'], false, false); $entry['aboutMe'] = bbcode($rr['about'], false, false);
if($fields_ret['currentLocation']) if($fields_ret['currentLocation'])
$entry['currentLocation'] = $rr['location']; $entry['currentLocation'] = $rr['location'];
if($fields_ret['gender'])
$entry['gender'] = $rr['gender'];
if($fields_ret['urls']) { if($fields_ret['urls']) {
$entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
@ -160,16 +197,19 @@ function poco_init(&$a) {
if($fields_ret['preferredUsername']) if($fields_ret['preferredUsername'])
$entry['preferredUsername'] = $rr['nick']; $entry['preferredUsername'] = $rr['nick'];
if($fields_ret['updated']) { if($fields_ret['updated']) {
$entry['updated'] = $rr['success_update']; if (!$global) {
$entry['updated'] = $rr['success_update'];
if ($rr['name-date'] > $entry['updated']) if ($rr['name-date'] > $entry['updated'])
$entry['updated'] = $rr['name-date']; $entry['updated'] = $rr['name-date'];
if ($rr['uri-date'] > $entry['updated']) if ($rr['uri-date'] > $entry['updated'])
$entry['updated'] = $rr['uri-date']; $entry['updated'] = $rr['uri-date'];
if ($rr['avatar-date'] > $entry['updated']) if ($rr['avatar-date'] > $entry['updated'])
$entry['updated'] = $rr['avatar-date']; $entry['updated'] = $rr['avatar-date'];
} else
$entry['updated'] = $rr['updated'];
$entry['updated'] = date("c", strtotime($entry['updated'])); $entry['updated'] = date("c", strtotime($entry['updated']));
} }
@ -182,6 +222,20 @@ function poco_init(&$a) {
if (($entry['network'] == "") AND ($rr['self'])) if (($entry['network'] == "") AND ($rr['self']))
$entry['network'] = NETWORK_DFRN; $entry['network'] = NETWORK_DFRN;
} }
if($fields_ret['tags']) {
$tags = str_replace(","," ",$rr['keywords']);
$tags = explode(" ", $tags);
$cleaned = array();
foreach ($tags as $tag) {
$tag = trim(strtolower($tag));
if ($tag != "")
$cleaned[] = $tag;
}
$entry['tags'] = array($cleaned);
}
$ret['entry'][] = $entry; $ret['entry'][] = $entry;
} }
} }

View file

@ -142,6 +142,23 @@ function profiles_init(&$a) {
} }
function profile_clean_keywords($keywords) {
$keywords = str_replace(","," ",$keywords);
$keywords = explode(" ", $keywords);
$cleaned = array();
foreach ($keywords as $keyword) {
$keyword = trim(strtolower($keyword));
$keyword = trim($keyword, "#");
if ($keyword != "")
$cleaned[] = $keyword;
}
$keywords = implode(", ", $cleaned);
return $keywords;
}
function profiles_post(&$a) { function profiles_post(&$a) {
if(! local_user()) { if(! local_user()) {
@ -212,8 +229,8 @@ function profiles_post(&$a) {
$region = notags(trim($_POST['region'])); $region = notags(trim($_POST['region']));
$postal_code = notags(trim($_POST['postal_code'])); $postal_code = notags(trim($_POST['postal_code']));
$country_name = notags(trim($_POST['country_name'])); $country_name = notags(trim($_POST['country_name']));
$pub_keywords = notags(trim($_POST['pub_keywords'])); $pub_keywords = profile_clean_keywords(notags(trim($_POST['pub_keywords'])));
$prv_keywords = notags(trim($_POST['prv_keywords'])); $prv_keywords = profile_clean_keywords(notags(trim($_POST['prv_keywords'])));
$marital = notags(trim($_POST['marital'])); $marital = notags(trim($_POST['marital']));
$howlong = notags(trim($_POST['howlong'])); $howlong = notags(trim($_POST['howlong']));
@ -469,9 +486,11 @@ function profiles_post(&$a) {
if($is_default) { if($is_default) {
$r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s' WHERE `self` = 1 AND `uid` = %d", $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` = 1 AND `uid` = %d",
dbesc($about), dbesc($about),
dbesc($locality), dbesc($locality),
dbesc($pub_keywords),
dbesc($gender),
intval(local_user()) intval(local_user())
); );

View file

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1177 ); define( 'UPDATE_VERSION' , 1178 );
/** /**
* *
@ -1609,3 +1609,24 @@ All following update functions are ONLY for jobs that need to run AFTER the data
Database changes are ONLY applied in the file include/dbstructure.php. Database changes are ONLY applied in the file include/dbstructure.php.
*/ */
function update_1177() {
require_once("mod/profiles.php");
$profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
foreach ($profiles AS $profile) {
if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
continue;
$profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
$r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
dbesc($profile["about"]),
dbesc($profile["locality"]),
dbesc($profile["pub_keywords"]),
dbesc($profile["gender"]),
intval($profile["uid"])
);
}
}