make.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $out = fopen('index.php', 'w');
  3. function clean_php_source(string $file): string
  4. {
  5. $php = file_get_contents($file);
  6. $php = preg_replace('/^namespace\s+.*;\s*$/m', '', $php);
  7. $php = preg_replace('/<\?php\s*/', '', $php);
  8. $php = preg_replace(';/\*(?!\*/).*?\*/;s', '', $php);
  9. $php = preg_replace('/^/m', "\t", $php);
  10. $php = preg_replace('/^\s*$/m', "", $php);
  11. return $php;
  12. }
  13. $php = file_get_contents('server.php');
  14. $php = strtr($php, [
  15. '//__KD2\WebDAV\Server__' => clean_php_source('lib/KD2/WebDAV/Server.php'),
  16. '//__KD2\WebDAV\AbstractStorage__' => clean_php_source('lib/KD2/WebDAV/AbstractStorage.php'),
  17. '/*__HTACCESS__*/' => var_export(file_get_contents('.htaccess'), true),
  18. '__JS_SIZE__' => filesize('webdav.js'),
  19. '__CSS_SIZE__' => filesize('webdav.css'),
  20. ]);
  21. $php = preg_replace('/\}\s*$/', "\n?>\n", $php);
  22. $end = "\n\n<?php } ?>\n";
  23. $size = strlen($php);
  24. $count = substr_count($php, '__PHP_SIZE__');
  25. $size -= strlen('__PHP_SIZE__') * $count;
  26. $size += strlen((string) $size) * $count;
  27. $php = str_replace('__PHP_SIZE__', $size, $php);
  28. fwrite($out, $php);
  29. fwrite($out, file_get_contents('webdav.js'));
  30. fwrite($out, file_get_contents('webdav.css'));
  31. fwrite($out, $end);
  32. fclose($out);