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

182 lines
7.2KB

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