From 75e2ec01fe867f535e2beba0daa30119e1f722b1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 5 Jan 2016 15:34:27 +0100 Subject: [PATCH 01/17] The gcontact will now be connected to the items --- boot.php | 2 +- database.sql | 197 +++++++++++++++++++++++++--------------- include/dbstructure.php | 3 + include/diaspora.php | 8 ++ include/items.php | 3 + include/ostatus.php | 51 ++++++----- include/socgraph.php | 130 +++++++++++++++++++++----- include/threads.php | 2 +- mod/item.php | 2 + mod/network.php | 14 +-- update.php | 2 +- 11 files changed, 285 insertions(+), 129 deletions(-) diff --git a/boot.php b/boot.php index 497a97b0e..7d8c7040d 100644 --- a/boot.php +++ b/boot.php @@ -36,7 +36,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1191 ); +define ( 'DB_UPDATE_VERSION', 1192 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index e3768c1ef..1277585c9 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ --- Friendica 3.4.2 (Lily of the valley) --- DB_UPDATE_VERSION 1190 +-- Friendica 3.5-dev (Asparagus) +-- DB_UPDATE_VERSION 1192 -- ------------------------------------------ @@ -8,20 +8,21 @@ -- TABLE addon -- CREATE TABLE IF NOT EXISTS `addon` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL DEFAULT '', `version` varchar(255) NOT NULL DEFAULT '', `installed` tinyint(1) NOT NULL DEFAULT 0, `hidden` tinyint(1) NOT NULL DEFAULT 0, `timestamp` bigint(20) NOT NULL DEFAULT 0, - `plugin_admin` tinyint(1) NOT NULL DEFAULT 0 + `plugin_admin` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE attach -- CREATE TABLE IF NOT EXISTS `attach` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `hash` varchar(64) NOT NULL DEFAULT '', `filename` varchar(255) NOT NULL DEFAULT '', @@ -33,28 +34,31 @@ CREATE TABLE IF NOT EXISTS `attach` ( `allow_cid` mediumtext NOT NULL, `allow_gid` mediumtext NOT NULL, `deny_cid` mediumtext NOT NULL, - `deny_gid` mediumtext NOT NULL + `deny_gid` mediumtext NOT NULL, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE auth_codes -- CREATE TABLE IF NOT EXISTS `auth_codes` ( - `id` varchar(40) NOT NULL PRIMARY KEY, + `id` varchar(40) NOT NULL, `client_id` varchar(20) NOT NULL DEFAULT '', `redirect_uri` varchar(200) NOT NULL DEFAULT '', `expires` int(11) NOT NULL DEFAULT 0, - `scope` varchar(250) NOT NULL DEFAULT '' + `scope` varchar(250) NOT NULL DEFAULT '', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE cache -- CREATE TABLE IF NOT EXISTS `cache` ( - `k` varchar(255) NOT NULL PRIMARY KEY, + `k` varchar(255) NOT NULL, `v` text NOT NULL, `expire_mode` int(11) NOT NULL DEFAULT 0, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`k`), INDEX `updated` (`updated`) ) DEFAULT CHARSET=utf8; @@ -62,34 +66,37 @@ CREATE TABLE IF NOT EXISTS `cache` ( -- TABLE challenge -- CREATE TABLE IF NOT EXISTS `challenge` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `challenge` varchar(255) NOT NULL DEFAULT '', `dfrn-id` varchar(255) NOT NULL DEFAULT '', `expire` int(11) NOT NULL DEFAULT 0, `type` varchar(255) NOT NULL DEFAULT '', - `last_update` varchar(255) NOT NULL DEFAULT '' + `last_update` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE clients -- CREATE TABLE IF NOT EXISTS `clients` ( - `client_id` varchar(20) NOT NULL PRIMARY KEY, + `client_id` varchar(20) NOT NULL, `pw` varchar(20) NOT NULL DEFAULT '', `redirect_uri` varchar(200) NOT NULL DEFAULT '', `name` text, `icon` text, - `uid` int(11) NOT NULL DEFAULT 0 + `uid` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`client_id`) ) DEFAULT CHARSET=utf8; -- -- TABLE config -- CREATE TABLE IF NOT EXISTS `config` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `cat` varchar(255) NOT NULL DEFAULT '', `k` varchar(255) NOT NULL DEFAULT '', `v` text NOT NULL, + PRIMARY KEY(`id`), INDEX `cat_k` (`cat`(30),`k`(30)) ) DEFAULT CHARSET=utf8; @@ -97,7 +104,7 @@ CREATE TABLE IF NOT EXISTS `config` ( -- TABLE contact -- CREATE TABLE IF NOT EXISTS `contact` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `self` tinyint(1) NOT NULL DEFAULT 0, @@ -162,6 +169,7 @@ CREATE TABLE IF NOT EXISTS `contact` ( `notify_new_posts` tinyint(1) NOT NULL DEFAULT 0, `fetch_further_information` tinyint(1) NOT NULL DEFAULT 0, `ffi_keyword_blacklist` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -169,7 +177,7 @@ CREATE TABLE IF NOT EXISTS `contact` ( -- TABLE conv -- CREATE TABLE IF NOT EXISTS `conv` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `guid` varchar(64) NOT NULL DEFAULT '', `recips` mediumtext NOT NULL, `uid` int(11) NOT NULL DEFAULT 0, @@ -177,6 +185,7 @@ CREATE TABLE IF NOT EXISTS `conv` ( `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `subject` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -184,27 +193,29 @@ CREATE TABLE IF NOT EXISTS `conv` ( -- TABLE deliverq -- CREATE TABLE IF NOT EXISTS `deliverq` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `cmd` varchar(32) NOT NULL DEFAULT '', `item` int(11) NOT NULL DEFAULT 0, - `contact` int(11) NOT NULL DEFAULT 0 + `contact` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE dsprphotoq -- CREATE TABLE IF NOT EXISTS `dsprphotoq` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `msg` mediumtext NOT NULL, - `attempt` tinyint(4) NOT NULL DEFAULT 0 + `attempt` tinyint(4) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE event -- CREATE TABLE IF NOT EXISTS `event` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `cid` int(11) NOT NULL DEFAULT 0, `uri` varchar(255) NOT NULL DEFAULT '', @@ -223,6 +234,7 @@ CREATE TABLE IF NOT EXISTS `event` ( `allow_gid` mediumtext NOT NULL, `deny_cid` mediumtext NOT NULL, `deny_gid` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -230,7 +242,7 @@ CREATE TABLE IF NOT EXISTS `event` ( -- TABLE fcontact -- CREATE TABLE IF NOT EXISTS `fcontact` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `url` varchar(255) NOT NULL DEFAULT '', `name` varchar(255) NOT NULL DEFAULT '', `photo` varchar(255) NOT NULL DEFAULT '', @@ -246,6 +258,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` ( `alias` varchar(255) NOT NULL DEFAULT '', `pubkey` text NOT NULL, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `addr` (`addr`) ) DEFAULT CHARSET=utf8; @@ -253,20 +266,22 @@ CREATE TABLE IF NOT EXISTS `fcontact` ( -- TABLE ffinder -- CREATE TABLE IF NOT EXISTS `ffinder` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `cid` int(10) unsigned NOT NULL DEFAULT 0, - `fid` int(10) unsigned NOT NULL DEFAULT 0 + `fid` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE fserver -- CREATE TABLE IF NOT EXISTS `fserver` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `server` varchar(255) NOT NULL DEFAULT '', `posturl` varchar(255) NOT NULL DEFAULT '', `key` text NOT NULL, + PRIMARY KEY(`id`), INDEX `server` (`server`) ) DEFAULT CHARSET=utf8; @@ -274,7 +289,7 @@ CREATE TABLE IF NOT EXISTS `fserver` ( -- TABLE fsuggest -- CREATE TABLE IF NOT EXISTS `fsuggest` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `cid` int(11) NOT NULL DEFAULT 0, `name` varchar(255) NOT NULL DEFAULT '', @@ -282,16 +297,18 @@ CREATE TABLE IF NOT EXISTS `fsuggest` ( `request` varchar(255) NOT NULL DEFAULT '', `photo` varchar(255) NOT NULL DEFAULT '', `note` text NOT NULL, - `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE gcign -- CREATE TABLE IF NOT EXISTS `gcign` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `gcid` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `gcid` (`gcid`) ) DEFAULT CHARSET=utf8; @@ -300,7 +317,7 @@ CREATE TABLE IF NOT EXISTS `gcign` ( -- TABLE gcontact -- CREATE TABLE IF NOT EXISTS `gcontact` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) NOT NULL DEFAULT '', `nick` varchar(255) NOT NULL DEFAULT '', `url` varchar(255) NOT NULL DEFAULT '', @@ -320,6 +337,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( `addr` varchar(255) NOT NULL DEFAULT '', `generation` tinyint(3) NOT NULL DEFAULT 0, `server_url` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `nurl` (`nurl`), INDEX `updated` (`updated`) ) DEFAULT CHARSET=utf8; @@ -328,12 +346,13 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( -- TABLE glink -- CREATE TABLE IF NOT EXISTS `glink` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `cid` int(11) NOT NULL DEFAULT 0, `uid` int(11) NOT NULL DEFAULT 0, `gcid` int(11) NOT NULL DEFAULT 0, `zcid` int(11) NOT NULL DEFAULT 0, `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`), INDEX `gcid` (`gcid`), INDEX `zcid` (`zcid`) @@ -343,11 +362,12 @@ CREATE TABLE IF NOT EXISTS `glink` ( -- TABLE group -- CREATE TABLE IF NOT EXISTS `group` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `visible` tinyint(1) NOT NULL DEFAULT 0, `deleted` tinyint(1) NOT NULL DEFAULT 0, `name` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -355,10 +375,11 @@ CREATE TABLE IF NOT EXISTS `group` ( -- TABLE group_member -- CREATE TABLE IF NOT EXISTS `group_member` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `gid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`) ) DEFAULT CHARSET=utf8; @@ -366,7 +387,7 @@ CREATE TABLE IF NOT EXISTS `group_member` ( -- TABLE gserver -- CREATE TABLE IF NOT EXISTS `gserver` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `url` varchar(255) NOT NULL DEFAULT '', `nurl` varchar(255) NOT NULL DEFAULT '', `version` varchar(255) NOT NULL DEFAULT '', @@ -381,6 +402,7 @@ CREATE TABLE IF NOT EXISTS `gserver` ( `last_poco_query` datetime DEFAULT '0000-00-00 00:00:00', `last_contact` datetime DEFAULT '0000-00-00 00:00:00', `last_failure` datetime DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `nurl` (`nurl`) ) DEFAULT CHARSET=utf8; @@ -388,11 +410,12 @@ CREATE TABLE IF NOT EXISTS `gserver` ( -- TABLE guid -- CREATE TABLE IF NOT EXISTS `guid` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `guid` varchar(255) NOT NULL DEFAULT '', `plink` varchar(255) NOT NULL DEFAULT '', `uri` varchar(255) NOT NULL DEFAULT '', `network` varchar(32) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `guid` (`guid`), INDEX `plink` (`plink`), INDEX `uri` (`uri`) @@ -402,11 +425,12 @@ CREATE TABLE IF NOT EXISTS `guid` ( -- TABLE hook -- CREATE TABLE IF NOT EXISTS `hook` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `hook` varchar(255) NOT NULL DEFAULT '', `file` varchar(255) NOT NULL DEFAULT '', `function` varchar(255) NOT NULL DEFAULT '', `priority` int(11) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `hook_file_function` (`hook`(30),`file`(60),`function`(30)) ) DEFAULT CHARSET=utf8; @@ -414,7 +438,7 @@ CREATE TABLE IF NOT EXISTS `hook` ( -- TABLE intro -- CREATE TABLE IF NOT EXISTS `intro` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `fid` int(11) NOT NULL DEFAULT 0, `contact-id` int(11) NOT NULL DEFAULT 0, @@ -424,18 +448,20 @@ CREATE TABLE IF NOT EXISTS `intro` ( `hash` varchar(255) NOT NULL DEFAULT '', `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `blocked` tinyint(1) NOT NULL DEFAULT 1, - `ignore` tinyint(1) NOT NULL DEFAULT 0 + `ignore` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE item -- CREATE TABLE IF NOT EXISTS `item` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `guid` varchar(255) NOT NULL DEFAULT '', `uri` varchar(255) NOT NULL DEFAULT '', `uid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(11) NOT NULL DEFAULT 0, + `gcontact-id` int(11) unsigned NOT NULL DEFAULT 0, `type` varchar(255) NOT NULL DEFAULT '', `wall` tinyint(1) NOT NULL DEFAULT 0, `gravity` tinyint(1) NOT NULL DEFAULT 0, @@ -493,6 +519,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `rendered-hash` varchar(32) NOT NULL DEFAULT '', `rendered-html` mediumtext NOT NULL, `global` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `guid` (`guid`), INDEX `uri` (`uri`), INDEX `parent` (`parent`), @@ -531,11 +558,12 @@ CREATE TABLE IF NOT EXISTS `item` ( -- TABLE item_id -- CREATE TABLE IF NOT EXISTS `item_id` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `iid` int(11) NOT NULL DEFAULT 0, `uid` int(11) NOT NULL DEFAULT 0, `sid` varchar(255) NOT NULL DEFAULT '', `service` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `sid` (`sid`), INDEX `service` (`service`), @@ -546,17 +574,18 @@ CREATE TABLE IF NOT EXISTS `item_id` ( -- TABLE locks -- CREATE TABLE IF NOT EXISTS `locks` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `name` varchar(128) NOT NULL DEFAULT '', `locked` tinyint(1) NOT NULL DEFAULT 0, - `created` datetime DEFAULT '0000-00-00 00:00:00' + `created` datetime DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE mail -- CREATE TABLE IF NOT EXISTS `mail` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `guid` varchar(64) NOT NULL DEFAULT '', `from-name` varchar(255) NOT NULL DEFAULT '', @@ -573,6 +602,7 @@ CREATE TABLE IF NOT EXISTS `mail` ( `uri` varchar(255) NOT NULL DEFAULT '', `parent-uri` varchar(255) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `guid` (`guid`), INDEX `convid` (`convid`), @@ -585,7 +615,7 @@ CREATE TABLE IF NOT EXISTS `mail` ( -- TABLE mailacct -- CREATE TABLE IF NOT EXISTS `mailacct` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `server` varchar(255) NOT NULL DEFAULT '', `port` int(11) NOT NULL DEFAULT 0, @@ -597,16 +627,18 @@ CREATE TABLE IF NOT EXISTS `mailacct` ( `action` int(11) NOT NULL DEFAULT 0, `movetofolder` varchar(255) NOT NULL DEFAULT '', `pubmail` tinyint(1) NOT NULL DEFAULT 0, - `last_check` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + `last_check` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE manage -- CREATE TABLE IF NOT EXISTS `manage` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `mid` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `uid_mid` (`uid`,`mid`) ) DEFAULT CHARSET=utf8; @@ -614,7 +646,7 @@ CREATE TABLE IF NOT EXISTS `manage` ( -- TABLE notify -- CREATE TABLE IF NOT EXISTS `notify` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `hash` varchar(64) NOT NULL DEFAULT '', `type` int(11) NOT NULL DEFAULT 0, `name` varchar(255) NOT NULL DEFAULT '', @@ -629,6 +661,7 @@ CREATE TABLE IF NOT EXISTS `notify` ( `seen` tinyint(1) NOT NULL DEFAULT 0, `verb` varchar(255) NOT NULL DEFAULT '', `otype` varchar(16) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -636,11 +669,12 @@ CREATE TABLE IF NOT EXISTS `notify` ( -- TABLE notify-threads -- CREATE TABLE IF NOT EXISTS `notify-threads` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `notify-id` int(11) NOT NULL DEFAULT 0, `master-parent-item` int(10) unsigned NOT NULL DEFAULT 0, `parent-item` int(10) unsigned NOT NULL DEFAULT 0, `receiver-uid` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `master-parent-item` (`master-parent-item`), INDEX `receiver-uid` (`receiver-uid`) ) DEFAULT CHARSET=utf8; @@ -649,11 +683,12 @@ CREATE TABLE IF NOT EXISTS `notify-threads` ( -- TABLE pconfig -- CREATE TABLE IF NOT EXISTS `pconfig` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `cat` varchar(255) NOT NULL DEFAULT '', `k` varchar(255) NOT NULL DEFAULT '', `v` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid_cat_k` (`uid`,`cat`(30),`k`(30)) ) DEFAULT CHARSET=utf8; @@ -661,7 +696,7 @@ CREATE TABLE IF NOT EXISTS `pconfig` ( -- TABLE photo -- CREATE TABLE IF NOT EXISTS `photo` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(10) unsigned NOT NULL DEFAULT 0, `guid` varchar(64) NOT NULL DEFAULT '', @@ -683,6 +718,7 @@ CREATE TABLE IF NOT EXISTS `photo` ( `allow_gid` mediumtext NOT NULL, `deny_cid` mediumtext NOT NULL, `deny_gid` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `resource-id` (`resource-id`), INDEX `guid` (`guid`) @@ -692,7 +728,7 @@ CREATE TABLE IF NOT EXISTS `photo` ( -- TABLE poll -- CREATE TABLE IF NOT EXISTS `poll` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `q0` mediumtext NOT NULL, `q1` mediumtext NOT NULL, @@ -704,6 +740,7 @@ CREATE TABLE IF NOT EXISTS `poll` ( `q7` mediumtext NOT NULL, `q8` mediumtext NOT NULL, `q9` mediumtext NOT NULL, + PRIMARY KEY(`id`), INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8; @@ -711,9 +748,10 @@ CREATE TABLE IF NOT EXISTS `poll` ( -- TABLE poll_result -- CREATE TABLE IF NOT EXISTS `poll_result` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `poll_id` int(11) NOT NULL DEFAULT 0, `choice` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `poll_id` (`poll_id`), INDEX `choice` (`choice`) ) DEFAULT CHARSET=utf8; @@ -722,7 +760,7 @@ CREATE TABLE IF NOT EXISTS `poll_result` ( -- TABLE profile -- CREATE TABLE IF NOT EXISTS `profile` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `profile-name` varchar(255) NOT NULL DEFAULT '', `is-default` tinyint(1) NOT NULL DEFAULT 0, @@ -763,6 +801,7 @@ CREATE TABLE IF NOT EXISTS `profile` ( `thumb` varchar(255) NOT NULL DEFAULT '', `publish` tinyint(1) NOT NULL DEFAULT 0, `net-publish` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `hometown` (`hometown`) ) DEFAULT CHARSET=utf8; @@ -770,39 +809,42 @@ CREATE TABLE IF NOT EXISTS `profile` ( -- TABLE profile_check -- CREATE TABLE IF NOT EXISTS `profile_check` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `uid` int(10) unsigned NOT NULL DEFAULT 0, `cid` int(10) unsigned NOT NULL DEFAULT 0, `dfrn_id` varchar(255) NOT NULL DEFAULT '', `sec` varchar(255) NOT NULL DEFAULT '', - `expire` int(11) NOT NULL DEFAULT 0 + `expire` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE push_subscriber -- CREATE TABLE IF NOT EXISTS `push_subscriber` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `callback_url` varchar(255) NOT NULL DEFAULT '', `topic` varchar(255) NOT NULL DEFAULT '', `nickname` varchar(255) NOT NULL DEFAULT '', `push` int(11) NOT NULL DEFAULT 0, `last_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `secret` varchar(255) NOT NULL DEFAULT '' + `secret` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE queue -- CREATE TABLE IF NOT EXISTS `queue` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `cid` int(11) NOT NULL DEFAULT 0, `network` varchar(32) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `last` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `content` mediumtext NOT NULL, `batch` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `cid` (`cid`), INDEX `created` (`created`), INDEX `last` (`last`), @@ -814,21 +856,23 @@ CREATE TABLE IF NOT EXISTS `queue` ( -- TABLE register -- CREATE TABLE IF NOT EXISTS `register` ( - `id` int(11) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(11) unsigned NOT NULL auto_increment, `hash` varchar(255) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `uid` int(11) unsigned NOT NULL DEFAULT 0, `password` varchar(255) NOT NULL DEFAULT '', - `language` varchar(16) NOT NULL DEFAULT '' + `language` varchar(16) NOT NULL DEFAULT '', + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE search -- CREATE TABLE IF NOT EXISTS `search` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `term` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `term` (`term`) ) DEFAULT CHARSET=utf8; @@ -837,10 +881,11 @@ CREATE TABLE IF NOT EXISTS `search` ( -- TABLE session -- CREATE TABLE IF NOT EXISTS `session` ( - `id` bigint(20) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` bigint(20) unsigned NOT NULL auto_increment, `sid` varchar(255) NOT NULL DEFAULT '', `data` text NOT NULL, `expire` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`id`), INDEX `sid` (`sid`), INDEX `expire` (`expire`) ) DEFAULT CHARSET=utf8; @@ -849,12 +894,13 @@ CREATE TABLE IF NOT EXISTS `session` ( -- TABLE sign -- CREATE TABLE IF NOT EXISTS `sign` ( - `id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `id` int(10) unsigned NOT NULL auto_increment, `iid` int(10) unsigned NOT NULL DEFAULT 0, `retract_iid` int(10) unsigned NOT NULL DEFAULT 0, `signed_text` mediumtext NOT NULL, `signature` text NOT NULL, `signer` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY(`id`), INDEX `iid` (`iid`), INDEX `retract_iid` (`retract_iid`) ) DEFAULT CHARSET=utf8; @@ -863,12 +909,13 @@ CREATE TABLE IF NOT EXISTS `sign` ( -- TABLE spam -- CREATE TABLE IF NOT EXISTS `spam` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL DEFAULT 0, `spam` int(11) NOT NULL DEFAULT 0, `ham` int(11) NOT NULL DEFAULT 0, `term` varchar(255) NOT NULL DEFAULT '', `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `uid` (`uid`), INDEX `spam` (`spam`), INDEX `ham` (`ham`), @@ -879,7 +926,7 @@ CREATE TABLE IF NOT EXISTS `spam` ( -- TABLE term -- CREATE TABLE IF NOT EXISTS `term` ( - `tid` int(10) unsigned NOT NULL auto_increment PRIMARY KEY, + `tid` int(10) unsigned NOT NULL auto_increment, `oid` int(10) unsigned NOT NULL DEFAULT 0, `otype` tinyint(3) unsigned NOT NULL DEFAULT 0, `type` tinyint(3) unsigned NOT NULL DEFAULT 0, @@ -891,6 +938,7 @@ CREATE TABLE IF NOT EXISTS `term` ( `global` tinyint(1) NOT NULL DEFAULT 0, `aid` int(10) unsigned NOT NULL DEFAULT 0, `uid` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY(`tid`), INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`), INDEX `uid_term_tid` (`uid`,`term`,`tid`), INDEX `type_term` (`type`,`term`), @@ -903,9 +951,10 @@ CREATE TABLE IF NOT EXISTS `term` ( -- TABLE thread -- CREATE TABLE IF NOT EXISTS `thread` ( - `iid` int(10) unsigned NOT NULL DEFAULT 0 PRIMARY KEY, + `iid` int(10) unsigned NOT NULL DEFAULT 0, `uid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(11) unsigned NOT NULL DEFAULT 0, + `gcontact-id` int(11) unsigned NOT NULL DEFAULT 0, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', @@ -926,6 +975,7 @@ CREATE TABLE IF NOT EXISTS `thread` ( `forum_mode` tinyint(1) NOT NULL DEFAULT 0, `mention` tinyint(1) NOT NULL DEFAULT 0, `network` varchar(32) NOT NULL DEFAULT '', + PRIMARY KEY(`iid`), INDEX `created` (`created`), INDEX `commented` (`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`), @@ -941,25 +991,27 @@ CREATE TABLE IF NOT EXISTS `thread` ( -- TABLE tokens -- CREATE TABLE IF NOT EXISTS `tokens` ( - `id` varchar(40) NOT NULL PRIMARY KEY, + `id` varchar(40) NOT NULL, `secret` text NOT NULL, `client_id` varchar(20) NOT NULL DEFAULT '', `expires` int(11) NOT NULL DEFAULT 0, `scope` varchar(200) NOT NULL DEFAULT '', - `uid` int(11) NOT NULL DEFAULT 0 + `uid` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; -- -- TABLE unique_contacts -- CREATE TABLE IF NOT EXISTS `unique_contacts` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `url` varchar(255) NOT NULL DEFAULT '', `nick` varchar(255) NOT NULL DEFAULT '', `name` varchar(255) NOT NULL DEFAULT '', `avatar` varchar(255) NOT NULL DEFAULT '', `location` varchar(255) NOT NULL DEFAULT '', `about` text NOT NULL, + PRIMARY KEY(`id`), INDEX `url` (`url`) ) DEFAULT CHARSET=utf8; @@ -967,7 +1019,7 @@ CREATE TABLE IF NOT EXISTS `unique_contacts` ( -- TABLE user -- CREATE TABLE IF NOT EXISTS `user` ( - `uid` int(11) NOT NULL auto_increment PRIMARY KEY, + `uid` int(11) NOT NULL auto_increment, `guid` varchar(64) NOT NULL DEFAULT '', `username` varchar(255) NOT NULL DEFAULT '', `password` varchar(255) NOT NULL DEFAULT '', @@ -1009,6 +1061,7 @@ CREATE TABLE IF NOT EXISTS `user` ( `deny_cid` mediumtext NOT NULL, `deny_gid` mediumtext NOT NULL, `openidserver` text NOT NULL, + PRIMARY KEY(`uid`), INDEX `nickname` (`nickname`) ) DEFAULT CHARSET=utf8; @@ -1016,8 +1069,9 @@ CREATE TABLE IF NOT EXISTS `user` ( -- TABLE userd -- CREATE TABLE IF NOT EXISTS `userd` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `username` varchar(255) NOT NULL, + PRIMARY KEY(`id`), INDEX `username` (`username`) ) DEFAULT CHARSET=utf8; @@ -1025,12 +1079,13 @@ CREATE TABLE IF NOT EXISTS `userd` ( -- TABLE workerqueue -- CREATE TABLE IF NOT EXISTS `workerqueue` ( - `id` int(11) NOT NULL auto_increment PRIMARY KEY, + `id` int(11) NOT NULL auto_increment, `parameter` text NOT NULL, `priority` tinyint(3) unsigned NOT NULL DEFAULT 0, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `pid` int(11) NOT NULL DEFAULT 0, `executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY(`id`), INDEX `created` (`created`) ) DEFAULT CHARSET=utf8; diff --git a/include/dbstructure.php b/include/dbstructure.php index 851eb2328..42ddc31b7 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -795,6 +795,7 @@ function db_definition() { "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), + "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), @@ -871,6 +872,7 @@ function db_definition() { "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_created" => array("uid","contact-id","created"), + "uid_gcontactid_created" => array("uid","gcontact-id","created"), "wall_body" => array("wall","body(6)"), "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid","uri"), @@ -1287,6 +1289,7 @@ function db_definition() { "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), + "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), diff --git a/include/diaspora.php b/include/diaspora.php index 75e4a7106..fe5c14164 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2488,6 +2488,14 @@ function diaspora_profile($importer,$xml,$msg) { datetime_convert(), 2, $contact['id'], $importer['uid']); } + // @todo: + /* + update_gcontact($contact["url"], $contact["network"], + $author["author-avatar"], $contact["name"], + $contact["nick"], $contact["location"], + $contact["about"]); + */ + $profileurl = ""; $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($contact['url']))); diff --git a/include/items.php b/include/items.php index c9e13b1a1..ada3906f8 100644 --- a/include/items.php +++ b/include/items.php @@ -1338,6 +1338,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa logger("item_store: Set network to ".$arr["network"]." for ".$arr["uri"], LOGGER_DEBUG); } + if ($arr["gcontact-id"] == 0) + $arr["gcontact-id"] = get_gcontact_id($arr['author-link'], $arr['network'], $arr['author-avatar'], $arr['author-name']); + if ($arr['guid'] != "") { // Checking if there is already an item with the same guid logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG); diff --git a/include/ostatus.php b/include/ostatus.php index 1087596e2..5426fc5fe 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -129,45 +129,50 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) if ($r AND !$onlyfetch) { // Update contact data - $update_contact = ($r[0]['name-date'] < datetime_convert('','','now -12 hours')); - if ($update_contact) { + + $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; + if ($value != "") + $contact["name"] = $value; + + $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; + if ($value != "") + $contact["nick"] = $value; + + $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; + if ($value != "") + $contact["about"] = html2bbcode($value); + + $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; + if ($value != "") + $contact["location"] = $value; + + if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["location"] != $r[0]["location"])) { + logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG); - $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($value != "") - $contact["name"] = $value; - - $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") - $contact["nick"] = $value; - - $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; - if ($value != "") - $contact["about"] = html2bbcode($value); - - $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; - if ($value != "") - $contact["location"] = $value; - q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'", dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"], - "", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]); + "", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]); } - $update_photo = ($r[0]['avatar-date'] < datetime_convert('','','now -12 hours')); - - if ($update_photo AND isset($author["author-avatar"])) { + if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['photo'])) { logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG); $photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]); q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'", - dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), + dbesc($author["author-avatar"]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); } + + // @todo: Addr + update_gcontact($contact["url"], $contact["network"], + $author["author-avatar"], $contact["name"], + $contact["nick"], $contact["location"], + $contact["about"]); } return($author); diff --git a/include/socgraph.php b/include/socgraph.php index 89b09515e..fcce0b4a5 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -326,28 +326,34 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca ); } } else { - q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`) - VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", - dbesc($name), - dbesc($nick), - dbesc($addr), - dbesc($network), - dbesc($profile_url), - dbesc(normalise_link($profile_url)), - dbesc($profile_photo), - dbesc($connect_url), - dbesc($server_url), - dbesc(datetime_convert()), - dbesc($updated), - dbesc($location), - dbesc($about), - dbesc($keywords), - dbesc($gender), - intval($generation) - ); - $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + // Maybe another process had inserted the entry after the first check, so it again + $x = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($profile_url)) ); + if(!$x) { + q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + dbesc($name), + dbesc($nick), + dbesc($addr), + dbesc($network), + dbesc($profile_url), + dbesc(normalise_link($profile_url)), + dbesc($profile_photo), + dbesc($connect_url), + dbesc($server_url), + dbesc(datetime_convert()), + dbesc($updated), + dbesc($location), + dbesc($about), + dbesc($keywords), + dbesc($gender), + intval($generation) + ); + $x = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($profile_url)) + ); + } if(count($x)) $gcid = $x[0]['id']; } @@ -380,11 +386,11 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca } // For unknown reasons there are sometimes duplicates - q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND - NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)", - dbesc(normalise_link($profile_url)), - intval($gcid) - ); + //q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND + // NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)", + // dbesc(normalise_link($profile_url)), + // intval($gcid) + //); return $gcid; } @@ -1481,4 +1487,78 @@ function poco_discover_server($data, $default_generation = 0) { } return $success; } + +function get_gcontact_id($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") { + + $gcontact_id = 0; + + if ($network == NETWORK_STATUSNET) + $network = NETWORK_OSTATUS; + + $r = q("SELECT `id`, `name`, `nick`, `network`, `photo`, `location`, `about` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($url))); + + if ($r) + $gcontact_id = $r[0]["id"]; + else { + q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", + dbesc($name), + dbesc($nick), + dbesc($addr), + dbesc($network), + dbesc($url), + dbesc(normalise_link($url)), + dbesc($avatar), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($location), + dbesc($about) + ); + + $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url))); + + if ($r) + $gcontact_id = $r[0]["id"]; + } + + return $gcontact_id; +} + +function update_gcontact($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") { + + if ($network == NETWORK_STATUSNET) + $network = NETWORK_OSTATUS; + + $gcontact_id = get_gcontact_id($url, $network, $avatar, $name, $nick, $location, $about); + + if (!$gcontact_id) + return false; + + if (($avatar != $r[0]["photo"]) AND ($avatar != "")) + q("UPDATE `gcontact` SET `photo` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `photo` = '')", + dbesc($avatar), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + if (($name != $r[0]["name"]) AND ($name != "")) + q("UPDATE `gcontact` SET `name` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `name` = '')", + dbesc($name), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + if (($nick != $r[0]["nick"]) AND ($nick != "")) + q("UPDATE `gcontact` SET `nick` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `nick` = '')", + dbesc($nick), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + if (($addr != $r[0]["addr"]) AND ($nick != "")) + q("UPDATE `gcontact` SET `addr` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `addr` = '')", + dbesc($addr), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + if (($location != $r[0]["location"]) AND ($location != "")) + q("UPDATE `gcontact` SET `location` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `location` = '')", + dbesc($location), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + if (($about != $r[0]["about"]) AND ($about != "")) + q("UPDATE `gcontact` SET `about` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `about` = '')", + dbesc($about), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + + return $gcontact_id; +} ?> diff --git a/include/threads.php b/include/threads.php index c12f43bb8..a67184659 100644 --- a/include/threads.php +++ b/include/threads.php @@ -1,6 +1,6 @@ %')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` "; - $sql_extra3 .= " AND `contact-id` IN ($contact_str$contact_str_self) "; + $sql_extra3 .= " AND $sql_table.`contact-id` IN ($contact_str$contact_str_self) "; $sql_extra3 .= " AND EXISTS (SELECT `id` FROM `item` WHERE (`contact-id` IN ($contact_str) OR `allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."') AND `deleted` = 0 - AND `parent` = $sql_table.$sql_parent) "; + AND `id` = $sql_table.$sql_parent) "; $o = replace_macros(get_markup_template("section_title.tpl"),array( '$title' => sprintf( t('Group: %s'), $r[0]['name']) @@ -582,11 +582,11 @@ function network_content(&$a, $update = 0) { intval($cid) ); if(count($r)) { - $sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` - WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." AND `deleted` = 0 - ORDER BY `item`.`received` DESC) AS `temp1` - ON $sql_table.$sql_parent = `temp1`.`parent` "; - $sql_extra = ""; + //$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` + // WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." AND `deleted` = 0 + // ORDER BY `item`.`received` DESC) AS `temp1` + // ON $sql_table.$sql_parent = `temp1`.`parent` "; + $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid); $entries[0] = array( 'id' => 'network', diff --git a/update.php b/update.php index caa167617..197e78de5 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Wed, 6 Jan 2016 14:13:59 +0100 Subject: [PATCH 02/17] More fields in gcontact, contact search respects "hide" setting --- database.sql | 3 ++ include/dbstructure.php | 3 ++ include/diaspora.php | 49 +++++++---------- include/items.php | 3 +- include/ostatus.php | 8 +-- include/socgraph.php | 114 ++++++++++++++++++++++++++-------------- mod/dirfind.php | 16 ++++-- mod/item.php | 5 +- mod/poco.php | 6 +-- 9 files changed, 120 insertions(+), 87 deletions(-) diff --git a/database.sql b/database.sql index 1277585c9..90604457b 100644 --- a/database.sql +++ b/database.sql @@ -333,6 +333,8 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( `keywords` text NOT NULL, `gender` varchar(32) NOT NULL DEFAULT '', `community` tinyint(1) NOT NULL DEFAULT 0, + `hide` tinyint(1) NOT NULL DEFAULT 0, + `nsfw` tinyint(1) NOT NULL DEFAULT 0, `network` varchar(255) NOT NULL DEFAULT '', `addr` varchar(255) NOT NULL DEFAULT '', `generation` tinyint(3) NOT NULL DEFAULT 0, @@ -536,6 +538,7 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_parenturi` (`uid`,`parent-uri`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), + INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`), INDEX `wall_body` (`wall`,`body`(6)), INDEX `uid_visible_moderated_created` (`uid`,`visible`,`moderated`,`created`), INDEX `uid_uri` (`uid`,`uri`), diff --git a/include/dbstructure.php b/include/dbstructure.php index 42ddc31b7..1fc388d6c 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -666,7 +666,10 @@ function db_definition() { "about" => array("type" => "text", "not null" => "1"), "keywords" => array("type" => "text", "not null" => "1"), "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), + "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"), "community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), + "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), + "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"), diff --git a/include/diaspora.php b/include/diaspora.php index fe5c14164..59c1ac5a2 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2407,10 +2407,10 @@ function diaspora_profile($importer,$xml,$msg) { if(! $contact) return; - if($contact['blocked']) { - logger('diaspora_post: Ignoring this author.'); - return 202; - } + //if($contact['blocked']) { + // logger('diaspora_post: Ignoring this author.'); + // return 202; + //} $name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : ''); $image_url = unxmlify($xml->image_url); @@ -2418,6 +2418,8 @@ function diaspora_profile($importer,$xml,$msg) { $location = diaspora2bb(unxmlify($xml->location)); $about = diaspora2bb(unxmlify($xml->bio)); $gender = unxmlify($xml->gender); + $searchable = (unxmlify($xml->searchable) == "true"); + $nsfw = (unxmlify($xml->nsfw) == "true"); $tags = unxmlify($xml->tag_string); $tags = explode("#", $tags); @@ -2432,6 +2434,8 @@ function diaspora_profile($importer,$xml,$msg) { $keywords = implode(", ", $keywords); $handle_parts = explode("@", $diaspora_handle); + $nick = $handle_parts[0]; + if($name === '') { $name = $handle_parts[0]; } @@ -2466,10 +2470,12 @@ function diaspora_profile($importer,$xml,$msg) { /// @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). - $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", + $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%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($nick), + dbesc($diaspora_handle), dbesc(datetime_convert()), - dbesc($images[0]), + dbesc($image_url), dbesc($images[1]), dbesc($images[2]), dbesc(datetime_convert()), @@ -2482,34 +2488,17 @@ function diaspora_profile($importer,$xml,$msg) { intval($importer['uid']) ); - if (unxmlify($xml->searchable) == "true") { + if ($searchable) { require_once('include/socgraph.php'); - poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "", + poco_check($contact['url'], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "", datetime_convert(), 2, $contact['id'], $importer['uid']); } - // @todo: - /* - update_gcontact($contact["url"], $contact["network"], - $author["author-avatar"], $contact["name"], - $contact["nick"], $contact["location"], - $contact["about"]); - */ - - $profileurl = ""; - $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", - dbesc(normalise_link($contact['url']))); - - if (count($author) == 0) { - q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`, `location`, `about`) VALUES ('%s', '%s', '%s', '%s', '%s')", - dbesc(normalise_link($contact['url'])), dbesc($name), dbesc($location), dbesc($about), dbesc($images[0])); - - $author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", - dbesc(normalise_link($contact['url']))); - } else if (normalise_link($contact['url']).$name.$location.$about != normalise_link($author[0]["url"]).$author[0]["name"].$author[0]["location"].$author[0]["about"]) { - q("UPDATE unique_contacts SET name = '%s', avatar = '%s', `location` = '%s', `about` = '%s' WHERE url = '%s'", - dbesc($name), dbesc($images[0]), dbesc($location), dbesc($about), dbesc(normalise_link($contact['url']))); - } + update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2, + "photo" => $image_url, "name" => $name, "location" => $location, + "about" => $about, "birthday" => $birthday, "gender" => $gender, + "addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords, + "hide" => !$searchable, "nsfw" => $nsfw)); /* if($r) { if($oldphotos) { diff --git a/include/items.php b/include/items.php index ada3906f8..549027671 100644 --- a/include/items.php +++ b/include/items.php @@ -1339,7 +1339,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } if ($arr["gcontact-id"] == 0) - $arr["gcontact-id"] = get_gcontact_id($arr['author-link'], $arr['network'], $arr['author-avatar'], $arr['author-name']); + $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'], + "photo" => $arr['author-avatar'], "name" => $arr['author-name'])); if ($arr['guid'] != "") { // Checking if there is already an item with the same guid diff --git a/include/ostatus.php b/include/ostatus.php index 5426fc5fe..4a999ae2c 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -169,10 +169,10 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) } // @todo: Addr - update_gcontact($contact["url"], $contact["network"], - $author["author-avatar"], $contact["name"], - $contact["nick"], $contact["location"], - $contact["about"]); + update_gcontact(array("url" => $contact["url"], "network" => $contact["network"], + "photo" => $author["author-avatar"], "name" => $contact["name"], + "nick" => $contact["nick"], "location" => $contact["location"], + "about" => $contact["about"], "generation" => 2)); } return($author); diff --git a/include/socgraph.php b/include/socgraph.php index fcce0b4a5..4881ac28e 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1488,35 +1488,37 @@ function poco_discover_server($data, $default_generation = 0) { return $success; } -function get_gcontact_id($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") { +function get_gcontact_id($contact) { $gcontact_id = 0; - if ($network == NETWORK_STATUSNET) - $network = NETWORK_OSTATUS; + if ($contact["network"] == NETWORK_STATUSNET) + $contact["network"] = NETWORK_OSTATUS; - $r = q("SELECT `id`, `name`, `nick`, `network`, `photo`, `location`, `about` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", - dbesc(normalise_link($url))); + $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($contact["url"]))); if ($r) $gcontact_id = $r[0]["id"]; else { - q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`) - VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", - dbesc($name), - dbesc($nick), - dbesc($addr), - dbesc($network), - dbesc($url), - dbesc(normalise_link($url)), - dbesc($avatar), + q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + dbesc($contact["name"]), + dbesc($contact["nick"]), + dbesc($contact["addr"]), + dbesc($contact["network"]), + dbesc($contact["url"]), + dbesc(normalise_link($contact["url"])), + dbesc($contact["photo"]), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc($location), - dbesc($about) + dbesc($contact["location"]), + dbesc($contact["about"]), + intval($contact["generation"]) ); - $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url))); + $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($contact["url"]))); if ($r) $gcontact_id = $r[0]["id"]; @@ -1525,39 +1527,71 @@ function get_gcontact_id($url, $network, $avatar = "", $name = "", $nick = "", $ return $gcontact_id; } -function update_gcontact($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") { +function update_gcontact($contact) { - if ($network == NETWORK_STATUSNET) - $network = NETWORK_OSTATUS; - - $gcontact_id = get_gcontact_id($url, $network, $avatar, $name, $nick, $location, $about); + $gcontact_id = get_gcontact_id($contact); if (!$gcontact_id) return false; - if (($avatar != $r[0]["photo"]) AND ($avatar != "")) - q("UPDATE `gcontact` SET `photo` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `photo` = '')", - dbesc($avatar), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw` + FROM `gcontact` WHERE `id` = %d LIMIT 1", + intval($gcontact_id)); - if (($name != $r[0]["name"]) AND ($name != "")) - q("UPDATE `gcontact` SET `name` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `name` = '')", - dbesc($name), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + if ($contact["generation"] == 0) + $contact["generation"] = $r[0]["generation"]; - if (($nick != $r[0]["nick"]) AND ($nick != "")) - q("UPDATE `gcontact` SET `nick` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `nick` = '')", - dbesc($nick), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + if ($contact["photo"] == "") + $contact["photo"] = $r[0]["photo"]; - if (($addr != $r[0]["addr"]) AND ($nick != "")) - q("UPDATE `gcontact` SET `addr` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `addr` = '')", - dbesc($addr), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + if ($contact["name"] == "") + $contact["name"] = $r[0]["name"]; - if (($location != $r[0]["location"]) AND ($location != "")) - q("UPDATE `gcontact` SET `location` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `location` = '')", - dbesc($location), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + if ($contact["nick"] == "") + $contact["nick"] = $r[0]["nick"]; - if (($about != $r[0]["about"]) AND ($about != "")) - q("UPDATE `gcontact` SET `about` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `about` = '')", - dbesc($about), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network)); + if ($contact["addr"] == "") + $contact["addr"] = $r[0]["addr"]; + + if ($contact["location"] =="") + $contact["location"] = $r[0]["location"]; + + if ($contact["about"] =="") + $contact["about"] = $r[0]["about"]; + + if ($contact["birthday"] =="") + $contact["birthday"] = $r[0]["birthday"]; + + if ($contact["gender"] =="") + $contact["gender"] = $r[0]["gender"]; + + if ($contact["keywords"] =="") + $contact["keywords"] = $r[0]["keywords"]; + + if (!isset($contact["hide"])) + $contact["hide"] = $r[0]["hide"]; + + if (!isset($contact["nsfw"])) + $contact["nsfw"] = $r[0]["nsfw"]; + + if ($contact["network"] == NETWORK_STATUSNET) + $contact["network"] = NETWORK_OSTATUS; + + if (($contact["photo"] != $r[0]["photo"]) OR ($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["addr"] != $r[0]["addr"]) OR + ($contact["birthday"] != $r[0]["birthday"]) OR ($contact["gender"] != $r[0]["gender"]) OR ($contact["keywords"] != $r[0]["keywords"]) OR + ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR + ($contact["location"] != $r[0]["location"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["generation"] < $r[0]["generation"])) { + + q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', + `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, + `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s' + WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `generation` >= %d)", + dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), + dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), + intval($contact["hide"]), intval($contact["nsfw"]), + dbesc($contact["location"]), dbesc($contact["about"]), intval($contact["generation"]), dbesc(datetime_convert()), + dbesc(normalise_link($contact["url"])), dbesc($contact["network"]), intval($contact["generation"])); + } return $gcontact_id; } diff --git a/mod/dirfind.php b/mod/dirfind.php index 3f9c82576..0dfe4d67a 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -94,9 +94,15 @@ function dirfind_content(&$a, $prefix = "") { else $ostatus = NETWORK_DFRN; - $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND - (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR - `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql, + $count = q("SELECT count(*) AS `total` FROM `gcontact` + LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` + AND `contact`.`uid` = %d AND NOT `contact`.`blocked` + AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') + WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND + ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND + (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR + `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql", + intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search))); @@ -106,8 +112,8 @@ function dirfind_content(&$a, $prefix = "") { LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d AND NOT `contact`.`blocked` AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') - WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND - ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND + WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND + ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql GROUP BY `gcontact`.`nurl` diff --git a/mod/item.php b/mod/item.php index 2bf89f67f..105f82708 100644 --- a/mod/item.php +++ b/mod/item.php @@ -693,9 +693,8 @@ function item_post(&$a) { $datarray['postopts'] = $postopts; $datarray['origin'] = $origin; $datarray['moderated'] = $allow_moderated; - $datarray['gcontact-id'] = get_gcontact_id($datarray['author-link'], $datarray['network'], - $datarray['author-avatar'], $datarray['author-name']); - + $datarray['gcontact-id'] = get_gcontact_id(array("url" => $datarray['author-link'], "network" => $datarray['network'], + "photo" => $datarray['author-avatar'], "name" => $datarray['author-name'])); /** * These fields are for the convenience of plugins... * 'self' if true indicates the owner is posting on their own wall diff --git a/mod/poco.php b/mod/poco.php index ae03aef2c..0a1b39216 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -61,8 +61,7 @@ function poco_init(&$a) { $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 ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND `network` IN ('%s')", - $r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND `network` IN ('%s', '%s', '%s')", + $r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')", dbesc($update_limit), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), @@ -94,8 +93,7 @@ function poco_init(&$a) { if ($global) { logger("Start global query", LOGGER_DEBUG); - //$r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s') AND ((`last_contact` >= `last_failure`) OR (`updated` > `last_failure`)) LIMIT %d, %d", - $r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s', '%s', '%s') AND `updated` > `last_failure` + $r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND NOT `hide` AND `network` IN ('%s', '%s', '%s') AND `updated` > `last_failure` ORDER BY `updated` DESC LIMIT %d, %d", dbesc($update_limit), dbesc(NETWORK_DFRN), From 5ab2786c00b84b3546d6c6c820c0f278baf6fb33 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 6 Jan 2016 22:23:12 +0100 Subject: [PATCH 03/17] Get rid of the table "unique_contacts" --- database.sql | 16 +---- doc/database.md | 1 - doc/database/db_unique_contacts.md | 14 ----- friendica_test_data.sql | 29 --------- include/Contact.php | 13 ---- include/api.php | 96 ++++++++---------------------- include/dbstructure.php | 15 ----- include/ostatus.php | 7 ++- mod/admin.php | 2 +- mod/display.php | 8 ++- 10 files changed, 38 insertions(+), 163 deletions(-) delete mode 100644 doc/database/db_unique_contacts.md diff --git a/database.sql b/database.sql index 90604457b..4e6f3d35c 100644 --- a/database.sql +++ b/database.sql @@ -332,6 +332,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( `about` text NOT NULL, `keywords` text NOT NULL, `gender` varchar(32) NOT NULL DEFAULT '', + `birthday` varchar(32) NOT NULL DEFAULT '0000-00-00', `community` tinyint(1) NOT NULL DEFAULT 0, `hide` tinyint(1) NOT NULL DEFAULT 0, `nsfw` tinyint(1) NOT NULL DEFAULT 0, @@ -1003,21 +1004,6 @@ CREATE TABLE IF NOT EXISTS `tokens` ( PRIMARY KEY(`id`) ) DEFAULT CHARSET=utf8; --- --- TABLE unique_contacts --- -CREATE TABLE IF NOT EXISTS `unique_contacts` ( - `id` int(11) NOT NULL auto_increment, - `url` varchar(255) NOT NULL DEFAULT '', - `nick` varchar(255) NOT NULL DEFAULT '', - `name` varchar(255) NOT NULL DEFAULT '', - `avatar` varchar(255) NOT NULL DEFAULT '', - `location` varchar(255) NOT NULL DEFAULT '', - `about` text NOT NULL, - PRIMARY KEY(`id`), - INDEX `url` (`url`) -) DEFAULT CHARSET=utf8; - -- -- TABLE user -- diff --git a/doc/database.md b/doc/database.md index 1893f77d0..2ef77c6da 100644 --- a/doc/database.md +++ b/doc/database.md @@ -54,7 +54,6 @@ Database Tables | [term](help/database/db_term) | item taxonomy (categories, tags, etc.) table | | [thread](help/database/db_thread) | | | [tokens](help/database/db_tokens) | OAuth usage | -| [unique_contacts](help/database/db_unique_contacts) | | | [user](help/database/db_user) | local user table | | [userd](help/database/db_userd) | | | [workerqueue](help/database/db_workerqueue) | | diff --git a/doc/database/db_unique_contacts.md b/doc/database/db_unique_contacts.md deleted file mode 100644 index 491da6aac..000000000 --- a/doc/database/db_unique_contacts.md +++ /dev/null @@ -1,14 +0,0 @@ -Table unique_contacts -===================== - -| Field | Description | Type | Null | Key | Default | Extra | -|----------|------------------|--------------|------|-----|---------|----------------| -| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment | -| url | | varchar(255) | NO | MUL | | | -| nick | | varchar(255) | NO | | | | -| name | | varchar(255) | NO | | | | -| avatar | | varchar(255) | NO | | | | -| location | | varchar(255) | NO | | | | -| about | | text | NO | | NULL | | - -Return to [database documentation](help/database) diff --git a/friendica_test_data.sql b/friendica_test_data.sql index c39a05765..45080e44d 100644 --- a/friendica_test_data.sql +++ b/friendica_test_data.sql @@ -1657,35 +1657,6 @@ LOCK TABLES `tokens` WRITE; /*!40000 ALTER TABLE `tokens` ENABLE KEYS */; UNLOCK TABLES; --- --- Table structure for table `unique_contacts` --- - -DROP TABLE IF EXISTS `unique_contacts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `unique_contacts` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `url` varchar(255) NOT NULL DEFAULT '', - `nick` varchar(255) NOT NULL DEFAULT '', - `name` varchar(255) NOT NULL DEFAULT '', - `avatar` varchar(255) NOT NULL DEFAULT '', - `location` varchar(255) NOT NULL DEFAULT '', - `about` text NOT NULL, - PRIMARY KEY (`id`), - KEY `url` (`url`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `unique_contacts` --- - -LOCK TABLES `unique_contacts` WRITE; -/*!40000 ALTER TABLE `unique_contacts` DISABLE KEYS */; -/*!40000 ALTER TABLE `unique_contacts` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `user` -- diff --git a/include/Contact.php b/include/Contact.php index a3cbbfed1..3185e8734 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -205,19 +205,6 @@ function get_contact_details_by_url($url, $uid = -1) { if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) proc_run('php',"include/update_gcontact.php", $profile["gid"]); - - } else { - $r = q("SELECT `url`, `name`, `nick`, `avatar` AS `photo`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", - dbesc(normalise_link($url))); - - if (count($r)) { - $profile = $r[0]; - $profile["keywords"] = ""; - $profile["gender"] = ""; - $profile["community"] = false; - $profile["network"] = ""; - $profile["addr"] = ""; - } } // Fetching further contact data from the contact table diff --git a/include/api.php b/include/api.php index 790894d3f..3bc7c8bab 100644 --- a/include/api.php +++ b/include/api.php @@ -393,7 +393,7 @@ * Contact url or False if contact id is unknown */ function api_unique_id_to_url($id){ - $r = q("SELECT `url` FROM `unique_contacts` WHERE `id`=%d LIMIT 1", + $r = q("SELECT `url` FROM `gcontact` WHERE `id`=%d LIMIT 1", intval($id)); if ($r) return ($r[0]["url"]); @@ -503,9 +503,7 @@ $r = array(); if ($url != "") - $r = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $url); - elseif ($nick != "") - $r = q("SELECT * FROM `unique_contacts` WHERE `nick`='%s' LIMIT 1", $nick); + $r = q("SELECT * FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($url))); if ($r) { // If no nick where given, extract it from the address @@ -517,14 +515,14 @@ 'id_str' => (string) $r[0]["id"], 'name' => $r[0]["name"], 'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']), - 'location' => NULL, - 'description' => NULL, + 'location' => $r[0]["location"], + 'description' => $r[0]["about"], 'url' => $r[0]["url"], 'protected' => false, 'followers_count' => 0, 'friends_count' => 0, 'listed_count' => 0, - 'created_at' => api_date(0), + 'created_at' => api_date($r[0]["created"]), 'favourites_count' => 0, 'utc_offset' => 0, 'time_zone' => 'UTC', @@ -535,8 +533,8 @@ 'contributors_enabled' => false, 'is_translator' => false, 'is_translation_enabled' => false, - 'profile_image_url' => $r[0]["avatar"], - 'profile_image_url_https' => $r[0]["avatar"], + 'profile_image_url' => $r[0]["photo"], + 'profile_image_url_https' => $r[0]["photo"], 'following' => false, 'follow_request_sent' => false, 'notifications' => false, @@ -546,7 +544,7 @@ 'uid' => 0, 'cid' => 0, 'self' => 0, - 'network' => '', + 'network' => $r[0]["network"], ); return $ret; @@ -617,22 +615,14 @@ $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]); } - // Fetching unique id - $r = q("SELECT id FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url']))); - - // If not there, then add it - if (count($r) == 0) { - q("INSERT INTO `unique_contacts` (`url`, `name`, `nick`, `avatar`) VALUES ('%s', '%s', '%s', '%s')", - dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro'])); - - $r = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url']))); - } - $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']); + $gcontact_id = get_gcontact_id(array("url" => $uinfo[0]['url'], "network" => $uinfo[0]['network'], + "photo" => $uinfo[0]['micro'], "name" => $uinfo[0]['name'])); + $ret = Array( - 'id' => intval($r[0]['id']), - 'id_str' => (string) intval($r[0]['id']), + 'id' => intval($gcontact_id), + 'id_str' => (string) intval($gcontact_id), 'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']), 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']), 'location' => ($usr) ? $usr[0]['default-location'] : $network_name, @@ -666,45 +656,12 @@ function api_item_get_user(&$a, $item) { - $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", - dbesc(normalise_link($item['author-link']))); + // Make sure that there is an entry in the global contacts for author and owner + get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'], + "photo" => $item['author-avatar'], "name" => $item['author-name'])); - if (count($author) == 0) { - q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')", - dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"])); - - $author = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", - dbesc(normalise_link($item['author-link']))); - } else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) { - $r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'", - dbesc($item["author-name"]), dbesc($item["author-avatar"]), - dbesc(normalise_link($item["author-link"]))); - - if (!$r) - q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'", - dbesc($item["author-name"]), dbesc($item["author-avatar"]), - dbesc(normalise_link($item["author-link"]))); - } - - $owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", - dbesc(normalise_link($item['owner-link']))); - - if (count($owner) == 0) { - q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')", - dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"])); - - $owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", - dbesc(normalise_link($item['owner-link']))); - } else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) { - $r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'", - dbesc($item["owner-name"]), dbesc($item["owner-avatar"]), - dbesc(normalise_link($item["owner-link"]))); - - if (!$r) - q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'", - dbesc($item["owner-name"]), dbesc($item["owner-avatar"]), - dbesc(normalise_link($item["owner-link"]))); - } + get_gcontact_id(array("url" => $item['owner-link'], "network" => $item['network'], + "photo" => $item['owner-avatar'], "name" => $item['owner-name'])); // Comments in threads may appear as wall-to-wall postings. // So only take the owner at the top posting. @@ -1073,7 +1030,7 @@ $in_reply_to_status_id= intval($lastwall['parent']); $in_reply_to_status_id_str = (string) intval($lastwall['parent']); - $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author']))); + $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($lastwall['item-author']))); if ($r) { if ($r[0]['nick'] == "") $r[0]['nick'] = api_get_nick($r[0]["url"]); @@ -1195,7 +1152,7 @@ $in_reply_to_status_id = intval($lastwall['parent']); $in_reply_to_status_id_str = (string) intval($lastwall['parent']); - $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author']))); + $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($reply[0]['item-author']))); if ($r) { if ($r[0]['nick'] == "") $r[0]['nick'] = api_get_nick($r[0]["url"]); @@ -1256,9 +1213,9 @@ $userlist = array(); if (isset($_GET["q"])) { - $r = q("SELECT id FROM `unique_contacts` WHERE `name`='%s'", dbesc($_GET["q"])); + $r = q("SELECT id FROM `gcontact` WHERE `name`='%s'", dbesc($_GET["q"])); if (!count($r)) - $r = q("SELECT `id` FROM `unique_contacts` WHERE `nick`='%s'", dbesc($_GET["q"])); + $r = q("SELECT `id` FROM `gcontact` WHERE `nick`='%s'", dbesc($_GET["q"])); if (count($r)) { foreach ($r AS $user) { @@ -2341,7 +2298,7 @@ intval(api_user()), intval($in_reply_to_status_id)); if ($r) { - $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link']))); + $r = q("SELECT * FROM `gcontact` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link']))); if ($r) { if ($r[0]['nick'] == "") @@ -2596,7 +2553,7 @@ $stringify_ids = (x($_REQUEST,'stringify_ids')?$_REQUEST['stringify_ids']:false); - $r = q("SELECT `unique_contacts`.`id` FROM `contact`, `unique_contacts` WHERE `contact`.`nurl` = `unique_contacts`.`url` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra", + $r = q("SELECT `gcontact`.`id` FROM `contact`, `gcontact` WHERE `contact`.`nurl` = `gcontact`.`nurl` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra", intval(api_user()) ); @@ -3094,11 +3051,8 @@ //} - if ($nick != "") { - q("UPDATE `unique_contacts` SET `nick` = '%s' WHERE `nick` != '%s' AND url = '%s'", - dbesc($nick), dbesc($nick), dbesc(normalise_link($profile))); + if ($nick != "") return($nick); - } return(false); } diff --git a/include/dbstructure.php b/include/dbstructure.php index 1fc388d6c..1b414c70f 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1340,21 +1340,6 @@ function db_definition() { "PRIMARY" => array("id"), ) ); - $database["unique_contacts"] = array( - "fields" => array( - "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), - "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "about" => array("type" => "text", "not null" => "1"), - ), - "indexes" => array( - "PRIMARY" => array("id"), - "url" => array("url"), - ) - ); $database["user"] = array( "fields" => array( "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), diff --git a/include/ostatus.php b/include/ostatus.php index 4a999ae2c..c1b823329 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1452,9 +1452,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) $repeated_owner["about"] = ""; $repeated_owner["uid"] = 0; - $r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"])); + // Fetch the missing data from the global contacts + $r =q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($repeated_item["author-link"])); if ($r) { - $repeated_owner["nick"] = $r[0]["nick"]; + if ($r[0]["nick"] != "") + $repeated_owner["nick"] = $r[0]["nick"]; + $repeated_owner["location"] = $r[0]["location"]; $repeated_owner["about"] = $r[0]["about"]; } diff --git a/mod/admin.php b/mod/admin.php index 9e330fd1d..0636a3420 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -341,7 +341,7 @@ function admin_page_site_post(&$a){ update_table("profile", array('photo', 'thumb'), $old_url, $new_url); update_table("term", array('url'), $old_url, $new_url); update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url); - update_table("unique_contacts", array('url'), $old_url, $new_url); + update_table("gcontact", array('photo','url','nurl','server_url'), $old_url, $new_url); update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url); // update config diff --git a/mod/display.php b/mod/display.php index 6d1f417e7..c173c5a91 100644 --- a/mod/display.php +++ b/mod/display.php @@ -179,8 +179,8 @@ function display_fetchauthor($a, $item) { $profiledata["nickname"] = $r[0]["nick"]; } - // Fetching profile data from unique contacts - $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"]))); + // Fetching profile data from global contacts + $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { if ($profiledata["photo"] == "") $profiledata["photo"] = $r[0]["avatar"]; @@ -190,6 +190,10 @@ function display_fetchauthor($a, $item) { $profiledata["about"] = $r[0]["about"]; if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != "")) $profiledata["nickname"] = $r[0]["nick"]; + if ($profiledata["gender"] == "") + $profiledata["gender"] = $r[0]["gender"]; + if ($profiledata["addr"] == "") + $profiledata["addr"] = $r[0]["addr"]; } if (local_user()) { From fdb31abdfa191350da1fe07f13e85d8cb8f5a398 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 7 Jan 2016 08:19:28 +0100 Subject: [PATCH 04/17] Use gcontact when adressing contacts in editor --- include/socgraph.php | 18 ++++++++++++------ mod/item.php | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 4881ac28e..a9cbedd66 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -784,6 +784,8 @@ function poco_check_server($server_url, $network = "", $force = false) { $version = trim(str_replace("X-Diaspora-Version:", "", $line)); $version = trim(str_replace("x-diaspora-version:", "", $version)); $network = NETWORK_DIASPORA; + $versionparts = explode("-", $version); + $version = $versionparts[0]; } } } @@ -1534,7 +1536,7 @@ function update_gcontact($contact) { if (!$gcontact_id) return false; - $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw` + $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network` FROM `gcontact` WHERE `id` = %d LIMIT 1", intval($gcontact_id)); @@ -1574,23 +1576,27 @@ function update_gcontact($contact) { if (!isset($contact["nsfw"])) $contact["nsfw"] = $r[0]["nsfw"]; + if ($contact["network"] =="") + $contact["network"] = $r[0]["network"]; + if ($contact["network"] == NETWORK_STATUSNET) $contact["network"] = NETWORK_OSTATUS; if (($contact["photo"] != $r[0]["photo"]) OR ($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["addr"] != $r[0]["addr"]) OR ($contact["birthday"] != $r[0]["birthday"]) OR ($contact["gender"] != $r[0]["gender"]) OR ($contact["keywords"] != $r[0]["keywords"]) OR - ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR + ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR ($contact["network"] != $r[0]["network"]) OR ($contact["location"] != $r[0]["location"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["generation"] < $r[0]["generation"])) { - q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', + q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s' - WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `generation` >= %d)", - dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), + WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", + dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), + dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), intval($contact["nsfw"]), dbesc($contact["location"]), dbesc($contact["about"]), intval($contact["generation"]), dbesc(datetime_convert()), - dbesc(normalise_link($contact["url"])), dbesc($contact["network"]), intval($contact["generation"])); + dbesc(normalise_link($contact["url"])), intval($contact["generation"])); } return $gcontact_id; diff --git a/mod/item.php b/mod/item.php index 105f82708..2d2a5710f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -137,6 +137,7 @@ function item_post(&$a) { AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { $parent_contact = null; + // @todo: Use gcontact require_once("include/Scrape.php"); $probed_contact = probe_url($thrparent[0]["author-link"]); if ($probed_contact["network"] != NETWORK_FEED) { @@ -1098,6 +1099,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo //is it a link or a full dfrn address? if((strpos($name,'@')) || (strpos($name,'http://'))) { $newname = $name; + //get the profile links $links = @lrdd($name); if(count($links)) { @@ -1209,8 +1211,29 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $inform .= 'cid:' . $r[0]['id']; } } + + if(!isset($profile)) { + $r = q("SELECT `url` FROM `gcontact` WHERE `addr` = '%s' LIMIT 1", + dbesc($name)); + if ($r) + $profile = $r[0]["url"]; + } + //if there is an url for this persons profile if(isset($profile)) { + + $r = q("SELECT `nick`, `name`, `network` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($profile))); + if ($r) { + $newname = $r[0]["name"]; + + //set newname to nick + if(($r[0]['network'] === NETWORK_OSTATUS) OR ($r[0]['network'] === NETWORK_TWITTER) + OR ($r[0]['network'] === NETWORK_STATUSNET) OR ($r[0]['network'] === NETWORK_APPNET)) { + $newname = $r[0]['nick']; + } + } + $replaced = true; //create profile link $profile = str_replace(',','%2c',$profile); From 9521cdc18f25efeeaa47115ba167b3996d6d626e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 7 Jan 2016 23:43:16 +0100 Subject: [PATCH 05/17] notify and alias are now in gcontact as well - the contact expansion in mod/item.php is renewed --- include/dbstructure.php | 2 + include/socgraph.php | 35 +++++++-- mod/display.php | 1 + mod/item.php | 159 ++++++++++++++++++++++++++++++++-------- 4 files changed, 162 insertions(+), 35 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 1b414c70f..4b2cdb251 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -672,6 +672,8 @@ function db_definition() { "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "notify" => array("type" => "text", "not null" => "1"), + "alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"), "server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), ), diff --git a/include/socgraph.php b/include/socgraph.php index a9cbedd66..0082cb43b 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -227,6 +227,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca $server_url = $x[0]["server_url"]; $nick = $x[0]["nick"]; $addr = $x[0]["addr"]; + $alias = $x[0]["alias"]; + $notify = $x[0]["notify"]; } else { $created = "0000-00-00 00:00:00"; $server_url = ""; @@ -234,6 +236,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca $urlparts = parse_url($profile_url); $nick = end(explode("/", $urlparts["path"])); $addr = ""; + $alias = ""; + $notify = ""; } if ((($network == "") OR ($name == "") OR ($addr == "") OR ($profile_photo == "") OR ($server_url == "") OR $alternate) @@ -246,6 +250,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca $name = $data["name"]; $nick = $data["nick"]; $addr = $data["addr"]; + $alias = $data["alias"]; + $notify = $data["notify"]; $profile_url = $data["url"]; $profile_photo = $data["photo"]; $server_url = $data["baseurl"]; @@ -301,12 +307,19 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca if (($addr == "") AND ($x[0]['addr'] != "")) $addr = $x[0]['addr']; + if (($alias == "") AND ($x[0]['alias'] != "")) + $alias = $x[0]['alias']; + + if (($notify == "") AND ($x[0]['notify'] != "")) + $notify = $x[0]['notify']; + if (($generation == 0) AND ($x[0]['generation'] > 0)) $generation = $x[0]['generation']; if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) { q("UPDATE `gcontact` SET `name` = '%s', `addr` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `server_url` = '%s', - `updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d + `updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d, + `alias` = '$s', `notify` = '%s' WHERE (`generation` >= %d OR `generation` = 0) AND `nurl` = '%s'", dbesc($name), dbesc($addr), @@ -320,6 +333,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca dbesc($about), dbesc($keywords), dbesc($gender), + dbesc($alias), + dbesc($notify), intval($generation), intval($generation), dbesc(normalise_link($profile_url)) @@ -331,8 +346,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca dbesc(normalise_link($profile_url)) ); if(!$x) { - q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`) - VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `alias`, `notify`, `generation`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", dbesc($name), dbesc($nick), dbesc($addr), @@ -348,6 +363,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca dbesc($about), dbesc($keywords), dbesc($gender), + dbesc($alias), + dbesc($notify), intval($generation) ); $x = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", @@ -1536,7 +1553,7 @@ function update_gcontact($contact) { if (!$gcontact_id) return false; - $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network` + $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network`, `alias`, `notify` FROM `gcontact` WHERE `id` = %d LIMIT 1", intval($gcontact_id)); @@ -1579,22 +1596,30 @@ function update_gcontact($contact) { if ($contact["network"] =="") $contact["network"] = $r[0]["network"]; + if ($contact["alias"] =="") + $contact["alias"] = $r[0]["alias"]; + + if ($contact["notify"] =="") + $contact["notify"] = $r[0]["notify"]; + if ($contact["network"] == NETWORK_STATUSNET) $contact["network"] = NETWORK_OSTATUS; if (($contact["photo"] != $r[0]["photo"]) OR ($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["addr"] != $r[0]["addr"]) OR ($contact["birthday"] != $r[0]["birthday"]) OR ($contact["gender"] != $r[0]["gender"]) OR ($contact["keywords"] != $r[0]["keywords"]) OR ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR ($contact["network"] != $r[0]["network"]) OR + ($contact["alias"] != $r[0]["alias"]) OR ($contact["notify"] != $r[0]["notify"]) OR ($contact["location"] != $r[0]["location"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["generation"] < $r[0]["generation"])) { q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, + `alias` = '%s', `notify` = '%s', `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s' WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), - intval($contact["hide"]), intval($contact["nsfw"]), + intval($contact["hide"]), intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), dbesc($contact["location"]), dbesc($contact["about"]), intval($contact["generation"]), dbesc(datetime_convert()), dbesc(normalise_link($contact["url"])), intval($contact["generation"])); } diff --git a/mod/display.php b/mod/display.php index c173c5a91..6ff599e2c 100644 --- a/mod/display.php +++ b/mod/display.php @@ -180,6 +180,7 @@ function display_fetchauthor($a, $item) { } // Fetching profile data from global contacts + // @todo: should override everything else (but not Feeds) $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { if ($profiledata["photo"] == "") diff --git a/mod/item.php b/mod/item.php index 2d2a5710f..56c5ccad9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -137,15 +137,25 @@ function item_post(&$a) { AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { $parent_contact = null; - // @todo: Use gcontact - require_once("include/Scrape.php"); - $probed_contact = probe_url($thrparent[0]["author-link"]); - if ($probed_contact["network"] != NETWORK_FEED) { - $parent_contact = $probed_contact; - $parent_contact["nurl"] = normalise_link($probed_contact["url"]); - $parent_contact["thumb"] = $probed_contact["photo"]; - $parent_contact["micro"] = $probed_contact["photo"]; - $parent_contact["addr"] = $probed_contact["addr"]; + $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($thrparent[0]["author-link"]))); + if (count($r)) { + $parent_contact = $r[0]; + $parent_contact["thumb"] = $parent_contact["photo"]; + $parent_contact["micro"] = $parent_contact["photo"]; + unset($parent_contact["id"]); + } + + if (!isset($parent_contact["nick"])) { + require_once("include/Scrape.php"); + $probed_contact = probe_url($thrparent[0]["author-link"]); + if ($probed_contact["network"] != NETWORK_FEED) { + $parent_contact = $probed_contact; + $parent_contact["nurl"] = normalise_link($probed_contact["url"]); + $parent_contact["thumb"] = $probed_contact["photo"]; + $parent_contact["micro"] = $probed_contact["photo"]; + $parent_contact["addr"] = $probed_contact["addr"]; + } } logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG); } else @@ -1062,6 +1072,8 @@ function item_content(&$a) { * @return boolean true if replaced, false if not replaced */ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") { + require_once("include/Scrape.php"); + require_once("include/socgraph.php"); $replaced = false; $r = null; @@ -1096,10 +1108,112 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $stat = false; //get the person's name $name = substr($tag,1); + + // Try to detect the contact in various ways + if ((strpos($name,'@')) || (strpos($name,'http://'))) { + // Is it in format @user@domain.tld or @http://domain.tld/...? + + // First check the contact table for the address + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` WHERE `addr` = '%s' AND `uid` = %d LIMIT 1", + dbesc($name), + intval($profile_uid) + ); + + // Then check in the contact table for the url + if (!$r) + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `notify`, `network` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", + dbesc(normalise_link($name)), + intval($profile_uid) + ); + + // Then check in the global contacts for the address + if (!$r) + $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `addr` = '%s' LIMIT 1", dbesc($name)); + + // Then check in the global contacts for the url + if (!$r) + $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($name))); + + // If the data isn't complete then refetch the data + if ($r AND ($r[0]["network"] == NETWORK_OSTATUS) AND (($r[0]["notify"] == "") OR ($r[0]["alias"] == ""))) + $r = false; + + if (!$r) { + $probed = probe_url($name); + if (isset($probed["url"])) { + update_gcontact($probed); + $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($probed["url"]))); + } + } + } elseif (!$r) { + $newname = str_replace('_',' ',$name); + $r = false; + if (strrpos($name,'+')) { + // Is it in format @nick+number? + $tagcid = intval(substr($name,strrpos($name,'+') + 1)); + + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($tagcid), + intval($profile_uid) + ); + } + + //select someone by attag or nick and the name passed in the current network + if(!$r AND ($network != "")) + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", + dbesc($name), + dbesc($name), + dbesc($network), + intval($profile_uid) + ); + + //select someone from this user's contacts by name in the current network + if (!$r AND ($network != "")) + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", + dbesc($newname), + dbesc($network), + intval($profile_uid) + ); + + //select someone by attag or nick and the name passed in + if(!$r) + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", + dbesc($name), + dbesc($name), + intval($profile_uid) + ); + + + //select someone from this user's contacts by name + if(!$r) + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", + dbesc($newname), + intval($profile_uid) + ); + } + + if ($r) { + if(strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) + $inform .= ','; + + if (isset($r[0]["id"])) + $inform .= 'cid:' . $r[0]["id"]; + elseif (isset($r[0]["notify"])) + $inform .= $r[0]["notify"]; + + $profile = $r[0]["url"]; + $alias = $r[0]["alias"]; + $newname = $r[0]["nick"]; + if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER) + AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) + $newname = $r[0]["name"]; + } + +/* //is it a link or a full dfrn address? if((strpos($name,'@')) || (strpos($name,'http://'))) { $newname = $name; - //get the profile links $links = @lrdd($name); if(count($links)) { @@ -1176,6 +1290,8 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); } } +*/ + /* } elseif(strstr($name,'_') || strstr($name,' ')) { //no id //get the real name $newname = str_replace('_',' ',$name); @@ -1192,6 +1308,8 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo intval($profile_uid) ); }*/ + +/* //$r is set, if someone could be selected if(count($r)) { $profile = $r[0]['url']; @@ -1211,29 +1329,10 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $inform .= 'cid:' . $r[0]['id']; } } - - if(!isset($profile)) { - $r = q("SELECT `url` FROM `gcontact` WHERE `addr` = '%s' LIMIT 1", - dbesc($name)); - if ($r) - $profile = $r[0]["url"]; - } - +*/ //if there is an url for this persons profile if(isset($profile)) { - $r = q("SELECT `nick`, `name`, `network` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", - dbesc(normalise_link($profile))); - if ($r) { - $newname = $r[0]["name"]; - - //set newname to nick - if(($r[0]['network'] === NETWORK_OSTATUS) OR ($r[0]['network'] === NETWORK_TWITTER) - OR ($r[0]['network'] === NETWORK_STATUSNET) OR ($r[0]['network'] === NETWORK_APPNET)) { - $newname = $r[0]['nick']; - } - } - $replaced = true; //create profile link $profile = str_replace(',','%2c',$profile); From 358a9fd6fda217a34b2fa589c50c603cb07fc914 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 8 Jan 2016 00:35:46 +0100 Subject: [PATCH 06/17] Notify and alias will be fetched via OStatus --- include/ostatus.php | 15 +++++++++++---- mod/item.php | 9 +++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index c1b823329..05a1efaaa 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -130,6 +130,14 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) if ($r AND !$onlyfetch) { // Update contact data + $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue; + if ($value != "") + $contact["notify"] = $value; + + $value = $xpath->evaluate('atom:author/uri/text()', $context)->item(0)->nodeValue; + if ($value != "") + $contact["alias"] = $value; + $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; if ($value != "") $contact["name"] = $value; @@ -169,10 +177,9 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) } // @todo: Addr - update_gcontact(array("url" => $contact["url"], "network" => $contact["network"], - "photo" => $author["author-avatar"], "name" => $contact["name"], - "nick" => $contact["nick"], "location" => $contact["location"], - "about" => $contact["about"], "generation" => 2)); + $contact["generation"] = 2; + $contact["photo"] = $author["author-avatar"]; + update_gcontact($contact); } return($author); diff --git a/mod/item.php b/mod/item.php index 56c5ccad9..eba8296e7 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1109,6 +1109,11 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo //get the person's name $name = substr($tag,1); + // Sometimes the tag detection doesn't seem to work right + // This is some workaround + $nameparts = explode(" ", $name); + $name = $nameparts[0]; + // Try to detect the contact in various ways if ((strpos($name,'@')) || (strpos($name,'http://'))) { // Is it in format @user@domain.tld or @http://domain.tld/...? @@ -1146,8 +1151,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo dbesc(normalise_link($probed["url"]))); } } - } elseif (!$r) { - $newname = str_replace('_',' ',$name); + } else { $r = false; if (strrpos($name,'+')) { // Is it in format @nick+number? @@ -1330,6 +1334,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo } } */ + //if there is an url for this persons profile if(isset($profile)) { From 6703ba468a02210d9c6f5079933f52919701dcc0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 8 Jan 2016 08:02:42 +0100 Subject: [PATCH 07/17] Profile data in gcontact overwrites profile data --- mod/display.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mod/display.php b/mod/display.php index 6ff599e2c..3a4674c32 100644 --- a/mod/display.php +++ b/mod/display.php @@ -180,21 +180,24 @@ function display_fetchauthor($a, $item) { } // Fetching profile data from global contacts - // @todo: should override everything else (but not Feeds) - $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); - if (count($r)) { - if ($profiledata["photo"] == "") - $profiledata["photo"] = $r[0]["avatar"]; - if (($profiledata["address"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA)) - $profiledata["address"] = $r[0]["location"]; - if (($profiledata["about"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA)) - $profiledata["about"] = $r[0]["about"]; - if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != "")) - $profiledata["nickname"] = $r[0]["nick"]; - if ($profiledata["gender"] == "") - $profiledata["gender"] = $r[0]["gender"]; - if ($profiledata["addr"] == "") - $profiledata["addr"] = $r[0]["addr"]; + if ($profiledata["network"] != NETWORK_FEED) { + $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); + if (count($r)) { + if ($r[0]["avatar"] != "") + $profiledata["photo"] = $r[0]["avatar"]; + if (($r[0]["location"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA)) + $profiledata["address"] = $r[0]["location"]; + if (($r[0]["about"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA)) + $profiledata["about"] = $r[0]["about"]; + if (($r[0]["nick"] != "") AND ($r[0]["nick"] != "")) + $profiledata["nickname"] = $r[0]["nick"]; + if ($r[0]["gender"] != "") + $profiledata["gender"] = $r[0]["gender"]; + if ($r[0]["addr"] != "") + $profiledata["addr"] = $r[0]["addr"]; + if ($r[0]["keywords"] != "") + $profiledata["keywords"] = $r[0]["keywords"]; + } } if (local_user()) { From 885dc1df81c9ab752f9f5d66894786944184a9c9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 09:19:00 +0100 Subject: [PATCH 08/17] gcontact update script, rebuilt follow page, query speedup for community and network groups --- include/Contact.php | 162 ++++++++++++++++++++++++++++++++++++++ include/acl_selectors.php | 15 +++- include/cron.php | 5 +- include/dbstructure.php | 4 +- include/group.php | 17 +++- include/identity.php | 3 + include/threads.php | 2 +- mod/community.php | 9 +-- mod/contacts.php | 43 ++-------- mod/display.php | 59 +++++++------- mod/follow.php | 28 +++++-- mod/network.php | 38 +++++---- view/global.css | 4 + 13 files changed, 287 insertions(+), 102 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 3185e8734..5aaaa11bf 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -500,3 +500,165 @@ function get_contact($url, $uid = 0) { return $contactid; } + +/** + * @brief Returns posts from a given gcontact + * + * @param App $a argv application class + * @param int $gcontact_id Global contact + * + * @return string posts in HTML + */ +function posts_from_gcontact($a, $gcontact_id) { + + require_once('include/conversation.php'); + + // There are no posts with "uid = 0" with connector networks + // This speeds up the query a lot + $r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id)); + if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) + $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))"; + else + $sql = "`item`.`uid` = %d"; + + if(get_config('system', 'old_pager')) { + $r = q("SELECT COUNT(*) AS `total` FROM `item` + WHERE `gcontact-id` = %d and $sql", + intval($gcontact_id), + intval(local_user())); + + $a->set_pager_total($r[0]['total']); + } + + $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, + `author-name` AS `name`, `owner-avatar` AS `photo`, + `owner-link` AS `url`, `owner-avatar` AS `thumb` + FROM `item` + WHERE `gcontact-id` = %d AND $sql AND + NOT `deleted` AND NOT `moderated` AND `visible` + ORDER BY `item`.`created` DESC LIMIT %d, %d", + intval($gcontact_id), + intval(local_user()), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); + + $o = conversation($a,$r,'community',false); + + if(!get_config('system', 'old_pager')) { + $o .= alt_pager($a,count($r)); + } else { + $o .= paginate($a); + } + + return $o; +} + +/** + * @brief set the gcontact-id in all item entries + * + * This job has to be started multiple times until all entries are set. + * It isn't started in the update function since it would consume too much time and can be done in the background. + */ +function item_set_gcontact() { + define ('POST_UPDATE_VERSION', 1192); + + // Was the script completed? + if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION) + return; + + // Check if the first step is done (Setting "gcontact-id" in the item table) + $r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000"); + if (!$r) { + // Are there unfinished entries in the thread table? + $r = q("SELECT COUNT(*) AS `total` FROM `thread` + INNER JOIN `item` ON `item`.`id` =`thread`.`iid` + WHERE `thread`.`gcontact-id` = 0 AND + (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); + + if ($r AND ($r[0]["total"] == 0)) { + set_config("system", "post_update_version", POST_UPDATE_VERSION); + return false; + } + + // Update the thread table from the item table + q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid` + SET `thread`.`gcontact-id` = `item`.`gcontact-id` + WHERE `thread`.`gcontact-id` = 0 AND + (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); + + return false; + } + + $item_arr = array(); + foreach ($r AS $item) { + $index = $item["author-link"]."-".$item["uid"]; + $item_arr[$index] = array("author-link" => $item["author-link"], + "uid" => $item["uid"], + "network" => $item["network"]); + } + + // Set the "gcontact-id" in the item table and add a new gcontact entry if needed + foreach($item_arr AS $item) { + $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'], + "photo" => $item['author-avatar'], "name" => $item['author-name'])); + q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0", + intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"])); + } + return true; +} + +/** + * @brief Returns posts from a given contact + * + * @param App $a argv application class + * @param int $contact_id contact + * + * @return string posts in HTML + */ +function posts_from_contact($a, $contact_id) { + + require_once('include/conversation.php'); + + $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id)); + if (!$r) + return false; + + $contact = $r[0]; + + if(get_config('system', 'old_pager')) { + $r = q("SELECT COUNT(*) AS `total` FROM `item` + WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')", + intval(local_user()), + dbesc(str_replace("https://", "http://", $contact["url"])), + dbesc(str_replace("http://", "https://", $contact["url"]))); + + $a->set_pager_total($r[0]['total']); + } + + $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, + `author-name` AS `name`, `owner-avatar` AS `photo`, + `owner-link` AS `url`, `owner-avatar` AS `thumb` + FROM `item` FORCE INDEX (uid_contactid_created) + WHERE `item`.`uid` = %d AND `contact-id` = %d + AND `author-link` IN ('%s', '%s') + AND NOT `deleted` AND NOT `moderated` AND `visible` + ORDER BY `item`.`created` DESC LIMIT %d, %d", + intval(local_user()), + intval($contact_id), + dbesc(str_replace("https://", "http://", $contact["url"])), + dbesc(str_replace("http://", "https://", $contact["url"])), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); + + $o .= conversation($a,$r,'community',false); + + if(!get_config('system', 'old_pager')) + $o .= alt_pager($a,count($r)); + else + $o .= paginate($a); + + return $o; +} +?> diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 4ef3d05ea..d5730a93a 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -407,7 +407,7 @@ function acl_lookup(&$a, $out_type = 'json') { $search = $_REQUEST['query']; } -// logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG); + logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG); if ($search!=""){ $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'"; @@ -503,7 +503,7 @@ function acl_lookup(&$a, $out_type = 'json') { } } - if ($type=='' || $type=='c'){ + if ($type==''){ $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' @@ -514,6 +514,17 @@ function acl_lookup(&$a, $out_type = 'json') { dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET) ); } + elseif ($type=='c'){ + + $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` + WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + AND NOT (`network` IN ('%s')) + $sql_extra2 + ORDER BY `name` ASC ", + intval(local_user()), + dbesc(NETWORK_STATUSNET) + ); + } elseif($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 diff --git a/include/cron.php b/include/cron.php index a6e81f6bf..b1db9278a 100644 --- a/include/cron.php +++ b/include/cron.php @@ -133,9 +133,8 @@ function cron_run(&$argv, &$argc){ // Check every conversation check_conversations(false); - // Follow your friends from your legacy OStatus account - // Doesn't work - // ostatus_check_follow_friends(); + // Set the gcontact-id in the item table if missing + item_set_gcontact(); // update nodeinfo data nodeinfo_cron(); diff --git a/include/dbstructure.php b/include/dbstructure.php index 4b2cdb251..7fed50e74 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -877,7 +877,7 @@ function db_definition() { "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_created" => array("uid","contact-id","created"), - "uid_gcontactid_created" => array("uid","gcontact-id","created"), + "gcontactid_uid_created" => array("gcontact-id","uid","created"), "wall_body" => array("wall","body(6)"), "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid","uri"), @@ -1324,6 +1324,8 @@ function db_definition() { "uid_network_created" => array("uid","network","created"), "uid_contactid_commented" => array("uid","contact-id","commented"), "uid_contactid_created" => array("uid","contact-id","created"), + "uid_gcontactid_commented" => array("uid","gcontact-id","commented"), + "uid_gcontactid_created" => array("uid","gcontact-id","created"), "wall_private_received" => array("wall","private","received"), "uid_created" => array("uid","created"), "uid_commented" => array("uid","commented"), diff --git a/include/group.php b/include/group.php index fd1c97dfd..a1375e00d 100644 --- a/include/group.php +++ b/include/group.php @@ -297,17 +297,26 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro return $o; } -function expand_groups($a,$check_dead = false) { +function expand_groups($a,$check_dead = false, $use_gcontact = false) { if(! (is_array($a) && count($a))) return array(); $groups = implode(',', $a); $groups = dbesc($groups); - $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )"); + + if ($use_gcontact) + $r = q("SELECT `gcontact`.`id` AS `contact-id` FROM `group_member` + INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` + INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` + WHERE `gid` IN ($groups)"); + else + $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )"); + + $ret = array(); if(count($r)) foreach($r as $rr) $ret[] = $rr['contact-id']; - if($check_dead) { + if($check_dead AND !$use_gcontact) { require_once('include/acl_selectors.php'); $ret = prune_deadguys($ret); } @@ -366,4 +375,4 @@ function groups_count_unseen() { ); return $r; -} \ No newline at end of file +} diff --git a/include/identity.php b/include/identity.php index fb405b90f..fdd28f81c 100644 --- a/include/identity.php +++ b/include/identity.php @@ -300,6 +300,7 @@ function profile_sidebar($profile, $block = 0) { $account_type = ""; if((x($profile,'address') == 1) + || (x($profile,'location') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1) @@ -368,6 +369,8 @@ function profile_sidebar($profile, $block = 0) { if (isset($p["address"])) $p["address"] = bbcode($p["address"]); + else + $p["address"] = bbcode($p["location"]); if (isset($p["photo"])) $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL); diff --git a/include/threads.php b/include/threads.php index a67184659..44a7e6538 100644 --- a/include/threads.php +++ b/include/threads.php @@ -111,7 +111,7 @@ function update_thread_uri($itemuri, $uid) { } function update_thread($itemid, $setmention = false) { - $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, + $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, 'gcontact-id`, `deleted`, `origin`, `forum_mode`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); if (!$items) diff --git a/mod/community.php b/mod/community.php index d6f87762b..86bd18c86 100644 --- a/mod/community.php +++ b/mod/community.php @@ -143,14 +143,13 @@ function community_getpublicitems($start, $itemspage) { $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` WHERE `item`.`uid` = 0 AND `item`.`id` = `item`.`parent` - AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' - AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - ORDER BY `item`.`received` DESC LIMIT %d, %d", + FROM `thread` + INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + WHERE `thread`.`uid` = 0 + ORDER BY `thread`.`created` DESC LIMIT %d, %d", intval($start), intval($itemspage) ); return($r); - } diff --git a/mod/contacts.php b/mod/contacts.php index 0a8aad9d7..ac7c7d85a 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -345,7 +345,6 @@ function _contact_archive($contact_id, $orig_record) { return $r; } function _contact_drop($contact_id, $orig_record) { - require_once('include/Contact.php'); $a = get_app(); terminate_friendship($a->user,$a->contact,$orig_record); @@ -890,50 +889,24 @@ function contacts_tab($a, $contact_id, $active_tab) { function contact_posts($a, $contact_id) { - require_once('include/conversation.php'); - - $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($contact_id)); + $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id)); if ($r) { $contact = $r[0]; $a->page['aside'] = ""; profile_load($a, "", 0, get_contact_details_by_url($contact["url"])); - } - - if(get_config('system', 'old_pager')) { - $r = q("SELECT COUNT(*) AS `total` FROM `item` - WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')", - intval(local_user()), - dbesc(str_replace("https://", "http://", $contact["url"])), - dbesc(str_replace("http://", "https://", $contact["url"]))); - - $a->set_pager_total($r[0]['total']); - } - - $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, - `author-name` AS `name`, `owner-avatar` AS `photo`, - `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` FORCE INDEX (uid_contactid_created) - WHERE `item`.`uid` = %d AND `contact-id` = %d - AND `author-link` IN ('%s', '%s') - ORDER BY `item`.`created` DESC LIMIT %d, %d", - intval(local_user()), - intval($contact_id), - dbesc(str_replace("https://", "http://", $contact["url"])), - dbesc(str_replace("http://", "https://", $contact["url"])), - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); + } else + $profile = ""; $tab_str = contacts_tab($a, $contact_id, 1); $o .= $tab_str; - $o .= conversation($a,$r,'community',false); + if ($contact["url"]) { + $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($contact["url"]))); - if(!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($r)); - } else { - $o .= paginate($a); + if ($r[0]["id"] <> 0) + $o .= posts_from_gcontact($a, $r[0]["id"]); } return $o; diff --git a/mod/display.php b/mod/display.php index 3a4674c32..41cad5c6a 100644 --- a/mod/display.php +++ b/mod/display.php @@ -154,49 +154,48 @@ function display_fetchauthor($a, $item) { $profiledata["about"] = ""; } + // Don't show details from Diaspora contacts if you don't follow the contact + $showdetails = ($profiledata["network"] != NETWORK_DIASPORA); + // Fetching further contact data from the contact table - $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'", - dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"])); - + $r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` + FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)", + dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]), + intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); if (!count($r)) - $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", - dbesc(normalise_link($profiledata["url"])), intval($item["uid"])); - - if (!count($r)) - $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0", - dbesc(normalise_link($profiledata["url"]))); + $r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` + FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)", + dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), + intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); if (count($r)) { - if ((($r[0]["uid"] != local_user()) OR !local_user()) AND ($profiledata["network"] == NETWORK_DIASPORA)) { - $r[0]["location"] = ""; - $r[0]["about"] = ""; - } - $profiledata["photo"] = $r[0]["photo"]; - $profiledata["address"] = $r[0]["location"]; - $profiledata["about"] = $r[0]["about"]; - if ($r[0]["nick"] != "") - $profiledata["nickname"] = $r[0]["nick"]; + $profiledata["nickname"] = $r[0]["nick"]; + $profiledata["addr"] = $r[0]["addr"]; + $profiledata["keywords"] = $r[0]["keywords"]; + + if (($r[0]["uid"] != 0) OR $showdetails) { + $showdetails = true; + $profiledata["address"] = $r[0]["location"]; + $profiledata["about"] = $r[0]["about"]; + $profiledata["gender"] = $r[0]["gender"]; + } } // Fetching profile data from global contacts if ($profiledata["network"] != NETWORK_FEED) { - $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); + $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { - if ($r[0]["avatar"] != "") - $profiledata["photo"] = $r[0]["avatar"]; - if (($r[0]["location"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA)) + $profiledata["photo"] = $r[0]["photo"]; + $profiledata["nickname"] = $r[0]["nick"]; + $profiledata["addr"] = $r[0]["addr"]; + $profiledata["keywords"] = $r[0]["keywords"]; + + if ($showdetails) { $profiledata["address"] = $r[0]["location"]; - if (($r[0]["about"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA)) $profiledata["about"] = $r[0]["about"]; - if (($r[0]["nick"] != "") AND ($r[0]["nick"] != "")) - $profiledata["nickname"] = $r[0]["nick"]; - if ($r[0]["gender"] != "") $profiledata["gender"] = $r[0]["gender"]; - if ($r[0]["addr"] != "") - $profiledata["addr"] = $r[0]["addr"]; - if ($r[0]["keywords"] != "") - $profiledata["keywords"] = $r[0]["keywords"]; + } } } diff --git a/mod/follow.php b/mod/follow.php index cc0883128..b92a0d980 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -2,6 +2,7 @@ require_once('include/Scrape.php'); require_once('include/follow.php'); +require_once('include/Contact.php'); require_once('include/contact_selectors.php'); function follow_content(&$a) { @@ -75,15 +76,18 @@ function follow_content(&$a) { } $myaddr = $r[0]["url"]; + $gcontact_id = 0; // Makes the connection request for friendica contacts easier $_SESSION["fastlane"] = $ret["url"]; - $r = q("SELECT `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", + $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($ret["url"])); if (!$r) $r = array(array("location" => "", "about" => "", "keywords" => "")); + else + $gcontact_id = $r[0]["id"]; if($ret['network'] === NETWORK_DIASPORA) { $r[0]["location"] = ""; @@ -95,11 +99,12 @@ function follow_content(&$a) { if ($ret["addr"] != "") $header .= " <".$ret["addr"].">"; - $header .= " (".network_to_name($ret['network'], $ret['url']).")"; + //$header .= " (".network_to_name($ret['network'], $ret['url']).")"; + $header = t("Connect/Follow"); $o = replace_macros($tpl,array( '$header' => htmlentities($header), - '$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL), + //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL), '$desc' => "", '$pls_answer' => t('Please answer the following:'), '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))), @@ -121,13 +126,26 @@ function follow_content(&$a) { '$url_label' => t("Profile URL"), '$myaddr' => $myaddr, '$request' => $request, - '$location' => bbcode($r[0]["location"]), + /*'$location' => bbcode($r[0]["location"]), '$location_label' => t("Location:"), '$about' => bbcode($r[0]["about"], false, false), - '$about_label' => t("About:"), + '$about_label' => t("About:"), */ '$keywords' => $r[0]["keywords"], '$keywords_label' => t("Tags:") )); + + $a->page['aside'] = ""; + profile_load($a, "", 0, get_contact_details_by_url($ret["url"])); + + // Show last public posts + if ($gcontact_id <> 0) { + $o .= replace_macros(get_markup_template('section_title.tpl'), + array('$title' => t('Status Messages and Posts') + )); + + $o .= posts_from_gcontact($a, $gcontact_id); + } + return $o; } diff --git a/mod/network.php b/mod/network.php index 4b9493bc6..a12fa4ec3 100644 --- a/mod/network.php +++ b/mod/network.php @@ -312,6 +312,9 @@ function network_content(&$a, $update = 0) { return login(false); } + // Rawmode is used for fetching new content at the end of the page + $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")); + /// @TODO Is this really necessary? $a is already available to hooks $arr = array('query' => $a->query_string); call_hooks('network_content_init', $arr); @@ -470,7 +473,7 @@ function network_content(&$a, $update = 0) { } set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all')); - if(! $update) { + if(!$update AND !$rawmode) { if($group) { if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice( sprintf( tt('Warning: This group contains %s member from an insecure network.', @@ -549,27 +552,30 @@ function network_content(&$a, $update = 0) { } $contacts = expand_groups(array($group)); - - $contact_str_self = ""; + $gcontacts = expand_groups(array($group), false, true); if((is_array($contacts)) && count($contacts)) { + $contact_str_self = ""; + $gcontact_str_self = ""; + $contact_str = implode(',',$contacts); - $self = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($_SESSION['uid'])); - if (count($self)) - $contact_str_self = ",".$self[0]["id"]; - } - else { - $contact_str = ' 0 '; + $gcontact_str = implode(',',$gcontacts); + $self = q("SELECT `contact`.`id`, `gcontact`.`id` AS `gid` FROM `contact` + INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` + WHERE `uid` = %d AND `self`", intval($_SESSION['uid'])); + if (count($self)) { + $contact_str_self = $self[0]["id"]; + $gcontact_str_self = $self[0]["gid"]; + } + + $sql_post_table = " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent; + $sql_extra3 .= " AND ($sql_table.`contact-id` IN ($contact_str) "; + $sql_extra3 .= " OR ($sql_table.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))"; + } else { + $sql_extra3 .= " AND false "; info( t('Group is empty')); } - //$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` "; - - $sql_extra3 .= " AND $sql_table.`contact-id` IN ($contact_str$contact_str_self) "; - $sql_extra3 .= " AND EXISTS (SELECT `id` FROM `item` WHERE (`contact-id` IN ($contact_str) - OR `allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."') AND `deleted` = 0 - AND `id` = $sql_table.$sql_parent) "; - $o = replace_macros(get_markup_template("section_title.tpl"),array( '$title' => sprintf( t('Group: %s'), $r[0]['name']) )) . $o; diff --git a/view/global.css b/view/global.css index 05940508c..900df5314 100644 --- a/view/global.css +++ b/view/global.css @@ -321,3 +321,7 @@ ul.credits li { .p-addr { clear: both; } + +#live-community { + clear: both; +} From 214f381e81cfe754c0b1e5e301d297192da83170 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 12:37:49 +0100 Subject: [PATCH 09/17] Code cleanup --- mod/item.php | 121 --------------------------------------------------- 1 file changed, 121 deletions(-) diff --git a/mod/item.php b/mod/item.php index eba8296e7..80a10179e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1214,127 +1214,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $newname = $r[0]["name"]; } -/* - //is it a link or a full dfrn address? - if((strpos($name,'@')) || (strpos($name,'http://'))) { - $newname = $name; - //get the profile links - $links = @lrdd($name); - if(count($links)) { - //for all links, collect how is to inform and how's profile is to link - foreach($links as $link) { - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') - $profile = $link['@attributes']['href']; - if($link['@attributes']['rel'] === 'salmon') { - if(strlen($inform)) - $inform .= ','; - $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']); - } - } - } - } elseif (($network != NETWORK_OSTATUS) AND ($network != NETWORK_TWITTER) AND - ($network != NETWORK_STATUSNET) AND ($network != NETWORK_APPNET)) { - //if it is a name rather than an address - $newname = $name; - $alias = ''; - $tagcid = 0; - //is it some generated name? - if(strrpos($newname,'+')) { - //get the id - $tagcid = intval(substr($newname,strrpos($newname,'+') + 1)); - //remove the next word from tag's name - if(strpos($name,' ')) { - $name = substr($name,0,strpos($name,' ')); - } - } - if($tagcid) { //if there was an id - //select contact with that id from the logged in user's contact list - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($tagcid), - intval($profile_uid) - ); - } - else { - $newname = str_replace('_',' ',$name); - - // At first try to fetch a contact according to the given network - if ($network != "") { - //select someone from this user's contacts by name - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - dbesc($network), - intval($profile_uid) - ); - if(! $r) { - //select someone by attag or nick and the name passed in - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - dbesc($network), - intval($profile_uid) - ); - } - } else - $r = false; - - if(! $r) { - //select someone from this user's contacts by name - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval($profile_uid) - ); - } - - if(! $r) { - //select someone by attag or nick and the name passed in - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($profile_uid) - ); - } - } -*/ - -/* } elseif(strstr($name,'_') || strstr($name,' ')) { //no id - //get the real name - $newname = str_replace('_',' ',$name); - //select someone from this user's contacts by name - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval($profile_uid) - ); - } else { - //select someone by attag or nick and the name passed in - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($profile_uid) - ); - }*/ - -/* - //$r is set, if someone could be selected - if(count($r)) { - $profile = $r[0]['url']; - //set newname to nick, find alias - if(($r[0]['network'] === NETWORK_OSTATUS) OR ($r[0]['network'] === NETWORK_TWITTER) - OR ($r[0]['network'] === NETWORK_STATUSNET) OR ($r[0]['network'] === NETWORK_APPNET)) { - $newname = $r[0]['nick']; - $stat = true; - if($r[0]['alias']) - $alias = $r[0]['alias']; - } - else - $newname = $r[0]['name']; - //add person's id to $inform - if(strlen($inform)) - $inform .= ','; - $inform .= 'cid:' . $r[0]['id']; - } - } -*/ - //if there is an url for this persons profile if(isset($profile)) { From 2f49e984bd3556338ad934ba821dfe9bd56b6636 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 14:12:05 +0100 Subject: [PATCH 10/17] Updated database.sql file, further code cleanup --- database.sql | 6 +++++- mod/network.php | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index 4e6f3d35c..df5ec74e2 100644 --- a/database.sql +++ b/database.sql @@ -338,6 +338,8 @@ CREATE TABLE IF NOT EXISTS `gcontact` ( `nsfw` tinyint(1) NOT NULL DEFAULT 0, `network` varchar(255) NOT NULL DEFAULT '', `addr` varchar(255) NOT NULL DEFAULT '', + `notify` text NOT NULL, + `alias` varchar(255) NOT NULL DEFAULT '', `generation` tinyint(3) NOT NULL DEFAULT 0, `server_url` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY(`id`), @@ -539,7 +541,7 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uid_thrparent` (`uid`,`thr-parent`), INDEX `uid_parenturi` (`uid`,`parent-uri`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), - INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`), + INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`), INDEX `wall_body` (`wall`,`body`(6)), INDEX `uid_visible_moderated_created` (`uid`,`visible`,`moderated`,`created`), INDEX `uid_uri` (`uid`,`uri`), @@ -986,6 +988,8 @@ CREATE TABLE IF NOT EXISTS `thread` ( INDEX `uid_network_created` (`uid`,`network`,`created`), INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`), INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), + INDEX `uid_gcontactid_commented` (`uid`,`gcontact-id`,`commented`), + INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`), INDEX `wall_private_received` (`wall`,`private`,`received`), INDEX `uid_created` (`uid`,`created`), INDEX `uid_commented` (`uid`,`commented`) diff --git a/mod/network.php b/mod/network.php index a12fa4ec3..3317dc684 100644 --- a/mod/network.php +++ b/mod/network.php @@ -588,10 +588,6 @@ function network_content(&$a, $update = 0) { intval($cid) ); if(count($r)) { - //$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` - // WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." AND `deleted` = 0 - // ORDER BY `item`.`received` DESC) AS `temp1` - // ON $sql_table.$sql_parent = `temp1`.`parent` "; $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid); $entries[0] = array( From 23731fc9aafb5625c4a3a8e714a77711b84a3a96 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 15:44:23 +0100 Subject: [PATCH 11/17] Bugfix: The display hadn't fetched the correct contact for the uid. --- include/bbcode.php | 20 ++++++++++++++++++-- mod/display.php | 16 ++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index b68a7c5b1..6a44e19ec 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -3,6 +3,7 @@ require_once("include/oembed.php"); require_once('include/event.php'); require_once('include/map.php'); require_once('mod/proxy.php'); +require_once('include/Contact.php'); function bb_PictureCacheExt($matches) { if (strpos($matches[3], "data:image/") === 0) @@ -541,8 +542,23 @@ function bb_ShareAttributes($share, $simplehtml) { $reldate = (($posted) ? " " . relative_date($posted) : ''); } - $userid = GetProfileUsername($profile,$author, false); - $userid_compact = GetProfileUsername($profile,$author, true); + $data = get_contact_details_by_url($profile); + + if (isset($data["name"]) AND isset($data["addr"])) + $userid_compact = $data["name"]." (".$data["addr"].")"; + else + $userid_compact = GetProfileUsername($profile,$author, true); + + if (isset($data["addr"])) + $userid = $data["addr"]; + else + $userid = GetProfileUsername($profile,$author, false); + + if (isset($data["name"])) + $author = $data["name"]; + + if (isset($data["photo"])) + $avatar = $data["photo"]; $preshare = trim($share[1]); diff --git a/mod/display.php b/mod/display.php index 41cad5c6a..c41d2f045 100644 --- a/mod/display.php +++ b/mod/display.php @@ -158,23 +158,25 @@ function display_fetchauthor($a, $item) { $showdetails = ($profiledata["network"] != NETWORK_DIASPORA); // Fetching further contact data from the contact table - $r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` + $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)", - dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]), + dbesc(normalise_link($profiledata["url"])), intval(local_user()), dbesc($item["network"]), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); if (!count($r)) - $r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` + $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)", - dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), + dbesc(normalise_link($profiledata["url"])), intval(local_user()), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); if (count($r)) { + $profiledata["name"] = $r[0]["name"]; $profiledata["photo"] = $r[0]["photo"]; $profiledata["nickname"] = $r[0]["nick"]; $profiledata["addr"] = $r[0]["addr"]; $profiledata["keywords"] = $r[0]["keywords"]; + $profiledata["network"] = $r[0]["network"]; - if (($r[0]["uid"] != 0) OR $showdetails) { + if (local_user() OR $showdetails) { $showdetails = true; $profiledata["address"] = $r[0]["location"]; $profiledata["about"] = $r[0]["about"]; @@ -184,12 +186,14 @@ function display_fetchauthor($a, $item) { // Fetching profile data from global contacts if ($profiledata["network"] != NETWORK_FEED) { - $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); + $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { + $profiledata["name"] = $r[0]["name"]; $profiledata["photo"] = $r[0]["photo"]; $profiledata["nickname"] = $r[0]["nick"]; $profiledata["addr"] = $r[0]["addr"]; $profiledata["keywords"] = $r[0]["keywords"]; + $profiledata["network"] = $r[0]["network"]; if ($showdetails) { $profiledata["address"] = $r[0]["location"]; From b4631cebed8acfac5c2e7329b2fb76324f734d9b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 17:10:56 +0100 Subject: [PATCH 12/17] Fixed SQL problems --- include/threads.php | 2 +- mod/network.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/threads.php b/include/threads.php index 44a7e6538..dddcc4cdd 100644 --- a/include/threads.php +++ b/include/threads.php @@ -111,7 +111,7 @@ function update_thread_uri($itemuri, $uid) { } function update_thread($itemid, $setmention = false) { - $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, 'gcontact-id`, + $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, `deleted`, `origin`, `forum_mode`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); if (!$items) diff --git a/mod/network.php b/mod/network.php index 3317dc684..a07c5868e 100644 --- a/mod/network.php +++ b/mod/network.php @@ -670,7 +670,7 @@ function network_content(&$a, $update = 0) { } if($conv) - $sql_extra3 .= " AND `mention`"; + $sql_extra3 .= " AND $sql_table.`mention`"; if($update) { From 6b85fa17bbc187604001df799dfabab7f0656819 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 19:06:34 +0100 Subject: [PATCH 13/17] Added some documentation --- include/Contact.php | 4 ++-- include/socgraph.php | 42 +++++++++++++++++++++++++++++++++++------- mod/contacts.php | 4 +++- mod/display.php | 2 +- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 5aaaa11bf..81692fa84 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -533,7 +533,7 @@ function posts_from_gcontact($a, $gcontact_id) { $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` + FROM `item` FORCE INDEX (`gcontactid_uid_created`) WHERE `gcontact-id` = %d AND $sql AND NOT `deleted` AND NOT `moderated` AND `visible` ORDER BY `item`.`created` DESC LIMIT %d, %d", @@ -639,7 +639,7 @@ function posts_from_contact($a, $contact_id) { $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` FORCE INDEX (uid_contactid_created) + FROM `item` FORCE INDEX (`uid_contactid_created`) WHERE `item`.`uid` = %d AND `contact-id` = %d AND `author-link` IN ('%s', '%s') AND NOT `deleted` AND NOT `moderated` AND `visible` diff --git a/include/socgraph.php b/include/socgraph.php index 0082cb43b..00fc439b7 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1507,6 +1507,12 @@ function poco_discover_server($data, $default_generation = 0) { return $success; } +/** + * @brief Fetch the gcontact id, add an entry if not existed + * + * @param arr $contact contact array + * @return bool|int Returns false if not found, integer if contact was found + */ function get_gcontact_id($contact) { $gcontact_id = 0; @@ -1546,6 +1552,12 @@ function get_gcontact_id($contact) { return $gcontact_id; } +/** + * @brief Updates the gcontact table from a given array + * + * @param arr $contact contact array + * @return bool|int Returns false if not found, integer if contact was found + */ function update_gcontact($contact) { $gcontact_id = get_gcontact_id($contact); @@ -1553,7 +1565,7 @@ function update_gcontact($contact) { if (!$gcontact_id) return false; - $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network`, `alias`, `notify` + $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network`, `alias`, `notify`, `url` FROM `gcontact` WHERE `id` = %d LIMIT 1", intval($gcontact_id)); @@ -1599,6 +1611,9 @@ function update_gcontact($contact) { if ($contact["alias"] =="") $contact["alias"] = $r[0]["alias"]; + if ($contact["url"] =="") + $contact["url"] = $r[0]["url"]; + if ($contact["notify"] =="") $contact["notify"] = $r[0]["notify"]; @@ -1608,22 +1623,35 @@ function update_gcontact($contact) { if (($contact["photo"] != $r[0]["photo"]) OR ($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["addr"] != $r[0]["addr"]) OR ($contact["birthday"] != $r[0]["birthday"]) OR ($contact["gender"] != $r[0]["gender"]) OR ($contact["keywords"] != $r[0]["keywords"]) OR ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR ($contact["network"] != $r[0]["network"]) OR - ($contact["alias"] != $r[0]["alias"]) OR ($contact["notify"] != $r[0]["notify"]) OR + ($contact["alias"] != $r[0]["alias"]) OR ($contact["notify"] != $r[0]["notify"]) OR ($contact["url"] != $r[0]["url"]) OR ($contact["location"] != $r[0]["location"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["generation"] < $r[0]["generation"])) { q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, - `alias` = '%s', `notify` = '%s', + `alias` = '%s', `notify` = '%s', `url` = '%s', `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s' WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), - dbesc($contact["addr"]), dbesc($contact["network"]), - dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), - intval($contact["hide"]), intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), - dbesc($contact["location"]), dbesc($contact["about"]), intval($contact["generation"]), dbesc(datetime_convert()), + dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), + dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), + intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), + dbesc($contact["url"]), dbesc($contact["location"]), dbesc($contact["about"]), + intval($contact["generation"]), dbesc(datetime_convert()), dbesc(normalise_link($contact["url"])), intval($contact["generation"])); } return $gcontact_id; } + +/** + * @brief Updates the gcontact entry from probe + * + * @param str $url profile link + */ +function update_gcontact_from_probe($url) { + $data = probe_url($url); + + if ($data["network"] != NETWORK_PHANTOM) + update_gcontact($data); +} ?> diff --git a/mod/contacts.php b/mod/contacts.php index ac7c7d85a..f83b1b5da 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -302,7 +302,7 @@ function _contact_update_profile($contact_id) { `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", - dbesc($photos[0]), + dbesc($data["photo"]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), @@ -311,6 +311,8 @@ function _contact_update_profile($contact_id) { intval($contact_id) ); + // Update the entry in the gcontact table + update_gcontact_from_probe($data["url"]); } function _contact_block($contact_id, $orig_record) { diff --git a/mod/display.php b/mod/display.php index c41d2f045..c53e92d05 100644 --- a/mod/display.php +++ b/mod/display.php @@ -186,7 +186,7 @@ function display_fetchauthor($a, $item) { // Fetching profile data from global contacts if ($profiledata["network"] != NETWORK_FEED) { - $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); + $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`, `network` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"]))); if (count($r)) { $profiledata["name"] = $r[0]["name"]; $profiledata["photo"] = $r[0]["photo"]; From 941b5fd11e7a7abe83940edfa5cfe74e1920c957 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 11 Jan 2016 14:24:54 +0100 Subject: [PATCH 14/17] Some added logging --- include/diaspora.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 59c1ac5a2..1cf8897af 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2640,11 +2640,12 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } logger('diaspora_send_status: '.$owner['username'].' -> '.$contact['name'].' base message: '.$msg, LOGGER_DATA); + logger('send guid '.$item['guid'], LOGGER_DEBUG); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); - $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch); + $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']); logger('diaspora_send_status: guid: '.$item['guid'].' result '.$return_code, LOGGER_DEBUG); @@ -2755,10 +2756,12 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); + logger('send guid '.$r[0]['guid'], LOGGER_DEBUG); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); - diaspora_transmit($owner,$contact,$slap,$public_batch); + diaspora_transmit($owner,$contact,$slap,$public_batch,false,$r[0]['guid']); } } @@ -2829,11 +2832,12 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { )); logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA); + logger('send guid '.$item['guid'], LOGGER_DEBUG); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); - return(diaspora_transmit($owner,$contact,$slap,$public_batch)); + return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid'])); } @@ -2965,12 +2969,12 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { )); logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA); - + logger('send guid '.$item['guid'], LOGGER_DEBUG); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); - return(diaspora_transmit($owner,$contact,$slap,$public_batch)); + return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid'])); } @@ -3002,10 +3006,12 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { '$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'))) )); + logger('send guid '.$item['guid'], LOGGER_DEBUG); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); - return(diaspora_transmit($owner,$contact,$slap,$public_batch)); + return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid'])); } function diaspora_send_mail($item,$owner,$contact) { @@ -3062,16 +3068,17 @@ function diaspora_send_mail($item,$owner,$contact) { } logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA); + logger('send guid '.$item['guid'], LOGGER_DEBUG); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false))); //$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)); - return(diaspora_transmit($owner,$contact,$slap,false)); + return(diaspora_transmit($owner,$contact,$slap,false,false,$item['guid'])); } -function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) { +function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false,$guid = "") { $enabled = intval(get_config('system','diaspora_enabled')); if(! $enabled) { @@ -3084,9 +3091,9 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) if(! $dest_url) { logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch); return 0; - } + } - logger('diaspora_transmit: ' . $logid . ' ' . $dest_url); + logger('diaspora_transmit: '.$logid.'-'.$guid.' '.$dest_url); if( (! $queue_run) && (was_recently_delayed($contact['id'])) ) { $return_code = 0; @@ -3101,7 +3108,7 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) } } - logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code); + logger('diaspora_transmit: '.$logid.'-'.$guid.' returns: '.$return_code); if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) { logger('diaspora_transmit: queue message'); From 012107f5f775de6fe87d8c8d37e797d2316758c5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 11 Jan 2016 20:17:31 +0100 Subject: [PATCH 15/17] Table documentation added --- doc/database/db_gcontact.md | 5 ++++ doc/database/db_item.md | 1 + doc/database/db_thread.md | 51 +++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/doc/database/db_gcontact.md b/doc/database/db_gcontact.md index 8e9de43c9..c47e72622 100644 --- a/doc/database/db_gcontact.md +++ b/doc/database/db_gcontact.md @@ -18,9 +18,14 @@ Table gcontact | about | | text | NO | | NULL | | | keywords | puplic keywords (interests) | text | NO | | NULL | | | gender | | varchar(32) | NO | | | | +| birthday | | varchar(32) | NO | | 0000-00-00 | | | community | 1 if contact is forum account | tinyint(1) | NO | | 0 | | +| hide | 1 = should be hidden from search | tinyint(1) | NO | | 0 | | +| nsfw | 1 = contact posts nsfw content | tinyint(1) | NO | | 0 | | | network | social network protocol | varchar(255) | NO | | | | | addr | | varchar(255) | NO | | | | +| notify | | text | NO | | | | +| alias | | varchar(255) | NO | | | | | generation | | tinyint(3) | NO | | 0 | | | server_url | baseurl of the contacts server | varchar(255) | NO | | | | diff --git a/doc/database/db_item.md b/doc/database/db_item.md index 3ed986a78..00fa213c8 100644 --- a/doc/database/db_item.md +++ b/doc/database/db_item.md @@ -8,6 +8,7 @@ Table item | uri | | varchar(255) | NO | MUL | | | | uid | user.id which owns this copy of the item | int(10) unsigned | NO | MUL | 0 | | | contact-id | contact.id | int(11) | NO | MUL | 0 | | +| gcontact-id | ID of the global contact | int(11) | NO | MUL | 0 | | | type | | varchar(255) | NO | | | | | wall | This item was posted to the wall of uid | tinyint(1) | NO | MUL | 0 | | | gravity | | tinyint(1) | NO | | 0 | | diff --git a/doc/database/db_thread.md b/doc/database/db_thread.md index 78af5cb37..4c912bec1 100644 --- a/doc/database/db_thread.md +++ b/doc/database/db_thread.md @@ -1,30 +1,31 @@ Table thread ============ -| Field | Description | Type | Null | Key | Default | Extra | -|------------|------------------|------------------|------|-----|---------------------|-------| -| iid | sequential ID | int(10) unsigned | NO | PRI | 0 | | -| uid | | int(10) unsigned | NO | MUL | 0 | | -| contact-id | | int(11) unsigned | NO | | 0 | | -| created | | datetime | NO | MUL | 0000-00-00 00:00:00 | | -| edited | | datetime | NO | | 0000-00-00 00:00:00 | | -| commented | | datetime | NO | MUL | 0000-00-00 00:00:00 | | -| received | | datetime | NO | | 0000-00-00 00:00:00 | | -| changed | | datetime | NO | | 0000-00-00 00:00:00 | | -| wall | | tinyint(1) | NO | MUL | 0 | | -| private | | tinyint(1) | NO | | 0 | | -| pubmail | | tinyint(1) | NO | | 0 | | -| moderated | | tinyint(1) | NO | | 0 | | -| visible | | tinyint(1) | NO | | 0 | | -| spam | | tinyint(1) | NO | | 0 | | -| starred | | tinyint(1) | NO | | 0 | | -| ignored | | tinyint(1) | NO | | 0 | | -| bookmark | | tinyint(1) | NO | | 0 | | -| unseen | | tinyint(1) | NO | | 1 | | -| deleted | | tinyint(1) | NO | | 0 | | -| origin | | tinyint(1) | NO | | 0 | | -| forum_mode | | tinyint(1) | NO | | 0 | | -| mention | | tinyint(1) | NO | | 0 | | -| network | | varchar(32) | NO | | | | +| Field | Description | Type | Null | Key | Default | Extra | +|-------------|------------------|------------------|------|-----|---------------------|-------| +| iid | sequential ID | int(10) unsigned | NO | PRI | 0 | | +| uid | | int(10) unsigned | NO | MUL | 0 | | +| contact-id | | int(11) unsigned | NO | | 0 | | +| gcontact-id | Global Contact | int(11) unsigned | NO | | 0 | | +| created | | datetime | NO | MUL | 0000-00-00 00:00:00 | | +| edited | | datetime | NO | | 0000-00-00 00:00:00 | | +| commented | | datetime | NO | MUL | 0000-00-00 00:00:00 | | +| received | | datetime | NO | | 0000-00-00 00:00:00 | | +| changed | | datetime | NO | | 0000-00-00 00:00:00 | | +| wall | | tinyint(1) | NO | MUL | 0 | | +| private | | tinyint(1) | NO | | 0 | | +| pubmail | | tinyint(1) | NO | | 0 | | +| moderated | | tinyint(1) | NO | | 0 | | +| visible | | tinyint(1) | NO | | 0 | | +| spam | | tinyint(1) | NO | | 0 | | +| starred | | tinyint(1) | NO | | 0 | | +| ignored | | tinyint(1) | NO | | 0 | | +| bookmark | | tinyint(1) | NO | | 0 | | +| unseen | | tinyint(1) | NO | | 1 | | +| deleted | | tinyint(1) | NO | | 0 | | +| origin | | tinyint(1) | NO | | 0 | | +| forum_mode | | tinyint(1) | NO | | 0 | | +| mention | | tinyint(1) | NO | | 0 | | +| network | | varchar(32) | NO | | | | Return to [database documentation](help/database) From d1d7ab799c2237fc6df7e94bcb78cd773c53c442 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 11 Jan 2016 20:21:42 +0100 Subject: [PATCH 16/17] Added some more documentation --- include/ostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 05a1efaaa..b7799fa9d 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -176,7 +176,7 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); } - // @todo: Addr + /// @todo Add the "addr" field $contact["generation"] = 2; $contact["photo"] = $author["author-avatar"]; update_gcontact($contact); From 86da77e8ee7da6682e16a282d57b36e8d2cefeff Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 13 Jan 2016 10:53:38 +0100 Subject: [PATCH 17/17] Added two to-dos to do. --- include/Contact.php | 1 + include/socgraph.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/Contact.php b/include/Contact.php index 81692fa84..c10bb9b79 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -402,6 +402,7 @@ function get_contact($url, $uid = 0) { $contactid = 0; // is it an address in the format user@server.tld? + /// @todo use gcontact and/or the addr field for a lookup if (!strstr($url, "http") OR strstr($url, "@")) { $data = probe_url($url); $url = $data["url"]; diff --git a/include/socgraph.php b/include/socgraph.php index 00fc439b7..a01c9c5cb 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1560,6 +1560,8 @@ function get_gcontact_id($contact) { */ function update_gcontact($contact) { + /// @todo update contact table as well + $gcontact_id = get_gcontact_id($contact); if (!$gcontact_id)