਀㰀栀攀愀搀㸀 ਀㰀琀椀琀氀攀㸀䐀漀挀甀洀攀渀琀 吀椀琀氀攀㰀⼀琀椀琀氀攀㸀 ਀㰀戀漀搀礀㸀 ਀㰀℀ⴀⴀ 䤀渀猀攀爀琀 䠀吀䴀䰀 栀攀爀攀 ⴀⴀ㸀 ਀ http_option('max_redirects',1);਀        椀昀 ⠀␀氀愀渀最⤀ ␀琀栀椀猀ⴀ㸀氀愀渀最 㴀 ␀氀愀渀最㬀 }਀         /**਀     ⨀ 夀漀甀 挀愀渀 甀猀攀 琀栀椀猀 洀攀琀栀漀搀 琀漀 最攀琀 漀爀 猀攀琀 猀漀洀攀 栀琀琀瀀 挀漀渀琀攀砀琀 漀瀀琀椀漀渀猀 ⠀猀攀攀 栀琀琀瀀㨀⼀⼀瀀栀瀀⸀渀攀琀⼀洀愀渀甀愀氀⼀攀渀⼀挀漀渀琀攀砀琀⸀栀琀琀瀀⸀瀀栀瀀⤀ * For example, to set the user agent to "Mozilla/5" call $object->http_option('user_agent','Mozilla/5')਀     ⨀ 䤀昀 礀漀甀 洀甀猀琀 猀攀琀 渀漀渀 栀琀琀瀀 漀瀀琀椀漀渀猀 ⠀椀攀㨀 猀漀挀欀攀琀⤀Ⰰ 礀漀甀 挀愀渀 甀猀攀 搀椀爀攀挀琀氀礀 琀栀攀 猀琀爀攀愀洀开挀漀渀琀攀砀琀开最攀琀开漀瀀琀椀漀渀猀⠀⤀ 昀甀渀挀琀椀漀渀 眀椀琀栀 ␀漀戀樀攀挀琀ⴀ㸀挀漀渀琀攀砀琀 愀猀 挀漀渀琀攀砀琀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 栀琀琀瀀开漀瀀琀椀漀渀⠀␀欀攀礀Ⰰ␀瘀愀氀甀攀㴀渀甀氀氀⤀ 笀 if ($value === null) { // return the current value for this key਀            ␀漀瀀琀椀漀渀猀 㴀 猀琀爀攀愀洀开挀漀渀琀攀砀琀开最攀琀开漀瀀琀椀漀渀猀⠀␀琀栀椀猀ⴀ㸀挀漀渀琀攀砀琀⤀㬀 return @$options['http'][$key] ? $options['http'][$key] : '';਀        紀 攀氀猀攀 笀 ⼀⼀ 猀攀琀 琀栀攀 漀瀀琀椀漀渀Ⰰ 爀攀琀甀爀渀 昀愀氀猀攀 椀昀 昀愀椀氀攀搀 return stream_context_set_option($this->context,'http',$key,$value);਀        紀 }਀             /**਀     ⨀ 刀攀琀甀爀渀 爀攀猀甀氀琀猀 昀漀爀 愀 眀攀戀 猀攀愀爀挀栀 焀甀攀爀礀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 眀攀戀⠀␀焀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀㴀愀爀爀愀礀⠀⤀⤀ 笀 $parameters['q'] = trim($q);਀        椀昀 ⠀␀琀栀椀猀ⴀ㸀氀愀渀最 ☀☀ ℀愀爀爀愀礀开欀攀礀开攀砀椀猀琀猀⠀✀氀爀✀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀⤀⤀ ␀瀀愀爀愀洀攀琀攀爀猀嬀✀氀爀✀崀 㴀 ∀氀愀渀最开␀琀栀椀猀ⴀ㸀氀愀渀最∀㬀 $this->host = self::webSearchURL;਀        爀攀琀甀爀渀 ␀琀栀椀猀ⴀ㸀愀瀀椀开挀愀氀氀⠀␀瀀愀爀愀洀攀琀攀爀猀⤀㬀 }਀     /**਀     ⨀ 刀攀琀甀爀渀 爀攀猀甀氀琀猀 昀漀爀 愀 氀漀挀愀氀 猀攀愀爀挀栀 焀甀攀爀礀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 氀漀挀愀氀⠀␀焀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀㴀愀爀爀愀礀⠀⤀⤀ 笀 $parameters['q'] = trim($q);਀        ␀琀栀椀猀ⴀ㸀栀漀猀琀 㴀 猀攀氀昀㨀㨀氀漀挀愀氀匀攀愀爀挀栀唀刀䰀㬀 return $this->api_call($parameters);਀    紀 ਀    ⼀⨀⨀ * Return results for a video search query਀     ⨀⼀ public function video($q,$parameters=array()) {਀        ␀瀀愀爀愀洀攀琀攀爀猀嬀✀焀✀崀 㴀 琀爀椀洀⠀␀焀⤀㬀 $this->host = self::videoSearchURL;਀        爀攀琀甀爀渀 ␀琀栀椀猀ⴀ㸀愀瀀椀开挀愀氀氀⠀␀瀀愀爀愀洀攀琀攀爀猀⤀㬀 }਀     /**਀     ⨀ 刀攀琀甀爀渀 爀攀猀甀氀琀猀 昀漀爀 愀 戀氀漀最 猀攀愀爀挀栀 焀甀攀爀礀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 戀氀漀最⠀␀焀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀㴀愀爀爀愀礀⠀⤀⤀ 笀 $parameters['q'] = trim($q);਀        ␀琀栀椀猀ⴀ㸀栀漀猀琀 㴀 猀攀氀昀㨀㨀戀氀漀最匀攀愀爀挀栀唀刀䰀㬀 return $this->api_call($parameters);਀    紀 ਀    ⼀⨀⨀ * Return results for a news search query਀     ⨀⼀ public function news($q,$parameters=array()) {਀        ␀瀀愀爀愀洀攀琀攀爀猀嬀✀焀✀崀 㴀 琀爀椀洀⠀␀焀⤀㬀 $this->host = self::newsSearchURL;਀        爀攀琀甀爀渀 ␀琀栀椀猀ⴀ㸀愀瀀椀开挀愀氀氀⠀␀瀀愀爀愀洀攀琀攀爀猀⤀㬀 }਀     /**਀     ⨀ 刀攀琀甀爀渀 爀攀猀甀氀琀猀 昀漀爀 愀 戀漀漀欀 猀攀愀爀挀栀 焀甀攀爀礀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 戀漀漀欀⠀␀焀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀㴀愀爀爀愀礀⠀⤀⤀ 笀 $parameters['q'] = trim($q);਀        ␀琀栀椀猀ⴀ㸀栀漀猀琀 㴀 猀攀氀昀㨀㨀戀漀漀欀匀攀愀爀挀栀唀刀䰀㬀 return $this->api_call($parameters);਀    紀 ਀    ⼀⨀⨀ * Return results for a image search query਀     ⨀⼀ public function image($q,$parameters=array()) {਀        ␀瀀愀爀愀洀攀琀攀爀猀嬀✀焀✀崀 㴀 琀爀椀洀⠀␀焀⤀㬀 $this->host = self::imageSearchURL;਀        爀攀琀甀爀渀 ␀琀栀椀猀ⴀ㸀愀瀀椀开挀愀氀氀⠀␀瀀愀爀愀洀攀琀攀爀猀⤀㬀 }਀     /**਀     ⨀ 刀攀琀甀爀渀 爀攀猀甀氀琀猀 昀漀爀 愀 瀀愀琀攀渀琀 猀攀愀爀挀栀 焀甀攀爀礀 */਀    瀀甀戀氀椀挀 昀甀渀挀琀椀漀渀 瀀愀琀攀渀琀⠀␀焀Ⰰ␀瀀愀爀愀洀攀琀攀爀猀㴀愀爀爀愀礀⠀⤀⤀ 笀 $parameters['q'] = trim($q);਀        ␀琀栀椀猀ⴀ㸀栀漀猀琀 㴀 猀攀氀昀㨀㨀瀀愀琀攀渀琀匀攀愀爀挀栀唀刀䰀㬀 return $this->api_call($parameters);਀    紀 ਀    ⼀⨀⨀ * Format query and return results਀     ⨀⼀ protected function api_call($parameters) {਀        ␀琀栀椀猀ⴀ㸀栀琀琀瀀开漀瀀琀椀漀渀⠀✀栀攀愀搀攀爀✀Ⰰ␀琀栀椀猀ⴀ㸀爀攀昀攀爀攀爀 㼀 ∀刀攀昀攀爀攀爀㨀 ␀琀栀椀猀ⴀ㸀爀攀昀攀爀攀爀∀ 㨀 ✀✀⤀㬀 if ($this->version) $parameters['v'] = $this->version;਀        椀昀 ⠀␀琀栀椀猀ⴀ㸀氀愀渀最⤀ ␀瀀愀爀愀洀攀琀攀爀猀嬀✀栀氀✀崀 㴀 ␀琀栀椀猀ⴀ㸀氀愀渀最㬀 if ($this->google_api_key) $parameters['key'] = $this->google_api_key;਀        椀昀 ⠀␀琀栀椀猀ⴀ㸀甀猀攀爀开椀瀀⤀ ␀瀀愀爀愀洀攀琀攀爀猀嬀✀甀猀攀爀开椀瀀✀崀 㴀 ␀琀栀椀猀ⴀ㸀甀猀攀爀开椀瀀㬀 if ($this->rsz) $parameters['rsz'] = $this->rsz;਀        ␀爀 㴀 樀猀漀渀开搀攀挀漀搀攀⠀␀琀栀椀猀ⴀ㸀栀琀琀瀀⠀猀瀀爀椀渀琀昀⠀✀─猀㼀─猀✀Ⰰ␀琀栀椀猀ⴀ㸀栀漀猀琀Ⰰ栀琀琀瀀开戀甀椀氀搀开焀甀攀爀礀⠀␀瀀愀爀愀洀攀琀攀爀猀⤀⤀Ⰰ✀䜀䔀吀✀⤀⤀㬀 $this->http_option('header','');਀        ␀琀栀椀猀ⴀ㸀爀攀猀瀀漀渀猀攀匀琀愀琀甀猀 㴀 椀猀开漀戀樀攀挀琀⠀␀爀⤀ ☀☀ 瀀爀漀瀀攀爀琀礀开攀砀椀猀琀猀⠀␀爀Ⰰ✀爀攀猀瀀漀渀猀攀匀琀愀琀甀猀✀⤀ 㼀 ␀爀ⴀ㸀爀攀猀瀀漀渀猀攀匀琀愀琀甀猀 㨀  㬀 $this->responseDetails = is_object($r) && property_exists($r,'responseDetails') ? $r->responseDetails : '';਀        ␀琀栀椀猀ⴀ㸀挀甀爀猀漀爀 㴀 椀猀开漀戀樀攀挀琀⠀␀爀⤀ ☀☀ 瀀爀漀瀀攀爀琀礀开攀砀椀猀琀猀⠀␀爀Ⰰ✀爀攀猀瀀漀渀猀攀䐀愀琀愀✀⤀ ☀☀ 椀猀开漀戀樀攀挀琀⠀␀爀ⴀ㸀爀攀猀瀀漀渀猀攀䐀愀琀愀⤀ ☀☀ 瀀爀漀瀀攀爀琀礀开攀砀椀猀琀猀⠀␀爀ⴀ㸀爀攀猀瀀漀渀猀攀䐀愀琀愀Ⰰ✀挀甀爀猀漀爀✀⤀㼀 ␀爀ⴀ㸀爀攀猀瀀漀渀猀攀䐀愀琀愀ⴀ㸀挀甀爀猀漀爀 㨀 渀甀氀氀㬀 return is_object($r) && property_exists($r,'responseData') && is_object($r->responseData) && property_exists($r->responseData,'results') ? $r->responseData->results : array();਀    紀 ਀    ⼀⨀⨀ * Make an HTTP request਀     ⨀ 䤀渀昀椀渀椀琀攀 氀漀漀瀀猀 漀昀 爀攀搀椀爀攀挀琀椀漀渀猀 愀爀攀 渀漀琀 栀愀渀搀氀攀搀⸀⸀⸀ * Last URL opened will be notified in $object->lastUrl਀     ⨀ 䰀愀猀琀 䠀吀吀倀 刀攀猀瀀漀渀猀攀 䌀漀搀攀 眀椀氀氀 戀攀 渀漀琀椀昀椀攀搀 椀渀 ␀漀戀樀攀挀琀ⴀ㸀氀愀猀琀刀攀猀瀀漀渀猀攀䌀漀搀攀 ⠀挀愀渀 戀攀   椀昀 琀栀攀 爀攀焀甀攀猀琀 栀愀猀 昀愀椀氀攀搀⤀ * Last HTTP Response Headers will be notified in $object->lastResponseHeaders (see http://php.net/manual/en/reserved.variables.httpresponseheader.php)਀     ⨀ 夀漀甀 挀愀渀 愀挀挀攀猀猀 琀栀攀 氀愀猀琀 爀愀眀 爀攀猀瀀漀渀猀攀 瘀椀愀 ␀漀戀樀攀挀琀ⴀ㸀氀愀猀琀刀攀猀瀀漀渀猀攀 */ ਀    瀀爀漀琀攀挀琀攀搀 昀甀渀挀琀椀漀渀 栀琀琀瀀⠀␀甀爀氀Ⰰ␀洀攀琀栀漀搀Ⰰ␀瀀漀猀琀昀椀攀氀搀猀㴀✀✀⤀ 笀 $this->lastResponseCode = 0;਀        ␀琀栀椀猀ⴀ㸀栀琀琀瀀开漀瀀琀椀漀渀⠀✀洀攀琀栀漀搀✀Ⰰ␀洀攀琀栀漀搀⤀㬀 $this->http_option('content',$postfields);਀        ␀爀攀猀瀀漀渀猀攀 㴀 䀀昀椀氀攀开最攀琀开挀漀渀琀攀渀琀猀⠀␀甀爀氀Ⰰ昀愀氀猀攀Ⰰ␀琀栀椀猀ⴀ㸀挀漀渀琀攀砀琀⤀㬀 $this->lastUrl = $url;਀        ␀琀栀椀猀ⴀ㸀氀愀猀琀刀攀猀瀀漀渀猀攀䠀攀愀搀攀爀猀 㴀 ␀栀琀琀瀀开爀攀猀瀀漀渀猀攀开栀攀愀搀攀爀㬀 $this->lastResponse = $response;਀        椀昀 ⠀椀猀开愀爀爀愀礀⠀␀琀栀椀猀ⴀ㸀氀愀猀琀刀攀猀瀀漀渀猀攀䠀攀愀搀攀爀猀⤀⤀ 笀 foreach ($this->lastResponseHeaders as $i=>$header) {਀                椀昀 ⠀␀椀 㴀㴀  ⤀ ␀琀栀椀猀ⴀ㸀氀愀猀琀刀攀猀瀀漀渀猀攀䌀漀搀攀 㴀 瀀爀攀最开洀愀琀挀栀⠀✀⌀帀䠀吀吀倀⼀嬀 ⴀ㤀⸀崀⬀ ⠀嬀 ⴀ㤀崀⬀⤀⌀猀✀Ⰰ␀栀攀愀搀攀爀Ⰰ␀洀⤀ 㼀 椀渀琀瘀愀氀⠀␀洀嬀㄀崀⤀ 㨀  㬀 elseif (preg_match('#^Location: (.*)$#s',$header,$m)) return $this->http(trim($m[1]),'GET');਀            紀 } else $this->lastResponseHeaders = array();਀        爀攀琀甀爀渀 ␀爀攀猀瀀漀渀猀攀㬀 }਀紀 ਀㼀㸀   ਀㰀⼀栀琀洀氀㸀