Advertisement
jargon

// Shared :: "Classes/queryClass.php"

Sep 25th, 2024 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | Gaming | 0 0
  1. <?php
  2. // Shared :: "Classes/queryClass.php"
  3.  
  4. class queryClass {
  5.  
  6.     public $gamesByRelease = [];
  7.     public $Blacklist = [];
  8.     public $queryRelease = "";
  9.     public $queryGame = "";
  10.    
  11.     public function __construct() {
  12.        
  13.         $type = 'type';
  14.         $this->Blacklist[$type] = explode("\r\n", file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/csv/blacklists/{$type}.csv"));
  15.                
  16.         foreach($this->Blacklist['type'] as $type) {
  17.             // Load blacklist from CSV
  18.             $this->Blacklist[$type] = explode("\r\n", file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/csv/blacklists/{$type}.csv"));
  19.         }
  20.        
  21.         $this->queryRelease = $_GET['release'] ?? false;
  22.         $this->queryGame = $_GET['game'] ?? false;
  23.     }
  24.    
  25.     public function query() {
  26.         $this->gamesByRelease = [];
  27.         $releases = array_filter(
  28.             array_map('basename', glob("{$_SERVER['DOCUMENT_ROOT']}/*", GLOB_ONLYDIR)),
  29.             fn($file) => !in_array($file, $this->Blacklist['release'])
  30.         );
  31.        
  32.         natcasesort($releases);
  33.        
  34.         foreach ($releases as $release) {
  35.             $this->gamesByRelease[$release] = [];
  36.            
  37.             $games = array_values(array_filter(
  38.                 array_map('basename', glob("{$_SERVER['DOCUMENT_ROOT']}/{$release}/*", GLOB_ONLYDIR)),
  39.                 fn($file) => !in_array($file, $this->Blacklist['game'])
  40.             ));
  41.            
  42.             natcasesort($games);
  43.            
  44.             $this->gamesByRelease[$release] = $games;
  45.         }
  46.        
  47.         print_r($this->gamesByRelease);
  48.        
  49.         $requestedRelease = $_GET['release'] ?? false;
  50.         $requestedGame = $_GET['game'] ?? false;
  51.        
  52.         if (!isset($this->gamesByRelease[$requestedRelease][$requestedGame])) {
  53.             $this->queryRelease = false;
  54.             $this->queryGame = false;
  55.         } else {
  56.             $this->queryRelease = $requestedRelease;
  57.             $this->queryGame = $requestedGame;
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement