PluginStaticSystem.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class PluginStaticSystem
  3. {
  4. function index($dir, $file)
  5. {
  6. $file = preg_replace("#\.\.#", "", $file);
  7. $file = plugins_path("static/" . $file);
  8. if (file_exists($file)) {
  9. return download($file)->force(false)->mimeType(self::mimeType($file))->expire(60*60*24*7);
  10. }
  11. return response('', 404);
  12. }
  13. static function mimeType($ext): string
  14. {
  15. $ext = pathinfo($ext);
  16. if ($ext['extension']) {
  17. $ext = $ext["extension"];
  18. $type = array(
  19. 'css' => 'text/css',
  20. 'js' => 'text/javascript',
  21. 'woff' => 'font/woff',
  22. 'ttf' => 'font/truetype',
  23. 'ico' => 'image/x-icon',
  24. 'jpg' => 'image/jpeg',
  25. 'png' => 'image/png',
  26. 'webp' => 'image/webp',
  27. 'gif' => 'image/gif',
  28. 'svg' => 'image/svg+xml',
  29. 'json'=> 'application/json',
  30. 'pdf' => 'application/pdf',
  31. 'doc' => 'application/msword',
  32. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  33. 'xls' => 'application/vnd.ms-excel',
  34. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  35. 'zip' => 'application/zip',
  36. 'rar' => 'application/x-rar-compressed',
  37. 'txt' => 'text/plain',
  38. 'html' => 'text/html',
  39. );
  40. if (isset($type[$ext])) {
  41. return $type[$ext];
  42. }
  43. }
  44. return '';
  45. }
  46. }