| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 require_once (AK_LIB_DIR.DS.'AkResponse.php'); 3 class AkTestResponse extends AkResponse 4 { 5 function __construct() 6 { 7 $this->_headers = array(); 8 $this->_headers_sent = array(); 9 } 10 function sendHeaders($terminate_if_redirected = true) 11 { 12 /** 13 * Fix a problem with IE 6.0 on opening downloaded files: 14 * If Cache-Control: IE removes the file it just downloaded from 15 * its cache immediately 16 * after it displays the "open/save" dialog, which means that if you 17 * hit "open" the file isn't there anymore when the application that 18 * is called for handling the download is run, so let's workaround that 19 */ 20 if(isset($this->_headers['Cache-Control']) && $this->_headers['Cache-Control'] == 'no-cache'){ 21 $this->_headers['Cache-Control'] = 'private'; 22 } 23 if(!empty($this->_headers['Status'])){ 24 $status = $this->_getStatusHeader($this->_headers['Status']); 25 array_unshift($this->_headers, $status ? $status : (strstr('HTTP/1.1 '.$this->_headers['Status'],'HTTP') ? $this->_headers['Status'] : 'HTTP/1.1 '.$this->_headers['Status'])); 26 //unset($this->_headers['Status']); 27 } else { 28 $this->_headers['Status'] = $this->_default_status; 29 } 30 31 if(!empty($this->_headers) && is_array($this->_headers)){ 32 $this->addHeader('Connection: close'); 33 foreach ($this->_headers as $k=>$v){ 34 if ($k == 'Status') continue; 35 $header = trim((!is_numeric($k) ? $k.': ' : '').$v); 36 $this->_headers_sent[] = $header; 37 if(strtolower(substr($header,0,9)) == 'location:'){ 38 $_redirected = true; 39 if(AK_DESKTOP){ 40 $javascript_redirection = '<title>'.Ak::t('Loading...').'</title><script type="text/javascript">location = "'.substr($header,9).'";</script>'; 41 continue; 42 } 43 } 44 if(strtolower(substr($header,0,13)) == 'content-type:'){ 45 $_has_content_type = true; 46 } 47 AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message("Sending header: $header") : null; 48 //header($header); 49 } 50 } 51 52 if(empty($_has_content_type) && defined('AK_CHARSET') && (empty($_redirected) || (!empty($_redirected) && !empty($javascript_redirection)))){ 53 //header('Content-Type: text/html; charset='.AK_CHARSET); 54 $this->_headers_sent[] = 'Content-Type: text/html; charset='.AK_CHARSET; 55 } 56 57 if(!empty($javascript_redirection)){ 58 echo $javascript_redirection; 59 } 60 61 $terminate_if_redirected ? (!empty($_redirected) ? $this->isRedirected(true) : null) : null; 62 } 63 function _parseHeaders() 64 { 65 $headers = array(); 66 foreach($this->_headers_sent as $header) { 67 $parts = preg_split('/:\s+/',$header); 68 69 $headers[strtolower($parts[0])] = isset($parts[1])?trim($parts[1]):trim($parts[0]); 70 } 71 return $headers; 72 } 73 function getHeader($name) 74 { 75 $headers = $this->_parseHeaders(); 76 $sentHeader = isset($headers[strtolower($name)])?$headers[strtolower($name)]:false; 77 if (!$sentHeader) { 78 $preparedHeader = isset($this->_headers[$name])?$this->_headers[$name]:false; 79 return $preparedHeader; 80 } 81 return $sentHeader; 82 } 83 function isRedirected($set=false) 84 { 85 static $isRedirected; 86 if ($set) { 87 $isRedirected = true; 88 } 89 return $isRedirected; 90 } 91 92 function redirect ($url) 93 { 94 $this->autoRender = false; 95 if(substr(@$this->_headers['Status'],0,3) != '301'){ 96 $this->_headers['Status'] = 302; 97 } 98 $this->addHeader('Location', $url); 99 $this->sendHeaders(); 100 } 101 } 102 103 function &AkTestResponse() 104 { 105 $null = null; 106 $AkResponse =& Ak::singleton('AkTestResponse', $null); 107 return $AkResponse; 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |