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

84 lines
2.5KB

  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|,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. $key = md5($url);
  21. try {
  22. if ($path=='') {
  23. $jsonq = new Jsonq($url);
  24. $revalue = GetCache("tagjsonq2", $key);
  25. if (!empty($revalue)) {
  26. return $revalue;
  27. }
  28. $revalue = "";
  29. $ctp = new DedeTagParse();
  30. $ctp->SetNameSpace('field', '[', ']');
  31. $ctp->LoadSource($Innertext);
  32. foreach ($ctp->CTags as $tagid => $ctag) {
  33. $tagname = $ctag->GetName();
  34. $vv = $jsonq->from($tagname)->get();
  35. $ctp->Assign($tagid, $vv);
  36. $jsonq->reset();
  37. }
  38. $revalue .= $ctp->GetResult();
  39. SetCache("tagjsonq2", $key, $revalue, $cachetime);
  40. return $revalue;
  41. }
  42. $row = GetCache("tagjsonq", $key);
  43. if (!is_array($row) || $cachetime == 0) {
  44. $jsonq = new Jsonq($url);
  45. $row = $jsonq->from($path)->get();
  46. SetCache("tagjsonq", $key, $row, $cachetime);
  47. }
  48. if (!is_array($row)) {
  49. return "";
  50. }
  51. $ctp = new DedeTagParse();
  52. $ctp->SetNameSpace('field', '[', ']');
  53. $ctp->LoadSource($Innertext);
  54. $GLOBALS['autoindex'] = 0;
  55. $revalue = "";
  56. foreach ($row as $key => $value) {
  57. $GLOBALS['autoindex']++;
  58. foreach ($ctp->CTags as $tagid => $ctag) {
  59. if ($ctag->GetName() == 'array') {
  60. $ctp->Assign($tagid, $value);
  61. } else {
  62. if (!empty($value[$ctag->GetName()])) {
  63. $ctp->Assign($tagid, $value[$ctag->GetName()]);
  64. } else {
  65. $ctp->Assign($tagid, "");
  66. }
  67. }
  68. }
  69. $revalue .= $ctp->GetResult();
  70. }
  71. return $revalue;
  72. } catch (Exception $e) {
  73. return "";
  74. }
  75. }