diff --git a/classes/class_sphinxql.php b/classes/class_sphinxql.php index 1ac14883..74c296da 100644 --- a/classes/class_sphinxql.php +++ b/classes/class_sphinxql.php @@ -119,6 +119,9 @@ public function escape_string($String) { '!'=>'\\\\!', '"'=>'\\\\"', '/'=>'\\\\/', + '*'=>'\\\\*', + '$'=>'\\\\$', + '^'=>'\\\\^', '\\'=>'\\\\\\\\') ); } @@ -262,35 +265,50 @@ public function where_match($Expr, $Field = '*', $Escape = true) { /** * Specify the order of the matches. Calling this function multiple times sets secondary priorities * - * @param string $Attribute attribute to use for sorting + * @param string $Attribute attribute to use for sorting. + * Passing an empty attribute value will clear the current sort settings * @param string $Mode sort method to apply to the selected attribute * @return current SphinxQL query object */ - public function order_by($Attribute, $Mode) { - $this->SortBy[] = "$Attribute $Mode"; + public function order_by($Attribute = false, $Mode) { + if (empty($Attribute)) { + $this->SortBy = array(); + } else { + $this->SortBy[] = "$Attribute $Mode"; + } return $this; } /** * Specify how the results are grouped * - * @param string $Attribute group matches with the same $Attribute value + * @param string $Attribute group matches with the same $Attribute value. + * Passing an empty attribute value will clear the current group settings * @return current SphinxQL query object */ - public function group_by($Attribute) { - $this->GroupBy = "$Attribute"; + public function group_by($Attribute = false) { + if (empty($Attribute)) { + $this->GroupBy = ''; + } else { + $this->GroupBy = $Attribute; + } return $this; } /** * Specify the order of the results within groups * - * @param string $Attribute attribute to use for sorting + * @param string $Attribute attribute to use for sorting. + * Passing an empty attribute will clear the current group sort settings * @param string $Mode sort method to apply to the selected attribute * @return current SphinxQL query object */ - public function order_group_by($Attribute, $Mode) { - $this->SortGroupBy = "$Attribute $Mode"; + public function order_group_by($Attribute = false, $Mode) { + if (empty($Attribute)) { + $this->SortGroupBy = ''; + } else { + $this->SortGroupBy = "$Attribute $Mode"; + } return $this; } @@ -302,7 +320,7 @@ public function order_group_by($Attribute, $Mode) { * @param int $MaxMatches number of results to store in the Sphinx server's memory. Must be >= ($Offset+$Limit) * @return current SphinxQL query object */ - public function limit($Offset, $Limit, $MaxMatches = SPHINX_MATCHES_START) { + public function limit($Offset, $Limit, $MaxMatches = SPHINX_MAX_MATCHES) { $this->Limits = "$Offset, $Limit"; $this->set('max_matches', $MaxMatches); return $this; @@ -340,7 +358,7 @@ private function build_query() { if(!$this->Indexes) { $this->error('Index name is required.'); } - $this->QueryString = "SELECT $this->Select FROM $this->Indexes"; + $this->QueryString = "SELECT $this->Select\nFROM $this->Indexes"; if(!empty($this->Expressions)) { $this->Filters['expr'] = "MATCH('".implode(" ", $this->Expressions)."')"; } @@ -524,7 +542,7 @@ public function to_array($Key, $ResultType = MYSQLI_ASSOC) { */ public function to_pair($Key1, $Key2) { $Return = array(); - while($Row = $this->fetch_row()) { + while($Row = $this->fetch_array()) { $Return[$Row[$Key1]] = $Row[$Key2]; } $this->data_seek(0); diff --git a/classes/class_torrents.php b/classes/class_torrents.php index 9c73c718..1c07b364 100644 --- a/classes/class_torrents.php +++ b/classes/class_torrents.php @@ -42,8 +42,7 @@ public static function get_groups($GroupIDs, $Return = true, $GetArtists = true, return array('matches'=>array(),'notfound'=>array()); } - $Found = array_flip($GroupIDs); - $NotFound = array_flip($GroupIDs); + $Found = $NotFound = array_flip($GroupIDs); $Key = $Torrents ? 'torrent_group_' : 'torrent_group_light_'; foreach ($GroupIDs as $GroupID) { @@ -247,6 +246,10 @@ public static function delete_torrent($ID, $GroupID=0, $OcelotReason=-1) { $DB->query("DELETE FROM torrents_cassette_approved WHERE TorrentID = ".$ID); $DB->query("DELETE FROM torrents_lossymaster_approved WHERE TorrentID = ".$ID); $DB->query("DELETE FROM torrents_lossyweb_approved WHERE TorrentID = ".$ID); + + // Tells Sphinx that the group is removed + $DB->query("REPLACE INTO sphinx_delta (ID,Time) VALUES ($ID, UNIX_TIMESTAMP())"); + $Cache->delete_value('torrent_download_'.$ID); $Cache->delete_value('torrent_group_'.$GroupID); $Cache->delete_value('torrents_details_'.$GroupID); @@ -332,9 +335,6 @@ public static function delete_group($GroupID) { $DB->query("DELETE FROM bookmarks_torrents WHERE GroupID='$GroupID'"); $DB->query("DELETE FROM wiki_torrents WHERE PageID='$GroupID'"); - // Tells Sphinx that the group is removed - $DB->query("REPLACE INTO sphinx_delta (ID,Time) VALUES ('$GroupID',UNIX_TIMESTAMP())"); - $Cache->delete_value('torrents_details_'.$GroupID); $Cache->delete_value('torrent_group_'.$GroupID); $Cache->delete_value('groups_artists_'.$GroupID); @@ -356,53 +356,38 @@ public static function update_hash($GroupID) { WHERE ID='$GroupID'"); $DB->query("REPLACE INTO sphinx_delta - (ID, GroupName, TagList, Year, CategoryID, Time, ReleaseType, RecordLabel, - CatalogueNumber, VanityHouse, Size, Snatched, Seeders, Leechers, LogScore, - Scene, HasLog, HasCue, FreeTorrent, Media, Format, Encoding, RemasterYear, - RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, FileList) + (ID, GroupID, GroupName, TagList, Year, CategoryID, Time, ReleaseType, RecordLabel, + CatalogueNumber, VanityHouse, Size, Snatched, Seeders, Leechers, LogScore, + Scene, HasLog, HasCue, FreeTorrent, Media, Format, Encoding, RemasterYear, + RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, FileList) SELECT - g.ID AS ID, - g.Name AS GroupName, - g.TagList, - g.Year, - g.CategoryID, - UNIX_TIMESTAMP(g.Time) AS Time, - g.ReleaseType, - g.RecordLabel, - g.CatalogueNumber, - g.VanityHouse, - MAX(CEIL(t.Size/1024)) AS Size, - SUM(t.Snatched) AS Snatched, - SUM(t.Seeders) AS Seeders, - SUM(t.Leechers) AS Leechers, - MAX(t.LogScore) AS LogScore, - MAX(t.Scene) AS Scene, - MAX(t.HasLog) AS HasLog, - MAX(t.HasCue) AS HasCue, - BIT_OR(t.FreeTorrent-1) AS FreeTorrent, - GROUP_CONCAT(DISTINCT t.Media SEPARATOR ' ') AS Media, - GROUP_CONCAT(DISTINCT t.Format SEPARATOR ' ') AS Format, - GROUP_CONCAT(DISTINCT t.Encoding SEPARATOR ' ') AS Encoding, - GROUP_CONCAT(DISTINCT t.RemasterYear SEPARATOR ' ') AS RemasterYear, - GROUP_CONCAT(DISTINCT t.RemasterTitle SEPARATOR ' ') AS RemasterTitle, - GROUP_CONCAT(DISTINCT t.RemasterRecordLabel SEPARATOR ' ') AS RemasterRecordLabel, - GROUP_CONCAT(DISTINCT t.RemasterCatalogueNumber SEPARATOR ' ') AS RemasterCatalogueNumber, - GROUP_CONCAT(REPLACE(REPLACE(FileList, '|||', '\n '), '_', ' ') SEPARATOR '\n ') AS FileList + t.ID, g.ID, Name, TagList, Year, CategoryID, UNIX_TIMESTAMP(t.Time), ReleaseType, + RecordLabel, CatalogueNumber, VanityHouse, Size >> 10 AS Size, Snatched, Seeders, + Leechers, LogScore, CAST(Scene AS CHAR), CAST(HasLog AS CHAR), CAST(HasCue AS CHAR), + CAST(FreeTorrent AS CHAR), Media, Format, Encoding, + RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, + REPLACE(REPLACE(REPLACE(REPLACE(FileList, + '.flac', ' .flac'), + '.mp3', ' .mp3'), + '|||', '\n '), + '_', ' ') + AS FileList FROM torrents AS t JOIN torrents_group AS g ON g.ID=t.GroupID - WHERE g.ID=$GroupID - GROUP BY g.ID"); + WHERE g.ID=$GroupID"); $DB->query("INSERT INTO sphinx_delta (ID, ArtistName) - SELECT - GroupID, - GROUP_CONCAT(aa.Name separator ' ') - FROM torrents_artists AS ta - JOIN artists_alias AS aa ON aa.AliasID=ta.AliasID - JOIN torrents_group AS tg ON tg.ID=ta.GroupID - WHERE ta.GroupID=$GroupID AND ta.Importance IN ('1', '4', '5', '6') - GROUP BY tg.ID + SELECT torrents.ID, artists.ArtistName FROM ( + SELECT + GroupID, + GROUP_CONCAT(aa.Name separator ' ') AS ArtistName + FROM torrents_artists AS ta + JOIN artists_alias AS aa ON aa.AliasID=ta.AliasID + WHERE ta.GroupID=$GroupID AND ta.Importance IN ('1', '4', '5', '6') + GROUP BY ta.GroupID + ) AS artists + JOIN torrents USING(GroupID) ON DUPLICATE KEY UPDATE ArtistName=values(ArtistName)"); $Cache->delete_value('torrents_details_'.$GroupID); diff --git a/classes/class_users.php b/classes/class_users.php index 8ccc6252..16acaf1f 100644 --- a/classes/class_users.php +++ b/classes/class_users.php @@ -487,4 +487,83 @@ function bookmark_data ($UserID) return array($K, $GroupIDs, $CollageDataList, $TorrentList); } + + /** + * Generate HTML for a user's avatar or just return the avatar url + * @param unknown $Avatar + * @param unknown $Username + * @param unknown $Setting + * @param number $Size + * @param string $ReturnHTML + * @return string + */ + public static function show_avatar($Avatar, $Username, $Setting, $Size=150, $ReturnHTML = True) { + global $LoggedUser; + //case 1 is avatars disabled + switch($Setting) { + case 0: + if(!empty($Avatar)) { + $ToReturn = $ReturnHTML ? "$Username avatar" : $Avatar; + } + else { + $URL = STATIC_SERVER."common/avatars/default.png"; + $ToReturn = $ReturnHTML ? "Default Avatar" : $URL; + } + break; + case 2: + $ShowAvatar = True; + case 3: + switch($LoggedUser['Identicons']) { + case 0: + $Type = "identicon"; + break; + case 1: + $Type = "monsterid"; + break; + case 2: + $Type = "wavatar"; + break; + case 3: + $Type = "retro"; + break; + case 4: + $Type = "1"; + $Robot = True; + break; + case 5: + $Type = "2"; + $Robot = True; + break; + case 6: + $Type = "3"; + $Robot = True; + break; + default: + $Type = "identicon"; + } + $Rating = "pg"; + if(!$Robot) { + $URL = "https://www.gravatar.com/avatar/".md5(strtolower(trim($Username)))."?s=$Size&d=$Type&r=$Rating"; + } + else { + $URL = "https://static1.robohash.org/".md5($Username)."?set=set".$Type."&size=".$Size."x".$Size; + } + if($ShowAvatar == True && !empty($Avatar)) { + $ToReturn = $ReturnHTML ? "$Username avatar" : $Avatar; + } + else { + $ToReturn = $ReturnHTML ? "Default Avatar" : $URL; + } + break; + default: + $URL = STATIC_SERVER."common/avatars/default.png"; + $ToReturn = $ReturnHTML ? "Default Avatar" : $URL; + } + return $ToReturn; + } + + public static function has_avatars_enabled() { + global $HeavyInfo; + return $HeavyInfo['DisableAvatars'] != 1; + } } diff --git a/design/privateheader.php b/design/privateheader.php index c3ac2586..c6dfdf1f 100644 --- a/design/privateheader.php +++ b/design/privateheader.php @@ -415,12 +415,6 @@
- - +
- + - - +- + - - + -
+
# - [Quote] @@ -1006,13 +1006,9 @@ function require(file, callback) {
- - <?=$Username ?>'s avatar - - Default avatar - + @@ -1042,7 +1038,7 @@ function require(file, callback) {
- +@@ -1060,15 +1056,11 @@ function require(file, callback) { - + - + diff --git a/sections/collages/all_comments.php b/sections/collages/all_comments.php index 865e9d93..9a10cd21 100644 --- a/sections/collages/all_comments.php +++ b/sections/collages/all_comments.php @@ -72,15 +72,15 @@ list($PostID, $AuthorID, $AddedTime, $Body) = $Post; list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID)); ?> - +
- + - - + - +
+ # by [Report Comment] - [Quote]
- - <?=$Username ?>'s avatar - - Default avatar - +
full_format($Body)?> diff --git a/sections/collages/collage.php b/sections/collages/collage.php index 7560301b..df3737c2 100644 --- a/sections/collages/collage.php +++ b/sections/collages/collage.php @@ -22,7 +22,7 @@ function compare($X, $Y){ if (!is_array($Data)) { $Data = unserialize($Data); } - list($K, list($Name, $Description, ,,,, $CommentList, $Deleted, $CollageCategoryID, $CreatorID)) = each($Data); + list($K, list($Name, $Description, , , $CommentList, $Deleted, $CollageCategoryID, $CreatorID, $Locked, $MaxGroups, $MaxGroupsPerUser)) = each($Data); } else { $DB->query("SELECT Name, Description, UserID, Deleted, CategoryID, Locked, MaxGroups, MaxGroupsPerUser FROM collages WHERE ID='$CollageID'"); if($DB->record_count() > 0) { diff --git a/sections/forums/main.php b/sections/forums/main.php index 185aab2e..a3fdabbc 100644 --- a/sections/forums/main.php +++ b/sections/forums/main.php @@ -31,6 +31,7 @@ ?>

Forums

+
+
query("INSERT INTO users_notify_quoted (UserID, QuoterID, ForumID, TopicID, PostID, Date) + $DB->query("INSERT IGNORE INTO users_notify_quoted (UserID, QuoterID, ForumID, TopicID, PostID, Date) VALUES ('$UserID', '$QuoterID', '$ForumID', '$TopicID', '$PostID', '" . sqltime() . "')"); $Cache->delete_value('forums_quotes_' . $UserID); } diff --git a/sections/forums/thread.php b/sections/forums/thread.php index 3db5a965..5599d71d 100644 --- a/sections/forums/thread.php +++ b/sections/forums/thread.php @@ -399,20 +399,20 @@ if (((!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) && $PostID>$LastRead && strtotime($AddedTime)>$LoggedUser['CatchupTime']) || (isset($RequestKey) && $Key==$RequestKey)) { echo ' forum_unread'; } - if ($HeavyInfo['DisableAvatars']) { + if (!Users::has_avatars_enabled()) { echo ' noavatar'; } if ($ThreadInfo['OP'] == $AuthorID) { echo ' important_user'; } ?>" id="post">
+
# @@ -459,16 +459,12 @@
- - <?=$Username ?>'s avatar - - Default avatar - + > + >
full_format($Body) ?> @@ -504,13 +500,13 @@
- + - - - - + + + diff --git a/sections/requests/request.php b/sections/requests/request.php index 14c51dd9..1ca6f690 100644 --- a/sections/requests/request.php +++ b/sections/requests/request.php @@ -519,15 +519,15 @@ list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post); list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID)); ?> - +
- + - - +
+
# by - [Quote] @@ -546,13 +546,9 @@
- - <?=$Username ?>'s avatar - - Default avatar - + @@ -582,13 +578,13 @@
- + - - + - + diff --git a/sections/schedule/index.php b/sections/schedule/index.php index c0fef73b..921829ea 100644 --- a/sections/schedule/index.php +++ b/sections/schedule/index.php @@ -932,6 +932,11 @@ function next_hour() { Misc::send_pm($UserID, 0, db_string('Unseeded torrent notification'), db_string($MessageInfo['Count']." of your uploads will be deleted for inactivity soon. Unseeded torrents are deleted after 4 weeks. If you still have the files, you can seed your uploads by ensuring the torrents are in your client and that they aren't stopped. You can view the time that a torrent has been unseeded by clicking on the torrent description line and looking for the \"Last active\" time. For more information, please go [url=https://what.cd/wiki.php?action=article&id=663]here[/url].\n\nThe following torrent".($MessageInfo['Count']>1?'s':'')." will be removed for inactivity:".$MessageInfo['Msg']."\n\nIf you no longer wish to receive these notifications, please disable them in your profile settings.")); } } + + $DB->query("UPDATE staff_pm_conversations + SET Status = 'Resolved', ResolverID = '0' + WHERE Date < NOW() - INTERVAL 1 MONTH AND Status = 'Open' AND AssignedToUser IS NULL"); + } /*************************************************************************\ //--------------Run twice per month -------------------------------------// diff --git a/sections/torrents/browse2.php b/sections/torrents/browse2.php index 3227210f..bb607c14 100644 --- a/sections/torrents/browse2.php +++ b/sections/torrents/browse2.php @@ -2,12 +2,12 @@ /************************************************************************ *-------------------- Browse page --------------------------------------- * Welcome to one of the most complicated pages in all of gazelle - the -* browse page. -* +* browse page. +* * This is the page that is displayed when someone visits torrents.php -* +* * It offers normal and advanced search, as well as enabled/disabled -* grouping. +* grouping. * * For an outdated non-Sphinx version, use /sections/torrents/browse.php. * @@ -27,26 +27,26 @@ // The "order by x" links on columns headers function header_link($SortKey,$DefaultWay="desc") { global $OrderBy,$OrderWay; - if($SortKey==$OrderBy) { - if($OrderWay=="desc") { $NewWay="asc"; } + if ($SortKey==$OrderBy) { + if ($OrderWay=="desc") { $NewWay="asc"; } else { $NewWay="desc"; } } else { $NewWay=$DefaultWay; } - return "torrents.php?order_way=".$NewWay."&order_by=".$SortKey."&".Format::get_url(array('order_way','order_by')); } -// Search by infohash -if(!empty($_GET['searchstr']) || !empty($_GET['groupname'])) { - if(!empty($_GET['searchstr'])) { +/** Start default parameters and validation **/ +if (!empty($_GET['searchstr']) || !empty($_GET['groupname'])) { + if (!empty($_GET['searchstr'])) { $InfoHash = $_GET['searchstr']; } else { $InfoHash = $_GET['groupname']; } - - if($InfoHash = is_valid_torrenthash($InfoHash)) { + + // Search by infohash + if ($InfoHash = is_valid_torrenthash($InfoHash)) { $InfoHash = db_string(pack("H*", $InfoHash)); $DB->query("SELECT ID,GroupID FROM torrents WHERE info_hash='$InfoHash'"); - if($DB->record_count() > 0) { + if ($DB->record_count() > 0) { list($ID, $GroupID) = $DB->next_record(); header('Location: torrents.php?id='.$GroupID.'&torrentid='.$ID); die(); @@ -55,13 +55,13 @@ function header_link($SortKey,$DefaultWay="desc") { } // Setting default search options -if(!empty($_GET['setdefault'])) { +if (!empty($_GET['setdefault'])) { $UnsetList = array('page','setdefault'); $UnsetRegexp = '/(&|^)('.implode('|',$UnsetList).')=.*?(&|$)/i'; $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'"); list($SiteOptions)=$DB->next_record(MYSQLI_NUM, false); - if(!empty($SiteOptions)) { + if (!empty($SiteOptions)) { $SiteOptions = unserialize($SiteOptions); } else { $SiteOptions = array(); @@ -73,7 +73,7 @@ function header_link($SortKey,$DefaultWay="desc") { $Cache->commit_transaction(0); // Clearing default search options -} elseif(!empty($_GET['cleardefault'])) { +} elseif (!empty($_GET['cleardefault'])) { $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'"); list($SiteOptions)=$DB->next_record(MYSQLI_NUM, false); $SiteOptions=unserialize($SiteOptions); @@ -84,65 +84,147 @@ function header_link($SortKey,$DefaultWay="desc") { $Cache->commit_transaction(0); // Use default search options -} elseif((empty($_SERVER['QUERY_STRING']) || (count($_GET) == 1 && isset($_GET['page']))) && !empty($LoggedUser['DefaultSearch'])) { - if(!empty($_GET['page'])) { - $Page = $_GET['page']; - parse_str($LoggedUser['DefaultSearch'],$_GET); - $_GET['page'] = $Page; - } else { - parse_str($LoggedUser['DefaultSearch'],$_GET); +} elseif (empty($_SERVER['QUERY_STRING']) || (count($_GET) == 1 && isset($_GET['page']))) { + if (!empty($LoggedUser['DefaultSearch'])) { + if (!empty($_GET['page'])) { + $Page = $_GET['page']; + parse_str($LoggedUser['DefaultSearch'],$_GET); + $_GET['page'] = $Page; + } else { + parse_str($LoggedUser['DefaultSearch'],$_GET); + } } } +// Terms were not submitted via the search form +if (!isset($_GET['searchsubmit'])) { + $_GET['group_results'] = !$LoggedUser['DisableGrouping2']; +} +if (isset($_GET['group_results']) && $_GET['group_results']) { + $_GET['group_results'] = 1; + $GroupResults = true; + $SortOrders = array( + // 'url attr' => [global order, order within group] + 'year' => array('year', 'year'), + 'time' => array('id', 'id'), + 'size' => array('maxsize', 'size'), + 'seeders' => array('sumseeders', 'seeders'), + 'leechers' => array('sumleechers', 'leechers'), + 'snatched' => array('sumsnatched', 'snatched'), + 'random' => false); + $AggregateExp = array( + 'maxsize' => 'MAX(size) AS maxsize', + 'sumseeders' => 'SUM(seeders) AS sumseeders', + 'sumleechers' => 'SUM(leechers) AS sumleechers', + 'sumsnatched' => 'SUM(snatched) AS sumsnatched'); +} else { + $SortOrders = array( + 'year' => 'year', + 'time' => 'id', + 'size' => 'size', + 'seeders' => 'seeders', + 'leechers' => 'leechers', + 'snatched' => 'snatched', + 'random' => false); +} + +if (empty($_GET['order_by']) || !isset($SortOrders[$_GET['order_by']])) { + $_GET['order_by'] = 'time'; + $OrderBy = 'time'; // For header links +} else { + $OrderBy = $_GET['order_by']; +} + +if(!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') { + $OrderWay = 'asc'; +} else { + $_GET['order_way'] = 'desc'; + $OrderWay = 'desc'; +} + +/** End default parameters and validation **/ + +/** Start preparation of property arrays **/ array_pop($Bitrates); // remove 'other' $SearchBitrates = array_merge($Bitrates, array('v0','v1','v2','24bit')); -foreach($SearchBitrates as $ID=>$Val) { - $SearchBitrates[$ID]=strtolower($Val); +foreach ($SearchBitrates as $ID=>$Val) { + $SearchBitrates[$ID] = strtolower($Val); } -foreach($Formats as $ID=>$Val) { - $SearchFormats[$ID]=strtolower($Val); +foreach ($Formats as $ID => $Val) { + $SearchFormats[$ID] = strtolower($Val); } +/** End preparation of property arrays **/ -$Queries = array(); +/** Start query preparation **/ +$SphQLHost = '192.168.5.6'; +$SphQLPort = '9307'; +$SphQL = new SphinxQL_Query($SphQLHost, $SphQLPort); +$SphQLTor = new SphinxQL_Query($SphQLHost, $SphQLPort); +if ($OrderBy == 'random') { + $SphQL->select('id, groupid, categoryid') + ->order_by('RAND()', ''); + $Random = true; +} else if ($GroupResults) { + $OrderProperties = $SortOrders[$OrderBy]; + $SphQL->select('groupid, categoryid' . (isset($AggregateExp[$OrderProperties[0]]) ? ', '.$AggregateExp[$OrderProperties[0]] : '')) + ->group_by('groupid') + ->order_by($OrderProperties[0], $OrderWay) + ->order_group_by($OrderProperties[1], $OrderWay); + +} else { + $SphQL->select('id, groupid, categoryid') + ->order_by($SortOrders[$OrderBy], $OrderWay); +} +$SphQL->from('torrents, delta'); +$SphQLTor->select('id, groupid')->from('torrents, delta'); +/** End query preparation **/ + +/** Start building search query **/ +$Filtered = false; $EnableNegation = false; // Sphinx needs at least one positive search condition to support the NOT operator // Filelist searches makes use of the proximity operator to ensure that all keywords match the same file -if(!empty($_GET['filelist'])) { +if (!empty($_GET['filelist'])) { $SearchString = trim($_GET['filelist']); - if($SearchString != '') { - $Queries[] = '@filelist "'.$SS->escape_string($_GET['filelist']).'"~20'; + if ($SearchString != '') { + $SearchString = '"'.SphinxQL::escape_string($_GET['filelist']).'"~20'; + $SphQL->where_match($SearchString, 'filelist', false); + $SphQLTor->where_match($SearchString, 'filelist', false); $EnableNegation = true; + $Filtered = true; } } // Collect all entered search terms to find out whether to enable the NOT operator +$GroupFields = array('artistname','groupname', 'recordlabel', 'cataloguenumber', 'taglist'); +$TorrentFields = array('remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', 'encoding', 'format', 'media'); $SearchWords = array(); -foreach(array('artistname','groupname', 'recordlabel', 'cataloguenumber', - 'remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', - 'encoding', 'format', 'media', 'taglist') as $Search) { - if(!empty($_GET[$Search])) { +foreach (array('artistname', 'groupname', 'recordlabel', 'cataloguenumber', + 'taglist', 'remastertitle', 'remasteryear', 'remasterrecordlabel', + 'remastercataloguenumber', 'encoding', 'format', 'media') as $Search) { + if (!empty($_GET[$Search])) { $SearchString = trim($_GET[$Search]); - if($SearchString != '') { + if ($SearchString != '') { $SearchWords[$Search] = array('include' => array(), 'exclude' => array()); - if($Search == 'taglist') { + if ($Search == 'taglist') { $SearchString = strtr($SearchString, '.', '_'); $Words = explode(',', $SearchString); } else { $Words = explode(' ', $SearchString); } - foreach($Words as $Word) { + foreach ($Words as $Word) { $Word = trim($Word); - if($Word[0] == '!' && strlen($Word) >= 2) { - if(strpos($Word,'!',1) === false) { + if ($Word[0] == '!' && strlen($Word) >= 2) { + if (strpos($Word,'!',1) === false) { $SearchWords[$Search]['exclude'][] = $Word; } else { $SearchWords[$Search]['include'][] = $Word; $EnableNegation = true; } - } elseif($Word != '') { + } elseif ($Word != '') { $SearchWords[$Search]['include'][] = $Word; $EnableNegation = true; } @@ -152,268 +234,310 @@ function header_link($SortKey,$DefaultWay="desc") { } //Simple search -if(!empty($_GET['searchstr'])) { +if (!empty($_GET['searchstr'])) { $SearchString = trim($_GET['searchstr']); $Words = explode(' ',strtolower($SearchString)); - if(!empty($Words)) { + if (!empty($Words)) { $FilterBitrates = $FilterFormats = array(); $BasicSearch = array('include' => array(), 'exclude' => array()); - foreach($Words as $Word) { + foreach ($Words as $Word) { $Word = trim($Word); - if($Word[0] == '!' && strlen($Word) >= 2) { - if($Word == '!100%') { + if ($Word[0] == '!' && strlen($Word) >= 2) { + if ($Word == '!100%') { $_GET['haslog'] = '-1'; - } elseif(strpos($Word,'!',1) === false) { + } elseif (strpos($Word,'!',1) === false) { $BasicSearch['exclude'][] = $Word; } else { $BasicSearch['include'][] = $Word; $EnableNegation = true; } - } elseif(in_array($Word, $SearchBitrates)) { + } elseif (in_array($Word, $SearchBitrates)) { $FilterBitrates[] = $Word; $EnableNegation = true; - } elseif(in_array($Word, $SearchFormats)) { + } elseif (in_array($Word, $SearchFormats)) { $FilterFormats[] = $Word; $EnableNegation = true; - } elseif($Word == '100%') { + } elseif ($Word == '100%') { $_GET['haslog'] = '100'; - } elseif($Word != '') { + } elseif ($Word != '') { $BasicSearch['include'][] = $Word; $EnableNegation = true; } } - if(!$EnableNegation && !empty($BasicSearch['exclude'])) { + if (!$EnableNegation && !empty($BasicSearch['exclude'])) { $BasicSearch['include'] = array_merge($BasicSearch['include'], $BasicSearch['exclude']); unset($BasicSearch['exclude']); } $QueryParts = array(); - foreach($BasicSearch['include'] as $Word) { - $QueryParts[] = $SS->escape_string($Word); + foreach ($BasicSearch['include'] as $Word) { + $QueryParts[] = SphinxQL::escape_string($Word); } - if(!empty($BasicSearch['exclude'])) { - foreach($BasicSearch['exclude'] as $Word) { - $QueryParts[] = '!'.$SS->escape_string(substr($Word,1)); + if (!empty($BasicSearch['exclude'])) { + foreach ($BasicSearch['exclude'] as $Word) { + $QueryParts[] = '!'.SphinxQL::escape_string(substr($Word,1)); } } - if(!empty($FilterBitrates)) { - $Queries[] = "@encoding ".implode(' ', $FilterBitrates); + if (!empty($FilterBitrates)) { + $SearchString = implode(' ', $FilterBitrates); + $SphQL->where_match($SearchString, 'encoding', false); + $SphQLTor->where_match($SearchString, 'encoding', false); + $Filtered = true; } - if(!empty($FilterFormats)) { - $Queries[] = "@format ".implode(' ', $FilterFormats); + if (!empty($FilterFormats)) { + $SearchString = implode(' ', $FilterFormats); + $SphQL->where_match($SearchString, 'format', false); + $SphQLTor->where_match($SearchString, 'format', false); + $Filtered = true; } - if(!empty($QueryParts)) { - $Queries[] = "@(groupname,artistname,yearfulltext) ".implode(' ', $QueryParts); + if (!empty($QueryParts)) { + $SearchString = implode(' ', $QueryParts); + $SphQL->where_match($SearchString, '(groupname,artistname,yearfulltext)', false); + $SphQLTor->where_match($SearchString, '(groupname,artistname,yearfulltext)', false); + $Filtered = true; } } } // Tag list -if(!empty($SearchWords['taglist'])) { +if (!empty($SearchWords['taglist'])) { $Tags = $SearchWords['taglist']; - if(!$EnableNegation && !empty($Tags['exclude'])) { + if (!$EnableNegation && !empty($Tags['exclude'])) { $Tags['include'] = array_merge($Tags['include'], $Tags['exclude']); unset($Tags['exclude']); } - foreach($Tags['include'] as &$Tag) { - $Tag = $SS->escape_string($Tag); + foreach ($Tags['include'] as &$Tag) { + $Tag = SphinxQL::escape_string($Tag); } - if(!empty($Tags['exclude'])) { - foreach($Tags['exclude'] as &$Tag) { - $Tag = '!'.$SS->escape_string(substr($Tag,1)); + if (!empty($Tags['exclude'])) { + foreach ($Tags['exclude'] as &$Tag) { + $Tag = '!'.SphinxQL::escape_string(substr($Tag,1)); } } $QueryParts = array(); // 'All' tags - if(!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { + if (!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { $_GET['tags_type'] = '1'; $Tags = array_merge($Tags['include'], $Tags['exclude']); - if(!empty($Tags)) { + if (!empty($Tags)) { $QueryParts[] = implode(' ', $Tags); } } // 'Any' tags else { $_GET['tags_type'] = '0'; - if(!empty($Tags['include'])) { + if (!empty($Tags['include'])) { $QueryParts[] = '( '.implode(' | ', $Tags['include']).' )'; } - if(!empty($Tags['exclude'])) { + if (!empty($Tags['exclude'])) { $QueryParts[] = implode(' ', $Tags['exclude']); } } - if(!empty($QueryParts)) { - $Queries[] = "@taglist ".implode(' ', $QueryParts); + if (!empty($QueryParts)) { + $SphQL->where_match(implode(' ', $QueryParts), 'taglist', false); + $Filtered = true; } unset($SearchWords['taglist']); } -elseif(!isset($_GET['tags_type'])) { +elseif (!isset($_GET['tags_type'])) { $_GET['tags_type'] = '1'; } -foreach($SearchWords as $Search => $Words) { +foreach ($SearchWords as $Search => $Words) { $QueryParts = array(); - if(!$EnableNegation && !empty($Words['exclude'])) { + if (!$EnableNegation && !empty($Words['exclude'])) { $Words['include'] = array_merge($Words['include'], $Words['exclude']); unset($Words['exclude']); } - foreach($Words['include'] as $Word) { - $QueryParts[] = $SS->escape_string($Word); + foreach ($Words['include'] as $Word) { + $QueryParts[] = SphinxQL::escape_string($Word); } - if(!empty($Words['exclude'])) { - foreach($Words['exclude'] as $Word) { - $QueryParts[] = '!'.$SS->escape_string(substr($Word,1)); + if (!empty($Words['exclude'])) { + foreach ($Words['exclude'] as $Word) { + $QueryParts[] = '!'.SphinxQL::escape_string(substr($Word,1)); } } - if(!empty($QueryParts)) { - $Queries[] = "@$Search ".implode(' ', $QueryParts); + if (!empty($QueryParts)) { + $SearchString = implode(' ', $QueryParts); + $SphQL->where_match($SearchString, $Search, false); + $SphQLTor->where_match($SearchString, $Search, false); + $Filtered = true; } } -if(!empty($_GET['year'])) { +if (!empty($_GET['year'])) { $Years = explode('-', $_GET['year']); - if(is_number($Years[0]) || (empty($Years[0]) && !empty($Years[1]) && is_number($Years[1]))) { - if(count($Years) == 1) { - $SS->set_filter('year', array((int)$Years[0])); + if (is_number($Years[0]) || (empty($Years[0]) && !empty($Years[1]) && is_number($Years[1]))) { + if (count($Years) == 1) { + $SphQL->where('year', (int)$Years[0]); + $SphQLTor->where('year', (int)$Years[0]); } else { - if(empty($Years[1]) || !is_number($Years[1])) { + if (empty($Years[1]) || !is_number($Years[1])) { $Years[1] = PHP_INT_MAX; - } elseif($Years[0] > $Years[1]) { + } elseif ($Years[0] > $Years[1]) { $Years = array_reverse($Years); } - $SS->set_filter_range('year', (int)$Years[0], (int)$Years[1]); + $SphQL->where_between('year', array((int)$Years[0], (int)$Years[1])); + $SphQLTor->where_between('year', array((int)$Years[0], (int)$Years[1])); } + $Filtered = true; } } -if(isset($_GET['haslog']) && $_GET['haslog']!=='') { - if($_GET['haslog'] == 100) { - $SS->set_filter('logscore', array(100)); +if (isset($_GET['haslog']) && $_GET['haslog']!=='') { + if ($_GET['haslog'] == 100) { + $SphQL->where('logscore', 100); + $SphQLTor->where('logscore', 100); + $Filtered = true; } elseif ($_GET['haslog'] < 0) { - // Exclude torrents with log score equal to 100 - $SS->set_filter('logscore', array(100), true); - $SS->set_filter('haslog', array(1)); + // Exclude torrents with log score equal to 100 + $SphQL->where('logscore', 100, true); + $SphQL->where('haslog', 1); + $SphQLTor->where('logscore', 100, true); + $SphQLTor->where('haslog', 1); + $Filtered = true; + } elseif ($_GET['haslog'] == 0) { + $SphQL->where('haslog', 0); + $SphQLTor->where('haslog', 0); } else { - $SS->set_filter('haslog', array(1)); - } + $SphQL->where('haslog', 1); + $SphQLTor->where('haslog', 1); + $Filtered = true; + } } - -foreach(array('hascue','scene','vanityhouse','freetorrent','releasetype') as $Search) { - if(isset($_GET[$Search]) && $_GET[$Search]!=='') { - if($Search == 'freetorrent') { - switch($_GET[$Search]) { - case 0: $SS->set_filter($Search, array(0)); break; - case 1: $SS->set_filter($Search, array(1)); break; - case 2: $SS->set_filter($Search, array(2)); break; - case 3: $SS->set_filter($Search, array(0), true); break; - } - } else { - $SS->set_filter($Search, array($_GET[$Search])); +foreach (array('hascue','scene','vanityhouse','releasetype') as $Search) { + if (isset($_GET[$Search]) && $_GET[$Search] !== '') { + $SphQL->where($Search, $_GET[$Search]); + // Release type is group specific + if ($Search != 'releasetype') { + $SphQLTor->where($Search, $_GET[$Search]); + } + if ($_GET[$Search] !== 0) { + // Hack! Deleted torrents may show up if we set to true unconditionally. Hope no one notices + $Filtered = true; } } } - -if(!empty($_GET['filter_cat'])) { - $SS->set_filter('categoryid', array_keys($_GET['filter_cat'])); +if (!empty($_GET['freetorrent'])) { + switch ($_GET['freetorrent']) { + case 0: // Only normal freeleech + $SphQL->where('freetorrent', 0); + $SphQLTor->where('freetorrent', 0); + $Filtered = true; + break; + case 1: // Only free leech + $SphQL->where('freetorrent', 1); + $SphQLTor->where('freetorrent', 1); + $Filtered = true; + break; + case 2: // Only neutral leech + $SphQL->where('freetorrent', 2); + $SphQLTor->where('freetorrent', 2); + $Filtered = true; + break; + case 3: // Free or neutral leech + $SphQL->where('freetorrent', 0, true); + $SphQLTor->where('freetorrent', 0, true); + $Filtered = true; + break; + } } -if(!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { - if(check_perms('site_search_many')) { - $Page = $_GET['page']; - } else { - $Page = min(SPHINX_MAX_MATCHES/TORRENTS_PER_PAGE, $_GET['page']); - } - $SS->limit(($Page-1)*TORRENTS_PER_PAGE, TORRENTS_PER_PAGE); -} else { +if (!empty($_GET['filter_cat'])) { + $SphQL->where('categoryid', array_keys($_GET['filter_cat'])); + $Filtered = true; +} + +if (!$Filtered) { + $SphQL->where('size', 0, true); +} +/** End building search query **/ + +/** Run search query and collect results **/ +if (isset($Random) && $GroupResults) { + // ORDER BY RAND() can't be used together with GROUP BY, so we need some special tactics $Page = 1; - $SS->limit(0, TORRENTS_PER_PAGE); -} - -if(!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') { - $Way = SPH_SORT_ATTR_ASC; - $OrderWay = 'asc'; // For header links -} else { - $Way = SPH_SORT_ATTR_DESC; - $_GET['order_way'] = 'desc'; - $OrderWay = 'desc'; -} - -if(empty($_GET['order_by']) || !in_array($_GET['order_by'], array('year','time','size','seeders','leechers','snatched','random'))) { - $_GET['order_by'] = 'time'; - $OrderBy = 'time'; // For header links -} elseif($_GET['order_by'] == 'random') { - $OrderBy = '@random'; - $Way = SPH_SORT_EXTENDED; - $SS->limit(0, TORRENTS_PER_PAGE); -} else { - $OrderBy = $_GET['order_by']; -} - -$SS->SetSortMode($Way, $OrderBy); - - -if(count($Queries)>0) { - $Query = implode(' ',$Queries); -} else { - $Query=''; - if(empty($SS->Filters)) { - $SS->set_filter('size', array(0), true); - } -} - -$SS->set_index(SPHINX_INDEX.' delta'); -$Results = $SS->search($Query, '', 0, array(), '', ''); -if(check_perms('site_search_many')) { - $TorrentCount = $SS->TotalResults; -} else { - $TorrentCount = min($SS->TotalResults, SPHINX_MAX_MATCHES); -} -/* -// If some were fetched from memcached, get their artists -if(!empty($Results['matches'])) { // Fetch the artists for groups - $GroupIDs = array_keys($Results['matches']); - $Artists = Artists::get_artists($GroupIDs); - - foreach($Artists as $GroupID=>$Data) { - if(!empty($Data[1])) { - $Results['matches'][$GroupID]['Artists']=$Data[1]; // Only use main artists + $SphQL->limit(0, 5*TORRENTS_PER_PAGE, 5*TORRENTS_PER_PAGE); + $SphQLResult = $SphQL->query(); + $TotalCount = $SphQLResult->get_meta('total_found'); + $Results = $SphQLResult->to_array('groupid'); + $GroupIDs = array_keys($Results); + $Debug->log_var($SphQLResult->get_meta(), 'Result meta info'); + $GroupCount = count($GroupIDs); + while ($SphQLResult->get_meta('total') < $TotalCount && $GroupCount < TORRENTS_PER_PAGE) { + // Make sure we get TORRENTS_PER_PAGE results, or all of them if there are less than TORRENTS_PER_PAGE hits + $SphQL->where('groupid', $GroupIDs, true); + $SphQLResult = $SphQL->query(); + if (!$SphQLResult->get_meta('total')) { + break; } - ksort($Results['matches'][$GroupID]); + $Results += $SphQLResult->to_array('groupid'); + $GroupIDs = array_keys($Results); + $GroupCount = count($GroupIDs); } -} -*/ -// These ones were not found in the cache, run SQL -if(!empty($Results['notfound'])) { - $SQLResults = Torrents::get_groups($Results['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) { - unset($SQLResults['matches'][$ID]); - unset($Results['matches'][$ID]); + if ($GroupCount > TORRENTS_PER_PAGE) { + $Results = array_slice($Results, 0, TORRENTS_PER_PAGE, true); + } + $GroupIDs = array_keys($Results); + $TorrentCount = count($Results); +} else { + if (!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { + if (check_perms('site_search_many')) { + $Page = $_GET['page']; + } else { + $Page = min(SPHINX_MAX_MATCHES/TORRENTS_PER_PAGE, $_GET['page']); } + $Offset = ($Page - 1) * TORRENTS_PER_PAGE; + $SphQL->limit($Offset, TORRENTS_PER_PAGE, $Offset + TORRENTS_PER_PAGE); + } else { + $Page = 1; + $SphQL->limit(0, TORRENTS_PER_PAGE, TORRENTS_PER_PAGE); } - - // Merge SQL results with sphinx/memcached results - foreach($SQLResults['matches'] as $ID=>$SQLResult) { - $Results['matches'][$ID] = array_merge($Results['matches'][$ID], $SQLResult); - ksort($Results['matches'][$ID]); + $SphQLResult = $SphQL->query(); + $TorrentCount = $SphQLResult->get_meta('total_found'); + if ($GroupResults) { + $Results = $SphQLResult->to_array('groupid'); + $GroupIDs = array_keys($Results); + } else { + $Results = $SphQLResult->to_array('id'); + $GroupIDs = $SphQLResult->collect('groupid'); } } -$Results = $Results['matches']; +if (!check_perms('site_search_many') && $TorrentCount > SPHINX_MAX_MATCHES) { + $TorrentCount = SPHINX_MAX_MATCHES; +} + +if ($TorrentCount) { + $Groups = Torrents::get_groups($GroupIDs); + $Groups = $Groups['matches']; + + if (!empty($Groups) && $GroupResults) { + $TorrentIDs = array(); + foreach ($Groups as $Group) { + if (!empty($Group['Torrents'])) { + $TorrentIDs = array_merge($TorrentIDs, array_keys($Group['Torrents'])); + } + } + + // Get a list of all torrent ids that match the search query + $SphQLTor->where('id', $TorrentIDs)->limit(0, count($TorrentIDs), count($TorrentIDs)); + $SphQLResultTor = $SphQLTor->query(); + $TorrentIDs = array_fill_keys($SphQLResultTor->collect('id'), true); + } +} +/** End run search query and collect results **/ $AdvancedSearch = false; $Action = 'action=basic'; -if(((!empty($_GET['action']) && strtolower($_GET['action'])=="advanced") || (!empty($LoggedUser['SearchType']) && ((!empty($_GET['action']) && strtolower($_GET['action'])!="basic") || empty($_GET['action'])))) && check_perms('site_advanced_search')) { +if (((!empty($_GET['action']) && strtolower($_GET['action'])=="advanced") || (!empty($LoggedUser['SearchType']) && ((!empty($_GET['action']) && strtolower($_GET['action'])!="basic") || empty($_GET['action'])))) && check_perms('site_advanced_search')) { $AdvancedSearch = true; $Action = 'action=advanced'; } - View::show_header('Browse Torrents','browse'); @@ -421,17 +545,16 @@ function header_link($SortKey,$DefaultWay="desc") {

- Filter - - (Basic Search) + Filter + + (Basic Search) (Advanced Search) - +

- + - + @@ -567,7 +690,7 @@ function header_link($SortKey,$DefaultWay="desc") { @@ -599,14 +722,18 @@ function header_link($SortKey,$DefaultWay="desc") { + + + +
Artist Name: @@ -465,7 +588,7 @@ function header_link($SortKey,$DefaultWay="desc") { [Click here to toggle searching for specific remaster information]
Search terms: - +
/>
$CatName) { - if($x%7==0) { - if($x > 0) { +foreach ($Categories as $CatKey => $CatName) { + if ($x%7==0) { + if ($x > 0) { ?> @@ -616,7 +743,7 @@ function header_link($SortKey,$DefaultWay="desc") { $x++; ?>
- checked="checked" /> + checked="checked" />
- +
get_value('genre_tags'); -if(!$GenreTags) { +if (!$GenreTags) { $DB->query('SELECT Name FROM tags WHERE TagType=\'genre\' ORDER BY Name'); $GenreTags = $DB->collect('Name'); $Cache->cache_value('genre_tags', $GenreTags, 3600*6); } $x = 0; -foreach($GenreTags as $Tag) { +foreach ($GenreTags as $Tag) { ?> @@ -656,16 +783,17 @@ function header_link($SortKey,$DefaultWay="desc") {
- +
Results - ?action=advanced'" /> + + ?action=advanced'" />    -0 || count($SS->Filters)>0) { ?> + -query("SELECT + +

Your search did not match anything.

Make sure all names are spelled correctly, or try making your search less specific.

-

You might like (Beta): next_record()) { ?>

+

You might like (Beta): next_record()) { ?>

@@ -728,9 +859,11 @@ function header_link($SortKey,$DefaultWay="desc") { - +
+ + @@ -741,36 +874,62 @@ function header_link($SortKey,$DefaultWay="desc") { $Data) { - list($Artists, $GroupCatalogueNumber, $ExtendedArtists, $GroupID2, $GroupName, $GroupRecordLabel, - $ReleaseType, $TagList, $Torrents, $GroupVanityHouse, $GroupYear, $CategoryID, $FreeTorrent, - $HasCue, $HasLog, $TotalLeechers, $LogScore, $ReleaseType, $ReleaseType, $TotalSeeders, - $MaxSize, $TotalSnatched, $GroupTime) = array_values($Data); - - $TagList = explode(' ',str_replace('_','.',$TagList)); - +// Start printing torrent list +foreach ($Results as $Result) { + $GroupID = $Result['groupid']; + $GroupInfo = $Groups[$GroupID]; + if (empty($GroupInfo['Torrents'])) { + continue; + } + $CategoryID = $Result['categoryid']; + $GroupYear = $GroupInfo['Year']; + $ExtendedArtists = $GroupInfo['ExtendedArtists']; + $GroupCatalogueNumber = $GroupInfo['CatalogueNumber']; + $GroupName = $GroupInfo['Name']; + $GroupRecordLabel = $GroupInfo['RecordLabel']; + $ReleaseType = $GroupInfo['ReleaseType']; + if ($GroupResults) { + $Torrents = $GroupInfo['Torrents']; + $GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0; + foreach ($Torrents as $T) { + if ($T['Time'] > $GroupTime) { + $GroupTime = $T['Time']; + } + if ($T['Size'] > $MaxSize) { + $MaxSize = $T['Size']; + } + $TotalLeechers += $T['Leechers']; + $TotalSeeders += $T['Seeders']; + $TotalSnatched += $T['Snatched']; + } + } else { + $Torrents = array($Result['id'] => $GroupInfo['Torrents'][$Result['id']]); + } + $TagList = explode(' ',str_replace('_','.',$GroupInfo['TagList'])); + $TorrentTags = array(); - foreach($TagList as $Tag) { + foreach ($TagList as $Tag) { $TorrentTags[]=''.$Tag.''; } $TorrentTags = implode(', ', $TorrentTags); - - if(count($Torrents)>1 || $CategoryID==1) { + + if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) { + unset($ExtendedArtists[2]); + unset($ExtendedArtists[3]); + $DisplayName = Artists::display_artists($ExtendedArtists); + } else { + $DisplayName = ''; + } + if ($GroupResults && (count($Torrents)>1 || isset($GroupedCategories[$CategoryID-1]))) { // These torrents are in a group - if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) { - unset($ExtendedArtists[2]); - unset($ExtendedArtists[3]); - $DisplayName = Artists::display_artists($ExtendedArtists); - } elseif(!empty($Artists)) { - $DisplayName = Artists::display_artists(array(1=>$Artists)); - } else { - $DisplayName=''; + $DisplayName .= ''.$GroupName.''; + if ($GroupYear > 0) { + $DisplayName .= " [".$GroupYear."]"; + } + if ($GroupVanityHouse) { + $DisplayName .= ' [VH]'; } - $DisplayName.=''.$GroupName.''; - if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; } - if($GroupVanityHouse) { $DisplayName .= ' [VH]'; } $DisplayName .= ' ['.$ReleaseTypes[$ReleaseType].']'; ?> @@ -788,7 +947,7 @@ function header_link($SortKey,$DefaultWay="desc") { - + > - $Data) { + foreach ($Torrents as $TorrentID => $Data) { // All of the individual torrents in the group - + // If they're using the advanced search and have chosen enabled grouping, we just skip the torrents that don't check out - - $Filter = false; - $Pass = false; - - if(!empty($FilterBitrates)) { - $Filter = true; - $Bitrate = strtolower(array_shift(explode(' ',$Data['Encoding']))); - if(in_array($Bitrate, $FilterBitrates)) { - $Pass = true; - } - } - if(!empty($FilterFormats)) { - $Filter = true; - if(in_array(strtolower($Data['Format']), $FilterFormats)) { - $Pass = true; - } - } - - if(!empty($_GET['encoding'])) { - $Filter = true; - if($Data['Encoding']==$_GET['encoding']) { - $Pass = true; - } - } - if(!empty($_GET['format'])) { - $Filter = true; - if($Data['Format']==$_GET['format']) { - $Pass = true; - } - } - - - if(!empty($_GET['media'])) { - $Filter = true; - if($Data['Media']==$_GET['media']) { - $Pass = true; - } - } - if(isset($_GET['haslog']) && $_GET['haslog']!=='') { - $Filter = true; - if($_GET['haslog'] == '100' && $Data['LogScore']==100) { - $Pass = true; - } elseif (($_GET['haslog'] == '-1') && ($Data['LogScore'] < 100) && ($Data['HasLog'] == '1')) { - $Pass = true; - } elseif(($_GET['haslog'] == '1' || $_GET['haslog'] == '0') && (int)$Data['HasLog']==$_GET['haslog']) { - $Pass = true; - } - } - if(isset($_GET['hascue']) && $_GET['hascue']!=='') { - $Filter = true; - if((int)$Data['HasCue']==$_GET['hascue']) { - $Pass = true; - } - } - if(isset($_GET['scene']) && $_GET['scene']!=='') { - $Filter = true; - if((int)$Data['Scene']==$_GET['scene']) { - $Pass = true; - } - } - if(isset($_GET['vanityhouse']) && $_GET['vanityhouse']!=='') { - $Filter = true; - if((int)$Data['VanityHouse']==$_GET['vanityhouse']) { - $Pass = true; - } - } - if(isset($_GET['freetorrent']) && $_GET['freetorrent']!=='') { - $Filter = true; - if((int)$Data['FreeTorrent'] & $_GET['freetorrent'] || (int)$Data['FreeTorrent'] == $_GET['freetorrent']) { - $Pass = true; - } - } - if(!empty($_GET['remastertitle'])) { - $Filter = true; - $Continue = false; - $RemasterParts = explode(' ', $_GET['remastertitle']); - foreach($RemasterParts as $RemasterPart) { - if(stripos($Data['RemasterTitle'],$RemasterPart) === false) { - $Continue = true; - } - } - if(!$Continue) { - $Pass = true; - } - } - if($Filter && !$Pass) { + if (!isset($TorrentIDs[$TorrentID])) { continue; } @@ -911,19 +985,24 @@ function header_link($SortKey,$DefaultWay="desc") { $FirstUnknown = !isset($FirstUnknown); } - if($CategoryID == 1 && ($Data['RemasterTitle'] != $LastRemasterTitle || $Data['RemasterYear'] != $LastRemasterYear || - $Data['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Data['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber) || $FirstUnknown || $Data['Media'] != $LastMedia) { + if (isset($GroupedCategories[$CategoryID-1]) + && ($Data['RemasterTitle'] != $LastRemasterTitle + || $Data['RemasterYear'] != $LastRemasterYear + || $Data['RemasterRecordLabel'] != $LastRemasterRecordLabel + || $Data['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber) + || $FirstUnknown + || $Data['Media'] != $LastMedia) { $EditionID++; - if($Data['Remastered'] && $Data['RemasterYear'] != 0) { - + if ($Data['Remastered'] && $Data['RemasterYear'] != 0) { + $RemasterName = $Data['RemasterYear']; $AddExtra = " - "; - if($Data['RemasterRecordLabel']) { $RemasterName .= $AddExtra.display_str($Data['RemasterRecordLabel']); $AddExtra=' / '; } - if($Data['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Data['RemasterCatalogueNumber']); $AddExtra=' / '; } - if($Data['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Data['RemasterTitle']); $AddExtra=' / '; } + if ($Data['RemasterRecordLabel']) { $RemasterName .= $AddExtra.display_str($Data['RemasterRecordLabel']); $AddExtra=' / '; } + if ($Data['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Data['RemasterCatalogueNumber']); $AddExtra=' / '; } + if ($Data['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Data['RemasterTitle']); $AddExtra=' / '; } $RemasterName .= $AddExtra.display_str($Data['Media']); - + ?> @@ -933,8 +1012,8 @@ function header_link($SortKey,$DefaultWay="desc") { $AddExtra = " / "; if (!$Data['Remastered']) { $MasterName = "Original Release"; - if($GroupRecordLabel) { $MasterName .= $AddExtra.$GroupRecordLabel; $AddExtra=' / '; } - if($GroupCatalogueNumber) { $MasterName .= $AddExtra.$GroupCatalogueNumber; $AddExtra=' / '; } + if ($GroupRecordLabel) { $MasterName .= $AddExtra.$GroupRecordLabel; $AddExtra=' / '; } + if ($GroupCatalogueNumber) { $MasterName .= $AddExtra.$GroupCatalogueNumber; $AddExtra=' / '; } } else { $MasterName = "Unknown Release(s)"; } @@ -964,7 +1043,7 @@ function header_link($SortKey,$DefaultWay="desc") { » - + > @@ -974,24 +1053,25 @@ function header_link($SortKey,$DefaultWay="desc") { } } else { // Viewing a type that does not require grouping - - list($TorrentID, $Data) = each($Torrents); - - $DisplayName = ''.$GroupName.''; - if ($Data['IsSnatched']) { - $DisplayName .= ' Snatched!'; - } - if ($Data['FreeTorrent'] == '1') { - $DisplayName .= ' Freeleech!'; - } elseif ($Data['FreeTorrent'] == '2') { - $DisplayName .= ' Neutral Leech!'; - } elseif ($Data['PersonalFL']) { - $DisplayName .= $AddExtra.' Personal Freeleech!'; + list($TorrentID, $Data) = each($Torrents); + $DisplayName .= ''.$GroupName.''; + if (isset($GroupedCategories[$CategoryID-1])) { + if ($GroupYear) { + $DisplayName .= " [".$GroupYear."]"; + } + if($CategoryID == 1 && $ReleaseType > 0) { + $DisplayName .= ' ['.$ReleaseTypes[$ReleaseType].']'; + } + $ExtraInfo = Torrents::torrent_info($Data, true, true); + } else { + $ExtraInfo = ''; } ?> + + @@ -1004,17 +1084,15 @@ function header_link($SortKey,$DefaultWay="desc") { | RP ] -
-
- -
+
+
- + - - > - + + > +
Name / Year FilesLeechers
- + Unbookmark Bookmark @@ -799,111 +958,26 @@ function header_link($SortKey,$DefaultWay="desc") { (Max) (Max)
-false)); ?> + diff --git a/sections/torrents/details.php b/sections/torrents/details.php index 1a411037..db4c429a 100644 --- a/sections/torrents/details.php +++ b/sections/torrents/details.php @@ -802,15 +802,15 @@ function filelist($Str) { list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post); list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID)); ?> - +
- + - - +
+
# - [Quote] @@ -844,13 +844,9 @@ function filelist($Str) {
- - <?=$Username ?>'s avatar - - Default avatar - + @@ -880,13 +876,13 @@ function filelist($Str) {
- + - + + diff --git a/sections/user/edit.php b/sections/user/edit.php index 032fa523..f8ec4fb6 100644 --- a/sections/user/edit.php +++ b/sections/user/edit.php @@ -115,8 +115,8 @@ function checked($Checked) { - - - + + +