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

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