3 * Function to turn the triggered errors into exceptions
4 * @author troelskn at gmail dot com
5 * @see http://php.net/manual/en/class.errorexception.php
10 * @throws ErrorException
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);
24 $aRgs = func_get_args();
27 if (php_sapi_name() != 'cli') {
28 // not running in console
32 foreach ($aRgs as $object) {
41 * @param string $sPackageName
44 function import ($sPackageName) {
45 return usingPackage($sPackageName);
48 * Adds the package name to the include path
49 * @todo make sure that the path isn't aleady in the include path
50 * @param string $packageName
52 * @throws tsExceptionPackageImport
54 function usingPackage ($packageName) {
55 $pkgLower = strtolower($packageName);
56 $pkgPath = LIB_PATH
. DIRECTORY_SEPARATOR
. $pkgLower;
58 $path = get_include_path();
59 if (is_dir($pkgPath)) {
60 if (strpos ($path, $pkgPath) === false) {
61 // adding exceptions dir to include path if it exists
62 if (is_dir ($pkgPath. DIRECTORY_SEPARATOR
. 'exceptions')) {
63 // adding the exceptions if they exist
64 $pkgPath .= PATH_SEPARATOR
. $pkgPath . DIRECTORY_SEPARATOR
. 'exceptions';
67 $path . PATH_SEPARATOR
.
75 usingPackage ('coreexceptions');
76 throw new tsExceptionPackageImport ("bad package " . $packageName);
80 function usingClass ($className) {
81 if (class_exists ($className, false)) {
85 $classNameLow = strtolower($className);
88 $fileIncluded = @include
($classNameLow . '.class.php');
89 if ( !$fileIncluded ) {
90 $fileIncluded = @include
($classNameLow . DIRECTORY_SEPARATOR
. $classNameLow . '.class.php');
96 * the __autoload automagic function for class initialization,
99 * @param string $className
101 function __autoload ($className) {
102 if (class_exists ($className, false)) {
105 return usingClass ($className);
109 * returns true if the user's ip is in our list of debug ips
114 if (stristr(C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG
)
120 if (!function_exists('usingClass')) {
122 * The php4 function for including the class file
124 * @param string $className
127 function usingClass($className) {
128 if (class_exists($className)) {
132 $classNameLow = strtolower($className);
135 $classPaths = array (
136 $classNameLow . '.class.php', // regular homegrown class
137 $classNameLow . DIRECTORY_SEPARATOR
.$classNameLow . '.class.php', // regular page
138 $classNameLow . DIRECTORY_SEPARATOR
. $classNameLow.'.class.php', // imported
141 foreach ($classPaths as $classPath) {
142 $fileIncluded = @include
($classPath);
149 if (!$fileIncluded) {
150 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR
);
154 if (!class_exists($className)) {
155 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR
);
162 * Dumb function for email validation
164 * @param string $address
167 function emailIsValid ($address) {
170 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
176 function getDirFiles ( $dir, $showHidden = false){
180 trigger_error('Can not find : '.$dir);
183 if ( $root = @opendir
($dir) ){
184 while ($file = readdir ($root)){
185 if ( ($file == '.' ||
$file == '..') ||
($showHidden == false && stripos($file, '.') === 0)){continue;}
187 if (substr($dir, -1) != '/') $dir .= '/';
189 if( is_dir ($dir . $file) ){
190 $files = array_merge($files, getDirFiles($dir . $file));
192 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
199 function isDBLink($incData) {
200 if (sqlFactory
::validType(DB_TYPE
) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE
)) {
206 if (!function_exists('mime_content_type')) {
207 function mime_content_type ($filename) {
208 $t = getimagesize($filename);
213 return 'application/unknown';