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

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