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

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