oop-setup.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php namespace HashOver;
  2. // Copyright (C) 2017 Jacob Barkdull
  3. // This file is part of HashOver.
  4. //
  5. // HashOver is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as
  7. // published by the Free Software Foundation, either version 3 of the
  8. // License, or (at your option) any later version.
  9. //
  10. // HashOver is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with HashOver. If not, see <http://www.gnu.org/licenses/>.
  17. // Display source code
  18. if (basename ($_SERVER['PHP_SELF']) === basename (__FILE__)) {
  19. if (isset ($_GET['source'])) {
  20. header ('Content-type: text/plain; charset=UTF-8');
  21. exit (file_get_contents (basename (__FILE__)));
  22. }
  23. }
  24. // Autoload class files
  25. spl_autoload_register (function ($uri) {
  26. $uri = str_replace ('\\', '/', strtolower ($uri));
  27. $class_name = basename ($uri);
  28. $error = '"' . $class_name . '.php" file could not be included!';
  29. if (!@include ('./' . $class_name . '.php')) {
  30. // Return JavaScript code to display an error
  31. $js_error = 'var hashover = document.getElementById (\'hashover\') || document.body;' . PHP_EOL;
  32. $js_error .= 'var error = \'<p><b>HashOver</b>: ' . $error . '</p>\';' . PHP_EOL . PHP_EOL;
  33. $js_error .= 'hashover.innerHTML += error;';
  34. echo $js_error;
  35. exit;
  36. }
  37. });