public function execute($raw = false) { $reply = $exception = false; if ($this->debug) { $raw = true; } try { if (strlen($this->url) == 0) { throw new Exception("webservice url was invalid"); } $curl = curl_init(); // This is just the first version of this code, it works, but it's hardly very elegant. // Also, I think I need to merge code from Amslib_Plugin_Service because we seem to be duplicating // it a lot here, perhaps we need to have a common shared object with methods to set and get from // the storage variable if ($this->sharedSession) { $key_remote = "/amslib/webservice/session/remote/"; $key_request = "/amslib/webservice/session/request/"; $id_session = Amslib_SESSION::get($key_remote); if ($id_session) { $cookie = "PHPSESSID={$id_session}; path=/"; //.Amslib_Router_URL::getFullURL(); curl_setopt($curl, CURLOPT_COOKIE, $cookie); Amslib_SESSION::set("REQUEST_COOKIE", $cookie); } else { $this->params[$key_request] = true; } } $params = http_build_query(Amslib_Array::valid($this->params)); if ($this->username && $this->password) { curl_setopt($curl, CURLOPT_USERPWD, "{$this->username}:{$this->password}"); } curl_setopt($curl, CURLOPT_URL, $this->url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, 1.0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); $reply = curl_exec($curl); if (!$reply || !strlen($reply)) { Amslib_Debug::log("CURL ERROR", curl_error($curl), Amslib_Debug::dump($reply)); curl_close($curl); return false; } curl_close($curl); $response = new Amslib_Webservice_Response($reply); if ($this->sharedSession && !$id_session) { $data = $response->getData("amslib"); if ($value = $data->getKey($key_remote)) { Amslib_SESSION::set($key_remote, $value); } } return $response; } catch (Exception $e) { $exception = $e->getMessage(); } Amslib_Debug::log("EXCEPTION: ", $exception, "WEBSERVICE URL: ", $this->url, "PARAMS: ", $this->params, "DATA: ", $reply); return false; }
/** * method: setLanguage * * Set the requested language code (4 character, e.g: en_GB, es_ES) for the specific domain * * parameters: * $name - The name of the language domain being set, normally "content" or "website" * $langCode - The 4 character code to set, e.g: en_GB, es_ES * * returns: * Boolean false if setting the code was not executed properly or the 4 character code that was successfully set * * notes: * - Remember, the language system can have multiple "domains" which can be independantly * controlled in order to mix languages within a single webpage, this might sound * ridiculous, but imagine a website being administrated in spanish, but viewing * the english content. * - The $name, specifies the language code given for a particular "domain", normally * they are "content" or "website" */ public static function setLanguage($name, $langCode) { if (is_string($name) && strlen($name) && in_array($langCode, self::getLanguageList($name))) { Amslib_SESSION::set(Amslib_File::reduceSlashes(self::$langKey . "/{$name}"), $langCode); } else { $langCode = false; } return $langCode; }