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

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