| version 1.12, 2017/11/08 01:12:03 |
version 1.13, 2024/11/20 15:48:03 |
|
|
| * Usage: |
* Usage: |
| * <?php |
* <?php |
| * require_once 'Platon.php'; |
* require_once 'Platon.php'; |
| * Platon::function_name(); |
* Platon::function_name(); |
| * ?> |
* ?> |
| * |
* |
| * @author Ondrej Jombik <nepto@platon.sk> |
* @author Ondrej Jombik <nepto@platon.sk> |
|
|
| * @access public |
* @access public |
| */ |
*/ |
| |
|
| /* $Platon: phpPlatonLib/Platon/Platon.php,v 1.43 2017/11/08 01:09:07 nepto Exp $ */ |
/* $Platon: Metafox/lib/Platon.php,v 1.12 2017/11/08 01:12:03 nepto Exp $ */ |
| |
|
| class Platon |
class Platon |
| { |
{ |
|
|
| */ |
*/ |
| static function get_cgi_var($name, $default_value = null) /* {{{ */ |
static function get_cgi_var($name, $default_value = null) /* {{{ */ |
| { |
{ |
| static $magic_quotes_gpc = null; |
$var = $_GET[$name] ?? $_POST[$name] ?? $default_value; |
| if ($magic_quotes_gpc === null) { |
if (isset($var)) { |
| $magic_quotes_gpc = get_magic_quotes_gpc(); |
if (is_array($var)) { |
| } |
foreach ($var as $key => $value) { |
| $var = @$_GET[$name]; |
$var[$key] = stripslashes($value); |
| if (! isset($var)) { |
} |
| $var = @$_POST[$name]; |
} else { |
| } |
$var = stripslashes($var); |
| if (isset($var)) { |
} |
| if ($magic_quotes_gpc) { |
} |
| if (is_array($var)) { |
return $var; |
| foreach (array_keys($var) as $key) { |
|
| $var[$key] = stripslashes($var[$key]); |
|
| } |
|
| } else { |
|
| $var = stripslashes($var); |
|
| } |
|
| } |
|
| } else { |
|
| $var = @$default_value; |
|
| } |
|
| return $var; |
|
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
|
|
| $dir_back = ''; |
$dir_back = ''; |
| $i = substr_count(Platon::append_slash($dir), '/'); |
$i = substr_count(Platon::append_slash($dir), '/'); |
| for (; $i > 0; $i--) |
for (; $i > 0; $i--) |
| $dir_back .= '../'; |
$dir_back .= '../'; |
| return $dir_back; |
return $dir_back; |
| } /* }}} */ |
} /* }}} */ |
| |
|
|
|
| |
|
| /** |
/** |
| * Performs a HTTP/1.1 redirect according to RFC 2068 |
* Performs a HTTP/1.1 redirect according to RFC 2068 |
| * |
* |
| * @param string $where where to redirect (URL or local script) |
* @param string $where where to redirect (URL or local script) |
| * @param boolean $temporary if such redirect is only temporary one |
* @param boolean $temporary if such redirect is only temporary one |
| * @todo implement HTML page redirecting if output was aleady sent |
* @todo implement HTML page redirecting if output was aleady sent |
|
|
| |
|
| /** |
/** |
| * Changes a HTTP host using permanent redirect |
* Changes a HTTP host using permanent redirect |
| * |
* |
| * @param string $new_http_host destination HTTP host |
* @param string $new_http_host destination HTTP host |
| * @param string $old_http_host source HTTP host (string or array) |
* @param string $old_http_host source HTTP host (string or array) |
| * empty string means any host |
* empty string means any host |
|
|
| $request_uri = $_SERVER['REQUEST_URI']; |
$request_uri = $_SERVER['REQUEST_URI']; |
| return Platon::redirect("$schema://$new_http_host$request_uri"); |
return Platon::redirect("$schema://$new_http_host$request_uri"); |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Redirects if it is neccessary for particular file. |
* Redirects if it is neccessary for particular file. |
| * |
* |
|
|
| { |
{ |
| // Pronounceable pieces of words |
// Pronounceable pieces of words |
| $array = array( |
$array = array( |
| 'ap', 'baz', 'car', 'dus', 'tin', 'rog', 'sti', |
'ap', 'baz', 'car', 'dus', 'tin', 'rog', 'sti', |
| 'rev', 'pik', 'sty', 'lev', 'qot', 'rel', 'vid', |
'rev', 'pik', 'sty', 'lev', 'qot', 'rel', 'vid', |
| 'kro', 'xo', 'pro', 'wia', 'axi', 'jer', 'foh', |
'kro', 'xo', 'pro', 'wia', 'axi', 'jer', 'foh', |
| 'mu', 'ya', 'zol', 'gu', 'pli', 'cra', 'den', |
'mu', 'ya', 'zol', 'gu', 'pli', 'cra', 'den', |
| 'bi', 'sat', 'ry', 'qui', 'wip', 'fla', 'gro', |
'bi', 'sat', 'ry', 'qui', 'wip', 'fla', 'gro', |
| 'tav', 'peh', 'gil', 'lot', 'kal', 'zan', 'noc', |
'tav', 'peh', 'gil', 'lot', 'kal', 'zan', 'noc', |
| 'bat', 'tev', 'lun', 'pal', 'hom', 'cun', 'wos', 'vox'); |
'bat', 'tev', 'lun', 'pal', 'hom', 'cun', 'wos', 'vox'); |
| |
|
| // Randomize on microseconds |
// Randomize on microseconds |
|
|
| return $pass; |
return $pass; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Returns random string of length $len consisting of A-Z and 0-9; first |
* Returns random string of length $len consisting of A-Z and 0-9; first |
| * character will always be an alphabet; requires srand(). |
* character will always be an alphabet; requires srand(). |
| * |
* |
|
|
| return $s; |
return $s; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Appends slash at the end of string if it is not empty and slash is not |
* Appends slash at the end of string if it is not empty and slash is not |
| * already present at the end of string. |
* already present at the end of string. |
| * |
* |
|
|
| return false; |
return false; |
| } |
} |
| if (strlen($string) > 0) { |
if (strlen($string) > 0) { |
| if ($string[strlen($string) - 1] != $char[0]) |
if ($string[strlen($string) - 1] != $char[0]) |
| $string .= $char[0]; |
$string .= $char[0]; |
| } |
} |
| return $string; |
return $string; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Returns appropriate value from array according to key compared with |
* Returns appropriate value from array according to key compared with |
| * passed string or false when no key contains passed string. |
* passed string or false when no key contains passed string. |
| * |
* |
|
|
| |
|
| /** |
/** |
| * Returns pretty formated substring. |
* Returns pretty formated substring. |
| * |
* |
| * @param string $string string to format |
* @param string $string string to format |
| * @param int $length maximum length |
* @param int $length maximum length |
| * @param int $slop slop |
* @param int $slop slop |
|
|
| # warning: code below contains at least one bug |
# warning: code below contains at least one bug |
| |
|
| # set define off; -- makes it so SQL*Plus doesn't choke on the '&' |
# set define off; -- makes it so SQL*Plus doesn't choke on the '&' |
| # |
# |
| # create or replace |
# create or replace |
| # static function pretty_substr |
# static function pretty_substr |
| # ( |
# ( |
|
|
| # begin |
# begin |
| # if length(str) > len then |
# if length(str) > len then |
| # result := substr(str, 0, len - 1); |
# result := substr(str, 0, len - 1); |
| # |
# |
| # last_space := instr(result, ' ', (-1 * slop), 1); |
# last_space := instr(result, ' ', (-1 * slop), 1); |
| # |
# |
| # if last_space > 0 then |
# if last_space > 0 then |
| # result := substr(result, 0, last_space - 1); |
# result := substr(result, 0, last_space - 1); |
| # end if; |
# end if; |
| # |
# |
| # result := result || '…'; |
# result := result || '…'; |
| # else |
# else |
| # result := str; |
# result := str; |
| # end if; |
# end if; |
| # |
# |
| # return result; |
# return result; |
| # end pretty_substr; |
# end pretty_substr; |
| # }}} |
# }}} |
| |
|
| /** |
/** |
| * Insert element into array on specific index. |
* Insert element into array on specific index. |
| * |
* |
|
|
| array_push($before, $element); |
array_push($before, $element); |
| return array_merge($before, $arr); |
return array_merge($before, $arr); |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Returns english grammar related number. |
* Returns english grammar related number. |
| * |
* |
|
|
| return $path; |
return $path; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |
| * Creates URL string from components; components are array as it is |
* Creates URL string from components; components are array as it is |
| * returned from glue_url() function. |
* returned from glue_url() function. |
| * |
* |
|
|
| * @date 19/Feb/2001 |
* @date 19/Feb/2001 |
| */ |
*/ |
| static function glue_url($url) /* {{{ */ |
static function glue_url($url) /* {{{ */ |
| { |
{ |
| if (! is_array($url)) |
if (! is_array($url)) |
| return false; |
return false; |
| // scheme |
// scheme |
| $uri = empty($url['scheme']) ? '' : $url['scheme'] . '://'; |
$uri = empty($url['scheme']) ? '' : $url['scheme'] . '://'; |
| // user and pass |
// user and pass |
| if (! empty($url['user'])) { |
if (! empty($url['user'])) { |
| $uri .= $url['user'].':'.$url['pass'].'@'; |
$uri .= $url['user'].':'.$url['pass'].'@'; |
| } |
} |
| // host |
// host |
| $uri .= $url['host']; |
$uri .= $url['host']; |
| // port |
// port |
| $port = empty($url['port']) ? '' : ':'.$url['port']; |
$port = empty($url['port']) ? '' : ':'.$url['port']; |
| $uri .= $port; |
$uri .= $port; |
| // path |
// path |
| $uri .= $url['path']; |
$uri .= $url['path']; |
| // fragment or query |
// fragment or query |
| if (isset($url['fragment'])) { |
if (isset($url['fragment'])) { |
| $uri .= '#' . $url['fragment']; |
$uri .= '#' . $url['fragment']; |
| } |
} |
| elseif (isset($url['query'])) { |
elseif (isset($url['query'])) { |
| $uri .= '?' . $url['query']; |
$uri .= '?' . $url['query']; |
| } |
} |
| return $uri; |
return $uri; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /** |
/** |