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

166 lines
7.1KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 关联内容标签
  5. *
  6. * @version $Id: relation.lib.php 1 9:29 2020年9月23日 tianya $
  7. * @package DedeBIZ.Taglib
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. //关联内容
  13. function lib_relation(&$ctag, &$refObj)
  14. {
  15. global $dsql;
  16. //属性处理
  17. $attlist = "row|12,titlelen|28,infolen|150,name|default,orderby|";
  18. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  19. extract($ctag->CAttribute->Items, EXTR_SKIP);
  20. if (get_class($refObj) != "Archives") {
  21. return "暂无相关内容";
  22. }
  23. if (empty($refObj->Fields[$name])) {
  24. return "暂无相关内容";
  25. }
  26. if (!isset($refObj->ChannelUnit->ChannelFields[$name])) {
  27. return "暂无相关内容";
  28. }
  29. if (empty($tablewidth)) $tablewidth = 100;
  30. if (empty($col)) $col = 1;
  31. $colWidth = ceil(100 / $col);
  32. $tablewidth = $tablewidth."%";
  33. $colWidth = $colWidth."%";
  34. $ids = array();
  35. $channelid = $refObj->ChannelUnit->ChannelFields[$name]["channel"];
  36. $odb = "";
  37. if ($channelid > 0) {
  38. $odb = " ORDER BY arc.sortrank DESC";
  39. } else {
  40. $odb = " ORDER BY arc.senddate DESC";
  41. }
  42. if ($orderby == "click") {
  43. $odb = " ORDER BY arc.click DESC";
  44. }
  45. if ($channelid > 0) {
  46. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
  47. tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  48. FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  49. where arc.arcrank>-1 AND arc.id IN (".$refObj->Fields[$name].") $odb";
  50. } else {
  51. $gquery = "SELECT addtable,listfields FROM `#@__channeltype` WHERE id='$channelid' ";
  52. $grow = $dsql->GetOne($gquery);
  53. $maintable = trim($grow['addtable']);
  54. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
  55. tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
  56. FROM `{$maintable}` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  57. where arc.arcrank>-1 AND arc.aid IN (".$refObj->Fields[$name].") $odb";
  58. }
  59. $innertext = trim($ctag->GetInnerText());
  60. if ($innertext == '') $innertext = GetSysTemplets('part_arclist.htm');
  61. $dsql->SetQuery($query);
  62. $dsql->Execute('al');
  63. $artlist = '';
  64. if ($col > 1) {
  65. $artlist = "<table width='$tablewidth' cellspacing='0' cellpadding='0'>\r\n";
  66. }
  67. $dtp2 = new DedeTagParse();
  68. $dtp2->SetNameSpace('field', '[', ']');
  69. $dtp2->LoadString($innertext);
  70. $GLOBALS['autoindex'] = 0;
  71. $line = $row;
  72. for ($i = 0; $i < $line; $i++) {
  73. if ($col > 1) $artlist .= "<tr>\r\n";
  74. for ($j = 0; $j < $col; $j++) {
  75. if ($col > 1) $artlist .= " <td width='$colWidth'>\r\n";
  76. if ($row = $dsql->GetArray("al")) {
  77. if ($channelid > 0) {
  78. $row['id'] = $row['id'];
  79. } else {
  80. $row['id'] = $row['aid'];
  81. }
  82. $ids[] = $row['id'];
  83. $row['description'] = isset($row['description']) ? $row['description'] : "";
  84. $row['filename'] = isset($row['filename']) ? $row['filename'] : "";
  85. $row['money'] = isset($row['money']) ? $row['money'] : 0;
  86. $row['ismake'] = isset($row['ismake']) ? $row['ismake'] : 0;
  87. //处理一些特殊字段
  88. $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
  89. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  90. $row['arcrank'] = $row['corank'];
  91. }
  92. $row['filename'] = $row['arcurl'] = GetFileUrl(
  93. $row['id'],
  94. $row['typeid'],
  95. $row['senddate'],
  96. $row['title'],
  97. $row['ismake'],
  98. $row['arcrank'],
  99. $row['namerule'],
  100. $row['typedir'],
  101. $row['money'],
  102. $row['filename'],
  103. $row['moresite'],
  104. $row['siteurl'],
  105. $row['sitepath']
  106. );
  107. $row['typeurl'] = GetTypeUrl(
  108. $row['typeid'],
  109. $row['typedir'],
  110. $row['isdefault'],
  111. $row['defaultname'],
  112. $row['ispart'],
  113. $row['namerule2'],
  114. $row['moresite'],
  115. $row['siteurl'],
  116. $row['sitepath']
  117. );
  118. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  119. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  120. }
  121. if (!preg_match("#^(http|https):\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  122. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  123. }
  124. $row['picname'] = $row['litpic'];
  125. $row['pubdate'] = isset($row['pubdate']) ? $row['pubdate'] : $row['senddate'];
  126. $row['stime'] = GetDateMK($row['pubdate']);
  127. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  128. $row['image'] = "<img src='".$row['picname']."' title='".preg_replace("#['><]#", "", $row['title'])."'>";
  129. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  130. $row['fulltitle'] = $row['title'];
  131. $row['title'] = cn_substr($row['title'], $titlelen);
  132. if (isset($row['color']) && $row['color'] != '') $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  133. if (preg_match('#b#', $row['flag'])) $row['title'] = "".$row['title']."";
  134. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  135. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  136. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  137. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  138. if (is_array($dtp2->CTags)) {
  139. foreach ($dtp2->CTags as $k => $ctag) {
  140. if ($ctag->GetName() == 'array') {
  141. $dtp2->Assign($k, $row);
  142. } else {
  143. if (isset($row[$ctag->GetName()])) $dtp2->Assign($k, $row[$ctag->GetName()]);
  144. else $dtp2->Assign($k, '');
  145. }
  146. }
  147. $GLOBALS['autoindex']++;
  148. }
  149. $artlist .= $dtp2->GetResult()."\r\n";
  150. }
  151. //if hasRow
  152. else {
  153. $artlist .= '';
  154. }
  155. if ($col > 1) $artlist .= " </td>\r\n";
  156. }
  157. //Loop Col
  158. if ($col > 1) $i += $col - 1;
  159. if ($col > 1) $artlist .= " </tr>\r\n";
  160. }
  161. //loop line
  162. if ($col > 1) $artlist .= " </table>\r\n";
  163. $dsql->FreeResult("al");
  164. return $artlist;
  165. }