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

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