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 (PHP_VERSION
< '4.1.0')
19 trigger_error('You need PHP version 4.1.0 or newer to run ISSO', ERR_FATAL
);
23 if ((bool
)ini_get('register_globals') === true
)
25 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
26 foreach ($superglobals AS $global)
28 if (is_array($
{$global}))
30 foreach ($
{$global} AS $_key => $_val)
42 * Iris Studios Shared Object Framework (ISSO)
44 * This framework allows a common backend to be used amongst all Iris
45 * Studios applications and can is built to be abstract and flexible.
46 * The base framework handles all loading and module management.
48 * @author Iris Studios, Inc.
49 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
53 class Shared_Object_Framework
56 * Global environment variables
58 * This is where we keep the global variables that are used within the shared framework
60 * @var version ISSO version
61 * @var sourcepath The location of the framework sources
62 * @var appath The path to the application's location
63 * @var application The name of the application that is using the framework
64 * @var debug Variable for debug mode
65 * @var debuginfo Listing of all debug notices
66 * @var modules An array of loaded framework modules
67 * @var input All input data for the system
68 * @var magicquotes Status of Magic Quotes GPC
70 var $version = '[#]version[#]';
73 var $application = '';
75 var $debuginfo = array();
76 var $modules = array();
83 function Shared_Object_Framework()
86 set_error_handler(array(&$this, '_error_handler'));
89 $this->magicquotes
= get_magic_quotes_gpc();
90 set_magic_quotes_runtime(0);
92 // start input sanitize using variable_order GP
93 $this->input
= $this->_sanitize_input_recursive(array_merge($_GET, $_POST));
95 $this->modules
['kernel'] = 'Shared Object Framework Core';
99 * Prepares a path for being set as the sourcepath
101 * @param str Source path or URL
103 * @return str Prepared source path
105 function fetch_sourcepath($source)
107 if (substr($source, strlen($source) - 1) != '/')
115 * Loads a framework extension
117 * @param str Name of the framework
119 function load($framework)
121 if (!$this->is_loaded($framework))
123 $newobj = $this->locate($framework);
124 $this->$newobj['OBJ'] = new $newobj['CLASS']();
125 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
126 $this->modules
["$framework"] = $newobj['OBJECT'];
131 * Includes a framework module. Module definitions need three variables:
132 * class, object, and obj. Class is the name of the class, object is
133 * the name human-readable name, and obj is the name that the module
134 * should be initialized as; this is used in class extensions.
136 * @param str Name of the framework
138 * @return array List of initialization variables
140 function locate($framework)
142 if ($this->sourcepath
== '')
144 trigger_error('Invalid sourcepath specified', ERR_FATAL
);
147 if (file_exists($this->sourcepath
. $framework . '.php'))
149 require_once($this->sourcepath
. $framework . '.php');
150 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
154 trigger_error('Could not find the framework ' . $this->sourcepath
. $framework . '.php', ERR_FATAL
);
160 * Prints a list of all currently loaded framework modules
162 * @param bool Return the data as an array?
164 * @return mixed HTML output or an array of loaded modules
166 function show_modules($return = false
)
170 return $this->modules
;
174 $output = "\n\n<ul>\n\t<li>";
175 $output .= implode("</li>\n\t<li>", $this->modules
);
176 $output .= "</li>\n</ul>\n\n";
177 $this->_message('Loaded Modules', $output, 1);
182 * Verifies to see if a framework has been loaded
184 * @param str Framework name
186 * @return bool Whether or not the framework has been loaded
188 function is_loaded($framework)
190 if (isset($this->modules
["$framework"]))
201 * Prints an ISSO message
203 * @param str The title of the message
204 * @param str The content of the message
205 * @param int Type of message to be printed
206 * @param bool Return the output?
208 * @return mixed Output or null
210 function _message($title, $message, $type, $return = false
)
235 $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;\">";
236 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
237 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
250 * Custom error handler for ISSO
252 * @param int Error number
253 * @param str Error message string
254 * @param str File that contains the error
255 * @param str The line number of the error
256 * @param str The active symbol table at which point the error occurred
258 function _error_handler($errno, $errstr, $errfile, $errline)
279 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
281 $this->_message($title, $errstr, 3);
283 if ($errno == ERR_FATAL
)
290 * Logs a debug message for verbose output
294 function debug($message)
298 $this->debuginfo
[] = $message;
303 * Recursive XSS cleaner
305 * @param mixed Unsanitized REQUEST data
307 * @return mixed Sanitized data
309 function _sanitize_input_recursive($data)
311 foreach($data AS $key => $value)
313 if (is_array($value))
315 $data["$key"] = $this->_sanitize_input_recursive($value);
319 $data["$key"] = $this->sanitize($value);
326 * Simple way to protect against HTML attacks with Unicode support
328 * @param str Unsanitzed text
330 * @return str Properly protected text that only encodes potential threats
332 function sanitize($text)
334 if ($this->magicquotes
)
336 return str_replace(array('<', '>', '\"', '"'), array('<', '>', '"', '"'), $text);
340 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
345 * Takes text that has been processed for HTML and unsanitizes it
347 * @param str Text that needs to be turned back into HTML
349 * @return str Unsanitized text
351 function unsanitize($text)
353 if ($this->magicquotes
)
355 return str_replace(array('<', '>', '"'), array('<', '>', '\"'), $text);
359 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
364 * Smart addslashes() that only applies itself it the Magic Quotes GPC is off
366 * @param str Some string
368 * @return str String that has slashes added
370 function escape($str)
374 if ($this->magicquotes
)
380 if (isset($_isso->db
))
382 if (is_resource($_isso->db
->link_id
))
384 return $_isso->db
->escape_string($str);
388 return addslashes($str);
393 return addslashes($str);
400 * Global callback used for module calls back to the kernel
402 $_isso = new Shared_Object_Framework();
405 * Wrapper for ternary operator that has to be in the global scope
407 * @param expr Expression
408 * @param mixed If the expression is true
409 * @param mixed If the expression is false
411 * @return mixed True or false data
413 function iff($condition, $iftrue, $iffalse = null
)
415 return ($condition) ?
($iftrue) : ($iffalse);
418 /*=====================================================================*\
419 || ###################################################################
422 || ###################################################################
423 \*=====================================================================*/