/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. * @return Zend_Http_Client * @throws Zend_Http_Client_Exception */ public function setCookie($cookie, $value = null) { Zend_Loader::loadClass('Zend_Http_Cookie'); if (is_array($cookie)) { foreach ($cookie as $c => $v) { if (is_string($c)) { $this->setCookie($c, $v); } else { $this->setCookie($v); } } return $this; } if ($value !== null && $this->config['encodecookies']) { $value = urlencode($value); } if (isset($this->cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->cookiejar->addCookie($cookie); } elseif (is_string($cookie) && $value !== null) { $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri, $this->config['encodecookies']); $this->cookiejar->addCookie($cookie); } } else { if ($cookie instanceof Zend_Http_Cookie) { $name = $cookie->getName(); $value = $cookie->getValue(); $cookie = $name; } if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { /** @see Zend_Http_Client_Exception */ require_once 'Zend/Http/Client/Exception.php'; throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$cookie})"); } $value = adchirashiplusashes($value); if (!isset($this->headers['cookie'])) { $this->headers['cookie'] = array('Cookie', ''); } $this->headers['cookie'][1] .= $cookie . '=' . $value . '; '; } return $this; }
/** * Quotes a variable into a condition * * @param string $text Condition, can contain question mark(s) (?) for parameter insertion. * @param string|array $value Value(s) to insert in question mark (?) parameters. * @return string */ protected function _quoteInto($text, $value = null) { if (!is_array($value)) { $text = str_replace('?', '\'' . adchirashiplusashes($value) . '\'', $text); } else { $i = 0; while (strpos($text, '?') !== false) { if (is_numeric($value[$i])) { $text = substr_replace($text, $value[$i++], strpos($text, '?'), 1); } else { $text = substr_replace($text, '\'' . adchirashiplusashes($value[$i++]) . '\'', strpos($text, '?'), 1); } } } return $text; }