|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- if (!defined('DEDEINC')) exit('dedebiz');
- /**
- * 后台栏目管理
- *
- * @version $id:typeunit.class.admin.php 15:21 2010年7月5日 tianya $
- * @package DedeBIZ.Libraries
- * @copyright Copyright (c) 2022 DedeBIZ.COM
- * @license https://www.dedebiz.com/license
- * @link https://www.dedebiz.com
- */
- require_once(DEDEINC."/channelunit.func.php");
- class TypeUnit
- {
- var $dsql;
- var $artDir;
- var $baseDir;
- var $idCounter;
- var $idArrary;
- var $shortName;
- var $CatalogNums;
- //php5构造函数
- function __construct()
- {
- $this->idCounter = 0;
- $this->artDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
- $this->baseDir = $GLOBALS['cfg_basedir'];
- $this->shortName = $GLOBALS['art_shortname'];
- $this->idArrary = '';
- $this->dsql = 0;
- }
- function TypeUnit()
- {
- $this->__construct();
- }
- //清理类
- function Close()
- {
- }
- //获取所有栏目的文档id数
- function UpdateCatalogNum()
- {
- $this->dsql->SetQuery("SELECT typeid,count(typeid) as dd FROM `#@__arctiny` WHERE arcrank <>-3 GROUP BY typeid");
- $this->dsql->Execute();
- while ($row = $this->dsql->GetArray()) {
- $this->CatalogNums[$row['typeid']] = $row['dd'];
- }
- }
- function GetTotalArc($tid)
- {
- if (!is_array($this->CatalogNums)) {
- $this->UpdateCatalogNum();
- }
- if (!isset($this->CatalogNums[$tid])) {
- return 0;
- } else {
- $totalnum = 0;
- $ids = explode(',', GetSonIds($tid));
- foreach ($ids as $tid) {
- if (isset($this->CatalogNums[$tid])) {
- $totalnum += $this->CatalogNums[$tid];
- }
- }
- return $totalnum;
- }
- }
- /**
- * 读出所有分类,在栏目管理页list_type中使用
- *
- * @access public
- * @param int $channel 栏目id
- * @param int $nowdir 当前操作ID
- * @return string
- */
- function ListAllType($channel = 0, $nowdir = 0)
- {
- global $cfg_admin_channel, $admin_catalogs;
- $this->dsql = $GLOBALS['dsql'];
- //检测会员有权限的顶级栏目
- if ($cfg_admin_channel == 'array') {
- $admin_catalog = join(',', $admin_catalogs);
- $this->dsql->SetQuery("SELECT reid FROM `#@__arctype` WHERE id in($admin_catalog) GROUP BY reid ");
- $this->dsql->Execute();
- $topidstr = '';
- while ($row = $this->dsql->GetObject()) {
- if ($row->reid == 0) continue;
- $topidstr .= ($topidstr == '' ? $row->reid : ','.$row->reid);
- }
- $admin_catalog .= ','.$topidstr;
- $admin_catalogs = explode(',', $admin_catalog);
- $admin_catalogs = array_unique($admin_catalogs);
- }
- $this->dsql->SetQuery("SELECT id,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid=0 ORDER BY sortrank");
- $this->dsql->Execute(0);
- $i = 0;
- while ($row = $this->dsql->GetObject(0)) {
- if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
- continue;
- }
- $typeDir = $row->typedir;
- $typeName = $row->typename;
- $ispart = $row->ispart;
- $id = $row->id;
- $rank = $row->sortrank;
- if ($row->ishidden == '1') {
- $nss = "<span class='btn btn-secondary btn-xs'>隐藏</span>";
- } else {
- $nss = '';
- }
- echo "<table width='100%' cellspacing='0' cellpadding='2'>";
- //普通列表
- if ($ispart == 0) {
- echo "<tr>";
- 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'></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).")";
- echo "</td><td align='right'>";
- 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>";
- echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
- echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- //带封面的栏目
- else if ($ispart == 1) {
- echo "<tr>";
- 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'></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."]";
- echo "</td><td align='right'>";
- 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>";
- echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
- echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- //独立页面
- else if ($ispart == 2) {
- echo "<tr>";
- 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'></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."]";
- echo "</td><td align='right'>";
- echo "<a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- echo "<tr><td colspan='2' id='suns".$id."' class='p-0'>";
- $lastid = GetCookie('lastCid');
- if ($channel == $id || $lastid == $id || isset($GLOBALS['exallct']) || $cfg_admin_channel == 'array') {
- echo "<table width='100%' cellspacing='0' cellpadding='0'>";
- $this->LogicListAllSunType($id, " ");
- echo "</table>";
- }
- echo "</td></tr></table>";
- $i++;
- }
- if ($i === 0) {
- echo "<div class='text-center py-3'>暂无栏目,请先添加栏目</div>";
- }
- }
- /**
- * 获得子栏目的递归调用
- *
- * @access public
- * @param int $id 栏目id
- * @param string $step 层级标志
- * @return void
- */
- function LogicListAllSunType($id, $step)
- {
- global $cfg_admin_channel, $admin_catalogs;
- $fid = $id;
- $this->dsql->SetQuery("SELECT id,reid,typedir,typename,ispart,sortrank,ishidden FROM `#@__arctype` WHERE reid='".$id."' ORDER BY sortrank");
- $this->dsql->Execute($fid);
- if ($this->dsql->GetTotalRow($fid) > 0) {
- while ($row = $this->dsql->GetObject($fid)) {
- if ($cfg_admin_channel == 'array' && !in_array($row->id, $admin_catalogs)) {
- continue;
- }
- $typeDir = $row->typedir;
- $typeName = $row->typename;
- $reid = $row->reid;
- $id = $row->id;
- $ispart = $row->ispart;
- if ($step == " ") {
- $stepdd = 2;
- } else {
- $stepdd = 3;
- }
- $rank = $row->sortrank;
- if ($row->ishidden == '1') {
- $nss = "<span class='btn btn-secondary btn-xs'>隐藏</span>";
- } else {
- $nss = '';
- }
- //普通列表
- if ($ispart == 0) {
- echo "<tr>";
- echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
- echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></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).")";
- echo "</td><td align='right'>";
- 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>";
- echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
- echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- //封面栏目
- else if ($ispart == 1) {
- echo "<tr>";
- echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
- echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></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."]";
- echo "</td><td align='right'>";
- 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>";
- echo "<a href='catalog_do.php?cid={$id}&dopost=listArchives' title='文档' class='btn btn-light btn-sm'><i class='fa fa-file-text'></i></a>";
- echo "<a href='catalog_add.php?id={$id}' title='添加' class='btn btn-light btn-sm'><i class='fa fa-plus-circle'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- //独立页面
- else if ($ispart == 2) {
- echo "<tr>";
- echo "<td class='admin-td'><table width='98%' cellspacing='0' cellpadding='0'><tr><td width='50%'>";
- echo "$step<i id='img".$id."' onClick=\"LoadSuns('suns".$id."',$id);\" class='fa fa-plus-square'></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."]";
- echo "</td><td align='right'>";
- echo "<a href='{$typeDir}' target='_blank' title='预览' class='btn btn-light btn-sm'><i class='fa fa-eye'></i></a>";
- echo "<a href='catalog_edit.php?id={$id}' title='修改' class='btn btn-light btn-sm'><i class='fa fa-pencil-square'></i></a>";
- 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>";
- echo "<a href='catalog_del.php?id={$id}&typeoldname=".urlencode($typeName)."' title='删除' class='btn btn-danger btn-sm'><i class='fa fa-trash'></i></a>";
- echo "<input type='text' name='sortrank{$id}' value='{$rank}' style='margin-left:1rem;width:30px;text-align:center'></td></tr></table></td></tr>";
- }
- echo "<tr><td id='suns".$id."' style='".($GLOBALS['exallct']? "" : "display:none")."'><table width='100%' cellspacing='0' cellpadding='0'>";
- $this->LogicListAllSunType($id, $step." ");
- echo "</table></td></tr>";
- }
- }
- }
- /**
- * 返回与某个目相关的下级目录的栏目id列表删除栏目或文档时调用
- *
- * @access public
- * @param int $id 栏目id
- * @param int $channel 栏目id
- * @return array
- */
- function GetSunTypes($id, $channel = 0)
- {
- $this->dsql = $GLOBALS['dsql'];
- $this->idArray[$this->idCounter] = $id;
- $this->idCounter++;
- $fid = $id;
- if ($channel != 0) {
- $csql = " And channeltype=$channel ";
- } else {
- $csql = "";
- }
- $this->dsql->SetQuery("SELECT id FROM `#@__arctype` WHERE reid=$id $csql");
- $this->dsql->Execute("gs".$fid);
- while ($row = $this->dsql->GetObject("gs".$fid)) {
- $nid = $row->id;
- $this->GetSunTypes($nid, $channel);
- }
- return $this->idArray;
- }
- /**
- * 删除栏目
- *
- * @access public
- * @param int $id 栏目id
- * @param bool $isDelFile 是否删除文件
- * @return string
- */
- function DelType($id, $isDelFile)
- {
- $this->idCounter = 0;
- $this->idArray = array();
- $this->GetSunTypes($id);
- $query = "SELECT `#@__arctype`.*,`#@__channeltype`.typename AS ctypename, `#@__channeltype`.addtable FROM `#@__arctype` LEFT JOIN `#@__channeltype` ON `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$id' ";
- $typeinfos = $this->dsql->GetOne($query);
- $topinfos = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$typeinfos['topid']."'");
- if (!is_array($typeinfos)) {
- return FALSE;
- }
- $indir = $typeinfos['typedir'];
- $addtable = $typeinfos['addtable'];
- $ispart = $typeinfos['ispart'];
- $defaultname = $typeinfos['defaultname'];
- //删除数据库里的相关记录
- foreach ($this->idArray as $id) {
- $myrow = $this->dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$id'");
- if ($myrow['topid'] > 0) {
- $mytoprow = $this->dsql->GetOne("SELECT moresite,siteurl FROM `#@__arctype` WHERE id='".$myrow['topid']."'");
- if (is_array($mytoprow) && !empty($mytoprow)) {
- foreach ($mytoprow as $k => $v) {
- if (!preg_match("/[0-9]/", $k)) {
- $myrow[$k] = $v;
- }
- }
- }
- }
- //删除目录和目录里的所有文件 ### 禁止了此功能
- //删除单独页面
- if ($myrow['ispart'] == 2 && $myrow['typedir'] == '') {
- if (is_file($this->baseDir.'/'.$myrow['defaultname'])) {
- @unlink($this->baseDir.'/'.$myrow['defaultname']);
- }
- }
- //删除数据库信息
- $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id='$id'");
- $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid='$id'");
- $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE typeid='$id'");
- $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid='$id'");
- $this->dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid='$id'");
- if ($addtable != "") {
- $this->dsql->ExecuteNoneQuery("DELETE FROM $addtable WHERE typeid='$id'");
- }
- }
- //删除目录和目录里的所有文件 ### 禁止了此功能
- //删除单独页面
- if ($ispart == 2 && $indir == "") {
- if (is_file($this->baseDir."/".$defaultname)) {
- @unlink($this->baseDir."/".$defaultname);
- }
- }
- @reset($this->idArray);
- $this->idCounter = 0;
- return TRUE;
- }
- /**
- * 删除指定目录的所有文件
- *
- * @access public
- * @param string $indir 指定目录
- * @return int
- */
- function RmDirFile($indir)
- {
- if (!file_exists($indir)) return;
- $dh = dir($indir);
- while ($file = $dh->read()) {
- if ($file == "." || $file == "..") {
- continue;
- } else if (is_file("$indir/$file")) {
- @unlink("$indir/$file");
- } else {
- $this->RmDirFile("$indir/$file");
- }
- if (is_dir("$indir/$file")) {
- @rmdir("$indir/$file");
- }
- }
- $dh->close();
- return (1);
- }
- }//End Class
- ?>
|