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
);
17 if ((bool
)ini_get('register_globals') === true
)
19 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
20 foreach ($superglobals AS $global)
22 if (is_array($
{$global}))
24 foreach ($
{$global} AS $_key => $_val)
36 * Iris Studios Shared Object Framework (ISSO)
38 * This framework allows a common backend to be used amongst all Iris
39 * Studios applications and can is built to be abstract and flexible.
40 * The base framework handles all loading and module management.
42 * @author Iris Studios, Inc.
43 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
47 class Shared_Object_Framework
50 * Global environment variables
52 * This is where we keep the global variables that are used within the shared framework
54 * @var version ISSO version
55 * @var sourcepath The location of the framework sources
56 * @var appath The path to the application's location
57 * @var application The name of the application that is using the framework
58 * @var debug Variable for debug mode
59 * @var debuginfo Listing of all debug notices
60 * @var modules An array of loaded framework modules
61 * @var input All input data for the system
62 * @var magicquotes Status of Magic Quotes GPC
64 var $version = '[#]version[#]';
67 var $application = '';
69 var $debuginfo = array();
70 var $modules = array();
77 function Shared_Object_Framework()
80 set_error_handler(array(&$this, '_error_handler'));
83 $this->magicquotes
= get_magic_quotes_gpc();
84 set_magic_quotes_runtime(0);
86 // start input sanitize using variable_order GP
87 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
89 $this->modules
['kernel'] = 'Shared Object Framework Core';
93 * Prepares a path for being set as the sourcepath
95 * @param str Source path or URL
97 * @return str Prepared source path
99 function fetch_sourcepath($source)
101 if (substr($source, strlen($source) - 1) != '/')
109 * Loads a framework extension
111 * @param str Name of the framework
113 function load($framework)
115 if (!$this->is_loaded($framework))
117 $newobj = $this->locate($framework);
118 $this->$newobj['OBJ'] = new $newobj['CLASS']();
119 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
120 $this->modules
["$framework"] = $newobj['OBJECT'];
125 * Includes a framework module. Module definitions need three variables:
126 * class, object, and obj. Class is the name of the class, object is
127 * the name human-readable name, and obj is the name that the module
128 * should be initialized as; this is used in class extensions.
130 * @param str Name of the framework
132 * @return array List of initialization variables
134 function locate($framework)
136 if ($this->sourcepath
== '')
138 trigger_error('Invalid sourcepath specified', ERR_FATAL
);
141 if (file_exists($this->sourcepath
. $framework . '.php'))
143 require_once($this->sourcepath
. $framework . '.php');
144 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
148 trigger_error('Could not find the framework ' . $this->sourcepath
. $framework . '.php', ERR_FATAL
);
154 * Prints a list of all currently loaded framework modules
156 * @param bool Return the data as an array?
158 * @return mixed HTML output or an array of loaded modules
160 function show_modules($return = false
)
164 return $this->modules
;
168 $output = "\n\n<ul>\n\t<li>";
169 $output .= implode("</li>\n\t<li>", $this->modules
);
170 $output .= "</li>\n</ul>\n\n";
171 $this->_message('Loaded Modules', $output, 1);
176 * Verifies to see if a framework has been loaded
178 * @param str Framework name
180 * @return bool Whether or not the framework has been loaded
182 function is_loaded($framework)
184 if (isset($this->modules
["$framework"]))
195 * Prints an ISSO message
197 * @param str The title of the message
198 * @param str The content of the message
199 * @param int Type of message to be printed
200 * @param bool Return the output?
202 * @return mixed Output or null
204 function _message($title, $message, $type, $return = false
)
229 $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;\">";
230 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
231 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
244 * Custom error handler for ISSO
246 * @param int Error number
247 * @param str Error message string
248 * @param str File that contains the error
249 * @param str The line number of the error
250 * @param str The active symbol table at which point the error occurred
252 function _error_handler($errno, $errstr, $errfile, $errline)
273 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
275 $this->_message($title, $errstr, 3);
277 if ($errno == ERR_FATAL
)
284 * Logs a debug message for verbose output
288 function debug($message)
292 $this->debuginfo
[] = $message;
297 * Recursive XSS cleaner
299 * @param mixed Unsanitized REQUEST data
301 * @return mixed Sanitized data
303 function _sanitize_input_recursive($data)
305 foreach($data AS $key => $value)
307 if (is_array($value))
309 $data["$key"] = $this->_sanitize_input_recursive($value);
313 $data["$key"] = $this->sanitize($value);
320 * Simple way to protect against HTML attacks with Unicode support
322 * @param str Unsanitzed text
324 * @return str Properly protected text that only encodes potential threats
326 function sanitize($text)
328 if ($this->magicquotes
)
330 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
334 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
339 * Takes text that has been processed for HTML and unsanitizes it
341 * @param str Text that needs to be turned back into HTML
343 * @return str Unsanitized text
345 function unsanitize($text)
347 if ($this->magicquotes
)
349 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
353 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
358 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
360 * @param str Some string
362 * @return str String that has slashes added
364 function escape($str)
368 if ($this->magicquotes
)
374 if (isset($_isso->db
))
376 if (is_resource($_isso->db
->link_id
))
378 return $_isso->db
->escape_string($str);
382 return addslashes($str);
387 return addslashes($str);
394 * Global callback used for module calls back to the kernel
396 $_isso = new Shared_Object_Framework();
399 * Wrapper for ternary operator that has to be in the global scope
401 * @param expr Expression
402 * @param mixed If the expression is true
403 * @param mixed If the expression is false
405 * @return mixed True or false data
407 function iff($condition, $iftrue, $iffalse = null
)
409 return ($condition) ?
($iftrue) : ($iffalse);
412 /*=====================================================================*\
413 || ###################################################################
416 || ###################################################################
417 \*=====================================================================*/