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

365 lines
15KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 当前位置面包屑
  5. *
  6. * @version $id:typelink.class.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 TypeLink
  17. * @subpackage DedeBIZ.Libraries
  18. * @link https://www.dedebiz.com
  19. */
  20. class TypeLink
  21. {
  22. var $typeDir;
  23. var $dsql;
  24. var $TypeID;
  25. var $baseDir;
  26. var $modDir;
  27. var $indexUrl;
  28. var $indexName;
  29. var $TypeInfos;
  30. var $SplitSymbol;
  31. var $valuePosition;
  32. var $valuePositionName;
  33. var $OptionArrayList;
  34. //php5构造函数
  35. function __construct($typeid)
  36. {
  37. $this->indexUrl = $GLOBALS['cfg_basehost'].$GLOBALS['cfg_indexurl'];
  38. $this->indexName = $GLOBALS['cfg_indexname'];
  39. $this->baseDir = $GLOBALS['cfg_basedir'];
  40. $this->modDir = $GLOBALS['cfg_templets_dir'];
  41. $this->SplitSymbol = $GLOBALS['cfg_list_symbol'] === " > " ? "" : $GLOBALS['cfg_list_symbol'];
  42. $this->dsql = $GLOBALS['dsql'];
  43. $this->TypeID = $typeid;
  44. $this->valuePosition = '';
  45. $this->valuePositionName = '';
  46. $this->typeDir = '';
  47. $this->OptionArrayList = '';
  48. //载入类目信息
  49. $query = "SELECT tp.*,ch.typename as ctypename,ch.addtable,ch.issystem FROM `#@__arctype` tp LEFT JOIN `#@__channeltype` ch on ch.id=tp.channeltype WHERE tp.id='$typeid' ";
  50. if ($typeid > 0) {
  51. $this->TypeInfos = $this->dsql->GetOne($query);
  52. if (is_array($this->TypeInfos)) {
  53. $this->TypeInfos['tempindex'] = MfTemplet($this->TypeInfos['tempindex']);
  54. $this->TypeInfos['templist'] = MfTemplet($this->TypeInfos['templist']);
  55. $this->TypeInfos['temparticle'] = MfTemplet($this->TypeInfos['temparticle']);
  56. }
  57. }
  58. }
  59. //对于使用默认构造函数的情况
  60. //GetPositionLink()将不可用
  61. function TypeLink($typeid)
  62. {
  63. $this->__construct($typeid);
  64. }
  65. //关闭数据库连接,析放资源
  66. function Close()
  67. {
  68. }
  69. //重设栏目id
  70. function SETtypeid($typeid)
  71. {
  72. $this->TypeID = $typeid;
  73. $this->valuePosition = "";
  74. $this->valuePositionName = "";
  75. $this->typeDir = "";
  76. $this->OptionArrayList = "";
  77. //载入类目信息
  78. $query = "SELECT `#@__arctype`.*,`#@__channeltype`.typename as ctypename FROM `#@__arctype` LEFT JOIN `#@__channeltype` on `#@__channeltype`.id=`#@__arctype`.channeltype WHERE `#@__arctype`.id='$typeid'";
  79. $this->dsql->SetQuery($query);
  80. $this->TypeInfos = $this->dsql->GetOne();
  81. }
  82. //获得这个类目的路径
  83. function GetTypeDir()
  84. {
  85. if (empty($this->TypeInfos['typedir'])) {
  86. return $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
  87. } else {
  88. return $this->TypeInfos['typedir'];
  89. }
  90. }
  91. //获得某类目的链接列表 如:类目一>>类目二>> 这样的形式
  92. //islink 表示返回的列表是否带连接
  93. function GetPositionLink($islink = true)
  94. {
  95. $indexpage = "<li class='breadcrumb-item'><a href='".$this->indexUrl."'>".$this->indexName."</a></li>";
  96. if ($this->valuePosition != "" && $islink) {
  97. return $this->valuePosition;
  98. } else if ($this->valuePositionName != "" && !$islink) {
  99. return $this->valuePositionName;
  100. } else if ($this->TypeID == 0) {
  101. if ($islink) {
  102. return $indexpage;
  103. } else {
  104. return "没指定分类";
  105. }
  106. } else {
  107. if ($islink) {
  108. $this->valuePosition = $this->GetOneTypeLink($this->TypeInfos);
  109. if ($this->TypeInfos['reid'] != 0) {
  110. //调用递归逻辑
  111. $this->LogicGetPosition($this->TypeInfos['reid'], true);
  112. }
  113. $this->valuePosition = $indexpage.$this->SplitSymbol.$this->valuePosition;
  114. return $this->valuePosition.$this->SplitSymbol;
  115. } else {
  116. $this->valuePositionName = $this->TypeInfos['typename'];
  117. if ($this->TypeInfos['reid'] != 0) {
  118. //调用递归逻辑
  119. $this->LogicGetPosition($this->TypeInfos['reid'], false);
  120. }
  121. return $this->valuePositionName;
  122. }
  123. }
  124. }
  125. //获得名字列表
  126. function GetPositionName()
  127. {
  128. return $this->GetPositionLink(false);
  129. }
  130. //获得某类目的链接列表,递归逻辑部分
  131. function LogicGetPosition($id, $islink)
  132. {
  133. $this->dsql->SetQuery("SELECT id,reid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `#@__arctype` WHERE id='".$id."'");
  134. $tinfos = $this->dsql->GetOne();
  135. if ($islink) {
  136. $this->valuePosition = $this->GetOneTypeLink($tinfos).$this->SplitSymbol.$this->valuePosition;
  137. } else {
  138. $this->valuePositionName = $tinfos['typename'].$this->SplitSymbol.$this->valuePositionName;
  139. }
  140. if ($tinfos['reid'] > 0) {
  141. $this->LogicGetPosition($tinfos['reid'], $islink);
  142. } else {
  143. return 0;
  144. }
  145. }
  146. //获得某个类目的超链接信息
  147. function GetOneTypeLink($typeinfos)
  148. {
  149. $typepage = $this->GetOneTypeUrl($typeinfos);
  150. $typelink = "<li class='breadcrumb-item'><a href='".$typepage."'>".$typeinfos['typename']."</a></li>";
  151. return $typelink;
  152. }
  153. //获得某分类连接的URL
  154. function GetOneTypeUrl($typeinfos)
  155. {
  156. return GetTypeUrl(
  157. $typeinfos['id'],
  158. MfTypedir($typeinfos['typedir']),
  159. $typeinfos['isdefault'],
  160. $typeinfos['defaultname'],
  161. $typeinfos['ispart'],
  162. $typeinfos['namerule2'],
  163. $typeinfos['moresite'],
  164. $typeinfos['siteurl'],
  165. $typeinfos['sitepath']
  166. );
  167. }
  168. //获得类别列表
  169. //hid是指默认选中类目,0表示“请选择类目”或“不限类目”
  170. //oper是用户允许管理的类目,0表示所有类目
  171. //channeltype是指类目的文档类型,0表示不限栏目
  172. function GetOptionArray($hid = 0, $oper = 0, $channeltype = 0, $usersg = 0)
  173. {
  174. return $this->GetOptionList($hid, $oper, $channeltype, $usersg);
  175. }
  176. function GetOptionList($hid = 0, $oper = 0, $channeltype = 0, $usersg = 0)
  177. {
  178. global $cfg_admin_channel;
  179. if (empty($cfg_admin_channel)) $cfg_admin_channel = 'all';
  180. if (!$this->dsql) $this->dsql = $GLOBALS['dsql'];
  181. $this->OptionArrayList = '';
  182. if ($hid > 0) {
  183. $row = $this->dsql->GetOne("SELECT id,typename,ispart,channeltype FROM `#@__arctype` WHERE id='$hid'");
  184. $channeltype = $row['channeltype'];
  185. if ($row['ispart'] == 1) {
  186. $this->OptionArrayList .= "<option value='".$row['id']."' style='background:#e9ecef;color:#545b62' selected>└─ ".$row['typename']."</option>\r\n";
  187. } else {
  188. $this->OptionArrayList .= "<option value='".$row['id']."' selected>└─ ".$row['typename']."</option>\r\n";
  189. }
  190. }
  191. if ($channeltype == 0) $ctsql = '';
  192. else $ctsql = " AND channeltype='$channeltype' ";
  193. if (is_array($oper) && $cfg_admin_channel != 'all') {
  194. if (count($oper) == 0) {
  195. $query = "SELECT id,typename,ispart FROM `#@__arctype` WHERE 1=2 ";
  196. } else {
  197. $admin_catalog_tmp = $admin_catalog = join(',', $oper);
  198. $this->dsql->SetQuery("SELECT reid FROM `#@__arctype` WHERE id in($admin_catalog) GROUP BY reid ");
  199. $this->dsql->Execute();
  200. $topidstr = '';
  201. while ($row = $this->dsql->GetObject()) {
  202. if ($row->reid == 0) continue;
  203. $topidstr .= ($topidstr == '' ? $row->reid : ','.$row->reid);
  204. }
  205. $admin_catalog .= ','.$topidstr;
  206. $admin_catalogs = explode(',', $admin_catalog);
  207. $admin_catalogs = array_unique($admin_catalogs);
  208. $admin_catalog = join(',', $admin_catalogs);
  209. $admin_catalog = preg_replace("/,$/", '', $admin_catalog);
  210. $query = "SELECT id,typename,ispart FROM `#@__arctype` WHERE id in({$admin_catalog}) AND reid=0 $ctsql";
  211. }
  212. } else {
  213. $query = "SELECT id,typename,ispart FROM `#@__arctype` WHERE reid=0 $ctsql ORDER BY sortrank ASC";
  214. }
  215. $this->dsql->SetQuery($query);
  216. $this->dsql->Execute();
  217. while ($row = $this->dsql->GetObject()) {
  218. if ($row->id != $hid) {
  219. if ($row->ispart == 1) {
  220. $this->OptionArrayList .= "<option value='".$row->id."' style='background:#e9ecef;color:#545b62'>└─ ".$row->typename."</option>\r\n";
  221. } else {
  222. $this->OptionArrayList .= "<option value='".$row->id."'>└─ ".$row->typename."</option>\r\n";
  223. }
  224. }
  225. $this->LogicGetOptionArray($row->id, "─", $oper);
  226. }
  227. return $this->OptionArrayList;
  228. }
  229. /**
  230. * 逻辑递归
  231. *
  232. * @access public
  233. * @param int $id 栏目id
  234. * @param int $step 步进标志
  235. * @param int $oper 操作权限
  236. * @return string
  237. */
  238. function LogicGetOptionArray($id, $step, $oper = 0)
  239. {
  240. global $cfg_admin_channel;
  241. if (empty($cfg_admin_channel)) $cfg_admin_channel = 'all';
  242. $this->dsql->SetQuery("SELECT id,typename,ispart FROM `#@__arctype` WHERE reid='".$id."' ORDER BY sortrank ASC");
  243. $this->dsql->Execute($id);
  244. while ($row = $this->dsql->GetObject($id)) {
  245. if (is_array($oper) && $cfg_admin_channel != 'all') {
  246. if (!in_array($row->id, $oper)) continue;
  247. }
  248. if ($row->ispart == 1) {
  249. $this->OptionArrayList .= "<option value='".$row->id."' style='background:#e9ecef;color:#545b62'>└─$step ".$row->typename."</option>\r\n";
  250. } else {
  251. $this->OptionArrayList .= "<option value='".$row->id."'>└─$step ".$row->typename."</option>\r\n";
  252. }
  253. $this->LogicGetOptionArray($row->id, $step."─", $oper);
  254. }
  255. }
  256. /**
  257. * 获得与该类相关的类目,本函数应用于模板标记{dede:channel}{/dede:channel}中
  258. * $typetype 的值为:sun下级分类 self同级分类 top顶级分类
  259. *
  260. * @access public
  261. * @param int $typeid 栏目id
  262. * @param int $reid 所属ID
  263. * @param int $row 栏目行数
  264. * @param string $typetype 栏目类型
  265. * @param string $innertext 底层模板
  266. * @param int $col 显示列数
  267. * @param int $tablewidth 表格宽度
  268. * @param int $myinnertext 自定义底层模板
  269. * @return string
  270. */
  271. function GetChannelList(
  272. $typeid = 0,
  273. $reid = 0,
  274. $row = 8,
  275. $typetype = 'sun',
  276. $innertext = '',
  277. $col = 1,
  278. $tablewidth = 100,
  279. $myinnertext = ''
  280. ) {
  281. if ($typeid == 0) $typeid = $this->TypeID;
  282. if ($row == "") $row = 8;
  283. if ($reid == "") $reid = 0;
  284. if ($col == "") $col = 1;
  285. $tablewidth = str_replace("%", "", $tablewidth);
  286. if ($tablewidth == "") $tablewidth = 100;
  287. if ($col == "") $col = 1;
  288. $colWidth = ceil(100 / $col);
  289. $tablewidth = $tablewidth."%";
  290. $colWidth = $colWidth."%";
  291. if ($typetype == "") $typetype = "sun";
  292. if ($innertext == "") $innertext = GetSysTemplets("channel_list.htm");
  293. if ($reid == 0 && $typeid > 0) {
  294. $dbrow = $this->dsql->GetOne("SELECT reid FROM `#@__arctype` WHERE id='$typeid' ");
  295. if (is_array($dbrow)) {
  296. $reid = $dbrow['reid'];
  297. }
  298. }
  299. $likeType = "";
  300. if ($typetype == "top") {
  301. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl FROM `#@__arctype` WHERE reid=0 AND ishidden<>1 ORDER BY sortrank ASC limit 0,$row";
  302. } else if ($typetype == "sun" || $typetype == "son") {
  303. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl FROM `#@__arctype` WHERE reid='$typeid' AND ishidden<>1 ORDER BY sortrank ASC limit 0,$row";
  304. } else if ($typetype == "self") {
  305. $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl FROM `#@__arctype` WHERE reid='$reid' AND ishidden<>1 ORDER BY sortrank ASC limit 0,$row";
  306. }
  307. //AND ID<>'$typeid'
  308. $dtp2 = new DedeTagParse();
  309. $dtp2->SetNameSpace("field", "[", "]");
  310. $dtp2->LoadSource($innertext);
  311. $this->dsql->SetQuery($sql);
  312. $this->dsql->Execute();
  313. $line = $row;
  314. $GLOBALS['autoindex'] = 0;
  315. if ($col > 1) {
  316. $likeType = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  317. }
  318. for ($i = 0; $i < $line; $i++) {
  319. if ($col > 1) {
  320. $likeType .= "<tr>\r\n";
  321. }
  322. for ($j = 0; $j < $col; $j++) {
  323. if ($col > 1) $likeType .= " <td width='$colWidth'>\r\n";
  324. if ($row = $this->dsql->GetArray()) {
  325. //处理当前栏目的样式
  326. if ($row['id'] == "$typeid" && $myinnertext != '') {
  327. $linkOkstr = $myinnertext;
  328. $row['typelink'] = $this->GetOneTypeUrl($row);
  329. $linkOkstr = str_replace("~typelink~", $row['typelink'], $linkOkstr);
  330. $linkOkstr = str_replace("~typename~", $row['typename'], $linkOkstr);
  331. $likeType .= $linkOkstr;
  332. } else {
  333. //非当前栏目
  334. $row['typelink'] = $this->GetOneTypeUrl($row);
  335. if (is_array($dtp2->CTags)) {
  336. foreach ($dtp2->CTags as $tagid => $ctag) {
  337. if (isset($row[$ctag->GetName()])) {
  338. $dtp2->Assign($tagid, $row[$ctag->GetName()]);
  339. }
  340. }
  341. }
  342. $likeType .= $dtp2->GetResult();
  343. }
  344. }
  345. if ($col > 1) {
  346. $likeType .= " </td>\r\n";
  347. }
  348. $GLOBALS['autoindex']++;
  349. } //Loop Col
  350. if ($col > 1) {
  351. $i += $col - 1;
  352. }
  353. if ($col > 1) {
  354. $likeType .= " </tr>\r\n";
  355. }
  356. } //Loop for $i
  357. if ($col > 1) {
  358. $likeType .= " </table>\r\n";
  359. }
  360. $this->dsql->FreeResult();
  361. return $likeType;
  362. } //GetChannel
  363. }//End Class
  364. ?>