diff --git a/classes/autoenable.class.php b/classes/autoenable.class.php index 94d6945c3..5af9bba90 100644 --- a/classes/autoenable.class.php +++ b/classes/autoenable.class.php @@ -2,354 +2,357 @@ class AutoEnable { - // Constants for database values - const APPROVED = 1; - const DENIED = 2; - const DISCARDED = 3; + // Constants for database values + const APPROVED = 1; + const DENIED = 2; + const DISCARDED = 3; - // Cache key to store the number of enable requests - const CACHE_KEY_NAME = 'num_enable_requests'; + // Cache key to store the number of enable requests + const CACHE_KEY_NAME = 'num_enable_requests'; - // The default request rejected message - const REJECTED_MESSAGE = "Your request to re-enable your account has been rejected.
This may be because a request is already pending for your username, or because a recent request was denied.

You are encouraged to discuss this with staff by visiting %s on %s"; + // The default request rejected message + const REJECTED_MESSAGE = "Your request to re-enable your account has been rejected.
This may be because a request is already pending for your username, or because a recent request was denied.

You are encouraged to discuss this with staff by visiting %s on %s"; - // The default request received message - const RECEIVED_MESSAGE = "Your request to re-enable your account has been received. You can expect a reply message in your email within 48 hours.
If you do not receive an email after 48 hours have passed, please visit us on IRC for assistance."; + // The default request received message + const RECEIVED_MESSAGE = "Your request to re-enable your account has been received. You can expect a reply message in your email within 48 hours.
If you do not receive an email after 48 hours have passed, please visit us on IRC for assistance."; - /** - * Handle a new enable request - * - * @param string $Username The user's username - * @param string $Email The user's email address - * @return string The output - */ - public static function new_request($Username, $Email) { - if (empty($Username)) { - header("Location: login.php"); - die(); - } + /** + * Handle a new enable request + * + * @param string $Username The user's username + * @param string $Email The user's email address + * @return string The output + */ + public static function new_request($Username, $Email) { + if (empty($Username)) { + header("Location: login.php"); + die(); + } - // Get the user's ID - G::$DB->query(" - SELECT um.ID - FROM users_main AS um - JOIN users_info ui ON ui.UserID = um.ID - WHERE um.Username = '$Username' - AND um.Enabled = '2'"); + // Get the user's ID + G::$DB->query(" + SELECT um.ID + FROM users_main AS um + JOIN users_info ui ON ui.UserID = um.ID + WHERE um.Username = '$Username' + AND um.Enabled = '2'"); - if (G::$DB->has_results()) { - // Make sure the user can make another request - list($UserID) = G::$DB->next_record(); - G::$DB->query(" - SELECT 1 FROM users_enable_requests - WHERE UserID = '$UserID' - AND ( - ( - Timestamp > NOW() - INTERVAL 1 WEEK - AND HandledTimestamp IS NULL - ) - OR - ( - Timestamp > NOW() - INTERVAL 2 MONTH - AND - (Outcome = '".self::DENIED."' - OR Outcome = '".self::DISCARDED."') - ) - )"); - } + if (G::$DB->has_results()) { + // Make sure the user can make another request + list($UserID) = G::$DB->next_record(); + G::$DB->query(" + SELECT 1 FROM users_enable_requests + WHERE UserID = '$UserID' + AND ( + ( + Timestamp > NOW() - INTERVAL 1 WEEK + AND HandledTimestamp IS NULL + ) + OR + ( + Timestamp > NOW() - INTERVAL 2 MONTH + AND + (Outcome = '".self::DENIED."' + OR Outcome = '".self::DISCARDED."') + ) + )"); + } - $IP = $_SERVER['REMOTE_ADDR']; + $IP = $_SERVER['REMOTE_ADDR']; - if (G::$DB->has_results() || !isset($UserID)) { - // User already has/had a pending activation request or username is invalid - $Output = sprintf(self::REJECTED_MESSAGE, BOT_DISABLED_CHAN, BOT_SERVER); - if (isset($UserID)) { - Tools::update_user_notes($UserID, sqltime() . " - Enable request rejected from $IP\n\n"); - } - } else { - // New disable activation request - $UserAgent = db_string($_SERVER['HTTP_USER_AGENT']); + if (G::$DB->has_results() || !isset($UserID)) { + // User already has/had a pending activation request or username is invalid + $Output = sprintf(self::REJECTED_MESSAGE, BOT_DISABLED_CHAN, BOT_SERVER); + if (isset($UserID)) { + Tools::update_user_notes($UserID, sqltime() . " - Enable request rejected from $IP\n\n"); + } + } else { + // New disable activation request + $UserAgent = db_string($_SERVER['HTTP_USER_AGENT']); - G::$DB->query(" - INSERT INTO users_enable_requests - (UserID, Email, IP, UserAgent, Timestamp) - VALUES ('$UserID', '$Email', '$IP', '$UserAgent', '".sqltime()."')"); + G::$DB->query(" + INSERT INTO users_enable_requests + (UserID, Email, IP, UserAgent, Timestamp) + VALUES ('$UserID', '$Email', '$IP', '$UserAgent', '".sqltime()."')"); - // Cache the number of requests for the modbar - G::$Cache->increment_value(self::CACHE_KEY_NAME); - setcookie('username', '', time() - 60 * 60, '/', '', false); - $Output = self::RECEIVED_MESSAGE; - Tools::update_user_notes($UserID, sqltime() . " - Enable request " . G::$DB->inserted_id() . " received from $IP\n\n"); - } + // Cache the number of requests for the modbar + G::$Cache->increment_value(self::CACHE_KEY_NAME); + setcookie('username', '', time() - 60 * 60, '/', '', false); + $Output = self::RECEIVED_MESSAGE; + Tools::update_user_notes($UserID, sqltime() . " - Enable request " . G::$DB->inserted_id() . " received from $IP\n\n"); + } - return $Output; - } + return $Output; + } - /* - * Handle requests - * - * @param int|int[] $IDs An array of IDs, or a single ID - * @param int $Status The status to mark the requests as - * @param string $Comment The staff member comment - */ - public static function handle_requests($IDs, $Status, $Comment) { - if ($Status != self::APPROVED && $Status != self::DENIED && $Status != self::DISCARDED) { - error(404); - } + /* + * Handle requests + * + * @param int|int[] $IDs An array of IDs, or a single ID + * @param int $Status The status to mark the requests as + * @param string $Comment The staff member comment + */ + public static function handle_requests($IDs, $Status, $Comment) { + if ($Status != self::APPROVED && $Status != self::DENIED && $Status != self::DISCARDED) { + error(404); + } - $UserInfo = array(); - $IDs = (!is_array($IDs)) ? [$IDs] : $IDs; + $UserInfo = array(); + $IDs = (!is_array($IDs)) ? [$IDs] : $IDs; - if (count($IDs) == 0) { - error(404); - } + if (count($IDs) == 0) { + error(404); + } - foreach ($IDs as $ID) { - if (!is_number($ID)) { - error(404); - } - } + foreach ($IDs as $ID) { + if (!is_number($ID)) { + error(404); + } + } - G::$DB->query("SELECT Email, ID, UserID - FROM users_enable_requests - WHERE ID IN (".implode(',', $IDs).") - AND Outcome IS NULL"); - $Results = G::$DB->to_array(false, MYSQLI_NUM); + G::$DB->query("SELECT Email, ID, UserID + FROM users_enable_requests + WHERE ID IN (".implode(',', $IDs).") + AND Outcome IS NULL"); + $Results = G::$DB->to_array(false, MYSQLI_NUM); - if ($Status != self::DISCARDED) { - // Prepare email - require(SERVER_ROOT . '/classes/templates.class.php'); - $TPL = NEW TEMPLATE; - if ($Status == self::APPROVED) { - $TPL->open(SERVER_ROOT . '/templates/enable_request_accepted.tpl'); - $TPL->set('SITE_URL', NONSSL_SITE_URL); - } else { - $TPL->open(SERVER_ROOT . '/templates/enable_request_denied.tpl'); - } + if ($Status != self::DISCARDED) { + // Prepare email + require(SERVER_ROOT . '/classes/templates.class.php'); + $TPL = NEW TEMPLATE; + if ($Status == self::APPROVED) { + $TPL->open(SERVER_ROOT . '/templates/enable_request_accepted.tpl'); + $TPL->set('SITE_URL', NONSSL_SITE_URL); + } else { + $TPL->open(SERVER_ROOT . '/templates/enable_request_denied.tpl'); + } - $TPL->set('SITE_NAME', SITE_NAME); + $TPL->set('SITE_NAME', SITE_NAME); - foreach ($Results as $Result) { - list($Email, $ID, $UserID) = $Result; - $UserInfo[] = array($ID, $UserID); + foreach ($Results as $Result) { + list($Email, $ID, $UserID) = $Result; + $UserInfo[] = array($ID, $UserID); - if ($Status == self::APPROVED) { - // Generate token - $Token = db_string(Users::make_secret()); - G::$DB->query(" - UPDATE users_enable_requests - SET Token = '$Token' - WHERE ID = '$ID'"); - $TPL->set('TOKEN', $Token); - } + if ($Status == self::APPROVED) { + // Generate token + $Token = db_string(Users::make_secret()); + G::$DB->query(" + UPDATE users_enable_requests + SET Token = '$Token' + WHERE ID = '$ID'"); + $TPL->set('TOKEN', $Token); + } - // Send email - $Subject = "Your enable request for " . SITE_NAME . " has been "; - $Subject .= ($Status == self::APPROVED) ? 'approved' : 'denied'; + // Send email + $Subject = "Your enable request for " . SITE_NAME . " has been "; + $Subject .= ($Status == self::APPROVED) ? 'approved' : 'denied'; - Misc::send_email($Email, $Subject, $TPL->get(), 'noreply'); - } - } else { - foreach ($Results as $Result) { - list(, $ID, $UserID) = $Result; - $UserInfo[] = array($ID, $UserID); - } - } + Misc::send_email($Email, $Subject, $TPL->get(), 'noreply'); + } + } else { + foreach ($Results as $Result) { + list(, $ID, $UserID) = $Result; + $UserInfo[] = array($ID, $UserID); + } + } - // User notes stuff - G::$DB->query(" - SELECT Username - FROM users_main - WHERE ID = '" . G::$LoggedUser['ID'] . "'"); - list($StaffUser) = G::$DB->next_record(); + // User notes stuff + G::$DB->query(" + SELECT Username + FROM users_main + WHERE ID = '" . G::$LoggedUser['ID'] . "'"); + list($StaffUser) = G::$DB->next_record(); - foreach ($UserInfo as $User) { - list($ID, $UserID) = $User; - $BaseComment = sqltime() . " - Enable request $ID " . strtolower(self::get_outcome_string($Status)) . ' by [user]'.$StaffUser.'[/user]'; - $BaseComment .= (!empty($Comment)) ? "\nReason: $Comment\n\n" : "\n\n"; - Tools::update_user_notes($UserID, $BaseComment); - } + foreach ($UserInfo as $User) { + list($ID, $UserID) = $User; + $BaseComment = sqltime() . " - Enable request $ID " . strtolower(self::get_outcome_string($Status)) . ' by [user]'.$StaffUser.'[/user]'; + $BaseComment .= (!empty($Comment)) ? "\nReason: $Comment\n\n" : "\n\n"; + Tools::update_user_notes($UserID, $BaseComment); + } - // Update database values and decrement cache - G::$DB->query(" - UPDATE users_enable_requests - SET HandledTimestamp = '".sqltime()."', - CheckedBy = '".G::$LoggedUser['ID']."', - Outcome = '$Status' - WHERE ID IN (".implode(',', $IDs).")"); - G::$Cache->decrement_value(self::CACHE_KEY_NAME, count($IDs)); - } + // Update database values and decrement cache + G::$DB->query(" + UPDATE users_enable_requests + SET HandledTimestamp = '".sqltime()."', + CheckedBy = '".G::$LoggedUser['ID']."', + Outcome = '$Status' + WHERE ID IN (".implode(',', $IDs).")"); + G::$Cache->decrement_value(self::CACHE_KEY_NAME, count($IDs)); + } - /** - * Unresolve a discarded request - * - * @param int $ID The request ID - */ - public static function unresolve_request($ID) { - $ID = (int) $ID; + /** + * Unresolve a discarded request + * + * @param int $ID The request ID + */ + public static function unresolve_request($ID) { + $ID = (int) $ID; - if (empty($ID)) { - error(404); - } + if (empty($ID)) { + error(404); + } - G::$DB->query(" - SELECT UserID - FROM users_enable_requests - WHERE Outcome = '" . self::DISCARDED . "' - AND ID = '$ID'"); + G::$DB->query(" + SELECT UserID + FROM users_enable_requests + WHERE Outcome = '" . self::DISCARDED . "' + AND ID = '$ID'"); - if (!G::$DB->has_results()) { - error(404); - } else { - list($UserID) = G::$DB->next_record(); - } + if (!G::$DB->has_results()) { + error(404); + } else { + list($UserID) = G::$DB->next_record(); + } - G::$DB->query(" - SELECT Username - FROM users_main - WHERE ID = '" . G::$LoggedUser['ID'] . "'"); - list($StaffUser) = G::$DB->next_record(); + G::$DB->query(" + SELECT Username + FROM users_main + WHERE ID = '" . G::$LoggedUser['ID'] . "'"); + list($StaffUser) = G::$DB->next_record(); - Tools::update_user_notes($UserID, sqltime() . " - Enable request $ID unresolved by [user]" . $StaffUser . '[/user]' . "\n\n"); - G::$DB->query(" - UPDATE users_enable_requests - SET Outcome = NULL, HandledTimestamp = NULL, CheckedBy = NULL - WHERE ID = '$ID'"); - G::$Cache->increment_value(self::CACHE_KEY_NAME); - } + Tools::update_user_notes($UserID, sqltime() . " - Enable request $ID unresolved by [user]" . $StaffUser . '[/user]' . "\n\n"); + G::$DB->query(" + UPDATE users_enable_requests + SET Outcome = NULL, HandledTimestamp = NULL, CheckedBy = NULL + WHERE ID = '$ID'"); + G::$Cache->increment_value(self::CACHE_KEY_NAME); + } - /** - * Get the corresponding outcome string for a numerical value - * - * @param int $Outcome The outcome integer - * @return string The formatted output string - */ - public static function get_outcome_string($Outcome) { - if ($Outcome == self::APPROVED) { - $String = "Approved"; - } else if ($Outcome == self::DENIED) { - $String = "Rejected"; - } else if ($Outcome == self::DISCARDED) { - $String = "Discarded"; - } else { - $String = "---"; - } + /** + * Get the corresponding outcome string for a numerical value + * + * @param int $Outcome The outcome integer + * @return string The formatted output string + */ + public static function get_outcome_string($Outcome) { + if ($Outcome == self::APPROVED) { + $String = "Approved"; + } else if ($Outcome == self::DENIED) { + $String = "Rejected"; + } else if ($Outcome == self::DISCARDED) { + $String = "Discarded"; + } else { + $String = "---"; + } - return $String; - } + return $String; + } - /** - * Handle a user's request to enable an account - * - * @param string $Token The token - * @return string The error output, or an empty string - */ - public static function handle_token($Token) { - $Token = db_string($Token); - G::$DB->query(" - SELECT UserID, HandledTimestamp - FROM users_enable_requests - WHERE Token = '$Token'"); + /** + * Handle a user's request to enable an account + * + * @param string $Token The token + * @return string The error output, or an empty string + */ + public static function handle_token($Token) { + $Token = db_string($Token); + G::$DB->query(" + SELECT UserID, HandledTimestamp + FROM users_enable_requests + WHERE Token = '$Token'"); - if (G::$DB->has_results()) { - list($UserID, $Timestamp) = G::$DB->next_record(); - G::$DB->query("UPDATE users_enable_requests SET Token = NULL WHERE Token = '$Token'"); - if ($Timestamp < time_minus(3600 * 48)) { - // Old request - Tools::update_user_notes($UserID, sqltime() . " - Tried to use an expired enable token from ".$_SERVER['REMOTE_ADDR']."\n\n"); - $Err = "Token has expired. Please visit ".BOT_DISABLED_CHAN." on ".BOT_SERVER." to discuss this with staff."; - } else { - // Good request, decrement cache value and enable account - G::$Cache->decrement_value(AutoEnable::CACHE_KEY_NAME); - G::$DB->query("UPDATE users_main SET Enabled = '1' WHERE ID = '$UserID'"); - G::$DB->query("UPDATE users_info SET BanReason = '0' WHERE UserID = '$UserID'"); - $Err = "Your account has been enabled. You may now log in."; - } - } else { - $Err = "Invalid token."; - } + if (G::$DB->has_results()) { + list($UserID, $Timestamp) = G::$DB->next_record(); + G::$DB->query("UPDATE users_enable_requests SET Token = NULL WHERE Token = '$Token'"); + if ($Timestamp < time_minus(3600 * 48)) { + // Old request + Tools::update_user_notes($UserID, sqltime() . " - Tried to use an expired enable token from ".$_SERVER['REMOTE_ADDR']."\n\n"); + $Err = "Token has expired. Please visit ".BOT_DISABLED_CHAN." on ".BOT_SERVER." to discuss this with staff."; + } else { + // Good request, decrement cache value and enable account + G::$Cache->decrement_value(AutoEnable::CACHE_KEY_NAME); + G::$DB->query("UPDATE users_main SET Enabled = '1', can_leech = '1' WHERE ID = '$UserID'"); + G::$DB->query("UPDATE users_info SET BanReason = '0' WHERE UserID = '$UserID'"); + G::$DB->query("SELECT torrent_pass FROM users_main WHERE ID='{$UserID}'"); + list($TorrentPass) = G::$DB->next_record(); + Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $TorrentPass)); + $Err = "Your account has been enabled. You may now log in."; + } + } else { + $Err = "Invalid token."; + } - return $Err; - } + return $Err; + } - /** - * Build the search query, from the searchbox inputs - * - * @param int $UserID The user ID - * @param string $IP The IP - * @param string $SubmittedTimestamp The timestamp representing when the request was submitted - * @param int $HandledUserID The ID of the user that handled the request - * @param string $HandledTimestamp The timestamp representing when the request was handled - * @param int $OutcomeSearch The outcome of the request - * @param boolean $Checked Should checked requests be included? - * @return array The WHERE conditions for the query - */ - public static function build_search_query($Username, $IP, $SubmittedBetween, $SubmittedTimestamp1, $SubmittedTimestamp2, $HandledUsername, $HandledBetween, $HandledTimestamp1, $HandledTimestamp2, $OutcomeSearch, $Checked) { - $Where = array(); + /** + * Build the search query, from the searchbox inputs + * + * @param int $UserID The user ID + * @param string $IP The IP + * @param string $SubmittedTimestamp The timestamp representing when the request was submitted + * @param int $HandledUserID The ID of the user that handled the request + * @param string $HandledTimestamp The timestamp representing when the request was handled + * @param int $OutcomeSearch The outcome of the request + * @param boolean $Checked Should checked requests be included? + * @return array The WHERE conditions for the query + */ + public static function build_search_query($Username, $IP, $SubmittedBetween, $SubmittedTimestamp1, $SubmittedTimestamp2, $HandledUsername, $HandledBetween, $HandledTimestamp1, $HandledTimestamp2, $OutcomeSearch, $Checked) { + $Where = array(); - if (!empty($Username)) { - $Where[] = "um1.Username = '$Username'"; - } + if (!empty($Username)) { + $Where[] = "um1.Username = '$Username'"; + } - if (!empty($IP)) { - $Where[] = "uer.IP = '$IP'"; - } + if (!empty($IP)) { + $Where[] = "uer.IP = '$IP'"; + } - if (!empty($SubmittedTimestamp1)) { - switch($SubmittedBetween) { - case 'on': - $Where[] = "DATE(uer.Timestamp) = DATE('$SubmittedTimestamp1')"; - break; - case 'before': - $Where[] = "DATE(uer.Timestamp) < DATE('$SubmittedTimestamp1')"; - break; - case 'after': - $Where[] = "DATE(uer.Timestamp) > DATE('$SubmittedTimestamp1')"; - break; - case 'between': - if (!empty($SubmittedTimestamp2)) { - $Where[] = "DATE(uer.Timestamp) BETWEEN DATE('$SubmittedTimestamp1') AND DATE('$SubmittedTimestamp2')"; - } - break; - default: - break; - } - } + if (!empty($SubmittedTimestamp1)) { + switch($SubmittedBetween) { + case 'on': + $Where[] = "DATE(uer.Timestamp) = DATE('$SubmittedTimestamp1')"; + break; + case 'before': + $Where[] = "DATE(uer.Timestamp) < DATE('$SubmittedTimestamp1')"; + break; + case 'after': + $Where[] = "DATE(uer.Timestamp) > DATE('$SubmittedTimestamp1')"; + break; + case 'between': + if (!empty($SubmittedTimestamp2)) { + $Where[] = "DATE(uer.Timestamp) BETWEEN DATE('$SubmittedTimestamp1') AND DATE('$SubmittedTimestamp2')"; + } + break; + default: + break; + } + } - if (!empty($HandledTimestamp1)) { - switch($HandledBetween) { - case 'on': - $Where[] = "DATE(uer.HandledTimestamp) = DATE('$HandledTimestamp1')"; - break; - case 'before': - $Where[] = "DATE(uer.HandledTimestamp) < DATE('$HandledTimestamp1')"; - break; - case 'after': - $Where[] = "DATE(uer.HandledTimestamp) > DATE('$HandledTimestamp1')"; - break; - case 'between': - if (!empty($HandledTimestamp2)) { - $Where[] = "DATE(uer.HandledTimestamp) BETWEEN DATE('$HandledTimestamp1') AND DATE('$HandledTimestamp2')"; - } - break; - default: - break; - } - } + if (!empty($HandledTimestamp1)) { + switch($HandledBetween) { + case 'on': + $Where[] = "DATE(uer.HandledTimestamp) = DATE('$HandledTimestamp1')"; + break; + case 'before': + $Where[] = "DATE(uer.HandledTimestamp) < DATE('$HandledTimestamp1')"; + break; + case 'after': + $Where[] = "DATE(uer.HandledTimestamp) > DATE('$HandledTimestamp1')"; + break; + case 'between': + if (!empty($HandledTimestamp2)) { + $Where[] = "DATE(uer.HandledTimestamp) BETWEEN DATE('$HandledTimestamp1') AND DATE('$HandledTimestamp2')"; + } + break; + default: + break; + } + } - if (!empty($HandledUsername)) { - $Where[] = "um2.Username = '$HandledUsername'"; - } + if (!empty($HandledUsername)) { + $Where[] = "um2.Username = '$HandledUsername'"; + } - if (!empty($OutcomeSearch)) { - $Where[] = "uer.Outcome = '$OutcomeSearch'"; - } + if (!empty($OutcomeSearch)) { + $Where[] = "uer.Outcome = '$OutcomeSearch'"; + } - if ($Checked) { - // This is to skip the if statement in enable_requests.php - $Where[] = "(uer.Outcome IS NULL OR uer.Outcome IS NOT NULL)"; - } + if ($Checked) { + // This is to skip the if statement in enable_requests.php + $Where[] = "(uer.Outcome IS NULL OR uer.Outcome IS NOT NULL)"; + } - return $Where; - } + return $Where; + } } diff --git a/classes/script_start.php b/classes/script_start.php index 6e6576faf..187e3be09 100644 --- a/classes/script_start.php +++ b/classes/script_start.php @@ -337,11 +337,11 @@ function logout() { */ function logout_all_sessions() { $UserID = G::$LoggedUser['ID']; - + G::$DB->query(" DELETE FROM users_sessions WHERE UserID = '$UserID'"); - + G::$Cache->delete_value('users_sessions_' . $UserID); logout(); } @@ -358,8 +358,8 @@ function enforce_login() { * Make sure $_GET['auth'] is the same as the user's authorization key * Should be used for any user action that relies solely on GET. * - * @param Are we using ajax? - * @return authorisation status. Prints an error message to LAB_CHAN on IRC on failure. + * @param bool Are we using ajax? + * @return bool authorisation status. Prints an error message to LAB_CHAN on IRC on failure. */ function authorize($Ajax = false) { if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != G::$LoggedUser['AuthKey']) { diff --git a/classes/users.class.php b/classes/users.class.php index c8e477d5b..d8d37d645 100644 --- a/classes/users.class.php +++ b/classes/users.class.php @@ -164,6 +164,7 @@ class Users { m.IP, m.CustomPermissions, m.can_leech AS CanLeech, + m.IRCKey, i.AuthKey, i.RatioWatchEnds, i.RatioWatchDownload, @@ -178,6 +179,7 @@ class Users { i.DisablePM, i.DisableRequests, i.DisableForums, + i.DisableIRC, i.DisableTagging," . " i.SiteOptions, i.DownloadAlt, @@ -243,10 +245,10 @@ class Users { unset($HeavyInfo['CustomForums']['']); } - $HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']); - if (!empty($HeavyInfo['SiteOptions'])) { - $HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']); - } + $HeavyInfo['SiteOptions'] = !empty($HeavyInfo['SiteOptions']) ? unserialize($HeavyInfo['SiteOptions']) : array(); + $HeavyInfo['SiteOptions'] = array_merge(static::default_site_options(), $HeavyInfo['SiteOptions']); + $HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']); + unset($HeavyInfo['SiteOptions']); G::$DB->set_query_id($QueryID); @@ -256,6 +258,16 @@ class Users { return $HeavyInfo; } + /** + * Default settings to use for SiteOptions + * @return array + */ + public static function default_site_options() { + return array( + 'HttpsTracker' => true + ); + } + /** * Updates the site options in the database * @@ -279,7 +291,8 @@ class Users { FROM users_info WHERE UserID = $UserID"); list($SiteOptions) = G::$DB->next_record(MYSQLI_NUM, false); - $SiteOptions = unserialize($SiteOptions); + $SiteOptions = !empty($SiteOptions) ? unserialize($SiteOptions) : array(); + $SiteOptions = array_merge(static::default_site_options(), $SiteOptions); // Get HeavyInfo $HeavyInfo = Users::user_heavy_info($UserID); diff --git a/classes/util.php b/classes/util.php index c0ea2f104..d986fef57 100644 --- a/classes/util.php +++ b/classes/util.php @@ -197,4 +197,18 @@ function json_print($Status, $Message) { function site_url($SSL = true) { return $SSL ? 'https://' . SSL_SITE_URL . '/' : 'http://' . NONSSL_SITE_URL . '/'; } -?> + +/** + * The text of the pop-up confirmation when burning an FL token. + * + * @param integer $seeders - number of seeders for the torrent + * @return string Warns if there are no seeders on the torrent + */ +function FL_confirmation_msg($seeders) { + /* Coder Beware: this text is emitted as part of a Javascript single quoted string. + * Any apostrophes should be avoided or escaped appropriately (with \\'). + */ + return ($seeders == 0) + ? 'Warning! This torrent is not seeded at the moment, are you sure you want to use a Freeleech token here?' + : 'Are you sure you want to use a Freeleech token here?'; +} diff --git a/design/privateheader.php b/design/privateheader.php index 95473f05b..3d9bfeaa4 100644 --- a/design/privateheader.php +++ b/design/privateheader.php @@ -11,6 +11,7 @@ $UseTooltipster = !isset(G::$LoggedUser['Tooltipster']) || G::$LoggedUser['Toolt + diff --git a/design/publicheader.php b/design/publicheader.php index 36a815b71..b8f11cc23 100644 --- a/design/publicheader.php +++ b/design/publicheader.php @@ -8,6 +8,7 @@ define('FOOTER_FILE',SERVER_ROOT.'/design/publicfooter.php'); <?=display_str($PageTitle)?> + @@ -35,9 +36,9 @@ define('FOOTER_FILE',SERVER_ROOT.'/design/publicfooter.php'); diff --git a/sections/api/User.php b/sections/api/User.php index 81861d187..753b42620 100644 --- a/sections/api/User.php +++ b/sections/api/User.php @@ -1,76 +1,93 @@ db->query(" -SELECT - um.ID, um.Username, um.Email, um.IRCKey, um.Uploaded, um.Downloaded, um.Paranoia, um.Enabled, - um.Invites, um.PermissionID, um.LastAccess, p.Level as PermissionLevel, p.Name as PermissionName, ui.* -FROM users_main as um -LEFT JOIN ( - SELECT UserID, AdminComment, Donor, JoinDate, Inviter, DisableIRC, BanDate, BanReason - FROM users_info -) AS ui ON ui.UserID = um.ID -LEFT JOIN (SELECT ID, Level, Name FROM permissions) AS p ON p.ID = um.PermissionID -WHERE {$where}"); - if ($this->db->record_count() === 0) { - error('No user found'); - } - $this->user = $this->db->next_record(MYSQLI_ASSOC, false); - $this->user['Paranoia'] = unserialize($this->user['Paranoia']); - - $this->user['Ratio'] = Format::get_ratio($this->user['Uploaded'], $this->user['Downloaded']); - $this->user['DisplayStats'] = array('Downloaded' => Format::get_size($this->user['Downloaded']), - 'Uploaded' => Format::get_size($this->user['Uploaded']), - 'Ratio' => $this->user['Ratio']); - foreach (array('Downloaded', 'Uploaded', 'Ratio') as $key) { - if (in_array(strtolower($key), $this->user['Paranoia'])) { - $this->user['DisplayStats'][$key] = "Hidden"; - } - } - $this->user['UserPage'] = "http"; - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") { - $this->user['UserPage'] .= "s"; - } - $this->user['UserPage'] .= "://" . SITE_URL . "/user.php?id={$this->user['ID']}"; - - switch($_GET['req']) { - case 'enable': - return $this->disableUser(); - break; - case 'disable': - return $this->enableUser(); - break; - default: - case 'stats': - return $this->getStats(); - break; - } - } - - private function getStats() { - return $this->user; - } - - private function disableUser() { - $this->db->query("UPDATE users_main SET Enabled='2' WHERE ID='{$this->user['ID']}'"); - return array('disabled' => true, 'user_id' => $this->user['ID'], 'username' => $this->user['Username']); - } - - private function enableUser() { - $this->db->query("UPDATE users_main SET Enabled='1' WHERE ID='{$this->user['ID']}'"); - return array('enabled' => true, 'user_id' => $this->user['ID'], 'username' => $this->user['Username']); - } + private $id = null; + private $username = null; + + public function run() { + if (isset($_GET['user_id'])) { + $this->id = intval($_GET['user_id']); + } + else if (isset($_GET['username'])) { + $this->username = $_GET['username']; + } + else { + json_error("Need to supply either user_id or username"); + } + + switch($_GET['req']) { + case 'enable': + return $this->disableUser(); + break; + case 'disable': + return $this->enableUser(); + break; + default: + case 'stats': + return $this->getUser(); + break; + } + } + + private function getUser() { + $where = ($this->id !== null) ? "um.ID = '{$this->id}'" : "um.Username = '".db_string($this->username)."'"; + // TODO: add um.BonusPoints, + $this->db->query(" + SELECT + um.ID, + um.Username, + um.IRCKey, + um.Uploaded, + um.Downloaded, + um.PermissionID AS Class, + um.Paranoia, + ui.DisableIRC, + p.Name as ClassName, + p.Level, + GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS SecondaryClasses + FROM + users_main AS um + INNER JOIN users_info AS ui ON ui.UserID = um.ID + INNER JOIN permissions AS p ON p.ID = um.PermissionID + LEFT JOIN users_levels AS ul ON ul.UserID = um.ID + WHERE + {$where}"); + + $user = $this->db->next_record(MYSQLI_ASSOC, array('Paranoia')); + if (!empty($user['Username'])) { + $user['SecondaryClasses'] = array_map("intval", explode(",", $user['SecondaryClasses'])); + foreach (array('ID', 'Uploaded', 'Downloaded', 'Class', 'Level') as $key) { + $user[$key] = intval($user[$key]); + } + $user['Paranoia'] = !empty($user['Paranoia']) ? unserialize($user['Paranoia']) : array(); + + $user['Ratio'] = Format::get_ratio($user['Uploaded'], $user['Downloaded']); + $user['DisplayStats'] = array( + 'Downloaded' => Format::get_size($user['Downloaded']), + 'Uploaded' => Format::get_size($user['Uploaded']), + 'Ratio' => $user['Ratio'] + ); + foreach (array('Downloaded', 'Uploaded', 'Ratio') as $key) { + if (in_array(strtolower($key), $user['Paranoia'])) { + $user['DisplayStats'][$key] = "Hidden"; + } + } + $user['UserPage'] = "http"; + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") { + $user['UserPage'] .= "s"; + } + $user['UserPage'] .= "://" . SITE_URL . "/user.php?id={$user['ID']}"; + } + return $user; + } + + private function disableUser() { + $this->db->query("UPDATE users_main SET Enabled='2' WHERE ID='{$this->id}'"); + return array('disabled' => true, 'user_id' => $user['ID'], 'username' => $user['Username']); + } + + private function enableUser() { + $this->db->query("UPDATE users_main SET Enabled='1' WHERE ID='{$this->id}'"); + return array('enabled' => true, 'user_id' => $user['ID'], 'username' => $user['Username']); + } } \ No newline at end of file diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 7a5b0e3a6..8bdf3c444 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -456,7 +456,7 @@ foreach ($Importances as $Group) { [ - | FL + | FL | [apollo.rip].json" class="tooltip" title="Download JSON">JS ] @@ -998,4 +998,3 @@ if ($RevisionID) { $Data = array(array($Name, $Image, $Body, $NumSimilar, $SimilarArray, array(), array(), $VanityHouseArtist)); $Cache->cache_value($Key, $Data, 3600); -?> diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index 4b036bf57..07bb9325a 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -147,7 +147,7 @@ foreach ($GroupIDs as $GroupID) { [ DL - | FL + | FL | RP ] @@ -189,7 +189,7 @@ foreach ($GroupIDs as $GroupID) { [ DL - | FL + | FL | RP ] diff --git a/sections/collages/torrent_collage.php b/sections/collages/torrent_collage.php index b605d0c63..da6ffce05 100644 --- a/sections/collages/torrent_collage.php +++ b/sections/collages/torrent_collage.php @@ -172,7 +172,7 @@ foreach ($GroupIDs as $GroupID) { DL - | FL + | FL | RP @@ -214,7 +214,7 @@ foreach ($GroupIDs as $GroupID) { DL - | FL + | FL | RP @@ -620,4 +620,3 @@ if ($CollageCovers != 0) { ?> diff --git a/sections/rules/chat.php b/sections/rules/chat.php index fe37a6175..37b18fa88 100644 --- a/sections/rules/chat.php +++ b/sections/rules/chat.php @@ -2,26 +2,25 @@ //Include the header View::show_header('Chat Rules'); ?> - +
+

Anything not allowed on the forums is also not allowed on IRC and vice versa. They are separated for convenience only.


-

Forum Rules

+ +

Forum Rules

-
-
-

IRC Rules

+

IRC Rules

-
get_value('whitelisted_clients')) { $Cache->cache_value('whitelisted_clients', $WhitelistedClients, 604800); } ?> -
+
+

Client Whitelist

@@ -35,6 +36,5 @@ if (!$WhitelistedClients = $Cache->get_value('whitelisted_clients')) {
-
diff --git a/sections/rules/collages.php b/sections/rules/collages.php index 624b9c738..8e50ea68b 100644 --- a/sections/rules/collages.php +++ b/sections/rules/collages.php @@ -3,6 +3,7 @@ View::show_header('Collages Rules'); ?>
+

Collages

@@ -52,7 +53,6 @@ View::show_header('Collages Rules');
- -

Other Sections

+

Rule Sections

diff --git a/sections/rules/ratio.php b/sections/rules/ratio.php index 45a4829b3..fd54ba075 100644 --- a/sections/rules/ratio.php +++ b/sections/rules/ratio.php @@ -3,6 +3,7 @@ View::show_header('Ratio Requirements'); ?>
+

Ratio Rules

@@ -197,7 +198,6 @@ View::show_header('Ratio Requirements');

-
+

Requests

@@ -25,7 +26,7 @@ View::show_header('Request Rules');
- +
+
-

Golden Rules

+

Golden Rules

The Golden Rules encompass all of and our IRC Network. These rules are paramount; non-compliance will jeopardize your account.

- +
+
-

Tagging rules

+

Tagging rules

-
+

Uploading Rules

@@ -375,7 +376,7 @@ View::show_header('Uploading Rules', 'rules');
  • ↑_ 2.3.17. The torrent artist for classical works should use the full composer name. Before uploading, see this wiki for guidelines on uploading and tagging classical music torrents.
  • ↑_ 2.3.18. Newly re-tagged torrents trumping badly tagged torrents must reflect a substantial improvement over the previous tags. Small changes that include replacing ASCII characters with proper foreign language characters with diacritical marks, fixing slight misspellings, or missing an alternate spelling of an artist (e.g., excluding "The" before a band name) are insufficient grounds for replacing other torrents. Artist names that are misspelled in the tags are grounds for trumping; this includes character accents and characters that mean one letter in one language and a different letter in another language. Improper capitalization in the tags is grounds for trumping; this includes artist tags (or composer tags) that contain names that are all capitalized or track titles that are all capitalized. Tags with multiple entries in the same tag (e.g., track number and track title in the track title tags; or track number, artist, and track title in the artist tags) are subject to trumping. You may trump a release if the tags do not follow the data from a reputable music cataloguing service such as MusicBrainz or Discogs. In the case of a conflict between reputable listings, either tagged version is equally preferred on the site and cannot trump the other. For example, an album is tagged differently in MusicBrainz and in Discogs. Either style of tagging is permitted; neither is "better" than the other. In that case, any newly tagged torrents replacing an already properly tagged torrent, which follows good tagging convention, will result in a dupe. Note: For classical music, please follow these tagging guidelines.
  • -
  • ↑_ 2.3.19. Avoid embedding large images in file metadata. The combined size of embedded images and padding may not exceed 512 KiB per file. You may include the artwork separately if it is too big. When removing embedded images, make sure that the padding is removed or reduced to a few kilobytes. Refer to this wiki article for more information.
  • +
  • ↑_ 2.3.19. Avoid embedding large images in file metadata. The combined size of embedded images and padding may not exceed 1024 KiB per file. You may include the artwork separately if it is too big. When removing embedded images, make sure that the padding is removed or reduced to a few kilobytes. Refer to this wiki article for more information.
  • ↑_ 2.3.20. Leading spaces are not allowed in any file or folder names. Leading spaces cause usability and interoperability problems among various operating systems and programs. Torrents with file or folder names that contain leading space characters are trumpable.
  • @@ -718,7 +719,6 @@ View::show_header('Uploading Rules', 'rules'); -query("SELECT count(*) as count FROM users_main"); + list($Count) = $DB->next_record(); + + for ($i = 1; $i <= $Count; $i++) { + $Cache->delete_value('users_stats_' . $i); + $Cache->delete_value('users_info_' . $i); + $Cache->delete_value('users_info_heavy_' . $i); + } + echo "
    {$Count} users' caches cleared!
    "; + } + elseif ($_GET['cache'] === 'torrent_groups') { + $DB->query("SELECT count(*) as count FROM torrents_group"); + list($Count) = $DB->next_record(); + for ($i = 1; $i <= $Count; $i++) { + $Cache->delete_value('torrent_group_' . $i); + $Cache->delete_value('groups_artists_' . $i); + } + } +} if (!empty($_GET['key'])) { if ($_GET['submit'] == 'Multi') { $Keys = array_map('trim', preg_split('/\s+/', $_GET['key'])); @@ -59,23 +80,30 @@ $MultiKeyTooltip = 'Enter cache keys delimited by any amount of whitespace.'; + + + + + + +
    Clear Common Caches:Users (clears out users_stats_*, users_info_*, and users_info_heavy_*)
    Torrent Groups (clears out torrent_group_* and groups_artists_*)
    + ?> - - - - - - + + + + + +
    -
    get_value($Key)); ?>
    -
    +
    get_value($Key)); ?>
    +
    -
    @@ -150,17 +150,7 @@ View::show_header('Staff Tools'); // begin Developer Sandboxes category $ToolsHTML = ""; - create_row("Sandbox (1)", "tools.php?action=sandbox1", check_perms("site_debug")); - create_row("Sandbox (2)", "tools.php?action=sandbox2", check_perms("site_debug")); - create_row("Sandbox (3)", "tools.php?action=sandbox3", check_perms("site_debug")); - create_row("Sandbox (4)", "tools.php?action=sandbox4", check_perms("site_debug")); - create_row("Sandbox (5)", "tools.php?action=sandbox5", check_perms("site_debug")); - create_row("Sandbox (6)", "tools.php?action=sandbox6", check_perms("site_debug")); - create_row("Sandbox (7)", "tools.php?action=sandbox7", check_perms("site_debug")); - create_row("Sandbox (8)", "tools.php?action=sandbox8", check_perms("site_debug")); create_row("BBCode sandbox", "tools.php?action=bbcode_sandbox", check_perms("users_mod")); - create_row("Public sandbox", "tools.php?action=public_sandbox", check_perms("users_mod"), "Do not click this!"); - create_row("Mod-level sandbox", "tools.php?action=mod_sandbox", check_perms("users_mod"), "Do not click this!"); create_row("Testing", "testing.php", check_perms("users_mod")); if ($ToolsHTML) { diff --git a/sections/top10/votes.php b/sections/top10/votes.php index 5ce19ba97..09daa09d3 100644 --- a/sections/top10/votes.php +++ b/sections/top10/votes.php @@ -294,7 +294,7 @@ foreach ($TopVotes as $GroupID => $Group) { [ DL - | FL + | FL | RP ] @@ -342,7 +342,7 @@ foreach ($TopVotes as $GroupID => $Group) { [ DL - | FL + | FL | RP @@ -395,4 +395,3 @@ if ($TopVotes === false) { ?>
    diff --git a/sections/torrents/browse.php b/sections/torrents/browse.php index 62ac6de93..632545509 100644 --- a/sections/torrents/browse.php +++ b/sections/torrents/browse.php @@ -49,11 +49,9 @@ if (!empty($_GET['setdefault'])) { FROM users_info WHERE UserID = '".db_string($LoggedUser['ID'])."'"); list($SiteOptions) = $DB->next_record(MYSQLI_NUM, false); - if (!empty($SiteOptions)) { - $SiteOptions = unserialize($SiteOptions); - } else { - $SiteOptions = array(); - } + $SiteOptions = (!empty($SiteOptions)) ? unserialize($SiteOptions) : array(); + $SiteOptions = array_merge(Users::default_site_options(), $SiteOptions); + $SiteOptions['DefaultSearch'] = preg_replace($UnsetRegexp, '', $_SERVER['QUERY_STRING']); $DB->query(" UPDATE users_info @@ -655,7 +653,7 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr [ - | FL + | FL | RP ] @@ -707,7 +705,7 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr [ DL - | FL + | FL | RP ] @@ -730,4 +728,5 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
    - + [ - | FL + | FL | RP @@ -939,4 +939,5 @@ CommentsView::render_comments($Thread, $LastRead, "torrents.php?id=$GroupID"); - + [ - | FL + | FL | RP diff --git a/sections/torrents/notify.php b/sections/torrents/notify.php index 958739b81..2c5d1eefc 100644 --- a/sections/torrents/notify.php +++ b/sections/torrents/notify.php @@ -301,7 +301,7 @@ if (empty($Results)) { [ DL - | FL + | FL @@ -347,4 +347,5 @@ if (empty($Results)) { - +Dec['encrypted_files'])) { - $Err = 'At least one of the torrents contain an encrypted file list which is not supported here'; - break; - } - if (!$ExtraTor->is_private()) { - $ExtraTor->make_private(); // The torrent is now private. - $PublicTorrent = true; - } - - // File list and size - list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list(); - $ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : ''; - - $ExtraTmpFileList = array(); - foreach ($ExtraFileList as $ExtraFile) { - list($ExtraSize, $ExtraName) = $ExtraFile; - - check_file($Type, $ExtraName); - - // Make sure the file name is not too long - if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) { - $Err = "The torrent contained one or more files with too long of a name:
    $ExtraDirName/$ExtraName"; - break; - } - // Add file and size to array - $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile); - } - - // To be stored in the database - $ThisInsert['FilePath'] = db_string($ExtraDirName); - $ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList)); - $ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash()); - $ThisInsert['NumFiles'] = count($ExtraFileList); - $ThisInsert['TorEnc'] = db_string($ExtraTor->encode()); - $ThisInsert['TotalSize'] = $ExtraTotalSize; - - $Debug->set_flag('upload: torrent decoded'); - $DB->query(" - SELECT ID - FROM torrents - WHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'"); - if ($DB->has_results()) { - list($ExtraID) = $DB->next_record(); - $DB->query(" - SELECT TorrentID - FROM torrents_files - WHERE TorrentID = $ExtraID"); - if ($DB->has_results()) { - $Err = "The exact same torrent file already exists on the site!"; - } else { - //One of the lost torrents. - $DB->query(" - INSERT INTO torrents_files (TorrentID, File) - VALUES ($ExtraID, '$ThisInsert[TorEnc]')"); - $Err = "Thank you for fixing this torrent."; - } - } -} -unset($ThisInsert); -?> diff --git a/sections/upload/get_extra_torrents.php b/sections/upload/get_extra_torrents.php deleted file mode 100644 index d71b27dab..000000000 --- a/sections/upload/get_extra_torrents.php +++ /dev/null @@ -1,43 +0,0 @@ - diff --git a/sections/upload/upload_handle.php b/sections/upload/upload_handle.php index 7eef67673..e14b6cbe0 100644 --- a/sections/upload/upload_handle.php +++ b/sections/upload/upload_handle.php @@ -255,7 +255,46 @@ if (!is_uploaded_file($TorrentName) || !filesize($TorrentName)) { } if ($Type == 'Music') { - include(SERVER_ROOT.'/sections/upload/get_extra_torrents.php'); + //extra torrent files + $ExtraTorrents = array(); + $DupeNames = array(); + $DupeNames[] = $_FILES['file_input']['name']; + + if (isset($_POST['extra_format']) && isset($_POST['extra_bitrate'])) { + for ($i = 1; $i <= 5; $i++) { + if (isset($_FILES["extra_file_$i"])) { + $ExtraFile = $_FILES["extra_file_$i"]; + $ExtraTorrentName = $ExtraFile['tmp_name']; + if (!is_uploaded_file($ExtraTorrentName) || !filesize($ExtraTorrentName)) { + $Err = 'No extra torrent file uploaded, or file is empty.'; + } elseif (substr(strtolower($ExtraFile['name']), strlen($ExtraFile['name']) - strlen('.torrent')) !== '.torrent') { + $Err = 'You seem to have put something other than an extra torrent file into the upload field. (' . $ExtraFile['name'] . ').'; + } elseif (in_array($ExtraFile['name'], $DupeNames)) { + $Err = 'One or more torrents has been entered into the form twice.'; + } else { + $j = $i - 1; + $ExtraTorrents[$ExtraTorrentName]['Name'] = $ExtraTorrentName; + $ExtraFormat = $_POST['extra_format'][$j]; + if (empty($ExtraFormat)) { + $Err = 'Missing format for extra torrent.'; + break; + } else { + $ExtraTorrents[$ExtraTorrentName]['Format'] = db_string(trim($ExtraFormat)); + } + $ExtraBitrate = $_POST['extra_bitrate'][$j]; + if (empty($ExtraBitrate)) { + $Err = 'Missing bitrate for extra torrent.'; + break; + } else { + $ExtraTorrents[$ExtraTorrentName]['Encoding'] = db_string(trim($ExtraBitrate)); + } + $ExtraReleaseDescription = $_POST['extra_release_desc'][$j]; + $ExtraTorrents[$ExtraTorrentName]['TorrentDescription'] = db_string(trim($ExtraReleaseDescription)); + $DupeNames[] = $ExtraFile['name']; + } + } + } + } } @@ -401,7 +440,71 @@ $FileString = db_string(implode("\n", $TmpFileList)); $Debug->set_flag('upload: torrent decoded'); if ($Type == 'Music') { - include(SERVER_ROOT.'/sections/upload/generate_extra_torrents.php'); + $ExtraTorrentsInsert = array(); + foreach ($ExtraTorrents as $ExtraTorrent) { + $Name = $ExtraTorrent['Name']; + $ExtraTorrentsInsert[$Name] = $ExtraTorrent; + $ThisInsert =& $ExtraTorrentsInsert[$Name]; + $ExtraTor = new BencodeTorrent($Name, true); + if (isset($ExtraTor->Dec['encrypted_files'])) { + $Err = 'At least one of the torrents contain an encrypted file list which is not supported here'; + break; + } + if (!$ExtraTor->is_private()) { + $ExtraTor->make_private(); // The torrent is now private. + $PublicTorrent = true; + } + + // File list and size + list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list(); + $ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : ''; + + $ExtraTmpFileList = array(); + foreach ($ExtraFileList as $ExtraFile) { + list($ExtraSize, $ExtraName) = $ExtraFile; + + check_file($Type, $ExtraName); + + // Make sure the file name is not too long + if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) { + $Err = "The torrent contained one or more files with too long of a name:
    $ExtraDirName/$ExtraName"; + break; + } + // Add file and size to array + $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile); + } + + // To be stored in the database + $ThisInsert['FilePath'] = db_string($ExtraDirName); + $ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList)); + $ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash()); + $ThisInsert['NumFiles'] = count($ExtraFileList); + $ThisInsert['TorEnc'] = db_string($ExtraTor->encode()); + $ThisInsert['TotalSize'] = $ExtraTotalSize; + + $Debug->set_flag('upload: torrent decoded'); + $DB->query(" + SELECT ID + FROM torrents + WHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'"); + if ($DB->has_results()) { + list($ExtraID) = $DB->next_record(); + $DB->query(" + SELECT TorrentID + FROM torrents_files + WHERE TorrentID = $ExtraID"); + if ($DB->has_results()) { + $Err = "The exact same torrent file already exists on the site!"; + } else { + //One of the lost torrents. + $DB->query(" + INSERT INTO torrents_files (TorrentID, File) + VALUES ($ExtraID, '$ThisInsert[TorEnc]')"); + $Err = "Thank you for fixing this torrent."; + } + } + } + unset($ThisInsert); } if (!empty($Err)) { // Show the upload form, with the data the user entered @@ -736,6 +839,69 @@ Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], 'uploaded ('. Torrents::update_hash($GroupID); $Debug->set_flag('upload: sphinx updated'); +foreach ($ExtraTorrentsInsert as $ExtraTorrent) { + $ExtraHasLog = 0; + $ExtraHasCue = 0; + $LogScore = 0; + // Torrent + $DB->query(" + INSERT INTO torrents + (GroupID, UserID, Media, Format, Encoding, + Remastered, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, + HasLog, HasCue, info_hash, FileCount, FileList, FilePath, Size, Time, + Description, LogScore, FreeTorrent, FreeLeechType) + VALUES + ($GroupID, $LoggedUser[ID], $T[Media], '$ExtraTorrent[Format]', '$ExtraTorrent[Encoding]', + $T[Remastered], $T[RemasterYear], $T[RemasterTitle], $T[RemasterRecordLabel], $T[RemasterCatalogueNumber], + $ExtraHasLog, $ExtraHasCue, '".db_string($ExtraTorrent['InfoHash'])."', $ExtraTorrent[NumFiles], + '$ExtraTorrent[FileString]', '$ExtraTorrent[FilePath]', $ExtraTorrent[TotalSize], '".sqltime()."', + '$ExtraTorrent[TorrentDescription]', $LogScore, '$T[FreeLeech]', '$T[FreeLeechType]')"); + + $Cache->increment('stats_torrent_count'); + $ExtraTorrentID = $DB->inserted_id(); + + Tracker::update_tracker('add_torrent', array('id' => $ExtraTorrentID, 'info_hash' => rawurlencode($ExtraTorrent['InfoHash']), 'freetorrent' => $T['FreeLeech'])); + + //******************************************************************************// + //--------------- Write torrent file -------------------------------------------// + + $DB->query(" + INSERT INTO torrents_files + (TorrentID, File) + VALUES + ($ExtraTorrentID, '$ExtraTorrent[TorEnc]')"); + + Misc::write_log("Torrent $ExtraTorrentID ($LogName) (" . number_format($ExtraTorrent['TotalSize'] / (1024 * 1024), 2) . ' MB) was uploaded by ' . $LoggedUser['Username']); + Torrents::write_group_log($GroupID, $ExtraTorrentID, $LoggedUser['ID'], 'uploaded (' . number_format($ExtraTorrent['TotalSize'] / (1024 * 1024), 2) . ' MB)', 0); + + Torrents::update_hash($GroupID); + + // IRC + $Announce = ''; + $Announce .= Artists::display_artists($ArtistForm, false); + $Announce .= trim($Properties['Title']) . ' '; + $Announce .= '[' . trim($Properties['Year']) . ']'; + if (($Properties['ReleaseType'] > 0)) { + $Announce .= ' [' . $ReleaseTypes[$Properties['ReleaseType']] . ']'; + } + $Announce .= ' - '; + $Announce .= trim(str_replace("'", '', $ExtraTorrent['Format'])) . ' / ' . trim(str_replace("'", '', $ExtraTorrent['Encoding'])); + $Announce .= ' / ' . trim($Properties['Media']); + if ($T['FreeLeech'] == '1') { + $Announce .= ' / Freeleech!'; + } + + $AnnounceSSL = $Announce . ' - ' . site_url() . "torrents.php?id=$GroupID / " . site_url() . "torrents.php?action=download&id=$ExtraTorrentID"; + $Announce .= ' - ' . site_url() . "torrents.php?id=$GroupID / " . site_url() . "torrents.php?action=download&id=$ExtraTorrentID"; + + $AnnounceSSL .= ' - ' . trim($Properties['TagList']); + $Announce .= ' - ' . trim($Properties['TagList']); + + // ENT_QUOTES is needed to decode single quotes/apostrophes + //send_irc('PRIVMSG #' . NONSSL_SITE_URL . '-announce :' . html_entity_decode($Announce, ENT_QUOTES)); + //send_irc('PRIVMSG #' . SSL_SITE_URL . '-announce-ssl :' . html_entity_decode($AnnounceSSL, ENT_QUOTES)); +} + //******************************************************************************// //--------------- Stupid Recent Uploads ----------------------------------------// @@ -1086,4 +1252,3 @@ $Cache->delete_value("torrents_details_$GroupID"); // Allow deletion of this torrent now $Cache->delete_value("torrent_{$TorrentID}_lock"); - diff --git a/sections/user/edit.php b/sections/user/edit.php index 5746cb2a4..61f08ac78 100644 --- a/sections/user/edit.php +++ b/sections/user/edit.php @@ -51,11 +51,8 @@ function checked($Checked) { return ($Checked ? ' checked="checked"' : ''); } -if ($SiteOptions) { - $SiteOptions = unserialize($SiteOptions); -} else { - $SiteOptions = array(); -} +$SiteOptions = (!empty($SiteOptions)) ? unserialize($SiteOptions) : array(); +$SiteOptions = array_merge(Users::default_site_options(), $SiteOptions); View::show_header("$Username > Settings", 'user,jquery-ui,release_sort,password_validate,validate,cssgallery,preview_paranoia,bbcode,user_settings,donor_titles'); diff --git a/static/functions/rules.js b/static/functions/rules.js index bb0832f07..461abbcb8 100644 --- a/static/functions/rules.js +++ b/static/functions/rules.js @@ -1,11 +1,11 @@ function findRule() { var query_string = $('#search_string').val(); var q = query_string.replace(/\s+/gm, '').split('+'); - var regex = new Array(); + var regex = []; for (var i = 0; i < q.length; i++) { regex[i] = new RegExp(q[i], 'mi'); } - $('#actual_rules li').each(function() { + $('#actual_rules li[id^=r]').each(function() { var show = true; for (var i = 0; i < regex.length; i++) { if (!regex[i].test($(this).html())) { @@ -15,21 +15,22 @@ function findRule() { } $(this).toggle(show); }); - $('.before_rules').toggle(query_string.length == 0); + $('.before_rules').toggle(query_string.length === 0); } $(document).ready(function() { - var original_value = $('#search_string').val(); - $('#search_string').keyup(findRule); - $('#search_string').focus(function() { - if ($(this).val() == original_value) { - $(this).val(''); - } - }); - $('#search_string').blur(function() { - if ($(this).val() == '') { - $(this).val(original_value); - $('.before_rules').show(); - } - }) + var search_string = $('#search_string'); + var original_value = search_string.val(); + search_string.keyup(findRule); + search_string.focus(function() { + if ($(this).val() === original_value) { + $(this).val(''); + } + }); + search_string.blur(function() { + if ($(this).val() === '') { + $(this).val(original_value); + $('.before_rules').show(); + } + }); });