Action.php
7.97 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
class Q_Action extends Yaf_Controller_Abstract
{
private $_headlink;
private $_headscript;
private $_headTitle;
private $_headmeta;
private $_qdebug;
private $_qdebugMicrotime;
/**
* Meta
* @return Q_View_Header_Meta
*/
public function _headMeta()
{
if (empty($this->_headmeta)) {
$this->_headmeta = new Q_View_Header_Meta();
$this->getView()->assign("_headmeta", $this->_headmeta);
}
return $this->_headmeta;
}
/**
* Script
* @return Q_View_Header_Script
*/
public function _headScript()
{
if (empty($this->_headscript)) {
$this->_headscript = new Q_View_Header_Script();
$this->getView()->assign("_headScript", $this->_headscript);
}
return $this->_headscript;
}
/**
*
* @return Q_View_Header_Link
*/
public function _headLink()
{
if (empty($this->_headlink)) {
$this->_headlink = new Q_View_Header_Link();
$this->getView()->assign("_headLink", $this->_headlink);
}
return $this->_headlink;
}
/**
* Title
* @return Q_View_Header_Title
*/
public function _headTitle($title = null)
{
if (empty($this->_headTitle)) {
$this->_headTitle = new Q_View_Header_Title();
$this->getView()->assign("_headTitle", $this->_headTitle);
}
return $this->_headTitle->headTitle($title);
}
public function helpHeader($code = 200, $msg = '')
{
header("content-type: text/html; charset=utf-8");
$codeStr = "";
switch ($code) {
case 404 :
$codeStr = " 404 Not Found";
break;
case 403 :
$codeStr = " 403 Forbidden";
break;
case 500 :
$codeStr = " 500 Internal Server Error";
break;
default :
$codeStr = " 200 OK";
break;
}
header("HTTP/1.0" . $codeStr);
echo $msg;
}
/**
* js 跳转 并 提示
*
* @param String $url
* @param String $expression
*/
protected function helpJsRedirect($message = '', $expression = "history.back()")
{
header("content-type: text/html; charset=utf-8");
if ($message != "") {
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
if ($expression != "") {
echo "<script language=\"javascript\">\n";
echo $expression . "\n";
echo "</script>";
}
exit();
}
/**
* 跳转
*
* @param String $url
* @param String $message
*/
protected function helpGo($url, $message = '')
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
header('Location: ' . $url);
exit();
}
/**
* refresh跳转
*
* @param String $url
* @param String $message
* @param Integer $content
*/
protected function helpRefresh($url, $message = '', $content = 0, $show = false)
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
echo "<script language=\"javascript\">";
echo "window.location.href='{$url}';";
echo "</script>";
if ($show == false) {
exit();
}
}
/**
* JSON输出
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJsonResult($code, $message = null, $data = null)
{
header('Content-type: application/json');
echo json_encode(Q_Utils_Function::result($code, $message, $data));
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
exit();
}
/**
* JSON输出
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJson($data = null)
{
header('Content-type: application/json');
echo json_encode($data);
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
exit();
}
/**
* JSONP Callback输出,用于远程调用
*
* @param String $caption
* @param Integer $code
* @param mixed $content
*/
protected function helpJsonCallbackResult($callbackString, $code, $message = null, $data = null)
{
echo $callbackString . "(";
echo json_encode(Q_Utils_Function::result($code, $message, $data));
echo ")";
exit();
}
/**
* 转义', "
*
* @param string $string
* @return string
*/
protected function helpAddslashes($string)
{
return get_magic_quotes_gpc() ? $string : addslashes($string);
}
/**
* refresh跳转
*
* @param String $url
* @param String $message
* @param Integer $content
*/
protected function helpRefreshNotExit($url, $message = '', $content = 0)
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
echo "<meta http-equiv=\"refresh\" content=\"{$content};url={$url}\">";
}
/**
* 跳转
* @param string $message
* @param string $url
* @param int $content
*/
protected function helpLocation($message, $url = '',$content = 0)
{
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = Q_Utils_String::format()->addslash($message);
$message = str_replace("\n", "\\n", $message);
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
if(!empty($url))
{
echo "<meta http-equiv=\"refresh\" content=\"{$message};url={$url}\">";
}
else
{
echo "<meta http-equiv=\"refresh\" content=\";url={$_SERVER['REQUEST_URI']}\">";
}
}
protected function _g()
{
return $this->getRequest()->getQuery();
}
public function _debugStart($debug = 'xhprof')
{
if ($this->_g('_qdebug') == 'action') {
$this->_qdebugMicrotime = microtime(true);
$this->_qdebug = new Q_Debug_Xhprof_Stat();
$this->_qdebug->setUrl('http://xhprof.debug.yohobuy.com')->start();
}
}
public function _debugEnd()
{
if ($this->_g('_qdebug') == 'action') {
$this->_qdebug->end();
echo '<br /> Action Time : ' . (microtime(true) - $this->_qdebugMicrotime) . '<br />';
}
}
/**
* 开启session
*/
public function sessionStart()
{
$sessionID = session_id();
if (empty($sessionID)) {
$qinSession = new Q_Core_Session();
session_set_save_handler(
array(&$qinSession, "open"),
array(&$qinSession, "close"),
array(&$qinSession, "read"),
array(&$qinSession, "write"),
array(&$qinSession, "destroy"),
array(&$qinSession, "gc")
);
session_start();
}
}
}