国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

87 wiersze
2.9KB

  1. <?php
  2. /**
  3. * JSONQ标签
  4. *
  5. * @version $id:jsonq.lib.php 2023年3月20日 tianya $
  6. * @package DedeBIZ.Taglib
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(DEDEINC . "/libraries/jsonq/Jsonq.php");
  12. helper('cache');
  13. function lib_jsonq(&$ctag, &$refObj)
  14. {
  15. $attlist = "url|,path|,typeid|,row|,apikey|,cachetime|3600";
  16. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  17. extract($ctag->CAttribute->Items, EXTR_SKIP);
  18. $Innertext = trim($ctag->GetInnerText());
  19. if ($url == '' || $Innertext == '') return '';
  20. if (!empty($typeid)) {
  21. $typeid = intval($typeid);
  22. }
  23. if ($typeid > 0) {
  24. $timestamp = time();
  25. $sign = sha1($typeid.$timestamp.$apikey.'1'.'10');
  26. $u = "tid={$typeid}&mod=1&timestamp={$timestamp}&PageNo=1&PageSize={$row}&sign={$sign}";
  27. $url = $url."/apps/list.php?{$u}";
  28. $path = "$.lists";
  29. }
  30. $key = md5($url);
  31. try {
  32. if ($path=='') {
  33. //选择器获取某个特定值
  34. $jsonq = new Jsonq($url);
  35. $revalue = GetCache("tagjsonq2", $key);
  36. if (!empty($revalue)) {
  37. return $revalue;
  38. }
  39. $revalue = "";
  40. $ctp = new DedeTagParse();
  41. $ctp->SetNameSpace('field', '[', ']');
  42. $ctp->LoadSource($Innertext);
  43. foreach ($ctp->CTags as $tagid => $ctag) {
  44. $tagname = $ctag->GetName();
  45. $vv = $jsonq->from($tagname)->get();
  46. $ctp->Assign($tagid, $vv);
  47. $jsonq->reset();
  48. }
  49. $revalue .= $ctp->GetResult();
  50. SetCache("tagjsonq2", $key, $revalue, $cachetime);
  51. return $revalue;
  52. }
  53. $row = GetCache("tagjsonq", $key);
  54. if (!is_array($row) || $cachetime == 0) {
  55. $jsonq = new Jsonq($url);
  56. $row = $jsonq->from($path)->get();
  57. SetCache("tagjsonq", $key, $row, $cachetime);
  58. }
  59. if (!is_array($row)) {
  60. return "";
  61. }
  62. $ctp = new DedeTagParse();
  63. $ctp->SetNameSpace('field', '[', ']');
  64. $ctp->LoadSource($Innertext);
  65. $GLOBALS['autoindex'] = 0;
  66. $revalue = "";
  67. foreach ($row as $key => $value) {
  68. $GLOBALS['autoindex']++;
  69. foreach ($ctp->CTags as $tagid => $ctag) {
  70. if ($ctag->GetName() == 'array') {
  71. $ctp->Assign($tagid, $value);
  72. } else {
  73. if (!empty($value[$ctag->GetName()])) {
  74. $ctp->Assign($tagid, $value[$ctag->GetName()]);
  75. } else {
  76. $ctp->Assign($tagid, "");
  77. }
  78. }
  79. }
  80. $revalue .= $ctp->GetResult();
  81. }
  82. return $revalue;
  83. } catch (Exception $e) {
  84. return "";
  85. }
  86. }
  87. ?>