SiteController.php
4.52 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
<?php
class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page' => array('class' => 'CViewAction'),
);
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
if (!Yii::app()->user->isGuest)
{
$this->render('index', array('model' => $this->getSystemInfo()));
}
else
{
$this->actionLogin();
}
}
/**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if ( $error = Yii::app()->errorHandler->error)
{
if (Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
/**
* Displays the contact page
*/
public function actionContact()
{
$model = new ContactForm;
if ( isset($_POST['ContactForm']) )
{
$model->attributes = $_POST['ContactForm'];
if ( $model->validate() )
{
$headers = "From: {$model->email}\r\nReply-To: {$model->email}";
mail(Yii::app()->params['adminEmail'], $model->subject, $model->body, $headers);
Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact', array('model' => $model));
}
/**
* Displays the login page
*/
public function actionLogin()
{
$model = new LoginForm;
// if it is ajax validation request
if ( (isset($_POST['ajax'])) && ($_POST['ajax'] === 'login-form') )
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if ( isset($_POST['LoginForm']) )
{
$model->attributes = $_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if ( ($model->validate()) && ($model->login()) )
{
$this->redirect(Yii::app()->user->returnUrl);
}
}
// display the login form
$this->renderPartial('login',array('model' => $model));
}
/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
}
/**
* 获取系统信息
*/
protected function getSystemInfo()
{
$info = array(
'操作系统' => PHP_OS,
'运行环境' => $_SERVER["SERVER_SOFTWARE"],
'PHP运行方式' => php_sapi_name(),
'上传附件限制' => ini_get('upload_max_filesize'),
'执行时间限制' => ini_get('max_execution_time').'秒',
'服务器时间' => date("Y年n月j日 H:i:s"),
'北京时间' => gmdate("Y年n月j日 H:i:s", time() + 8 * 3600),
'服务器域名/IP' => $_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
'剩余空间' => round((@disk_free_space(".")/(1024*1024*1024)), 2).'G',
'register_globals' => (get_cfg_var("register_globals") == "1" ) ? "ON" : "OFF",
'magic_quotes_gpc' => (1 === get_magic_quotes_gpc()) ? "YES" : "NO",
'magic_quotes_runtime' => (1 === get_magic_quotes_runtime()) ? "YES": "NO",
);
return $info;
}
}
?>