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

188 lines
9.0KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * 分类信息地区与类型快捷链接标签
  5. *
  6. * @version $id:infolink.lib.php 9:29 2010年7月6日 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. require_once(DEDEINC.'/enums.func.php');
  13. $cachefile = DEDESTATIC.'/enums/nativeplace.json';
  14. $data = json_decode(file_get_contents($cachefile));
  15. foreach ($data as $key => $value) {
  16. $GLOBALS['em_nativeplaces'][$key] = $value;
  17. }
  18. $cachefile = DEDESTATIC.'/enums/infotype.json';
  19. $data = json_decode(file_get_contents($cachefile));
  20. foreach ($data as $key => $value) {
  21. $GLOBALS['em_infotypes'][$key] = $value;
  22. }
  23. function is_str_float($value){
  24. return ((int)$value != $value) ;
  25. }
  26. function lib_infolink(&$ctag, &$refObj)
  27. {
  28. global $dsql, $nativeplace, $infotype, $hasSetEnumJs, $cfg_cmspath, $cfg_mainsite, $em_nativeplaces, $em_infotypes;
  29. //属性处理
  30. //$attlist="row|12,titlelen|30";
  31. //FillAttsDefault($ctag->CAttribute->Items,$attlist);
  32. //extract($ctag->CAttribute->Items, EXTR_SKIP);
  33. $cmspath = ((empty($cfg_cmspath) || !preg_match("#\/$#", $cfg_cmspath)) ? $cfg_cmspath.'/' : $cfg_cmspath);
  34. $baseurl = preg_replace("#\/$#", '', $cfg_mainsite).$cmspath;
  35. $smalltypes = '';
  36. if (!empty($refObj->TypeLink->TypeInfos['smalltypes'])) {
  37. $smalltypes = explode(',', $refObj->TypeLink->TypeInfos['smalltypes']);
  38. }
  39. if (empty($refObj->Fields['typeid'])) {
  40. $row = $dsql->GetOne("SELECT id FROM `#@__arctype` WHERE channeltype='-8' And reid = '0' ");
  41. $typeid = (is_array($row) ? $row['id'] : 0);
  42. } else {
  43. $typeid = $refObj->Fields['typeid'];
  44. }
  45. $innerText = trim($ctag->GetInnerText());
  46. if (empty($innerText)) $innerText = GetSysTemplets("info_link.htm");
  47. $ctp = new DedeTagParse();
  48. $ctp->SetNameSpace('field', '[', ']');
  49. $ctp->LoadSource($innerText);
  50. $revalue = $seli = '';
  51. $channelid = (empty($refObj->TypeLink->TypeInfos['channeltype']) ? -8 : $refObj->TypeLink->TypeInfos['channeltype']);
  52. $fields = array(
  53. 'nativeplace' => '', 'infotype' => '', 'typeid' => $typeid,
  54. 'channelid' => $channelid, 'linkallplace' => '', 'linkalltype' => ''
  55. );
  56. $fields['nativeplace'] = $fields['infotype'] = '';
  57. $fields['linkallplace'] = "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$infotype}'>不限</a>";
  58. $fields['linkalltype'] = "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}'>不限</a>";
  59. //地区链接
  60. if (empty($nativeplace)) {
  61. foreach ($em_nativeplaces as $eid => $em) {
  62. if ($eid % 500 != 0) continue;
  63. $fields['nativeplace'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  64. }
  65. } else {
  66. $sontype = (($nativeplace % 500 != 0) ? $nativeplace : 0); //子集
  67. $toptype = (($nativeplace % 500 == 0) ? (int)$nativeplace : (int)($nativeplace - ($nativeplace % 500))); //顶级联动分类
  68. $fields['nativeplace'] = "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$toptype}&infotype={$infotype}'> {$em_nativeplaces[$toptype]}</a> -";
  69. if ($nativeplace % 500 == 0) {
  70. //1级分类
  71. foreach ($em_nativeplaces as $eid => $em) {
  72. if ($eid < $toptype + 1 || $eid > $toptype + 499) continue;
  73. if (is_str_float($eid)) continue; //仅显示2级
  74. if ($eid == $nativeplace) {
  75. $fields['nativeplace'] .= " {$em}\r\n";
  76. } else {
  77. $fields['nativeplace'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  78. }
  79. }
  80. } else if (!is_str_float($nativeplace)) {
  81. //2级分类
  82. $fields['nativeplace'] .= "<span> {$em_nativeplaces[$sontype]}</span>";
  83. $i = 0;
  84. $ff = "";
  85. foreach ($em_nativeplaces as $eid => $em) {
  86. if ($eid < $sontype + 1 && $eid > $sontype)
  87. {
  88. if (is_str_float($eid)) {
  89. $i++;
  90. }
  91. if ($eid === $nativeplace) {
  92. $ff .= " {$em}\r\n";
  93. } else {
  94. $ff .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  95. }
  96. }
  97. }
  98. if ($i > 0) $fields['nativeplace'] .= " - ";
  99. $fields['nativeplace'] .= $ff;
  100. } else {
  101. //3级分类
  102. $t = intval($nativeplace);
  103. $fields['nativeplace'] .= "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$t}&infotype={$infotype}'> {$em_nativeplaces[$t]}</a> -";
  104. foreach ($em_nativeplaces as $eid => $em) {
  105. if ($eid < $t + 1 && $eid > $t)
  106. {
  107. if ($eid === $nativeplace) {
  108. $fields['nativeplace'] .= " {$em}\r\n";
  109. } else {
  110. $fields['nativeplace'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  111. }
  112. }
  113. }
  114. }
  115. }
  116. //小分类链接
  117. if (empty($infotype) || !is_array($smalltypes)) {
  118. foreach ($em_infotypes as $eid => $em) {
  119. if (!is_array($smalltypes) || $eid % 500 != 0) continue;
  120. if (is_array($smalltypes) && !in_array($eid, $smalltypes)) continue;
  121. if ($eid == $infotype) {
  122. $fields['infotype'] .= " {$em}\r\n";
  123. } else {
  124. $fields['infotype'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$eid}&nativeplace={$nativeplace}'>{$em}</a>\r\n";
  125. }
  126. }
  127. } else {
  128. $sontype = (($infotype % 500 != 0) ? $infotype : 0);
  129. $toptype = (($infotype % 500 == 0) ? (int)$infotype : (int)($infotype - ($infotype % 500)));
  130. $fields['infotype'] = "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$toptype}&nativeplace={$nativeplace}'>{$em_infotypes[$toptype]}</a> - ";
  131. if ($infotype % 500 == 0) {
  132. //1级分类
  133. foreach ($em_infotypes as $eid => $em) {
  134. if ($eid < $toptype + 1 || $eid > $toptype + 499) continue;
  135. if (is_str_float($eid)) continue; //仅显示2级
  136. if ($eid == $infotype) {
  137. $fields['infotype'] .= " {$em}\r\n";
  138. } else {
  139. $fields['infotype'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  140. }
  141. }
  142. } else if (!is_str_float($infotype)) {
  143. //2级分类
  144. $fields['infotype'] .= "<span> {$em_infotypes[$sontype]}</span>";
  145. $i = 0;
  146. $ff = "";
  147. foreach ($em_infotypes as $eid => $em) {
  148. if ($eid < $sontype + 1 && $eid > $sontype)
  149. {
  150. if (is_str_float($eid)) {
  151. $i++;
  152. }
  153. if ($eid === $infotype) {
  154. $ff .= " {$em}\r\n";
  155. } else {
  156. $ff .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  157. }
  158. }
  159. }
  160. if ($i > 0) $fields['infotype'] .= " - ";
  161. $fields['infotype'] .= $ff;
  162. } else {
  163. //3级分类
  164. $t = intval($infotype);
  165. $fields['infotype'] .= "<a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$t}'> {$em_infotypes[$t]}</a> -";
  166. foreach ($em_infotypes as $eid => $em) {
  167. if ($eid < $t + 1 && $eid > $t)
  168. {
  169. if ($eid === $infotype) {
  170. $fields['infotype'] .= " {$em}\r\n";
  171. } else {
  172. $fields['infotype'] .= " <a href='{$baseurl}apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  173. }
  174. }
  175. }
  176. }
  177. }
  178. if (is_array($ctp->CTags)) {
  179. foreach ($ctp->CTags as $tagid => $ctag) {
  180. if (isset($fields[$ctag->GetName()])) {
  181. $ctp->Assign($tagid, $fields[$ctag->GetName()]);
  182. }
  183. }
  184. $revalue .= $ctp->GetResult();
  185. }
  186. return $revalue;
  187. }
  188. ?>