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

371 lines
15KB

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