diff --git a/classes/class_format.php b/classes/class_format.php index f55d3f06..8abfcc39 100644 --- a/classes/class_format.php +++ b/classes/class_format.php @@ -1,6 +1,5 @@ ∞'; - - if ($Color) + if ($Ratio === false) { + return '--'; + } + if ($Ratio === '∞') { + return ''; + } + if ($Color) { $Ratio = sprintf('%s', self::get_ratio_color($Ratio), self::get_ratio($Dividend, $Divisor, 5), $Ratio ); + } return $Ratio; } @@ -120,11 +126,14 @@ public static function get_ratio_html($Dividend, $Divisor, $Color = true) * @param int $Decimal floor to n decimals (eg Subtract .005 to floor to 2 decimals) * @return boolean|string */ - public function get_ratio ($Dividend, $Divisor, $Decimal = 2) - { - if ($Divisor == 0 && $Dividend == 0) return false; - if ($Divisor == 0) return '∞'; - return number_format(max($Dividend/$Divisor - (0.5/pow(10, $Decimal)), 0), $Decimal); + public function get_ratio ($Dividend, $Divisor, $Decimal = 2) { + if ($Divisor == 0 && $Dividend == 0) { + return false; + } + if ($Divisor == 0) { + return '∞'; + } + return number_format(max($Dividend / $Divisor - (0.5 / pow(10, $Decimal)), 0), $Decimal); } /** @@ -188,8 +197,8 @@ public static function catalogue_limit($Page, $PerPage, $CatalogueSize=500) { return array($CatalogueID, $CatalogueLimit); } - public static function catalogue_select($Catalogue, $Page, $PerPage, $CatalogueSize=500) { - return array_slice($Catalogue,(($PerPage*$Page-$PerPage)%$CatalogueSize),$PerPage,true); + public static function catalogue_select($Catalogue, $Page, $PerPage, $CatalogueSize = 500) { + return array_slice($Catalogue,(($PerPage * $Page - $PerPage) % $CatalogueSize),$PerPage,true); } @@ -197,41 +206,41 @@ public static function catalogue_select($Catalogue, $Page, $PerPage, $CatalogueS * Returns a page list, given certain information about the pages. * * @param int $StartPage: The current record the page you're on starts with. - * eg. if you're on page 2 of a forum thread with 25 posts per page, $StartPage is 25. + * e.g. if you're on page 2 of a forum thread with 25 posts per page, $StartPage is 25. * If you're on page 1, $StartPage is 0. * @param int $TotalRecords: The total number of records in the result set. - * eg. if you're on a forum thread with 152 posts, $TotalRecords is 152. + * e.g. if you're on a forum thread with 152 posts, $TotalRecords is 152. * @param int $ItemsPerPage: Self-explanatory. The number of records shown on each page - * eg. if there are 25 posts per forum page, $ItemsPerPage is 25. + * e.g. if there are 25 posts per forum page, $ItemsPerPage is 25. * @param int $ShowPages: The number of page links that are shown. - * eg. If there are 20 pages that exist, but $ShowPages is only 11, only 11 links will be shown. + * e.g. If there are 20 pages that exist, but $ShowPages is only 11, only 11 links will be shown. * @param string $Anchor A URL fragment to attach to the links. - * eg. '#comment12' + * e.g. '#comment12' * @return A sanitized HTML page listing. */ - public static function get_pages($StartPage,$TotalRecords,$ItemsPerPage,$ShowPages=11,$Anchor='') { + public static function get_pages($StartPage, $TotalRecords, $ItemsPerPage, $ShowPages = 11, $Anchor = '') { global $Document, $Method, $Mobile; $Location = $Document.'.php'; $StartPage = ceil($StartPage); $TotalPages = 0; if ($TotalRecords > 0) { - $StartPage = min($StartPage, ceil($TotalRecords/$ItemsPerPage)); + $StartPage = min($StartPage, ceil($TotalRecords / $ItemsPerPage)); $ShowPages--; - $TotalPages = ceil($TotalRecords/$ItemsPerPage); + $TotalPages = ceil($TotalRecords / $ItemsPerPage); if ($TotalPages > $ShowPages) { - $StartPosition = $StartPage-round($ShowPages/2); + $StartPosition = $StartPage - round($ShowPages / 2); if ($StartPosition <= 0) { $StartPosition = 1; } else { - if ($StartPosition >= ($TotalPages-$ShowPages)) { - $StartPosition = $TotalPages-$ShowPages; + if ($StartPosition >= ($TotalPages - $ShowPages)) { + $StartPosition = $TotalPages - $ShowPages; } } - $StopPage = $ShowPages+$StartPosition; + $StopPage = $ShowPages + $StartPosition; } else { $StopPage = $TotalPages; @@ -259,18 +268,18 @@ public static function get_pages($StartPage,$TotalRecords,$ItemsPerPage,$ShowPag $Pages .= ''; } $Pages .= ""; - if ($i*$ItemsPerPage > $TotalRecords) { - $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($TotalRecords); + if ($i * $ItemsPerPage > $TotalRecords) { + $Pages .= ((($i - 1) * $ItemsPerPage) + 1).'-'.($TotalRecords); } else { - $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($i*$ItemsPerPage); + $Pages .= ((($i - 1) * $ItemsPerPage) + 1).'-'.($i * $ItemsPerPage); } - $Pages .= ""; + $Pages .= ''; if ($i != $StartPage) { $Pages.=''; } if ($i < $StopPage) { - $Pages.=" | "; + $Pages.=' | '; } } } else { @@ -278,7 +287,7 @@ public static function get_pages($StartPage,$TotalRecords,$ItemsPerPage,$ShowPag } if ($StartPage && $StartPage < $TotalPages) { - $Pages .= ' | Next > '; + $Pages .= ' | Next > '; $Pages .= ' Last >>'; } } @@ -314,9 +323,9 @@ public static function get_size($Size, $Levels = 2) { */ public static function human_format($Number) { $Steps = 0; - while($Number>=1000) { + while ($Number >= 1000) { $Steps++; - $Number=$Number/1000; + $Number = $Number / 1000; } switch ($Steps) { case 0: return round($Number); break; @@ -393,11 +402,11 @@ public static function form($Index, $Return = false) { * @param $Array The array the option is in, defaults to GET. * @return */ - public static function selected($Name, $Value, $Attribute='selected', $Array = array()) { + public static function selected($Name, $Value, $Attribute = 'selected', $Array = array()) { if (empty($Array)) { $Array = $_GET; } - if (isset($Array[$Name]) && $Array[$Name]!=='') { + if (isset($Array[$Name]) && $Array[$Name] !== '') { if ($Array[$Name] == $Value) { echo ' '.$Attribute.'="'.$Attribute.'"'; } @@ -468,12 +477,21 @@ public static function add_class($Target, $Tests, $ClassName, $AddAttribute, $Us * @return UTF-8 encoded version of $Str */ public static function make_utf8($Str) { - if ($Str!="") { - if (self::is_utf8($Str)) { $Encoding="UTF-8"; } - if (empty($Encoding)) { $Encoding=mb_detect_encoding($Str,'UTF-8, ISO-8859-1'); } - if (empty($Encoding)) { $Encoding="ISO-8859-1"; } - if ($Encoding=="UTF-8") { return $Str; } - else { return @mb_convert_encoding($Str,"UTF-8",$Encoding); } + if ($Str != '') { + if (self::is_utf8($Str)) { + $Encoding = 'UTF-8'; + } + if (empty($Encoding)) { + $Encoding = mb_detect_encoding($Str,'UTF-8, ISO-8859-1'); + } + if (empty($Encoding)) { + $Encoding = 'ISO-8859-1'; + } + if ($Encoding == 'UTF-8') { + return $Str; + } else { + return @mb_convert_encoding($Str,'UTF-8',$Encoding); + } } } @@ -508,8 +526,11 @@ public static function is_utf8($Str) { public static function find_torrent_label_class ($text) { $index = mb_eregi_replace('(?:[^\w\d\s]+)', '', strtolower($text)); - if (isset(self::$TorrentLabels[$index])) return self::$TorrentLabels[$index]; - return self::$TorrentLabels['default']; + if (isset(self::$TorrentLabels[$index])) { + return self::$TorrentLabels[$index]; + } else { + return self::$TorrentLabels['default']; + } } /** @@ -522,9 +543,11 @@ public static function find_torrent_label_class ($text) * @param string $class Custom CSS class * @return string Strong element */ - public static function torrent_label ($text, $class='') + public static function torrent_label ($text, $class = '') { - if (empty($class)) $class = self::find_torrent_label_class($text); + if (empty($class)) { + $class = self::find_torrent_label_class($text); + } return sprintf('%2$s', display_str($class), display_str($text)); } @@ -541,4 +564,4 @@ public static function css_category ($CategoryID = 1) return 'cats_' . strtolower(str_replace(array('-', ' '), '', $Categories[$CategoryID - 1])); } -} \ No newline at end of file +} diff --git a/classes/class_irc.php b/classes/class_irc.php index 4c28b835..9aaa506e 100644 --- a/classes/class_irc.php +++ b/classes/class_irc.php @@ -180,6 +180,7 @@ protected function listen() { } if (isset($this->DisabledUsers[$Nick[1]])) { $DB->query("DELETE FROM disable_list WHERE Nick = '" . $Nick[1] . "'"); + $Cache->increment_value('num_disablees', -1); unset($this->DisabledUsers[$Nick[1]]); } } @@ -187,6 +188,7 @@ protected function listen() { if (preg_match("/:([^!]+)![^\s]* PART #what.cd-disabled/", $this->Data, $Nick)) { if (isset($this->DisabledUsers[$Nick[1]])) { $DB->query("DELETE FROM disable_list WHERE Nick = '" . $Nick[1] . "'"); + $Cache->increment_value('num_disablees', -1); unset($this->DisabledUsers[$Nick[1]]); } } @@ -195,6 +197,7 @@ protected function listen() { $Nick = explode(" ", $Nick[0]); if (isset($this->DisabledUsers[$Nick[3]])) { $DB->query("DELETE FROM disable_list WHERE Nick = '" . $Nick[3] . "'"); + $Cache->increment_value('num_disablees', -1); unset($this->DisabledUsers[$Nick[3]]); } } diff --git a/sections/ajax/requests.php b/sections/ajax/requests.php index 7e4bdf0e..0a7c23c4 100644 --- a/sections/ajax/requests.php +++ b/sections/ajax/requests.php @@ -15,9 +15,9 @@ $BookmarkView = false; -if(empty($_GET['type'])) { +if (empty($_GET['type'])) { $Title = 'Requests'; - if(!check_perms('site_see_old_requests') || empty($_GET['showall'])) { + if (!check_perms('site_see_old_requests') || empty($_GET['showall'])) { $SS->set_filter('visible', array(1)); } } else { @@ -27,8 +27,8 @@ $SS->set_filter('userid', array($LoggedUser['ID'])); break; case 'voted': - if(!empty($_GET['userid'])) { - if(is_number($_GET['userid'])) { + if (!empty($_GET['userid'])) { + if (is_number($_GET['userid'])) { if (!check_paranoia('requestsvoted_list', $UserInfo['Paranoia'], $Perms['Class'], $_GET['userid'])) { print json_encode(array('status' => 'failure')); die(); @@ -45,7 +45,7 @@ } break; case 'filled': - if(empty($_GET['userid']) || !is_number($_GET['userid'])) { + if (empty($_GET['userid']) || !is_number($_GET['userid'])) { print json_encode(array('status' => 'failure')); die(); } else { @@ -68,132 +68,132 @@ } } -if($Submitted && empty($_GET['show_filled'])) { +if ($Submitted && empty($_GET['show_filled'])) { $SS->set_filter('torrentid', array(0)); } -if(!empty($_GET['search'])) { +if (!empty($_GET['search'])) { $Words = explode(' ', $_GET['search']); - foreach($Words as $Key => &$Word) { - if($Word[0] == '!' && strlen($Word) > 2) { - if(strpos($Word,'!',1) === false) { + foreach ($Words as $Key => &$Word) { + if ($Word[0] == '!' && strlen($Word) > 2) { + if (strpos($Word,'!',1) === false) { $Word = '!'.$SS->EscapeString(substr($Word,1)); } else { $Word = $SS->EscapeString($Word); } - } elseif(strlen($Word) >= 2) { + } elseif (strlen($Word) >= 2) { $Word = $SS->EscapeString($Word); } else { unset($Words[$Key]); } } - if(!empty($Words)) { + if (!empty($Words)) { $Queries[] = "@* ".implode(' ', $Words); } } -if(!empty($_GET['tags'])){ +if (!empty($_GET['tags'])){ $Tags = explode(',', $_GET['tags']); $TagNames = array(); foreach ($Tags as $Tag) { $Tag = Misc::sanitize_tag($Tag); - if(!empty($Tag)) { + if (!empty($Tag)) { $TagNames[] = $Tag; } } $Tags = Misc::get_tags($TagNames); } -if(empty($_GET['tags_type']) && !empty($Tags)) { +if (empty($_GET['tags_type']) && !empty($Tags)) { $_GET['tags_type'] = '0'; $SS->set_filter('tagid', array_keys($Tags)); -} elseif(!empty($Tags)) { - foreach(array_keys($Tags) as $Tag) { +} elseif (!empty($Tags)) { + foreach (array_keys($Tags) as $Tag) { $SS->set_filter('tagid', array($Tag)); } } else { $_GET['tags_type'] = '1'; } -if(!empty($_GET['filter_cat'])) { +if (!empty($_GET['filter_cat'])) { $CategoryArray = array_keys($_GET['filter_cat']); - if(count($CategoryArray) != count($Categories)) { - foreach($CategoryArray as $Key => $Index) { - if(!isset($Categories[$Index-1])) { + if (count($CategoryArray) != count($Categories)) { + foreach ($CategoryArray as $Key => $Index) { + if (!isset($Categories[$Index-1])) { unset($CategoryArray[$Key]); } } - if(count($CategoryArray) >= 1) { + if (count($CategoryArray) >= 1) { $SS->set_filter('categoryid', $CategoryArray); } } } -if(!empty($_GET['releases'])) { +if (!empty($_GET['releases'])) { $ReleaseArray = $_GET['releases']; - if(count($ReleaseArray) != count($ReleaseTypes)) { - foreach($ReleaseArray as $Index => $Value) { - if(!isset($ReleaseTypes[$Value])) { + if (count($ReleaseArray) != count($ReleaseTypes)) { + foreach ($ReleaseArray as $Index => $Value) { + if (!isset($ReleaseTypes[$Value])) { unset($ReleaseArray[$Index]); } } - if(count($ReleaseArray) >= 1) { + if (count($ReleaseArray) >= 1) { $SS->set_filter('releasetype', $ReleaseArray); } } } -if(!empty($_GET['formats'])) { +if (!empty($_GET['formats'])) { $FormatArray = $_GET['formats']; - if(count($FormatArray) != count($Formats)) { + if (count($FormatArray) != count($Formats)) { $FormatNameArray = array(); - foreach($FormatArray as $Index => $MasterIndex) { - if(isset($Formats[$MasterIndex])) { + foreach ($FormatArray as $Index => $MasterIndex) { + if (isset($Formats[$MasterIndex])) { $FormatNameArray[$Index] = '"'.strtr($Formats[$MasterIndex], '-.', ' ').'"'; } } - if(count($FormatNameArray) >= 1) { + if (count($FormatNameArray) >= 1) { $Queries[]='@formatlist (any | '.implode(' | ', $FormatNameArray).')'; } } } -if(!empty($_GET['media'])) { +if (!empty($_GET['media'])) { $MediaArray = $_GET['media']; - if(count($MediaArray) != count($Media)) { + if (count($MediaArray) != count($Media)) { $MediaNameArray = array(); - foreach($MediaArray as $Index => $MasterIndex) { - if(isset($Media[$MasterIndex])) { + foreach ($MediaArray as $Index => $MasterIndex) { + if (isset($Media[$MasterIndex])) { $MediaNameArray[$Index] = '"'.strtr($Media[$MasterIndex], '-.', ' ').'"'; } } - if(count($MediaNameArray) >= 1) { + if (count($MediaNameArray) >= 1) { $Queries[]='@medialist (any | '.implode(' | ', $MediaNameArray).')'; } } } -if(!empty($_GET['bitrates'])) { +if (!empty($_GET['bitrates'])) { $BitrateArray = $_GET['bitrates']; - if(count($BitrateArray) != count($Bitrates)) { + if (count($BitrateArray) != count($Bitrates)) { $BitrateNameArray = array(); - foreach($BitrateArray as $Index => $MasterIndex) { - if(isset($Bitrates[$MasterIndex])) { + foreach ($BitrateArray as $Index => $MasterIndex) { + if (isset($Bitrates[$MasterIndex])) { $BitrateNameArray[$Index] = '"'.strtr($SS->EscapeString($Bitrates[$MasterIndex]), '-.', ' ').'"'; } } - if(count($BitrateNameArray) >= 1) { + if (count($BitrateNameArray) >= 1) { $Queries[]='@bitratelist (any | '.implode(' | ', $BitrateNameArray).')'; } } } -if(!empty($_GET['requestor']) && check_perms('site_see_old_requests')) { - if(is_number($_GET['requestor'])) { +if (!empty($_GET['requestor']) && check_perms('site_see_old_requests')) { + if (is_number($_GET['requestor'])) { $SS->set_filter('userid', array($_GET['requestor'])); } else { print json_encode(array('status' => 'failure')); @@ -201,8 +201,8 @@ } } -if(isset($_GET['year'])) { - if(is_number($_GET['year']) || $_GET['year'] == 0) { +if (isset($_GET['year'])) { + if (is_number($_GET['year']) || $_GET['year'] == 0) { $SS->set_filter('year', array($_GET['year'])); } else { print json_encode(array('status' => 'failure')); @@ -210,7 +210,7 @@ } } -if(!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { +if (!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { $Page = $_GET['page']; $SS->limit(($Page - 1) * REQUESTS_PER_PAGE, REQUESTS_PER_PAGE); } else { @@ -218,15 +218,15 @@ $SS->limit(0, REQUESTS_PER_PAGE); } -if(empty($_GET['order'])) { +if (empty($_GET['order'])) { $CurrentOrder = 'created'; $CurrentSort = 'desc'; $Way = SPH_SORT_ATTR_DESC; $NewSort = 'asc'; } else { - if(in_array($_GET['order'], $OrderWays)) { + if (in_array($_GET['order'], $OrderWays)) { $CurrentOrder = $_GET['order']; - if($_GET['sort'] == 'asc' || $_GET['sort'] == 'desc') { + if ($_GET['sort'] == 'asc' || $_GET['sort'] == 'desc') { $CurrentSort = $_GET['sort']; $Way = ($CurrentSort == 'asc' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC); $NewSort = ($_GET['sort'] == 'asc' ? 'desc' : 'asc'); @@ -266,10 +266,10 @@ //print($Way); print($OrderBy); die(); $SS->SetSortMode($Way, $OrderBy); -if(count($Queries) > 0) { +if (count($Queries) > 0) { $Query = implode(' ',$Queries); } else { - $Query=''; + $Query = ''; } $SS->set_index('requests requests_delta'); @@ -277,19 +277,19 @@ $NumResults = $SS->TotalResults; //We don't use sphinxapi's default cache searcher, we use our own functions -if(!empty($SphinxResults['notfound'])) { +if (!empty($SphinxResults['notfound'])) { $SQLResults = Requests::get_requests($SphinxResults['notfound']); - if(is_array($SQLResults['notfound'])) { + if (is_array($SQLResults['notfound'])) { //Something wasn't found in the db, remove it from results reset($SQLResults['notfound']); - foreach($SQLResults['notfound'] as $ID) { + foreach ($SQLResults['notfound'] as $ID) { unset($SQLResults['matches'][$ID]); unset($SphinxResults['matches'][$ID]); } } // Merge SQL results with memcached results - foreach($SQLResults['matches'] as $ID => $SQLResult) { + foreach ($SQLResults['matches'] as $ID => $SQLResult) { $SphinxResults['matches'][$ID] = $SQLResult; //$Requests['matches'][$ID] = array_merge($Requests['matches'][$ID], $SQLResult); @@ -328,14 +328,14 @@ $VoteCount = count($RequestVotes['Voters']); - if($CategoryID == 0) { + if ($CategoryID == 0) { $CategoryName = "Unknown"; } else { $CategoryName = $Categories[$CategoryID - 1]; } $JsonArtists = array(); - if($CategoryName == "Music") { + if ($CategoryName == "Music") { $ArtistForm = get_request_artists($RequestID); $JsonArtists = array_values($ArtistForm); } diff --git a/sections/ajax/top10/users.php b/sections/ajax/top10/users.php index 67bfe59a..819a17d5 100644 --- a/sections/ajax/top10/users.php +++ b/sections/ajax/top10/users.php @@ -1,8 +1,6 @@ 'failure')); @@ -16,82 +14,83 @@ $Limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10; $Limit = in_array($Limit, array(10,100,250)) ? $Limit : 10; -$BaseQuery = "SELECT - u.ID, - u.Username, - ui.JoinDate, - u.Uploaded, - u.Downloaded, - ABS(u.Uploaded-524288000) / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS UpSpeed, - u.Downloaded / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS DownSpeed, - COUNT(t.ID) AS NumUploads +$BaseQuery = " + SELECT + u.ID, + u.Username, + ui.JoinDate, + u.Uploaded, + u.Downloaded, + ABS(u.Uploaded-524288000) / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS UpSpeed, + u.Downloaded / (".time()." - UNIX_TIMESTAMP(ui.JoinDate)) AS DownSpeed, + COUNT(t.ID) AS NumUploads FROM users_main AS u - JOIN users_info AS ui ON ui.UserID = u.ID - LEFT JOIN torrents AS t ON t.UserID=u.ID + JOIN users_info AS ui ON ui.UserID = u.ID + LEFT JOIN torrents AS t ON t.UserID=u.ID WHERE u.Enabled='1' - AND Uploaded>'". 5*1024*1024*1024 ."' - AND Downloaded>'". 5*1024*1024*1024 ."' - AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%')) + AND Uploaded>'". 5 * 1024 * 1024 * 1024 ."' + AND Downloaded>'". 5 * 1024 * 1024 * 1024 ."' + AND (Paranoia IS NULL OR (Paranoia NOT LIKE '%\"uploaded\"%' AND Paranoia NOT LIKE '%\"downloaded\"%')) GROUP BY u.ID"; $OuterResults = array(); -if($Details == 'all' || $Details == 'ul') { +if ($Details == 'all' || $Details == 'ul') { if (!$TopUserUploads = $Cache->get_value('topuser_ul_'.$Limit)) { $DB->query("$BaseQuery ORDER BY u.Uploaded DESC LIMIT $Limit;"); $TopUserUploads = $DB->to_array(); - $Cache->cache_value('topuser_ul_'.$Limit,$TopUserUploads,3600*12); + $Cache->cache_value('topuser_ul_'.$Limit,$TopUserUploads,3600 * 12); } $OuterResults[] = generate_user_json('Uploaders', 'ul', $TopUserUploads, $Limit); } -if($Details == 'all' || $Details == 'dl') { +if ($Details == 'all' || $Details == 'dl') { if (!$TopUserDownloads = $Cache->get_value('topuser_dl_'.$Limit)) { $DB->query("$BaseQuery ORDER BY u.Downloaded DESC LIMIT $Limit;"); $TopUserDownloads = $DB->to_array(); - $Cache->cache_value('topuser_dl_'.$Limit,$TopUserDownloads,3600*12); + $Cache->cache_value('topuser_dl_'.$Limit,$TopUserDownloads,3600 * 12); } $OuterResults[] = generate_user_json('Downloaders', 'dl', $TopUserDownloads, $Limit); } -if($Details == 'all' || $Details == 'numul') { +if ($Details == 'all' || $Details == 'numul') { if (!$TopUserNumUploads = $Cache->get_value('topuser_numul_'.$Limit)) { $DB->query("$BaseQuery ORDER BY NumUploads DESC LIMIT $Limit;"); $TopUserNumUploads = $DB->to_array(); - $Cache->cache_value('topuser_numul_'.$Limit,$TopUserNumUploads,3600*12); + $Cache->cache_value('topuser_numul_'.$Limit,$TopUserNumUploads,3600 * 12); } $OuterResults[] = generate_user_json('Torrents Uploaded', 'numul', $TopUserNumUploads, $Limit); } -if($Details == 'all' || $Details == 'uls') { +if ($Details == 'all' || $Details == 'uls') { if (!$TopUserUploadSpeed = $Cache->get_value('topuser_ulspeed_'.$Limit)) { $DB->query("$BaseQuery ORDER BY UpSpeed DESC LIMIT $Limit;"); $TopUserUploadSpeed = $DB->to_array(); - $Cache->cache_value('topuser_ulspeed_'.$Limit,$TopUserUploadSpeed,3600*12); + $Cache->cache_value('topuser_ulspeed_'.$Limit,$TopUserUploadSpeed,3600 * 12); } $OuterResults[] = generate_user_json('Fastest Uploaders', 'uls', $TopUserUploadSpeed, $Limit); } -if($Details == 'all' || $Details == 'dls') { +if ($Details == 'all' || $Details == 'dls') { if (!$TopUserDownloadSpeed = $Cache->get_value('topuser_dlspeed_'.$Limit)) { $DB->query("$BaseQuery ORDER BY DownSpeed DESC LIMIT $Limit;"); $TopUserDownloadSpeed = $DB->to_array(); - $Cache->cache_value('topuser_dlspeed_'.$Limit,$TopUserDownloadSpeed,3600*12); + $Cache->cache_value('topuser_dlspeed_'.$Limit,$TopUserDownloadSpeed,3600 * 12); } $OuterResults[] = generate_user_json('Fastest Downloaders', 'dls', $TopUserDownloadSpeed, $Limit); } print - json_encode( - array( - 'status' => 'success', - 'response' => $OuterResults - ) - ); + json_encode( + array( + 'status' => 'success', + 'response' => $OuterResults + ) + ); function generate_user_json($Caption, $Tag, $Details, $Limit) { $results = array(); - foreach($Details as $Details) { + foreach ($Details as $Details) { $results[] = array( 'id' => (int) $Detail['ID'], 'username' => $Detail['Username'], diff --git a/sections/ajax/userhistory/index.php b/sections/ajax/userhistory/index.php index 6b3106c0..6d4e6a55 100644 --- a/sections/ajax/userhistory/index.php +++ b/sections/ajax/userhistory/index.php @@ -1,21 +1,20 @@ 'failure') - ); - } -} -else { - print json_encode( - array('status' => 'failure') - ); + switch ($_GET['type']) { + case 'posts': + // Load post history page + include('post_history.php'); + break; + default: + print json_encode( + array('status' => 'failure') + ); + } +} else { + print json_encode( + array('status' => 'failure') + ); } -?> \ No newline at end of file +?> diff --git a/sections/ajax/userhistory/post_history.php b/sections/ajax/userhistory/post_history.php index 5d29c6ca..edf96e52 100644 --- a/sections/ajax/userhistory/post_history.php +++ b/sections/ajax/userhistory/post_history.php @@ -5,15 +5,15 @@ */ function error_out($reason = '') { - $error = array('status' => 'failure'); - if ($reason != '') - $error['reason'] = $reason; - print $error; - die(); + $error = array('status' => 'failure'); + if ($reason != '') + $error['reason'] = $reason; + print $error; + die(); } if (!empty($LoggedUser['DisableForums'])) { - error_out("You do not have access to the forums!"); + error_out('You do not have access to the forums!'); } @@ -23,7 +23,7 @@ function error_out($reason = '') { $UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid']; if (!is_number($UserID)) { - error_out("User does not exist!"); + error_out('User does not exist!'); } if (isset($LoggedUser['PostsPerPage'])) { @@ -43,11 +43,11 @@ function error_out($reason = '') { i.Donor, i.Warned FROM users_main AS m - JOIN users_info AS i ON i.UserID = m.ID + JOIN users_info AS i ON i.UserID = m.ID WHERE m.ID = $UserID"); if ($DB->record_count() == 0){ // If user doesn't exist - error_out("User does not exist!"); + error_out('User does not exist!'); } list($Username, $Enabled, $Title, $Avatar, $Donor, $Warned) = $DB->next_record(); } else { @@ -67,32 +67,32 @@ function error_out($reason = '') { $ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group'])); if ($ShowGrouped) { $sql = 'SELECT - SQL_CALC_FOUND_ROWS - MAX(p.ID) AS ID + SQL_CALC_FOUND_ROWS + MAX(p.ID) AS ID FROM forums_posts AS p - LEFT JOIN forums_topics AS t ON t.ID = p.TopicID'; + LEFT JOIN forums_topics AS t ON t.ID = p.TopicID'; if ($ShowUnread) { $sql.=' - LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID']; + LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID']; } $sql .= ' - LEFT JOIN forums AS f ON f.ID = t.ForumID + LEFT JOIN forums AS f ON f.ID = t.ForumID WHERE p.AuthorID = '.$UserID.' - AND ((f.MinClassRead <= '.$LoggedUser['EffectiveClass']; + AND ((f.MinClassRead <= '.$LoggedUser['EffectiveClass']; if (!empty($RestrictedForums)) { $sql.=' - AND f.ID NOT IN (\''.$RestrictedForums.'\')'; + AND f.ID NOT IN (\''.$RestrictedForums.'\')'; } $sql .= ')'; if (!empty($PermittedForums)) { $sql.=' - OR f.ID IN (\''.$PermittedForums.'\')'; + OR f.ID IN (\''.$PermittedForums.'\')'; } $sql .= ')'; if ($ShowUnread) { $sql .= ' - AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') - AND (l.PostIDquery($sql); @@ -152,23 +152,23 @@ function error_out($reason = '') { t.IsLocked, t.IsSticky FROM forums_posts as p - LEFT JOIN users_main AS um ON um.ID = p.AuthorID - LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID - LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID - JOIN forums_topics AS t ON t.ID = p.TopicID - JOIN forums AS f ON f.ID = t.ForumID - LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID + LEFT JOIN users_main AS um ON um.ID = p.AuthorID + LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID + LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID + JOIN forums_topics AS t ON t.ID = p.TopicID + JOIN forums AS f ON f.ID = t.ForumID + LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID WHERE p.AuthorID = '.$UserID.' - AND f.MinClassRead <= '.$LoggedUser['EffectiveClass']; + AND f.MinClassRead <= '.$LoggedUser['EffectiveClass']; if (!empty($RestrictedForums)) { $sql.=' - AND f.ID NOT IN (\''.$RestrictedForums.'\')'; + AND f.ID NOT IN (\''.$RestrictedForums.'\')'; } if ($ShowUnread) { $sql.=' - AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND (l.PostIDnext_record()) { - $JsonResults[] = array( - 'postId' => (int) $PostID, - 'topicId' => (int) $TopicID, - 'threadTitle' => $ThreadTitle, - 'lastPostId' => (int) $LastPostID, - 'lastRead' => (int) $LastRead, - 'locked' => $Locked == 1, - 'sticky' => $Sticky == 1, - 'addedTime' => $AddedTime, - 'body' => $Text->full_format($Body), - 'bbbody' => $Body, - 'editedUserId' => (int) $EditedUserID, - 'editedTime' => $EditedTime, - 'editedUsername' => $EditedUsername - ); + $JsonResults[] = array( + 'postId' => (int) $PostID, + 'topicId' => (int) $TopicID, + 'threadTitle' => $ThreadTitle, + 'lastPostId' => (int) $LastPostID, + 'lastRead' => (int) $LastRead, + 'locked' => $Locked == 1, + 'sticky' => $Sticky == 1, + 'addedTime' => $AddedTime, + 'body' => $Text->full_format($Body), + 'bbbody' => $Body, + 'editedUserId' => (int) $EditedUserID, + 'editedTime' => $EditedTime, + 'editedUsername' => $EditedUsername + ); } print json_encode( - array( - 'status' => 'success', - 'response' => array( - 'currentPage' => (int) $Page, - 'pages' => ceil($Results/$PerPage), - 'threads' => $JsonResults - ) - ) - ); + array( + 'status' => 'success', + 'response' => array( + 'currentPage' => (int) $Page, + 'pages' => ceil($Results/$PerPage), + 'threads' => $JsonResults + ) + ) + ); diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 63421e60..f30c3df7 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -2,7 +2,7 @@ //~~~~~~~~~~~ Main artist page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// //For sorting tags -function compare($X, $Y){ +function compare($X, $Y) { return($Y['count'] - $X['count']); } @@ -18,12 +18,14 @@ function compare($X, $Y){ $UserVotes = Votes::get_user_votes($LoggedUser['ID']); $ArtistID = $_GET['id']; -if(!is_number($ArtistID)) { error(0); } +if (!is_number($ArtistID)) { + error(0); +} -if(!empty($_GET['revisionid'])) { // if they're viewing an old revision +if (!empty($_GET['revisionid'])) { // if they're viewing an old revision $RevisionID=$_GET['revisionid']; - if(!is_number($RevisionID)) { + if (!is_number($RevisionID)) { error(0); } $Data = $Cache->get_value("artist_$ArtistID"."_revision_$RevisionID", true); @@ -32,7 +34,7 @@ function compare($X, $Y){ $RevisionID = false; } -if($Data) { +if ($Data) { if (!is_array($Data)) { $Data = unserialize($Data); } @@ -40,27 +42,29 @@ function compare($X, $Y){ } else { if ($RevisionID) { $sql = "SELECT - a.Name, - wiki.Image, - wiki.body, - a.VanityHouse - FROM wiki_artists AS wiki - LEFT JOIN artists_group AS a ON wiki.RevisionID=a.RevisionID - WHERE wiki.RevisionID='$RevisionID' "; + a.Name, + wiki.Image, + wiki.body, + a.VanityHouse + FROM wiki_artists AS wiki + LEFT JOIN artists_group AS a ON wiki.RevisionID=a.RevisionID + WHERE wiki.RevisionID='$RevisionID' "; } else { $sql = "SELECT - a.Name, - wiki.Image, - wiki.body, - a.VanityHouse - FROM artists_group AS a - LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID=a.RevisionID - WHERE a.ArtistID='$ArtistID' "; + a.Name, + wiki.Image, + wiki.body, + a.VanityHouse + FROM artists_group AS a + LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID=a.RevisionID + WHERE a.ArtistID='$ArtistID' "; } $sql .= " GROUP BY a.ArtistID"; $DB->query($sql); - if($DB->record_count()==0) { error(404); } + if ($DB->record_count() == 0) { + error(404); + } list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(0)); } @@ -72,24 +76,24 @@ function compare($X, $Y){ // Requests $Requests = $Cache->get_value('artists_requests_'.$ArtistID); -if(!is_array($Requests)) { +if (!is_array($Requests)) { $DB->query("SELECT - r.ID, - r.CategoryID, - r.Title, - r.Year, - r.TimeAdded, - COUNT(rv.UserID) AS Votes, - SUM(rv.Bounty) AS Bounty - FROM requests AS r - LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID - LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID - WHERE ra.ArtistID = ".$ArtistID." - AND r.TorrentID = 0 - GROUP BY r.ID - ORDER BY Votes DESC"); + r.ID, + r.CategoryID, + r.Title, + r.Year, + r.TimeAdded, + COUNT(rv.UserID) AS Votes, + SUM(rv.Bounty) AS Bounty + FROM requests AS r + LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID + LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID + WHERE ra.ArtistID = ".$ArtistID." + AND r.TorrentID = 0 + GROUP BY r.ID + ORDER BY Votes DESC"); - if($DB->record_count() > 0) { + if ($DB->record_count() > 0) { $Requests = $DB->to_array(); } else { $Requests = array(); @@ -101,11 +105,11 @@ function compare($X, $Y){ if (($Importances = $Cache->get_value('artist_groups_'.$ArtistID)) === false) { $DB->query("SELECT - DISTINCTROW ta.GroupID, ta.Importance, tg.VanityHouse, tg.Year - FROM torrents_artists AS ta - JOIN torrents_group AS tg ON tg.ID=ta.GroupID - WHERE ta.ArtistID='$ArtistID' - ORDER BY tg.Year DESC, tg.Name DESC"); + DISTINCTROW ta.GroupID, ta.Importance, tg.VanityHouse, tg.Year + FROM torrents_artists AS ta + JOIN torrents_group AS tg ON tg.ID=ta.GroupID + WHERE ta.ArtistID='$ArtistID' + ORDER BY tg.Year DESC, tg.Name DESC"); $GroupIDs = $DB->collect('GroupID'); $Importances = $DB->to_array(false, MYSQLI_BOTH, false); $Cache->cache_value('artist_groups_'.$ArtistID, $Importances, 0); @@ -206,7 +210,7 @@ function compare($X, $Y){ if (!empty($UsedReleases)) { ?>
+ if ($OpenTable) { ?> @@ -330,7 +334,7 @@ function compare($X, $Y){ $DisplayName =''.$GroupName.''; - if(check_perms('users_mod') || check_perms('torrents_fix_ghosts')) { + if (check_perms('users_mod') || check_perms('torrents_fix_ghosts')) { $DisplayName .= ' Fix'; } @@ -344,17 +348,17 @@ function compare($X, $Y){ unset($ExtendedArtists[2]); unset($ExtendedArtists[3]); $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName; - } elseif(count($GroupArtists)>0) { + } elseif (count($GroupArtists) > 0) { $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName; } break; - case 1022: // Show performers on composer pages + case 1022: // Show performers on composer pages if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5])) { unset($ExtendedArtists[4]); unset($ExtendedArtists[3]); unset($ExtendedArtists[6]); $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName; - } elseif(count($GroupArtists)>0) { + } elseif (count($GroupArtists) > 0) { $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName; } break; @@ -364,9 +368,13 @@ function compare($X, $Y){ } } - if($GroupYear>0) { $DisplayName = $GroupYear. ' - '.$DisplayName; } + if ($GroupYear > 0) { + $DisplayName = $GroupYear. ' - '.$DisplayName; + } - if($GroupVanityHouse) { $DisplayName .= ' [VH]'; } + if ($GroupVanityHouse) { + $DisplayName .= ' [VH]'; + } $SnatchedGroupClass = $GroupFlags['IsSnatched'] ? ' snatched_group' : ''; ?> @@ -410,8 +418,9 @@ function compare($X, $Y){ } $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; - if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear || - $Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) { + if ($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear || + $Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != + $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) { $EditionID++; @@ -445,7 +454,7 @@ function compare($X, $Y){ +if (!empty($TorrentList)) { ?>
Remove bookmark @@ -490,39 +499,39 @@ function compare($X, $Y){ ?> Bookmark - Edit - + View history Info Concerts Comments - + Delete - Revert to this revision - + - + -