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

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