⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soap_google.php

📁 ATutor是一个学习管理系统(LCMS/LMS), 为教师和学生建立一个网络教学平台。
💻 PHP
字号:
<?php
require(AT_INCLUDE_PATH . 'classes/nusoap.php');

class SOAP_Google { 
	/**    * @var    string    * @access private    */    var $_licenseKey = "";

	    /**    * @var    object    * @access private    */    var $_soapClient = NULL;

		/**
    * Constructor.
    *
    * @param  string
    * @access public
    */
    function SOAP_Google($licenseKey) {
        $this->_licenseKey = $licenseKey;

        $this->_soapClient = new nusoapclient("http://api.google.com/search/beta2");
    }

/**
    * Retrieves a page by URL from the Google Cache.
    *
    * @param  string
    * @return mixed
    * @access public
    */
    function getCachedPage($url) {
        $result = $this->_performAPICall(
          "doGetCachedPage",

          array(
            "key" => $this->_licenseKey,
            "url" => $url
          )
        );

        if ($result) {
            $result = base64_decode($result);
        }

        return $result;
    }

    /**
    * Retrieves a spelling suggestion for a phrase.
    *
    * @param  string
    * @return mixed
    * @access public
    */
    function getSpellingSuggestion($phrase) {
        return $this->_performAPICall(
          "doSpellingSuggestion",

          array(
            "key"    => $this->_licenseKey,
            "phrase" => $phrase
          )
        );
    }

    /**
    * Performs a web search.
    *
    * @param  array
    * @return mixed
    * @access public
    */
    function search($parameters = array()) {
        if (!isset($parameters["query"])) {
            return false;
        }

        return $this->_performAPICall(
          "doGoogleSearch",

          array(
            "key"         => $this->_licenseKey,
            "q"           => $parameters["query"],
            "start"       => isset($parameters["start"])      ? $parameters["start"]      : 0,
            "maxResults"  => isset($parameters["maxResults"]) ? $parameters["maxResults"] : 10,
            "filter"      => isset($parameters["filter"])     ? $parameters["filter"]     : false,
            "restrict"    => isset($parameters["restrict"])   ? $parameters["restrict"]   : "",
            "safeSearch"  => isset($parameters["safeSearch"]) ? $parameters["safeSearch"] : false,
            "lr"          => isset($parameters["lr"])         ? $parameters["lr"]         : "",
            "ie"          => isset($parameters["ie"])         ? $parameters["ie"]         : "",
            "oe"          => isset($parameters["oe"])         ? $parameters["oe"]         : ""
          )
        );
    }

    /**
    * @param  string
    * @param  array
    * @return mixed
    * @access private
    */
    function _performAPICall($apiCall, $parameters) {
			$result = $this->_soapClient->call(
			  $apiCall,
			  $parameters,
			  "urn:GoogleSearch"
			);

		// if (!PEAR::isError($result)) {
		if (is_array($result)) {
            return $result;
        } else {
            return false;
        }
    }
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -