function lib_json(&$ctag, &$refObj) { global $dsql, $sqlCt, $cfg_soft_lang; $attlist = "url|"; FillAttsDefault($ctag->CAttribute->Items, $attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $Innertext = trim($ctag->GetInnerText()); if ($url == '' || $Innertext == '') { return ''; } $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); $ctp->LoadSource($Innertext); $mcache = new MiniCache(); $GLOBALS['autoindex'] = 0; $chash = md5($url); if (!($row = $mcache->Get($chash))) { $content = @file_get_contents($url); $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $row = $json->decode($content); if ($cfg_soft_lang != 'utf-8') { $row = AutoCharset($row, 'utf-8', 'gb2312'); } $mcache->Save($chash, $row, $cache); } $revalue = ""; foreach ($row as $key => $value) { $GLOBALS['autoindex']++; foreach ($ctp->CTags as $tagid => $ctag) { if ($ctag->GetName() == 'array') { $ctp->Assign($tagid, $value); } else { if (!empty($value[$ctag->GetName()])) { $ctp->Assign($tagid, $value[$ctag->GetName()]); } else { $ctp->Assign($tagid, ""); } } } $revalue .= $ctp->GetResult(); } return $revalue; }