Move mod/randprof to src/Module/RandomProfile
This commit is contained in:
parent
d252598821
commit
8bb85b1da7
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @file mod/randprof.php
|
|
||||||
*/
|
|
||||||
use Friendica\App;
|
|
||||||
use Friendica\Model\Contact;
|
|
||||||
use Friendica\Model\GContact;
|
|
||||||
|
|
||||||
function randprof_init(App $a)
|
|
||||||
{
|
|
||||||
$x = GContact::getRandomUrl();
|
|
||||||
|
|
||||||
if ($x) {
|
|
||||||
$link = Contact::magicLink($x);
|
|
||||||
$a->redirect($link);
|
|
||||||
}
|
|
||||||
|
|
||||||
$a->internalRedirect('profile');
|
|
||||||
}
|
|
|
@ -196,6 +196,7 @@ class Router
|
||||||
$collector->addRoute(['GET', 'POST'], '/verify' , Module\Settings\TwoFactor\Verify::class);
|
$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', 'POST'], '/register', Module\Register::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/robots.txt', Module\RobotsTxt::class);
|
$this->routeCollector->addRoute(['GET'], '/robots.txt', Module\RobotsTxt::class);
|
||||||
$this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class);
|
$this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class);
|
||||||
|
|
|
@ -1511,7 +1511,9 @@ class DBA
|
||||||
if (isset($params['order'])) {
|
if (isset($params['order'])) {
|
||||||
$order_string = " ORDER BY ";
|
$order_string = " ORDER BY ";
|
||||||
foreach ($params['order'] AS $fields => $order) {
|
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") . ", ";
|
$order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", ";
|
||||||
} else {
|
} else {
|
||||||
$order_string .= "`" . $order . "`, ";
|
$order_string .= "`" . $order . "`, ";
|
||||||
|
|
|
@ -1039,11 +1039,16 @@ class GContact
|
||||||
|
|
||||||
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
|
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
|
||||||
|
|
||||||
$r = q(
|
$r = DBA::select('gserver', ['nurl', 'url'], [
|
||||||
"SELECT `nurl`, `url` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `network` = '%s' AND `last_poco_query` < '%s' ORDER BY RAND() LIMIT 5",
|
'`network` = ?
|
||||||
DBA::escape(Protocol::OSTATUS),
|
AND `last_contact` >= `last_failure`
|
||||||
DBA::escape($last_update)
|
AND `last_poco_query` < ?',
|
||||||
);
|
Protocol::OSTATUS,
|
||||||
|
$last_update
|
||||||
|
], [
|
||||||
|
'limit' => 5,
|
||||||
|
'order' => ['RAND()']
|
||||||
|
]);
|
||||||
|
|
||||||
if (!DBA::isResult($r)) {
|
if (!DBA::isResult($r)) {
|
||||||
return;
|
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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function getRandomUrl()
|
public static function getRandomUrl()
|
||||||
{
|
{
|
||||||
$r = q(
|
$r = DBA::selectFirst('gcontact', ['url'], [
|
||||||
"SELECT `url` FROM `gcontact` WHERE `network` = '%s'
|
'`network` = ?
|
||||||
AND `last_contact` >= `last_failure`
|
AND `last_contact` >= `last_failure`
|
||||||
AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH
|
AND `updated` > ?',
|
||||||
ORDER BY rand() LIMIT 1",
|
Protocol::DFRN,
|
||||||
DBA::escape(Protocol::DFRN)
|
DateTimeFormat::utc('now - 1 month'),
|
||||||
);
|
], ['order' => ['RAND()']]);
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
if (DBA::isResult($r)) {
|
||||||
return dirname($r[0]['url']);
|
return $r['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
27
src/Module/RandomProfile.php
Normal file
27
src/Module/RandomProfile.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Module;
|
||||||
|
|
||||||
|
use Friendica\BaseModule;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\GContact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects to a random profile of this node
|
||||||
|
*/
|
||||||
|
class RandomProfile extends BaseModule
|
||||||
|
{
|
||||||
|
public static function content()
|
||||||
|
{
|
||||||
|
$a = self::getApp();
|
||||||
|
|
||||||
|
$contactUrl = GContact::getRandomUrl();
|
||||||
|
|
||||||
|
if ($contactUrl) {
|
||||||
|
$link = Contact::magicLink($contactUrl);
|
||||||
|
$a->redirect($link);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a->internalRedirect('profile');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue