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