catalog_add.php
9.19 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
<?php
/**
* 栏目添加
*
* @version $Id: catalog_add.php 1 14:31 2010年7月12日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
*/
require_once(dirname(__FILE__)."/config.php");
require_once(DEDEINC."/typelink.class.php");
if(empty($listtype)) $listtype='';
if(empty($dopost)) $dopost = '';
if(empty($upinyin)) $upinyin = 0;
if(empty($channelid)) $channelid = 1;
if(isset($channeltype)) $channelid = $channeltype;
$id = empty($id) ? 0 :intval($id);
$reid = empty($reid) ? 0 :intval($reid);
$nid = 'article';
if($id==0 && $reid==0)
{
CheckPurview('t_New');
}
else
{
$checkID = empty($id) ? $reid : $id;
CheckPurview('t_AccNew');
CheckCatalog($checkID, '你无权在本栏目下创建子类!');
}
if(empty($myrow)) $myrow = array();
$dsql->SetQuery("SELECT id,typename,nid FROM `#@__channeltype` WHERE id<>-1 AND isshow=1 ORDER BY id");
$dsql->Execute();
while($row=$dsql->GetObject())
{
$channelArray[$row->id]['typename'] = $row->typename;
$channelArray[$row->id]['nid'] = $row->nid;
if($row->id==$channelid)
{
$nid = $row->nid;
}
}
if($dopost=='quick')
{
$tl = new TypeLink(0);
$typeOptions = $tl->GetOptionArray(0,0,$channelid);
include DedeInclude('templets/catalog_add_quick.htm');
exit();
}
/*---------------------
function action_savequick(){ }
---------------------*/
else if($dopost=='savequick')
{
if(!isset($savetype)) $savetype = '';
$isdefault = isset($isdefault)? $isdefault : 0;
$tempindex = "{style}/index_{$nid}.htm";
$templist = "{style}/list_{$nid}.htm";
$temparticle = "{style}/article_{$nid}.htm";
$queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`)
VALUES('~reid~','~topid~','~rank~','~typename~','~typedir~','$isdefault','$defaultname','$issend','$channeltype',
'$tempindex','$templist','$temparticle','default','$namerule','$namerule2','0','0','','','~typename~','0','','','0','0','0','','')";
if (empty($savetype))
{
foreach($_POST as $k=>$v)
{
if(preg_match("#^posttype#", $k))
{
$k = str_replace('posttype', '', $k);
}
else
{
continue;
}
$rank = ${'rank'.$k};
$toptypename = trim(${'toptype'.$k});
$sontype = trim(${'sontype'.$k});
$toptypedir = GetPinyin(stripslashes($toptypename));
$toptypedir = $referpath=='parent' ? $nextdir.'/'.$toptypedir : '/'.$toptypedir;
if(empty($toptypename))
{
continue;
}
$sql = str_replace('~reid~','0',$queryTemplate);
$sql = str_replace('~topid~','0',$sql);
$sql = str_replace('~rank~',$rank,$sql);
$sql = str_replace('~typename~',$toptypename,$sql);
$sql = str_replace('~typedir~',$toptypedir,$sql);
$dsql->ExecuteNoneQuery($sql);
$tid = $dsql->GetLastID();
if($tid>0 && $sontype!='')
{
$sontypes = explode(',',$sontype);
foreach($sontypes as $k=>$v)
{
$v = trim($v);
if($v=='')
{
continue;
}
$typedir = $toptypedir.'/'.GetPinyin(stripslashes($v));
$sql = str_replace('~reid~',$tid,$queryTemplate);
$sql = str_replace('~topid~',$tid,$sql);
$sql = str_replace('~rank~',$k,$sql);
$sql = str_replace('~typename~',$v,$sql);
$sql = str_replace('~typedir~',$typedir,$sql);
$dsql->ExecuteNoneQuery($sql);
}
}
}
} else {
$row = $dsql->GetOne("SELECT `typedir` FROM `#@__arctype` WHERE `id`={$reid}");
foreach($_POST as $k=>$v)
{
if(preg_match("#^posttype#", $k))
{
$k = str_replace('posttype', '', $k);
}
else
{
continue;
}
$rank = ${'rank'.$k};
$toptypename = trim(${'reltype'.$k});
$toptypedir = GetPinyin(stripslashes($toptypename));
switch ($referpath) {
case 'parent':
$toptypedir = $nextdir.'/'.$toptypedir;
break;
case 'typepath':
$toptypedir = isset($row['typedir'])? $row['typedir'].'/'.$toptypedir : '/'.$toptypedir;
break;
default:
$toptypedir = '/'.$toptypedir;
break;
}
if(empty($toptypename))
{
continue;
}
$sql = str_replace('~reid~', $reid, $queryTemplate);
$sql = str_replace('~topid~', $reid, $sql);
$sql = str_replace('~rank~', $rank, $sql);
$sql = str_replace('~typename~', $toptypename, $sql);
$sql = str_replace('~typedir~', $toptypedir, $sql);
$dsql->ExecuteNoneQuery($sql);
}
}
UpDateCatCache();
ShowMsg('成功增加指定栏目!','catalog_main.php');
exit();
}
/*---------------------
function action_save(){ }
---------------------*/
else if($dopost=='save')
{
$smalltypes = '';
if(empty($smalltype)) $smalltype = '';
if(is_array($smalltype)) $smalltypes = join(',',$smalltype);
if(!isset($sitepath)) $sitepath = '';
if($topid==0 && $reid>0) $topid = $reid;
if($ispart!=0) $cross = 0;
$description = Html2Text($description,1);
$keywords = Html2Text($keywords,1);
if($ispart != 2 )
{
//栏目的参照目录
if($referpath=='cmspath') $nextdir = '{cmspath}';
if($referpath=='basepath') $nextdir = '';
//用拼音命名
if($upinyin==1 || $typedir=='')
{
$typedir = GetPinyin(stripslashes($typename));
}
$typedir = $nextdir.'/'.$typedir;
$typedir = preg_replace("#\/{1,}#", "/", $typedir);
}
//开启多站点时的设置(仅针对顶级栏目)
if($reid==0 && $moresite==1)
{
$sitepath = $typedir;
//检测二级网址
if($siteurl!='')
{
$siteurl = preg_replace("#\/$#", "", $siteurl);
if(!preg_match("#http:\/\/#i", $siteurl))
{
ShowMsg("你绑定的二级域名无效,请用(http://host)的形式!","-1");
exit();
}
if(preg_match("#".$cfg_basehost."#i", $siteurl))
{
ShowMsg("你绑定的二级域名与当前站点是同一个域,不需要绑定!","-1");
exit();
}
}
}
//创建目录
if($ispart != 2)
{
$true_typedir = str_replace("{cmspath}", $cfg_cmspath, $typedir);
$true_typedir = preg_replace("#\/{1,}#", "/", $true_typedir);
if(!CreateDir($true_typedir))
{
ShowMsg("创建目录 {$true_typedir} 失败,请检查你的路径是否存在问题!","-1");
exit();
}
}
$in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
tempindex,templist,temparticle,modname,namerule,namerule2,
ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`)
VALUES('$reid','$topid','$sortrank','$typename','$typedir','$isdefault','$defaultname','$issend','$channeltype',
'$tempindex','$templist','$temparticle','default','$namerule','$namerule2',
'$ispart','$corank','$description','$keywords','$seotitle','$moresite','$siteurl','$sitepath','$ishidden','$cross','$crossid','$content','$smalltypes')";
if(!$dsql->ExecuteNoneQuery($in_query))
{
ShowMsg("保存目录数据时失败,请检查你的输入资料是否存在问题!","-1");
exit();
}
UpDateCatCache();
if($reid>0)
{
PutCookie('lastCid',GetTopid($reid),3600*24,'/');
}
ShowMsg("成功创建一个分类!","catalog_main.php");
exit();
}//End dopost==save
//获取从父目录继承的默认参数
if($dopost=='')
{
$channelid = 1;
$issend = 1;
$corank = 0;
$reid = 0;
$topid = 0;
$typedir = '';
$moresite = 0;
if($id>0)
{
$myrow = $dsql->GetOne(" SELECT tp.*,ch.typename AS ctypename FROM `#@__arctype` tp LEFT JOIN `#@__channeltype` ch ON ch.id=tp.channeltype WHERE tp.id=$id ");
$channelid = $myrow['channeltype'];
$issennd = $myrow['issend'];
$corank = $myrow['corank'];
$topid = $myrow['topid'];
$typedir = $myrow['typedir'];
}
//父栏目是否为二级站点
$moresite = empty($myrow['moresite']) ? 0 : $myrow['moresite'];
}
include DedeInclude('templets/catalog_add.htm');