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);
112 $sFilePath = $classNameLow . '.class.php';
113 $fileIncluded = @include
($sFilePath);
114 if ( !$fileIncluded ) {
115 $sFilePath = $classNameLow . DIRECTORY_SEPARATOR
. $sFilePath;
116 $fileIncluded = @include
($sFilePath);
119 return $fileIncluded;
123 * the __autoload automagic function for class initialization,
126 * @param string $className
128 function __autoload ($className) {
129 if (class_exists ($className, false)) {
132 return usingClass ($className);
136 * returns true if the user's ip is in our list of debug ips
141 if (stristr(C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG
)
147 if (!function_exists('usingClass')) {
149 * The php4 function for including the class file
151 * @param string $className
154 function usingClass($className) {
155 if (class_exists($className)) {
159 $classNameLow = strtolower($className);
162 $classPaths = array (
163 $classNameLow . '.class.php', // regular homegrown class
164 $classNameLow . DIRECTORY_SEPARATOR
.$classNameLow . '.class.php', // regular page
165 $classNameLow . DIRECTORY_SEPARATOR
. $classNameLow.'.class.php', // imported
168 foreach ($classPaths as $classPath) {
169 $fileIncluded = @include
($classPath);
176 if (!$fileIncluded) {
177 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR
);
181 if (!class_exists($className)) {
182 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR
);
189 * Dumb function for email validation
191 * @param string $address
194 function emailIsValid ($address) {
197 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
203 function getDirFiles ( $dir, $showHidden = false){
207 trigger_error('Can not find : '.$dir);
210 if ( $root = @opendir
($dir) ){
211 while ($file = readdir ($root)){
212 if ( ($file == '.' ||
$file == '..') ||
($showHidden == false && stripos($file, '.') === 0)){continue;}
214 if (substr($dir, -1) != '/') $dir .= '/';
216 if( is_dir ($dir . $file) ){
217 $files = array_merge($files, getDirFiles($dir . $file));
219 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
226 function isDBLink($incData) {
227 if (sqlFactory
::validType(DB_TYPE
) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE
)) {
233 if (!function_exists('mime_content_type')) {
234 function mime_content_type ($filename) {
235 $t = getimagesize($filename);
240 return 'application/unknown';