国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

357 行
21KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 后台栏目管理
  5. *
  6. * @version $id:typeunit.class.admin.php 15:21 2010年7月5日 tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC."/channelunit.func.php");
  13. class TypeUnit
  14. {
  15. var $dsql;
  16. var $artDir;
  17. var $baseDir;
  18. var $idCounter;
  19. var $idArrary;
  20. var $shortName;
  21. var $CatalogNums;
  22. //php5构造函数
  23. function __construct()
  24. {
  25. $this->idCounter = 0;
  26. $this->artDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
  27. $this->baseDir = $GLOBALS['cfg_basedir'];
  28. $this->shortName = $GLOBALS['art_shortname'];
  29. $this->idArrary = '';
  30. $this->dsql = 0;
  31. }
  32. function TypeUnit()
  33. {
  34. $this->__construct();
  35. }
  36. //清理类
  37. function Close()
  38. {
  39. }
  40. //获取所有栏目的文档id数
  41. function UpdateCatalogNum()
  42. {
  43. $this->dsql->SetQuery("SELECT typeid,count(typeid) as dd FROM `#@__arctiny` WHERE arcrank <>-3 GROUP BY typeid");
  44. $this->dsql->Execute();
  45. while ($row = $this->dsql->GetArray()) {
  46. $this->CatalogNums[$row['typeid']] = $row['dd'];
  47. }
  48. }
  49. function GetTotalArc($tid)
  50. {
  51. if (!is_array($this->CatalogNums)) {
  52. $this->UpdateCatalogNum();
  53. }
  54. if (!isset($this->CatalogNums[$tid])) {
  55. return 0;
  56. } else {
  57. $totalnum = 0;
  58. $ids = explode(',', GetSonIds($tid));
  59. foreach ($ids as $tid) {
  60. if (isset($this->CatalogNums[$tid])) {
  61. $totalnum += $this->CatalogNums[$tid];
  62. }
  63. }
  64. return $totalnum;
  65. }
  66. }
  67. /**
  68. * 读出所有分类,在栏目管理页list_type中使用
  69. *
  70. * @access public
  71. * @param int $channel 栏目id
  72. * @param int $nowdir 当前操作ID
  73. * @return string
  74. */
  75. function ListAllType($channel = 0, $nowdir = 0)
  76. {
  77. global $cfg_admin_channel, $admin_catalogs;
  78. $this->dsql = $GLOBALS['dsql'];
  79. //检测会员有权限的顶级栏目
  80. if ($cfg_admin_channel == 'array') {
  81. $admin_catalog = join(',', $admin_catalogs);
  82. $this->dsql->SetQuery("SELECT reid FROM `#@__arctype` WHERE id in($admin_catalog) GROUP BY reid ");
  83. $this->dsql->Execute();
  84. $topidstr = '';
  85. while ($row = $this->dsql->GetObject()) {
  86. if ($row->reid == 0) continue;
  87. $topidstr .= ($topidstr == '' ? $row->reid : ','.$row->reid);
  88. }
  89. $admin_catalog .= ','.$topidstr;
  90. $admin_catalogs = explode(',', $admin_catalog);
  91. $admin_catalogs = array_unique($admin_catalogs);
  92. }
  93. $this->dsql->SetQuery("SELECT id,typedir,typename,ispart,sortrank,ishidden,apienabled FROM `#@__arctype` WHERE reid=0 ORDER BY sortrank");
  94. $this->dsql->Execute(0);
  95. $i = 0;
  96. while ($row = $this->dsql->GetObject(0)) {
  97. if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
  98. continue;
  99. }
  100. $typeDir = $row->typedir;
  101. $typeName = $row->typename;
  102. $ispart = $row->ispart;
  103. $id = $row->id;
  104. $rank = $row->sortrank;
  105. if ($row->ishidden == '1') {
  106. $nss = "<span class='btn btn-secondary btn-xs'>隐藏</span>";
  107. } else {
  108. $nss = '';
  109. }
  110. echo "<table width='100%' cellspacing='0' cellpadding='2'>";
  111. if ($ispart == 0) {
  112. //列表栏目
  113. echo "<tr>";
  114. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-success btn-xs'>列表</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."](文档数:".$this->GetTotalArc($id).")";
  115. echo "</td>";
  116. echo "<td align='right'><a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  117. $apidisabled = $row->apienabled == 1? '' : ' disabled';
  118. echo "<a href='catalog_do.php?dopost=viewAPI&typeid={$id}' target='_blank' title='接口' class='btn btn-light btn-sm{$apidisabled}'><i class='fa fa-bolt'></i></a>";
  119. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
  120. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  121. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  122. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  123. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  124. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  125. } else if ($ispart == 1) {
  126. //封面栏目
  127. echo "<tr>";
  128. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-warning btn-xs'>封面</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."]";
  129. echo "</td>";
  130. echo "<td align='right'><a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  131. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
  132. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  133. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  134. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  135. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  136. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  137. } else if ($ispart == 2) {
  138. //外部栏目
  139. echo "<tr>";
  140. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-primary btn-xs'>外部</span>{$nss}<a href='catalog_edit.php?id=".$id."' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."]";
  141. echo "</td>";
  142. echo "<td align='right'><a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  143. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  144. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  145. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  146. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  147. }
  148. echo "<tr><td colspan='2' id='suns".$id."' class='p-0'>";
  149. $lastid = GetCookie('lastCid');
  150. if ($channel == $id || $lastid == $id || isset($GLOBALS['exallct']) || $cfg_admin_channel == 'array') {
  151. echo "<table width='100%' cellspacing='0' cellpadding='0'>";
  152. $this->LogicListAllSunType($id, " ");
  153. echo "</table>";
  154. }
  155. echo "</td></tr></table>";
  156. $i++;
  157. } if ($i === 0) {
  158. echo "<div class='text-center py-2'>暂无栏目,请添加栏目</div>";
  159. }
  160. }
  161. /**
  162. * 获得子栏目的递归调用
  163. *
  164. * @access public
  165. * @param int $id 栏目id
  166. * @param string $step 层级标志
  167. * @return void
  168. */
  169. function LogicListAllSunType($id, $step)
  170. {
  171. global $cfg_admin_channel, $admin_catalogs;
  172. $fid = $id;
  173. $this->dsql->SetQuery("SELECT id,reid,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid='".$id."' ORDER BY sortrank");
  174. $this->dsql->Execute($fid);
  175. if ($this->dsql->GetTotalRow($fid) > 0) {
  176. while ($row = $this->dsql->GetObject($fid)) {
  177. if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
  178. continue;
  179. }
  180. $typeDir = $row->typedir;
  181. $typeName = $row->typename;
  182. $reid = $row->reid;
  183. $id = $row->id;
  184. $ispart = $row->ispart;
  185. if ($step == " ") {
  186. $stepdd = 2;
  187. } else {
  188. $stepdd = 3;
  189. }
  190. $rank = $row->sortrank;
  191. if ($row->ishidden == '1') {
  192. $nss = "<span class='btn btn-secondary btn-xs'>隐藏</span>";
  193. } else {
  194. $nss = '';
  195. } if ($ispart == 0) {
  196. //列表栏目
  197. echo "<tr>";
  198. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  199. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-success btn-xs'>列表</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."](文档数:".$this->GetTotalArc($id).")";
  200. echo "</td>";
  201. echo "<td align='right'><a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  202. $apidisabled = $row->apienabled == 1? '' : ' disabled';
  203. echo "<a href='catalog_do.php?dopost=viewAPI&typeid={$id}' target='_blank' title='接口' class='btn btn-light btn-sm{$apidisabled}'><i class='fa fa-bolt'></i></a>";
  204. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
  205. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  206. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  207. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  208. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  209. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  210. } else if ($ispart == 1) {
  211. //封面栏目
  212. echo "<tr>";
  213. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  214. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-warning btn-xs'>封面</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."]";
  215. echo "</td>";
  216. echo "<td align='right'><a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  217. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
  218. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  219. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  220. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  221. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  222. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  223. } else if ($ispart == 2) {
  224. //外部栏目
  225. echo "<tr>";
  226. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  227. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></i><input type='checkbox' name='tids[]' value='{$id}' class='mr-3 ml-3'><span class='btn btn-primary btn-xs'>外部</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives' class='mr-3 ml-3'>".$typeName."</a>[id:".$id."]";
  228. echo "</td>";
  229. echo "<td align='right'><a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  230. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  231. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动' class='btn btn-light btn-sm'><i class='fa fa-share-square'></i></a>";
  232. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
  233. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  234. }
  235. echo "<tr><td id='suns".$id."' style='".($GLOBALS['exallct']? "" : "display:none")."'><table width='100%' cellspacing='0' cellpadding='0'>";
  236. $this->LogicListAllSunType($id, $step." ");
  237. echo "</table></td></tr>";
  238. }
  239. }
  240. }
  241. /**
  242. * 返回某个相关下级目录的栏目id列表删除栏目或文档时调用
  243. *
  244. * @access public
  245. * @param int $id 栏目id
  246. * @param int $channel 栏目id
  247. * @return array
  248. */
  249. function GetSunTypes($id, $channel = 0)
  250. {
  251. $this->dsql = $GLOBALS['dsql'];
  252. $this->idArray[$this->idCounter] = $id;
  253. $this->idCounter++;
  254. $fid = $id;
  255. if ($channel != 0) {
  256. $csql = " And channeltype=$channel ";
  257. } else {
  258. $csql = "";
  259. }
  260. $this->dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid=$id $csql");
  261. $this->dsql->Execute("gs".$fid);
  262. while ($row = $this->dsql->GetObject("gs".$fid)) {
  263. $nid = $row->id;
  264. $this->GetSunTypes($nid, $channel);
  265. }
  266. return $this->idArray;
  267. }
  268. /**
  269. * 删除栏目
  270. *
  271. * @access public
  272. * @param int $id 栏目id
  273. * @param bool $isDelFile 是否删除文件
  274. * @return string
  275. */
  276. function DelType($id, $isDelFile)
  277. {
  278. $this->idCounter = 0;
  279. $this->idArray = array();
  280. $this->GetSunTypes($id);
  281. $query = "SELECT `#@__arctype`.*,`#@__channeltype`.typename AS ctypename, `#@__channeltype`.addtable FROM `#@__arctype` LEFT JOIN `#@__channeltype` ON `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$id' ";
  282. $typeinfos = $this->dsql->GetOne($query);
  283. $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
  284. if (!is_array($typeinfos)) {
  285. return FALSE;
  286. }
  287. $indir = $typeinfos['typedir'];
  288. $addtable = $typeinfos['addtable'];
  289. $ispart = $typeinfos['ispart'];
  290. $defaultname = $typeinfos['defaultname'];
  291. //删除数据库里的相关记录
  292. foreach ($this->idArray as $id) {
  293. $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
  294. if ($myrow['topid'] > 0) {
  295. $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
  296. if (is_array($mytoprow) && !empty($mytoprow)) {
  297. foreach ($mytoprow as $k => $v) {
  298. if (!preg_match("/[0-9]/", $k)) {
  299. $myrow[$k] = $v;
  300. }
  301. }
  302. }
  303. }
  304. //删除单独页面,删除目录和目录里的所有文件,禁止了此功能
  305. if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
  306. if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
  307. @unlink($this->baseDir.'/'.$myrow['defaultname']);
  308. }
  309. }
  310. //删除数据库信息
  311. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
  312. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
  313. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
  314. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
  315. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
  316. if ($addtable != "") {
  317. $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
  318. }
  319. }
  320. //删除单独页面,删除目录和目录里的所有文件,禁止了此功能
  321. if ($ispart == 2 && $indir == "") {
  322. if (is_file($this->baseDir."/".$defaultname)) {
  323. @unlink($this->baseDir."/".$defaultname);
  324. }
  325. }
  326. @reset($this->idArray);
  327. $this->idCounter = 0;
  328. return TRUE;
  329. }
  330. /**
  331. * 删除指定目录的所有文件
  332. *
  333. * @access public
  334. * @param string $indir 指定目录
  335. * @return int
  336. */
  337. function RmDirFile($indir)
  338. {
  339. if (!file_exists($indir)) return;
  340. $dh = dir($indir);
  341. while ($file = $dh->read()) {
  342. if ($file == "." || $file == "..") {
  343. continue;
  344. } else if (is_file("$indir/$file")) {
  345. @unlink("$indir/$file");
  346. } else {
  347. $this->RmDirFile("$indir/$file");
  348. }
  349. if (is_dir("$indir/$file")) {
  350. @rmdir("$indir/$file");
  351. }
  352. }
  353. $dh->close();
  354. return (1);
  355. }
  356. }//End Class
  357. ?>