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://www.gnu.org/licenses/lgpl-3.0.txt">GNU LGPL version
3 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>
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">303</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=
"functionawl_version" id=
"functionawl_version"><!-- --></a>
150 <div class=
"evenrow">
153 <img src=
"../../media/images/Function.png" />
154 <span class=
"method-title">awl_version
</span> (line
<span class=
"line-number">539</span>)
157 <!-- ========== Info from phpDoc block ========= -->
158 <p class=
"short-description">Return the AWL version
</p>
159 <div class=
"method-signature">
160 <span class=
"method-result">void
</span>
161 <span class=
"method-name">
170 <a name=
"functioncheck_by_regex" id=
"functioncheck_by_regex"><!-- --></a>
174 <img src=
"../../media/images/Function.png" />
175 <span class=
"method-title">check_by_regex
</span> (line
<span class=
"line-number">333</span>)
178 <!-- ========== Info from phpDoc block ========= -->
179 <p class=
"short-description">Verify a value is OK by testing a regex against 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>
200 <div class=
"evenrow">
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>
228 <img src=
"../../media/images/Function.png" />
229 <span class=
"method-title">dbg_log_array
</span> (line
<span class=
"line-number">87</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>
263 <div class=
"evenrow">
266 <img src=
"../../media/images/Function.png" />
267 <span class=
"method-title">define_byte_mappings
</span> (line
<span class=
"line-number">434</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>
286 <img src=
"../../media/images/Function.png" />
287 <span class=
"method-title">force_utf8
</span> (line
<span class=
"line-number">486</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>
308 <div class=
"evenrow">
311 <img src=
"../../media/images/Function.png" />
312 <span class=
"method-title">get_fields
</span> (line
<span class=
"line-number">413</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=
"functionolson_from_tzstring" id=
"functionolson_from_tzstring"><!-- --></a>
340 <img src=
"../../media/images/Function.png" />
341 <span class=
"method-title">olson_from_tzstring
</span> (line
<span class=
"line-number">520</span>)
344 <!-- ========== Info from phpDoc block ========= -->
345 <p class=
"short-description">Try and extract something like
"Pacific/Auckland
" or
"America/Indiana/Indianapolis
" if possible.
</p>
346 <div class=
"method-signature">
347 <span class=
"method-result">void
</span>
348 <span class=
"method-name">
351 (
<span class=
"var-type"></span> <span class=
"var-name">$tzstring
</span>)
354 <ul class=
"parameters">
356 <span class=
"var-type"></span>
357 <span class=
"var-name">$tzstring
</span> </li>
362 <a name=
"functionparam_to_global" id=
"functionparam_to_global"><!-- --></a>
363 <div class=
"evenrow">
366 <img src=
"../../media/images/Function.png" />
367 <span class=
"method-title">param_to_global
</span> (line
<span class=
"line-number">367</span>)
370 <!-- ========== Info from phpDoc block ========= -->
371 <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>
372 <div class=
"method-signature">
373 <span class=
"method-result">void
</span>
374 <span class=
"method-name">
377 (
<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>)
380 <ul class="parameters
">
382 <span class="var-type
">string</span>
383 <span class="var-name
">$varname</span><span class="var-description
">: The name of the global variable to put the answer in</span> </li>
385 <span class="var-type
">string</span>
386 <span class="var-name
">$match_regex</span><span class="var-description
">: The part of the parameter matching this regex will be returned</span> </li>
388 <span class="var-type
">string</span>
389 <span class="var-name
">$alias1</span><span class="var-description
">: An alias for the name that we should look for first.</span> </li>
391 <span class="var-type
">"</span>
392 <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>
397 <a name=
"functionquoted_printable_encode" id=
"functionquoted_printable_encode"><!-- --></a>
401 <img src=
"../../media/images/Function.png" />
402 <span class=
"method-title">quoted_printable_encode
</span> (line
<span class=
"line-number">321</span>)
405 <!-- ========== Info from phpDoc block ========= -->
406 <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>
407 <div class=
"method-signature">
408 <span class=
"method-result">void
</span>
409 <span class=
"method-name">
410 quoted_printable_encode
412 (
<span class=
"var-type"></span> <span class=
"var-name">$string
</span>)
415 <ul class=
"parameters">
417 <span class=
"var-type"></span>
418 <span class=
"var-name">$string
</span> </li>
423 <a name=
"functionreplace_uri_params" id=
"functionreplace_uri_params"><!-- --></a>
424 <div class=
"evenrow">
427 <img src=
"../../media/images/Function.png" />
428 <span class=
"method-title">replace_uri_params
</span> (line
<span class=
"line-number">232</span>)
431 <!-- ========== Info from phpDoc block ========= -->
432 <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>
434 <li><span class=
"field">return:
</span> The URI with the replacements done.
</li>
436 <div class=
"method-signature">
437 <span class=
"method-result">string
</span>
438 <span class=
"method-name">
441 (
<span class=
"var-type">string
</span> <span class=
"var-name">$uri
</span>,
<span class=
"var-type">array
</span> <span class=
"var-name">$replacements
</span>)
444 <ul class=
"parameters">
446 <span class=
"var-type">string
</span>
447 <span class=
"var-name">$uri
</span><span class=
"var-description">: The URI we will be replacing parameters in.
</span> </li>
449 <span class=
"var-type">array
</span>
450 <span class=
"var-name">$replacements
</span><span class=
"var-description">: An array of replacement pairs array(
"replace_this
" =
> "with this
" )
</span> </li>
455 <a name=
"functionsession_salted_md5" id=
"functionsession_salted_md5"><!-- --></a>
459 <img src=
"../../media/images/Function.png" />
460 <span class=
"method-title">session_salted_md5
</span> (line
<span class=
"line-number">130</span>)
463 <!-- ========== Info from phpDoc block ========= -->
464 <p class=
"short-description">Make a salted MD5 string, given a string and (possibly) a salt.
</p>
465 <p class=
"description"><p>If no salt is supplied we will generate a random one.
</p></p>
467 <li><span class=
"field">return:
</span> The salt, a * and the MD5 of the salted string, as in SALT*SALTEDHASH
</li>
469 <div class=
"method-signature">
470 <span class=
"method-result">string
</span>
471 <span class=
"method-name">
474 (
<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>])
477 <ul class=
"parameters">
479 <span class=
"var-type">string
</span>
480 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and MD5'd
</span> </li>
482 <span class=
"var-type">string
</span>
483 <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>
488 <a name=
"functionsession_salted_sha1" id=
"functionsession_salted_sha1"><!-- --></a>
489 <div class=
"evenrow">
492 <img src=
"../../media/images/Function.png" />
493 <span class=
"method-title">session_salted_sha1
</span> (line
<span class=
"line-number">154</span>)
496 <!-- ========== Info from phpDoc block ========= -->
497 <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>
498 <p class=
"description"><p>the '{SSHA}....' part.
</p><p>If no salt is supplied we will generate a random one.
</p></p>
500 <li><span class=
"field">return:
</span> A *, the salt, a * and the SHA1 of the salted string, as in *SALT*SALTEDHASH
</li>
502 <div class=
"method-signature">
503 <span class=
"method-result">string
</span>
504 <span class=
"method-name">
507 (
<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>])
510 <ul class=
"parameters">
512 <span class=
"var-type">string
</span>
513 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and SHA1'd
</span> </li>
515 <span class=
"var-type">string
</span>
516 <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>
521 <a name=
"functionsession_simple_md5" id=
"functionsession_simple_md5"><!-- --></a>
525 <img src=
"../../media/images/Function.png" />
526 <span class=
"method-title">session_simple_md5
</span> (line
<span class=
"line-number">111</span>)
529 <!-- ========== Info from phpDoc block ========= -->
530 <p class=
"short-description">Make a plain MD5 hash of a string, identifying the type of hash it is
</p>
532 <li><span class=
"field">return:
</span> The *MD5* and the MD5 of the string
</li>
534 <div class=
"method-signature">
535 <span class=
"method-result">string
</span>
536 <span class=
"method-name">
539 (
<span class=
"var-type">string
</span> <span class=
"var-name">$instr
</span>)
542 <ul class=
"parameters">
544 <span class=
"var-type">string
</span>
545 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and MD5'd
</span> </li>
550 <a name=
"functionsession_validate_password" id=
"functionsession_validate_password"><!-- --></a>
551 <div class=
"evenrow">
554 <img src=
"../../media/images/Function.png" />
555 <span class=
"method-title">session_validate_password
</span> (line
<span class=
"line-number">170</span>)
558 <!-- ========== Info from phpDoc block ========= -->
559 <p class=
"short-description">Checks what a user entered against the actual password on their account.
</p>
561 <li><span class=
"field">return:
</span> Whether or not the users attempt matches what is already on file.
</li>
563 <div class=
"method-signature">
564 <span class=
"method-result">boolean
</span>
565 <span class=
"method-name">
566 session_validate_password
568 (
<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>)
571 <ul class=
"parameters">
573 <span class=
"var-type">string
</span>
574 <span class=
"var-name">$they_sent
</span><span class=
"var-description">: What the user entered.
</span> </li>
576 <span class=
"var-type">string
</span>
577 <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>
582 <a name=
"functionuuid" id=
"functionuuid"><!-- --></a>
586 <img src=
"../../media/images/Function.png" />
587 <span class=
"method-title">uuid
</span> (line
<span class=
"line-number">285</span>)
590 <!-- ========== Info from phpDoc block ========= -->
591 <p class=
"short-description">Generates a Universally Unique IDentifier, version
4.
</p>
592 <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>
594 <li><span class=
"field">return:
</span> A UUID, made up of
32 hex digits and
4 hyphens.
</li>
595 <li><span class=
"field">author:
</span> David Holmes
<<a href=
"mailto:dholmes@cfdsoftware.net">dholmes@cfdsoftware.net
</a>></li>
596 <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>
598 <div class=
"method-signature">
599 <span class=
"method-result">string
</span>
600 <span class=
"method-name">
612 <p class=
"notes" id=
"credit">
613 Documentation generated on Tue,
28 Dec
2010 02:
01:
35 +
1300 by
<a href=
"http://www.phpdoc.org" target=
"_blank">phpDocumentor
1.4.3</a>