function plugin_yahoo_gethtml($mode, $query, $type, $max, $target, $col) { include_once XOOPS_TRUST_PATH . '/class/hyp_common/hyp_simplexml.php'; if ($this->root->yahoo_application_id) { $this->appid = $this->root->yahoo_application_id; } if ($this->root->yahoo_app_upgrade_id) { $this->appid_upg = $this->root->yahoo_app_upgrade_id; } $qs = htmlspecialchars($query); // RESTリクエストの構築 $query = rawurlencode(mb_convert_encoding(trim($query), "UTF-8", $this->cont['SOURCE_ENCODING'])); $max = (int) $max; $type = trim(strtolower($type)); switch ($type) { case "and": case "all": $type = "all"; break; case "or": case "any": $type = "any"; break; case "word": case "phrase": $type = "phrase"; break; default: $type = "any"; } $mode = trim(strtolower($mode)); switch ($mode) { case "image": case "img": $mode = "img"; if ($this->appid_upg) { $url = 'http://search.yahooapis.jp/PremiumImageSearchService/V1/imageSearch?appid=' . $this->appid_upg; } else { $url = 'http://search.yahooapis.jp/ImageSearchService/V2/imageSearch?appid=' . $this->appid; } $url .= "&query={$query}&results={$max}&type={$type}"; break; case "movie": case "mov": $mode = "mov"; $url = "http://search.yahooapis.jp/VideoSearchService/V2/videoSearch?appid={$this->appid}&query={$query}&results={$max}&type={$type}"; break; case "related": case "rel": $mode = "rel"; $url = "http://search.yahooapis.jp/AssistSearchService/V1/webunitSearch?appid={$this->appid}&query={$query}&results={$max}"; break; case "web": default: $mode = "web"; if ($this->appid_upg) { $url = 'http://search.yahooapis.jp/PremiumWebSearchService/V1/webSearch?appid=' . $this->appid_upg; } else { $url = 'http://search.yahooapis.jp/WebSearchService/V2/webSearch?appid=' . $this->appid; } $url .= "&query={$query}&results={$max}&type={$type}"; } // データ取得 $xml = $this->func->http_request($url); if ($xml['rc'] == 200 && $xml['data']) { $xml = $xml['data']; $xm = new HypSimpleXML(); $xml = $xm->XMLstr_in($xml); // 該当データなし if (!$xml['totalResultsReturned']) { return sprintf($this->msg['msg_notfound'], $qs, $this->msg['msg_' . $mode]); } } else { // データ取得エラー return $this->msg['err_badres']; } // 該当データなし if (!$xml['totalResultsReturned']) { return sprintf($this->msg['msg_notfound'], $qs, $this->msg['msg_' . $mode]); } $func = "plugin_yahoo_build_" . $mode; $html = $this->{$func}($xml, $target, $col); return $html; }
function _sendQuery($params) { $url = $this->_getUrl($params); $timer = $this->cacheDir . 'hyp_hsa_' . $this->AccessKeyId . '.timer'; $loop = 0; if ($this->OneRequestPerSec) { while ($loop < $this->retry_count && is_file($timer) && filemtime($timer) >= time()) { $loop++; clearstatcache(); usleep($this->retry_interval * 1000); // 250ms } } if ($this->OneRequestPerSec && $loop >= $this->retry_count) { $this->xml = ''; $this->error = 'Request Error: Too busy.'; } else { if ($this->OneRequestPerSec) { HypCommonFunc::touch($timer); } $ht = new Hyp_HTTP_Request(); $ht->init(); $this->url = $ht->url = $url; $ht->get(); if ($ht->rc === 200 || $ht->rc === 403) { $data = $ht->data; $xm = new HypSimpleXML(); $this->xml = $xm->XMLstr_in($data); //var_dump($this->xml);exit(); if ($xm->error) { $this->error = $xm->error; } else { if ($error = @$this->xml['Items']['Request']['Errors']['Error']) { $this->error = mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['Items'][0]['Request']['Errors']['Error']) { $this->error = mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['OperationRequest']['Errors']['Error']) { $this->error = $error['Code'] . ': ' . mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['Error']) { $this->error = $error['Code'] . ': ' . mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } } } } } } else { $this->xml = ''; $this->error = 'HTTP Error: ' . $ht->rc; } } }
function _sendQuery($params) { $this->url = $this->_getUrl($params); $this->data = null; $timer = $this->cacheDir . 'hyp_hsr_' . $this->DevId . '.timer'; $loop = 0; if ($this->OneRequestPerSec) { while ($loop < $this->retry_count && is_file($timer) && filemtime($timer) >= time()) { $loop++; clearstatcache(); usleep($this->retry_interval * 1000); // 250ms } } if ($this->OneRequestPerSec && $loop >= $this->retry_count) { $this->xml = ''; $this->error = 'Request Error: Too busy.'; } else { if ($this->OneRequestPerSec) { HypCommonFunc::touch($timer); } $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->url = $this->url; $ht->get(); if ($ht->rc === 200) { if (!$this->parseXml) { $this->xml = ''; } else { $this->data = $ht->data; $xm = new HypSimpleXML(); $this->xml = $xm->XMLstr_in($this->data); } } else { $this->xml = ''; $this->error = 'HTTP Error: ' . $ht->rc; } } }