Update index.php

#15 Fixed Cache issues
#14 Added more things to search by
#12 No longer show 0.0.0.0 and if min/max is the same will do a ==
This commit is contained in:
Eslyium 2021-05-20 10:44:50 -04:00 committed by GitHub
parent 346b23d737
commit 4b2f5645bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
<a class="nav-link" href="https://red-discordbot.readthedocs.io/en/stable/guide_cog_creation.html">Build Your Own Cog</a>
</div>
<div class="search">
<form id="search" method="post" action="?filter=<?php print($filter);?>&ua=<?php print($show_ua);?>">
<form id="search" method="post" action="?filter=<?php print($filter);?>&ua=<?php print($show_ua);?>&cb=<?php print(intval(microtime(TRUE))); ?>">
<svg class="icon" viewBox="0 0 20 20">
<path d="M12.323,2.398c-0.741-0.312-1.523-0.472-2.319-0.472c-2.394,0-4.544,1.423-5.476,3.625C3.907,7.013,3.896,8.629,4.49,10.102c0.528,1.304,1.494,2.333,2.72,2.99L5.467,17.33c-0.113,0.273,0.018,0.59,0.292,0.703c0.068,0.027,0.137,0.041,0.206,0.041c0.211,0,0.412-0.127,0.498-0.334l1.74-4.23c0.583,0.186,1.18,0.309,1.795,0.309c2.394,0,4.544-1.424,5.478-3.629C16.755,7.173,15.342,3.68,12.323,2.398z M14.488,9.77c-0.769,1.807-2.529,2.975-4.49,2.975c-0.651,0-1.291-0.131-1.897-0.387c-0.002-0.004-0.002-0.004-0.002-0.004c-0.003,0-0.003,0-0.003,0s0,0,0,0c-1.195-0.508-2.121-1.452-2.607-2.656c-0.489-1.205-0.477-2.53,0.03-3.727c0.764-1.805,2.525-2.969,4.487-2.969c0.651,0,1.292,0.129,1.898,0.386C14.374,4.438,15.533,7.3,14.488,9.77z"></path>
</svg>