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

234 lines
12KB

  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 GNU GPL v2 (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, $cfg_rewrite, $cfg_cmspath, $cfg_mainsite, $em_nativeplaces, $em_infotypes;
  29. //$attlist="row|10,titlelen|30";
  30. //FillAttsDefault($ctag->CAttribute->Items,$attlist);
  31. //extract($ctag->CAttribute->Items, EXTR_SKIP);
  32. $cmspath = ((empty($cfg_cmspath) || !preg_match("#\/$#", $cfg_cmspath)) ? $cfg_cmspath.'/' : $cfg_cmspath);
  33. $baseurl = preg_replace("#\/$#", '', $cfg_mainsite).$cmspath;
  34. $smalltypes = '';
  35. if($baseurl == "/") $baseurl = "";
  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('nativeplace' => '', 'infotype' => '', 'typeid' => $typeid, 'channelid' => $channelid, 'linkallplace' => '', 'linkalltype' => '');
  53. $fields['nativeplace'] = $fields['infotype'] = '';
  54. if ($cfg_rewrite == 'Y') {
  55. $fields['linkallplace'] = "<a href='{$baseurl}/list-{$typeid}?infotype={$infotype}&channelid={$channelid}'>不限</a>";
  56. $fields['linkalltype'] = "<a href='{$baseurl}/list-{$typeid}?nativeplace={$nativeplace}&channelid={$channelid}'>不限</a>";
  57. } else {
  58. $fields['linkallplace'] = "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$infotype}'>不限</a>";
  59. $fields['linkalltype'] = "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}'>不限</a>";
  60. }
  61. //地区
  62. if (empty($nativeplace)) {
  63. foreach ($em_nativeplaces as $eid => $em) {
  64. if ($eid % 500 != 0) continue;
  65. if ($cfg_rewrite == 'Y') {
  66. $fields['nativeplace'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$eid}&infotype={$infotype}&channelid={$channelid}'>{$em}</a>\r\n";
  67. } else {
  68. $fields['nativeplace'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  69. }
  70. }
  71. } else {
  72. $sontype = (($nativeplace % 500 != 0) ? $nativeplace : 0);//子级联动分类
  73. $toptype = (($nativeplace % 500 == 0) ? (int)$nativeplace : (int)($nativeplace - ($nativeplace % 500)));//顶级联动分类
  74. if ($cfg_rewrite == 'Y') {
  75. $fields['nativeplace'] = "<a href='{$baseurl}/list-{$typeid}?nativeplace={$toptype}&infotype={$infotype}&channelid={$channelid}'> {$em_nativeplaces[$toptype]}</a><br>";
  76. } else {
  77. $fields['nativeplace'] = "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$toptype}&infotype={$infotype}'> {$em_nativeplaces[$toptype]}</a><br>";
  78. }
  79. if ($nativeplace % 500 == 0) {
  80. //1级分类
  81. foreach ($em_nativeplaces as $eid => $em) {
  82. if ($eid < $toptype + 1 || $eid > $toptype + 499) continue;
  83. if (is_str_float($eid)) continue;//仅显示2级
  84. if ($eid == $nativeplace) {
  85. $fields['nativeplace'] .= "{$em}\r\n";
  86. } else {
  87. if ($cfg_rewrite == 'Y') {
  88. $fields['nativeplace'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$eid}&infotype={$infotype}&channelid={$channelid}'>{$em}</a>\r\n";
  89. } else {
  90. $fields['nativeplace'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  91. }
  92. }
  93. }
  94. } else if (!is_str_float($nativeplace)) {
  95. //2级分类
  96. $fields['nativeplace'] .= "<span>{$em_nativeplaces[$sontype]}</span>";
  97. $i = 0;
  98. $ff = '';
  99. foreach ($em_nativeplaces as $eid => $em) {
  100. if ($eid < $sontype + 1 && $eid > $sontype) {
  101. if (is_str_float($eid)) {
  102. $i++;
  103. }
  104. if ($eid === $nativeplace) {
  105. $ff .= " {$em}\r\n";
  106. } else {
  107. if ($cfg_rewrite == 'Y') {
  108. $ff .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$eid}&infotype={$infotype}&channelid={$channelid}'>{$em}</a>\r\n";
  109. } else {
  110. $ff .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  111. }
  112. }
  113. }
  114. }
  115. if ($i > 0) $fields['nativeplace'] .= "<br>";
  116. $fields['nativeplace'] .= $ff;
  117. } else {
  118. //3级分类
  119. $t = intval($nativeplace);
  120. if ($cfg_rewrite == 'Y') {
  121. $fields['nativeplace'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$t}&infotype={$infotype}&channelid={$channelid}'> {$em_nativeplaces[$t]}</a><br>";
  122. } else {
  123. $fields['nativeplace'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$t}&infotype={$infotype}'> {$em_nativeplaces[$t]}</a><br>";
  124. }
  125. foreach ($em_nativeplaces as $eid => $em) {
  126. if ($eid < $t + 1 && $eid > $t) {
  127. if ($eid === $nativeplace) {
  128. $fields['nativeplace'] .= " {$em}\r\n";
  129. } else {
  130. if ($cfg_rewrite == 'Y') {
  131. $fields['nativeplace'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$eid}&infotype={$infotype}&channelid={$channelid}'>{$em}</a>\r\n";
  132. } else {
  133. $fields['nativeplace'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$eid}&infotype={$infotype}'>{$em}</a>\r\n";
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. //信息类型
  141. if (empty($infotype) || !is_array($smalltypes)) {
  142. foreach ($em_infotypes as $eid => $em) {
  143. if (!is_array($smalltypes) || $eid % 500 != 0) continue;
  144. if (is_array($smalltypes) && !in_array($eid, $smalltypes)) continue;
  145. if ($eid == $infotype) {
  146. $fields['infotype'] .= " {$em}\r\n";
  147. } else {
  148. if ($cfg_rewrite == 'Y') {
  149. $fields['infotype'] .= "<a href='{$baseurl}/list-{$typeid}?infotype={$eid}&nativeplace={$nativeplace}&channelid={$channelid}'>{$em}</a>\r\n";
  150. } else {
  151. $fields['infotype'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$eid}&nativeplace={$nativeplace}'>{$em}</a>\r\n";
  152. }
  153. }
  154. }
  155. } else {
  156. $sontype = (($infotype % 500 != 0) ? $infotype : 0);
  157. $toptype = (($infotype % 500 == 0) ? (int)$infotype : (int)($infotype - ($infotype % 500)));
  158. if ($cfg_rewrite == 'Y') {
  159. $fields['infotype'] = "<a href='{$baseurl}/list-{$typeid}?infotype={$toptype}&nativeplace={$nativeplace}&channelid={$channelid}'>{$em_infotypes[$toptype]}</a><br>";
  160. } else {
  161. $fields['infotype'] = "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&infotype={$toptype}&nativeplace={$nativeplace}'>{$em_infotypes[$toptype]}</a><br>";
  162. }
  163. if ($infotype % 500 == 0) {
  164. //1级分类
  165. foreach ($em_infotypes as $eid => $em) {
  166. if ($eid < $toptype + 1 || $eid > $toptype + 499) continue;
  167. if (is_str_float($eid)) continue;//仅显示2级
  168. if ($eid == $infotype) {
  169. $fields['infotype'] .= "{$em}\r\n";
  170. } else {
  171. if ($cfg_rewrite == 'Y') {
  172. $fields['infotype'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$nativeplace}&infotype={$eid}&channelid={$channelid}'>{$em}</a>\r\n";
  173. } else {
  174. $fields['infotype'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  175. }
  176. }
  177. }
  178. } else if (!is_str_float($infotype)) {
  179. //2级分类
  180. $fields['infotype'] .= "<span>{$em_infotypes[$sontype]}</span>";
  181. $i = 0;
  182. $ff = '';
  183. foreach ($em_infotypes as $eid => $em) {
  184. if ($eid < $sontype + 1 && $eid > $sontype) {
  185. if (is_str_float($eid)) {
  186. $i++;
  187. }
  188. if ($eid === $infotype) {
  189. $ff .= " {$em}\r\n";
  190. } else {
  191. if ($cfg_rewrite == 'Y') {
  192. $ff .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$nativeplace}&infotype={$eid}&channelid={$channelid}'>{$em}</a>\r\n";
  193. } else {
  194. $ff .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  195. }
  196. }
  197. }
  198. }
  199. if ($i > 0) $fields['infotype'] .= "<br>";
  200. $fields['infotype'] .= $ff;
  201. } else {
  202. //3级分类
  203. $t = intval($infotype);
  204. if ($cfg_rewrite == 'Y') {
  205. $fields['infotype'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$nativeplace}&infotype={$t}&channelid={$channelid}'> {$em_infotypes[$t]}</a><br>";
  206. } else {
  207. $fields['infotype'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$t}'> {$em_infotypes[$t]}</a><br>";
  208. }
  209. foreach ($em_infotypes as $eid => $em) {
  210. if ($eid < $t + 1 && $eid > $t) {
  211. if ($eid === $infotype) {
  212. $fields['infotype'] .= " {$em}\r\n";
  213. } else {
  214. if ($cfg_rewrite == 'Y') {
  215. $fields['infotype'] .= "<a href='{$baseurl}/list-{$typeid}?nativeplace={$nativeplace}&infotype={$eid}&channelid={$channelid}'>{$em}</a>\r\n";
  216. } else {
  217. $fields['infotype'] .= "<a href='{$baseurl}/apps/list.php?channelid={$channelid}&tid={$typeid}&nativeplace={$nativeplace}&infotype={$eid}'>{$em}</a>\r\n";
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. if (is_array($ctp->CTags)) {
  225. foreach ($ctp->CTags as $tagid => $ctag) {
  226. if (isset($fields[$ctag->GetName()])) {
  227. $ctp->Assign($tagid, $fields[$ctag->GetName()]);
  228. }
  229. }
  230. $revalue .= $ctp->GetResult();
  231. }
  232. return $revalue;
  233. }
  234. ?>