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

412 lines
16KB

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