2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 define('ERR_FATAL', E_USER_ERROR
);
14 define('ERR_ERROR', E_USER_WARNING
);
15 define('ERR_WARNING', E_USER_NOTICE
);
18 * Iris Studios Shared Object Framework (ISSO)
20 * This framework allows a common backend to be used amongst all Iris
21 * Studios applications and can is built to be abstract and flexible.
22 * The base framework handles all loading and module management.
24 * @author Iris Studios, Inc.
25 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
29 class Shared_Object_Framework
32 * Global environment variables
34 * This is where we keep the global variables that are used within the shared framework
36 * @var version ISSO version
37 * @var sourcepath The location of the framework sources
38 * @var appath The path to the application's location
39 * @var application The name of the application that is using the framework
40 * @var debug Variable for debug mode
41 * @var debuginfo Listing of all debug notices
42 * @var modules An array of loaded framework modules
43 * @var input All input data for the system
44 * @var magicquotes Status of Magic Quotes GPC
46 var $version = '[#]version[#]';
49 var $application = '';
51 var $debuginfo = array();
52 var $modules = array();
59 function Shared_Object_Framework()
62 set_error_handler(array(&$this, '_error_handler'));
65 $this->magicquotes
= get_magic_quotes_gpc();
66 set_magic_quotes_runtime(0);
68 // start input sanitize using variable_order GP
69 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
71 $this->modules
['kernel'] = 'Shared Object Framework Core';
75 * Prepares a path for being set as the sourcepath
77 * @param str Source path or URL
79 * @return str Prepared source path
81 function fetch_sourcepath($source)
83 if (substr($source, strlen($source) - 1) != '/')
91 * Loads a framework extension
93 * @param str Name of the framework
95 function load($framework)
97 if (!$this->is_loaded($framework))
99 $newobj = $this->locate($framework);
100 $this->$newobj['OBJ'] = new $newobj['CLASS']();
101 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
102 $this->modules
["$framework"] = $newobj['OBJECT'];
107 * Includes a framework module. Module definitions need three variables:
108 * class, object, and obj. Class is the name of the class, object is
109 * the name human-readable name, and obj is the name that the module
110 * should be initialized as; this is used in class extensions.
112 * @param str Name of the framework
114 * @return array List of initialization variables
116 function locate($framework)
118 if ($this->sourcepath
== '')
120 trigger_error('Invalid sourcepath specified', ERR_FATAL
);
123 if (file_exists($this->sourcepath
. $framework . '.php'))
125 require_once($this->sourcepath
. $framework . '.php');
126 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
130 trigger_error('Could not find the framework ' . $this->sourcepath
. $framework . '.php', ERR_FATAL
);
136 * Prints a list of all currently loaded framework modules
138 * @param bool Return the data as an array?
140 * @return mixed HTML output or an array of loaded modules
142 function show_modules($return = false
)
146 return $this->modules
;
150 $output = "\n\n<ul>\n\t<li>";
151 $output .= implode("</li>\n\t<li>", $this->modules
);
152 $output .= "</li>\n</ul>\n\n";
153 $this->_message('Loaded Modules', $output, 1);
158 * Verifies to see if a framework has been loaded
160 * @param str Framework name
162 * @return bool Whether or not the framework has been loaded
164 function is_loaded($framework)
166 if (isset($this->modules
["$framework"]))
177 * Prints an ISSO message
179 * @param str The title of the message
180 * @param str The content of the message
181 * @param int Type of message to be printed
182 * @param bool Return the output?
184 * @return mixed Output or null
186 function _message($title, $message, $type, $return = false
)
211 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"500\" style=\"background-color: $color; font-family: Verdana, sans-serif; font-size: 12px;\">";
212 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
213 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
226 * Custom error handler for ISSO
228 * @param int Error number
229 * @param str Error message string
230 * @param str File that contains the error
231 * @param str The line number of the error
232 * @param str The active symbol table at which point the error occurred
234 function _error_handler($errno, $errstr, $errfile, $errline)
255 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
257 $this->_message($title, $errstr, 3);
259 if ($errno == ERR_FATAL
)
266 * Logs a debug message for verbose output
270 function debug($message)
274 $this->debuginfo
[] = $message;
279 * Recursive XSS cleaner
281 * @param mixed Unsanitized REQUEST data
283 * @return mixed Sanitized data
285 function _sanitize_input_recursive($data)
287 foreach($data AS $key => $value)
289 if (is_array($value))
291 $data["$key"] = $this->_sanitize_input_recursive($value);
295 $data["$key"] = $this->sanitize($value);
302 * Simple way to protect against HTML attacks with Unicode support
304 * @param str Unsanitzed text
306 * @return str Properly protected text that only encodes potential threats
308 function sanitize($text)
310 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
314 * Takes text that has been processed for HTML and unsanitizes it
316 * @param str Text that needs to be turned back into HTML
318 * @return str Unsanitized text
320 function unsanitize($text)
322 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
326 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
328 * @param str Some string
330 * @return str String that has slashes added
332 function escape($str)
336 if ($this->magicquotes
)
342 if (isset($_isso->db
))
344 if (is_resource($_isso->db
->link_id
))
346 return $_isso->db
->escape_string($str);
350 return addslashes($str);
355 return addslashes($str);
362 * Global callback used for module calls back to the kernel
364 $_isso = new Shared_Object_Framework();
367 * Wrapper for ternary operator that has to be in the global scope
369 * @param expr Expression
370 * @param mixed If the expression is true
371 * @param mixed If the expression is false
373 * @return mixed True or false data
375 function iff($condition, $iftrue, $iffalse = null
)
377 return ($condition) ?
($iftrue) : ($iffalse);
380 /*=====================================================================*\
381 || ###################################################################
384 || ###################################################################
385 \*=====================================================================*/