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 $fileIncluded = @include
($classNameLow . '.class.php');
53 // var_dump( $classNameLow . '.class.php');
54 // var_dump( $fileIncluded);
55 if ( !$fileIncluded ) {
56 // var_dump($classNameLow . DIRECTORY_SEPARATOR . $classNameLow . '.class.php');
57 $fileIncluded = @include
($classNameLow . DIRECTORY_SEPARATOR
. $classNameLow . '.class.php');
59 // var_dump($fileIncluded);
64 * the __autoload automagic function for class initialization,
67 * @param string $className
69 function __autoload ($className) {
70 if (class_exists ($className, false)) {
73 return usingClass ($className);
77 * returns true if the user's ip is in our list of debug ips
82 if (stristr(C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG
)
88 if (!function_exists('usingClass')) {
90 * The php4 function for including the class file
92 * @param string $className
95 function usingClass($className) {
96 if (class_exists($className)) {
100 $classNameLow = strtolower($className);
103 $classPaths = array (
104 $classNameLow . '.class.php', // regular homegrown class
105 $classNameLow . DIRECTORY_SEPARATOR
.$classNameLow . '.class.php', // regular page
106 $classNameLow . DIRECTORY_SEPARATOR
. $classNameLow.'.class.php', // imported
109 foreach ($classPaths as $classPath) {
110 $fileIncluded = @include
($classPath);
117 if (!$fileIncluded) {
118 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR
);
122 if (!class_exists($className)) {
123 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR
);
129 * Dumb function for email validation
131 * @param string $address
134 function emailIsValid ($address) {
137 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
143 function getDirFiles ( $dir, $showHidden = false){
147 trigger_error('Can not find : '.$dir);
150 if ( $root = @opendir
($dir) ){
151 while ($file = readdir ($root)){
152 if ( ($file == '.' ||
$file == '..') ||
($showHidden == false && stripos($file, '.') === 0)){continue;}
154 if (substr($dir, -1) != '/') $dir .= '/';
156 if( is_dir ($dir . $file) ){
157 $files = array_merge($files, getDirFiles($dir . $file));
159 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
166 function isDBLink($incData) {
167 if (sqlFactory
::validType(DB_TYPE
) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE
)) {
173 if (!function_exists('mime_content_type')) {
174 function mime_content_type ($filename) {
175 $t = getimagesize($filename);
180 return 'application/unknown';