ztcli 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * 禅道系统命令行访问入口。使用方法:http://www.zentao.net/help-read-78899.html
  5. * The cli router file of zentaopms.
  6. *
  7. * @copyright Copyright 2009-2013 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
  8. * @license LGPL (http://www.gnu.org/licenses/lgpl.html)
  9. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  10. * @package bin
  11. * @version $Id$
  12. * @link http://www.zentao.net
  13. */
  14. error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
  15. define('IN_SHELL', true);
  16. /* Judge the args. */
  17. if($argc < 2 or $argc > 3) die('Usage: ' . basename(__FILE__) . " <request>\n");
  18. /* Parse the request into params. */
  19. $request = parse_url(trim($argv[1]));
  20. $_SERVER['HTTP_HOST'] = $request['host'];
  21. $_SERVER['SCRIPT_NAME'] = $request['path'];
  22. /* Load the framework. */
  23. chdir(dirname(dirname(__FILE__)));
  24. include './framework/router.class.php';
  25. include './framework/control.class.php';
  26. include './framework/model.class.php';
  27. include './framework/helper.class.php';
  28. /* Instance the app and run it. */
  29. $app = router::createApp('pms', dirname(dirname(__FILE__)), 'router');
  30. $common = $app->loadCommon();
  31. /* Set the PATH_INFO request. */
  32. if(!empty($argv[2]) && $argv[2] == 'pathinfo')
  33. {
  34. $config->requestType = 'PATH_INFO';
  35. $config->requestFix = '-';
  36. }
  37. /* Set the PATH_INFO variable. */
  38. if($config->requestType == 'PATH_INFO')
  39. {
  40. $path = pathinfo($request['path']);
  41. /* url like http://pms.zentao.net/zentao/my-todo.html, PATH_INFO is 'my-todo.html'. */
  42. if(strpos($path['basename'], $config->requestFix))
  43. {
  44. $_SERVER['PATH_INFO'] = $path['basename'];
  45. }
  46. else
  47. {
  48. /* url like http://pms.zentao.net/zentao/my/, PATH_INFO is 'my'. */
  49. if(is_dir('./module/' . $path['basename']))
  50. {
  51. $_SERVER['PATH_INFO'] = $path['basename'];
  52. }
  53. /* url like http://pms.zentao.net/zentao/, PATH_INFO is '/'. */
  54. else
  55. {
  56. $_SERVER['PATH_INFO'] = '/';
  57. }
  58. }
  59. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  60. }
  61. else
  62. {
  63. parse_str($request['query'], $_GET);
  64. $_SERVER['SCRIPT_NAME'] = $request['path'];
  65. $_SERVER['REQUEST_URI'] = isset($request['query']) ? $request['query'] : '';
  66. }
  67. try
  68. {
  69. $app->parseRequest();
  70. if(!$app->setParams()) helper::end();
  71. $app->loadModule();
  72. }
  73. catch (EndResponseException $endResponseException)
  74. {
  75. echo $endResponseException->getContent();
  76. }
  77. /* Flush the buffer. */
  78. echo helper::removeUTF8Bom(ob_get_clean());