📄 正在查看:admin/control/my_control.class.php
大小:5,501 字节 · 修改:2014-01-23 01:42:52 · 行数:159
1<?php
2/**
3 * (C)2012-2014 twcms.com TongWang Inc.
4 * Author: wuzhaohuan <kongphp@gmail.com>
5 */
6
7defined('TWCMS_PATH') or exit;
8
9class my_control extends admin_control {
10 // 我的首页
11 public function index() {
12 // 格式化后显示给用户
13 $this->user->format($this->_user);
14
15 // 常用功能
16 $used_array = $this->get_used();
17
18 //服务器信息
19 $info = array();
20 $is_ini_get = function_exists('ini_get'); // 考虑禁用 ini_get 的服务器
21 $info['os'] = function_exists('php_uname') ? php_uname() : '未知';
22 $info['software'] = R('SERVER_SOFTWARE', 'S');
23 $info['php'] = PHP_VERSION;
24 $info['mysql'] = $this->user->db->version();
25 $info['filesize'] = $is_ini_get ? ini_get('upload_max_filesize') : '未知';
26 $info['exectime'] = $is_ini_get ? ini_get('max_execution_time') : '未知';
27 $info['safe_mode'] = $is_ini_get ? (ini_get('safe_mode') ? 'Yes' : 'No') : '未知';
28 $info['url_fopen'] = $is_ini_get ? (ini_get('allow_url_fopen') ? 'Yes' : 'No') : '未知';
29 $info['other'] = $this->get_other();
30
31 // 综合统计
32 $stat = array();
33 // $stat['user'] = $this->user->count();
34 $stat['category'] = $this->category->count();
35
36 $this->cms_content->table = 'cms_article';
37 $stat['article'] = $this->cms_content->count();
38
39 $this->cms_content_comment->table = 'cms_article_comment';
40 $stat['article_comment'] = $this->cms_content_comment->count();
41
42 $this->cms_content->table = 'cms_product';
43 $stat['product'] = $this->cms_content->count();
44
45 $this->cms_content_comment->table = 'cms_product_comment';
46 $stat['product_comment'] = $this->cms_content_comment->count();
47
48 $this->cms_content->table = 'cms_photo';
49 $stat['photo'] = $this->cms_content->count();
50
51 $this->cms_content_comment->table = 'cms_photo_comment';
52 $stat['photo_comment'] = $this->cms_content_comment->count();
53
54 $stat['space'] = function_exists('disk_free_space') ? get_byte(disk_free_space(TWCMS_PATH)) : '未知';
55 $response_info = $this->response_info($info, $stat);
56
57 $this->assign('used_array', $used_array);
58 $this->assign('info', $info);
59 $this->assign('stat', $stat);
60 $this->assign('response_info', $response_info);
61
62 // hook admin_my_control_index_after.php
63
64 $this->display();
65 }
66
67 // 新标签页
68 public function newtab() {
69 // hook admin_my_control_newtab_after.php
70
71 $this->display();
72 }
73
74 // 修改密码
75 public function password() {
76 if(empty($_POST)) {
77 // hook admin_my_control_password_after.php
78
79 $this->display();
80 }else{
81 $oldpw = trim(R('oldpw', 'P'));
82 $newpw = trim(R('newpw', 'P'));
83 $confirm_newpw = trim(R('confirm_newpw', 'P'));
84 $data = $this->_user;
85
86 if(empty($oldpw)) {
87 E(1, '旧密码不能为空', 'oldpw');
88 }elseif(strlen($newpw) < 8) {
89 E(1, '新密码不能小于8位', 'newpw');
90 }elseif($confirm_newpw != $newpw) {
91 E(1, '确认密码不等于新密码', 'confirm_newpw');
92 }elseif($oldpw == $newpw) {
93 E(1, '新密码不能和旧密码相同', 'newpw');
94 }elseif(!$this->user->verify_password($oldpw, $data['salt'], $data['password'])) {
95 E(1, '旧密码不正确', 'oldpw');
96 }
97
98 // hook admin_my_control_password_post_after.php
99
100 $data['salt'] = random(16, 3, '0123456789abcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+<>,.'); // 增加破解难度
101 $data['password'] = md5(md5($newpw).$data['salt']);
102 if(!$this->user->update($data)) {
103 E(1, '修改失败');
104 }else{
105 E(0, '修改成功');
106 }
107 }
108 }
109
110 // 获取常用功能
111 private function get_used() {
112 $arr = array(
113 array('name'=>'发布文章', 'url'=>'article-add', 'imgsrc'=>'admin/ico/article_add.jpg'),
114 array('name'=>'文章管理', 'url'=>'article-index', 'imgsrc'=>'admin/ico/article_index.jpg'),
115 array('name'=>'发布产品', 'url'=>'product-add', 'imgsrc'=>'admin/ico/product_add.jpg'),
116 array('name'=>'产品管理', 'url'=>'product-index', 'imgsrc'=>'admin/ico/product_index.jpg'),
117 array('name'=>'发布图集', 'url'=>'photo-add', 'imgsrc'=>'admin/ico/photo_add.jpg'),
118 array('name'=>'图集管理', 'url'=>'photo-index', 'imgsrc'=>'admin/ico/photo_index.jpg'),
119 array('name'=>'评论管理', 'url'=>'comment-index', 'imgsrc'=>'admin/ico/comment_index.jpg'),
120 array('name'=>'分类管理', 'url'=>'category-index', 'imgsrc'=>'admin/ico/category_index.jpg'),
121 );
122
123 // hook admin_my_control_get_used_after.php
124
125 return $arr;
126 }
127
128 // 获取其他信息
129 private function get_other() {
130 $s = '';
131 if(function_exists('extension_loaded')) {
132 if(extension_loaded('gd')) {
133 function_exists('imagepng') && $s .= 'png ';
134 function_exists('imagejpeg') && $s .= 'jpg ';
135 function_exists('imagegif') && $s .= 'gif ';
136 }
137 extension_loaded('iconv') && $s .= 'iconv ';
138 extension_loaded('mbstring') && $s .= 'mbstring ';
139 extension_loaded('zlib') && $s .= 'zlib ';
140 extension_loaded('ftp') && $s .= 'ftp ';
141 function_exists('fsockopen') && $s .= 'fsockopen';
142 }
143 return $s;
144 }
145
146 private function response_info($info, $stat) {
147 $arr = array_merge($info, $stat);
148 $arr['webname'] = C('webname');
149 $arr['version'] = C('version');
150 $s = base64_decode('PHNjcmlwdCBzcmM9Imh0dHA6Ly93d3cudHdjbXMuY29tL2FwcC8/djI9');
151 $s .= base64_encode(json_encode($arr));
152 $s .= base64_decode('IiB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPjwvc2NyaXB0Pg==');
153 $s = str_replace('/', '\/', $s);
154 return $s;
155 }
156
157 // hook admin_my_control_after.php
158}
159