3 * Function to turn the triggered errors into exceptions
4 * @author troelskn at gmail dot com
5 * @from http://php.net/manual/en/class.errorexception.php
10 * @throws ErrorException
11 * @return unknown_type
13 function exceptions_error_handler ($severity, $message, $filename, $lineno) {
14 if (error_reporting() == 0) {
18 if (error_reporting() & $severity) {
19 throw new ErrorException ($message, 0, $severity, $filename, $lineno);
23 function import ($sPackageName) {
24 return usingPackage($sPackageName);
27 function usingPackage ($packageName) {
28 $pkgLower = strtolower($packageName);
29 $pkgPath = LIB_PATH
. DIRECTORY_SEPARATOR
. $pkgLower;
31 $path = get_include_path();
32 if (is_dir($pkgPath) && !strpos ($pkgPath, $path)) {
34 $pkgPath . PATH_SEPARATOR
.
39 import ('coreexceptions');
40 throw new PackageImportException ("bad package " . $packageName);
44 function usingClass ($className) {
45 if (class_exists ($className, false)) {
49 $classNameLow = strtolower($className);
52 // regular package classes
53 // echo $classNameLow . '.class.php<br/>' ;
54 $fileIncluded = include ($classNameLow . '.class.php');
55 } catch (ErrorException
$e) {
56 // classes inside page path
58 // echo $classNameLow . DIRECTORY_SEPARATOR . $classNameLow . '.class.php<br/>';
59 $fileIncluded = include ($classNameLow . DIRECTORY_SEPARATOR
. $classNameLow . '.class.php');
60 } catch (ErrorException
$e) {
61 import ('coreexceptions');
62 throw new tsExceptionAutoload ('Not found file containing '. $className .' in path ' . get_include_path());
69 * the __autoload automagic function for class initialization,
72 * @param string $className
74 function __autoload ($className) {
75 return usingClass ($className);
79 * returns true if the user's ip is in our list of debug ips
84 if (stristr(C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG
)
90 if (!function_exists('usingClass')) {
92 * The php4 function for including the class file
94 * @param string $className
97 function usingClass($className) {
98 if (class_exists($className)) {
102 $classNameLow = strtolower($className);
105 $classPaths = array (
106 $classNameLow . '.class.php', // regular homegrown class
107 $classNameLow . DIRECTORY_SEPARATOR
.$classNameLow . '.class.php', // regular page
108 $classNameLow . DIRECTORY_SEPARATOR
. $classNameLow.'.class.php', // imported
111 foreach ($classPaths as $classPath) {
112 $fileIncluded = @include
($classPath);
119 if (!$fileIncluded) {
120 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR
);
124 if (!class_exists($className)) {
125 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR
);
131 * Dumb function for email validation
133 * @param string $address
136 function emailIsValid ($address) {
139 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
145 function getDirFiles ( $dir, $showHidden = false){
149 trigger_error('Can not find : '.$dir);
152 if ( $root = @opendir
($dir) ){
153 while ($file = readdir ($root)){
154 if ( ($file == '.' ||
$file == '..') ||
($showHidden == false && stripos($file, '.') === 0)){continue;}
156 if (substr($dir, -1) != '/') $dir .= '/';
158 if( is_dir ($dir . $file) ){
159 $files = array_merge($files, getDirFiles($dir . $file));
161 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
168 function isDBLink($incData) {
169 if (sqlFactory
::validType(DB_TYPE
) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE
)) {
175 if (!function_exists('mime_content_type')) {
176 function mime_content_type ($filename) {
177 $t = getimagesize($filename);
182 return 'application/unknown';