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 ((bool
)ini_get('register_globals') === true
)
33 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
34 foreach ($superglobals AS $global)
36 if (is_array($
{$global}))
38 foreach ($
{$global} AS $_key => $_val)
50 * Iris Studios Shared Object Framework (ISSO)
52 * This framework allows a common backend to be used amongst all Iris
53 * Studios applications and can is built to be abstract and flexible.
54 * The base framework handles all loading and module management.
56 * @author Iris Studios, Inc.
57 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
61 class Shared_Object_Framework
64 * Global environment variables
66 * This is where we keep the global variables that are used within the shared framework
68 * @var version ISSO version
69 * @var sourcepath The location of the framework sources
70 * @var appath The path to the application's location
71 * @var application The name of the application that is using the framework
72 * @var debug Variable for debug mode
73 * @var debuginfo Listing of all debug notices
74 * @var modules An array of loaded framework modules
75 * @var input All input data for the system
76 * @var magicquotes Status of Magic Quotes GPC
78 var $version = '[#]version[#]';
81 var $application = '';
83 var $debuginfo = array();
84 var $modules = array();
91 function Shared_Object_Framework()
94 set_error_handler(array(&$this, '_error_handler'));
97 $this->magicquotes
= get_magic_quotes_gpc();
98 set_magic_quotes_runtime(0);
100 // start input sanitize using variable_order GP
101 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
103 $this->modules
['kernel'] = 'Shared Object Framework Core';
107 * Prepares a path for being set as the sourcepath
109 * @param str Source path or URL
111 * @return str Prepared source path
113 function fetch_sourcepath($source)
115 if (substr($source, strlen($source) - 1) != '/')
123 * Loads a framework extension
125 * @param str Name of the framework
127 function load($framework)
129 if (!$this->is_loaded($framework))
131 $newobj = $this->locate($framework);
132 $this->$newobj['OBJ'] = new $newobj['CLASS']();
133 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
134 $this->modules
["$framework"] = $newobj['OBJECT'];
139 * Includes a framework module. Module definitions need three variables:
140 * class, object, and obj. Class is the name of the class, object is
141 * the name human-readable name, and obj is the name that the module
142 * should be initialized as; this is used in class extensions.
144 * @param str Name of the framework
146 * @return array List of initialization variables
148 function locate($framework)
150 if ($this->sourcepath
== '')
152 trigger_error('Invalid sourcepath specified', ERR_FATAL
);
155 if (file_exists($this->sourcepath
. $framework . '.php'))
157 require_once($this->sourcepath
. $framework . '.php');
158 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
162 trigger_error('Could not find the framework ' . $this->sourcepath
. $framework . '.php', ERR_FATAL
);
168 * Prints a list of all currently loaded framework modules
170 * @param bool Return the data as an array?
172 * @return mixed HTML output or an array of loaded modules
174 function show_modules($return = false
)
178 return $this->modules
;
182 $output = "\n\n<ul>\n\t<li>";
183 $output .= implode("</li>\n\t<li>", $this->modules
);
184 $output .= "</li>\n</ul>\n\n";
185 $this->_message('Loaded Modules', $output, 1);
190 * Verifies to see if a framework has been loaded
192 * @param str Framework name
194 * @return bool Whether or not the framework has been loaded
196 function is_loaded($framework)
198 if (isset($this->modules
["$framework"]))
209 * Prints an ISSO message
211 * @param str The title of the message
212 * @param str The content of the message
213 * @param int Type of message to be printed
214 * @param bool Return the output?
216 * @return mixed Output or null
218 function _message($title, $message, $type, $return = false
)
243 $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;\">";
244 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
245 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
258 * Custom error handler for ISSO
260 * @param int Error number
261 * @param str Error message string
262 * @param str File that contains the error
263 * @param str The line number of the error
264 * @param str The active symbol table at which point the error occurred
266 function _error_handler($errno, $errstr, $errfile, $errline)
273 if (!(ini_get('error_reporting') & ERR_FATAL
))
282 if (!(ini_get('error_reporting') & ERR_ALERT
))
292 if (!(ini_get('error_reporting') & ERR_WARNING
))
299 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
301 $this->_message($title, $errstr, 3);
303 if ($errno == ERR_FATAL
)
310 * Logs a debug message for verbose output
314 function debug($message)
318 $this->debuginfo
[] = $message;
323 * Recursive XSS cleaner
325 * @param mixed Unsanitized REQUEST data
327 * @return mixed Sanitized data
329 function _sanitize_input_recursive($data)
331 foreach($data AS $key => $value)
333 if (is_array($value))
335 $data["$key"] = $this->_sanitize_input_recursive($value);
339 $data["$key"] = $this->sanitize($value);
346 * Simple way to protect against HTML attacks with Unicode support
348 * @param str Unsanitzed text
350 * @return str Properly protected text that only encodes potential threats
352 function sanitize($text)
354 if ($this->magicquotes
)
356 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
360 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
365 * Takes text that has been processed for HTML and unsanitizes it
367 * @param str Text that needs to be turned back into HTML
369 * @return str Unsanitized text
371 function unsanitize($text)
373 if ($this->magicquotes
)
375 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
379 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
384 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
386 * @param str Some string
388 * @return str String that has slashes added
390 function escape($str)
394 if ($this->magicquotes
)
400 if (isset($_isso->db
))
402 if (is_resource($_isso->db
->link_id
))
404 return $_isso->db
->escape_string($str);
408 return addslashes($str);
413 return addslashes($str);
420 * Global callback used for module calls back to the kernel
422 $_isso = new Shared_Object_Framework();
425 * Wrapper for ternary operator that has to be in the global scope
427 * @param expr Expression
428 * @param mixed If the expression is true
429 * @param mixed If the expression is false
431 * @return mixed True or false data
433 function iff($condition, $iftrue, $iffalse = null
)
435 return ($condition) ?
($iftrue) : ($iffalse);
438 /*=====================================================================*\
439 || ###################################################################
442 || ###################################################################
443 \*=====================================================================*/