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_ALERT', E_USER_WARNING
);
15 define('ERR_WARNING', E_USER_NOTICE
);
17 if (PHP_VERSION
< '4.1.0')
19 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', ERR_FATAL
);
23 if (PHP_VERSION
> '5.0.0')
25 if (ini_get('error_reporting') & E_USER_NOTICE
)
27 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
31 if (!(ini_get('error_reporting') & E_NOTICE
))
33 error_reporting(ini_get('error_reporting') - E_USER_NOTICE
);
36 if (!(ini_get('error_reporting') & E_WARNING
))
38 error_reporting(ini_get('error_reporting') - E_USER_WARNING
);
41 if (!(ini_get('error_reporting') & E_ERROR
))
43 error_reporting(ini_get('error_reporting') - E_USER_ERROR
);
46 if ((bool)ini_get('register_globals') === true)
48 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
49 foreach ($superglobals AS $global)
51 if (is_array(${$global}))
53 foreach (${$global} AS $_key => $_val)
65 * Iris Studios Shared Object Framework (ISSO)
67 * This framework allows a common backend to be used amongst all Iris
68 * Studios applications and can is built to be abstract and flexible.
69 * The base framework handles all loading and module management.
71 * @author Iris Studios, Inc.
72 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
76 class Shared_Object_Framework
79 * Global environment variables
81 * This is where we keep the global variables that are used within the shared framework
83 * @var version ISSO version
84 * @var sourcepath The location of the framework sources
85 * @var appath The path to the application's location
86 * @var application The name of the application that is using the framework
87 * @var debug Variable for debug mode
88 * @var debuginfo Listing of all debug notices
89 * @var modules An array of loaded framework modules
90 * @var input All input data for the system
91 * @var i Short-hand reference to $isso::input
92 * @var in Short-hand reference to $isso::input
93 * @var magicquotes Status of Magic Quotes GPC
94 * @var escapestrings Sets whether or not we escape strings automatically
96 var $version = '[#]version[#]';
99 var $application = '';
101 var $debuginfo = array();
102 var $modules = array();
103 var $input = array();
106 var $magicquotes = 0;
107 var $escapestrings = false;
112 function Shared_Object_Framework()
115 set_error_handler(array(&$this, '_error_handler'));
118 $this->magicquotes
= get_magic_quotes_gpc();
119 set_magic_quotes_runtime(0);
121 if (defined('ISSO_ESCAPE_STRINGS'))
123 $this->escapestrings
= (bool)constant('ISSO_ESCAPE_STRINGS');
126 // start input sanitize using variable_order GP
127 if (!$this->escapestrings
)
129 $this->exec_sanitize_data();
132 $this->modules
['kernel'] = 'Shared Object Framework Core';
136 * Prepares a path for being set as the sourcepath
138 * @param str Source path or URL
140 * @return str Prepared source path
142 function fetch_sourcepath($source)
144 if (substr($source, strlen($source) - 1) != '/')
152 * Loads a framework extension
154 * @param str Name of the framework
156 function load($framework)
158 if (!$this->is_loaded($framework))
160 $newobj = $this->locate($framework);
161 $this->$newobj['OBJ'] = new $newobj['CLASS']();
162 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
163 $this->modules
["$framework"] = $newobj['OBJECT'];
168 * Includes a framework module. Module definitions need three variables:
169 * class, object, and obj. Class is the name of the class, object is
170 * the name human-readable name, and obj is the name that the module
171 * should be initialized as; this is used in class extensions.
173 * @param str Name of the framework
175 * @return array List of initialization variables
177 function locate($framework)
179 if ($this->sourcepath == '')
181 trigger_error('Invalid sourcepath specified', ERR_FATAL);
184 if (file_exists($this->sourcepath . $framework . '.php'))
186 require_once($this->sourcepath . $framework . '.php');
187 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
191 trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', ERR_FATAL);
197 * Prints a list of all currently loaded framework modules
199 * @param bool Return the data as an array?
201 * @return mixed HTML output or an array of loaded modules
203 function show_modules($return = false)
207 return $this->modules;
211 $output = "\n\n
<ul
>\n\t<li
>";
212 $output .= implode("</li
>\n\t<li
>", $this->modules);
213 $output .= "</li
>\n</ul
>\n\n";
214 $this->_message('Loaded Modules', $output, 1);
219 * Verifies to see if a framework has been loaded
221 * @param str Framework name
223 * @return bool Whether or not the framework has been loaded
225 function is_loaded($framework)
227 if (isset($this->modules["$framework"]))
238 * Prints an ISSO message
240 * @param str The title of the message
241 * @param str The content of the message
242 * @param int Type of message to be printed
243 * @param bool Return the output?
245 * @return mixed Output or null
247 function _message($title, $message, $type, $return = false)
272 $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;\">";
273 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
274 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
287 * Custom error handler for ISSO
289 * @param int Error number
290 * @param str Error message string
291 * @param str File that contains the error
292 * @param str The line number of the error
293 * @param str The active symbol table at which point the error occurred
295 function _error_handler($errno, $errstr, $errfile, $errline)
302 if (!(ini_get('error_reporting') & ERR_FATAL
))
311 if (!(ini_get('error_reporting') & ERR_ALERT
))
321 if (!(ini_get('error_reporting') & ERR_WARNING
))
328 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
330 $this->_message($title, $errstr, 3);
332 if ($errno == ERR_FATAL
)
339 * Logs a debug message for verbose output
343 function debug($message)
347 $this->debuginfo
[] = $message;
352 * Recursive XSS cleaner
354 * @param mixed Unsanitized REQUEST data
356 * @return mixed Sanitized data
358 function _sanitize_input_recursive($data)
360 foreach($data AS $key => $value)
362 if (is_array($value))
364 $data["$key"] = $this->_sanitize_input_recursive($value);
368 if ($this->escapestrings)
370 $data["$key"] = $this->escape($this->sanitize($value));
374 $data["$key"] = $this->sanitize($value);
382 * Simple way to protect against HTML attacks with Unicode support
384 * @param str Unsanitzed text
386 * @return str Properly protected text that only encodes potential threats
388 function sanitize($text)
390 if ($this->magicquotes)
392 return str_replace(array('<', '>', '\"', '"'), array('<
;', '>
;', '"
;', '"
;'), $text);
396 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
401 * Takes text that has been processed for HTML and unsanitizes it
403 * @param str Text that needs to be turned back into HTML
405 * @return str Unsanitized text
407 function unsanitize($text)
409 if ($this->magicquotes)
411 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
415 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
420 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
422 * @param str Some string
424 * @return str String that has slashes added
426 function escape($str)
430 if ($this->magicquotes)
432 if (isset($_isso->db))
434 if (is_resource($_isso->db->link_id))
436 return $_isso->db->escape_string(stripslashes($str));
450 if (isset($_isso->db))
452 if (is_resource($_isso->db->link_id))
454 return $_isso->db->escape_string($str);
458 return addslashes($str);
463 return addslashes($str);
469 * Runs through all of the input data and sanitizes it.
471 function exec_sanitize_data()
473 $this->input = $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
474 $this->i =& $this->input;
475 $this->in =& $this->input;
476 // we're now using magic quotes
477 $this->magicquotes
= 1;
482 * Global callback used for module calls back to the kernel
484 $_isso = new Shared_Object_Framework();
487 * Wrapper for ternary operator that has to be in the global scope
489 * @param expr Expression
490 * @param mixed If the expression is true
491 * @param mixed If the expression is false
493 * @return mixed True or false data
495 function iff($condition, $iftrue, $iffalse = null)
497 return ($condition) ? ($iftrue) : ($iffalse);
500 /*=====================================================================*\
501 || ###################################################################
504 || ###################################################################
505 \*=====================================================================*/