* changed the name of the mysql improved sql driver
[vsc.git] / _res / _libs / functions.inc.php
blobdcb4ac354a5038f26cb32197f045d10a69dede4d
1 <?php
2 /**
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
6 * @param $severity
7 * @param $message
8 * @param $filename
9 * @param $lineno
10 * @throws ErrorException
11 * @return unknown_type
13 function exceptions_error_handler ($severity, $message, $filename, $lineno) {
14 if (error_reporting() == 0) {
15 return;
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)) {
33 set_include_path(
34 $pkgPath . PATH_SEPARATOR .
35 $path
37 return true;
38 } else {
39 import ('coreexceptions');
40 throw new PackageImportException ("bad package " . $packageName);
44 function usingClass ($className) {
45 if (class_exists ($className, false)) {
46 return true;
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);
60 return $fileIncluded;
63 /**
64 * the __autoload automagic function for class initialization,
65 * see usingClass
67 * @param string $className
69 function __autoload ($className) {
70 if (class_exists ($className, false)) {
71 return true;
73 return usingClass ($className);
76 /**
77 * returns true if the user's ip is in our list of debug ips
79 * @return bool
81 function isDebug (){
82 if (stristr(C_SYSTEM_DEBUG_IPS, $_SERVER['REMOTE_ADDR']) && C_SYSTEM_DEBUG)
83 return true;
85 return false;
88 if (!function_exists('usingClass')) {
89 /**
90 * The php4 function for including the class file
92 * @param string $className
93 * @return bool
95 function usingClass($className) {
96 if (class_exists($className)) {
97 return true;
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);
112 if ($fileIncluded) {
113 return true;
117 if (!$fileIncluded) {
118 trigger_error ('Not found file containing '. $className .'.', E_USER_ERROR);
119 return false;
122 if (!class_exists($className)) {
123 trigger_error ('Unable to load class '.$className.' in path '.get_include_path().'.class.php', E_USER_ERROR);
124 return false;
129 * Dumb function for email validation
131 * @param string $address
132 * @return bool
134 function emailIsValid ($address) {
135 return (
136 ereg(
137 '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
138 $address
143 function getDirFiles ( $dir, $showHidden = false){
145 $files = array();
146 if (!is_dir($dir)){
147 trigger_error('Can not find : '.$dir);
148 return false;
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));
158 } else {
159 /*if ( stristr($file, 'tpl') )*/ $files[] = $dir . $file;
163 return $files;
166 function isDBLink($incData) {
167 if (sqlFactory::validType(DB_TYPE) && is_resource($incData) && stristr(get_resource_type($incData),DB_TYPE)) {
168 return true;
170 return false;
173 if (!function_exists('mime_content_type')) {
174 function mime_content_type ($filename) {
175 $t = getimagesize($filename);
177 if (is_array($t))
178 return $t['mime'];
179 else
180 return 'application/unknown';