mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
remove obsolete utility functions
This commit is contained in:
@@ -165,9 +165,11 @@ class User extends AbstractAPI {
|
||||
INNER user_flt AS uf ON (uf.user_id = um.ID)
|
||||
SET
|
||||
{$set},
|
||||
ui.AdminComment = CONCAT('".sqltime()." - ".$Comment."\n\n', ui.AdminComment)
|
||||
ui.AdminComment = CONCAT(now(), ' - ', ?, ui.AdminComment)
|
||||
WHERE
|
||||
um.ID = ?", $Cur['ID']);
|
||||
um.ID = ?
|
||||
", "$Comment\n\n", Cur['ID']
|
||||
);
|
||||
|
||||
return ['enabled' => true, 'user_id' => $Cur['ID'], 'username' => $Cur['Username']];
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ abstract class AbstractCollage extends \Gazelle\Base {
|
||||
}
|
||||
|
||||
public function updateSequence(string $series): int {
|
||||
$series = parseUrlArgs($series, 'li[]');
|
||||
$series = $this->parseUrlArgs($series, 'li[]');
|
||||
if (empty($series)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -185,4 +185,37 @@ abstract class AbstractCollage extends \Gazelle\Base {
|
||||
);
|
||||
return self::$db->affected_rows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate an array from a query string (everything that follow '?')
|
||||
* This reimplements parse_str() and side-steps the issue of max_input_vars limits.
|
||||
*
|
||||
* Example:
|
||||
* in: li[]=14&li[]=31&li[]=58&li[]=68&li[]=69&li[]=54&li[]=5, param=li[]
|
||||
* parsed: ['li[]' => ['14', '31, '58', '68', '69', '5']]
|
||||
* out: ['14', '31, '58', '68', '69', '5']
|
||||
*
|
||||
* @param string $urlArgs query string from url
|
||||
* @param string $param url param to extract
|
||||
* @return array hydrated equivalent
|
||||
*/
|
||||
protected function parseUrlArgs(string $urlArgs, string $param): array {
|
||||
if (empty($urlArgs)) {
|
||||
return [];
|
||||
}
|
||||
$list = [];
|
||||
$pairs = explode('&', $urlArgs);
|
||||
foreach ($pairs as $p) {
|
||||
[$name, $value] = explode('=', $p, 2);
|
||||
if (!isset($list[$name])) {
|
||||
$list[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($list[$name])) {
|
||||
$list[$name] = [$list[$name]];
|
||||
}
|
||||
$list[$name][] = $value;
|
||||
}
|
||||
}
|
||||
return array_key_exists($param, $list) ? $list[$param] : [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Gazelle\Manager;
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
class User extends \Gazelle\Base {
|
||||
|
||||
protected const CACHE_STAFF = 'pm_staff_list';
|
||||
@@ -770,7 +772,7 @@ class User extends \Gazelle\Base {
|
||||
if (is_null($current)) {
|
||||
// User was not already warned
|
||||
self::$cache->delete_value("u_$userId");
|
||||
$warnTime = time_plus($duration);
|
||||
$warnTime = Time::timePlus($duration);
|
||||
$warning = "Warned until $warnTime";
|
||||
} else {
|
||||
// User was already warned, appending new warning to old.
|
||||
|
||||
@@ -410,9 +410,9 @@ class Recovery extends Base {
|
||||
/* staff note */
|
||||
self::$db->prepared_query("
|
||||
UPDATE users_info
|
||||
SET AdminComment = CONCAT(?, AdminComment)
|
||||
SET AdminComment = CONCAT(now(), ' - ', ?, AdminComment)
|
||||
WHERE UserID = ?
|
||||
", sqltime() . " mapped to previous id $prevUserId by $admin_username\n\n", $siteUserId
|
||||
", "mapped to previous id $prevUserId by $admin_username\n\n", $siteUserId
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -486,15 +486,15 @@ class Request extends BaseObject {
|
||||
);
|
||||
if (self::$db->affected_rows() == 1) {
|
||||
$this->informRequestFillerReduction($bounty, $staffName);
|
||||
$message = sprintf("%s Refund of %s bounty (%s b) on %s by %s\n\n",
|
||||
sqltime(), \Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
$message = sprintf("Refund of %s bounty (%s b) on %s by %s\n\n",
|
||||
\Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
);
|
||||
self::$db->prepared_query("
|
||||
UPDATE users_info ui
|
||||
INNER JOIN users_leech_stats uls USING (UserID)
|
||||
SET
|
||||
uls.Uploaded = uls.Uploaded + ?,
|
||||
ui.AdminComment = concat(?, ui.AdminComment)
|
||||
ui.AdminComment = concat(now(), ' - ', ?, ui.AdminComment)
|
||||
WHERE ui.UserId = ?
|
||||
", $bounty, $message, $userId
|
||||
);
|
||||
@@ -518,12 +518,12 @@ class Request extends BaseObject {
|
||||
);
|
||||
if (self::$db->affected_rows() == 1) {
|
||||
$this->informRequestFillerReduction($bounty, $staffName);
|
||||
$message = sprintf("%s Removal of %s bounty (%s b) on %s by %s\n\n",
|
||||
sqltime(), \Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
$message = sprintf("Removal of %s bounty (%s b) on %s by %s\n\n",
|
||||
\Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
);
|
||||
self::$db->prepared_query("
|
||||
UPDATE users_info ui SET
|
||||
ui.AdminComment = concat(?, ui.AdminComment)
|
||||
ui.AdminComment = concat(now(), ' - ', ?, ui.AdminComment)
|
||||
WHERE ui.UserId = ?
|
||||
", $message, $userId
|
||||
);
|
||||
@@ -548,15 +548,15 @@ class Request extends BaseObject {
|
||||
if (!$fillerId) {
|
||||
return;
|
||||
}
|
||||
$message = sprintf("%s Reduction of %s bounty (%s b) on filled request %s by %s\n\n",
|
||||
sqltime(), \Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
$message = sprintf("Reduction of %s bounty (%s b) on filled request %s by %s\n\n",
|
||||
\Format::get_size($bounty), $bounty, $this->url(), $staffName
|
||||
);
|
||||
self::$db->prepared_query("
|
||||
UPDATE users_info ui
|
||||
INNER JOIN users_leech_stats uls USING (UserID)
|
||||
SET
|
||||
uls.Uploaded = uls.Uploaded - ?,
|
||||
ui.AdminComment = concat(?, ui.AdminComment)
|
||||
ui.AdminComment = concat(now(), ' - ', ?, ui.AdminComment)
|
||||
WHERE ui.UserId = ?
|
||||
", $bounty, $message, $fillerId
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Gazelle;
|
||||
|
||||
use Gazelle\Exception\UserCreatorException;
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
class UserCreator extends Base {
|
||||
protected $newInstall;
|
||||
@@ -113,7 +114,7 @@ class UserCreator extends Base {
|
||||
$infoArgs[] = $this->id;
|
||||
if ($this->adminComment) {
|
||||
$infoFields[] = 'AdminComment';
|
||||
$infoArgs[] = sqltime() . " - " . implode("\n", $this->adminComment);
|
||||
$infoArgs[] = Time::sqlTime() . " - " . implode("\n", $this->adminComment);
|
||||
}
|
||||
self::$db->prepared_query("
|
||||
INSERT INTO users_info
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Mail;
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
class AutoEnable {
|
||||
|
||||
@@ -231,7 +232,8 @@ class AutoEnable {
|
||||
UPDATE users_enable_requests SET Token = NULL WHERE Token = ?
|
||||
", $Token
|
||||
);
|
||||
if ($Timestamp < time_minus(3600 * 48)) {
|
||||
|
||||
if ($Timestamp < Time::timeMinus(3600 * 48)) {
|
||||
// Old request
|
||||
(new \Gazelle\User($UserID))->addStaffNote("Tried to use an expired enable token from ".$_SERVER['REMOTE_ADDR'])->modify();
|
||||
$Err = "Token has expired. Please visit ".BOT_DISABLED_CHAN." on ".BOT_SERVER." to discuss this with staff.";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Crypto;
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
// 1. Basic sanity checks and initialization
|
||||
|
||||
@@ -145,7 +146,7 @@ if (DEBUG_MODE || ($Viewer && $Viewer->permitted('site_debug'))) {
|
||||
|
||||
// for sections/tools/development/process_info.php
|
||||
$Cache->cache_value('php_' . getmypid(), [
|
||||
'start' => sqltime(),
|
||||
'start' => Time::sqlTime(),
|
||||
'document' => $Document,
|
||||
'query' => $_SERVER['QUERY_STRING'],
|
||||
'get' => $_GET,
|
||||
|
||||
88
lib/util.php
88
lib/util.php
@@ -302,39 +302,6 @@ function add_json_info($Json) {
|
||||
return $Json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate an array from a query string (everything that follow '?')
|
||||
* This reimplements parse_str() and side-steps the issue of max_input_vars limits.
|
||||
*
|
||||
* Example:
|
||||
* in: li[]=14&li[]=31&li[]=58&li[]=68&li[]=69&li[]=54&li[]=5, param=li[]
|
||||
* parsed: ['li[]' => ['14', '31, '58', '68', '69', '5']]
|
||||
* out: ['14', '31, '58', '68', '69', '5']
|
||||
*
|
||||
* @param string $urlArgs query string from url
|
||||
* @param string $param url param to extract
|
||||
* @return array hydrated equivalent
|
||||
*/
|
||||
function parseUrlArgs(string $urlArgs, string $param): array {
|
||||
if (empty($urlArgs)) {
|
||||
return [];
|
||||
}
|
||||
$list = [];
|
||||
$pairs = explode('&', $urlArgs);
|
||||
foreach ($pairs as $p) {
|
||||
[$name, $value] = explode('=', $p, 2);
|
||||
if (!isset($list[$name])) {
|
||||
$list[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($list[$name])) {
|
||||
$list[$name] = [$list[$name]];
|
||||
}
|
||||
$list[$name][] = $value;
|
||||
}
|
||||
}
|
||||
return array_key_exists($param, $list) ? $list[$param] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function that unserializes an array, and then if the unserialization fails,
|
||||
* it'll then return an empty array instead of a null or false which will break downstream
|
||||
@@ -488,10 +455,6 @@ function proxyCheck(string $IP): bool {
|
||||
|
||||
/*** Time and date functions ***/
|
||||
|
||||
function time_ago($TimeStamp) {
|
||||
return Time::timeAgo($TimeStamp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a <span> by default but can optionally return the raw time
|
||||
* difference in text (e.g. "16 hours and 28 minutes", "1 day, 18 hours").
|
||||
@@ -500,41 +463,6 @@ function time_diff($TimeStamp, $Levels = 2, $Span = true, $Lowercase = false, $S
|
||||
return Time::timeDiff($TimeStamp, $Levels, $Span, $Lowercase, $StartTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a number of hours, convert it to a human readable time of
|
||||
* years, months, days, etc.
|
||||
*
|
||||
* @param int $Hours
|
||||
* @param int $Levels
|
||||
* @param bool $Span
|
||||
* @return string
|
||||
*/
|
||||
function convert_hours($Hours,$Levels=2,$Span=true) {
|
||||
return Time::convertHours($Hours, $Levels, $Span);
|
||||
}
|
||||
|
||||
/* SQL utility functions */
|
||||
|
||||
function time_plus($Offset) {
|
||||
return Time::timePlus($Offset);
|
||||
}
|
||||
|
||||
function time_minus($Offset, $Fuzzy = false) {
|
||||
return Time::timeMinus($Offset, $Fuzzy);
|
||||
}
|
||||
|
||||
function sqltime($timestamp = false) {
|
||||
return Time::sqlTime($timestamp);
|
||||
}
|
||||
|
||||
function validDate($DateString) {
|
||||
return Time::validDate($DateString);
|
||||
}
|
||||
|
||||
function is_valid_date($Date) {
|
||||
return Time::isValidDate($Date);
|
||||
}
|
||||
|
||||
/*** Paranoia functions ***/
|
||||
|
||||
// The following are used throughout the site:
|
||||
@@ -812,20 +740,6 @@ function get_group_info($GroupID, $RevisionID = 0, $PersonalProperties = true, $
|
||||
return [$TorrentDetails, $TorrentList];
|
||||
}
|
||||
|
||||
function get_torrent_info($TorrentID, $RevisionID = 0, $PersonalProperties = true, $ApiCall = false) {
|
||||
$GroupInfo = get_group_info((new Gazelle\Manager\Torrent)->findById($TorrentID)->id(), $RevisionID, $PersonalProperties, $ApiCall);
|
||||
if (!$GroupInfo) {
|
||||
return null;
|
||||
}
|
||||
foreach ($GroupInfo[1] as &$Torrent) {
|
||||
//Remove unneeded entries
|
||||
if ($Torrent['ID'] != $TorrentID) {
|
||||
unset($GroupInfo[1][$Torrent['ID']]);
|
||||
}
|
||||
return $GroupInfo;
|
||||
}
|
||||
}
|
||||
|
||||
function get_group_requests($GroupID) {
|
||||
if (empty($GroupID) || !is_number($GroupID)) {
|
||||
return [];
|
||||
@@ -864,7 +778,7 @@ function geoip($IP): string {
|
||||
$Long = sprintf('%u', ip2long($IP));
|
||||
}
|
||||
if (!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
|
||||
return 'localhost';
|
||||
return 'XX';
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
if (!$Viewer->permitted('users_warn')) {
|
||||
error(404);
|
||||
}
|
||||
@@ -28,7 +30,7 @@ $Reason = trim($_POST['reason']);
|
||||
$PrivateMessage = trim($_POST['privatemessage']);
|
||||
if ($Length !== 'verbal') {
|
||||
$Time = (int)$Length * (7 * 24 * 60 * 60);
|
||||
$WarnTime = time_plus($Time);
|
||||
$WarnTime = Time::timePlus($Time);
|
||||
$userMan->warn($user->id(), $Time, "$url - $Reason", $Viewer->username());
|
||||
$subject = 'You have received a warning';
|
||||
$message = "You have received a $Length week warning for [url=$url]this comment[/url].\n\n[quote]{$PrivateMessage}[/quote]";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
$search = new Gazelle\Search\Forum($Viewer);
|
||||
$search->setSearchType($_GET['type'] ?? 'title')
|
||||
->setSearchText(trim($_GET['search']) ?? '');
|
||||
@@ -26,37 +28,33 @@ if (!empty($userSearch)) {
|
||||
|
||||
$threadCreatedBefore = $_GET['thread_created_before'] ?? '';
|
||||
if (!empty($threadCreatedBefore)) {
|
||||
if (is_valid_date($threadCreatedBefore)) {
|
||||
$search->setThreadCreatedBefore($threadCreatedBefore);
|
||||
} else {
|
||||
if (!Time::isValidDate($threadCreatedBefore)) {
|
||||
error("Incorrect topic created before date");
|
||||
}
|
||||
$search->setThreadCreatedBefore($threadCreatedBefore);
|
||||
}
|
||||
$threadCreatedAfter = $_GET['thread_created_after'] ?? '';
|
||||
if (!empty($threadCreatedAfter)) {
|
||||
if (is_valid_date($threadCreatedAfter)) {
|
||||
$search->setThreadCreatedAfter($threadCreatedAfter);
|
||||
} else {
|
||||
if (!Time::isValidDate($threadCreatedAfter)) {
|
||||
error("Incorrect topic created after date");
|
||||
}
|
||||
$search->setThreadCreatedAfter($threadCreatedAfter);
|
||||
}
|
||||
|
||||
if ($search->isBodySearch()) {
|
||||
$postCreatedBefore = $_GET['post_created_before'] ?? '';
|
||||
if (!empty($postCreatedBefore)) {
|
||||
if (is_valid_date($postCreatedBefore)) {
|
||||
$search->setPostCreatedBefore($postCreatedBefore);
|
||||
} else {
|
||||
if (!Time::isValidDate($postCreatedBefore)) {
|
||||
error("Incorrect post created before date");
|
||||
}
|
||||
$search->setPostCreatedBefore($postCreatedBefore);
|
||||
}
|
||||
$postCreatedAfter = $_GET['post_created_after'] ?? '';
|
||||
if (!empty($postCreatedAfter)) {
|
||||
if (is_valid_date($postCreatedAfter)) {
|
||||
$search->setPostCreatedAfter($postCreatedAfter);
|
||||
} else {
|
||||
if (!Time::isValidDate($postCreatedAfter)) {
|
||||
error("Incorrect post created after date");
|
||||
}
|
||||
$search->setPostCreatedAfter($postCreatedAfter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
if (!$Viewer->permitted('users_warn')) {
|
||||
error(403);
|
||||
}
|
||||
@@ -39,7 +41,7 @@ if ($WarningLength !== 'verbal') {
|
||||
$userMan->warn($user->id(), $Time, "{$post->url()} - $Reason", $Viewer->username());
|
||||
$subject = 'You have received a warning';
|
||||
$message = "You have received a $WarningLength week warning for [url={$post->url()}]this post[/url].";
|
||||
$warned = "Warned until " . time_plus($Time);
|
||||
$warned = "Warned until " . Time::timePlus($Time);
|
||||
} else {
|
||||
$subject = 'You have received a verbal warning';
|
||||
$message = "You have received a verbal warning for [url={$post->url()}]this post[/url].";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
if (!$Viewer->permitted('users_mod')) {
|
||||
error(404);
|
||||
}
|
||||
@@ -39,7 +41,8 @@ View::show_header('Top 10 Torrents history!');
|
||||
if (!empty($_GET['date'])) {
|
||||
$Date = $_GET['date'];
|
||||
$SQLTime = $Date.' 00:00:00';
|
||||
if (!validDate($SQLTime)) {
|
||||
|
||||
if (!Time::validDate($SQLTime)) {
|
||||
error('Something is wrong with the date you provided');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
$TorrentID = (int)$_GET['torrentid'];
|
||||
if (!$TorrentID) {
|
||||
error(404);
|
||||
@@ -32,7 +35,7 @@ if ($Viewer->id() != $UserID && !$Viewer->permitted('torrents_delete')) {
|
||||
error(403);
|
||||
}
|
||||
|
||||
if (time_ago($Time) > 3600 * 24 * 7 && !$Viewer->permitted('torrents_delete')) { // Should this be torrents_delete or torrents_delete_fast?
|
||||
if (Time::timeAgo($Time) > 3600 * 24 * 7 && !$Viewer->permitted('torrents_delete')) { // Should this be torrents_delete or torrents_delete_fast?
|
||||
error('You can no longer delete this torrent as it has been uploaded for over a week. If you now think there is a problem, please report the torrent instead.');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Gazelle\Util\Mail;
|
||||
use Gazelle\Util\Time;
|
||||
|
||||
authorize();
|
||||
|
||||
@@ -601,7 +602,7 @@ if (!(count($set) || count($leechSet) || count($editSummary)) && $reason) {
|
||||
if (count($editSummary)) {
|
||||
$summary = implode(', ', $editSummary) . ' by ' . $Viewer->username();
|
||||
$set[] = "AdminComment = ?";
|
||||
$args[] = sqltime() . ' - ' . ucfirst($summary) . ($reason ? "\nReason: $reason" : '') . "\n\n$adminComment";
|
||||
$args[] = Time::sqlTime() . ' - ' . ucfirst($summary) . ($reason ? "\nReason: $reason" : '') . "\n\n$adminComment";
|
||||
} elseif ($adminComment !== $cur['admincomment']) {
|
||||
$set[] = "AdminComment = ?";
|
||||
$args[] = $adminComment;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{{ header('Edit request bounty') }}
|
||||
<div class="thin">
|
||||
<div class="header">
|
||||
<h2>Edit request bounty</h2>
|
||||
<h3><a href="requests.php?action=view&id={{ request.id }}">{{ request.title }}</a></h3>
|
||||
<h2><a href="requests.php">Request</a> › {{ request.categoryName }} › {{ request.link|raw }} › edit bounty</h2>
|
||||
<br />
|
||||
</div>
|
||||
|
||||
<div class="box pad">
|
||||
|
||||
Reference in New Issue
Block a user