From ce4905e534042cf2922cff00606c1474342a30bb Mon Sep 17 00:00:00 2001 From: Git Date: Sun, 2 Sep 2012 08:00:26 +0000 Subject: [PATCH] Empty commit --- classes/class_search.php | 6 +- design/privateheader.php | 2 +- sections/requests/requests.php | 200 +++++++++++++++++------------ sections/schedule/index.php | 4 +- sections/torrents/browse2.php | 224 ++++++++++++++++++++------------- 5 files changed, 272 insertions(+), 164 deletions(-) diff --git a/classes/class_search.php b/classes/class_search.php index 79571f9c..4d1ec69d 100644 --- a/classes/class_search.php +++ b/classes/class_search.php @@ -149,7 +149,11 @@ function set_index($Index) { function set_filter($Name, $Vals, $Exclude=false) { foreach($Vals as $Val) { - $this->Filters[$Name][] = $Val; + if($Exclude) { + $this->Filters[$Name][] = "!$Val"; + } else { + $this->Filters[$Name][] = $Val; + } } $this->SetFilter($Name, $Vals, $Exclude); } diff --git a/design/privateheader.php b/design/privateheader.php index 29e272c2..1bb68e28 100644 --- a/design/privateheader.php +++ b/design/privateheader.php @@ -122,7 +122,7 @@
  • Required:
  • 0) { ?> -
  • Tokens:
  • +
  • Tokens:
  • set_filter('torrentid', array(0)); } -if(!empty($_GET['search'])) { - $Words = explode(' ', $_GET['search']); - 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); +$EnableNegation = false; // Sphinx needs at least one positive search condition to support the NOT operator + +if(!empty($_GET['formats'])) { + $FormatArray = $_GET['formats']; + if(count($FormatArray) != count($Formats)) { + $FormatNameArray = array(); + foreach($FormatArray as $Index => $MasterIndex) { + if(isset($Formats[$MasterIndex])) { + $FormatNameArray[$Index] = '"'.strtr($Formats[$MasterIndex], '-.', ' ').'"'; + } + } + if(count($FormatNameArray) >= 1) { + $EnableNegation = true; + if(!empty($_GET['formats_strict'])) { + $Queries[]='@formatlist ('.implode(' | ', $FormatNameArray).')'; + } else { + $Queries[]='@formatlist (any | '.implode(' | ', $FormatNameArray).')'; } - } elseif(strlen($Word) >= 2) { - $Word = $SS->EscapeString($Word); - } else { - unset($Words[$Key]); } } - if(!empty($Words)) { - $Queries[] = "@* ".implode(' ', $Words); +} + +if(!empty($_GET['media'])) { + $MediaArray = $_GET['media']; + if(count($MediaArray) != count($Media)) { + $MediaNameArray = array(); + foreach($MediaArray as $Index => $MasterIndex) { + if(isset($Media[$MasterIndex])) { + $MediaNameArray[$Index] = '"'.strtr($Media[$MasterIndex], '-.', ' ').'"'; + } + } + + if(count($MediaNameArray) >= 1) { + $EnableNegation = true; + if(!empty($_GET['media_strict'])) { + $Queries[]='@medialist ('.implode(' | ', $MediaNameArray).')'; + } else { + $Queries[]='@medialist (any | '.implode(' | ', $MediaNameArray).')'; + } + } + } +} + +if(!empty($_GET['bitrates'])) { + $BitrateArray = $_GET['bitrates']; + if(count($BitrateArray) != count($Bitrates)) { + $BitrateNameArray = array(); + foreach($BitrateArray as $Index => $MasterIndex) { + if(isset($Bitrates[$MasterIndex])) { + $BitrateNameArray[$Index] = '"'.strtr($SS->EscapeString($Bitrates[$MasterIndex]), '-.', ' ').'"'; + } + } + + if(count($BitrateNameArray) >= 1) { + $EnableNegation = true; + if(!empty($_GET['bitrate_strict'])) { + $Queries[]='@bitratelist ('.implode(' | ', $BitrateNameArray).')'; + } else { + $Queries[]='@bitratelist (any | '.implode(' | ', $BitrateNameArray).')'; + } + } + } +} + +if(!empty($_GET['search'])) { + $SearchString = trim($_GET['search']); + if($SearchString != '') { + $SearchWords = array('include' => array(), 'exclude' => array()); + $Words = explode(' ', $SearchString); + foreach($Words as $Word) { + $Word = trim($Word); + if($Word[0] == '!' && strlen($Word) >= 2) { + if(strpos($Word,'!',1) === false) { + $SearchWords['exclude'][] = $Word; + } else { + $SearchWords['include'][] = $Word; + $EnableNegation = true; + } + } elseif($Word != '') { + $SearchWords['include'][] = $Word; + $EnableNegation = true; + } + } + $QueryParts = array(); + if(!$EnableNegation && !empty($SearchWords['exclude'])) { + $SearchWords['include'] = array_merge($SearchWords['include'], $SearchWords['exclude']); + unset($SearchWords['exclude']); + } + foreach($SearchWords['include'] as $Word) { + $QueryParts[] = $SS->EscapeString($Word); + } + if(!empty($SearchWords['exclude'])) { + foreach($SearchWords['exclude'] as $Word) { + $QueryParts[] = '!'.$SS->EscapeString(substr($Word,1)); + } + } + if(!empty($QueryParts)) { + $Queries[] = "@* ".implode(' ', $QueryParts); + } } } if(!empty($_GET['tags'])){ $Tags = explode(',', $_GET['tags']); $TagNames = array(); - foreach ($Tags as $Tag) { + if(!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { + $TagType = 1; + $_GET['tags_type'] = '1'; + } else { + $TagType = 0; + $_GET['tags_type'] = '0'; + } + foreach($Tags as $Tag) { $Tag = ltrim($Tag); - $Exclude = (!empty($_GET['tags_type']) && $Tag[0] == '!'); // Negations aren't supported in the "any" mode + $Exclude = ($Tag[0] == '!'); $Tag = sanitize_tag($Tag); if(!empty($Tag)) { $TagNames[] = $Tag; $TagsExclude[$Tag] = $Exclude; } } + $AllNegative = !in_array(false, $TagsExclude); $Tags = get_tags($TagNames); - // Sphinx can't handle queries consisting of only exclusions - if(!in_array(false, $TagsExclude)) { - $TagsExclude = array(); - } // Replace the ! characters that sanitize_tag removed - foreach($TagNames as &$TagName) { - if($TagsExclude[$TagName]) { - $TagName = '!'.$TagName; + if($TagType == 1 || $AllNegative) { + foreach($TagNames as &$TagName) { + if($TagsExclude[$TagName]) { + $TagName = '!'.$TagName; + } } + unset($TagName); } - unset($TagName); +} elseif(!isset($_GET['tags_type']) || $_GET['tags_type'] != 0) { + $_GET['tags_type'] = 1; +} else { + $_GET['tags_type'] = 0; } -if(empty($_GET['tags_type']) && !empty($Tags)) { - $_GET['tags_type'] = '0'; - $SS->set_filter('tagid', array_keys($Tags)); -} elseif(!empty($Tags)) { +// 'All' tags +if($TagType == 1 && !empty($Tags)) { foreach($Tags as $TagID => $TagName) { $SS->set_filter('tagid', array($TagID), $TagsExclude[$TagName]); } -} else { - $_GET['tags_type'] = '1'; +} elseif(!empty($Tags)) { + $SS->set_filter('tagid', array_keys($Tags), $AllNegative); } if(!empty($_GET['filter_cat'])) { @@ -148,53 +238,6 @@ } } -if(!empty($_GET['formats'])) { - $FormatArray = $_GET['formats']; - if(count($FormatArray) != count($Formats)) { - $FormatNameArray = array(); - foreach($FormatArray as $Index => $MasterIndex) { - if(isset($Formats[$MasterIndex])) { - $FormatNameArray[$Index] = '"'.strtr($Formats[$MasterIndex], '-.', ' ').'"'; - } - } - if(count($FormatNameArray) >= 1) { - $Queries[]='@formatlist (any | '.implode(' | ', $FormatNameArray).')'; - } - } -} - -if(!empty($_GET['media'])) { - $MediaArray = $_GET['media']; - if(count($MediaArray) != count($Media)) { - $MediaNameArray = array(); - foreach($MediaArray as $Index => $MasterIndex) { - if(isset($Media[$MasterIndex])) { - $MediaNameArray[$Index] = '"'.strtr($Media[$MasterIndex], '-.', ' ').'"'; - } - } - - if(count($MediaNameArray) >= 1) { - $Queries[]='@medialist (any | '.implode(' | ', $MediaNameArray).')'; - } - } -} - -if(!empty($_GET['bitrates'])) { - $BitrateArray = $_GET['bitrates']; - if(count($BitrateArray) != count($Bitrates)) { - $BitrateNameArray = array(); - foreach($BitrateArray as $Index => $MasterIndex) { - if(isset($Bitrates[$MasterIndex])) { - $BitrateNameArray[$Index] = '"'.strtr($SS->EscapeString($Bitrates[$MasterIndex]), '-.', ' ').'"'; - } - } - - if(count($BitrateNameArray) >= 1) { - $Queries[]='@bitratelist (any | '.implode(' | ', $BitrateNameArray).')'; - } - } -} - if(!empty($_GET['requestor']) && check_perms('site_see_old_requests')) { if(is_number($_GET['requestor'])) { $SS->set_filter('userid', array($_GET['requestor'])); @@ -396,6 +439,7 @@ Formats /> + /> $Val) { if($Key % 8 == 0) echo "
    ";?> Bitrates /> + /> $Val) { if($Key % 8 == 0) echo "
    ";?> Media /> + /> $Val) { if($Key % 8 == 0) echo "
    ";?> next_record(); $DB->query("UPDATE schedule SET NextHour = ".next_hour().", NextDay = ".next_day().", NextBiWeekly = ".next_biweek()); +$NoDaily = isset($argv[2]) && $argv[2] == 'nodaily'; + $sqltime = sqltime(); echo "$sqltime\n"; @@ -326,7 +328,7 @@ function next_hour() { \*************************************************************************/ -if($Day != next_day() || $_GET['runday']){ +if(!$NoDaily && $Day != next_day() || $_GET['runday']){ echo "Ran daily functions\n"; if($Day%2 == 0) { // If we should generate the drive database (at the end) $GenerateDriveDB = true; diff --git a/sections/torrents/browse2.php b/sections/torrents/browse2.php index 1453e80f..1827bda9 100644 --- a/sections/torrents/browse2.php +++ b/sections/torrents/browse2.php @@ -114,108 +114,166 @@ function header_link($SortKey,$DefaultWay="desc") { $Queries = array(); +$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'])) { + $SearchString = trim($_GET['filelist']); + if($SearchString != '') { + $Queries[] = '@filelist "'.$SS->EscapeString($_GET['filelist']).'"~20'; + $EnableNegation = true; + } +} + +// Collect all entered search terms to find out whether to enable the NOT operator +foreach(array('artistname','groupname', 'recordlabel', 'cataloguenumber', + 'remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', + 'format', 'media', 'taglist') as $Search) { + if(!empty($_GET[$Search])) { + $SearchString = trim($_GET[$Search]); + if($SearchString != '') { + $SearchWords[$Search] = array('include' => array(), 'exclude' => array()); + if($Search == 'taglist') { + $SearchString = strtr($SearchString, '.', '_'); + $Words = explode(',', $SearchString); + } else { + $Words = explode(' ', $SearchString); + } + foreach($Words as $Word) { + $Word = trim($Word); + if($Word[0] == '!' && strlen($Word) >= 2) { + if(strpos($Word,'!',1) === false) { + $SearchWords[$Search]['exclude'][] = $Word; + } else { + $SearchWords[$Search]['include'][] = $Word; + $EnableNegation = true; + } + } elseif($Word != '') { + $SearchWords[$Search]['include'][] = $Word; + $EnableNegation = true; + } + } + } + } +} + //Simple search if(!empty($_GET['searchstr'])) { - $Words = explode(' ',strtolower($_GET['searchstr'])); - $FilterBitrates = array_intersect($Words, $SearchBitrates); - if(count($FilterBitrates)>0) { - $Queries[]='@encoding '.implode(' ',$FilterBitrates); - } - - $FilterFormats = array_intersect($Words, $SearchFormats); - if(count($FilterFormats)>0) { - $Queries[]='@format '.implode(' ',$FilterFormats); - } - - if(in_array('100%', $Words)) { - $_GET['haslog'] = '100'; - unset($Words[array_search('100%',$Words)]); - } - - $Words = array_diff($Words, $FilterBitrates, $FilterFormats); + $SearchString = trim($_GET['searchstr']); + $Words = explode(' ',strtolower($SearchString)); if(!empty($Words)) { - foreach($Words as $Key => &$Word) { - if($Word[0] == '!' && strlen($Word) >= 3 && count($Words) >= 2) { - if(strpos($Word,'!',1) === false) { - $Word = '!'.$SS->EscapeString(substr($Word,1)); + $FilterBitrates = $FilterFormats = array(); + $BasicSearch = array('include' => array(), 'exclude' => array()); + foreach($Words as $Word) { + $Word = trim($Word); + if($Word[0] == '!' && strlen($Word) >= 2) { + if($Word == '!100%') { + $_GET['haslog'] = '-1'; + } elseif(strpos($Word,'!',1) === false) { + $BasicSearch['exclude'][] = $Word; } else { - $Word = $SS->EscapeString($Word); + $BasicSearch['include'][] = $Word; + $EnableNegation = true; } - } elseif(strlen($Word) >= 2) { - $Word = $SS->EscapeString($Word); - } else { - unset($Words[$Key]); + } elseif(in_array($Word, $SearchBitrates)) { + $FilterBitrates[] = $Word; + $EnableNegation = true; + } elseif(in_array($Word, $SearchFormats)) { + $FilterFormats[] = $Word; + $EnableNegation = true; + } elseif($Word == '100%') { + $_GET['haslog'] = '100'; + } elseif($Word != '') { + $BasicSearch['include'][] = $Word; + $EnableNegation = true; } } - unset($Word); - $Words = trim(implode(' ',$Words)); - if(!empty($Words)) { - $Queries[]='@(groupname,artistname,yearfulltext) '.$Words; + 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->EscapeString($Word); + } + if(!empty($BasicSearch['exclude'])) { + foreach($BasicSearch['exclude'] as $Word) { + $QueryParts[] = '!'.$SS->EscapeString(substr($Word,1)); + } + } + if(!empty($FilterBitrates)) { + $Queries[] = "@encoding ".implode(' ', $FilterBitrates); + } + if(!empty($FilterFormats)) { + $Queries[] = "@format ".implode(' ', $FilterFormats); + } + if(!empty($QueryParts)) { + $Queries[] = "@(groupname,artistname,yearfulltext) ".implode(' ', $QueryParts); } } } -if(!empty($_GET['taglist'])) { - $_GET['taglist'] = str_replace('.','_',$_GET['taglist']); - $TagList = explode(',',$_GET['taglist']); - $TagListEx = array(); - foreach($TagList as $Key => &$Tag) { - $Tag = trim($Tag); - if(strlen($Tag) >= 2) { - if($Tag[0] == '!' && strlen($Tag) >= 3) { - $TagListEx[] = '!'.$SS->EscapeString(substr($Tag,1)); - unset($TagList[$Key]); - } else { - $Tag = $SS->EscapeString($Tag); - } - } else { - unset($TagList[$Key]); +// Tag list +if(!empty($SearchWords['taglist'])) { + $Tags = $SearchWords['taglist']; + if(!$EnableNegation && !empty($Tags['exclude'])) { + $Tags['include'] = array_merge($Tags['include'], $Tags['exclude']); + unset($Tags['exclude']); + } + foreach($Tags['include'] as &$Tag) { + $Tag = $SS->EscapeString($Tag); + } + if(!empty($Tags['exclude'])) { + foreach($Tags['exclude'] as &$Tag) { + $Tag = '!'.$SS->EscapeString(substr($Tag,1)); } } - unset($Tag); -} -if(empty($_GET['tags_type']) && !empty($TagList) && count($TagList) > 1) { - $_GET['tags_type'] = '0'; - if(!empty($TagListEx)) { - $Queries[]='@taglist ( '.implode(' | ', $TagList).' ) '.implode(' ', $TagListEx); - } else { - $Queries[]='@taglist ( '.implode(' | ', $TagList).' )'; + $QueryParts = array(); + // 'All' tags + if(!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { + $_GET['tags_type'] = '1'; + $Tags = array_merge($Tags['include'], $Tags['exclude']); + if(!empty($Tags)) { + $QueryParts[] = implode(' ', $Tags); + } } -} elseif(!empty($TagList)) { - $Queries[]='@taglist '.implode(' ', array_merge($TagList,$TagListEx)); -} else { + // 'Any' tags + else { + $_GET['tags_type'] = '0'; + if(!empty($Tags['include'])) { + $QueryParts[] = '( '.implode(' | ', $Tags['include']).' )'; + } + if(!empty($Tags['exclude'])) { + $QueryParts[] = implode(' ', $Tags['exclude']); + } + } + if(!empty($QueryParts)) { + $Queries[] = "@taglist ".implode(' ', $QueryParts); + } + unset($SearchWords['taglist']); +} +elseif(!isset($_GET['tags_type'])) { $_GET['tags_type'] = '1'; } -foreach(array('artistname','groupname', 'recordlabel', 'cataloguenumber', - 'remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', - 'filelist', 'format', 'media') as $Search) { - if(!empty($_GET[$Search])) { - $_GET[$Search] = str_replace(array('%'), '', $_GET[$Search]); - if($Search == 'filelist') { - $Queries[]='@filelist "'.$SS->EscapeString($_GET['filelist']).'"~20'; - } else { - $Words = explode(' ', $_GET[$Search]); - foreach($Words as $Key => &$Word) { - if($Word[0] == '!' && strlen($Word) >= 3 && count($Words) >= 2) { - if(strpos($Word,'!',1) === false) { - $Word = '!'.$SS->EscapeString(substr($Word,1)); - } else { - $Word = $SS->EscapeString($Word); - } - } elseif(strlen($Word) >= 2) { - $Word = $SS->EscapeString($Word); - } else { - unset($Words[$Key]); - } - } - $Words = trim(implode(' ',$Words)); - if(!empty($Words)) { - $Queries[]="@$Search ".$Words; - } +foreach($SearchWords as $Search => $Words) { + $QueryParts = array(); + if(!$EnableNegation && !empty($Words['exclude'])) { + $Words['include'] = array_merge($Words['include'], $Words['exclude']); + unset($Words['exclude']); + } + foreach($Words['include'] as $Word) { + $QueryParts[] = $SS->EscapeString($Word); + } + if(!empty($Words['exclude'])) { + foreach($Words['exclude'] as $Word) { + $QueryParts[] = '!'.$SS->EscapeString(substr($Word,1)); } } + if(!empty($QueryParts)) { + $Queries[] = "@$Search ".implode(' ', $QueryParts); + } } if(!empty($_GET['year'])) { @@ -316,9 +374,7 @@ function header_link($SortKey,$DefaultWay="desc") { $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); }