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

463 lines
16KB

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