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

209 lines
9.2KB

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