api.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once dirname(__FILE__) . '/se-lib/bootstrap.php';
  3. if (!Request::isHttps()) {
  4. header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
  5. exit();
  6. }
  7. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  8. $errorReportingLevel = E_ALL & ~E_NOTICE;
  9. error_reporting($errorReportingLevel);
  10. ini_set('error_reporting', $errorReportingLevel);
  11. if (file_exists(APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php")) {
  12. require APP_PATH_ROOT . "/config/.config_{$_SERVER['SERVER_NAME']}.php";
  13. }
  14. if (file_exists(APP_PATH_ROOT . "/.config.php")) include APP_PATH_ROOT . "/.config.php";
  15. require_once APP_PATH_ROOT . "/superedit-SEF.php";
  16. SEF('DEBUG_S');
  17. Lib::loadClass('ApiUser');
  18. Lib::loadClass('Api');
  19. session_start();
  20. session_write_close();
  21. $apiUser = new ApiUser();
  22. // ?LOGIN=LOGOUT
  23. if ('LOGOUT' == V::get('LOGIN', '', $_GET)) {
  24. $apiUser->logout();
  25. } else {
  26. $apiUser->auth();
  27. }
  28. $taskPath = Request::getRewriteTaskPath();
  29. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">taskPath (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($taskPath);echo'</pre>';}
  30. $api = new Api();
  31. $api->setUser($apiUser);
  32. try {
  33. $api->execute($taskPath);
  34. }
  35. catch (HttpException $e) {
  36. Http::sendHeaderByCode($e->getCode());
  37. echo $e->getMessage();
  38. }
  39. catch (Exception $e) {
  40. Http::sendHeaderByCode(500);
  41. echo $e->getMessage();
  42. }
  43. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">PHP_AUTH_USER (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SERVER['PHP_AUTH_USER']);echo'</pre>';}
  44. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">REQUEST_URI (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SERVER['REQUEST_URI']);echo'</pre>';}
  45. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">SCRIPT_NAME (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SERVER['SCRIPT_NAME']);echo'</pre>';}
  46. IF(V::get('DBG','',$_GET)){die("\nEOF L." . __LINE__);}
  47. ?>