index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Elgg front controller entry point
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. */
  8. /*
  9. * Rewrite rules for PHP cli webserver used for testing. Do not use on production sites
  10. * as normal web server replacement.
  11. *
  12. * You need to explicitly point to index.php in order for router to work properly:
  13. *
  14. * <code>php -S localhost:8888 index.php</code>
  15. */
  16. if (php_sapi_name() === 'cli-server') {
  17. $urlPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
  18. if (preg_match('/^\/cache\/(.*)$/', $urlPath, $matches)) {
  19. $_GET['request'] = $matches[1];
  20. require('engine/handlers/cache_handler.php');
  21. exit;
  22. } else if (preg_match('/^\/export\/([A-Za-z]+)\/([0-9]+)\/?$/', $urlPath, $matches)) {
  23. $_GET['view'] = $matches[1];
  24. $_GET['guid'] = $matches[2];
  25. require('engine/handlers/export_handler.php');
  26. exit;
  27. } else if (preg_match('/^\/export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$/', $urlPath, $matches)) {
  28. $_GET['view'] = $matches[1];
  29. $_GET['guid'] = $matches[2];
  30. $_GET['type'] = $matches[3];
  31. $_GET['idname'] = $matches[4];
  32. require('engine/handlers/export_handler.php');
  33. exit;
  34. } else if (preg_match("/^\/rewrite.php$/", $urlPath, $matches)) {
  35. require('install.php');
  36. exit;
  37. } else if ($urlPath !== '/' && file_exists(__DIR__ . $urlPath)) {
  38. // serve the requested resource as-is.
  39. return false;
  40. } else {
  41. $_GET['__elgg_uri'] = $urlPath;
  42. }
  43. }
  44. // allow testing from the upgrade page before the site is upgraded.
  45. if (isset($_GET['__testing_rewrite'])) {
  46. if (isset($_GET['__elgg_uri']) && false !== strpos($_GET['__elgg_uri'], '__testing_rewrite')) {
  47. echo "success";
  48. }
  49. exit;
  50. }
  51. require_once(dirname(__FILE__) . "/engine/start.php");
  52. $router = _elgg_services()->router;
  53. $request = _elgg_services()->request;
  54. // TODO use formal Response object instead
  55. header("Content-Type: text/html;charset=utf-8");
  56. if (!$router->route($request)) {
  57. forward('', '404');
  58. }