6
6
7
7
$ version =$ argv [1 ];
8
8
9
- echo <<<HTML
10
- <!DOCTYPE html>
11
- <html lang="zh-CN">
12
- <head>
13
- <meta charset="UTF-8" />
14
- <title>MiniCMS安装程序</title>
15
- <style>
16
- * {padding:0;margin:0;font-family:"Microsoft YaHei",Segoe UI,Tahoma,Arial,Verdana,sans-serif;}
17
- html,body { height:100%; }
18
- body {background:#f5f5f5; color:#2d2d2d; font-size:14px;}
19
- #main {position:absolute; left:50%; top:50%;}
20
- #mainbox {
21
- background-color: #fff;
22
- border: 1px solid #e5e5e5;
23
- -webkit-border-radius: 5px;
24
- -moz-border-radius: 5px;
25
- border-radius: 5px;
26
- -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
27
- -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
28
- box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
29
- padding:20px;
30
- margin-bottom:20px;
31
- }
32
- .btn {
33
- display: inline-block;
34
- padding: 4px 12px;
35
- margin-bottom: 0;
36
- font-size: 15px;
37
- line-height: 21px;
38
- color: #434848;
39
- text-align: center;
40
- text-shadow: 0 1px 1px rgba(255,255,255,0.75);
41
- vertical-align: middle;
42
- cursor: pointer;
43
- background-color: #f8f8f8;
44
- background-image: -moz-linear-gradient(top,#fff,#eee);
45
- background-image: -webkit-gradient(linear,0 0,0 100%,from(#fff),to(#eee));
46
- background-image: -webkit-linear-gradient(top,#fff,#eee);
47
- background-image: -o-linear-gradient(top,#fff,#eee);
48
- background-image: linear-gradient(to bottom,#fff,#eee);
49
- background-repeat: repeat-x;
50
- border: 1px solid #ccc;
51
- border-color: #eee #eee #c8c8c8;
52
- border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);
53
- border-bottom-color: #b3b3b3;
54
- -webkit-border-radius: 4px;
55
- -moz-border-radius: 4px;
56
- border-radius: 4px;
57
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffeeeeee',GradientType=0);
58
- filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
59
- -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
60
- -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
61
- box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
62
- }
63
- .btn-primary {
64
- color: #fff;
65
- text-shadow: 0 -1px 0 rgba(0,0,0,0.25);
66
- background-color: #0aaaf1;
67
- background-image: -moz-linear-gradient(top,#11b6ff,#09d);
68
- background-image: -webkit-gradient(linear,0 0,0 100%,from(#11b6ff),to(#09d));
69
- background-image: -webkit-linear-gradient(top,#11b6ff,#09d);
70
- background-image: -o-linear-gradient(top,#11b6ff,#09d);
71
- background-image: linear-gradient(to bottom,#11b6ff,#09d);
72
- background-repeat: repeat-x;
73
- border-color: #09d #09d #006491;
74
- border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);
75
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff11b6ff',endColorstr='#ff0099dd',GradientType=0);
76
- filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
77
- }
78
- .btn:hover, .btn:focus {
79
- color: #fff;
80
- background-color: #09d;
81
- text-decoration: none;
82
- background-position: 0 -15px;
83
- -webkit-transition: background-position .1s linear;
84
- -moz-transition: background-position .1s linear;
85
- -o-transition: background-position .1s linear;
86
- transition: background-position .1s linear;
87
- }
88
- label { font-weight:bold; color:#333; font-size:12px; }
89
- .textbox input { border:none; padding:0; font-size:18px; width:312px; color:#333; outline:0; }
90
- .textbox { border:1px solid #e0e0e0; padding:6px; margin:6px 0 20px; border-radius:3px 3px 3px 3px; }
91
- </style>
92
- <script type="text/javascript">
93
- function vMiddle(inner){
94
- var outer = (inner.parentNode.tagName == 'body') ? document.documentElement : inner.parentNode;
95
-
96
- var innerHeight = inner.offsetHeight,
97
- innerWidth = inner.offsetWidth,
98
- outerHeight = outer.offsetHeight ,
99
- outerWidth = outer.offsetWidth ;
100
-
101
- (outerHeight > innerHeight) ? (function(){
102
- inner.style.marginTop = -innerHeight/2 + "px" ;
103
- inner.style.top = "50%";
104
- })()
105
- : (function(){
106
- inner.style.marginTop = 0;
107
- inner.style.top = 0;
108
- })();
109
-
110
- (outerWidth > innerWidth) ? (function(){
111
- inner.style.marginLeft = -innerWidth/2 + "px" ;
112
- inner.style.left = "50%";
113
- })()
114
- : (function(){
115
- inner.style.marginLeft = 0;
116
- inner.style.left = 0;
117
- })();
118
- }
119
-
120
- window.onload = window.onresize = function(){
121
- vMiddle(document.getElementById("main"));
122
- }
123
- </script>
124
- </head>
125
- <body style="background:#f2f2f2;">
126
- <div id="main">
127
- <div style="font-size:32px;font-weight:bold;text-align:center;padding-top:40px;">MiniCMS安装程序</div>
128
- <div style="font-size:13px;color:#888;text-align:center;padding:10px 0 20px;">v {$ version }</div>
129
- <div id="mainbox">
130
- <?php if (!isset( \$_POST["start_install"])) { ?>
131
- <form method="post" action="<?php echo \$_SERVER['PHP_SELF']; ?>">
132
- <?php if (!is_file('mc-files/mc-conf.php')) { ?>
133
- <label>网站标题</label>
134
- <div class="textbox"><input type="text" name="sitename" value="我的网站"/></div>
135
- <label>网站地址</label>
136
- <div class="textbox"><input type="text" name="sitelink" id="sitelink" value=""/></div>
137
- <script type="text/javascript">
138
- document.getElementById('sitelink').value = location.href.substring(0, location.href.lastIndexOf('/'));
139
- </script>
140
- <label>您的昵称</label>
141
- <div class="textbox"><input type="text" name="nickname" value="神秘人"/></div>
142
- <label>后台账号</label>
143
- <div class="textbox"><input type="text" name="username" value="admin"/></div>
144
- <label>后台密码</label>
145
- <div class="textbox"><input type="text" name="password" value="123456"/></div>
146
- <div style="text-align:center;"><input type="submit" name="start_install" value="开始安装" class="btn btn-primary"/></div>
147
- <?php } else { ?>
148
- <div style="text-align:center;padding-bottom:20px;">检测到MiniCMS配置文件,将使用升级模式安装。</div>
149
- <div style="text-align:center;"><input type="submit" name="start_install" value="开始升级" class="btn btn-primary"/></div>
150
- <?php } ?>
151
- <form>
152
- <?php } ?>
153
- <?php
154
- \$install_failed=false;
155
-
156
- function install( \$file, \$content) {
157
- global \$install_failed;
158
-
159
- if ( \$install_failed)
160
- return;
161
-
162
- echo "解压 \$file";
163
-
164
- \$dir = dirname( \$file);
165
-
166
- if (is_dir( \$dir) || @mkdir( \$dir, 0744, true)) {
167
- if (!@file_put_contents( \$file, gzuncompress(base64_decode( \$content)))) {
168
- \$install_failed = true;
169
- echo '[<span style="color:red;">失败</span>]';
170
- }
171
- } else {
172
- \$install_failed = true;
173
- echo '[<span style="color:red;">无法创建目录</span>]';
174
- }
175
- echo '<br/>';
176
- }
177
-
178
- if (isset( \$_POST["start_install"])) {
179
- ?>
180
- <style> #main { min-width:400px; } </style>
181
- <div style="font-size:13px;color:#666;line-height:16px;padding:20px;margin:0 auto;">
182
- <?php
183
-
184
- HTML ;
185
-
186
- $ dirs = array (
187
- ". " ,
188
- );
9
+ $ dirs = array (". " );
189
10
190
11
$ ignores = array (
191
12
'README.md ' ,
192
13
'build.php ' ,
193
14
'install.php ' ,
15
+ 'install_template.txt ' ,
194
16
);
195
17
196
- build ( $ dirs ) ;
18
+ $ files = '' ;
197
19
198
- echo <<<HTML
199
- \$is_upgrade=true;
20
+ build ($ dirs , $ files );
200
21
201
- if (! \$install_failed) {
202
- if (!is_file('mc-files/mc-conf.php')) {
203
- \$is_upgrade = false;
204
- echo '<br/>';
205
- echo "创建配置文件";
206
- if (!@file_put_contents('mc-files/mc-conf.php',
207
- "<?php \\ \$mc_config = array(".
208
- "'version' => ' \$version',".
209
- "'site_link' => '{ \$_POST['sitelink']}',".
210
- "'site_name' => '{ \$_POST['sitename']}',".
211
- "'site_desc' => '又一个MiniCMS网站',".
212
- "'user_name' => '{ \$_POST['username']}',".
213
- "'user_pass' => '{ \$_POST['password']}',".
214
- "'user_nick' => '{ \$_POST['nickname']}',".
215
- "'comment_code' => '');?>"
216
- )) {
217
- \$install_failed = true;
218
- echo '[<span style="color:red;">失败</span>]';
219
- }
220
- echo '<br/>';
221
- }
22
+ $ template = file_get_contents ("install.txt " );
222
23
223
- if (!is_dir('mc-files/posts/index')) {
224
- echo '<br/>';
225
- echo "创建文章索引目录";
226
- if (@mkdir('mc-files/posts/index', 0744, true)) {
227
- echo '<br/>';
228
- echo "创建页面索引文件";
229
- if (
230
- !@file_put_contents('mc-files/posts/index/delete.php', '<?php \$mc_posts=array(); ?>') ||
231
- !@file_put_contents('mc-files/posts/index/publish.php', '<?php \$mc_posts=array(); ?>') ||
232
- !@file_put_contents('mc-files/posts/index/draft.php', '<?php \$mc_posts=array(); ?>')
233
- ) {
234
- \$install_failed = true;
235
- echo '[<span style="color:red;">失败</span>]';
236
- rmdir('mc-files/posts/index');
237
- }
238
- echo '<br/>';
239
- } else {
240
- \$install_failed = true;
241
- echo '[<span style="color:red;">失败</span>]';
242
- echo '<br/>';
243
- }
244
- }
24
+ $ template = str_replace ('/*MINICMS_VERSION*/ ' , $ version , $ template );
25
+ $ template = str_replace ('/*MINICMS_FILES*/ ' , $ files , $ template );
245
26
246
- if (!is_dir('mc-files/pages/index')) {
247
- echo '<br/>';
248
- echo "创建页面索引目录";
249
- if (@mkdir('mc-files/pages/index', 0744, true)) {
250
- echo '<br/>';
251
- echo "创建页面索引文件";
252
- if (
253
- !@file_put_contents('mc-files/pages/index/delete.php', '<?php \$mc_pages=array(); ?>') ||
254
- !@file_put_contents('mc-files/pages/index/publish.php', '<?php \$mc_pages=array(); ?>') ||
255
- !@file_put_contents('mc-files/pages/index/draft.php', '<?php \$mc_pages=array(); ?>')
256
- ) {
257
- \$install_failed = true;
258
- echo '[<span style="color:red;">失败</span>]';
259
- rmdir('mc-files/pages/index');
260
- }
261
- echo '<br/>';
262
- } else {
263
- \$install_failed = true;
264
- echo '[<span style="color:red;">失败</span>]';
265
- echo '<br/>';
266
- }
267
- }
268
- }
269
- ?>
270
- </div>
271
- <?php if ( \$install_failed) { ?>
272
- <div style="text-align:center;"><?php if ( \$is_upgrade) { ?>升级<?php } else { ?>安装<?php } ?>失败</div>
273
- <?php } else { ?>
274
- <div style="text-align:center;"><?php if ( \$is_upgrade) { ?>升级<?php } else { ?>安装<?php } ?>完毕</div>
275
- <?php if (!unlink(__FILE__)) { ?>
276
- <div style= \"text-align:center;padding-top:20px;color:red; \">安装文件无法删除,请手工删除。</div>
277
- <?php } ?>
278
- <div style="text-align:center;padding:20px 0 0;">
279
- <form method="get" action="mc-admin/">
280
- <input type="submit" value="开始体验" class="btn btn-primary"/>
281
- </form>
282
- </div>
283
- <?php } ?>
284
- <?php } ?>
285
- </div>
286
- </div>
287
- </body>
288
- </html>
289
- HTML ;
27
+ file_put_contents ("install.php " , $ template );
290
28
291
- function build ($ dirs ) {
29
+ function build ($ dirs, & $ files ) {
292
30
global $ ignores ;
293
31
294
32
foreach ($ dirs as $ dir ) {
@@ -314,13 +52,13 @@ function build($dirs) {
314
52
if (is_dir ($ file )) {
315
53
$ sub_dirs [] = $ file ;
316
54
} else {
317
- echo "install(' $ file', ' " ;
318
- echo base64_encode (gzcompress (file_get_contents ($ file )));
319
- echo "'); \n" ;
55
+ $ files .= "install(' $ file', ' " ;
56
+ $ files .= base64_encode (gzcompress (file_get_contents ($ file )));
57
+ $ files .= "'); \n" ;
320
58
}
321
59
}
322
60
closedir ($ dh );
323
- build ($ sub_dirs );
61
+ build ($ sub_dirs, $ files );
324
62
} else {
325
63
echo "目录 \"$ dir \"无法访问 " ;
326
64
exit ;
0 commit comments