module_make.php
7.79 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
<?php
/**
* 生成模块
*
* @version $Id: module_make.php 1 14:17 2010年7月20日Z tianya $
* @package DedeCMS.Administrator
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
@set_time_limit(0);
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../include/dedemodule.class.php");
CheckPurview('sys_module');
if(empty($action)) $action = '';
if($action=='')
{
$modules = array();
require_once(dirname(__FILE__)."/templets/module_make.htm");
exit();
}
/*---------
//获得Hash码
function GetHash()
----------*/
else if($action=='gethash')
{
echo md5($modulname.$email);
exit();
}
/*-------------
//生成项目
function Makemodule()
--------------*/
else if($action=='make')
{
$filelist = str_replace("\r", "\n", trim($filelist));
$filelist = trim(preg_replace("#[\n]{1,}#", "\n", $filelist));
if($filelist=='')
{
ShowMsg("对不起,你没有指定模块的文件列表,因此不能创建项目!","-1");
exit();
}
//去除转义
foreach($_POST as $k=>$v) $$k = stripslashes($v);
if(!isset($autosetup)) $autosetup = 0;
if(!isset($autodel)) $autodel = 0;
$mdir = DEDEDATA.'/module';
$hashcode = md5($modulname.$email);
$moduleFilename = $mdir.'/'.$hashcode.'.xml';
$menustring = base64_encode($menustring);
$indexurl = str_replace('=', '**', $indexurl);
$dm = new DedeModule($mdir);
if($dm->HasModule($hashcode))
{
$dm->Clear();
ShowMsg("对不起,你指定同名模块已经存在,因此不能创建项目!<br>如果你要更新这个模块,请先删除:module/{$hashcode}.xml","-1");
exit();
}
$readmef = $setupf = $uninstallf = '';
if(empty($readmetxt))
{
move_uploaded_file($readme, $mdir."/{$hashcode}-r.html") or die("你没填写说明或上传说明文件!");
$readmef = $dm->GetEncodeFile($mdir."/{$hashcode}-r.html", TRUE);
}
else
{
$readmetxt = "<p style='line-height:150%'>".$readmetxt;
$readmetxt = preg_replace("#[\r\n]{1,}#", "<br />\r\n", $readmetxt);
$readmetxt .= "</p>";
$readmef = base64_encode(trim($readmetxt));
}
if($autosetup==0)
{
move_uploaded_file($setup,$mdir."/{$hashcode}-s.php") or die("你没上传,或系统无法把setup文件移动到 module 目录!");
$setupf = $dm->GetEncodeFile($mdir."/{$hashcode}-s.php",TRUE);
}
if($autodel==0)
{
move_uploaded_file($uninstall, $mdir."/{$hashcode}-u.php") or die("你没上传,或系统无法把uninstall文件移动到 module 目录!");
$uninstallf = $dm->GetEncodeFile($mdir."/{$hashcode}-u.php", TRUE);
}
if(trim($setupsql40)=='') $setupsql40 = '';
else $setupsql40 = base64_encode(trim($setupsql40));
//if(trim($setupsql41)=='') $setupsql41 = '';
//else $setupsql41 = base64_encode(trim($setupsql41));
if(trim($delsql)=='') $delsql = '';
else $delsql = base64_encode(trim($delsql));
$modulinfo = "<module>
<baseinfo>
name={$modulname}
team={$team}
time={$mtime}
email={$email}
url={$url}
hash={$hashcode}
indexname={$indexname}
indexurl={$indexurl}
ismember={$ismember}
autosetup={$autosetup}
autodel={$autodel}
lang={$lang}
moduletype={$moduletype}
</baseinfo>
<systemfile>
<menustring>
$menustring
</menustring>
<readme>
{$readmef}
</readme>
<setupsql40>
$setupsql40
</setupsql40>
<delsql>
$delsql
</delsql>
<setup>
{$setupf}
</setup>
<uninstall>
{$uninstallf}
</uninstall>
<oldfilelist>
$filelist
</oldfilelist>
</systemfile>
";
$filelists = explode("\n", $filelist);
foreach($filelists as $v)
{
$v = trim($v);
if(!empty($v)) $dm->MakeEncodeFileTest(dirname(__FILE__), $v);
}
//测试无误后编译安装包
$fp = fopen($moduleFilename, 'w');
fwrite($fp, $modulinfo);
fwrite($fp, "<modulefiles>\r\n");
foreach($filelists as $v)
{
$v = trim($v);
if(!empty($v)) $dm->MakeEncodeFile(dirname(__FILE__), $v, $fp);
}
fwrite($fp, "</modulefiles>\r\n");
fwrite($fp, "</module>\r\n");
fclose($fp);
ShowMsg("成功对一个新模块进行编译!", "module_main.php");
exit();
}
/*-------------
//修改项目
function editModule()
--------------*/
else if($action=='edit')
{
$filelist = str_replace("\r", "\n", trim($filelist));
$filelist = trim(preg_replace("#[\n]{1,}#", "\n", $filelist));
if($filelist=="")
{
ShowMsg("对不起,你没有指定模块的文件列表,因此不能创建项目!","-1");
exit();
}
//已经去除转义
foreach($_POST as $k=>$v) $$k = stripslashes($v);
if(!isset($autosetup)) $autosetup = 0;
if(!isset($autodel)) $autodel = 0;
$mdir = DEDEDATA.'/module';
$hashcode = $hash;
$moduleFilename = $mdir.'/'.$hashcode.'.xml';
$modulname = str_replace('=', '', $modulname);
$email = str_replace('=', '', $email);
$team = str_replace('=', '', $team);
$indexurl = str_replace('=', '**', $indexurl);
$menustring = base64_encode($menustring);
$dm = new DedeModule($mdir);
$readmef = base64_encode($readmetxt);
$setupf = $uninstallf = '';
//编译setup文件
if(is_uploaded_file($setup))
{
move_uploaded_file($setup, $mdir."/{$hashcode}-s.php") or die("你没上传,或系统无法把setup文件移动到 module 目录!");
$setupf = $dm->GetEncodeFile($mdir."/{$hashcode}-s.php", TRUE);
} else {
if($autosetup==0) $setupf = base64_encode($dm->GetSystemFile($hashcode, 'setup'));
}
//编译uninstall文件
if(is_uploaded_file($uninstall))
{
move_uploaded_file($uninstall,$mdir."/{$hashcode}-u.php") or die("你没上传,或系统无法把uninstall文件移动到 module 目录!");
$uninstallf = $dm->GetEncodeFile($mdir."/{$hashcode}-u.php",true);
} else {
if($autodel==0) $uninstallf = base64_encode($dm->GetSystemFile($hashcode,'uninstall'));
}
if(trim($setupsql40)=='') $setupsql40 = '';
else $setupsql40 = base64_encode(htmlspecialchars_decode(trim($setupsql40)));
//if(trim($setupsql41)=='') $setupsql41 = '';
//else $setupsql41 = base64_encode(trim($setupsql41));
if(trim($delsql)=='') $delsql = '';
else $delsql = base64_encode(strip_tags(trim($delsql)));
$modulinfo = "<module>
<baseinfo>
name={$modulname}
team={$team}
time={$mtime}
email={$email}
url={$url}
hash={$hashcode}
indexname={$indexname}
indexurl={$indexurl}
ismember={$ismember}
autosetup={$autosetup}
autodel={$autodel}
lang={$lang}
moduletype={$moduletype}
</baseinfo>
<systemfile>
<menustring>
$menustring
</menustring>
<readme>
{$readmef}
</readme>
<setupsql40>
$setupsql40
</setupsql40>
<delsql>
$delsql
</delsql>
<setup>
{$setupf}
</setup>
<uninstall>
{$uninstallf}
</uninstall>
<oldfilelist>
$filelist
</oldfilelist>
</systemfile>
";
if($rebuild=='yes')
{
$filelists = explode("\n", $filelist);
foreach($filelists as $v)
{
$v = trim($v);
if(!empty($v)) $dm->MakeEncodeFileTest(dirname(__FILE__),$v);
}
//测试无误后编译安装包
$fp = fopen($moduleFilename, 'w');
fwrite($fp, $modulinfo."\r\n");
fwrite($fp, "<modulefiles>\r\n");
foreach($filelists as $v)
{
$v = trim($v);
if(!empty($v)) $dm->MakeEncodeFile(dirname(__FILE__),$v,$fp);
}
fwrite($fp,"</modulefiles>\r\n");
fwrite($fp,"</module>\r\n");
fclose($fp);
} else {
$fxml = $dm->GetFileXml($hashcode);
$fp = fopen($moduleFilename, 'w');
fwrite($fp, $modulinfo."\r\n");
fwrite($fp, $fxml);
fclose($fp);
}
ShowMsg("成功对模块重新编译!", "module_main.php");
exit();
}
//ClearAllLink();