diff --git a/database.sql b/database.sql
index d7772920d8..f5db49600d 100644
--- a/database.sql
+++ b/database.sql
@@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2020.06-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1338
+-- DB_UPDATE_VERSION 1340
-- ------------------------------------------
@@ -1175,6 +1175,31 @@ CREATE TABLE IF NOT EXISTS `term` (
INDEX `guid` (`guid`(64))
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='item taxonomy (categories, tags, etc.) table';
+--
+-- TABLE tag
+--
+CREATE TABLE IF NOT EXISTS `tag` (
+ `id` int unsigned NOT NULL auto_increment COMMENT '',
+ `name` varchar(96) NOT NULL DEFAULT '' COMMENT '',
+ `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '',
+ PRIMARY KEY(`id`),
+ UNIQUE INDEX `type_name_url` (`name`,`url`),
+ INDEX `url` (`url`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
+
+--
+-- TABLE post-tag
+--
+CREATE TABLE IF NOT EXISTS `post-tag` (
+ `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+ `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+ `tid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
+ `cid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Contact id of the mentioned public contact',
+ PRIMARY KEY(`uri-id`,`type`,`tid`,`cid`),
+ INDEX `uri-id` (`tid`),
+ INDEX `cid` (`tid`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to tags';
+
--
-- TABLE thread
--
@@ -1361,4 +1386,163 @@ CREATE TABLE IF NOT EXISTS `storage` (
PRIMARY KEY(`id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Data stored by Database storage backend';
+--
+-- VIEW tag-view
+--
+DROP VIEW IF EXISTS `tag-view`;
+CREATE VIEW `tag-view` AS SELECT
+ `post-tag`.`uri-id` AS `uri-id`,
+ `item-uri`.`uri` AS `uri`,
+ `item-uri`.`guid` AS `guid`,
+ `post-tag`.`type` AS `type`,
+ `post-tag`.`tid` AS `tid`,
+ `post-tag`.`cid` AS `cid`,
+ CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END AS `name`,
+ CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END AS `url`
+ FROM `post-tag`
+ INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
+ LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
+ LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
+
+--
+-- VIEW owner-view
+--
+DROP VIEW IF EXISTS `owner-view`;
+CREATE VIEW `owner-view` AS SELECT
+ `contact`.`id` AS `id`,
+ `contact`.`uid` AS `uid`,
+ `contact`.`created` AS `created`,
+ `contact`.`updated` AS `updated`,
+ `contact`.`self` AS `self`,
+ `contact`.`remote_self` AS `remote_self`,
+ `contact`.`rel` AS `rel`,
+ `contact`.`duplex` AS `duplex`,
+ `contact`.`network` AS `network`,
+ `contact`.`protocol` AS `protocol`,
+ `contact`.`name` AS `name`,
+ `contact`.`nick` AS `nick`,
+ `contact`.`location` AS `location`,
+ `contact`.`about` AS `about`,
+ `contact`.`keywords` AS `keywords`,
+ `contact`.`gender` AS `gender`,
+ `profile`.`xmpp` AS `xmpp`,
+ `contact`.`attag` AS `attag`,
+ `contact`.`avatar` AS `avatar`,
+ `contact`.`photo` AS `photo`,
+ `contact`.`thumb` AS `thumb`,
+ `contact`.`micro` AS `micro`,
+ `contact`.`site-pubkey` AS `site-pubkey`,
+ `contact`.`issued-id` AS `issued-id`,
+ `contact`.`dfrn-id` AS `dfrn-id`,
+ `contact`.`url` AS `url`,
+ `contact`.`nurl` AS `nurl`,
+ `contact`.`addr` AS `addr`,
+ `contact`.`alias` AS `alias`,
+ `contact`.`pubkey` AS `pubkey`,
+ `contact`.`prvkey` AS `prvkey`,
+ `contact`.`batch` AS `batch`,
+ `contact`.`request` AS `request`,
+ `contact`.`notify` AS `notify`,
+ `contact`.`poll` AS `poll`,
+ `contact`.`confirm` AS `confirm`,
+ `contact`.`poco` AS `poco`,
+ `contact`.`aes_allow` AS `aes_allow`,
+ `contact`.`ret-aes` AS `ret-aes`,
+ `contact`.`usehub` AS `usehub`,
+ `contact`.`subhub` AS `subhub`,
+ `contact`.`hub-verify` AS `hub-verify`,
+ `contact`.`last-update` AS `last-update`,
+ `contact`.`success_update` AS `success_update`,
+ `contact`.`failure_update` AS `failure_update`,
+ `contact`.`name-date` AS `name-date`,
+ `contact`.`uri-date` AS `uri-date`,
+ `contact`.`avatar-date` AS `avatar-date`,
+ `contact`.`id` AS `contact_id`,
+ `contact`.`avatar-date` AS `picdate`,
+ `contact`.`term-date` AS `term-date`,
+ `contact`.`last-item` AS `last-item`,
+ `contact`.`last-item` AS `lastitem_date`,
+ `contact`.`priority` AS `priority`,
+ `contact`.`blocked` AS `blocked`,
+ `contact`.`block_reason` AS `block_reason`,
+ `contact`.`readonly` AS `readonly`,
+ `contact`.`writable` AS `writable`,
+ `contact`.`forum` AS `forum`,
+ `contact`.`prv` AS `prv`,
+ `contact`.`contact-type` AS `contact-type`,
+ `contact`.`hidden` AS `hidden`,
+ `contact`.`archive` AS `archive`,
+ `contact`.`pending` AS `pending`,
+ `contact`.`deleted` AS `deleted`,
+ `contact`.`rating` AS `rating`,
+ `contact`.`unsearchable` AS `unsearchable`,
+ `contact`.`sensitive` AS `sensitive`,
+ `contact`.`baseurl` AS `baseurl`,
+ `contact`.`reason` AS `reason`,
+ `contact`.`closeness` AS `closeness`,
+ `contact`.`info` AS `info`,
+ `contact`.`profile-id` AS `profile-id`,
+ `contact`.`bdyear` AS `bdyear`,
+ `contact`.`bd` AS `bd`,
+ `user`.`guid` AS `guid`,
+ `user`.`theme` AS `theme`,
+ `user`.`language` AS `language`,
+ `user`.`email` AS `email`,
+ `user`.`prvkey` AS `uprvkey`,
+ `user`.`pubkey` AS `upubkey`,
+ `user`.`timezone` AS `timezone`,
+ `user`.`nickname` AS `nickname`,
+ `user`.`username` AS `username`,
+ `user`.`sprvkey` AS `sprvkey`,
+ `user`.`spubkey` AS `spubkey`,
+ `user`.`page-flags` AS `page-flags`,
+ `user`.`account-type` AS `account-type`,
+ `user`.`prvnets` AS `prvnets`,
+ `user`.`account_removed` AS `account_removed`,
+ `user`.`hidewall` AS `hidewall`,
+ `user`.`login_date` AS `login_date`,
+ `user`.`register_date` AS `register_date`,
+ `user`.`verified` AS `verified`,
+ `user`.`expire` AS `expire`,
+ `user`.`expire_notification_sent` AS `expire_notification_sent`,
+ `user`.`account_expired` AS `account_expired`,
+ `user`.`account_expires_on` AS `account_expires_on`,
+ `profile`.`publish` AS `publish`,
+ `profile`.`net-publish` AS `net-publish`,
+ `profile`.`hide-friends` AS `hide-friends`,
+ `profile`.`prv_keywords` AS `prv_keywords`,
+ `profile`.`pub_keywords` AS `pub_keywords`,
+ `profile`.`address` AS `address`,
+ `profile`.`locality` AS `locality`,
+ `profile`.`region` AS `region`,
+ `profile`.`postal-code` AS `postal-code`,
+ `profile`.`country-name` AS `country-name`,
+ `profile`.`homepage` AS `homepage`,
+ `profile`.`dob` AS `dob`
+ FROM `user`
+ INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
+ INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`;
+
+--
+-- VIEW pending-view
+--
+DROP VIEW IF EXISTS `pending-view`;
+CREATE VIEW `pending-view` AS SELECT
+ `register`.`id` AS `id`,
+ `register`.`hash` AS `hash`,
+ `register`.`created` AS `created`,
+ `register`.`uid` AS `uid`,
+ `register`.`password` AS `password`,
+ `register`.`language` AS `language`,
+ `register`.`note` AS `note`,
+ `contact`.`self` AS `self`,
+ `contact`.`name` AS `name`,
+ `contact`.`url` AS `url`,
+ `contact`.`micro` AS `micro`,
+ `user`.`email` AS `email`,
+ `contact`.`nick` AS `nick`
+ FROM `register`
+ INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
+ INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
+
diff --git a/mod/display.php b/mod/display.php
index 107e666d48..a06d8a7239 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -116,11 +116,7 @@ function display_init(App $a)
$nickname = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/profile/', '', Strings::normaliseLink($profiledata['url']));
if (!empty($a->user['nickname']) && $nickname != $a->user['nickname']) {
- $profile = DBA::fetchFirst("SELECT `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
- INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
- WHERE `user`.`nickname` = ? AND `contact`.`self` LIMIT 1",
- $nickname
- );
+ $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname]);
if (DBA::isResult($profile)) {
$profiledata = $profile;
}
diff --git a/mod/poco.php b/mod/poco.php
index f04ec42790..ef77c9c992 100644
--- a/mod/poco.php
+++ b/mod/poco.php
@@ -81,10 +81,7 @@ function poco_init(App $a) {
}
if (!$system_mode && !$global) {
- $user = DBA::fetchFirst("SELECT `user`.`uid`, `user`.`nickname` FROM `user`
- INNER JOIN `profile` ON `user`.`uid` = `profile`.`uid`
- WHERE `user`.`nickname` = ? AND NOT `profile`.`hide-friends`",
- $nickname);
+ $user = DBA::selectFirst('owner-view', ['uid', 'nickname'], ['nickname' => $nickname, 'hide-friends' => false]);
if (!DBA::isResult($user)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
@@ -147,16 +144,7 @@ function poco_init(App $a) {
);
} elseif ($system_mode) {
Logger::log("Start system mode query", Logger::DEBUG);
- $contacts = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`,
- `profile`.`address` AS `paddress`, `profile`.`region` AS `pregion`,
- `profile`.`postal-code` AS `ppostalcode`, `profile`.`country-name` AS `pcountry`, `user`.`account-type`
- FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
- INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `self` = 1 AND `profile`.`net-publish`
- LIMIT %d, %d",
- intval($startIndex),
- intval($itemsPerPage)
- );
+ $contacts = DBA::selectToArray('owner-view', [], ['net-publish' => true], ['limit' => [$startIndex, $itemsPerPage]]);
} else {
Logger::log("Start query for user " . $user['nickname'], Logger::DEBUG);
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
@@ -233,28 +221,6 @@ function poco_init(App $a) {
}
}
- if (($contact['about'] == "") && isset($contact['pabout'])) {
- $contact['about'] = $contact['pabout'];
- }
- if ($contact['location'] == "") {
- if (isset($contact['plocation'])) {
- $contact['location'] = $contact['plocation'];
- }
- if (isset($contact['pregion']) && ( $contact['pregion'] != "")) {
- if ($contact['location'] != "") {
- $contact['location'] .= ", ";
- }
- $contact['location'] .= $contact['pregion'];
- }
-
- if (isset($contact['pcountry']) && ( $contact['pcountry'] != "")) {
- if ($contact['location'] != "") {
- $contact['location'] .= ", ";
- }
- $contact['location'] .= $contact['pcountry'];
- }
- }
-
if (($contact['keywords'] == "") && isset($contact['pub_keywords'])) {
$contact['keywords'] = $contact['pub_keywords'];
}
@@ -346,21 +312,21 @@ function poco_init(App $a) {
$entry['address'] = [];
// Deactivated. It just reveals too much data. (Although its from the default profile)
- //if (isset($rr['paddress']))
- // $entry['address']['streetAddress'] = $rr['paddress'];
+ //if (isset($rr['address']))
+ // $entry['address']['streetAddress'] = $rr['address'];
- if (isset($contact['plocation'])) {
- $entry['address']['locality'] = $contact['plocation'];
+ if (isset($contact['locality'])) {
+ $entry['address']['locality'] = $contact['locality'];
}
- if (isset($contact['pregion'])) {
- $entry['address']['region'] = $contact['pregion'];
+ if (isset($contact['region'])) {
+ $entry['address']['region'] = $contact['region'];
}
// See above
- //if (isset($rr['ppostalcode']))
- // $entry['address']['postalCode'] = $rr['ppostalcode'];
+ //if (isset($rr['postal-code']))
+ // $entry['address']['postalCode'] = $rr['postal-code'];
- if (isset($contact['pcountry'])) {
- $entry['address']['country'] = $contact['pcountry'];
+ if (isset($contact['country'])) {
+ $entry['address']['country'] = $contact['country'];
}
}
diff --git a/mod/wall_upload.php b/mod/wall_upload.php
index ad0b5d3c0b..093d5db773 100644
--- a/mod/wall_upload.php
+++ b/mod/wall_upload.php
@@ -45,15 +45,9 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($a->argc > 1) {
if (empty($_FILES['media'])) {
- $nick = $a->argv[1];
- $r = q("SELECT `user`.*, `contact`.`id` FROM `user`
- INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
- WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0
- AND `contact`.`self` = 1 LIMIT 1",
- DBA::escape($nick)
- );
-
- if (!DBA::isResult($r)) {
+ $nick = $a->argv[1];
+ $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $nick, 'blocked' => false]);
+ if (!DBA::isResult($user)) {
if ($r_json) {
echo json_encode(['error' => DI::l10n()->t('Invalid request.')]);
exit();
@@ -62,12 +56,7 @@ function wall_upload_post(App $a, $desktopmode = true)
}
} else {
$user_info = api_get_user($a);
- $r = q("SELECT `user`.*, `contact`.`id` FROM `user`
- INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
- WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0
- AND `contact`.`self` = 1 LIMIT 1",
- DBA::escape($user_info['screen_name'])
- );
+ $user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $user_info['screen_name'], 'blocked' => false]);
}
} else {
if ($r_json) {
@@ -83,10 +72,10 @@ function wall_upload_post(App $a, $desktopmode = true)
$can_post = false;
$visitor = 0;
- $page_owner_uid = $r[0]['uid'];
- $default_cid = $r[0]['id'];
- $page_owner_nick = $r[0]['nickname'];
- $community_page = (($r[0]['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
+ $page_owner_uid = $user['uid'];
+ $default_cid = $user['id'];
+ $page_owner_nick = $user['nickname'];
+ $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
if ((local_user()) && (local_user() == $page_owner_uid)) {
$can_post = true;
diff --git a/src/Console/User.php b/src/Console/User.php
index b12a3a6ad3..d976620382 100644
--- a/src/Console/User.php
+++ b/src/Console/User.php
@@ -361,7 +361,7 @@ HELP;
$contact['email'],
Temporal::getRelativeDate($contact['created']),
Temporal::getRelativeDate($contact['login_date']),
- Temporal::getRelativeDate($contact['lastitem_date']),
+ Temporal::getRelativeDate($contact['last-item']),
]);
}
$this->out($table->getTable());
diff --git a/src/Core/Worker.php b/src/Core/Worker.php
index f41636beda..6fb8bd40ff 100644
--- a/src/Core/Worker.php
+++ b/src/Core/Worker.php
@@ -684,7 +684,7 @@ class Worker
self::$db_duration_stat += (microtime(true) - $stamp);
while ($entry = DBA::fetch($jobs)) {
$stamp = (float)microtime(true);
- $processes = DBA::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` WHERE NOT `done` AND `priority` = ?", $entry["priority"]);
+ $processes = DBA::p("SELECT COUNT(*) AS `running` FROM `workerqueue-view` WHERE `priority` = ?", $entry["priority"]);
self::$db_duration += (microtime(true) - $stamp);
self::$db_duration_stat += (microtime(true) - $stamp);
if ($process = DBA::fetch($processes)) {
@@ -698,7 +698,7 @@ class Worker
} else {
$waiting_processes = self::totalEntries();
$stamp = (float)microtime(true);
- $jobs = DBA::p("SELECT COUNT(*) AS `running`, `priority` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done` GROUP BY `priority` ORDER BY `priority`");
+ $jobs = DBA::p("SELECT COUNT(*) AS `running`, `priority` FROM `workerqueue-view` GROUP BY `priority` ORDER BY `priority`");
self::$db_duration += (microtime(true) - $stamp);
self::$db_duration_stat += (microtime(true) - $stamp);
@@ -839,9 +839,7 @@ class Worker
$running = [];
$running_total = 0;
$stamp = (float)microtime(true);
- $processes = DBA::p("SELECT COUNT(DISTINCT(`process`.`pid`)) AS `running`, `priority` FROM `process`
- INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
- WHERE NOT `done` GROUP BY `priority`");
+ $processes = DBA::p("SELECT COUNT(DISTINCT(`pid`)) AS `running`, `priority` FROM `workerqueue-view` GROUP BY `priority`");
self::$db_duration += (microtime(true) - $stamp);
while ($process = DBA::fetch($processes)) {
$running[$process['priority']] = $process['running'];
diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php
index 6fe4d614d8..dc13bd6566 100644
--- a/src/Database/DBStructure.php
+++ b/src/Database/DBStructure.php
@@ -112,10 +112,12 @@ class DBStructure
echo "\n";
}
+
+ View::printStructure($basePath);
}
/**
- * Loads the database structure definition from the config/dbstructure.config.php file.
+ * Loads the database structure definition from the static/dbstructure.config.php file.
* On first pass, defines DB_UPDATE_VERSION constant.
*
* @see static/dbstructure.config.php
@@ -594,6 +596,8 @@ class DBStructure
}
}
+ View::create($verbose, $action);
+
if ($action && !$install) {
DI::config()->set('system', 'maintenance', 0);
DI::config()->set('system', 'maintenance_reason', '');
diff --git a/src/Database/View.php b/src/Database/View.php
new file mode 100644
index 0000000000..e1335d9df6
--- /dev/null
+++ b/src/Database/View.php
@@ -0,0 +1,137 @@
+.
+ *
+ */
+
+namespace Friendica\Database;
+
+use Exception;
+use Friendica\Core\Hook;
+use Friendica\DI;
+
+class View
+{
+ /**
+ * view definition loaded from static/dbview.config.php
+ *
+ * @var array
+ */
+ private static $definition = [];
+
+ /**
+ * Loads the database structure definition from the static/dbview.config.php file.
+ * On first pass, defines DB_UPDATE_VERSION constant.
+ *
+ * @see static/dbview.config.php
+ * @param boolean $with_addons_structure Whether to tack on addons additional tables
+ * @param string $basePath The base path of this application
+ * @return array
+ * @throws Exception
+ */
+ public static function definition($basePath = '', $with_addons_structure = true)
+ {
+ if (!self::$definition) {
+ if (empty($basePath)) {
+ $basePath = DI::app()->getBasePath();
+ }
+
+ $filename = $basePath . '/static/dbview.config.php';
+
+ if (!is_readable($filename)) {
+ throw new Exception('Missing database view config file static/dbview.config.php');
+ }
+
+ $definition = require $filename;
+
+ if (!$definition) {
+ throw new Exception('Corrupted database view config file static/dbview.config.php');
+ }
+
+ self::$definition = $definition;
+ } else {
+ $definition = self::$definition;
+ }
+
+ if ($with_addons_structure) {
+ Hook::callAll('dbview_definition', $definition);
+ }
+
+ return $definition;
+ }
+
+ public static function create(bool $verbose, bool $action)
+ {
+ $definition = self::definition();
+
+ foreach ($definition as $name => $structure) {
+ self::createview($name, $structure, $verbose, $action);
+ }
+ }
+
+ public static function printStructure($basePath)
+ {
+ $database = self::definition($basePath, false);
+
+ foreach ($database AS $name => $structure) {
+ echo "--\n";
+ echo "-- VIEW $name\n";
+ echo "--\n";
+ self::createView($name, $structure, true, false);
+
+ echo "\n";
+ }
+ }
+
+ private static function createview($name, $structure, $verbose, $action)
+ {
+ $r = true;
+
+ $sql_rows = [];
+ foreach ($structure["fields"] AS $fieldname => $origin) {
+ if (is_string($origin)) {
+ $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`";
+ } elseif (is_array($origin) && (sizeof($origin) == 2)) {
+ $sql_rows[] = "`" . DBA::escape($origin[0]) . "`.`" . DBA::escape($origin[1]) . "` AS `" . DBA::escape($fieldname) . "`";
+ }
+ }
+
+ $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name));
+
+ if ($verbose) {
+ echo $sql . ";\n";
+ }
+
+ if ($action) {
+ DBA::e($sql);
+ }
+
+ $sql = sprintf("CREATE VIEW `%s` AS SELECT \n\t", DBA::escape($name)) .
+ implode(",\n\t", $sql_rows) . "\n\t" . $structure['query'];
+
+ if ($verbose) {
+ echo $sql . ";\n";
+ }
+
+ if ($action) {
+ $r = DBA::e($sql);
+ }
+
+ return $r;
+ }
+}
diff --git a/src/Model/Item.php b/src/Model/Item.php
index f6d08047b2..bd8d03359e 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -2563,7 +2563,8 @@ class Item
Contact::unmarkForArchival($contact);
}
- $update = (($arr['private'] != self::PRIVATE) && ((($arr['author-link'] ?? '') === ($arr['owner-link'] ?? '')) || ($arr["parent-uri"] === $arr["uri"])));
+ /// @todo On private posts we could obfuscate the date
+ $update = ($arr['private'] != self::PRIVATE);
// Is it a forum? Then we don't care about the rules from above
if (!$update && in_array($arr["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN]) && ($arr["parent-uri"] === $arr["uri"])) {
@@ -2573,8 +2574,15 @@ class Item
}
if ($update) {
- DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']],
- ['id' => $arr['contact-id']]);
+ // The "self" contact id is used (for example in the connectors) when the contact is unknown
+ // So we have to ensure to only update the last item when it had been our own post,
+ // or it had been done by a "regular" contact.
+ if (!empty($arr['wall'])) {
+ $condition = ['id' => $arr['contact-id']];
+ } else {
+ $condition = ['id' => $arr['contact-id'], 'self' => false];
+ }
+ DBA::update('contact', ['success_update' => $arr['received'], 'last-item' => $arr['received']], $condition);
}
// Now do the same for the system wide contacts with uid=0
if ($arr['private'] != self::PRIVATE) {
diff --git a/src/Model/Profile.php b/src/Model/Profile.php
index 867a6db4fb..348e16badd 100644
--- a/src/Model/Profile.php
+++ b/src/Model/Profile.php
@@ -234,19 +234,7 @@ class Profile
*/
public static function getByNickname($nickname, $uid = 0)
{
- $profile = DBA::fetchFirst(
- "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
- `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
- `profile`.*,
- `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
- FROM `profile`
- INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
- INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
- WHERE `user`.`nickname` = ? AND `profile`.`uid` = ? LIMIT 1",
- $nickname,
- intval($uid)
- );
-
+ $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname, 'uid' => $uid]);
return $profile;
}
@@ -399,9 +387,9 @@ class Profile
'fullname' => $profile['name'],
'firstname' => $firstname,
'lastname' => $lastname,
- 'photo300' => $profile['contact_photo'] ?? '',
- 'photo100' => $profile['contact_thumb'] ?? '',
- 'photo50' => $profile['contact_micro'] ?? '',
+ 'photo300' => $profile['photo'] ?? '',
+ 'photo100' => $profile['thumb'] ?? '',
+ 'photo50' => $profile['micro'] ?? '',
];
} else {
$diaspora = false;
@@ -410,18 +398,15 @@ class Profile
$contact_block = '';
$updated = '';
$contact_count = 0;
+
+ if (!empty($profile['last-item'])) {
+ $updated = date('c', strtotime($profile['last-item']));
+ }
+
if (!$block) {
$contact_block = ContactBlock::getHTML($a->profile);
if (is_array($a->profile) && !$a->profile['hide-friends']) {
- $r = q(
- "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
- intval($a->profile['uid'])
- );
- if (DBA::isResult($r)) {
- $updated = date('c', strtotime($r[0]['updated']));
- }
-
$contact_count = DBA::count('contact', [
'uid' => $profile['uid'],
'self' => false,
@@ -902,87 +887,37 @@ class Profile
*/
public static function searchProfiles($start = 0, $count = 100, $search = null)
{
- $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
- $total = 0;
-
if (!empty($search)) {
+ $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
$searchTerm = '%' . $search . '%';
- $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
- FROM `profile`
- LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
- AND ((`profile`.`name` LIKE ?) OR
- (`user`.`nickname` LIKE ?) OR
- (`profile`.`about` LIKE ?) OR
- (`profile`.`locality` LIKE ?) OR
- (`profile`.`region` LIKE ?) OR
- (`profile`.`country-name` LIKE ?) OR
- (`profile`.`pub_keywords` LIKE ?) OR
- (`profile`.`prv_keywords` LIKE ?))",
- $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
- $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
+ $condition = ["NOT `blocked` AND NOT `account_removed`
+ $publish
+ AND ((`name` LIKE ?) OR
+ (`nickname` LIKE ?) OR
+ (`about` LIKE ?) OR
+ (`locality` LIKE ?) OR
+ (`region` LIKE ?) OR
+ (`country-name` LIKE ?) OR
+ (`pub_keywords` LIKE ?) OR
+ (`prv_keywords` LIKE ?))",
+ $searchTerm, $searchTerm, $searchTerm, $searchTerm,
+ $searchTerm, $searchTerm, $searchTerm, $searchTerm];
} else {
- $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
- FROM `profile`
- LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`");
- }
-
- if (DBA::isResult($cnt)) {
- $total = $cnt['total'];
- }
-
- $order = " ORDER BY `name` ASC ";
- $profiles = [];
-
- // If nothing found, don't try to select details
- if ($total > 0) {
- if (!empty($search)) {
- $searchTerm = '%' . $search . '%';
-
- $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
- `contact`.`addr`, `contact`.`url` AS `profile_url`
- FROM `profile`
- LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
- WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
- AND ((`profile`.`name` LIKE ?) OR
- (`user`.`nickname` LIKE ?) OR
- (`profile`.`about` LIKE ?) OR
- (`profile`.`locality` LIKE ?) OR
- (`profile`.`region` LIKE ?) OR
- (`profile`.`country-name` LIKE ?) OR
- (`profile`.`pub_keywords` LIKE ?) OR
- (`profile`.`prv_keywords` LIKE ?))
- $order LIMIT ?,?",
- $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
- $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
- $start, $count
- );
- } else {
- $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
- `contact`.`addr`, `contact`.`url` AS `profile_url`
- FROM `profile`
- LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
- WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
- $order LIMIT ?,?",
- $start, $count
- );
+ $condition = ['blocked' => false, 'account_removed' => false];
+ if (!DI::config()->get('system', 'publish_all')) {
+ $condition['publish'] = true;
}
}
- if (DBA::isResult($profiles) && $total > 0) {
- return [
- 'total' => $total,
- 'entries' => DBA::toArray($profiles),
- ];
+ $total = DBA::count('owner-view', $condition);
+ // If nothing found, don't try to select details
+ if ($total > 0) {
+ $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['name'], 'limit' => [$start, $count]]);
} else {
- return [
- 'total' => $total,
- 'entries' => [],
- ];
+ $profiles = [];
}
+
+ return ['total' => $total, 'entries' => $profiles];
}
}
diff --git a/src/Model/Register.php b/src/Model/Register.php
index be00699bfa..5eb9a417ca 100644
--- a/src/Model/Register.php
+++ b/src/Model/Register.php
@@ -42,15 +42,7 @@ class Register
*/
public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE)
{
- $stmt = DBA::p(
- "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`, `contact`.`nick`
- FROM `register`
- INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
- INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
- LIMIT ?, ?", $start, $count
- );
-
- return DBA::toArray($stmt);
+ return DBA::selectToArray('pending-view', [], [], ['limit' => [$start, $count]]);
}
/**
@@ -64,14 +56,7 @@ class Register
*/
public static function getPendingForUser(int $uid)
{
- return DBA::fetchFirst(
- "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
- FROM `register`
- INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
- INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
- WHERE `register`.uid = ?",
- $uid
- );
+ return DBA::selectToArray('pending-view', [], ['uid' => $uid]);
}
/**
@@ -82,13 +67,7 @@ class Register
*/
public static function getPendingCount()
{
- $register = DBA::fetchFirst(
- "SELECT COUNT(*) AS `count`
- FROM `register`
- INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
- );
-
- return $register['count'];
+ return DBA::count('pending-view', ['self' => true]);
}
/**
diff --git a/src/Model/Tag.php b/src/Model/Tag.php
index e2ce5ad0d5..cf453f2431 100644
--- a/src/Model/Tag.php
+++ b/src/Model/Tag.php
@@ -231,13 +231,18 @@ class Tag
*/
public static function remove(int $uriid, int $type, string $name, string $url = '')
{
- $tag = DBA::fetchFirst("SELECT `id` FROM `tag` INNER JOIN `post-tag` ON `post-tag`.`tid` = `tag`.`id`
- WHERE `uri-id` = ? AND `type` = ? AND `name` = ? AND `url` = ?", $uriid, $type, $name, $url);
+ $condition = ['uri-id' => $uriid, 'type' => $type, 'url' => $url];
+ if ($type == self::HASHTAG) {
+ $condition['name'] = $name;
+ }
+
+ $tag = DBA::selectFirst('tag-view', ['tid', 'cid'], $condition);
if (!DBA::isResult($tag)) {
return;
}
- Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['id'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
- DBA::delete('post-tag', ['uri-id' => $uriid, 'tid' => $tag['id']]);
+
+ Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
+ DBA::delete('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
}
/**
diff --git a/src/Model/User.php b/src/Model/User.php
index 4ef5ffa33c..be71bcf645 100644
--- a/src/Model/User.php
+++ b/src/Model/User.php
@@ -195,66 +195,50 @@ class User
*/
public static function getOwnerDataById($uid, $check_valid = true)
{
- $r = DBA::fetchFirst(
- "SELECT
- `contact`.*,
- `user`.`prvkey` AS `uprvkey`,
- `user`.`timezone`,
- `user`.`nickname`,
- `user`.`sprvkey`,
- `user`.`spubkey`,
- `user`.`page-flags`,
- `user`.`account-type`,
- `user`.`prvnets`,
- `user`.`account_removed`,
- `user`.`hidewall`
- FROM `contact`
- INNER JOIN `user`
- ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`uid` = ?
- AND `contact`.`self`
- LIMIT 1",
- $uid
- );
- if (!DBA::isResult($r)) {
- return false;
+ $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]);
+ if (!DBA::isResult($owner)) {
+ if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) {
+ return false;
+ }
+ Contact::createSelfFromUserId($uid);
+ $owner = self::getOwnerDataById($uid, false);
}
- if (empty($r['nickname'])) {
+ if (empty($owner['nickname'])) {
return false;
}
if (!$check_valid) {
- return $r;
+ return $owner;
}
// Check if the returned data is valid, otherwise fix it. See issue #6122
// Check for correct url and normalised nurl
- $url = DI::baseUrl() . '/profile/' . $r['nickname'];
- $repair = ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url']));
+ $url = DI::baseUrl() . '/profile/' . $owner['nickname'];
+ $repair = ($owner['url'] != $url) || ($owner['nurl'] != Strings::normaliseLink($owner['url']));
if (!$repair) {
// Check if "addr" is present and correct
- $addr = $r['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
- $repair = ($addr != $r['addr']);
+ $addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
+ $repair = ($addr != $owner['addr']);
}
if (!$repair) {
// Check if the avatar field is filled and the photo directs to the correct path
$avatar = Photo::selectFirst(['resource-id'], ['uid' => $uid, 'profile' => true]);
if (DBA::isResult($avatar)) {
- $repair = empty($r['avatar']) || !strpos($r['photo'], $avatar['resource-id']);
+ $repair = empty($owner['avatar']) || !strpos($owner['photo'], $avatar['resource-id']);
}
}
if ($repair) {
Contact::updateSelfFromUserID($uid);
// Return the corrected data and avoid a loop
- $r = self::getOwnerDataById($uid, false);
+ $owner = self::getOwnerDataById($uid, false);
}
- return $r;
+ return $owner;
}
/**
@@ -1290,17 +1274,10 @@ class User
'active_users_monthly' => 0,
];
- $userStmt = DBA::p("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
- FROM `user`
- INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
- WHERE `user`.`verified`
- AND `user`.`login_date` > ?
- AND NOT `user`.`blocked`
- AND NOT `user`.`account_removed`
- AND NOT `user`.`account_expired`",
- DBA::NULL_DATETIME
- );
-
+ $userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'],
+ ["`verified` AND `login_date` > ? AND NOT `blocked`
+ AND NOT `account_removed` AND NOT `account_expired`",
+ DBA::NULL_DATETIME]);
if (!DBA::isResult($userStmt)) {
return $statistics;
}
@@ -1332,39 +1309,27 @@ class User
* @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
* @param string $type The type of users, which should get (all, bocked, removed)
* @param string $order Order of the user list (Default is 'contact.name')
- * @param string $order_direction Order direction (Default is ASC)
+ * @param bool $descending Order direction (Default is ascending)
*
* @return array The list of the users
* @throws Exception
*/
- public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+')
+ public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'name', bool $descending = false)
{
- $sql_order = '`' . str_replace('.', '`.`', $order) . '`';
- $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC';
-
+ $param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
+ $condition = [];
switch ($type) {
case 'active':
- $sql_extra = 'AND `user`.`blocked` = 0';
+ $condition['blocked'] = false;
break;
case 'blocked':
- $sql_extra = 'AND `user`.`blocked` = 1';
+ $condition['blocked'] = true;
break;
case 'removed':
- $sql_extra = 'AND `user`.`account_removed` = 1';
- break;
- case 'all':
- default:
- $sql_extra = '';
+ $condition['account_removed'] = true;
break;
}
- $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created`
- FROM `user`
- INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
- WHERE `user`.`verified` $sql_extra
- ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count
- );
-
- return DBA::toArray($usersStmt);
+ return DBA::selectToArray('owner-view', [], $condition, $param);
}
}
diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php
index 3ef91aadf7..002e6c5feb 100644
--- a/src/Module/Admin/Users.php
+++ b/src/Module/Admin/Users.php
@@ -157,15 +157,15 @@ class Users extends BaseAdmin
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
$valid_orders = [
- 'contact.name',
- 'user.email',
- 'user.register_date',
- 'user.login_date',
- 'lastitem_date',
- 'user.page-flags'
+ 'name',
+ 'email',
+ 'register_date',
+ 'login_date',
+ 'last-item',
+ 'page-flags'
];
- $order = 'contact.name';
+ $order = 'name';
$order_direction = '+';
if (!empty($_GET['o'])) {
$new_order = $_GET['o'];
@@ -179,7 +179,7 @@ class Users extends BaseAdmin
}
}
- $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction);
+ $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-'));
$adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
$_setup_users = function ($e) use ($adminlist) {
@@ -206,7 +206,7 @@ class Users extends BaseAdmin
$e['register_date'] = Temporal::getRelativeDate($e['register_date']);
$e['login_date'] = Temporal::getRelativeDate($e['login_date']);
- $e['lastitem_date'] = Temporal::getRelativeDate($e['lastitem_date']);
+ $e['last-item'] = Temporal::getRelativeDate($e['last-item']);
$e['is_admin'] = in_array($e['email'], $adminlist);
$e['is_deletable'] = (intval($e['uid']) != local_user());
$e['deleted'] = ($e['account_removed'] ? Temporal::getRelativeDate($e['account_expires_on']) : False);
diff --git a/src/Module/NoScrape.php b/src/Module/NoScrape.php
index a03770d0d4..13a683d974 100644
--- a/src/Module/NoScrape.php
+++ b/src/Module/NoScrape.php
@@ -85,22 +85,11 @@ class NoScrape extends BaseModule
$json_info['tags'] = $keywords;
$json_info['language'] = $a->profile['language'];
- if (!($a->profile['hide-friends'] ?? false)) {
- $stmt = DBA::p(
- "SELECT `gcontact`.`updated`
- FROM `contact`
- INNER JOIN `gcontact`
- WHERE `gcontact`.`nurl` = `contact`.`nurl`
- AND `self`
- AND `uid` = ?
- LIMIT 1",
- intval($a->profile['uid'])
- );
- if ($gcontact = DBA::fetch($stmt)) {
- $json_info["updated"] = date("c", strtotime($gcontact['updated']));
- }
- DBA::close($stmt);
+ if (!empty($a->profile['last-item'])) {
+ $json_info['updated'] = date("c", strtotime($a->profile['last-item']));
+ }
+ if (!($a->profile['hide-friends'] ?? false)) {
$json_info['contacts'] = DBA::count('contact',
[
'uid' => $a->profile['uid'],
diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php
index 6142648803..6c7f4f14e5 100644
--- a/src/Module/Profile/Profile.php
+++ b/src/Module/Profile/Profile.php
@@ -299,10 +299,10 @@ class Profile extends BaseProfile
$htmlhead .= '' . "\n";
}
- $htmlhead .= '' . "\n";
- $htmlhead .= '' . "\n";
- $htmlhead .= '' . "\n";
- $htmlhead .= '' . "\n";
+ $htmlhead .= '' . "\n";
+ $htmlhead .= '' . "\n";
+ $htmlhead .= '' . "\n";
+ $htmlhead .= '' . "\n";
$uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
$htmlhead .= '' . "\n";
header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php
index bb19be2b9c..8b6734e5cd 100644
--- a/src/Module/Profile/Status.php
+++ b/src/Module/Profile/Status.php
@@ -53,10 +53,10 @@ class Status extends BaseProfile
DI::page()['htmlhead'] .= '' . "\n";
}
- DI::page()['htmlhead'] .= '' . "\n";
- DI::page()['htmlhead'] .= '' . "\n";
- DI::page()['htmlhead'] .= '' . "\n";
- DI::page()['htmlhead'] .= '' . "\n";
+ DI::page()['htmlhead'] .= '' . "\n";
+ DI::page()['htmlhead'] .= '' . "\n";
+ DI::page()['htmlhead'] .= '' . "\n";
+ DI::page()['htmlhead'] .= '' . "\n";
$category = $datequery = $datequery2 = '';
@@ -162,7 +162,7 @@ class Status extends BaseProfile
// If not then we can improve the performance with an additional condition
$condition = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
if (!DBA::exists('user', $condition)) {
- $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
+ $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['id'])));
} else {
$sql_extra3 = "";
}
diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php
index 83010f811e..f65a202f48 100644
--- a/src/Protocol/DFRN.php
+++ b/src/Protocol/DFRN.php
@@ -183,19 +183,12 @@ class DFRN
$sql_extra = sprintf(" AND `item`.`private` != %s ", Item::PRIVATE);
- $r = q(
- "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
- FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`self` AND `user`.`nickname` = '%s' LIMIT 1",
- DBA::escape($owner_nick)
- );
-
- if (! DBA::isResult($r)) {
+ $owner = DBA::selectFirst('owner-view', [], ['nickname' => $owner_nick]);
+ if (!DBA::isResult($owner)) {
Logger::log(sprintf('No contact found for nickname=%d', $owner_nick), Logger::WARNING);
exit();
}
- $owner = $r[0];
$owner_id = $owner['uid'];
$sql_post_table = "";
@@ -684,18 +677,10 @@ class DFRN
}
// Only show contact details when we are allowed to
- $r = q(
- "SELECT `profile`.`about`, `profile`.`name`, `profile`.`homepage`, `user`.`nickname`,
- `user`.`timezone`, `profile`.`locality`, `profile`.`region`, `profile`.`country-name`,
- `profile`.`pub_keywords`, `profile`.`xmpp`, `profile`.`dob`
- FROM `profile`
- INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE NOT `user`.`hidewall` AND `user`.`uid` = %d",
- intval($owner['uid'])
- );
- if (DBA::isResult($r)) {
- $profile = $r[0];
-
+ $profile = DBA::selectFirst('owner-view',
+ ['about', 'name', 'homepage', 'nickname', 'timezone', 'locality', 'region', 'country-name', 'pub_keywords', 'xmpp', 'dob'],
+ ['uid' => $owner['uid'], 'hidewall' => false]);
+ if (DBA::isResult($profile)) {
XML::addElement($doc, $author, "poco:displayName", $profile["name"]);
XML::addElement($doc, $author, "poco:updated", $namdate);
diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php
index 513cd0bcc0..fe6c328d9f 100644
--- a/src/Protocol/Diaspora.php
+++ b/src/Protocol/Diaspora.php
@@ -259,27 +259,13 @@ class Diaspora
*/
public static function participantsForThread($thread, array $contacts)
{
- $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
- `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
- INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
- INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
- WHERE `participation`.`iid` = ? AND NOT `contact`.`archive`", $thread);
-
- while ($contact = DBA::fetch($r)) {
- if (!empty($contact['fnetwork'])) {
- $contact['network'] = $contact['fnetwork'];
- }
- unset($contact['fnetwork']);
+ $participation = DBA::select('participation-view', [], ['iid' => $thread]);
+ while ($contact = DBA::fetch($participation)) {
if (empty($contact['protocol'])) {
$contact['protocol'] = $contact['network'];
}
- if (empty($contact['batch']) && !empty($contact['fbatch'])) {
- $contact['batch'] = $contact['fbatch'];
- }
- unset($contact['fbatch']);
-
$exists = false;
foreach ($contacts as $entry) {
if ($entry['batch'] == $contact['batch']) {
@@ -291,7 +277,8 @@ class Diaspora
$contacts[] = $contact;
}
}
- DBA::close($r);
+
+ DBA::close($participation);
return $contacts;
}
@@ -4170,20 +4157,11 @@ class Diaspora
*/
private static function createProfileData($uid)
{
- $r = q(
- "SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr`
- FROM `profile`
- INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
- INNER JOIN `contact` ON `profile`.`uid` = `contact`.`uid`
- WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
- intval($uid)
- );
-
- if (!$r) {
+ $profile = DBA::selectFirst('owner-view', ['uid', 'addr', 'name', 'location', 'net-publish', 'dob', 'about', 'pub_keywords'], ['uid' => $uid]);
+ if (!DBA::isResult($profile)) {
return [];
}
- $profile = $r[0];
$handle = $profile["addr"];
$split_name = self::splitName($profile['name']);
@@ -4212,7 +4190,7 @@ class Diaspora
$about = BBCode::toMarkdown($profile['about']);
- $location = Profile::formatLocation($profile);
+ $location = $profile['location'];
$tags = '';
if ($profile['pub_keywords']) {
$kw = str_replace(',', ' ', $profile['pub_keywords']);
diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php
index 0d234b53f0..d082909ae5 100644
--- a/src/Protocol/Salmon.php
+++ b/src/Protocol/Salmon.php
@@ -111,13 +111,13 @@ class Salmon
{
// does contact have a salmon endpoint?
- if (! strlen($url)) {
+ if (!strlen($url)) {
return;
}
- if (! $owner['sprvkey']) {
+ if (!$owner['sprvkey']) {
Logger::log(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.",
- $owner['username'], $owner['uid']));
+ $owner['name'], $owner['uid']));
return;
}
diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php
index ff844ca392..6c6d26f26c 100644
--- a/src/Worker/Directory.php
+++ b/src/Worker/Directory.php
@@ -61,16 +61,10 @@ class Directory
}
private static function updateAll() {
- $r = q("SELECT `url` FROM `contact`
- INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
- INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`self` AND `profile`.`net-publish` AND
- NOT `user`.`account_expired` AND `user`.`verified`");
-
- if (DBA::isResult($r)) {
- foreach ($r AS $user) {
- Worker::add(PRIORITY_LOW, 'Directory', $user['url']);
- }
+ $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]);
+ while ($user = DBA::fetch($users)) {
+ Worker::add(PRIORITY_LOW, 'Directory', $user['url']);
}
+ DBA::close($users);
}
}
diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php
index 4eabe2d37b..50055f62ae 100755
--- a/static/dbstructure.config.php
+++ b/static/dbstructure.config.php
@@ -51,7 +51,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1339);
+ define('DB_UPDATE_VERSION', 1340);
}
return [
diff --git a/static/dbview.config.php b/static/dbview.config.php
new file mode 100755
index 0000000000..1d95261a25
--- /dev/null
+++ b/static/dbview.config.php
@@ -0,0 +1,234 @@
+.
+ *
+ * Main view structure configuration file.
+ *
+ * Here are described all the view Friendica needs to work.
+ *
+ * Syntax (braces indicate optionale values):
+ * "" => [
+ * "fields" => [
+ * "" => ["table", "field"],
+ * "" => "SQL expression",
+ * ...
+ * ],
+ * "query" => "FROM `table` INNER JOIN `other-table` ..."
+ * ],
+ * ],
+ *
+ * If you need to make any change, make sure to increment the DB_UPDATE_VERSION constant value in dbstructure.config.php.
+ *
+ */
+
+return [
+ "tag-view" => [
+ "fields" => [
+ "uri-id" => ["post-tag", "uri-id"],
+ "uri" => ["item-uri", "uri"],
+ "guid" => ["item-uri", "guid"],
+ "type" => ["post-tag", "type"],
+ "tid" => ["post-tag", "tid"],
+ "cid" => ["post-tag", "cid"],
+ "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END",
+ "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END",
+ ],
+ "query" => "FROM `post-tag`
+ INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
+ LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
+ LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`"
+ ],
+ "owner-view" => [
+ "fields" => [
+ "id" => ["contact", "id"],
+ "uid" => ["contact", "uid"],
+ "created" => ["contact", "created"],
+ "updated" => ["contact", "updated"],
+ "self" => ["contact", "self"],
+ "remote_self" => ["contact", "remote_self"],
+ "rel" => ["contact", "rel"],
+ "duplex" => ["contact", "duplex"],
+ "network" => ["contact", "network"],
+ "protocol" => ["contact", "protocol"],
+ "name" => ["contact", "name"],
+ "nick" => ["contact", "nick"],
+ "location" => ["contact", "location"],
+ "about" => ["contact", "about"],
+ "keywords" => ["contact", "keywords"],
+ "gender" => ["contact", "gender"],
+ "xmpp" => ["contact", "xmpp"],
+ "attag" => ["contact", "attag"],
+ "avatar" => ["contact", "avatar"],
+ "photo" => ["contact", "photo"],
+ "thumb" => ["contact", "thumb"],
+ "micro" => ["contact", "micro"],
+ "site-pubkey" => ["contact", "site-pubkey"],
+ "issued-id" => ["contact", "issued-id"],
+ "dfrn-id" => ["contact", "dfrn-id"],
+ "url" => ["contact", "url"],
+ "nurl" => ["contact", "nurl"],
+ "addr" => ["contact", "addr"],
+ "alias" => ["contact", "alias"],
+ "pubkey" => ["contact", "pubkey"],
+ "prvkey" => ["contact", "prvkey"],
+ "batch" => ["contact", "batch"],
+ "request" => ["contact", "request"],
+ "notify" => ["contact", "notify"],
+ "poll" => ["contact", "poll"],
+ "confirm" => ["contact", "confirm"],
+ "poco" => ["contact", "poco"],
+ "aes_allow" => ["contact", "aes_allow"],
+ "ret-aes" => ["contact", "ret-aes"],
+ "usehub" => ["contact", "usehub"],
+ "subhub" => ["contact", "subhub"],
+ "hub-verify" => ["contact", "hub-verify"],
+ "last-update" => ["contact", "last-update"],
+ "success_update" => ["contact", "success_update"],
+ "failure_update" => ["contact", "failure_update"],
+ "name-date" => ["contact", "name-date"],
+ "uri-date" => ["contact", "uri-date"],
+ "avatar-date" => ["contact", "avatar-date"],
+ "picdate" => ["contact", "avatar-date"], /// @todo Replaces all uses of "picdate" with "avatar-date"
+ "term-date" => ["contact", "term-date"],
+ "last-item" => ["contact", "last-item"],
+ "priority" => ["contact", "priority"],
+ "blocked" => ["contact", "blocked"], /// @todo Check if "blocked" from contact or from the users table
+ "block_reason" => ["contact", "block_reason"],
+ "readonly" => ["contact", "readonly"],
+ "writable" => ["contact", "writable"],
+ "forum" => ["contact", "forum"],
+ "prv" => ["contact", "prv"],
+ "contact-type" => ["contact", "contact-type"],
+ "hidden" => ["contact", "hidden"],
+ "archive" => ["contact", "archive"],
+ "pending" => ["contact", "pending"],
+ "deleted" => ["contact", "deleted"],
+ "rating" => ["contact", "rating"],
+ "unsearchable" => ["contact", "unsearchable"],
+ "sensitive" => ["contact", "sensitive"],
+ "baseurl" => ["contact", "baseurl"],
+ "reason" => ["contact", "reason"],
+ "closeness" => ["contact", "closeness"],
+ "info" => ["contact", "info"],
+ "profile-id" => ["contact", "profile-id"],
+ "bdyear" => ["contact", "bdyear"],
+ "bd" => ["contact", "bd"],
+ "notify_new_posts" => ["notify_new_posts"],
+ "fetch_further_information" => ["fetch_further_information"],
+ "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"],
+ "parent-uid" => ["user", "parent-uid"],
+ "guid" => ["user", "guid"],
+ "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick"
+ "email" => ["user", "email"],
+ "openid" => ["user", "openid"],
+ "timezone" => ["user", "timezone"],
+ "language" => ["user", "language"],
+ "register_date" => ["user", "register_date"],
+ "login_date" => ["user", "login_date"],
+ "default-location" => ["user", "default-location"],
+ "allow_location" => ["user", "allow_location"],
+ "theme" => ["user", "theme"],
+ "upubkey" => ["user", "pubkey"],
+ "uprvkey" => ["user", "prvkey"],
+ "sprvkey" => ["user", "sprvkey"],
+ "spubkey" => ["user", "spubkey"],
+ "verified" => ["user", "verified"],
+ "blockwall" => ["user", "blockwall"],
+ "hidewall" => ["user", "hidewall"],
+ "blocktags" => ["user", "blocktags"],
+ "unkmail" => ["user", "unkmail"],
+ "cntunkmail" => ["user", "cntunkmail"],
+ "notify-flags" => ["user", "notify-flags"],
+ "page-flags" => ["user", "page-flags"],
+ "account-type" => ["user", "account-type"],
+ "prvnets" => ["user", "prvnets"],
+ "maxreq" => ["user", "maxreq"],
+ "expire" => ["user", "expire"],
+ "account_removed" => ["user", "account_removed"],
+ "account_expired" => ["user", "account_expired"],
+ "account_expires_on" => ["user", "account_expires_on"],
+ "expire_notification_sent" => ["user", "expire_notification_sent"],
+ "def_gid" => ["user", "def_gid"],
+ "allow_cid" => ["user", "allow_cid"],
+ "allow_gid" => ["user", "allow_gid"],
+ "deny_cid" => ["user", "deny_cid"],
+ "deny_gid" => ["user", "deny_gid"],
+ "openidserver" => ["user", "openidserver"],
+ "publish" => ["profile", "publish"],
+ "net-publish" => ["profile", "net-publish"],
+ "hide-friends" => ["profile", "hide-friends"],
+ "prv_keywords" => ["profile", "prv_keywords"],
+ "pub_keywords" => ["profile", "pub_keywords"],
+ "address" => ["profile", "address"],
+ "locality" => ["profile", "locality"],
+ "region" => ["profile", "region"],
+ "postal-code" => ["profile", "postal-code"],
+ "country-name" => ["profile", "country-name"],
+ "homepage" => ["profile", "homepage"],
+ "xmpp" => ["profile", "xmpp"],
+ "dob" => ["profile", "dob"],
+ ],
+ "query" => "FROM `user`
+ INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
+ INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`"
+ ],
+ "participation-view" => [
+ "fields" => [
+ "iid" => ["participation", "iid"],
+ "id" => ["contact", "id"],
+ "url" => ["contact", "url"],
+ "name" => ["contact", "name"],
+ "protocol" => ["contact", "protocol"],
+ "batch" => "CASE `contact`.`batch` WHEN '' THEN `fcontact`.`batch` ELSE `contact`.`batch` END",
+ "network" => "CASE `fcontact`.`network` WHEN '' THEN `contact`.`network` ELSE `fcontact`.`network` END",
+ ],
+ "query" => "FROM `participation`
+ INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid` AND NOT `contact`.`archive`
+ INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`"
+ ],
+ "pending-view" => [
+ "fields" => [
+ "id" => ["register", "id"],
+ "hash" => ["register", "hash"],
+ "created" => ["register", "created"],
+ "uid" => ["register", "uid"],
+ "password" => ["register", "password"],
+ "language" => ["register", "language"],
+ "note" => ["register", "note"],
+ "self" => ["contact", "self"],
+ "name" => ["contact", "name"],
+ "url" => ["contact", "url"],
+ "micro" => ["contact", "micro"],
+ "email" => ["user", "email"],
+ "nick" => ["contact", "nick"],
+ ],
+ "query" => "FROM `register`
+ INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
+ INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
+ ],
+ "workerqueue-view" => [
+ "fields" => [
+ "pid" => ["process", "pid"],
+ "priority" => ["workerqueue", "priority"],
+ ],
+ "query" => "FROM `process`
+ INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
+ WHERE NOT `workerqueue`.`done`"
+ ],
+];
+
diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php
index 8bb701da1d..c9c16a33fc 100644
--- a/tests/datasets/api.fixture.php
+++ b/tests/datasets/api.fixture.php
@@ -256,6 +256,12 @@ return [
'wall' => 1,
],
],
+ 'profile' => [
+ [
+ 'id' => 1,
+ 'uid' => 42,
+ ],
+ ],
'group' => [
[
'id' => 1,
diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php
index fcbb148dc7..cc3a668e6a 100644
--- a/view/theme/vier/theme.php
+++ b/view/theme/vier/theme.php
@@ -140,29 +140,26 @@ function vier_community_info()
// last 9 users
if ($show_lastusers) {
- $publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
- $order = " ORDER BY `register_date` DESC ";
+ $condition = ['blocked' => false];
+ if (!DI::config()->get('system', 'publish_all')) {
+ $condition['publish'] = true;
+ }
$tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
- $r = q("SELECT `profile`.*, `user`.`nickname`
- FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
- 0,
- 9
- );
+ $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
- if (DBA::isResult($r)) {
+ if (DBA::isResult($profiles)) {
$aside['$lastusers_title'] = DI::l10n()->t('Last users');
$aside['$lastusers_items'] = [];
- foreach ($r as $rr) {
- $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['uid']);
+ foreach ($profiles as $profile) {
+ $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
$entry = Renderer::replaceMacros($tpl, [
- '$id' => $rr['id'],
+ '$id' => $profile['id'],
'$profile_link' => $profile_link,
- '$photo' => DI::baseUrl()->remove($rr['thumb']),
- '$alt_text' => $rr['name']]);
+ '$photo' => DI::baseUrl()->remove($profile['thumb']),
+ '$alt_text' => $profile['name']]);
$aside['$lastusers_items'][] = $entry;
}
}