PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/kirby/toolkit/lib/detect.php

https://gitlab.com/gricelya/rental
PHP | 261 lines | 102 code | 27 blank | 132 comment | 6 complexity | 06eae89f2d89e30bb7922dd7ab9fefb1 MD5 | raw file
  1. <?php
  2. /**
  3. * Detect
  4. *
  5. * This class is a system feature detection helper
  6. * to check for installed packages and software
  7. *
  8. * @package Kirby Toolkit
  9. * @author Bastian Allgeier <bastian@getkirby.com>
  10. * @link http://getkirby.com
  11. * @copyright Bastian Allgeier
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. class Detect {
  15. /**
  16. * Checks if the mb string extension is installed
  17. *
  18. * @return boolean
  19. */
  20. public static function mbstring() {
  21. return function_exists('mb_split');
  22. }
  23. /**
  24. * Checks if the required php version is installed
  25. *
  26. * @param mixed $min
  27. * @return boolean
  28. */
  29. public static function php($min = '5.3') {
  30. return version_compare(PHP_VERSION, $min, '>=');
  31. }
  32. /**
  33. * Checks if PHP is running on Apache
  34. *
  35. * @return boolean
  36. */
  37. public static function apache() {
  38. return apache_get_version() ? true : false;
  39. }
  40. /**
  41. * Checks if the site is running on Windows
  42. *
  43. * @return boolean
  44. */
  45. public static function windows() {
  46. return DS == '/' ? false : true;
  47. }
  48. /**
  49. * Checks if the site is running on IIS
  50. *
  51. * @return boolean
  52. */
  53. public static function iis() {
  54. return isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'IIS') !== false ? true : false;
  55. }
  56. /**
  57. * Checks if mysql installed with the minimum required version
  58. *
  59. * @param mixed $min
  60. * @return boolean
  61. */
  62. public static function mysql($min = '5') {
  63. $extensions = get_loaded_extensions();
  64. if(!in_array('mysql', $extensions)) return false;
  65. $version = preg_replace('#(^\D*)([0-9.]+).*$#', '\2', mysql_get_client_info());
  66. return version_compare($version, $min, '>=');
  67. }
  68. /**
  69. * Checks if SQLite 3 is installed
  70. *
  71. * @return boolean
  72. */
  73. public static function sqlite() {
  74. return in_array('sqlite3', get_loaded_extensions());
  75. }
  76. /**
  77. * Checks if safe mode is enabled
  78. *
  79. * @return boolean
  80. */
  81. public static function safemode() {
  82. return ini_get('safe_mode');
  83. }
  84. /**
  85. * Checks if gdlib is installed
  86. *
  87. * @return boolean
  88. */
  89. public static function gdlib() {
  90. return function_exists('gd_info');
  91. }
  92. /**
  93. * Checks if imageick is installed
  94. *
  95. * @return boolean
  96. */
  97. public static function imagick() {
  98. return class_exists('Imagick');
  99. }
  100. /**
  101. * Checks if CURL is installed
  102. *
  103. * @return boolean
  104. */
  105. public static function curl() {
  106. return in_array('curl', get_loaded_extensions());
  107. }
  108. /**
  109. * Check if APC cache is installed
  110. *
  111. * @return boolean
  112. */
  113. public static function apc() {
  114. return function_exists('apc_add');
  115. }
  116. /**
  117. * Check if the Memcache extension is installed
  118. *
  119. * @return boolean
  120. */
  121. public static function memcache() {
  122. return class_exists('Memcache');
  123. }
  124. /**
  125. * Check if the Memcached extension is installed
  126. *
  127. * @return boolean
  128. */
  129. public static function memcached() {
  130. return class_exists('Memcached');
  131. }
  132. /**
  133. * Check if the imap extension is installed
  134. *
  135. * @return boolean
  136. */
  137. public static function imap() {
  138. return function_exists('imap_body');
  139. }
  140. /**
  141. * Check if the mcrypt extension is installed
  142. *
  143. * @return boolean
  144. */
  145. public static function mcrypt() {
  146. return function_exists('mcrypt_encrypt');
  147. }
  148. /**
  149. * Check if the exif extension is installed
  150. *
  151. * @return boolean
  152. */
  153. public static function exif() {
  154. return function_exists('read_exif_data');
  155. }
  156. /**
  157. * Detect if the script is installed in a subfolder
  158. *
  159. * @return string
  160. */
  161. public static function subfolder() {
  162. return trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
  163. }
  164. /**
  165. * Detects the current path
  166. *
  167. * @return string
  168. */
  169. public static function path() {
  170. $uri = explode('/', url::path());
  171. $script = explode('/', trim($_SERVER['SCRIPT_NAME'], '/\\'));
  172. $parts = array_diff_assoc($uri, $script);
  173. if(empty($parts)) return false;
  174. return implode('/', $parts);
  175. }
  176. /**
  177. * Detect the document root
  178. *
  179. * @return string
  180. */
  181. public static function documentRoot() {
  182. $local = $_SERVER['SCRIPT_NAME'];
  183. $absolute = $_SERVER['SCRIPT_FILENAME'];
  184. return substr($absolute, 0, strpos($absolute, $local));
  185. }
  186. /**
  187. * Converts any ini size value to an integer
  188. *
  189. * @param string $key
  190. * @return int
  191. */
  192. public static function iniSize($key) {
  193. $size = ini_get($key);
  194. $size = trim($size);
  195. $last = strtolower($size[strlen($size)-1]);
  196. switch($last) {
  197. case 'g':
  198. $size *= 1024;
  199. case 'm':
  200. $size *= 1024;
  201. case 'k':
  202. $size *= 1024;
  203. }
  204. return $size;
  205. }
  206. /**
  207. * Returns the max accepted upload size
  208. * defined in the php.ini
  209. *
  210. * @return int
  211. */
  212. public static function maxUploadSize() {
  213. return static::iniSize('upload_max_filesize');
  214. }
  215. /**
  216. * Returns the max accepted post size
  217. * defined in the php.ini
  218. *
  219. * @return int
  220. */
  221. public static function maxPostSize() {
  222. return static::iniSize('post_max_size');
  223. }
  224. /**
  225. * Dirty browser sniffing for an ios device
  226. *
  227. * @return boolean
  228. */
  229. public static function ios() {
  230. $ua = visitor::ua();
  231. return (str::contains($ua, 'iPod') || str::contains($ua, 'iPhone') || str::contains($ua, 'iPad'));
  232. }
  233. }