Browse Source

Merge pull request #2244 from annando/1601-gcontact-total

Global contacts are now playing a central role
pull/2251/head
fabrixxm 5 years ago
parent
commit
f4173d1764
32 changed files with 927 additions and 561 deletions
  1. +1
    -1
      boot.php
  2. +132
    -84
      database.sql
  3. +0
    -1
      doc/database.md
  4. +5
    -0
      doc/database/db_gcontact.md
  5. +1
    -0
      doc/database/db_item.md
  6. +26
    -25
      doc/database/db_thread.md
  7. +0
    -14
      doc/database/db_unique_contacts.md
  8. +0
    -29
      friendica_test_data.sql
  9. +163
    -13
      include/Contact.php
  10. +13
    -2
      include/acl_selectors.php
  11. +25
    -71
      include/api.php
  12. +18
    -2
      include/bbcode.php
  13. +2
    -3
      include/cron.php
  14. +10
    -15
      include/dbstructure.php
  15. +37
    -33
      include/diaspora.php
  16. +13
    -4
      include/group.php
  17. +3
    -0
      include/identity.php
  18. +4
    -0
      include/items.php
  19. +37
    -22
      include/ostatus.php
  20. +201
    -26
      include/socgraph.php
  21. +2
    -2
      include/threads.php
  22. +1
    -1
      mod/admin.php
  23. +4
    -5
      mod/community.php
  24. +11
    -36
      mod/contacts.php
  25. +11
    -5
      mod/dirfind.php
  26. +38
    -27
      mod/display.php
  27. +23
    -5
      mod/follow.php
  28. +115
    -108
      mod/item.php
  29. +24
    -22
      mod/network.php
  30. +2
    -4
      mod/poco.php
  31. +1
    -1
      update.php
  32. +4
    -0
      view/global.css

+ 1
- 1
boot.php View File

@ -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.


+ 132
- 84
database.sql View File

@ -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 '',
@ -315,11 +332,17 @@ 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,
`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`),
INDEX `nurl` (`nurl`),
INDEX `updated` (`updated`)
) DEFAULT CHARSET=utf8;
@ -328,12 +351,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 +367,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 +380,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 +392,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 +407,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 +415,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 +430,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 +443,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 +453,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 +524,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`),
@ -509,6 +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 `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`),
@ -531,11 +564,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 +580,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 +608,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 +621,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 +633,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 +652,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 +667,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 +675,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 +689,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 +702,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 +724,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 +734,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 +746,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 +754,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 +766,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 +807,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 +815,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 +862,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 +887,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 +900,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 +915,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 +932,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 +944,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 +957,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,12 +981,15 @@ 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`),
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`)
@ -941,33 +999,20 @@ 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
) DEFAULT CHARSET=utf8;
--
-- TABLE unique_contacts
--
CREATE TABLE IF NOT EXISTS `unique_contacts` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`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,
INDEX `url` (`url`)
`uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- 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 +1054,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 +1062,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 +1072,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;

+ 0
- 1
doc/database.md View File

@ -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) | |

+ 5
- 0
doc/database/db_gcontact.md View File

@ -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 | | | |


+ 1
- 0
doc/database/db_item.md View File

@ -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 | |


+ 26
- 25
doc/database/db_thread.md View File

@ -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)

+ 0
- 14
doc/database/db_unique_contacts.md View File

@ -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)

+ 0
- 29
friendica_test_data.sql View File

@ -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`
--


+ 163
- 13
include/Contact.php View File

@ -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
@ -415,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"];
@ -513,3 +501,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` 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",
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;
}
?>

+ 13
- 2
include/acl_selectors.php View File

@ -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


+ 25
- 71
include/api.php View File

@ -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'])));
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]["