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);
27 return (php_sapi_name() == 'cli');
31 * returns an end of line, based on the environment
35 return isCli() ?
"\n" : '<br/>'. "\n";
39 * Removes all extra spaces from a string
43 function alltrim ($s) {
44 return trim(preg_replace('/\s+/', ' ', $s));
48 $aRgs = func_get_args();
52 // not running in console
55 foreach ($aRgs as $object) {
60 // not running in console
68 * @param string $sPackageName
71 function import ($sPackageName) {
72 return usingPackage($sPackageName);
75 * Adds the package name to the include path
76 * @todo make sure that the path isn't aleady in the include path
77 * @param string $packageName
79 * @throws tsExceptionPackageImport
81 function usingPackage ($packageName) {
82 $pkgLower = strtolower($packageName);
83 $pkgPath = LIB_PATH
. DIRECTORY_SEPARATOR
. $pkgLower;
85 $path = get_include_path();
86 if (is_dir($pkgPath)) {
87 if (strpos ($path, $pkgPath) === false) {
88 // adding exceptions dir to include path if it exists
89 if (is_dir ($pkgPath. DIRECTORY_SEPARATOR
. 'exceptions')) {
90 // adding the exceptions if they exist
91 $pkgPath .= PATH_SEPARATOR
. $pkgPath . DIRECTORY_SEPARATOR
. 'exceptions';
94 $path . PATH_SEPARATOR
.
100 usingPackage ('coreexceptions');
101 throw new tsExceptionPackageImport ("bad package " . $packageName);
105 function usingClass ($className) {
106 if (class_exists ($className, false)) {
110 $classNameLow = strtolower($className);
113 $fileIncluded = @include
($classNameLow . '.class.php');
114 if ( !$fileIncluded ) {
115 $fileIncluded = @include
($classNameLow . DIRECTORY_SEPARATOR
. $classNameLow . '.class.php');
117 return $fileIncluded;
121 * the __autoload automagic function for class initialization,
124 * @param string $className
126 function __autoload ($className) {
127 if (class_exists ($className, false)) {
130 return usingClass ($className);
134 * returns true if the user's ip is in our list of debug ips
139 if (stristr(C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG
)
145 if (!function_exists('usingClass')) {
147 * The php4 function for including the class file
149 * @param string $className
152 function usingClass($className) {
153 if (class_exists($className)) {
157 $classNameLow = strtolower($className);
160 $classPaths = array (
161 $classNameLow . '.class.php', // regular homegrown class
162 $classNameLow . DIRECTORY_SEPARATOR
.$classNameLow . '.class.php', // regular page
163 $classNameLow . DIRECTORY_SEPARATOR
. $classNameLow.'.class.php', // imported
166 foreach ($classPaths as $classPath) {
167 $fileIncluded = @include
($classPath);
174 if (!$fileIncluded) {
175 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR
);
179 if (!class_exists($className)) {
180 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR
);
187 * Dumb function for email validation
189 * @param string $address
192 function emailIsValid ($address) {
195 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
201 function getDirFiles ( $dir, $showHidden = false){
205 trigger_error('Can not find : '.$dir);
208 if ( $root = @opendir
($dir) ){
209 while ($file = readdir ($root)){
210 if ( ($file == '.' ||
$file == '..') ||
($showHidden == false && stripos($file, '.') === 0)){continue;}
212 if (substr($dir, -1) != '/') $dir .= '/';
214 if( is_dir ($dir . $file) ){
215 $files = array_merge($files, getDirFiles($dir . $file));
217 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
224 function isDBLink($incData) {
225 if (sqlFactory
::validType(DB_TYPE
) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE
)) {
231 if (!function_exists('mime_content_type')) {
232 function mime_content_type ($filename) {
233 $t = getimagesize($filename);
238 return 'application/unknown';