Source for file utilities.inc.php
Documentation is available at utilities.inc.php
/***********************************************\
* Copyright (c) 2009 Zibings Incorporated *
* You should have received a copy of the *
* Microsoft Reciprocal License along with *
* this program. If not, see: *
* <http://opensource.org/licenses/ms-rl.html> *
\***********************************************/
* $Id: utilities.inc.php 38 2009-10-17 10:01:27Z amale $
* Runs main process for N2 Framework Yverdon.
* Pulls a string from the system's string set, given the current system language.
* @param string $key Key to search strings definition for
* @param array $replacements Optional array of arguments to replace in the defined string
function S($key, array $replacements =
null) {
if (!isset
($strings[$n2f->cfg->sys_lang])) {
if (!isset
($strings[$n2f->cfg->sys_lang][$key])) {
$n2f->debug->throwWarning(N2F_WARN_LANG_KEY_MISSING, S('N2F_WARN_LANG_KEY_MISSING', array($key)), 'system/includes/strings.inc.php');
if (!isset
($strings['en'][$key])) {
$lang =
$n2f->cfg->sys_lang;
$string =
$strings[$lang][$key];
if ($replacements !==
null) {
for ($i =
1; $i <=
count($replacements); $i++
) {
$string =
str_replace("_%{$i}%_", $replacements[$i -
1], $string);
* Returns a string based on the callback provided.
* @param callback $callback Callback to return as a string
$ret .=
"::{$callback[1]}";
* Creates a one-way hash from the provided string. Setting $old to true will use the old algorithm for creating the hash.
* @param string $str String to hash
* @param boolean $old Whether or not to use the old ZSF algorithm
function encStr($str, $old =
false) {
for ($i =
0; $i <
strlen($str); ++
$i) {
$str .=
$n2f->cfg->crypt_hash;
for ($i =
0; $i <
strlen($str); ++
$i) {
* Hand-made print_r() that provides a method list if $showMethods is set to true.
* @param mixed $mixed Item to break down and display
* @param boolean $return Whether or not to return the output from debugEcho()
* @param boolean $showMethods Whether or not to show methods on objects
* @param mixed $prefix Internal for handling recursion
function debugEcho($mixed, $return =
false, $showMethods =
false, $prefix =
false) {
// if it's false, we can assume we're at the beginning
// If we're to return this
// Start the output buffering
// so output a bit of styling
echo
("<div style='text-align: left;'>");
echo
("{
$prefix}Array Elements {\n
");
// show that we're runnin on emptyyyy
echo
("{
$prefix} No Elements;\n
");
// loop through the elements
foreach ($mixed as $key =>
$ele) {
// if it's an array or object
echo
("{
$prefix} [{
$key}] => (
".
gettype($ele).
") {");
debugEcho($ele, $return, $showMethods, "{
$prefix} ");
// and show the end of it
echo
("\n{$prefix} };\n");
echo
("{
$prefix} [{
$key}] => (
".
gettype($ele).
") '{$ele}';\n");
echo
("{
$prefix}".
get_class($mixed).
" Object:\n\n{$prefix}Public Properties {\n");
// if there aren't any properties
// show that there aren't any
echo
("{
$prefix} No Properties;\n
");
// loop through the properties
foreach ($vars as $prop =>
$valu) {
// if it's the special bugger
if ($prop ==
'_loadedMethods') {
// throw them into a temp variable
// and skip this iteration
// if it's an array or it's an object
// show the property and value
echo
("{
$prefix} [{
$prop}] => (
".
gettype($valu).
") {");
// and throw it into another discovery mission
debugEcho($valu, $return, $showMethods, "{
$prefix} ");
echo
("\n{$prefix} };\n");
// show the property and value
echo
("{
$prefix} [{
$prop}] => (
".
gettype($valu).
") '{$valu}';\n");
// throw in an end-of bracket
// if we're to show the methods
echo
("\n{$prefix}Public Methods {\n");
// grab the methods we can see
// if we have other methods
if (isset
($_loadedMethods) &&
count($_loadedMethods) >
0) {
foreach (array_keys($_loadedMethods['methods']) as $method) {
// and add them onto the end of the pile
if (count($methods) <
1) {
echo
("{
$prefix} No Methods;\n
");
foreach ($methods as $method) {
// show the one it'd be called by
echo
("{
$prefix} {
$method[1]};\n
");
echo
("{
$prefix} {
$method};\n
");
// and the OFFICIAL end-of
echo
("\n{$prefix}End of ".
get_class($mixed).
" Object");
// just a catch-all, shouldn't ever use this
echo
("{
$prefix}UNKNOWN of type [
".
gettype($mixed).
"]: '{$mixed}';\n");
// if we're at the 'top' level
// If we've been buffering for output
// Otherwise, set to null
* Tries to find and replace the search string inside of the subject string once.
* @param string $search String to find inside of $subject string
* @param string $replace String to replace first instance of $search string
* @param string $subject String to perform actions upon
$offset =
strpos($subject, $search);
$search_len =
strlen($search);
$subject_len =
strlen($subject);
$after_start =
($offset +
$search_len);
$after_len =
($subject_len -
($offset -
$search_len));
$before =
substr($subject, 0, $offset);
$after =
substr($subject, $after_start, $after_len);
return($before .
$replace .
$after);
* Finds and replaces text contained within the $start and $end tags with the $replace sequence. Use of the text between $start and $end is signified in the $replace string using the string '%TEXT%'.
* @param stringt $start Beginning tag surrounding text
* @param string $end End tag surrounding text
* @param string $replace String to replace tags and inner text with (reference inner text with %TEXT%)
* @param string $text Subject string to perform search/replace within
'spos' =>
strpos($text, $start),
'spos' =>
strpos($text, $end),
if ($s['spos'] ===
false ||
$e['spos'] ===
false) {
$s['epos'] =
$s['spos'] +
$s['len'];
$e['epos'] =
$e['epos'] +
$e['len'];
if ($s['epos'] ==
($e['spos'] -
1)) {
$inner_text =
substr($text, $s['epos'], ($e['spos'] -
$s['epos']));
$replace =
str_replace('%TEXT%', $inner_text, $replace);
$text =
str_replace($start .
$inner_text .
$end, $replace, $text);
Documentation generated on Sat, 23 Jan 2010 11:13:51 -0500 by phpDocumentor 1.4.1