Common Class Reference
[Lib]
Helper methods for PHP. More...
Static Public Member Functions |
|
static | check_if_none_match ($etag) |
Check if If-None-Match header is set and if
it matches the given ETag If so, return a "304 Not Modifed" HTTP
header. |
|
static | check_not_modified ($date) |
Checks if Modified-Since is sended and sends
a 304, if larger then passed date. |
|
static | constant ($name, $default=false) |
Returns value of constant, if defined, else
default value. |
|
static | create_temp_file ($content) |
static | create_token ($salt=false) |
Creates a token, which is 40 characters
long. |
|
static | flag_is_set ($value, $flag) |
Returns true if bitflag is set on value.
|
|
static | get_headers () |
Get all send headers as assoziative array
with (lower case) header name as key and full header as value.
|
|
static | get_temp_dir () |
Reeturns temporary directory. |
|
static | header ($name, $value=false, $override=true) |
Send a header. |
|
static | header_remove ($name) |
Remove given header. |
|
static | header_restore ($arr_headers) |
Restore headers. |
|
static | is_cgi () |
Returns true, if PHP runs as CGI (and not
mod_php). |
|
static | is_google () |
static | is_header_sent ($name) |
Returns TRUE, if header with given name was
alreday sent. |
|
static | preprocess_input () |
Strips possible slashes added by magic
quotes. |
|
static | send_status_code ($iStatusCode) |
Isusses a header with given http code.
|
|
static | split_header ($header) |
Split header into array with name as first
element, and value as second. |
Detailed Description
Helper methods for PHP.
Definition at line 9 of file common.cls.php.
Member Function Documentation
static Common::check_if_none_match | ( | $ | etag | ) | [static] |
Check if If-None-Match header is set and if it matches the given ETag If so, return a "304 Not Modifed" HTTP header.
Definition at line 247 of file common.cls.php.
00247 { 00248 // Get client headers - Apache only 00249 $match_tag = Arr::get_item($_SERVER, 'HTTP_IF_NONE_MATCH', ''); 00250 if ($match_tag && $match_tag == $etag) { 00251 // Save on some bandwidth! 00252 //self::header_restore(array()); 00253 Common::send_status_code(304); // Not modified 00254 exit; 00255 } 00256 00257 return false; 00258 }
static Common::check_not_modified | ( | $ | date | ) | [static] |
Checks if Modified-Since is sended and sends a 304, if larger then passed date.
Exits application if header was send
Definition at line 216 of file common.cls.php.
00216 { 00217 if ($date) { 00218 // Get client headers - Apache only 00219 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { 00220 // Split the If-Modified-Since (Netscape < v6 gets this wrong) 00221 $modifiedSince = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE']); 00222 00223 // Turn the client request If-Modified-Since into a timestamp 00224 $modifiedSince = strtotime($modifiedSince[0]); 00225 } 00226 else { 00227 // Set modified since to 0 00228 $modifiedSince = 0; 00229 } 00230 00231 // Compare time the content was last modified with client cache 00232 if ($date <= $modifiedSince) { 00233 // Save on some bandwidth! 00234 // self::header_restore(array()); 00235 Common::send_status_code(304); // Not modified 00236 exit; 00237 } 00238 } 00239 00240 return false; 00241 }
static Common::constant | ( | $ | name, | |
$ | default = false |
|||
) | [static] |
Returns value of constant, if defined, else default value.
- Parameters:
-
string $name Name of constant mixed $default Default value
- Returns:
- mixed
Definition at line 193 of file common.cls.php.
00193 { 00194 return (defined($name)) ? constant($name) : $default; 00195 }
static Common::create_temp_file | ( | $ | content | ) | [static] |
Definition at line 307 of file common.cls.php.
static Common::create_token | ( | $ | salt = false |
) | [static] |
Creates a token, which is 40 characters long.
- Parameters:
-
string $salt Optional extra salt, if ommitted mt_rand() is used
Definition at line 272 of file common.cls.php.
static Common::flag_is_set | ( | $ | value, | |
$ | flag | |||
) | [static] |
Returns true if bitflag is set on value.
- Parameters:
-
int $value int $flag
- Returns:
- bool
Definition at line 204 of file common.cls.php.
static Common::get_headers | ( | ) | [static] |
Get all send headers as assoziative array with (lower case) header name as key and full header as value.
- Deprecated:
- Use GyroHeaders instead
- Since:
- 0.5.1
- Returns:
- array
Definition at line 139 of file common.cls.php.
00139 { 00140 return GyroHeaders::headers(); 00141 }
static Common::get_temp_dir | ( | ) | [static] |
Reeturns temporary directory.
- Returns:
- string
Definition at line 281 of file common.cls.php.
00281 { 00282 $ret = ''; 00283 if (function_exists('sys_get_temp_dir')) { 00284 $ret = sys_get_temp_dir(); 00285 } 00286 00287 if (empty($ret)) { 00288 foreach(array('TMP','TEMP','TMPDIR') as $env) { 00289 $ret = getenc($env); 00290 if ($ret) { 00291 break; 00292 } 00293 } 00294 } 00295 00296 if (empty($ret)) { 00297 $ret = Config::get_value(Config::TEMP_DIR); 00298 } 00299 00300 if ($ret) { 00301 $ret = rtrim(realpath($ret), '/') . '/'; 00302 } 00303 00304 return $ret; 00305 }
Send a header.
- Since:
- 0.5.1
- Parameters:
-
string $name Name of header or complete header (if $value is false) string $value Value of header bool If FALSE, header will not be send, if header with same name was already sent
Definition at line 92 of file common.cls.php.
00092 { 00093 GyroHeaders::set($name, $value, $override); 00094 }
static Common::header_remove | ( | $ | name | ) | [static] |
Remove given header.
- Deprecated:
- Use GyroHeaders instead
Definition at line 101 of file common.cls.php.
00101 { 00102 GyroHeaders::remove($name); 00103 }
static Common::header_restore | ( | $ | arr_headers | ) | [static] |
Restore headers.
Headers not in passed array wil be removed, headers fro marray will be set
- Deprecated:
- Use GyroHeaders instead
- Parameters:
-
$arr_headers Array of headers retrieved by Common::get_headers()
Definition at line 152 of file common.cls.php.
00152 { 00153 GyroHeaders::restore($arr_headers); 00154 }
static Common::is_cgi | ( | ) | [static] |
Returns true, if PHP runs as CGI (and not mod_php).
- Returns:
- unknown_type
Definition at line 15 of file common.cls.php.
static Common::is_google | ( | ) | [static] |
Definition at line 260 of file common.cls.php.
static Common::is_header_sent | ( | $ | name | ) | [static] |
Returns TRUE, if header with given name was alreday sent.
- Deprecated:
- Use GyroHeaders instead
- Since:
- 0.5.1
- Parameters:
-
string $name
- Returns:
- bool
Definition at line 126 of file common.cls.php.
00126 { 00127 return GyroHeaders::is_set($name); 00128 }
static Common::preprocess_input | ( | ) | [static] |
Strips possible slashes added by magic quotes.
Definition at line 159 of file common.cls.php.
00159 { 00160 // Is magic quotes on? 00161 if ( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) { 00162 // Yes? Strip the added slashes 00163 $_REQUEST = self::transcribe($_REQUEST); 00164 $_GET = self::transcribe($_GET); 00165 $_POST = self::transcribe($_POST); 00166 $_COOKIE = self::transcribe($_COOKIE); 00167 } 00168 }
static Common::send_status_code | ( | $ | iStatusCode | ) | [static] |
Isusses a header with given http code.
Definition at line 22 of file common.cls.php.
00022 { 00023 if (headers_sent()) { 00024 return; 00025 } 00026 $arr = array( 00027 100 => 'Continue', 00028 101 => 'Switching Protocols', 00029 200 => 'OK', 00030 201 => 'Created', 00031 202 => 'Accepted', 00032 203 => 'Non-Authoritative Information', 00033 204 => 'No Content', 00034 205 => 'Reset Content', 00035 206 => 'Partial Content', 00036 300 => 'Multiple Choices', 00037 301 => 'Moved Permanently', 00038 302 => 'Found', 00039 303 => 'See Other', 00040 304 => 'Not Modified', 00041 305 => 'Use Proxy', 00042 306 => '[Unused]', 00043 307 => 'Temporary Redirect', 00044 400 => 'Bad Request', 00045 401 => 'Unauthorized', 00046 402 => 'Payment Required', 00047 403 => 'Forbidden', 00048 404 => 'Not Found', 00049 405 => 'Method Not Allowed', 00050 406 => 'Not Acceptable', 00051 407 => 'Proxy Authentication Required', 00052 408 => 'Request Timeout', 00053 409 => 'Conflict', 00054 410 => 'Gone', 00055 411 => 'Length Required', 00056 412 => 'Precondition Failed', 00057 413 => 'Request Entity Too Large', 00058 414 => 'Request-URI Too Long', 00059 415 => 'Unsupported Media Type', 00060 416 => 'Requested Range Not Satisfiable', 00061 417 => 'Expectation Failed', 00062 500 => 'Internal Server Error', 00063 501 => 'Not Implemented', 00064 502 => 'Bad Gateway', 00065 503 => 'Service Unavailable', 00066 504 => 'Gateway Timeout', 00067 505 => 'HTTP Version Not Supported' 00068 ); 00069 if (isset($arr[$iStatusCode])) { 00070 $text = $iStatusCode . ' ' . $arr[$iStatusCode]; 00071 if ( self::is_cgi() ) { 00072 header('Status: ' . $text); 00073 } 00074 else { 00075 header('HTTP/1.x ' . $text); 00076 } 00077 } 00078 if ($iStatusCode >= 500 && $iStatusCode < 600) { 00079 header('Retry-After: 120'); // Retry after 2 minutes 00080 } 00081 }
static Common::split_header | ( | $ | header | ) | [static] |
Split header into array with name as first element, and value as second.
- Deprecated:
- Use GyroHeaders instead
- Since:
- 0.5.1
- Returns:
- array
Definition at line 113 of file common.cls.php.
00113 { 00114 return GyroHeaders::split($header); 00115 }
The documentation for this class was generated from the following file:
- gyro/core/lib/helpers/common.cls.php