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

366 lines
21KB

  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. /**
  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 <>-3 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 GROUP 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='btn btn-secondary btn-xs'>隐藏</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='biz-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'><span class='mr-3 ml-3'>".$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;text-align:center'></td></tr></table></td></tr>";
  129. }
  130. //带封面的频道
  131. else if ($ispart == 1) {
  132. echo "<tr>";
  133. echo "<td class='biz-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'><span class='mr-3 ml-3'>".$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;text-align:center'></td></tr></table></td></tr>";
  142. }
  143. //独立页面
  144. else if ($ispart == 2) {
  145. echo "<tr>";
  146. echo "<td class='biz-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."'><span class='mr-3 ml-3'>".$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;text-align:center'></td></tr></table></td></tr>";
  153. }
  154. echo "<tr><td colspan='2' id='suns".$id."' class='p-0'>";
  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."' GROUP 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='btn btn-secondary btn-xs'>隐藏</span>";
  196. } else {
  197. $nss = '';
  198. }
  199. //普通列表
  200. if ($ispart == 0) {
  201. echo "<tr>";
  202. echo "<td class='nbiz-td'>";
  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-3 ml-3'><span class='btn btn-success btn-xs'>列表</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives'><span class='mr-3 ml-3'>".$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;text-align:center'></td></tr></table></td></tr>";
  214. }
  215. //封面频道
  216. else if ($ispart == 1) {
  217. echo "<tr>";
  218. echo "<td class='nbiz-td'><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-3 ml-3'><span class='btn btn-warning btn-xs'>封面</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives'><span class='mr-3 ml-3'>".$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;text-align:center'></td></tr></table></td></tr>";
  228. }
  229. //独立页面
  230. else if ($ispart == 2) {
  231. echo "<tr>";
  232. echo "<td class='biz-td'><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-3 ml-3'><span class='btn btn-primary btn-xs'>外部</span>{$nss}<a href='catalog_do.php?cid=".$id."&dopost=listArchives'><span class='mr-3 ml-3'>".$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;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 = "SELECT `#@__arctype`.*,`#@__channeltype`.typename AS ctypename, `#@__channeltype`.addtable FROM `#@__arctype` LEFT JOIN `#@__channeltype` ON `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$id' ";
  289. $typeinfos = $this->dsql->GetOne($query);
  290. $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
  291. if (!is_array($typeinfos)) {
  292. return FALSE;
  293. }
  294. $indir = $typeinfos['typedir'];
  295. $addtable = $typeinfos['addtable'];
  296. $ispart = $typeinfos['ispart'];
  297. $defaultname = $typeinfos['defaultname'];
  298. //删除数据库里的相关记录
  299. foreach ($this->idArray as $id) {
  300. $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
  301. if ($myrow['topid'] > 0) {
  302. $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
  303. if (is_array($mytoprow) && !empty($mytoprow)) {
  304. foreach ($mytoprow as $k => $v) {
  305. if (!preg_match("/[0-9]/", $k)) {
  306. $myrow[$k] = $v;
  307. }
  308. }
  309. }
  310. }
  311. //删除目录和目录里的所有文件 ### 禁止了此功能
  312. //删除单独页面
  313. if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
  314. if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
  315. @unlink($this->baseDir.'/'.$myrow['defaultname']);
  316. }
  317. }
  318. //删除数据库信息
  319. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
  320. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
  321. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
  322. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
  323. $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
  324. if ($addtable != "") {
  325. $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
  326. }
  327. }
  328. //删除目录和目录里的所有文件 ### 禁止了此功能
  329. //删除单独页面
  330. if ($ispart == 2 && $indir == "") {
  331. if (is_file($this->baseDir."/".$defaultname)) {
  332. @unlink($this->baseDir."/".$defaultname);
  333. }
  334. }
  335. @reset($this->idArray);
  336. $this->idCounter = 0;
  337. return TRUE;
  338. }
  339. /**
  340. * 删除指定目录的所有文件
  341. *
  342. * @access public
  343. * @param string $indir 指定目录
  344. * @return int
  345. */
  346. function RmDirFile($indir)
  347. {
  348. if (!file_exists($indir)) return;
  349. $dh = dir($indir);
  350. while ($file = $dh->read()) {
  351. if ($file == "." || $file == "..") {
  352. continue;
  353. } else if (is_file("$indir/$file")) {
  354. @unlink("$indir/$file");
  355. } else {
  356. $this->RmDirFile("$indir/$file");
  357. }
  358. if (is_dir("$indir/$file")) {
  359. @rmdir("$indir/$file");
  360. }
  361. }
  362. $dh->close();
  363. return (1);
  364. }
  365. }//End Class
  366. ?>