/** * Returns information about the client user agent. * * // Returns "Chrome" when using Google Chrome * $browser = Text::user_agent('browser'); * * Multiple values can be returned at once by using an array: * * // Get the browser and platform with a single call * $info = Text::user_agent(array('browser', 'platform')); * * When using an array for the value, an associative array will be returned. * * @param mixed $value array or string to return: browser, version, robot, mobile, platform * @return mixed requested information, FALSE if nothing is found * @uses Kohana::$config */ public static function user_agent($agent, $value) { if (is_array($value)) { $data = array(); foreach ($value as $part) { // Add each part to the set $data[$part] = Text::user_agent($agent, $part); } return $data; } if ($value === 'browser' or $value == 'version') { // Extra data will be captured $info = array(); // Load browsers $browsers = Kohana::$config->load('user_agents')->browser; foreach ($browsers as $search => $name) { if (stripos($agent, $search) !== FALSE) { // Set the browser name $info['browser'] = $name; if (preg_match('#' . preg_quote($search) . '[^0-9.]*+([0-9.][0-9.a-z]*)#i', Request::$user_agent, $matches)) { // Set the version number $info['version'] = $matches[1]; } else { // No version number found $info['version'] = FALSE; } return $info[$value]; } } } else { // Load the search group for this type $group = Kohana::$config->load('user_agents')->{$value}; foreach ($group as $search => $name) { if (stripos($agent, $search) !== FALSE) { // Set the value name return $name; } } } // The value requested could not be found return FALSE; }
/** * Sends headers to the php processor, or supplied `$callback` argument. * This method formats the headers correctly for output, re-instating their * capitalization for transmission. * * [!!] if you supply a custom header handler via `$callback`, it is * recommended that `$response` is returned * * @param HTTP_Response $response header to send * @param boolean $replace replace existing value * @param callback $callback optional callback to replace PHP header function * @return mixed * @since 3.2.0 */ public function send_headers(Response $response = NULL, $replace = FALSE, $callback = NULL) { $protocol = $response->protocol(); $status = $response->status(); // Create the response header $processed_headers = array($protocol . ' ' . $status . ' ' . $response->message($status)); // Get the headers array $headers = $response->headers()->getArrayCopy(); foreach ($headers as $header => $value) { if (is_array($value)) { $value = implode(', ', $value); } $processed_headers[] = Text::ucfirst($header) . ': ' . $value; } if (!isset($headers['content-type'])) { $processed_headers[] = 'Content-Type: text/html; charset=utf-8'; } // Get the cookies and apply if ($cookies = $response->cookie()) { $processed_headers['Set-Cookie'] = $cookies; } if (is_callable($callback)) { // Use the callback method to set header return call_user_func($callback, $response, $processed_headers, $replace); } else { $this->_send_headers_to_php($processed_headers, $replace); return $response; } }