1 <?php
2 /**
3 * XAO_DomDoc.php
4 *
5 * This script provides base class for alll the classes in the XAO
6 * library. Some of the methods need to be overriden. It serves to provide the
7 * minimum features for any XAO class.
8 */
9
10 /**
11 * XAO REQUIREMENTS CHECKS
12 *
13 * XAO cannot work without first meeting some basic requirements. This script is
14 * used to test these requirements as it is the base class and is therefore
15 * inevitably included before any XAO classes can be used.
16 */
17 function XAO_CHECK_MINIMUM_REQUIREMENTS() {
18 $arrPhpVer = explode(".",phpversion());
19 if($arrPhpVer[0] != 4) die("Currently XAO only supports PHP version 4");
20
21 if(extension_loaded("domxml")) {
22 if(!function_exists("domxml_new_doc"))
23 die(
24 "The version of DOMXML that you are using is too outdated for XAO. "
25 ."Please upgrade to a newer version of PHP4."
26 );
27 }
28 else {
29 die("The DOMXML extension to PHP is required for XAO functionality.");
30 }
31
32 if(!extension_loaded("xml"))
33 die("XAO requires the XML extension to be loaded.");
34 }
35 XAO_CHECK_MINIMUM_REQUIREMENTS();
36
37
38 /**
39 * Base class from which all XAO classes are inherited,
40 *
41 * This class is previded mainly for the purposes of centralisation so that any
42 * properties and methods required by all classes in the framework, can easily
43 * be added at this one central point. It provides crude error
44 * handling capabilties which are extended for content-based
45 * classes.
46 */
47 class XaoRoot {
48
49 /**
50 * XAO XML Namespace Identifier
51 *
52 * This is used to separate XAO generated XML data from the user's XML data.
53 *
54 * @access public
55 * @var string
56 */
57 var $idXaoNamespace = "http://xao-php.sourceforge.net/schema/xao_1-0.xsd";
58
59 /**
60 * XAO XML Namespace Prefix
61 *
62 * This is an arbitary string whos default is set here. If the users wishes
63 * to change it, they need to do so before the DomDoc constructor is called.
64 *
65 * @access public
66 * @var string
67 */
68 var $strXaoNamespacePrefix = "xao";
69
70 var $strDebugData;
71
72 /**
73 * All error information is kept here
74 *
75 * This is usually populated by the class which overrides the $Throw()
76 * method. It's worth checking out the way DomDoc overrides this, any class
77 * that inherits DomDoc (and there are a lot of them) will obviously use it's
78 * version.
79 *
80 * @access public
81 * @var array
82 */
83 var $strError;
84
85 /**
86 * Name of user-defined callback function to handle all errors.
87 *
88 * The user must then define a member function using the name specified in
89 * this string variable. The function must implement the signature like so
90 * function myHardErrorChucker($strMsg,$intLevel,$strCode) {...}
91 * assuming they did $this->strErrCallbackFunc = "myHardErrorChucker";
92 * in their child class constructor. Suggest checking out the source code for
93 * $this->Throw();
94 * The idea behind this facility is that you do not need to override Throw()
95 * in order to implement custom logging etc.
96 *
97 * @access public
98 * @var string
99 */
100 var $fncErrCallbackFunc = "";
101
102 /**
103 * Paramters used to cache work done by the class.
104 *
105 * This is an associative array with three different types of potential
106 * keys:
107 * 1) "key" - the cache key
108 * 2) "ttl" - time to live (seconds).
109 * 3) "exp" - a unix timestamp when when the object expires
110 * To use the cache, "key" is required. In addition, either "ttl" or "exp"
111 * need to be populated. This array is passed to the contructor of the
112 * CacheMan class for further action. see documentation in CacheMan for more
113 * information.
114 *
115 * @access public
116 * @var array
117 */
118 var $arrCacheParams = array();
119
120 /**
121 * Generic/default error handler.
122 *
123 * This is an associative array with three different types of potential
124 * keys:
125 * 1) "key" - the cache key
126 * 2) "ttl" - time to live (seconds).
127 * 3) "exp" - a unix timestamp when when the object expires
128 * To use the cache, "key" is required. In addition, either "ttl" or "exp"
129 * need to be populated. This array is passed to the contructor of the
130 * CacheMan class for further action. see documentation in CacheMan for more
131 * information.
132 *
133 * @param string user-defined error message
134 * @param array hash list of metadata to provide supportive context
135 * @access public
136 * @return void
137 */
138 function Throw($strErrMsg,$arrAttribs = null) {
139 if(is_null($arrAttribs)) $arrAttribs = array();
140 // clear any previous errors
141 $this->strError = "";
142
143 if(
144 isset($arrAttribs["class"])
145 && isset($arrAttribs["function"])
146 && isset($arrAttribs["line"])
147 ) {
148 $this->strError .=
149 "In method "
150 .$arrAttribs["class"]."::"
151 .$arrAttribs["function"]."() on line "
152 .$arrAttribs["line"]."<br />\n";
153 }
154
155 $this->strError .= "<div style=\"color:red;\">".$strErrMsg."</div>";
156 // call user-defined error function
157 if(strlen($this->fncErrCallbackFunc)) {
158 if(method_exists($this,$this->fncErrCallbackFunc)) {
159 $this->$fncErrCallbackFunc($strErrMsg);
160 }
161 }
162 }
163
164 function arrSetErrFnc($fcnCurrent,$intLine) {
165 $arrErrAttribs["class"] = get_class($this);
166 $arrErrAttribs["function"] = $fcnCurrent;
167 $arrErrAttribs["line"] = $intLine;
168 return $arrErrAttribs;
169 }
170
171 function blnTestSafeName($strSubject) {
172 // a multi-line string is not safe
173 if(strstr($strSubject,"\n")) return false;
174 // begining with a digit is not safe
175 if(preg_match("/^\d/",$strSubject)) return false;
176 // non-word characters are not safe
177 // underscores "_" are allowed
178 if(preg_match("/\W/",$strSubject)) return false;
179 return true;
180 }
181 }
182
183 ?>