mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 01:25:39 +00:00
initial commit
This commit is contained in:
parent
6e03cabcb1
commit
b6082d6eec
15 changed files with 3058 additions and 1 deletions
1032
src/library/database.php
Normal file
1032
src/library/database.php
Normal file
File diff suppressed because it is too large
Load diff
49
src/library/sphinx.php
Normal file
49
src/library/sphinx.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
class Sphinx {
|
||||
|
||||
private $_sphinx;
|
||||
|
||||
public function __construct(string $host, int $port) {
|
||||
|
||||
$this->_sphinx = new PDO('mysql:host=' . $host . ';port=' . $port . ';charset=utf8', false, false, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
||||
$this->_sphinx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->_sphinx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function searchMagnetsTotal(string $keyword) {
|
||||
|
||||
$query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `magnet` WHERE MATCH(?)');
|
||||
|
||||
$query->execute(
|
||||
[
|
||||
$keyword
|
||||
]
|
||||
);
|
||||
|
||||
return $query->fetch()->total;
|
||||
}
|
||||
|
||||
public function searchMagnets(string $keyword, int $start, int $limit, int $maxMatches) {
|
||||
|
||||
$query = $this->_sphinx->prepare("SELECT *
|
||||
|
||||
FROM `magnet`
|
||||
|
||||
WHERE MATCH(?)
|
||||
|
||||
ORDER BY `magnetId` DESC, WEIGHT() DESC
|
||||
|
||||
LIMIT " . (int) ($start >= $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . "," . (int) $limit . "
|
||||
|
||||
OPTION `max_matches`=" . (int) ($maxMatches >= 1 ? $maxMatches : 1));
|
||||
|
||||
$query->execute(
|
||||
[
|
||||
$keyword
|
||||
]
|
||||
);
|
||||
|
||||
return $query->fetchAll();
|
||||
}
|
||||
}
|
||||
45
src/library/time.php
Normal file
45
src/library/time.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
class Time
|
||||
{
|
||||
public static function ago(int $time)
|
||||
{
|
||||
$diff = time() - $time;
|
||||
|
||||
if ($diff < 1)
|
||||
{
|
||||
return _('now');
|
||||
}
|
||||
|
||||
$values =
|
||||
[
|
||||
365 * 24 * 60 * 60 => _('year'),
|
||||
30 * 24 * 60 * 60 => _('month'),
|
||||
24 * 60 * 60 => _('day'),
|
||||
60 * 60 => _('hour'),
|
||||
60 => _('minute'),
|
||||
1 => _('second')
|
||||
];
|
||||
|
||||
$plural = [
|
||||
_('year') => _('years'),
|
||||
_('month') => _('months'),
|
||||
_('day') => _('days'),
|
||||
_('hour') => _('hours'),
|
||||
_('minute') => _('minutes'),
|
||||
_('second') => _('seconds')
|
||||
];
|
||||
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
$result = $diff / $key;
|
||||
|
||||
if ($result >= 1)
|
||||
{
|
||||
$round = round($result);
|
||||
|
||||
return sprintf('%s %s ago', $round, $round > 1 ? $plural[$value] : $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue