index.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?PHP
  2. //////////////////////////////////////////////////////////////////////////
  3. // + $Id$
  4. // +------------------------------------------------------------------+ //
  5. // + Cake <https://developers.nextco.com/cake/> + //
  6. // + Copyright: (c) 2005, Cake Authors/Developers + //
  7. // + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
  8. // + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
  9. // + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
  10. // +------------------------------------------------------------------+ //
  11. // + Licensed under The MIT License + //
  12. // + Redistributions of files must retain the above copyright notice. + //
  13. // + See: http://www.opensource.org/licenses/mit-license.php + //
  14. //////////////////////////////////////////////////////////////////////////
  15. /**
  16. * This file collects requests if:
  17. * - no mod_rewrite is avilable or .htaccess files are not supported
  18. * - /public is not set as a web root.
  19. *
  20. * @filesource
  21. * @author Cake Authors/Developers
  22. * @copyright Copyright (c) 2005, Cake Authors/Developers
  23. * @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
  24. * @package cake
  25. * @since Cake v 0.2.9
  26. * @version $Revision$
  27. * @modifiedby $LastChangedBy$
  28. * @lastmodified $Date$
  29. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  30. */
  31. /**
  32. * Get Cake's root directory
  33. */
  34. define ('DS', DIRECTORY_SEPARATOR);
  35. define ('ROOT', dirname(__FILE__).DS);
  36. /**
  37. * We need to redefine some constants and variables, so that Cake knows it is
  38. * working without mod_rewrite.
  39. */
  40. define ('BASE_URL', $_SERVER['SCRIPT_NAME'].'?url=');
  41. /**
  42. * As mod_rewrite (or .htaccess files) is not working, we need to take care
  43. * of what would normally be rewrited, i.e. the static files in /public
  44. */
  45. if (empty($_GET['url']) || ($_GET['url'] == '/'))
  46. {
  47. require (ROOT.'public/index.php');
  48. }
  49. else
  50. {
  51. $elements = explode('/index.php?url=', $_SERVER['REQUEST_URI']);
  52. $base = $elements[0].'/public';
  53. $path = $elements[1];
  54. $filename = ROOT.'public'.str_replace('/', DS, $path);
  55. $url = $base.$path;
  56. if (file_exists($filename))
  57. {
  58. if (preg_match('/^.*\.([a-z]+)$/i', $filename, $ext))
  59. {
  60. switch ($ext[1])
  61. {
  62. case 'jpg':
  63. case 'jpeg':
  64. header('Content-type: image/jpeg');
  65. break;
  66. case 'css':
  67. header('Content-type: text/css');
  68. }
  69. }
  70. print (file_get_contents($filename));
  71. die();
  72. }
  73. else
  74. {
  75. require (ROOT.'public/index.php');
  76. }
  77. }
  78. ?>