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

353 lines
20KB

  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 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. 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>";
  118. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  119. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  120. 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>";
  121. 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>";
  122. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  123. } else if ($ispart == 1) {
  124. //封面栏目
  125. echo "<tr>";
  126. 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."]";
  127. echo "</td>";
  128. 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>";
  129. 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>";
  130. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  131. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  132. 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>";
  133. 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>";
  134. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  135. } else if ($ispart == 2) {
  136. //外部栏目
  137. echo "<tr>";
  138. 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."]";
  139. echo "</td>";
  140. echo "<td align='right'><a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  141. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  142. 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>";
  143. 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>";
  144. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  145. }
  146. echo "<tr><td colspan='2' id='suns".$id."' class='p-0'>";
  147. $lastid = GetCookie('lastCid');
  148. if ($channel == $id || $lastid == $id || isset($GLOBALS['exallct']) || $cfg_admin_channel == 'array') {
  149. echo "<table width='100%' cellspacing='0' cellpadding='0'>";
  150. $this->LogicListAllSunType($id, " ");
  151. echo "</table>";
  152. }
  153. echo "</td></tr></table>";
  154. $i++;
  155. } if ($i === 0) {
  156. echo "<div class='text-center py-2'>暂无栏目,请添加栏目</div>";
  157. }
  158. }
  159. /**
  160. * 获得子栏目的递归调用
  161. *
  162. * @access public
  163. * @param int $id 栏目id
  164. * @param string $step 层级标志
  165. * @return void
  166. */
  167. function LogicListAllSunType($id, $step)
  168. {
  169. global $cfg_admin_channel, $admin_catalogs;
  170. $fid = $id;
  171. $this->dsql->SetQuery("SELECT id,reid,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid='".$id."' ORDER BY sortrank");
  172. $this->dsql->Execute($fid);
  173. if ($this->dsql->GetTotalRow($fid) > 0) {
  174. while ($row = $this->dsql->GetObject($fid)) {
  175. if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
  176. continue;
  177. }
  178. $typeDir = $row->typedir;
  179. $typeName = $row->typename;
  180. $reid = $row->reid;
  181. $id = $row->id;
  182. $ispart = $row->ispart;
  183. if ($step == " ") {
  184. $stepdd = 2;
  185. } else {
  186. $stepdd = 3;
  187. }
  188. $rank = $row->sortrank;
  189. if ($row->ishidden == '1') {
  190. $nss = "<span class='btn btn-secondary btn-xs'>隐藏</span>";
  191. } else {
  192. $nss = '';
  193. } if ($ispart == 0) {
  194. //列表栏目
  195. echo "<tr>";
  196. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  197. 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).")";
  198. echo "</td>";
  199. 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>";
  200. 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>";
  201. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  202. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  203. 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>";
  204. 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>";
  205. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  206. } else if ($ispart == 1) {
  207. //封面栏目
  208. echo "<tr>";
  209. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  210. 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."]";
  211. echo "</td>";
  212. 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>";
  213. 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>";
  214. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  215. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  216. 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>";
  217. 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>";
  218. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  219. } else if ($ispart == 2) {
  220. //外部栏目
  221. echo "<tr>";
  222. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  223. 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."]";
  224. echo "</td>";
  225. echo "<td align='right'><a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  226. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  227. 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>";
  228. 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>";
  229. echo "<input type='text' name='sortrank{$id}' value='{$rank}' class='admin-main-sort'></td></tr></table></td></tr>";
  230. }
  231. echo "<tr><td id='suns".$id."' style='".($GLOBALS['exallct']? "" : "display:none")."'><table width='100%' cellspacing='0' cellpadding='0'>";
  232. $this->LogicListAllSunType($id, $step." ");
  233. echo "</table></td></tr>";
  234. }
  235. }
  236. }
  237. /**
  238. * 返回某个相关下级目录的栏目id列表删除栏目或文档时调用
  239. *
  240. * @access public
  241. * @param int $id 栏目id
  242. * @param int $channel 栏目id
  243. * @return array
  244. */
  245. function GetSunTypes($id, $channel = 0)
  246. {
  247. $this->dsql = $GLOBALS['dsql'];
  248. $this->idArray[$this->idCounter] = $id;
  249. $this->idCounter++;
  250. $fid = $id;
  251. if ($channel != 0) {
  252. $csql = " And channeltype=$channel ";
  253. } else {
  254. $csql = "";
  255. }
  256. $this->dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid=$id $csql");
  257. $this->dsql->Execute("gs".$fid);
  258. while ($row = $this->dsql->GetObject("gs".$fid)) {
  259. $nid = $row->id;
  260. $this->GetSunTypes($nid, $channel);
  261. }
  262. return $this->idArray;
  263. }
  264. /**
  265. * 删除栏目
  266. *
  267. * @access public
  268. * @param int $id 栏目id
  269. * @param bool $isDelFile 是否删除文件
  270. * @return string
  271. */
  272. function DelType($id, $isDelFile)
  273. {
  274. $this->idCounter = 0;
  275. $this->idArray = array();
  276. $this->GetSunTypes($id);
  277. $query = "SELECT `#@__arctype`.*,`#@__channeltype`.typename AS ctypename, `#@__channeltype`.addtable FROM `#@__arctype` LEFT JOIN `#@__channeltype` ON `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$id' ";
  278. $typeinfos = $this->dsql->GetOne($query);
  279. $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
  280. if (!is_array($typeinfos)) {
  281. return FALSE;
  282. }
  283. $indir = $typeinfos['typedir'];
  284. $addtable = $typeinfos['addtable'];
  285. $ispart = $typeinfos['ispart'];
  286. $defaultname = $typeinfos['defaultname'];
  287. //删除数据库里的相关记录
  288. foreach ($this->idArray as $id) {
  289. $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
  290. if ($myrow['topid'] > 0) {
  291. $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
  292. if (is_array($mytoprow) && !empty($mytoprow)) {
  293. foreach ($mytoprow as $k => $v) {
  294. if (!preg_match("/[0-9]/", $k)) {
  295. $myrow[$k] = $v;
  296. }
  297. }
  298. }
  299. }
  300. //删除单独页面,删除目录和目录里的所有文件,禁止了此功能
  301. if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
  302. if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
  303. @unlink($this->baseDir.'/'.$myrow['defaultname']);
  304. }
  305. }
  306. //删除数据库信息
  307. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
  308. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
  309. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
  310. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
  311. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
  312. if ($addtable != "") {
  313. $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
  314. }
  315. }
  316. //删除单独页面,删除目录和目录里的所有文件,禁止了此功能
  317. if ($ispart == 2 && $indir == "") {
  318. if (is_file($this->baseDir."/".$defaultname)) {
  319. @unlink($this->baseDir."/".$defaultname);
  320. }
  321. }
  322. @reset($this->idArray);
  323. $this->idCounter = 0;
  324. return TRUE;
  325. }
  326. /**
  327. * 删除指定目录的所有文件
  328. *
  329. * @access public
  330. * @param string $indir 指定目录
  331. * @return int
  332. */
  333. function RmDirFile($indir)
  334. {
  335. if (!file_exists($indir)) return;
  336. $dh = dir($indir);
  337. while ($file = $dh->read()) {
  338. if ($file == "." || $file == "..") {
  339. continue;
  340. } else if (is_file("$indir/$file")) {
  341. @unlink("$indir/$file");
  342. } else {
  343. $this->RmDirFile("$indir/$file");
  344. }
  345. if (is_dir("$indir/$file")) {
  346. @rmdir("$indir/$file");
  347. }
  348. }
  349. $dh->close();
  350. return (1);
  351. }
  352. }//End Class
  353. ?>