x.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* Set the error reporting. */
  3. error_reporting(E_ALL);
  4. /* Start output buffer. */
  5. ob_start();
  6. /* Set front as default mode. */
  7. $runMode = 'front';
  8. /* Check is api mode. */
  9. if(preg_match('/token=[a-z0-9]{32}/i', $_SERVER["QUERY_STRING"])) $runMode = 'api';
  10. function checkXXDUA()
  11. {
  12. return !empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'easysoft/xuan.im') !== false;
  13. }
  14. function checkXXDVersion()
  15. {
  16. if(empty($_SERVER['HTTP_XXD_VERSION'])) return false;
  17. if($_SERVER['HTTP_XXD_VERSION'] == 'XXDBuildVersion') return true;
  18. $version = trim($_SERVER['HTTP_XXD_VERSION'], "v");
  19. return version_compare($version, '9.3', '>=');
  20. }
  21. /* Check is xuanxuan client mode. */
  22. if(checkXXDUA() && checkXXDVersion()) $runMode = 'xuanxuan';
  23. define('RUN_MODE', $runMode);
  24. /* Load the framework. */
  25. $routerFile = (RUN_MODE == 'api') ? '../framework/router.class.php' : '../framework/xuanxuan.class.php';
  26. include $routerFile;
  27. include '../framework/control.class.php';
  28. include '../framework/model.class.php';
  29. include '../framework/helper.class.php';
  30. /* Log the time and define the run mode. */
  31. $startTime = getTime();
  32. /* Clear cookies for api requests. */
  33. if(RUN_MODE == 'api') $_COOKIE = array();
  34. /* Run the app. */
  35. if(RUN_MODE == 'api') $app = router::createApp('xxb', dirname(dirname(__FILE__)));
  36. if(RUN_MODE != 'api') $app = router::createApp('xxb', dirname(dirname(__FILE__)), 'xuanxuan');
  37. /* Load common model. */
  38. $common = $app->loadCommon();
  39. /* Api mode need check entry and set default params. */
  40. if(RUN_MODE == 'api')
  41. {
  42. $common->checkEntry();
  43. $config->requestType = 'GET';
  44. $config->default->view = 'json';
  45. }
  46. /* Remove serverside cookies. */
  47. header_remove('Set-Cookie');
  48. /* Parse request. */
  49. $result = $app->parseRequest();
  50. if(RUN_MODE != 'api' && !$result) die;
  51. /* Check privilege of api. */
  52. if(RUN_MODE == 'api') $common->checkPriv();
  53. /* Load module. */
  54. $app->loadModule();
  55. /* Process api response. */
  56. if(RUN_MODE == 'api')
  57. {
  58. $output = json_decode(ob_get_clean());
  59. $data = new stdClass();
  60. $data->status = isset($output->status) ? $output->status : $output->result;
  61. if(isset($output->message)) $data->message = $output->message;
  62. if(isset($output->data)) $data->data = json_decode($output->data);
  63. $output = json_encode($data);
  64. unset($_SESSION['entryCode']);
  65. unset($_SESSION['validEntry']);
  66. }
  67. /* Flush the buffer. */
  68. echo helper::removeUTF8Bom(ob_get_clean());