diff --git a/index.php b/index.php index c25095c..c68a611 100644 --- a/index.php +++ b/index.php @@ -12,6 +12,7 @@ if(isset($_GET['p'])){ setcookie('search', $search, time() + (86400 * 30), "/"); }else{ $search = NULL; + setcookie('search', '', time() -3600 , "/"); } } @@ -23,18 +24,29 @@ $cogs = array(); foreach($json as $source => $sourceData){ foreach($sourceData['rx_cogs'] as $cogId => $cog){ $cog['id'] = $cogId; - list($url, $branch) = explode('@', $source, 2); - $cog['source'] = $url; + $cog['source'] = explode('@', $source, 2)[0]; $cog['source_name'] = $sourceData['name']; $cog['rx_category'] = $sourceData['rx_category']; $cog['rx_branch'] = $sourceData['rx_branch']; - if(!empty($cog['max_bot_version'])){ - array_unshift($cog['requirements'], 'Bot<=' . $cog['max_bot_version']); - } - if(!empty($cog['min_bot_version'])){ - array_unshift($cog['requirements'], 'Bot>=' . $cog['min_bot_version']); + if($cog['min_bot_version'] == '0.0.0'){ $cog['min_bot_version'] = ''; } + if($cog['max_bot_version'] == '0.0.0'){ $cog['max_bot_version'] = ''; } + + if($cog['min_bot_version'] === $cog['max_bot_version']){ + if(!empty($cog['max_bot_version'])){ + array_unshift($cog['requirements'], 'Bot==' . $cog['max_bot_version']); + } else + if(!empty($cog['max_bot_version'])){ + array_unshift($cog['requirements'], 'Bot==' . $cog['max_bot_version']); + } + } else { + if(!empty($cog['max_bot_version'])){ + array_unshift($cog['requirements'], 'Bot<=' . $cog['max_bot_version']); + } + if(!empty($cog['min_bot_version'])){ + array_unshift($cog['requirements'], 'Bot>=' . $cog['min_bot_version']); + } } if(!empty($cog['min_python_version'])){ array_unshift($cog['requirements'], 'Python>=' . implode('.', $cog['min_python_version'])); @@ -45,10 +57,20 @@ foreach($json as $source => $sourceData){ if(count($cog['author']) == 0){ continue; } # ghost entries foreach($cog['tags'] as $index => $this_tag){$cog['tags'][$index] = strtolower($this_tag);} if($filter && !in_array(strtolower($filter), $cog['tags'])){ continue; } - if($search && stripos(strtolower($cog['id']), strtolower($search)) === false){ - if(stripos(strtolower($cog['description'] ?: $cog['short']), strtolower($search)) === false && !in_array(strtolower($search), $cog['tags'])){ - continue; + if($search){ + $matched = FALSE; + if(stripos(strtolower($cog['id']), strtolower($search)) !== false){ $matched = TRUE; } else + if(stripos(strtolower($cog['description'] ?: $cog['short']), strtolower($search)) !== false){ $matched = TRUE; } else + if(in_array(strtolower($search), $cog['tags'])){ $matched = TRUE; } else { + foreach($cog['author'] as $author) { + if(stripos(strtolower($author), strtolower($search)) !== false){ $matched = TRUE; break; } + } + + foreach($cog['requirements'] as $req) { + if(stripos(strtolower($req), strtolower($search)) !== false){ $matched = TRUE; break; } + } } + if(!$matched){ continue; } } array_push($cogs, $cog); } @@ -77,7 +99,7 @@ $cog_chunks = array_chunk($cogs, $per_page); Build Your Own Cog