appid = $appid; $this->key = $key; $this->secret = $secret; $this->path = $path; $this->api_host = parse_url("https://www.sweetcaptcha.com", PHP_URL_HOST); $this->registered = (!empty($appid) && !empty($key) && !empty($secret) ); $this->error = ''; } private function api($method, $params) { $basic = array( 'method' => $method, 'appid' => $this->appid, 'key' => $this->key, 'path' => $this->path, 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'platform' => 'adsnipp' ); if (is_admin()) { return $this->call(array_merge(isset($params[0]) ? $params[0] : $params, $basic)); } else { if ($this->registered) { return $this->call(array_merge(isset($params[0]) ? $params[0] : $params, $basic)); } else { //return ''.__('Your sweetCaptcha plugin is not setup yet', 'sweetcaptcha').''; return ''; } } } private function call($params) { $param_data = ""; foreach ($params as $param_name => $param_value) { $param_data .= urlencode($param_name) . '=' . urlencode($param_value) . '&'; } $fs = fsockopen($this->api_host, 80, $errno, $errstr, 10 /* The connection timeout, in seconds */); if (!$fs) { if (isset($params['check'])) { return '
" . SWEETCAPTCHA_CONNECT_ERROR . "
Details"; } public function __call($method, $params) { return $this->api($method, $params); } public function check_access() { echo $this->api('get_html', array('check' => 1)); } }