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

360 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. } if ($i === 0) {
  158. echo "<div class='text-center py-3'>暂无栏目,请添加栏目</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. }
  196. //普通列表
  197. if ($ispart == 0) {
  198. echo "<tr>";
  199. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  200. 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).")";
  201. echo "</td><td align='right'>";
  202. 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>";
  203. 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>";
  204. echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
  205. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  206. 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>";
  207. 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>";
  208. echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
  209. }
  210. //封面栏目
  211. else if ($ispart == 1) {
  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><td align='right'>";
  216. 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>";
  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}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
  223. }
  224. //独立页面
  225. else if ($ispart == 2) {
  226. echo "<tr>";
  227. echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
  228. 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."]";
  229. echo "</td><td align='right'>";
  230. echo "<a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
  231. echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
  232. 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>";
  233. 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>";
  234. echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
  235. }
  236. echo "<tr><td id='suns".$id."' style='".($GLOBALS['exallct']? "" : "display:none")."'><table width='100%' cellspacing='0' cellpadding='0'>";
  237. $this->LogicListAllSunType($id, $step." ");
  238. echo "</table></td></tr>";
  239. }
  240. }
  241. }
  242. /**
  243. * 返回与某个目相关的下级目录的栏目id列表删除栏目或文档时调用
  244. *
  245. * @access public
  246. * @param int $id 栏目id
  247. * @param int $channel 栏目id
  248. * @return array
  249. */
  250. function GetSunTypes($id, $channel = 0)
  251. {
  252. $this->dsql = $GLOBALS['dsql'];
  253. $this->idArray[$this->idCounter] = $id;
  254. $this->idCounter++;
  255. $fid = $id;
  256. if ($channel != 0) {
  257. $csql = " And channeltype=$channel ";
  258. } else {
  259. $csql = "";
  260. }
  261. $this->dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid=$id $csql");
  262. $this->dsql->Execute("gs".$fid);
  263. while ($row = $this->dsql->GetObject("gs".$fid)) {
  264. $nid = $row->id;
  265. $this->GetSunTypes($nid, $channel);
  266. }
  267. return $this->idArray;
  268. }
  269. /**
  270. * 删除栏目
  271. *
  272. * @access public
  273. * @param int $id 栏目id
  274. * @param bool $isDelFile 是否删除文件
  275. * @return string
  276. */
  277. function DelType($id, $isDelFile)
  278. {
  279. $this->idCounter = 0;
  280. $this->idArray = array();
  281. $this->GetSunTypes($id);
  282. $query = "SELECT `#@__arctype`.*,`#@__channeltype`.typename AS ctypename, `#@__channeltype`.addtable FROM `#@__arctype` LEFT JOIN `#@__channeltype` ON `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$id' ";
  283. $typeinfos = $this->dsql->GetOne($query);
  284. $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
  285. if (!is_array($typeinfos)) {
  286. return FALSE;
  287. }
  288. $indir = $typeinfos['typedir'];
  289. $addtable = $typeinfos['addtable'];
  290. $ispart = $typeinfos['ispart'];
  291. $defaultname = $typeinfos['defaultname'];
  292. //删除数据库里的相关记录
  293. foreach ($this->idArray as $id) {
  294. $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
  295. if ($myrow['topid'] > 0) {
  296. $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
  297. if (is_array($mytoprow) && !empty($mytoprow)) {
  298. foreach ($mytoprow as $k => $v) {
  299. if (!preg_match("/[0-9]/", $k)) {
  300. $myrow[$k] = $v;
  301. }
  302. }
  303. }
  304. }
  305. //删除目录和目录里的所有文件 ### 禁止了此功能
  306. //删除单独页面
  307. if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
  308. if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
  309. @unlink($this->baseDir.'/'.$myrow['defaultname']);
  310. }
  311. }
  312. //删除数据库信息
  313. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
  314. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
  315. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
  316. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
  317. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
  318. if ($addtable != "") {
  319. $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
  320. }
  321. }
  322. //删除目录和目录里的所有文件 ### 禁止了此功能
  323. //删除单独页面
  324. if ($ispart == 2 && $indir == "") {
  325. if (is_file($this->baseDir."/".$defaultname)) {
  326. @unlink($this->baseDir."/".$defaultname);
  327. }
  328. }
  329. @reset($this->idArray);
  330. $this->idCounter = 0;
  331. return TRUE;
  332. }
  333. /**
  334. * 删除指定目录的所有文件
  335. *
  336. * @access public
  337. * @param string $indir 指定目录
  338. * @return int
  339. */
  340. function RmDirFile($indir)
  341. {
  342. if (!file_exists($indir)) return;
  343. $dh = dir($indir);
  344. while ($file = $dh->read()) {
  345. if ($file == "." || $file == "..") {
  346. continue;
  347. } else if (is_file("$indir/$file")) {
  348. @unlink("$indir/$file");
  349. } else {
  350. $this->RmDirFile("$indir/$file");
  351. }
  352. if (is_dir("$indir/$file")) {
  353. @rmdir("$indir/$file");
  354. }
  355. }
  356. $dh->close();
  357. return (1);
  358. }
  359. }//End Class
  360. ?>