1 <?xml version=
"1.0" encoding=
"iso-8859-1"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <!-- template designed by Marco Von Ballmoos -->
6 <title>Docs for page AWLUtilities.php
</title>
7 <link rel=
"stylesheet" href=
"../../media/stylesheet.css" />
8 <script src=
"../../media/lib/classTree.js"></script>
9 <script language=
"javascript" type=
"text/javascript">
10 var imgPlus = new Image();
11 var imgMinus = new Image();
12 imgPlus.src =
"../../media/images/plus.png";
13 imgMinus.src =
"../../media/images/minus.png";
15 function showNode(Node){
16 switch(navigator.family){
18 // Nav
4.x code fork...
19 var oTable = document.layers[
"span" + Node];
20 var oImg = document.layers[
"img" + Node];
23 // IE
4/
5 code fork...
24 var oTable = document.all[
"span" + Node];
25 var oImg = document.all[
"img" + Node];
28 // Standards Compliant code fork...
29 var oTable = document.getElementById(
"span" + Node);
30 var oImg = document.getElementById(
"img" + Node);
33 oImg.src = imgMinus.src;
34 oTable.style.display =
"block";
37 function hideNode(Node){
38 switch(navigator.family){
40 // Nav
4.x code fork...
41 var oTable = document.layers[
"span" + Node];
42 var oImg = document.layers[
"img" + Node];
45 // IE
4/
5 code fork...
46 var oTable = document.all[
"span" + Node];
47 var oImg = document.all[
"img" + Node];
50 // Standards Compliant code fork...
51 var oTable = document.getElementById(
"span" + Node);
52 var oImg = document.getElementById(
"img" + Node);
55 oImg.src = imgPlus.src;
56 oTable.style.display =
"none";
59 function nodeIsVisible(Node){
60 switch(navigator.family){
62 // Nav
4.x code fork...
63 var oTable = document.layers[
"span" + Node];
66 // IE
4/
5 code fork...
67 var oTable = document.all[
"span" + Node];
70 // Standards Compliant code fork...
71 var oTable = document.getElementById(
"span" + Node);
74 return (oTable && oTable.style.display ==
"block");
77 function toggleNodeVisibility(Node){
78 if (nodeIsVisible(Node)){
87 <div class=
"page-body">
88 <h2 class=
"file-name"><img src=
"../../media/images/Page_logo.png" alt=
"File" style=
"vertical-align: middle">/AWLUtilities.php
</h2>
90 <a name=
"sec-description"></a>
91 <div class=
"info-box">
92 <div class=
"info-box-title">Description
</div>
94 <span class=
"disabled">Description
</span> |
95 <a href=
"#sec-includes">Includes
</a>
96 |
<a href=
"#sec-functions">Functions
</a>
98 <div class=
"info-box-body">
99 <!-- ========== Info from phpDoc block ========= -->
100 <p class=
"short-description">Utility functions of a general nature which are used by most AWL library classes.
</p>
102 <li><span class=
"field">author:
</span> Andrew McMillan
<<a href=
"mailto:andrew@mcmillan.net.nz">andrew@mcmillan.net.nz
</a>></li>
103 <li><span class=
"field">copyright:
</span> Catalyst IT Ltd, Morphoss Ltd
<http://www.morphoss.com/
></li>
104 <li><span class=
"field">license:
</span> <a href=
"http://gnu.org/copyleft/gpl.html">GNU GPL v2 or later
</a></li>
111 <a name=
"sec-includes"></a>
112 <div class=
"info-box">
113 <div class=
"info-box-title">Includes
</div>
114 <div class=
"nav-bar">
115 <a href=
"#sec-description">Description
</a> |
116 <span class=
"disabled">Includes
</span>
117 |
<a href=
"#sec-functions">Functions
</a>
119 <div class=
"info-box-body">
120 <a name=
"_Translation_php"><!-- --></a>
121 <div class=
"evenrow">
124 <img src=
"../../media/images/Page.png" alt=
" " />
125 <span class=
"include-title">
126 <span class=
"include-type">require
</span>
127 (
<span class=
"include-name"><a href=
"../../awl/Translation/_Translation.php.html">"Translation.php"</a></span>)
128 (line
<span class=
"line-number">281</span>)
132 <!-- ========== Info from phpDoc block ========= -->
140 <a name=
"sec-functions"></a>
141 <div class=
"info-box">
142 <div class=
"info-box-title">Functions
</div>
143 <div class=
"nav-bar">
144 <a href=
"#sec-description">Description
</a> |
145 <a href=
"#sec-includes">Includes
</a>
146 |
<span class=
"disabled">Functions
</span>
148 <div class=
"info-box-body">
149 <a name=
"functionapache_request_headers" id=
"functionapache_request_headers"><!-- --></a>
153 <img src=
"../../media/images/Function.png" />
154 <span class=
"method-title">apache_request_headers
</span> (line
<span class=
"line-number">63</span>)
157 <!-- ========== Info from phpDoc block ========= -->
158 <p class=
"short-description">Compatibility so we can use the apache function name and still work with CGI
</p>
159 <div class=
"method-signature">
160 <span class=
"method-result">void
</span>
161 <span class=
"method-name">
162 apache_request_headers
170 <a name=
"functionclean_by_regex" id=
"functionclean_by_regex"><!-- --></a>
171 <div class=
"evenrow">
174 <img src=
"../../media/images/Function.png" />
175 <span class=
"method-title">clean_by_regex
</span> (line
<span class=
"line-number">311</span>)
178 <!-- ========== Info from phpDoc block ========= -->
179 <p class=
"short-description">Clean a value by applying a regex to it. If it is an array apply it to each element in the array recursively. If it is an object we don't mess with it.
</p>
180 <div class=
"method-signature">
181 <span class=
"method-result">void
</span>
182 <span class=
"method-name">
185 (
<span class=
"var-type"></span> <span class=
"var-name">$val
</span>,
<span class=
"var-type"></span> <span class=
"var-name">$regex
</span>)
188 <ul class=
"parameters">
190 <span class=
"var-type"></span>
191 <span class=
"var-name">$val
</span> </li>
193 <span class=
"var-type"></span>
194 <span class=
"var-name">$regex
</span> </li>
199 <a name=
"functiondbg_error_log" id=
"functiondbg_error_log"><!-- --></a>
203 <img src=
"../../media/images/Function.png" />
204 <span class=
"method-title">dbg_error_log
</span> (line
<span class=
"line-number">27</span>)
207 <!-- ========== Info from phpDoc block ========= -->
208 <p class=
"short-description">Writes a debug message into the error log using printf syntax. If the first parameter is
"ERROR
" then the message will _always_ be logged.
</p>
209 <p class=
"description"><p>Otherwise, the first parameter is a
"component
" name, and will only be logged if $c-
>dbg[
"component
"] is set to some non-null value.
</p><p>If you want to see every log message then $c-
>dbg[
"ALL
"] can be set, to override the debugging status of the individual components.
</p></p>
211 <li><span class=
"field">var:
</span> The component to identify itself, or
"ERROR
", or
"LOG:component
"</li>
213 <div class=
"method-signature">
214 <span class=
"method-result">void
</span>
215 <span class=
"method-name">
224 <a name=
"functiondbg_log_array" id=
"functiondbg_log_array"><!-- --></a>
225 <div class=
"evenrow">
228 <img src=
"../../media/images/Function.png" />
229 <span class=
"method-title">dbg_log_array
</span> (line
<span class=
"line-number">89</span>)
232 <!-- ========== Info from phpDoc block ========= -->
233 <p class=
"short-description">Function to dump an array to the error log, possibly recursively
</p>
235 <li><span class=
"field">var:
</span> Which component should this log message identify itself from
</li>
237 <div class=
"method-signature">
238 <span class=
"method-result">void
</span>
239 <span class=
"method-name">
242 (
<span class=
"var-type"></span> <span class=
"var-name">$component
</span>,
<span class=
"var-type"></span> <span class=
"var-name">$name
</span>,
<span class=
"var-type"></span> <span class=
"var-name">$arr
</span>, [
<span class=
"var-type"></span> <span class=
"var-name">$recursive
</span> =
<span class=
"var-default">false
</span>])
245 <ul class=
"parameters">
247 <span class=
"var-type"></span>
248 <span class=
"var-name">$component
</span> </li>
250 <span class=
"var-type"></span>
251 <span class=
"var-name">$name
</span> </li>
253 <span class=
"var-type"></span>
254 <span class=
"var-name">$arr
</span> </li>
256 <span class=
"var-type"></span>
257 <span class=
"var-name">$recursive
</span> </li>
262 <a name=
"functiondefine_byte_mappings" id=
"functiondefine_byte_mappings"><!-- --></a>
266 <img src=
"../../media/images/Function.png" />
267 <span class=
"method-title">define_byte_mappings
</span> (line
<span class=
"line-number">415</span>)
270 <!-- ========== Info from phpDoc block ========= -->
271 <div class=
"method-signature">
272 <span class=
"method-result">void
</span>
273 <span class=
"method-name">
282 <a name=
"functionforce_utf8" id=
"functionforce_utf8"><!-- --></a>
283 <div class=
"evenrow">
286 <img src=
"../../media/images/Function.png" />
287 <span class=
"method-title">force_utf8
</span> (line
<span class=
"line-number">467</span>)
290 <!-- ========== Info from phpDoc block ========= -->
291 <div class=
"method-signature">
292 <span class=
"method-result">void
</span>
293 <span class=
"method-name">
296 (
<span class=
"var-type"></span> <span class=
"var-name">$input
</span>)
299 <ul class=
"parameters">
301 <span class=
"var-type"></span>
302 <span class=
"var-name">$input
</span> </li>
307 <a name=
"functionget_fields" id=
"functionget_fields"><!-- --></a>
311 <img src=
"../../media/images/Function.png" />
312 <span class=
"method-title">get_fields
</span> (line
<span class=
"line-number">392</span>)
315 <!-- ========== Info from phpDoc block ========= -->
316 <p class=
"short-description">Get the names of the fields for a particular table
</p>
318 <li><span class=
"field">return:
</span> of string The public fields in the table.
</li>
320 <div class=
"method-signature">
321 <span class=
"method-result">array
</span>
322 <span class=
"method-name">
325 (
<span class=
"var-type">string
</span> <span class=
"var-name">$tablename
</span>)
328 <ul class=
"parameters">
330 <span class=
"var-type">string
</span>
331 <span class=
"var-name">$tablename
</span><span class=
"var-description">: The name of the table.
</span> </li>
336 <a name=
"functionparam_to_global" id=
"functionparam_to_global"><!-- --></a>
337 <div class=
"evenrow">
340 <img src=
"../../media/images/Function.png" />
341 <span class=
"method-title">param_to_global
</span> (line
<span class=
"line-number">345</span>)
344 <!-- ========== Info from phpDoc block ========= -->
345 <p class=
"short-description">Convert a parameter to a global. We first look in _POST and then in _GET, and if they passed in a bunch of valid characters, we will make sure the incoming is cleaned to only match that set.
</p>
346 <div class=
"method-signature">
347 <span class=
"method-result">void
</span>
348 <span class=
"method-name">
351 (
<span class=
"var-type">string
</span> <span class=
"var-name">$varname
</span>,
<span class=
"var-type">string
</span> <span class=
"var-name">$match_regex
</span>,
<span class=
"var-type">string
</span> <span class=
"var-name">$alias1
</span>,
<span class=
"var-type">"</span> <span class="var-name
">3</span>)
354 <ul class="parameters
">
356 <span class="var-type
">string</span>
357 <span class="var-name
">$varname</span><span class="var-description
">: The name of the global variable to put the answer in</span> </li>
359 <span class="var-type
">string</span>
360 <span class="var-name
">$match_regex</span><span class="var-description
">: The part of the parameter matching this regex will be returned</span> </li>
362 <span class="var-type
">string</span>
363 <span class="var-name
">$alias1</span><span class="var-description
">: An alias for the name that we should look for first.</span> </li>
365 <span class="var-type
">"</span>
366 <span class=
"var-name">3</span><span class=
"var-description">: ... More aliases, in the order which they should be examined. $varname will be appended to the end.
</span> </li>
371 <a name=
"functionquoted_printable_encode" id=
"functionquoted_printable_encode"><!-- --></a>
375 <img src=
"../../media/images/Function.png" />
376 <span class=
"method-title">quoted_printable_encode
</span> (line
<span class=
"line-number">299</span>)
379 <!-- ========== Info from phpDoc block ========= -->
380 <p class=
"short-description">Process a string to fit the requirements of RFC2045 section
6.7. Note that this works, but replaces more characters than the minimum set. For readability the spaces aren't encoded as =
20 though.
</p>
381 <div class=
"method-signature">
382 <span class=
"method-result">void
</span>
383 <span class=
"method-name">
384 quoted_printable_encode
386 (
<span class=
"var-type"></span> <span class=
"var-name">$string
</span>)
389 <ul class=
"parameters">
391 <span class=
"var-type"></span>
392 <span class=
"var-name">$string
</span> </li>
397 <a name=
"functionreplace_uri_params" id=
"functionreplace_uri_params"><!-- --></a>
398 <div class=
"evenrow">
401 <img src=
"../../media/images/Function.png" />
402 <span class=
"method-title">replace_uri_params
</span> (line
<span class=
"line-number">210</span>)
405 <!-- ========== Info from phpDoc block ========= -->
406 <p class=
"short-description">Given a URL (presumably the current one) and a parameter, replace the value of parameter, extending the URL as necessary if the parameter is not already there.
</p>
408 <li><span class=
"field">return:
</span> The URI with the replacements done.
</li>
410 <div class=
"method-signature">
411 <span class=
"method-result">string
</span>
412 <span class=
"method-name">
415 (
<span class=
"var-type">string
</span> <span class=
"var-name">$uri
</span>,
<span class=
"var-type">array
</span> <span class=
"var-name">$replacements
</span>)
418 <ul class=
"parameters">
420 <span class=
"var-type">string
</span>
421 <span class=
"var-name">$uri
</span><span class=
"var-description">: The URI we will be replacing parameters in.
</span> </li>
423 <span class=
"var-type">array
</span>
424 <span class=
"var-name">$replacements
</span><span class=
"var-description">: An array of replacement pairs array(
"replace_this
" =
> "with this
" )
</span> </li>
429 <a name=
"functionsession_salted_md5" id=
"functionsession_salted_md5"><!-- --></a>
433 <img src=
"../../media/images/Function.png" />
434 <span class=
"method-title">session_salted_md5
</span> (line
<span class=
"line-number">116</span>)
437 <!-- ========== Info from phpDoc block ========= -->
438 <p class=
"short-description">Make a salted MD5 string, given a string and (possibly) a salt.
</p>
439 <p class=
"description"><p>If no salt is supplied we will generate a random one.
</p></p>
441 <li><span class=
"field">return:
</span> The salt, a * and the MD5 of the salted string, as in SALT*SALTEDHASH
</li>
443 <div class=
"method-signature">
444 <span class=
"method-result">string
</span>
445 <span class=
"method-name">
448 (
<span class=
"var-type">string
</span> <span class=
"var-name">$instr
</span>, [
<span class=
"var-type">string
</span> <span class=
"var-name">$salt
</span> =
<span class=
"var-default">&quot;
&quot;
</span>])
451 <ul class=
"parameters">
453 <span class=
"var-type">string
</span>
454 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and MD5'd
</span> </li>
456 <span class=
"var-type">string
</span>
457 <span class=
"var-name">$salt
</span><span class=
"var-description">: Some salt to sprinkle into the string to be MD5'd so we don't get the same PW always hashing to the same value.
</span> </li>
462 <a name=
"functionsession_salted_sha1" id=
"functionsession_salted_sha1"><!-- --></a>
463 <div class=
"evenrow">
466 <img src=
"../../media/images/Function.png" />
467 <span class=
"method-title">session_salted_sha1
</span> (line
<span class=
"line-number">139</span>)
470 <!-- ========== Info from phpDoc block ========= -->
471 <p class=
"short-description">Make a salted SHA1 string, given a string and (possibly) a salt. PHP5 only (although it could be made to work on PHP4 (@see http://www.openldap.org/faq/data/cache/
347.html). The algorithm used here is compatible with OpenLDAP so passwords generated through this function should be able to be migrated to OpenLDAP by using the part following the second '*', i.e.
</p>
472 <p class=
"description"><p>the '{SSHA}....' part.
</p><p>If no salt is supplied we will generate a random one.
</p></p>
474 <li><span class=
"field">return:
</span> A *, the salt, a * and the SHA1 of the salted string, as in *SALT*SALTEDHASH
</li>
476 <div class=
"method-signature">
477 <span class=
"method-result">string
</span>
478 <span class=
"method-name">
481 (
<span class=
"var-type">string
</span> <span class=
"var-name">$instr
</span>, [
<span class=
"var-type">string
</span> <span class=
"var-name">$salt
</span> =
<span class=
"var-default">&quot;
&quot;
</span>])
484 <ul class=
"parameters">
486 <span class=
"var-type">string
</span>
487 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and SHA1'd
</span> </li>
489 <span class=
"var-type">string
</span>
490 <span class=
"var-name">$salt
</span><span class=
"var-description">: Some salt to sprinkle into the string to be SHA1'd so we don't get the same PW always hashing to the same value.
</span> </li>
495 <a name=
"functionsession_validate_password" id=
"functionsession_validate_password"><!-- --></a>
499 <img src=
"../../media/images/Function.png" />
500 <span class=
"method-title">session_validate_password
</span> (line
<span class=
"line-number">154</span>)
503 <!-- ========== Info from phpDoc block ========= -->
504 <p class=
"short-description">Checks what a user entered against the actual password on their account.
</p>
506 <li><span class=
"field">return:
</span> Whether or not the users attempt matches what is already on file.
</li>
508 <div class=
"method-signature">
509 <span class=
"method-result">boolean
</span>
510 <span class=
"method-name">
511 session_validate_password
513 (
<span class=
"var-type">string
</span> <span class=
"var-name">$they_sent
</span>,
<span class=
"var-type">string
</span> <span class=
"var-name">$we_have
</span>)
516 <ul class=
"parameters">
518 <span class=
"var-type">string
</span>
519 <span class=
"var-name">$they_sent
</span><span class=
"var-description">: What the user entered.
</span> </li>
521 <span class=
"var-type">string
</span>
522 <span class=
"var-name">$we_have
</span><span class=
"var-description">: What we have in the database as their password. Which may (or may not) be a salted MD5.
</span> </li>
527 <a name=
"functionuuid" id=
"functionuuid"><!-- --></a>
528 <div class=
"evenrow">
531 <img src=
"../../media/images/Function.png" />
532 <span class=
"method-title">uuid
</span> (line
<span class=
"line-number">263</span>)
535 <!-- ========== Info from phpDoc block ========= -->
536 <p class=
"short-description">Generates a Universally Unique IDentifier, version
4.
</p>
537 <p class=
"description"><p>RFC
4122 (http://www.ietf.org/rfc/rfc4122.txt) defines a special type of Globally Unique IDentifiers (GUID), as well as several methods for producing them. One such method, described in section
4.4, is based on truly random or pseudo-random number generators, and is therefore implementable in a language like PHP.
</p><p>We choose to produce pseudo-random numbers with the Mersenne Twister, and to always limit single generated numbers to
16 bits (ie. the decimal value
65535). That is because, even on
32-bit systems, PHP's RAND_MAX will often be the maximum *signed* value, with only the equivalent of
31 significant bits. Producing two
16-bit random numbers to make up a
32-bit one is less efficient, but guarantees that all
32 bits are random.
</p><p>The algorithm for version
4 UUIDs (ie. those based on random number generators) states that all
128 bits separated into the various fields (
32 bits,
16 bits,
16 bits,
8 bits and
8 bits,
48 bits) should be random, except : (a) the version number should be the last
4 bits in the
3rd field, and (b) bits
6 and
7 of the
4th field should be
01. We try to conform to that definition as efficiently as possible, generating smaller values where possible, and minimizing the number of base conversions.
</p></p>
539 <li><span class=
"field">return:
</span> A UUID, made up of
32 hex digits and
4 hyphens.
</li>
540 <li><span class=
"field">author:
</span> David Holmes
<<a href=
"mailto:dholmes@cfdsoftware.net">dholmes@cfdsoftware.net
</a>></li>
541 <li><span class=
"field">copyright:
</span> Copyright (c) CFD Labs,
2006. This function may be used freely for any purpose ; it is distributed without any form of warranty whatsoever.
</li>
543 <div class=
"method-signature">
544 <span class=
"method-result">string
</span>
545 <span class=
"method-name">
557 <p class=
"notes" id=
"credit">
558 Documentation generated on Mon,
21 Dec
2009 23:
33:
32 +
1300 by
<a href=
"http://www.phpdoc.org" target=
"_blank">phpDocumentor
1.3.2</a>