diff --git a/mod/randprof.php b/mod/randprof.php deleted file mode 100644 index 10bff588ef..0000000000 --- a/mod/randprof.php +++ /dev/null @@ -1,19 +0,0 @@ -redirect($link); - } - - $a->internalRedirect('profile'); -} diff --git a/src/App/Router.php b/src/App/Router.php index cd59c3dd90..ef1c47b859 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -196,6 +196,7 @@ class Router $collector->addRoute(['GET', 'POST'], '/verify' , Module\Settings\TwoFactor\Verify::class); }); }); + $this->routeCollector->addRoute(['GET'], '/randprof', Module\RandomProfile::class); $this->routeCollector->addRoute(['GET', 'POST'], '/register', Module\Register::class); $this->routeCollector->addRoute(['GET'], '/robots.txt', Module\RobotsTxt::class); $this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class); diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 228565f940..85bdbbb628 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -1511,7 +1511,9 @@ class DBA if (isset($params['order'])) { $order_string = " ORDER BY "; foreach ($params['order'] AS $fields => $order) { - if (!is_int($fields)) { + if ($order === 'RAND()') { + $order_string .= "RAND(), "; + } elseif (!is_int($fields)) { $order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", "; } else { $order_string .= "`" . $order . "`, "; diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 43375b9afb..c259467a86 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -1039,11 +1039,16 @@ class GContact $last_update = date("c", time() - (60 * 60 * 24 * $requery_days)); - $r = q( - "SELECT `nurl`, `url` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `network` = '%s' AND `last_poco_query` < '%s' ORDER BY RAND() LIMIT 5", - DBA::escape(Protocol::OSTATUS), - DBA::escape($last_update) - ); + $r = DBA::select('gserver', ['nurl', 'url'], [ + '`network` = ? + AND `last_contact` >= `last_failure` + AND `last_poco_query` < ?', + Protocol::OSTATUS, + $last_update + ], [ + 'limit' => 5, + 'order' => ['RAND()'] + ]); if (!DBA::isResult($r)) { return; @@ -1056,21 +1061,23 @@ class GContact } /** - * @return string + * Returns a random, global contact of the current node + * + * @return string The profile URL * @throws Exception */ public static function getRandomUrl() { - $r = q( - "SELECT `url` FROM `gcontact` WHERE `network` = '%s' - AND `last_contact` >= `last_failure` - AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH - ORDER BY rand() LIMIT 1", - DBA::escape(Protocol::DFRN) - ); + $r = DBA::selectFirst('gcontact', ['url'], [ + '`network` = ? + AND `last_contact` >= `last_failure` + AND `updated` > ?', + Protocol::DFRN, + DateTimeFormat::utc('now - 1 month'), + ], ['order' => ['RAND()']]); if (DBA::isResult($r)) { - return dirname($r[0]['url']); + return $r['url']; } return ''; diff --git a/src/Module/RandomProfile.php b/src/Module/RandomProfile.php new file mode 100644 index 0000000000..325cc1e659 --- /dev/null +++ b/src/Module/RandomProfile.php @@ -0,0 +1,27 @@ +redirect($link); + } + + $a->internalRedirect('profile'); + } +}