Advertisement
jargon

Avatar Collision Finder Class.php

Jul 7th, 2025
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | Gaming | 0 0
  1. <?php
  2. /* "Avatar Collision Finder Class.php" */
  3.  
  4. include_once("{$_SERVER['DOCUMENT_ROOT']}/Url Check Class.php");
  5. $urlCheck = new UrlCheckClass(['audience','author'], false);
  6. include_once("{$_SERVER['DOCUMENT_ROOT']}/Impressions.php");
  7. $audienceFolder = $urlCheck->audienceFolder;
  8. $fullPath = $urlCheck->fullPath;
  9.  
  10. class AvatarCollisionFinderClass
  11. {
  12.     protected string $avatar;
  13.     protected string $basePath;
  14.     protected array $track = [];
  15.  
  16.     public function __construct(array $get, array $nsfz)
  17.     {
  18.         $this->avatar = pathinfo($get['author'] ?? '', PATHINFO_FILENAME) . '.png';
  19.         $this->basePath = "{$_SERVER['DOCUMENT_ROOT']}/../../nsfz.1.test/../nsfz-author-cache/authors/images";
  20.  
  21.         if ($get['audience'] !== '')
  22.         {
  23.             $this->track[] = '.';
  24.         }
  25.  
  26.         foreach ($nsfz['captions']['audience']['default'] as $default)
  27.         {
  28.             if ($get['audience'] !== $default)
  29.             {
  30.                 continue;
  31.             }
  32.             $this->track[] = $default;
  33.         }
  34.  
  35.         $this->track[] = 'vods';
  36.     }
  37.  
  38.     public function output()
  39.     {
  40.         foreach ($this->track as $folder)
  41.         {
  42.             $check = $this->basePath . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $this->avatar;
  43.             if (is_file($check))
  44.             {
  45.                 header('HTTP/1.1 200 OK');
  46.                 header('Content-Type: image/png');
  47.                 readfile($check);
  48.                 exit;
  49.             }
  50.         }
  51.  
  52. // Fallback to "Various.png" in tracked folders
  53. foreach ($this->track as $folder)
  54. {
  55.     $fallback = $this->basePath . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . 'Various.png';
  56.     if (is_file($fallback))
  57.     {
  58.         header('HTTP/1.1 200 OK');
  59.         header('Content-Type: image/png');
  60.         readfile($fallback);
  61.         exit;
  62.     }
  63. }
  64.  
  65. // Final fallback to root-level Various.png
  66. $fallback = $this->basePath . DIRECTORY_SEPARATOR . 'Various.png';
  67. if (is_file($fallback))
  68. {
  69.     header('Content-Type: image/png');
  70.     readfile($fallback);
  71.     exit;
  72. }
  73.  
  74.         // Still not found
  75.         http_response_code(404);
  76.         header('Content-Type: text/plain');
  77.         echo "Avatar not found: {$this->avatar} or fallback.";
  78.         exit;
  79.     }
  80. }
  81.  
  82. $finder = new AvatarCollisionFinderClass($get, $nsfz);
  83. $finder->output();
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement