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

161 lines
7.0KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * 关联文档标签
  5. *
  6. * @version $id:relation.lib.php 9:29 2020年9月23日 tianya $
  7. * @package DedeBIZ.Taglib
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license GNU GPL v2 (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,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE arc.arcrank>-1 AND arc.id IN (".$refObj->Fields[$name].") $odb";
  47. } else {
  48. $gquery = "SELECT addtable,listfields FROM `#@__channeltype` WHERE id='$channelid' ";
  49. $grow = $dsql->GetOne($gquery);
  50. $maintable = trim($grow['addtable']);
  51. $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `{$maintable}` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id WHERE arc.arcrank>-1 AND arc.aid IN (".$refObj->Fields[$name].") $odb";
  52. }
  53. $innertext = trim($ctag->GetInnerText());
  54. if ($innertext == '') $innertext = GetSysTemplets('part_arclist.htm');
  55. $dsql->SetQuery($query);
  56. $dsql->Execute('al');
  57. $artlist = '';
  58. if ($col > 1) {
  59. $artlist = "<table width='$tablewidth'>\r\n";
  60. }
  61. $dtp2 = new DedeTagParse();
  62. $dtp2->SetNameSpace('field', '[', ']');
  63. $dtp2->LoadString($innertext);
  64. $GLOBALS['autoindex'] = 0;
  65. $line = $row;
  66. for ($i = 0; $i < $line; $i++) {
  67. if ($col > 1) $artlist .= "<tr>\r\n";
  68. for ($j = 0; $j < $col; $j++) {
  69. if ($col > 1) $artlist .= "<td width='$colWidth'>\r\n";
  70. if ($row = $dsql->GetArray("al")) {
  71. if ($channelid > 0) {
  72. $row['aid'] = $row['id'];
  73. } else {
  74. $row['id'] = $row['aid'];
  75. }
  76. $ids[] = $row['id'];
  77. $row['description'] = isset($row['description']) ? $row['description'] : "";
  78. $row['filename'] = isset($row['filename']) ? $row['filename'] : "";
  79. $row['money'] = isset($row['money']) ? $row['money'] : 0;
  80. $row['ismake'] = isset($row['ismake']) ? $row['ismake'] : 0;
  81. //处理一些特殊字段
  82. $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
  83. if ($row['corank'] > 0 && $row['arcrank'] == 0) {
  84. $row['arcrank'] = $row['corank'];
  85. }
  86. $row['filename'] = $row['arcurl'] = GetFileUrl(
  87. $row['id'],
  88. $row['typeid'],
  89. $row['senddate'],
  90. $row['title'],
  91. $row['ismake'],
  92. $row['arcrank'],
  93. $row['namerule'],
  94. $row['typedir'],
  95. $row['money'],
  96. $row['filename'],
  97. $row['moresite'],
  98. $row['siteurl'],
  99. $row['sitepath']
  100. );
  101. $row['typeurl'] = GetTypeUrl(
  102. $row['typeid'],
  103. $row['typedir'],
  104. $row['isdefault'],
  105. $row['defaultname'],
  106. $row['ispart'],
  107. $row['namerule2'],
  108. $row['moresite'],
  109. $row['siteurl'],
  110. $row['sitepath']
  111. );
  112. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  113. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  114. }
  115. if (!preg_match("#^(http|https):\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  116. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  117. }
  118. $row['picname'] = $row['litpic'];
  119. $row['pubdate'] = isset($row['pubdate']) ? $row['pubdate'] : $row['senddate'];
  120. $row['stime'] = GetDateMK($row['pubdate']);
  121. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  122. $row['image'] = "<img src='".$row['picname']."' title='".preg_replace("#['><]#", "", $row['title'])."'>";
  123. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  124. $row['fulltitle'] = $row['title'];
  125. $row['title'] = cn_substr($row['title'], $titlelen);
  126. if (isset($row['color']) && $row['color'] != '') $row['title'] = "<span style='color:".$row['color']."'>".$row['title']."</span>";
  127. if (preg_match('#b#', $row['flag'])) $row['title'] = "".$row['title']."";
  128. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  129. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  130. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  131. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  132. if (is_array($dtp2->CTags)) {
  133. foreach ($dtp2->CTags as $k => $ctag) {
  134. if ($ctag->GetName() == 'array') {
  135. $dtp2->Assign($k, $row);
  136. } else {
  137. if (isset($row[$ctag->GetName()])) $dtp2->Assign($k, $row[$ctag->GetName()]);
  138. else $dtp2->Assign($k, '');
  139. }
  140. }
  141. $GLOBALS['autoindex']++;
  142. }
  143. $artlist .= $dtp2->GetResult()."\r\n";
  144. }
  145. //if hasRow
  146. else {
  147. $artlist .= '';
  148. }
  149. if ($col > 1) $artlist .= "</td>\r\n";
  150. }
  151. //Loop Col
  152. if ($col > 1) $i += $col - 1;
  153. if ($col > 1) $artlist .= "</tr>\r\n";
  154. }
  155. //loop line
  156. if ($col > 1) $artlist .= "</table>\r\n";
  157. $dsql->FreeResult("al");
  158. return $artlist;
  159. }
  160. ?>