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

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