1 - whether to run FmtPagename() over $pn # 'fmtval'=>1 - whether to run FmtPagename() over $val # 'simplewrite'=>1 - use WritePage() instead of UpdatePage() # # logit($pagename, $pn, $text, $opt) # Append text to the end of a page. # $pagename - a reference page (can be the same as $pn) # $pn - the page to which to append # $text - the text to write # $opt - an array containing modifying semantics # [NO_FMTPAGENAME] - suppress running FmtPageName() over $pn # [NO_FMTTEXT] - suppress running FmtPagename() over $text $RecipeInfo['Toolbox']['Version'] = '2009-04-20'; define(toolbox, true); ## While these variables cannot be counted on absolutely, if you load ## toolbox.php fairly early in your config.php then you can do a comparison ## of microtime(true) against $Timeout to determine how close you are to ## timing out on the max_execution_time. It's wise to give yourself a few ## seconds of leeway by subtracting from $Timeout or adding to microtime(). ## EXAMPLE: if (microtime(true)+2 > $Timeout) ... ## -don't forget to globalize $Timeout... $StartTime = microtime(true); $Timeout = $StartTime + ini_get('max_execution_time'); SDV($DebugLevel, 5); // Default is no debugging. Set to lower # for more detail $pagename = ResolvePageName($pagename); # Err() # Right now a simple echo. Later on it might use $opt or something to get # fancier. Possibly logging errors to a file or optionally putting them in # (:messages:) instead or a (new) (:errmessage:). That sort of thing. That's # why it's nice to put all errors through a single function. function Err($pagename, $opt, $msg) { echo "$msg
\n"; } # SafeFmtPagename() $MarkupExpr["dbg"] = 'tbDbg($pagename, @$argp, @$args)'; function tbDbg($pagename, $opt, $args) { for ($i = 0; $i < 3; $i++) if ($args[$i] == 'array') $args[$i] = array('a'=>1,'b'=>'abc','def'); dbg(5,"Dbg: " . $args[0], $args[1], $args[2]); return (''); } # dbg() # Printlevel indicates what level of importance this line is. # 0=never print # 1=very detailed debugging # 2=a little less detailed # 3=fairly normal debugging # 4=high-level, print it without thinking about it # (you can go higher, but the indentation doesn't work) # if $printlevel is lower than $DebugLevel (global) then nothing will be # printed. Thus you get more detailed debug by setting the $DebugLevel to # a lower number. Typically $DebugLevel=1 is maximum detail and $DebugLevel=5 # has all debug statements turned off. function dbg($printlevel, $text, $txt2 = '', $txt3 = '', $txt4 = '', $txt5='') { global $MessagesFmt, $DebugLevel; if ($printlevel < $DebugLevel) return; # If your cookbook is messed up enough that you can't get a page to display # and so you can't see the (:messages:) output then uncomment the line # below and the lines will be echoed instead (arrays are not handled). #echo "
" . (is_array($text)?print_r($text,true):str_repeat("   ", 5-$printlevel).$text) . " (" . (microtime(true) - $StartTime) . ")

\n"; foreach (array($text, $txt2, $txt3, $txt4, $txt5) as $txt) { if ($txt == '') break; elseif (is_array($txt)) { $MessagesFmt[] = "
" . print_r($txt,true) . "
"; } else { $suffix = ""; $prefix = ''; for ($i = 4-$printlevel; $i > 0; $i--) { $prefix .= "
"; $suffix .= "
"; } $prefix .= "