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

374 lines
21KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 栏目单元,主要用户管理后台管理处
  5. *
  6. * @version $Id: typeunit.class.admin.php 1 15:21 2010年7月5日Z 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. /**
  14. * 栏目单元,主要用户管理后台管理处
  15. *
  16. * @package TypeUnit
  17. * @subpackage DedeBIZ.Libraries
  18. * @link https://www.dedebiz.com
  19. */
  20. class TypeUnit
  21. {
  22. var $dsql;
  23. var $artDir;
  24. var $baseDir;
  25. var $idCounter;
  26. var $idArrary;
  27. var $shortName;
  28. var $CatalogNums;
  29. //php5构造函数
  30. function __construct()
  31. {
  32. $this->idCounter = 0;
  33. $this->artDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
  34. $this->baseDir = $GLOBALS['cfg_basedir'];
  35. $this->shortName = $GLOBALS['art_shortname'];
  36. $this->idArrary = '';
  37. $this->dsql = 0;
  38. }
  39. function TypeUnit()
  40. {
  41. $this->__construct();
  42. }
  43. //清理类
  44. function Close()
  45. {
  46. }
  47. //获取所有栏目的文档ID数
  48. function UpdateCatalogNum()
  49. {
  50. $this->dsql->SetQuery("SELECT typeid,count(typeid) as dd FROM `#@__arctiny` WHERE arcrank <>-2 group by typeid");
  51. $this->dsql->Execute();
  52. while ($row = $this->dsql->GetArray()) {
  53. $this->CatalogNums[$row['typeid']] = $row['dd'];
  54. }
  55. }
  56. function GetTotalArc($tid)
  57. {
  58. if (!is_array($this->CatalogNums)) {
  59. $this->UpdateCatalogNum();
  60. }
  61. if (!isset($this->CatalogNums[$tid])) {
  62. return 0;
  63. } else {
  64. $totalnum = 0;
  65. $ids = explode(',', GetSonIds($tid));
  66. foreach ($ids as $tid) {
  67. if (isset($this->CatalogNums[$tid])) {
  68. $totalnum += $this->CatalogNums[$tid];
  69. }
  70. }
  71. return $totalnum;
  72. }
  73. }
  74. /**
  75. * 读出所有分类,在类目管理页(list_type)中使用
  76. *
  77. * @access public
  78. * @param int $channel 频道ID
  79. * @param int $nowdir 当前操作ID
  80. * @return string
  81. */
  82. function ListAllType($channel = 0, $nowdir = 0)
  83. {
  84. global $cfg_admin_channel, $admin_catalogs;
  85. $this->dsql = $GLOBALS['dsql'];
  86. //检测用户有权限的顶级栏目
  87. if ($cfg_admin_channel == 'array') {
  88. $admin_catalog = join(',', $admin_catalogs);
  89. $this->dsql->SetQuery("SELECT reid FROM `#@__arctype` WHERE id in($admin_catalog) group by reid ");
  90. $this->dsql->Execute();
  91. $topidstr = '';
  92. while ($row = $this->dsql->GetObject()) {
  93. if ($row->reid == 0) continue;
  94. $topidstr .= ($topidstr == '' ? $row->reid : ','.$row->reid);
  95. }
  96. $admin_catalog .= ','.$topidstr;
  97. $admin_catalogs = explode(',', $admin_catalog);
  98. $admin_catalogs = array_unique($admin_catalogs);
  99. }
  100. $this->dsql->SetQuery("SELECT id,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid=0 order by sortrank");
  101. $this->dsql->Execute(0);
  102. while ($row = $this->dsql->GetObject(0)) {
  103. if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
  104. continue;
  105. }
  106. $typeDir = $row->typedir;
  107. $typeName = $row->typename;
  108. $ispart = $row->ispart;
  109. $id = $row->id;
  110. $rank = $row->sortrank;
  111. if ($row->ishidden == '1') {
  112. $nss = "<span style='color:#dc3545'>[隐藏]</span>";
  113. } else {
  114. $nss = '';
  115. }
  116. echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>";
  117. //普通列表
  118. if ($ispart == 0) {
  119. echo "<tr>";
  120. echo "<td style='background:#FBFCE2;' width='2%' class='bline'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i></td>";
  121. echo "<td style='background:#FBFCE2;' class='bline'><table width='98%' border='0' cellspacing='0' cellpadding='0'><tr><td width='50%'><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_do.php?cid=".$id."&dopost=listArchives' oncontextmenu=\"CommonMenu(event,this,$id,'".urlencode($typeName)."')\">{$nss}".$typeName."[ID:".$id."]</a>(文档:".$this->GetTotalArc($id).")<a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  122. echo "</td><td align='right'>";
  123. echo "<a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  124. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='内容'><i class='fa fa-list'></i></a>";
  125. echo "<a href='catalog_add.php?id={$id}' title='增加子类'><i class='fa fa-plus-circle'></i></a>";
  126. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  127. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  128. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  129. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  130. }
  131. //带封面的频道
  132. else if ($ispart == 1) {
  133. echo "<tr>";
  134. echo "<td style='background:#FBFCE2;' width='2%' class='bline'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i></td>";
  135. echo "<td style='background:#FBFCE2;' class='bline'><table width='98%' border='0' cellspacing='0' cellpadding='0'><tr><td width='50%'><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_do.php?cid=".$id."&dopost=listArchives' oncontextmenu=\"CommonMenuPart(event,this,$id,'".urlencode($typeName)."')\">{$nss}".$typeName."[ID:".$id."]</a> <a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  136. echo "</td><td align='right'>";
  137. echo "<a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  138. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='内容'><i class='fa fa-list'></i></a>";
  139. echo "<a href='catalog_add.php?id={$id}' title='增加子类'><i class='fa fa-plus-circle'></i></a>";
  140. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  141. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  142. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  143. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  144. }
  145. //独立页面
  146. else if ($ispart == 2) {
  147. echo "<tr height='26' bgcolor='#FBFCE2'>";
  148. echo "<td width='2%' class='bline2'><i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i></td>";
  149. echo "<td class='bline2'><table width='98%' border='0' cellspacing='0' cellpadding='0'><tr><td width='50%'><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_edit.php?id=".$id."' oncontextmenu=\"SingleMenu(event,this,$id,'".urlencode($typeName)."')\">{$nss}".$typeName."[ID:".$id."]</a><a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  150. echo "</td><td align='right'>";
  151. echo "<a href='{$typeDir}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  152. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  153. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  154. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  155. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  156. }
  157. echo "<tr><td colspan='2' id='suns".$id."'>";
  158. $lastid = GetCookie('lastCid');
  159. if ($channel == $id || $lastid == $id || isset($GLOBALS['exallct']) || $cfg_admin_channel == 'array') {
  160. echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
  161. $this->LogicListAllSunType($id, " ");
  162. echo "</table>";
  163. }
  164. echo "</td></tr></table>";
  165. }
  166. }
  167. /**
  168. * 获得子类目的递归调用
  169. *
  170. * @access public
  171. * @param int $id 栏目ID
  172. * @param string $step 层级标志
  173. * @return void
  174. */
  175. function LogicListAllSunType($id, $step)
  176. {
  177. global $cfg_admin_channel, $admin_catalogs;
  178. $fid = $id;
  179. $this->dsql->SetQuery("SELECT id,reid,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid='".$id."' order by sortrank");
  180. $this->dsql->Execute($fid);
  181. if ($this->dsql->GetTotalRow($fid) > 0) {
  182. while ($row = $this->dsql->GetObject($fid)) {
  183. if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
  184. continue;
  185. }
  186. $typeDir = $row->typedir;
  187. $typeName = $row->typename;
  188. $reid = $row->reid;
  189. $id = $row->id;
  190. $ispart = $row->ispart;
  191. if ($step == " ") {
  192. $stepdd = 2;
  193. } else {
  194. $stepdd = 3;
  195. }
  196. $rank = $row->sortrank;
  197. if ($row->ishidden == '1') {
  198. $nss = "<span style='color:#dc3545'>[隐藏]</span>";
  199. } else {
  200. $nss = '';
  201. }
  202. //普通列表
  203. if ($ispart == 0) {
  204. echo "<tr height='26' oncontextmenu=\"CommonMenu(event,this,$id,'".urlencode($typeName)."')\">";
  205. echo "<td class='nbline'>";
  206. echo "<table width='98%' border='0' cellspacing='0' cellpadding='0'>";
  207. echo "<tr onMouseMove=\"javascript:this.bgColor='#FAFCE0';\" onMouseOut=\"javascript:this.bgColor='#ffffff';\"><td width='50%'>";
  208. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_do.php?cid=".$id."&dopost=listArchives'>{$nss}".$typeName."[ID:".$id."]</a>(文档:".$this->GetTotalArc($id).")<a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  209. echo "</td><td align='right'>";
  210. echo "<a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  211. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='内容'><i class='fa fa-list'></i></a>";
  212. echo "<a href='catalog_add.php?id={$id}' title='增加子类'><i class='fa fa-plus-circle'></i></a>";
  213. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  214. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  215. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  216. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  217. }
  218. //封面频道
  219. else if ($ispart == 1) {
  220. echo "<tr height='26' oncontextmenu=\"CommonMenu(event,this,$id,'".urlencode($typeName)."')\">";
  221. echo "<td class='nbline'><table width='98%' border='0' cellspacing='0' cellpadding='0'><tr onMouseMove=\"javascript:this.bgColor='#FAFCE0';\" onMouseOut=\"javascript:this.bgColor='#ffffff';\"><td width='50%'>";
  222. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_do.php?cid=".$id."&dopost=listArchives'>{$nss}".$typeName."[ID:".$id."]</a><a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  223. echo "</td><td align='right'>";
  224. echo "<a href='{$GLOBALS['cfg_phpurl']}/list.php?tid={$id}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  225. echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='内容'><i class='fa fa-list'></i></a>";
  226. echo "<a href='catalog_add.php?id={$id}' title='增加子类'><i class='fa fa-plus-circle'></i></a>";
  227. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  228. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  229. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  230. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  231. }
  232. //独立页面
  233. else if ($ispart == 2) {
  234. echo "<tr height='26' oncontextmenu=\"SingleMenu(event,this,$id,'".urlencode($typeName)."')\">";
  235. echo "<td class='bline2'><table width='98%' border='0' cellspacing='0' cellpadding='0'>";
  236. echo "<tr onMouseMove=\"javascript:this.bgColor='#FAFCE0';\" onMouseOut=\"javascript:this.bgColor='#ffffff';\"><td width='50%'>";
  237. echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square-o' style='margin:0 10px;cursor:pointer'></i><input class='np' type='checkbox' name='tids[]' value='{$id}' style='margin:0 10px'><a href='catalog_do.php?cid=".$id."&dopost=listArchives'>{$nss}".$typeName."[ID:".$id."]</a><a onclick=\"AlertMsg('快捷编辑窗口','$id');\" href=\"javascript:;\"><i class='fa fa-pencil-square-o' style='vertical-align:text-top'></i></a>";
  238. echo "</td><td align='right'>";
  239. echo "<a href='{$typeDir}' target='_blank' title='预览'><i class='fa fa-globe'></i></a>";
  240. echo "<a href='catalog_edit.php?id={$id}' title='修改'><i class='fa fa-pencil-square-o'></i></a>";
  241. echo "<a href='catalog_do.php?dopost=moveCatalog&typeid={$id}' title='移动'><i class='fa fa-share-square'></i></a>";
  242. echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除'><i class='fa fa-trash'></i></a>";
  243. echo "&nbsp;<input type='text' name='sortrank{$id}' value='{$rank}' style='width:30px;height:26px'></td></tr></table></td></tr>";
  244. }
  245. echo "<tr><td id='suns".$id."' style='display:none'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
  246. $this->LogicListAllSunType($id, $step." ");
  247. echo "</table></td></tr>";
  248. }
  249. }
  250. }
  251. /**
  252. * 返回与某个目相关的下级目录的类目ID列表(删除类目或文章时调用)
  253. *
  254. * @access public
  255. * @param int $id 栏目ID
  256. * @param int $channel 频道ID
  257. * @return array
  258. */
  259. function GetSunTypes($id, $channel = 0)
  260. {
  261. $this->dsql = $GLOBALS['dsql'];
  262. $this->idArray[$this->idCounter] = $id;
  263. $this->idCounter++;
  264. $fid = $id;
  265. if ($channel != 0) {
  266. $csql = " And channeltype=$channel ";
  267. } else {
  268. $csql = "";
  269. }
  270. $this->dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid=$id $csql");
  271. $this->dsql->Execute("gs".$fid);
  272. while ($row = $this->dsql->GetObject("gs".$fid)) {
  273. $nid = $row->id;
  274. $this->GetSunTypes($nid, $channel);
  275. }
  276. return $this->idArray;
  277. }
  278. /**
  279. * 删除类目
  280. *
  281. * @access public
  282. * @param int $id 栏目ID
  283. * @param bool $isDelFile 是否删除文件
  284. * @return string
  285. */
  286. function DelType($id, $isDelFile)
  287. {
  288. $this->idCounter = 0;
  289. $this->idArray = array();
  290. $this->GetSunTypes($id);
  291. $query = "
  292. SELECT #@__arctype.*,#@__channeltype.typename AS ctypename,
  293. #@__channeltype.addtable
  294. FROM `#@__arctype` LEFT JOIN #@__channeltype
  295. ON #@__channeltype.id=#@__arctype.channeltype
  296. WHERE #@__arctype.id='$id'
  297. ";
  298. $typeinfos = $this->dsql->GetOne($query);
  299. $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
  300. if (!is_array($typeinfos)) {
  301. return FALSE;
  302. }
  303. $indir = $typeinfos['typedir'];
  304. $addtable = $typeinfos['addtable'];
  305. $ispart = $typeinfos['ispart'];
  306. $defaultname = $typeinfos['defaultname'];
  307. //删除数据库里的相关记录
  308. foreach ($this->idArray as $id) {
  309. $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
  310. if ($myrow['topid'] > 0) {
  311. $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
  312. if (is_array($mytoprow) && !empty($mytoprow)) {
  313. foreach ($mytoprow as $k => $v) {
  314. if (!preg_match("/[0-9]/", $k)) {
  315. $myrow[$k] = $v;
  316. }
  317. }
  318. }
  319. }
  320. //删除目录和目录里的所有文件 ### 禁止了此功能
  321. //删除单独页面
  322. if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
  323. if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
  324. @unlink($this->baseDir.'/'.$myrow['defaultname']);
  325. }
  326. }
  327. //删除数据库信息
  328. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
  329. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
  330. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
  331. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
  332. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
  333. if ($addtable != "") {
  334. $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
  335. }
  336. }
  337. //删除目录和目录里的所有文件 ### 禁止了此功能
  338. //删除单独页面
  339. if ($ispart == 2 && $indir == "") {
  340. if (is_file($this->baseDir."/".$defaultname)) {
  341. @unlink($this->baseDir."/".$defaultname);
  342. }
  343. }
  344. @reset($this->idArray);
  345. $this->idCounter = 0;
  346. return TRUE;
  347. }
  348. /**
  349. * 删除指定目录的所有文件
  350. *
  351. * @access public
  352. * @param string $indir 指定目录
  353. * @return int
  354. */
  355. function RmDirFile($indir)
  356. {
  357. if (!file_exists($indir)) return;
  358. $dh = dir($indir);
  359. while ($file = $dh->read()) {
  360. if ($file == "." || $file == "..") {
  361. continue;
  362. } else if (is_file("$indir/$file")) {
  363. @unlink("$indir/$file");
  364. } else {
  365. $this->RmDirFile("$indir/$file");
  366. }
  367. if (is_dir("$indir/$file")) {
  368. @rmdir("$indir/$file");
  369. }
  370. }
  371. $dh->close();
  372. return (1);
  373. }
  374. }//End Class