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=
"functionclean_by_regex" id=
"functionclean_by_regex"><!-- --></a>
150 <div class=
"evenrow">
153 <img src=
"../../media/images/Function.png" />
154 <span class=
"method-title">clean_by_regex
</span> (line
<span class=
"line-number">333</span>)
157 <!-- ========== Info from phpDoc block ========= -->
158 <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>
159 <div class=
"method-signature">
160 <span class=
"method-result">void
</span>
161 <span class=
"method-name">
164 (
<span class=
"var-type"></span> <span class=
"var-name">$val
</span>,
<span class=
"var-type"></span> <span class=
"var-name">$regex
</span>)
167 <ul class=
"parameters">
169 <span class=
"var-type"></span>
170 <span class=
"var-name">$val
</span> </li>
172 <span class=
"var-type"></span>
173 <span class=
"var-name">$regex
</span> </li>
178 <a name=
"functiondbg_error_log" id=
"functiondbg_error_log"><!-- --></a>
182 <img src=
"../../media/images/Function.png" />
183 <span class=
"method-title">dbg_error_log
</span> (line
<span class=
"line-number">27</span>)
186 <!-- ========== Info from phpDoc block ========= -->
187 <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>
188 <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>
190 <li><span class=
"field">var:
</span> The component to identify itself, or
"ERROR
", or
"LOG:component
"</li>
192 <div class=
"method-signature">
193 <span class=
"method-result">void
</span>
194 <span class=
"method-name">
203 <a name=
"functiondbg_log_array" id=
"functiondbg_log_array"><!-- --></a>
204 <div class=
"evenrow">
207 <img src=
"../../media/images/Function.png" />
208 <span class=
"method-title">dbg_log_array
</span> (line
<span class=
"line-number">87</span>)
211 <!-- ========== Info from phpDoc block ========= -->
212 <p class=
"short-description">Function to dump an array to the error log, possibly recursively
</p>
214 <li><span class=
"field">var:
</span> Which component should this log message identify itself from
</li>
216 <div class=
"method-signature">
217 <span class=
"method-result">void
</span>
218 <span class=
"method-name">
221 (
<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>])
224 <ul class=
"parameters">
226 <span class=
"var-type"></span>
227 <span class=
"var-name">$component
</span> </li>
229 <span class=
"var-type"></span>
230 <span class=
"var-name">$name
</span> </li>
232 <span class=
"var-type"></span>
233 <span class=
"var-name">$arr
</span> </li>
235 <span class=
"var-type"></span>
236 <span class=
"var-name">$recursive
</span> </li>
241 <a name=
"functiondefine_byte_mappings" id=
"functiondefine_byte_mappings"><!-- --></a>
245 <img src=
"../../media/images/Function.png" />
246 <span class=
"method-title">define_byte_mappings
</span> (line
<span class=
"line-number">437</span>)
249 <!-- ========== Info from phpDoc block ========= -->
250 <div class=
"method-signature">
251 <span class=
"method-result">void
</span>
252 <span class=
"method-name">
261 <a name=
"functionforce_utf8" id=
"functionforce_utf8"><!-- --></a>
262 <div class=
"evenrow">
265 <img src=
"../../media/images/Function.png" />
266 <span class=
"method-title">force_utf8
</span> (line
<span class=
"line-number">489</span>)
269 <!-- ========== Info from phpDoc block ========= -->
270 <div class=
"method-signature">
271 <span class=
"method-result">void
</span>
272 <span class=
"method-name">
275 (
<span class=
"var-type"></span> <span class=
"var-name">$input
</span>)
278 <ul class=
"parameters">
280 <span class=
"var-type"></span>
281 <span class=
"var-name">$input
</span> </li>
286 <a name=
"functionget_fields" id=
"functionget_fields"><!-- --></a>
290 <img src=
"../../media/images/Function.png" />
291 <span class=
"method-title">get_fields
</span> (line
<span class=
"line-number">414</span>)
294 <!-- ========== Info from phpDoc block ========= -->
295 <p class=
"short-description">Get the names of the fields for a particular table
</p>
297 <li><span class=
"field">return:
</span> of string The public fields in the table.
</li>
299 <div class=
"method-signature">
300 <span class=
"method-result">array
</span>
301 <span class=
"method-name">
304 (
<span class=
"var-type">string
</span> <span class=
"var-name">$tablename
</span>)
307 <ul class=
"parameters">
309 <span class=
"var-type">string
</span>
310 <span class=
"var-name">$tablename
</span><span class=
"var-description">: The name of the table.
</span> </li>
315 <a name=
"functionolson_from_tzstring" id=
"functionolson_from_tzstring"><!-- --></a>
316 <div class=
"evenrow">
319 <img src=
"../../media/images/Function.png" />
320 <span class=
"method-title">olson_from_tzstring
</span> (line
<span class=
"line-number">523</span>)
323 <!-- ========== Info from phpDoc block ========= -->
324 <p class=
"short-description">Try and extract something like
"Pacific/Auckland
" or
"America/Indiana/Indianapolis
" if possible.
</p>
325 <div class=
"method-signature">
326 <span class=
"method-result">void
</span>
327 <span class=
"method-name">
330 (
<span class=
"var-type"></span> <span class=
"var-name">$tzstring
</span>)
333 <ul class=
"parameters">
335 <span class=
"var-type"></span>
336 <span class=
"var-name">$tzstring
</span> </li>
341 <a name=
"functionparam_to_global" id=
"functionparam_to_global"><!-- --></a>
345 <img src=
"../../media/images/Function.png" />
346 <span class=
"method-title">param_to_global
</span> (line
<span class=
"line-number">367</span>)
349 <!-- ========== Info from phpDoc block ========= -->
350 <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>
351 <div class=
"method-signature">
352 <span class=
"method-result">void
</span>
353 <span class=
"method-name">
356 (
<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>)
359 <ul class="parameters
">
361 <span class="var-type
">string</span>
362 <span class="var-name
">$varname</span><span class="var-description
">: The name of the global variable to put the answer in</span> </li>
364 <span class="var-type
">string</span>
365 <span class="var-name
">$match_regex</span><span class="var-description
">: The part of the parameter matching this regex will be returned</span> </li>
367 <span class="var-type
">string</span>
368 <span class="var-name
">$alias1</span><span class="var-description
">: An alias for the name that we should look for first.</span> </li>
370 <span class="var-type
">"</span>
371 <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>
376 <a name=
"functionquoted_printable_encode" id=
"functionquoted_printable_encode"><!-- --></a>
377 <div class=
"evenrow">
380 <img src=
"../../media/images/Function.png" />
381 <span class=
"method-title">quoted_printable_encode
</span> (line
<span class=
"line-number">321</span>)
384 <!-- ========== Info from phpDoc block ========= -->
385 <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>
386 <div class=
"method-signature">
387 <span class=
"method-result">void
</span>
388 <span class=
"method-name">
389 quoted_printable_encode
391 (
<span class=
"var-type"></span> <span class=
"var-name">$string
</span>)
394 <ul class=
"parameters">
396 <span class=
"var-type"></span>
397 <span class=
"var-name">$string
</span> </li>
402 <a name=
"functionreplace_uri_params" id=
"functionreplace_uri_params"><!-- --></a>
406 <img src=
"../../media/images/Function.png" />
407 <span class=
"method-title">replace_uri_params
</span> (line
<span class=
"line-number">232</span>)
410 <!-- ========== Info from phpDoc block ========= -->
411 <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>
413 <li><span class=
"field">return:
</span> The URI with the replacements done.
</li>
415 <div class=
"method-signature">
416 <span class=
"method-result">string
</span>
417 <span class=
"method-name">
420 (
<span class=
"var-type">string
</span> <span class=
"var-name">$uri
</span>,
<span class=
"var-type">array
</span> <span class=
"var-name">$replacements
</span>)
423 <ul class=
"parameters">
425 <span class=
"var-type">string
</span>
426 <span class=
"var-name">$uri
</span><span class=
"var-description">: The URI we will be replacing parameters in.
</span> </li>
428 <span class=
"var-type">array
</span>
429 <span class=
"var-name">$replacements
</span><span class=
"var-description">: An array of replacement pairs array(
"replace_this
" =
> "with this
" )
</span> </li>
434 <a name=
"functionsession_salted_md5" id=
"functionsession_salted_md5"><!-- --></a>
435 <div class=
"evenrow">
438 <img src=
"../../media/images/Function.png" />
439 <span class=
"method-title">session_salted_md5
</span> (line
<span class=
"line-number">130</span>)
442 <!-- ========== Info from phpDoc block ========= -->
443 <p class=
"short-description">Make a salted MD5 string, given a string and (possibly) a salt.
</p>
444 <p class=
"description"><p>If no salt is supplied we will generate a random one.
</p></p>
446 <li><span class=
"field">return:
</span> The salt, a * and the MD5 of the salted string, as in SALT*SALTEDHASH
</li>
448 <div class=
"method-signature">
449 <span class=
"method-result">string
</span>
450 <span class=
"method-name">
453 (
<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>])
456 <ul class=
"parameters">
458 <span class=
"var-type">string
</span>
459 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and MD5'd
</span> </li>
461 <span class=
"var-type">string
</span>
462 <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>
467 <a name=
"functionsession_salted_sha1" id=
"functionsession_salted_sha1"><!-- --></a>
471 <img src=
"../../media/images/Function.png" />
472 <span class=
"method-title">session_salted_sha1
</span> (line
<span class=
"line-number">154</span>)
475 <!-- ========== Info from phpDoc block ========= -->
476 <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>
477 <p class=
"description"><p>the '{SSHA}....' part.
</p><p>If no salt is supplied we will generate a random one.
</p></p>
479 <li><span class=
"field">return:
</span> A *, the salt, a * and the SHA1 of the salted string, as in *SALT*SALTEDHASH
</li>
481 <div class=
"method-signature">
482 <span class=
"method-result">string
</span>
483 <span class=
"method-name">
486 (
<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>])
489 <ul class=
"parameters">
491 <span class=
"var-type">string
</span>
492 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and SHA1'd
</span> </li>
494 <span class=
"var-type">string
</span>
495 <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>
500 <a name=
"functionsession_simple_md5" id=
"functionsession_simple_md5"><!-- --></a>
501 <div class=
"evenrow">
504 <img src=
"../../media/images/Function.png" />
505 <span class=
"method-title">session_simple_md5
</span> (line
<span class=
"line-number">111</span>)
508 <!-- ========== Info from phpDoc block ========= -->
509 <p class=
"short-description">Make a plain MD5 hash of a string, identifying the type of hash it is
</p>
511 <li><span class=
"field">return:
</span> The *MD5* and the MD5 of the string
</li>
513 <div class=
"method-signature">
514 <span class=
"method-result">string
</span>
515 <span class=
"method-name">
518 (
<span class=
"var-type">string
</span> <span class=
"var-name">$instr
</span>)
521 <ul class=
"parameters">
523 <span class=
"var-type">string
</span>
524 <span class=
"var-name">$instr
</span><span class=
"var-description">: The string to be salted and MD5'd
</span> </li>
529 <a name=
"functionsession_validate_password" id=
"functionsession_validate_password"><!-- --></a>
533 <img src=
"../../media/images/Function.png" />
534 <span class=
"method-title">session_validate_password
</span> (line
<span class=
"line-number">170</span>)
537 <!-- ========== Info from phpDoc block ========= -->
538 <p class=
"short-description">Checks what a user entered against the actual password on their account.
</p>
540 <li><span class=
"field">return:
</span> Whether or not the users attempt matches what is already on file.
</li>
542 <div class=
"method-signature">
543 <span class=
"method-result">boolean
</span>
544 <span class=
"method-name">
545 session_validate_password
547 (
<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>)
550 <ul class=
"parameters">
552 <span class=
"var-type">string
</span>
553 <span class=
"var-name">$they_sent
</span><span class=
"var-description">: What the user entered.
</span> </li>
555 <span class=
"var-type">string
</span>
556 <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>
561 <a name=
"functionuuid" id=
"functionuuid"><!-- --></a>
562 <div class=
"evenrow">
565 <img src=
"../../media/images/Function.png" />
566 <span class=
"method-title">uuid
</span> (line
<span class=
"line-number">285</span>)
569 <!-- ========== Info from phpDoc block ========= -->
570 <p class=
"short-description">Generates a Universally Unique IDentifier, version
4.
</p>
571 <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>
573 <li><span class=
"field">return:
</span> A UUID, made up of
32 hex digits and
4 hyphens.
</li>
574 <li><span class=
"field">author:
</span> David Holmes
<<a href=
"mailto:dholmes@cfdsoftware.net">dholmes@cfdsoftware.net
</a>></li>
575 <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>
577 <div class=
"method-signature">
578 <span class=
"method-result">string
</span>
579 <span class=
"method-name">
591 <p class=
"notes" id=
"credit">
592 Documentation generated on Mon,
20 Sep
2010 12:
52:
17 +
1200 by
<a href=
"http://www.phpdoc.org" target=
"_blank">phpDocumentor
1.4.3</a>