国内流行的内容管理系统(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.

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