国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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