@@ -11,176 +11,176 @@ |
||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | public static function isModRewriteAvailable () { |
| 14 | - if (function_exists("apache_get_modules")) { |
|
| 15 | - if (in_array('mod_rewrite',apache_get_modules())) { |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 14 | + if (function_exists("apache_get_modules")) { |
|
| 15 | + if (in_array('mod_rewrite',apache_get_modules())) { |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - return false; |
|
| 20 | - } |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return false; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public static function startsWith ($haystack, $needle) : bool { |
|
| 26 | - //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 27 | 24 | |
| 28 | - $length = strlen($needle); |
|
| 29 | - return (substr($haystack, 0, $length) === $needle); |
|
| 30 | - } |
|
| 25 | + public static function startsWith ($haystack, $needle) : bool { |
|
| 26 | + //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php |
|
| 31 | 27 | |
| 32 | - public static function endsWith ($haystack, $needle) : bool { |
|
| 33 | - $length = strlen($needle); |
|
| 28 | + $length = strlen($needle); |
|
| 29 | + return (substr($haystack, 0, $length) === $needle); |
|
| 30 | + } |
|
| 34 | 31 | |
| 35 | - return $length === 0 || (substr($haystack, -$length) === $needle); |
|
| 36 | - } |
|
| 32 | + public static function endsWith ($haystack, $needle) : bool { |
|
| 33 | + $length = strlen($needle); |
|
| 37 | 34 | |
| 38 | - /** |
|
| 39 | - * get IP address of client browser |
|
| 40 | - * |
|
| 41 | - * @return IPv4 / IPv6 address (up to 45 characters) |
|
| 42 | - */ |
|
| 43 | - public static function getClientIP () : string { |
|
| 44 | - //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php |
|
| 35 | + return $length === 0 || (substr($haystack, -$length) === $needle); |
|
| 36 | + } |
|
| 45 | 37 | |
| 46 | - $ip = ""; |
|
| 38 | + /** |
|
| 39 | + * get IP address of client browser |
|
| 40 | + * |
|
| 41 | + * @return IPv4 / IPv6 address (up to 45 characters) |
|
| 42 | + */ |
|
| 43 | + public static function getClientIP () : string { |
|
| 44 | + //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php |
|
| 45 | + |
|
| 46 | + $ip = ""; |
|
| 47 | + |
|
| 48 | + if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 49 | + $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
| 50 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 51 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 52 | + } else { |
|
| 53 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $ip; |
|
| 57 | + } |
|
| 47 | 58 | |
| 48 | - if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 49 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
| 50 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 51 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 52 | - } else { |
|
| 53 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 54 | - } |
|
| 59 | + public static function strEqs (string $str1, string $str2) : bool { |
|
| 60 | + return strcmp($str1, $str2) === 0; |
|
| 61 | + } |
|
| 55 | 62 | |
| 56 | - return $ip; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public static function strEqs (string $str1, string $str2) : bool { |
|
| 60 | - return strcmp($str1, $str2) === 0; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Generate a random string, using a cryptographically secure |
|
| 65 | - * pseudorandom number generator (random_int) |
|
| 66 | - * |
|
| 67 | - * For PHP 7, random_int is a PHP core function |
|
| 68 | - * For PHP 5.x, depends on https://github.com/paragonie/random_compat |
|
| 69 | - * |
|
| 70 | - * @param int $length How many characters do we want? |
|
| 71 | - * @param string $keyspace A string of all possible characters |
|
| 72 | - * to select from |
|
| 73 | - * |
|
| 74 | - * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425 |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string { |
|
| 79 | - $str = ''; |
|
| 80 | - $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 81 | - |
|
| 82 | - for ($i = 0; $i < $length; ++$i) { |
|
| 83 | - $str .= $keyspace[random_int(0, $max)]; |
|
| 84 | - } |
|
| 63 | + /** |
|
| 64 | + * Generate a random string, using a cryptographically secure |
|
| 65 | + * pseudorandom number generator (random_int) |
|
| 66 | + * |
|
| 67 | + * For PHP 7, random_int is a PHP core function |
|
| 68 | + * For PHP 5.x, depends on https://github.com/paragonie/random_compat |
|
| 69 | + * |
|
| 70 | + * @param int $length How many characters do we want? |
|
| 71 | + * @param string $keyspace A string of all possible characters |
|
| 72 | + * to select from |
|
| 73 | + * |
|
| 74 | + * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425 |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string { |
|
| 79 | + $str = ''; |
|
| 80 | + $max = mb_strlen($keyspace, '8bit') - 1; |
|
| 81 | + |
|
| 82 | + for ($i = 0; $i < $length; ++$i) { |
|
| 83 | + $str .= $keyspace[random_int(0, $max)]; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $str; |
|
| 87 | + } |
|
| 85 | 88 | |
| 86 | - return $str; |
|
| 87 | - } |
|
| 89 | + public static function getHostname () : string { |
|
| 90 | + if (function_exists("gethostname")) { |
|
| 91 | + return gethostname(); |
|
| 92 | + } else { |
|
| 93 | + //Or, an option that also works before PHP 5.3 |
|
| 94 | + return php_uname('n'); |
|
| 95 | + } |
|
| 96 | + } |
|
| 88 | 97 | |
| 89 | - public static function getHostname () : string { |
|
| 90 | - if (function_exists("gethostname")) { |
|
| 91 | - return gethostname(); |
|
| 92 | - } else { |
|
| 93 | - //Or, an option that also works before PHP 5.3 |
|
| 94 | - return php_uname('n'); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public static function sendPOSTRequest (string $url, array $data = array()) { |
|
| 99 | - //check, if allow_url_fopen is enabled |
|
| 100 | - if (PHPUtils::isUrlfopenEnabled()) { |
|
| 101 | - // use key 'http' even if you send the request to https://... |
|
| 102 | - $options = array( |
|
| 103 | - 'http' => array( |
|
| 104 | - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 105 | - 'method' => 'POST', |
|
| 106 | - 'content' => http_build_query($data) |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - $context = stream_context_create($options); |
|
| 110 | - $result = file_get_contents($url, false, $context); |
|
| 111 | - |
|
| 112 | - if ($result === FALSE) { |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $result; |
|
| 117 | - } else { |
|
| 118 | - //try to use curl instead |
|
| 119 | - |
|
| 120 | - //https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
|
| 121 | - |
|
| 122 | - //create a new curl session |
|
| 123 | - $ch = curl_init(); |
|
| 124 | - |
|
| 125 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 126 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
| 127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 128 | - |
|
| 129 | - //receive server response |
|
| 130 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 131 | - $result = curl_exec ($ch); |
|
| 132 | - |
|
| 133 | - //close curl session |
|
| 134 | - curl_close ($ch); |
|
| 135 | - |
|
| 136 | - return $result; |
|
| 137 | - } |
|
| 138 | - } |
|
| 98 | + public static function sendPOSTRequest (string $url, array $data = array()) { |
|
| 99 | + //check, if allow_url_fopen is enabled |
|
| 100 | + if (PHPUtils::isUrlfopenEnabled()) { |
|
| 101 | + // use key 'http' even if you send the request to https://... |
|
| 102 | + $options = array( |
|
| 103 | + 'http' => array( |
|
| 104 | + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
| 105 | + 'method' => 'POST', |
|
| 106 | + 'content' => http_build_query($data) |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + $context = stream_context_create($options); |
|
| 110 | + $result = file_get_contents($url, false, $context); |
|
| 111 | + |
|
| 112 | + if ($result === FALSE) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $result; |
|
| 117 | + } else { |
|
| 118 | + //try to use curl instead |
|
| 119 | + |
|
| 120 | + //https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
|
| 121 | + |
|
| 122 | + //create a new curl session |
|
| 123 | + $ch = curl_init(); |
|
| 124 | + |
|
| 125 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 126 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
| 127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 128 | + |
|
| 129 | + //receive server response |
|
| 130 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 131 | + $result = curl_exec ($ch); |
|
| 132 | + |
|
| 133 | + //close curl session |
|
| 134 | + curl_close ($ch); |
|
| 135 | + |
|
| 136 | + return $result; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public static function isUrlfopenEnabled () : bool { |
|
| 141 | - $res = ini_get("allow_url_fopen"); |
|
| 140 | + public static function isUrlfopenEnabled () : bool { |
|
| 141 | + $res = ini_get("allow_url_fopen"); |
|
| 142 | 142 | |
| 143 | - if ($res) { |
|
| 144 | - return true; |
|
| 145 | - } else { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - } |
|
| 143 | + if ($res) { |
|
| 144 | + return true; |
|
| 145 | + } else { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - public static function isCurlAvailable () : bool { |
|
| 151 | - /*if (in_array ('curl', get_loaded_extensions())) { |
|
| 150 | + public static function isCurlAvailable () : bool { |
|
| 151 | + /*if (in_array ('curl', get_loaded_extensions())) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | else { |
| 155 | 155 | return false; |
| 156 | 156 | }*/ |
| 157 | 157 | |
| 158 | - return function_exists('curl_version'); |
|
| 159 | - } |
|
| 158 | + return function_exists('curl_version'); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - public static function isGettextAvailable () : bool { |
|
| 162 | - return function_exists("gettext"); |
|
| 163 | - } |
|
| 161 | + public static function isGettextAvailable () : bool { |
|
| 162 | + return function_exists("gettext"); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - public static function clearGetTextCache () { |
|
| 166 | - //clear stats cache, often this clears also gettext cache |
|
| 167 | - clearstatcache(); |
|
| 168 | - } |
|
| 165 | + public static function clearGetTextCache () { |
|
| 166 | + //clear stats cache, often this clears also gettext cache |
|
| 167 | + clearstatcache(); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - public static function checkSessionStarted (bool $throw_exception = true) : bool { |
|
| 171 | - if (session_status() !== PHP_SESSION_ACTIVE) { |
|
| 172 | - if ($throw_exception) { |
|
| 173 | - throw new IllegalStateException("session wasnt started yet."); |
|
| 174 | - } |
|
| 170 | + public static function checkSessionStarted (bool $throw_exception = true) : bool { |
|
| 171 | + if (session_status() !== PHP_SESSION_ACTIVE) { |
|
| 172 | + if ($throw_exception) { |
|
| 173 | + throw new IllegalStateException("session wasnt started yet."); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - return false; |
|
| 177 | - } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - return true; |
|
| 180 | - } |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public static function containsStr (string $haystack, string $needle) : bool { |
|
| 183 | - return strpos($haystack, $needle) !== FALSE; |
|
| 184 | - } |
|
| 182 | + public static function containsStr (string $haystack, string $needle) : bool { |
|
| 183 | + return strpos($haystack, $needle) !== FALSE; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | } |
@@ -2,17 +2,17 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class PHPUtils { |
| 4 | 4 | |
| 5 | - public static function isMemcacheAvailable () { |
|
| 5 | + public static function isMemcacheAvailable() { |
|
| 6 | 6 | return class_exists('Memcache'); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | - public static function isMemcachedAvailable () { |
|
| 9 | + public static function isMemcachedAvailable() { |
|
| 10 | 10 | return class_exists('Memcached'); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - public static function isModRewriteAvailable () { |
|
| 13 | + public static function isModRewriteAvailable() { |
|
| 14 | 14 | if (function_exists("apache_get_modules")) { |
| 15 | - if (in_array('mod_rewrite',apache_get_modules())) { |
|
| 15 | + if (in_array('mod_rewrite', apache_get_modules())) { |
|
| 16 | 16 | return true; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | return false; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public static function startsWith ($haystack, $needle) : bool { |
|
| 25 | + public static function startsWith($haystack, $needle) : bool { |
|
| 26 | 26 | //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php |
| 27 | 27 | |
| 28 | 28 | $length = strlen($needle); |
| 29 | 29 | return (substr($haystack, 0, $length) === $needle); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public static function endsWith ($haystack, $needle) : bool { |
|
| 32 | + public static function endsWith($haystack, $needle) : bool { |
|
| 33 | 33 | $length = strlen($needle); |
| 34 | 34 | |
| 35 | 35 | return $length === 0 || (substr($haystack, -$length) === $needle); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return IPv4 / IPv6 address (up to 45 characters) |
| 42 | 42 | */ |
| 43 | - public static function getClientIP () : string { |
|
| 43 | + public static function getClientIP() : string { |
|
| 44 | 44 | //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php |
| 45 | 45 | |
| 46 | 46 | $ip = ""; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | return $ip; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public static function strEqs (string $str1, string $str2) : bool { |
|
| 59 | + public static function strEqs(string $str1, string $str2) : bool { |
|
| 60 | 60 | return strcmp($str1, $str2) === 0; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | return $str; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public static function getHostname () : string { |
|
| 89 | + public static function getHostname() : string { |
|
| 90 | 90 | if (function_exists("gethostname")) { |
| 91 | 91 | return gethostname(); |
| 92 | 92 | } else { |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public static function sendPOSTRequest (string $url, array $data = array()) { |
|
| 98 | + public static function sendPOSTRequest(string $url, array $data = array()) { |
|
| 99 | 99 | //check, if allow_url_fopen is enabled |
| 100 | 100 | if (PHPUtils::isUrlfopenEnabled()) { |
| 101 | 101 | // use key 'http' even if you send the request to https://... |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | 'content' => http_build_query($data) |
| 107 | 107 | ) |
| 108 | 108 | ); |
| 109 | - $context = stream_context_create($options); |
|
| 109 | + $context = stream_context_create($options); |
|
| 110 | 110 | $result = file_get_contents($url, false, $context); |
| 111 | 111 | |
| 112 | 112 | if ($result === FALSE) { |
@@ -124,20 +124,20 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | curl_setopt($ch, CURLOPT_URL, $url); |
| 126 | 126 | curl_setopt($ch, CURLOPT_POST, 1); |
| 127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //"postvar1=value1&postvar2=value2&postvar3=value3" |
|
| 128 | 128 | |
| 129 | 129 | //receive server response |
| 130 | 130 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 131 | - $result = curl_exec ($ch); |
|
| 131 | + $result = curl_exec($ch); |
|
| 132 | 132 | |
| 133 | 133 | //close curl session |
| 134 | - curl_close ($ch); |
|
| 134 | + curl_close($ch); |
|
| 135 | 135 | |
| 136 | 136 | return $result; |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public static function isUrlfopenEnabled () : bool { |
|
| 140 | + public static function isUrlfopenEnabled() : bool { |
|
| 141 | 141 | $res = ini_get("allow_url_fopen"); |
| 142 | 142 | |
| 143 | 143 | if ($res) { |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public static function isCurlAvailable () : bool { |
|
| 150 | + public static function isCurlAvailable() : bool { |
|
| 151 | 151 | /*if (in_array ('curl', get_loaded_extensions())) { |
| 152 | 152 | return true; |
| 153 | 153 | } |
@@ -158,16 +158,16 @@ discard block |
||
| 158 | 158 | return function_exists('curl_version'); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public static function isGettextAvailable () : bool { |
|
| 161 | + public static function isGettextAvailable() : bool { |
|
| 162 | 162 | return function_exists("gettext"); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public static function clearGetTextCache () { |
|
| 165 | + public static function clearGetTextCache() { |
|
| 166 | 166 | //clear stats cache, often this clears also gettext cache |
| 167 | 167 | clearstatcache(); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public static function checkSessionStarted (bool $throw_exception = true) : bool { |
|
| 170 | + public static function checkSessionStarted(bool $throw_exception = true) : bool { |
|
| 171 | 171 | if (session_status() !== PHP_SESSION_ACTIVE) { |
| 172 | 172 | if ($throw_exception) { |
| 173 | 173 | throw new IllegalStateException("session wasnt started yet."); |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | return true; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public static function containsStr (string $haystack, string $needle) : bool { |
|
| 182 | + public static function containsStr(string $haystack, string $needle) : bool { |
|
| 183 | 183 | return strpos($haystack, $needle) !== FALSE; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -107,47 +107,47 @@ discard block |
||
| 107 | 107 | require(ROOT_PATH . "system/core/classes/" . strtolower($classname) . ".php"); |
| 108 | 108 | return null; |
| 109 | 109 | } else if (file_exists(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php")) { |
| 110 | - require(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php"); |
|
| 111 | - return null; |
|
| 112 | - } else if (file_exists(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php")) { |
|
| 113 | - require(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php"); |
|
| 114 | - return null; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - //check, if class belongs to dwoo template engine |
|
| 110 | + require(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php"); |
|
| 111 | + return null; |
|
| 112 | + } else if (file_exists(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php")) { |
|
| 113 | + require(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php"); |
|
| 114 | + return null; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + //check, if class belongs to dwoo template engine |
|
| 118 | 118 | if (PHPUtils::startsWith($classname, "Dwoo")) { |
| 119 | 119 | if (class_exists("DwooAutoloader", true)) { |
| 120 | 120 | DwooAutoloader::loadClass($classname); |
| 121 | 121 | return; |
| 122 | 122 | } else { |
| 123 | - echo "Could not load Dwoo template engine class " . $classname . "!"; |
|
| 123 | + echo "Could not load Dwoo template engine class " . $classname . "!"; |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | //check, if we have to use namespace classloading |
| 128 | - if (PHPUtils::containsStr($classname, "\\")) { |
|
| 129 | - //we have to use namespace classloading |
|
| 130 | - if (PHPUtils::startsWith($classname, "\\")) { |
|
| 131 | - //use normal class loading |
|
| 132 | - $classname = substr($classname, 1); |
|
| 133 | - } else { |
|
| 134 | - $array = explode("_", $classname); |
|
| 135 | - |
|
| 136 | - if ($array[0] === "Plugin") { |
|
| 137 | - //load plugin class |
|
| 138 | - $path = PLUGIN_PATH . $array[1] . "/" . str_replace("\\", "/", $array[2]) . ".php"; |
|
| 139 | - |
|
| 140 | - if (file_exists($path)) { |
|
| 141 | - require($path); |
|
| 142 | - } else { |
|
| 143 | - $expected_str = (DEBUG_MODE ? " (expected path: " . $path . ")" : ""); |
|
| 144 | - echo "Could not load plugin-class with namespace " . $classname . $expected_str . "!"; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return; |
|
| 149 | - } |
|
| 150 | - } |
|
| 128 | + if (PHPUtils::containsStr($classname, "\\")) { |
|
| 129 | + //we have to use namespace classloading |
|
| 130 | + if (PHPUtils::startsWith($classname, "\\")) { |
|
| 131 | + //use normal class loading |
|
| 132 | + $classname = substr($classname, 1); |
|
| 133 | + } else { |
|
| 134 | + $array = explode("_", $classname); |
|
| 135 | + |
|
| 136 | + if ($array[0] === "Plugin") { |
|
| 137 | + //load plugin class |
|
| 138 | + $path = PLUGIN_PATH . $array[1] . "/" . str_replace("\\", "/", $array[2]) . ".php"; |
|
| 139 | + |
|
| 140 | + if (file_exists($path)) { |
|
| 141 | + require($path); |
|
| 142 | + } else { |
|
| 143 | + $expected_str = (DEBUG_MODE ? " (expected path: " . $path . ")" : ""); |
|
| 144 | + echo "Could not load plugin-class with namespace " . $classname . $expected_str . "!"; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | $array = explode("_", strtolower($classname)); |
| 153 | 153 | |
@@ -170,32 +170,32 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | } else if (sizeof($array) == 2) { |
| 173 | - if ($array[0] == "validator") { |
|
| 174 | - if (file_exists(ROOT_PATH . "system/core/validator/" . $array[1] . ".php")) { |
|
| 175 | - require(ROOT_PATH . "system/core/validator/" . $array[1] . ".php"); |
|
| 176 | - } else { |
|
| 177 | - echo "Could not load validator class " . $classname . "!"; |
|
| 178 | - } |
|
| 179 | - } else if ($array[0] == "datatype") { |
|
| 180 | - if (file_exists(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php")) { |
|
| 181 | - require(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php"); |
|
| 182 | - } else { |
|
| 183 | - echo "Could not load datatype class " . $classname . "!"; |
|
| 184 | - } |
|
| 185 | - } else if (strpos($classname, "Plugin")) { |
|
| 186 | - //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
|
| 187 | - } else { |
|
| 188 | - echo "Could not load class " . $classname . ", unknown prefix '" . $array[0] . "'!"; |
|
| 173 | + if ($array[0] == "validator") { |
|
| 174 | + if (file_exists(ROOT_PATH . "system/core/validator/" . $array[1] . ".php")) { |
|
| 175 | + require(ROOT_PATH . "system/core/validator/" . $array[1] . ".php"); |
|
| 176 | + } else { |
|
| 177 | + echo "Could not load validator class " . $classname . "!"; |
|
| 178 | + } |
|
| 179 | + } else if ($array[0] == "datatype") { |
|
| 180 | + if (file_exists(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php")) { |
|
| 181 | + require(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php"); |
|
| 182 | + } else { |
|
| 183 | + echo "Could not load datatype class " . $classname . "!"; |
|
| 184 | + } |
|
| 185 | + } else if (strpos($classname, "Plugin")) { |
|
| 186 | + //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
|
| 187 | + } else { |
|
| 188 | + echo "Could not load class " . $classname . ", unknown prefix '" . $array[0] . "'!"; |
|
| 189 | 189 | } |
| 190 | - } else if (sizeOf($array) == 1) { |
|
| 190 | + } else if (sizeOf($array) == 1) { |
|
| 191 | 191 | |
| 192 | 192 | if (file_exists(ROOT_PATH . "system/classes/" . strtolower($classname) . ".php")) { |
| 193 | 193 | include ROOT_PATH . "system/classes/" . strtolower($classname) . ".php"; |
| 194 | 194 | } else if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
| 195 | 195 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
| 196 | 196 | } else if (strpos($classname, "Plugin") !== FALSE) { |
| 197 | - //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
|
| 198 | - } else { |
|
| 197 | + //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
|
| 198 | + } else { |
|
| 199 | 199 | echo "Could not load class '" . $classname . "'' (array size 1)!"; |
| 200 | 200 | } |
| 201 | 201 | |