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

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