Empty commit

This commit is contained in:
Git 2013-09-12 08:00:52 +00:00
parent b051b7a7c4
commit fcb95ba306
6 changed files with 194 additions and 248 deletions

View File

@ -1,4 +1,7 @@
<?php <?php
if (PHP_VERSION_ID < 50400) {
die("Gazelle requires PHP 5.4 or later to function properly");
}
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
// Main settings // Main settings
@ -56,13 +59,7 @@ if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 80) {
} }
// Site settings // Site settings
if (PHP_VERSION_ID < 50307) { define('CRYPT_HASH_PREFIX', '$2y$07$');
die("PHP version 5.3.7 or later is highly recommended for gazelle's password hashing methods.".
" Comment out line ".__LINE__." in file ".__FILE__." if you want to continue to use this version.");
define('CRYPT_HASH_PREFIX', '$2a$07$'); // Crypt salt prefix for hash settings. See http://php.net/crypt for details
} else {
define('CRYPT_HASH_PREFIX', '$2y$07$');
}
define('DEBUG_MODE', false); //Set to false if you dont want everyone to see debug information, can be overriden with 'site_debug' define('DEBUG_MODE', false); //Set to false if you dont want everyone to see debug information, can be overriden with 'site_debug'
define('DEBUG_WARNINGS', true); //Set to true if you want to see PHP warnings in the footer define('DEBUG_WARNINGS', true); //Set to true if you want to see PHP warnings in the footer
define('OPEN_REGISTRATION', true); //Set to false to disable open regirstration, true to allow anyone to register define('OPEN_REGISTRATION', true); //Set to false to disable open regirstration, true to allow anyone to register

View File

@ -35,16 +35,16 @@ class Donations {
public static function regular_donate($UserID, $DonationAmount, $Source, $Reason, $Currency = "EUR") { public static function regular_donate($UserID, $DonationAmount, $Source, $Reason, $Currency = "EUR") {
self::donate($UserID, array( self::donate($UserID, array(
"Source" => $Source, "Source" => $Source,
"Price" => $DonationAmount, "Price" => $DonationAmount,
"Currency" => $Currency, "Currency" => $Currency,
"Source" => $Source, "Source" => $Source,
"Reason" => $Reason, "Reason" => $Reason,
"SendPM" => true)); "SendPM" => true));
} }
public static function donate($UserID, $Args) { public static function donate($UserID, $Args) {
$UserID = (int) $UserID; $UserID = (int)$UserID;
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query("SELECT 1 FROM users_main WHERE ID = '$UserID' LIMIT 1"); G::$DB->query("SELECT 1 FROM users_main WHERE ID = '$UserID' LIMIT 1");
@ -76,14 +76,14 @@ public static function donate($UserID, $Args) {
$DonorPoints = $Rank; $DonorPoints = $Rank;
$AdjustedRank = $Rank >= MAX_EXTRA_RANK ? MAX_EXTRA_RANK : $Rank; $AdjustedRank = $Rank >= MAX_EXTRA_RANK ? MAX_EXTRA_RANK : $Rank;
G::$DB->query(" G::$DB->query("
INSERT INTO users_donor_ranks INSERT INTO users_donor_ranks
(UserID, Rank, TotalRank, DonationTime) (UserID, Rank, TotalRank, DonationTime)
VALUES VALUES
('$UserID', '$AdjustedRank', '$TotalRank', '$Date') ('$UserID', '$AdjustedRank', '$TotalRank', '$Date')
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Rank = '$AdjustedRank', Rank = '$AdjustedRank',
TotalRank = '$TotalRank', TotalRank = '$TotalRank',
DonationTime = '$Date'"); DonationTime = '$Date'");
} }
else { else {
// Donations from the store get donor points directly, no need to calculate them // Donations from the store get donor points directly, no need to calculate them
@ -106,17 +106,17 @@ public static function donate($UserID, $Args) {
$AdjustedRank = $CurrentRank + $DonorPoints; $AdjustedRank = $CurrentRank + $DonorPoints;
} }
G::$DB->query(" G::$DB->query("
INSERT INTO users_donor_ranks INSERT INTO users_donor_ranks
(UserID, Rank, TotalRank, DonationTime) (UserID, Rank, TotalRank, DonationTime)
VALUES VALUES
('$UserID', '$AdjustedRank', '$DonorPoints', '$Date') ('$UserID', '$AdjustedRank', '$DonorPoints', '$Date')
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Rank = '$AdjustedRank', Rank = '$AdjustedRank',
TotalRank = TotalRank + '$DonorPoints', TotalRank = TotalRank + '$DonorPoints',
DonationTime = '$Date'"); DonationTime = '$Date'");
} }
// Clear the rank cache key // Donor cache key is outdated
G::$Cache->delete_value("donor_rank_$UserID"); G::$Cache->delete_value("donor_info_$UserID");
// Get their rank // Get their rank
$Rank = self::get_rank($UserID); $Rank = self::get_rank($UserID);
@ -145,30 +145,29 @@ public static function donate($UserID, $Args) {
// Lastly, add this donation to our history // Lastly, add this donation to our history
G::$DB->query(" G::$DB->query("
INSERT INTO donations INSERT INTO donations
(UserID, Amount, Source, Reason, Currency, Email, Time, AddedBy, Rank, TotalRank) (UserID, Amount, Source, Reason, Currency, Email, Time, AddedBy, Rank, TotalRank)
VALUES VALUES
('$UserID', '$ConvertedPrice', '$Source', '$Reason', '$Currency', '$Email', '$Date', '$AddedBy', '$DonorPoints', '$TotalRank')"); ('$UserID', '$ConvertedPrice', '$Source', '$Reason', '$Currency', '$Email', '$Date', '$AddedBy', '$DonorPoints', '$TotalRank')");
// Clear their user cache keys because the users_info values has been modified // Clear their user cache keys because the users_info values has been modified
G::$Cache->delete_value("user_info_$UserID"); G::$Cache->delete_value("user_info_$UserID");
G::$Cache->delete_value("user_info_heavy_$UserID"); G::$Cache->delete_value("user_info_heavy_$UserID");
G::$Cache->delete_value("donor_rank_$UserID"); G::$Cache->delete_value("donor_info_$UserID");
G::$Cache->delete_value("donor_special_rank_$UserID");
} }
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
private static function calculate_special_rank($UserID) { private static function calculate_special_rank($UserID) {
$UserID = (int) $UserID; $UserID = (int)$UserID;
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
// Are they are special? // Are they are special?
G::$DB->query(" G::$DB->query("
SELECT TotalRank, SpecialRank SELECT TotalRank, SpecialRank
FROM users_donor_ranks FROM users_donor_ranks
WHERE UserID = '$UserID'"); WHERE UserID = '$UserID'");
if (G::$DB->has_results()) { if (G::$DB->has_results()) {
// Adjust their special rank depending on the total rank. // Adjust their special rank depending on the total rank.
list($TotalRank, $SpecialRank) = G::$DB->next_record(); list($TotalRank, $SpecialRank) = G::$DB->next_record();
@ -189,10 +188,10 @@ private static function calculate_special_rank($UserID) {
} }
// Make them special // Make them special
G::$DB->query(" G::$DB->query("
UPDATE users_donor_ranks UPDATE users_donor_ranks
SET SpecialRank = '$SpecialRank' SET SpecialRank = '$SpecialRank'
WHERE UserID = '$UserID'"); WHERE UserID = '$UserID'");
G::$Cache->delete_value("donor_special_rank_$UserID"); G::$Cache->delete_value("donor_info_$UserID");
} }
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
@ -208,24 +207,23 @@ public static function schedule() {
public static function expire_ranks() { public static function expire_ranks() {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
SELECT UserID, Rank SELECT UserID, Rank
FROM users_donor_ranks FROM users_donor_ranks
WHERE Rank > 1 WHERE Rank > 1
AND SpecialRank != 3 AND SpecialRank != 3
AND DonationTime < NOW() - INTERVAL 32 DAY"); AND DonationTime < NOW() - INTERVAL 32 DAY");
if (G::$DB->record_count() > 0) { if (G::$DB->record_count() > 0) {
$UserIDs = array(); $UserIDs = array();
while (list($UserID, $Rank) = G::$DB->next_record()) { while (list($UserID, $Rank) = G::$DB->next_record()) {
G::$Cache->delete_value("donor_rank_$UserID"); G::$Cache->delete_value("donor_info_$UserID");
G::$Cache->delete_value("donor_rewards_$UserID");
$UserIDs[] = $UserID; $UserIDs[] = $UserID;
} }
$In = implode(',', $UserIDs); $In = implode(',', $UserIDs);
G::$DB->query(" G::$DB->query("
UPDATE users_donor_ranks UPDATE users_donor_ranks
SET Rank = Rank - IF(Rank = " . MAX_RANK . ", 2, 1) SET Rank = Rank - IF(Rank = " . MAX_RANK . ", 2, 1)
WHERE UserID IN ($In)"); WHERE UserID IN ($In)");
} }
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
@ -239,45 +237,45 @@ public static function update_rank($UserID, $Rank, $TotalRank, $Reason) {
$TotalRank = (int)$TotalRank; $TotalRank = (int)$TotalRank;
self::donate($UserID, array( self::donate($UserID, array(
"Manipulation" => "Direct", "Manipulation" => "Direct",
"Rank" => $Rank, "Rank" => $Rank,
"TotalRank" => $TotalRank, "TotalRank" => $TotalRank,
"Reason" => $Reason, "Reason" => $Reason,
"Source" => "Modify Values", "Source" => "Modify Values",
"Currency" => "EUR")); "Currency" => "EUR"));
} }
public static function hide_stats($UserID) { public static function hide_stats($UserID) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
INSERT INTO users_donor_ranks INSERT INTO users_donor_ranks
(UserID, Hidden) (UserID, Hidden)
VALUES VALUES
('$UserID', '1') ('$UserID', '1')
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Hidden = '1'"); Hidden = '1'");
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
public static function show_stats($UserID) { public static function show_stats($UserID) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
INSERT INTO users_donor_ranks INSERT INTO users_donor_ranks
(UserID, Hidden) (UserID, Hidden)
VALUES VALUES
('$UserID', '0') ('$UserID', '0')
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Hidden = '0'"); Hidden = '0'");
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
public static function is_visible($UserID) { public static function is_visible($UserID) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
SELECT Hidden SELECT Hidden
FROM users_donor_ranks FROM users_donor_ranks
WHERE Hidden = '0' WHERE Hidden = '0'
AND UserID = '$UserID'"); AND UserID = '$UserID'");
$HasResults = G::$DB->has_results(); $HasResults = G::$DB->has_results();
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
return $HasResults; return $HasResults;
@ -292,65 +290,74 @@ public static function is_mod($UserID) {
return isset($Permissions['users_mod']) && $Permissions['users_mod']; return isset($Permissions['users_mod']) && $Permissions['users_mod'];
} }
/**
public static function get_rank($UserID) { * Put all the common donor info in the same cache key to save some cache calls
$Rank = G::$Cache->get_value("donor_rank_$UserID"); */
if ($Rank === false) { public static function get_donor_info($UserID) {
// Our cache class should prevent identical memcached requests
$DonorInfo = G::$Cache->get_value("donor_info_$UserID");
if ($DonorInfo === false) {
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT Rank, SpecialRank, TotalRank, DonationTime
FROM users_donor_ranks
WHERE UserID = '$UserID'");
if (G::$DB->has_results()) {
list($Rank, $SpecialRank, $TotalRank, $DonationTime) = G::$DB->next_record(MYSQLI_NUM, false);
} else {
$Rank = $SpecialRank = $TotalRank = $DonationTime = 0;
}
if (self::is_mod($UserID)) { if (self::is_mod($UserID)) {
$Rank = MAX_EXTRA_RANK; $Rank = MAX_EXTRA_RANK;
} else { $SpecialRank = MAX_SPECIAL_RANK;
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT Rank
FROM users_donor_ranks
WHERE UserID = '$UserID'");
list($Rank) = G::$DB->next_record();
G::$DB->set_query_id($QueryID);
} }
G::$Cache->cache_value("donor_rank_$UserID", $Rank, 0); G::$DB->query("
SELECT
IconMouseOverText,
AvatarMouseOverText,
CustomIcon,
CustomIconLink,
SecondAvatar
FROM donor_rewards
WHERE UserID = '$UserID'");
$Rewards = G::$DB->next_record(MYSQLI_ASSOC, false);
G::$DB->set_query_id($QueryID);
$DonorInfo = array(
'Rank' => (int)$Rank,
'SRank' => (int)$SpecialRank,
'TotRank' => (int)$TotalRank,
'Time' => $DonationTime,
'Rewards' => $Rewards);
G::$Cache->cache_value("donor_info_$UserID", $DonorInfo, 0);
} }
return $Rank; return $DonorInfo;
}
public static function get_rank($UserID) {
return self::get_donor_info($UserID)['Rank'];
} }
public static function get_special_rank($UserID) { public static function get_special_rank($UserID) {
$SpecialRank = G::$Cache->get_value("donor_special_rank_$UserID"); return self::get_donor_info($UserID)['SRank'];
if ($SpecialRank === false) {
if (self::is_mod($UserID)) {
$SpecialRank = MAX_SPECIAL_RANK;
} else {
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT SpecialRank
FROM users_donor_ranks
WHERE UserID = '$UserID'");
list($SpecialRank) = G::$DB->next_record();
G::$DB->set_query_id($QueryID);
}
G::$Cache->cache_value("donor_special_rank_$UserID", $SpecialRank, 0);
}
return $SpecialRank;
} }
public static function get_total_rank($UserID) { public static function get_total_rank($UserID) {
$QueryID = G::$DB->get_query_id(); return self::get_donor_info($UserID)['TotRank'];
G::$DB->query("
SELECT TotalRank
FROM users_donor_ranks
WHERE UserID = '$UserID'");
list($Rank) = G::$DB->next_record();
G::$DB->set_query_id($QueryID);
return $Rank;
} }
public static function get_donation_time($UserID) { public static function get_donation_time($UserID) {
$QueryID = G::$DB->get_query_id(); return self::get_donor_info($UserID)['Time'];
G::$DB->query(" }
SELECT DonationTime
FROM users_donor_ranks public static function get_personal_collages($UserID) {
WHERE UserID = '$UserID'"); $DonorInfo = self::get_donor_info($UserID);
list($DonationTime) = G::$DB->next_record(); if ($DonorInfo['SRank'] == MAX_SPECIAL_RANK) {
G::$DB->set_query_id($QueryID); $Collages = 5;
return $DonationTime; } else {
$Collages = min($DonorInfo['Rank'], 5); // One extra collage per donor rank up to 5
}
return $Collages;
} }
public static function get_titles($UserID) { public static function get_titles($UserID) {
@ -358,9 +365,9 @@ public static function get_titles($UserID) {
if ($Results === false) { if ($Results === false) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
SELECT Prefix, Suffix, UseComma SELECT Prefix, Suffix, UseComma
FROM donor_forum_usernames FROM donor_forum_usernames
WHERE UserID = '$UserID'"); WHERE UserID = '$UserID'");
$Results = G::$DB->next_record(); $Results = G::$DB->next_record();
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
G::$Cache->cache_value("donor_title_$UserID", $Results, 0); G::$Cache->cache_value("donor_title_$UserID", $Results, 0);
@ -415,23 +422,7 @@ public static function get_enabled_rewards($UserID) {
} }
public static function get_rewards($UserID) { public static function get_rewards($UserID) {
$Results = G::$Cache->get_value("donor_rewards_$UserID"); return self::get_donor_info($UserID)['Rewards'];
if ($Results === false) {
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT
IconMouseOverText,
AvatarMouseOverText,
CustomIcon,
CustomIconLink,
SecondAvatar
FROM donor_rewards
WHERE UserID = '$UserID'");
$Results = G::$DB->next_record();
G::$DB->set_query_id($QueryID);
G::$Cache->cache_value("donor_rewards_$UserID", $Results, 0);
}
return $Results;
} }
public static function get_profile_rewards($UserID) { public static function get_profile_rewards($UserID) {
@ -439,17 +430,17 @@ public static function get_profile_rewards($UserID) {
if ($Results === false) { if ($Results === false) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
SELECT SELECT
ProfileInfo1, ProfileInfo1,
ProfileInfoTitle1, ProfileInfoTitle1,
ProfileInfo2, ProfileInfo2,
ProfileInfoTitle2, ProfileInfoTitle2,
ProfileInfo3, ProfileInfo3,
ProfileInfoTitle3, ProfileInfoTitle3,
ProfileInfo4, ProfileInfo4,
ProfileInfoTitle4 ProfileInfoTitle4
FROM donor_rewards FROM donor_rewards
WHERE UserID = '$UserID'"); WHERE UserID = '$UserID'");
$Results = G::$DB->next_record(); $Results = G::$DB->next_record();
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
G::$Cache->cache_value("donor_profile_rewards_$UserID", $Results, 0); G::$Cache->cache_value("donor_profile_rewards_$UserID", $Results, 0);
@ -551,16 +542,16 @@ public static function update_rewards($UserID) {
if ($Counter > 0) { if ($Counter > 0) {
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query(" G::$DB->query("
INSERT INTO donor_rewards INSERT INTO donor_rewards
($Insert) ($Insert)
VALUES VALUES
($Values) ($Values)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
$Update"); $Update");
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
G::$Cache->delete_value("donor_profile_rewards_$UserID"); G::$Cache->delete_value("donor_profile_rewards_$UserID");
G::$Cache->delete_value("donor_rewards_$UserID"); G::$Cache->delete_value("donor_info_$UserID");
} }
@ -570,21 +561,21 @@ public static function update_titles($UserID, $Prefix, $Suffix, $UseComma) {
$Suffix = trim(db_string($Suffix)); $Suffix = trim(db_string($Suffix));
$UseComma = empty($UseComma) ? true : false; $UseComma = empty($UseComma) ? true : false;
G::$DB->query(" G::$DB->query("
INSERT INTO donor_forum_usernames INSERT INTO donor_forum_usernames
(UserID, Prefix, Suffix, UseComma) (UserID, Prefix, Suffix, UseComma)
VALUES VALUES
('$UserID', '$Prefix', '$Suffix', '$UseComma') ('$UserID', '$Prefix', '$Suffix', '$UseComma')
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
Prefix = '$Prefix', Prefix = '$Prefix',
Suffix = '$Suffix', Suffix = '$Suffix',
UseComma = '$UseComma'"); UseComma = '$UseComma'");
G::$Cache->delete_value("donor_title_$UserID"); G::$Cache->delete_value("donor_title_$UserID");
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
} }
public static function get_donation_history($UserID) { public static function get_donation_history($UserID) {
$UserID = (int) $UserID; $UserID = (int)$UserID;
if (empty($UserID)) { if (empty($UserID)) {
error(404); error(404);
} }
@ -594,33 +585,41 @@ public static function get_donation_history($UserID) {
FROM donations FROM donations
WHERE UserID = '$UserID' WHERE UserID = '$UserID'
ORDER BY Time DESC"); ORDER BY Time DESC");
$DonationHistory = G::$DB->to_array(); $DonationHistory = G::$DB->to_array(false, MYSQLI_ASSOC, false);
G::$DB->set_query_id($QueryID); G::$DB->set_query_id($QueryID);
return $DonationHistory; return $DonationHistory;
} }
public static function get_rank_expiration($UserID) { public static function get_rank_expiration($UserID) {
$UserID = (int) $UserID; $DonorInfo = self::get_donor_info($UserID);
$QueryID = G::$DB->get_query_id(); if ($DonorInfo['SRank'] == MAX_SPECIAL_RANK || $DonorInfo['Rank'] == 1) {
G::$DB->query("SELECT Rank, SpecialRank, (DonationTime + INTERVAL 32 DAY) AS Expiration FROM users_donor_ranks WHERE UserID = '$UserID'"); $Return = 'never';
$Return = ""; } elseif ($DonorInfo['Time']) {
if (G::$DB->has_results()) { $ExpireTime = strtotime($DonorInfo['Time']) + 2764800;
list($Rank, $SpecialRank, $Expiration) = G::$DB->next_record(); if ($ExpireTime - time() < 60) {
$Expiration = time_diff($Expiration); $Return = 'soon';
if ($Expiration != "Never") { } else {
$Expiration = "in " . $Expiration; $Expiration = time_diff($ExpireTime); // 32 days
$Return = "in $Expiration";
} }
$Return = $SpecialRank == MAX_SPECIAL_RANK || $Rank == 1 ? "Never" : $Expiration; } else {
$Return = '';
} }
G::$DB->set_query_id($QueryID);
return $Return; return $Return;
} }
public static function get_leaderboard_position($UserID) { public static function get_leaderboard_position($UserID) {
$UserID = (int) $UserID; $UserID = (int)$UserID;
$QueryID = G::$DB->get_query_id(); $QueryID = G::$DB->get_query_id();
G::$DB->query("SET @RowNum := 0"); G::$DB->query("SET @RowNum := 0");
G::$DB->query("SELECT Position FROM (SELECT d.UserID, @RowNum := @RowNum + 1 AS Position FROM users_donor_ranks d ORDER BY TotalRank DESC) l WHERE UserID = '$UserID'"); G::$DB->query("
SELECT Position
FROM (
SELECT d.UserID, @RowNum := @RowNum + 1 AS Position
FROM users_donor_ranks d
ORDER BY TotalRank DESC
) l
WHERE UserID = '$UserID'");
if (G::$DB->has_results()) { if (G::$DB->has_results()) {
list($Position) = G::$DB->next_record(); list($Position) = G::$DB->next_record();
} else { } else {
@ -631,11 +630,7 @@ public static function get_leaderboard_position($UserID) {
} }
public static function is_donor($UserID) { public static function is_donor($UserID) {
$QueryID = G::$DB->get_query_id(); return self::get_rank($UserID) > 0;
G::$DB->query("SELECT 1 FROM users_donor_ranks WHERE UserID = '$UserID'");
$HasResults = G::$DB->has_results();
G::$DB->set_query_id($QueryID);
return $HasResults;
} }
public static function currency_exchange($Amount, $Currency) { public static function currency_exchange($Amount, $Currency) {

View File

@ -150,7 +150,7 @@ public static function render_donation_history($DonationHistory) {
<? foreach ($DonationHistory as $Donation) { ?> <? foreach ($DonationHistory as $Donation) { ?>
<tr class="row<?=$Row?>"> <tr class="row<?=$Row?>">
<td> <td>
<?=$Donation['Source']?> (<?=Users::format_username($Donation['AddedBy'])?>) <?=display_str($Donation['Source'])?> (<?=Users::format_username($Donation['AddedBy'])?>)
</td> </td>
<td> <td>
<?=$Donation['Time']?> <?=$Donation['Time']?>
@ -165,10 +165,10 @@ public static function render_donation_history($DonationHistory) {
<?=$Donation['TotalRank']?> <?=$Donation['TotalRank']?>
</td> </td>
<td> <td>
<?=$Donation['Email']?> <?=display_str($Donation['Email'])?>
</td> </td>
<td> <td>
<?=$Donation['Reason']?> <?=display_str($Donation['Reason'])?>
</td> </td>
</tr> </tr>
<? <?

View File

@ -47,7 +47,6 @@ public static function get_permissions($PermissionID) {
* @return array Mapping of PermissionName=>bool/int * @return array Mapping of PermissionName=>bool/int
*/ */
public static function get_permissions_for_user($UserID, $CustomPermissions = false) { public static function get_permissions_for_user($UserID, $CustomPermissions = false) {
$UserInfo = Users::user_info($UserID); $UserInfo = Users::user_info($UserID);
// Fetch custom permissions if they weren't passed in. // Fetch custom permissions if they weren't passed in.
@ -65,13 +64,13 @@ public static function get_permissions_for_user($UserID, $CustomPermissions = fa
$CustomPermissions = unserialize($CustomPermissions); $CustomPermissions = unserialize($CustomPermissions);
} }
$Permissions = Permissions::get_permissions($UserInfo['PermissionID']); $Permissions = self::get_permissions($UserInfo['PermissionID']);
// Manage 'special' inherited permissions // Manage 'special' inherited permissions
$BonusPerms = array(); $BonusPerms = array();
$BonusCollages = 0; $BonusCollages = 0;
foreach ($UserInfo['ExtraClasses'] as $PermID => $Value) { foreach ($UserInfo['ExtraClasses'] as $PermID => $Value) {
$ClassPerms = Permissions::get_permissions($PermID); $ClassPerms = self::get_permissions($PermID);
$BonusCollages += $ClassPerms['Permissions']['MaxCollages']; $BonusCollages += $ClassPerms['Permissions']['MaxCollages'];
unset($ClassPerms['Permissions']['MaxCollages']); unset($ClassPerms['Permissions']['MaxCollages']);
$BonusPerms = array_merge($BonusPerms, $ClassPerms['Permissions']); $BonusPerms = array_merge($BonusPerms, $ClassPerms['Permissions']);
@ -83,61 +82,23 @@ public static function get_permissions_for_user($UserID, $CustomPermissions = fa
// This is legacy donor cruft // This is legacy donor cruft
if ($UserInfo['Donor']) { if ($UserInfo['Donor']) {
$DonorPerms = Permissions::get_permissions(DONOR); $DonorPerms = self::get_permissions(DONOR);
} else { } else {
$DonorPerms = array('Permissions' => array()); $DonorPerms = array('Permissions' => array());
} }
$IsMod = isset($Permissions['Permissions']['users_mod']) && $Permissions['Permissions']['users_mod']; $MaxCollages = $Permissions['Permissions']['MaxCollages'] + $BonusCollages;
$DonorCollages = self::get_personal_collages($UserID, $IsMod);
$MaxCollages = $Permissions['Permissions']['MaxCollages'] + $BonusCollages + $DonorCollages;
if (isset($CustomPermissions['MaxCollages'])) { if (isset($CustomPermissions['MaxCollages'])) {
$MaxCollages += $CustomPermissions['MaxCollages']; $MaxCollages += $CustomPermissions['MaxCollages'];
} }
$Permissions['MaxCollages'] = $MaxCollages;
//Combine the permissions //Combine the permissions
return array_merge( return array_merge(
$Permissions['Permissions'], $Permissions['Permissions'],
$BonusPerms, $BonusPerms,
$CustomPermissions, $CustomPermissions,
$DonorPerms['Permissions'], $DonorPerms['Permissions']);
array('MaxCollages' => $MaxCollages));
}
private static function get_personal_collages($UserID, $HasAll) {
$QueryID = G::$DB->get_query_id();
if (!$HasAll) {
$SpecialRank = G::$Cache->get_value("donor_special_rank_$UserID");
if ($SpecialRank === false) {
G::$DB->query("SELECT SpecialRank FROM users_donor_ranks WHERE UserID = '$UserID'");
list($SpecialRank) = G::$DB->next_record();
$HasAll = $SpecialRank == MAX_SPECIAL_RANK ? true : false;
G::$Cache->cache_value("donor_special_rank_$UserID", $SpecialRank, 0);
}
} else {
G::$Cache->cache_value("donor_special_rank_$UserID", MAX_SPECIAL_RANK, 0);
}
if ($HasAll) {
$Collages = 5;
} else {
$Collages = 0;
$Rank = G::$Cache->get_value("donor_rank_$UserID");
if ($Rank === false) {
G::$DB->query("SELECT Rank FROM users_donor_ranks WHERE UserID = '$UserID'");
list($Rank) = G::$DB->next_record();
G::$Cache->cache_value("donor_rank_$UserID", $Rank, 0);
}
$Rank = min($Rank, 5);
for ($i = 1; $i <= $Rank; $i++) {
$Collages++;
}
}
G::$DB->set_query_id($QueryID);
return $Collages;
} }
} }
?> ?>

View File

@ -173,11 +173,8 @@
$LightInfo = Users::user_info($LoggedUser['ID']); $LightInfo = Users::user_info($LoggedUser['ID']);
$HeavyInfo = Users::user_heavy_info($LoggedUser['ID']); $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
// Get user permissions
$Permissions = Permissions::get_permissions($LightInfo['PermissionID']);
// Create LoggedUser array // Create LoggedUser array
$LoggedUser = array_merge($HeavyInfo, $LightInfo, $Permissions, $UserStats); $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
$LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']); $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
@ -187,15 +184,10 @@
&& time() < strtotime($LoggedUser['RatioWatchEnds']) && time() < strtotime($LoggedUser['RatioWatchEnds'])
&& ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded'] && ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
); );
if (!isset($LoggedUser['ID'])) {
$Debug->log_var($LightInfo, 'LightInfo');
$Debug->log_var($HeavyInfo, 'HeavyInfo');
$Debug->log_var($Permissions, 'Permissions');
$Debug->log_var($UserStats, 'UserStats');
}
// Load in the permissions // Load in the permissions
$LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']); $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
$LoggedUser['Permissions']['MaxCollages'] += Donations::get_personal_collages($LoggedUser['ID'], check_perms('users_mod'));
// Change necessary triggers in external components // Change necessary triggers in external components
$Cache->CanClear = check_perms('admin_clear_cache'); $Cache->CanClear = check_perms('admin_clear_cache');

View File

@ -333,6 +333,7 @@
} }
$ClearStaffIDCache = true; $ClearStaffIDCache = true;
} }
$Cache->delete_value("donor_info_$UserID");
} }
if ($Username != $Cur['Username'] && check_perms('users_edit_usernames', $Cur['Class'] - 1)) { if ($Username != $Cur['Username'] && check_perms('users_edit_usernames', $Cur['Class'] - 1)) {