国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
9.5KB

  1. <?php
  2. /**
  3. * 栏目添加
  4. *
  5. * @version $Id: catalog_add.php 1 14:31 2010年7月12日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2007 - 2019, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. require_once(DEDEINC."/typelink.class.php");
  13. if(empty($listtype)) $listtype='';
  14. if(empty($dopost)) $dopost = '';
  15. if(empty($upinyin)) $upinyin = 0;
  16. if(empty($channelid)) $channelid = 1;
  17. if(isset($channeltype)) $channelid = $channeltype;
  18. $id = empty($id) ? 0 :intval($id);
  19. $reid = empty($reid) ? 0 :intval($reid);
  20. $nid = 'article';
  21. if($id==0 && $reid==0)
  22. {
  23. CheckPurview('t_New');
  24. }
  25. else
  26. {
  27. $checkID = empty($id) ? $reid : $id;
  28. CheckPurview('t_AccNew');
  29. CheckCatalog($checkID, '你无权在本栏目下创建子类!');
  30. }
  31. if(empty($myrow)) $myrow = array();
  32. $dsql->SetQuery("SELECT id,typename,nid FROM `#@__channeltype` WHERE id<>-1 AND isshow=1 ORDER BY id");
  33. $dsql->Execute();
  34. while($row=$dsql->GetObject())
  35. {
  36. $channelArray[$row->id]['typename'] = $row->typename;
  37. $channelArray[$row->id]['nid'] = $row->nid;
  38. if($row->id==$channelid)
  39. {
  40. $nid = $row->nid;
  41. }
  42. }
  43. if($dopost=='quick')
  44. {
  45. $tl = new TypeLink(0);
  46. $typeOptions = $tl->GetOptionArray(0,0,$channelid);
  47. include DedeInclude('templets/catalog_add_quick.htm');
  48. exit();
  49. }
  50. /*---------------------
  51. function action_savequick(){ }
  52. ---------------------*/
  53. else if($dopost=='savequick')
  54. {
  55. if(!isset($savetype)) $savetype = '';
  56. $isdefault = isset($isdefault)? $isdefault : 0;
  57. $tempindex = "{style}/index_{$nid}.htm";
  58. $templist = "{style}/list_{$nid}.htm";
  59. $temparticle = "{style}/article_{$nid}.htm";
  60. $queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
  61. tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`)
  62. VALUES('~reid~','~topid~','~rank~','~typename~','~typedir~','$isdefault','$defaultname','$issend','$channeltype',
  63. '$tempindex','$templist','$temparticle','default','$namerule','$namerule2','0','0','','','~typename~','0','','','0','0','0','','')";
  64. if (empty($savetype))
  65. {
  66. foreach($_POST as $k=>$v)
  67. {
  68. if(preg_match("#^posttype#", $k))
  69. {
  70. $k = str_replace('posttype', '', $k);
  71. }
  72. else
  73. {
  74. continue;
  75. }
  76. $rank = ${'rank'.$k};
  77. $toptypename = trim(${'toptype'.$k});
  78. $sontype = trim(${'sontype'.$k});
  79. $toptypedir = GetPinyin(stripslashes($toptypename));
  80. $toptypedir = $referpath=='parent' ? $nextdir.'/'.$toptypedir : '/'.$toptypedir;
  81. if(empty($toptypename))
  82. {
  83. continue;
  84. }
  85. $sql = str_replace('~reid~','0',$queryTemplate);
  86. $sql = str_replace('~topid~','0',$sql);
  87. $sql = str_replace('~rank~',$rank,$sql);
  88. $sql = str_replace('~typename~',$toptypename,$sql);
  89. $sql = str_replace('~typedir~',$toptypedir,$sql);
  90. $dsql->ExecuteNoneQuery($sql);
  91. $tid = $dsql->GetLastID();
  92. if($tid>0 && $sontype!='')
  93. {
  94. $sontypes = explode(',',$sontype);
  95. foreach($sontypes as $k=>$v)
  96. {
  97. $v = trim($v);
  98. if($v=='')
  99. {
  100. continue;
  101. }
  102. $typedir = $toptypedir.'/'.GetPinyin(stripslashes($v));
  103. $sql = str_replace('~reid~',$tid,$queryTemplate);
  104. $sql = str_replace('~topid~',$tid,$sql);
  105. $sql = str_replace('~rank~',$k,$sql);
  106. $sql = str_replace('~typename~',$v,$sql);
  107. $sql = str_replace('~typedir~',$typedir,$sql);
  108. $dsql->ExecuteNoneQuery($sql);
  109. }
  110. }
  111. }
  112. } else {
  113. $row = $dsql->GetOne("SELECT `typedir` FROM `#@__arctype` WHERE `id`={$reid}");
  114. foreach($_POST as $k=>$v)
  115. {
  116. if(preg_match("#^posttype#", $k))
  117. {
  118. $k = str_replace('posttype', '', $k);
  119. }
  120. else
  121. {
  122. continue;
  123. }
  124. $rank = ${'rank'.$k};
  125. $toptypename = trim(${'reltype'.$k});
  126. $toptypedir = GetPinyin(stripslashes($toptypename));
  127. switch ($referpath) {
  128. case 'parent':
  129. $toptypedir = $nextdir.'/'.$toptypedir;
  130. break;
  131. case 'typepath':
  132. $toptypedir = isset($row['typedir'])? $row['typedir'].'/'.$toptypedir : '/'.$toptypedir;
  133. break;
  134. default:
  135. $toptypedir = '/'.$toptypedir;
  136. break;
  137. }
  138. if(empty($toptypename))
  139. {
  140. continue;
  141. }
  142. $sql = str_replace('~reid~', $reid, $queryTemplate);
  143. $sql = str_replace('~topid~', $reid, $sql);
  144. $sql = str_replace('~rank~', $rank, $sql);
  145. $sql = str_replace('~typename~', $toptypename, $sql);
  146. $sql = str_replace('~typedir~', $toptypedir, $sql);
  147. $dsql->ExecuteNoneQuery($sql);
  148. }
  149. }
  150. UpDateCatCache();
  151. ShowMsg('成功增加指定栏目!','catalog_main.php');
  152. exit();
  153. }
  154. /*---------------------
  155. function action_save(){ }
  156. ---------------------*/
  157. else if($dopost=='save')
  158. {
  159. $smalltypes = '';
  160. if(empty($smalltype)) $smalltype = '';
  161. if(is_array($smalltype)) $smalltypes = join(',',$smalltype);
  162. if(!isset($sitepath)) $sitepath = '';
  163. if($topid==0 && $reid>0) $topid = $reid;
  164. if($ispart!=0) $cross = 0;
  165. $description = Html2Text($description,1);
  166. $keywords = Html2Text($keywords,1);
  167. if($ispart != 2 )
  168. {
  169. //栏目的参照目录
  170. if($referpath=='cmspath') $nextdir = '{cmspath}';
  171. if($referpath=='basepath') $nextdir = '';
  172. //用拼音命名
  173. if($upinyin==1 || $typedir=='')
  174. {
  175. $typedir = GetPinyin(stripslashes($typename));
  176. }
  177. $typedir = $nextdir.'/'.$typedir;
  178. $typedir = preg_replace("#\/{1,}#", "/", $typedir);
  179. }
  180. //开启多站点时的设置(仅针对顶级栏目)
  181. if($reid==0 && $moresite==1)
  182. {
  183. $sitepath = $typedir;
  184. //检测二级网址
  185. if($siteurl!='')
  186. {
  187. $siteurl = preg_replace("#\/$#", "", $siteurl);
  188. if(!preg_match("#http:\/\/#i", $siteurl))
  189. {
  190. ShowMsg("你绑定的二级域名无效,请用(http://host)的形式!","-1");
  191. exit();
  192. }
  193. if(preg_match("#".$cfg_basehost."#i", $siteurl))
  194. {
  195. ShowMsg("你绑定的二级域名与当前站点是同一个域,不需要绑定!","-1");
  196. exit();
  197. }
  198. }
  199. }
  200. //创建目录
  201. if($ispart != 2)
  202. {
  203. $true_typedir = str_replace("{cmspath}", $cfg_cmspath, $typedir);
  204. $true_typedir = preg_replace("#\/{1,}#", "/", $true_typedir);
  205. if(!CreateDir($true_typedir))
  206. {
  207. ShowMsg("创建目录 {$true_typedir} 失败,请检查你的路径是否存在问题!","-1");
  208. exit();
  209. }
  210. }
  211. $in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
  212. tempindex,templist,temparticle,modname,namerule,namerule2,
  213. ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`)
  214. VALUES('$reid','$topid','$sortrank','$typename','$typedir','$isdefault','$defaultname','$issend','$channeltype',
  215. '$tempindex','$templist','$temparticle','default','$namerule','$namerule2',
  216. '$ispart','$corank','$description','$keywords','$seotitle','$moresite','$siteurl','$sitepath','$ishidden','$cross','$crossid','$content','$smalltypes')";
  217. if(!$dsql->ExecuteNoneQuery($in_query))
  218. {
  219. ShowMsg("保存目录数据时失败,请检查你的输入资料是否存在问题!","-1");
  220. exit();
  221. }
  222. UpDateCatCache();
  223. if($reid>0)
  224. {
  225. PutCookie('lastCid',GetTopid($reid),3600*24,'/');
  226. }
  227. ShowMsg("成功创建一个分类!","catalog_main.php");
  228. exit();
  229. }//End dopost==save
  230. //获取从父目录继承的默认参数
  231. if($dopost=='')
  232. {
  233. $channelid = 1;
  234. $issend = 1;
  235. $corank = 0;
  236. $reid = 0;
  237. $topid = 0;
  238. $typedir = '';
  239. $moresite = 0;
  240. if($id>0)
  241. {
  242. $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 ");
  243. $channelid = $myrow['channeltype'];
  244. $issennd = $myrow['issend'];
  245. $corank = $myrow['corank'];
  246. $topid = $myrow['topid'];
  247. $typedir = $myrow['typedir'];
  248. }
  249. //父栏目是否为二级站点
  250. $moresite = empty($myrow['moresite']) ? 0 : $myrow['moresite'];
  251. }
  252. include DedeInclude('templets/catalog_add.htm');