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

169 lines
6.8KB

  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 DedeCMS.Taglib
  7. * @copyright Copyright (c) 2020, 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. {
  73. if($col>1) $artlist .= "<tr>\r\n";
  74. for($j=0; $j < $col; $j++)
  75. {
  76. if($col>1) $artlist .= " <td width='$colWidth'>\r\n";
  77. if($row = $dsql->GetArray("al"))
  78. {
  79. if ($channelid > 0) {
  80. $row['id'] = $row['id'];
  81. } else {
  82. $row['id'] = $row['aid'];
  83. }
  84. $ids[] = $row['id'];
  85. $row['description'] = isset($row['description'])? $row['description'] : "";
  86. $row['filename'] = isset($row['filename'])? $row['filename'] : "";
  87. $row['money'] = isset($row['money'])? $row['money'] : 0;
  88. $row['ismake'] = isset($row['ismake'])? $row['ismake'] : 0;
  89. //处理一些特殊字段
  90. $row['info'] = $row['infos'] = cn_substr($row['description'],$infolen);
  91. if($row['corank'] > 0 && $row['arcrank']==0)
  92. {
  93. $row['arcrank'] = $row['corank'];
  94. }
  95. $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  96. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  97. $row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],
  98. $row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  99. if($row['litpic'] == '-' || $row['litpic'] == '')
  100. {
  101. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  102. }
  103. if(!preg_match("#^http:\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  104. {
  105. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  106. }
  107. $row['picname'] = $row['litpic'];
  108. $row['pubdate'] = isset($row['pubdate'])? $row['pubdate'] : $row['senddate'];
  109. $row['stime'] = GetDateMK($row['pubdate']);
  110. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  111. $row['image'] = "<img src='".$row['picname']."' border='0' alt='".preg_replace("#['><]#","",$row['title'])."'>";
  112. $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
  113. $row['fulltitle'] = $row['title'];
  114. $row['title'] = cn_substr($row['title'], $titlelen);
  115. if(isset($row['color']) && $row['color']!='') $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
  116. if(preg_match('#b#', $row['flag'])) $row['title'] = "<strong>".$row['title']."</strong>";
  117. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  118. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  119. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  120. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  121. if(is_array($dtp2->CTags))
  122. {
  123. foreach($dtp2->CTags as $k=>$ctag)
  124. {
  125. if($ctag->GetName()=='array') {
  126. $dtp2->Assign($k,$row);
  127. }
  128. else {
  129. if(isset($row[$ctag->GetName()])) $dtp2->Assign($k,$row[$ctag->GetName()]);
  130. else $dtp2->Assign($k,'');
  131. }
  132. }
  133. $GLOBALS['autoindex']++;
  134. }
  135. $artlist .= $dtp2->GetResult()."\r\n";
  136. }
  137. //if hasRow
  138. else
  139. {
  140. $artlist .= '';
  141. }
  142. if($col>1) $artlist .= " </td>\r\n";
  143. }
  144. //Loop Col
  145. if($col>1) $i += $col - 1;
  146. if($col>1) $artlist .= " </tr>\r\n";
  147. }
  148. //loop line
  149. if($col>1) $artlist .= " </table>\r\n";
  150. $dsql->FreeResult("al");
  151. return $artlist;
  152. }