国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

88 líneas
2.9KB

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