国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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