PHPModules.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Grav\Plugin\Problems;
  3. use Grav\Common\Grav;
  4. use Grav\Plugin\Problems\Base\Problem;
  5. class PHPModules extends Problem
  6. {
  7. public function __construct()
  8. {
  9. $this->id = 'PHP Modules';
  10. $this->class = get_class($this);
  11. $this->order = 101;
  12. $this->level = Problem::LEVEL_CRITICAL;
  13. $this->status = false;
  14. $this->help = 'https://learn.getgrav.org/basics/requirements#php-requirements';
  15. }
  16. public function process()
  17. {
  18. $modules_errors = [];
  19. $modules_success = [];
  20. // Check for PHP CURL library
  21. $msg = 'PHP Curl (Data Transfer Library) is %s installed';
  22. if (function_exists('curl_version')) {
  23. $modules_success['curl'] = sprintf($msg, 'successfully');
  24. } else {
  25. $modules_errors['curl'] = sprintf($msg, 'required but not');
  26. }
  27. // Check for PHP Ctype library
  28. $msg = 'PHP Ctype is %s installed';
  29. if (function_exists('ctype_print')) {
  30. $modules_success['ctype'] = sprintf($msg, 'successfully');
  31. } else {
  32. $modules_errors['ctype'] = sprintf($msg, 'required but not');
  33. }
  34. // Check for PHP Dom library
  35. $msg = 'PHP DOM is %s installed';
  36. if (class_exists('DOMDocument')) {
  37. $modules_success['dom'] = sprintf($msg, 'successfully');
  38. } else {
  39. $modules_errors['dom'] = sprintf($msg, 'required but not');
  40. }
  41. // Check for GD library
  42. $msg = 'PHP GD (Image Manipulation Library) is %s installed';
  43. if (defined('GD_VERSION') && function_exists('gd_info')) {
  44. $msg = $modules_success['gd'] = sprintf($msg, 'successfully');
  45. // Extra checks for Image support
  46. $ginfo = gd_info();
  47. $gda = array('PNG Support', 'JPEG Support', 'FreeType Support', 'GIF Read Support');
  48. $gda_msg = '';
  49. $problems_found = false;
  50. foreach ($gda as $image_type) {
  51. if (!$ginfo[$image_type]) {
  52. $problems_found = true;
  53. $gda_msg = "missing $image_type, but is ";
  54. break;
  55. }
  56. }
  57. if ($problems_found) {
  58. $msg .= ' but missing ' . $gda_msg;
  59. }
  60. $modules_success['gd'] = $msg;
  61. } else {
  62. $modules_errors['gd'] = sprintf($msg, 'required but not');
  63. }
  64. // Check for PHP MbString library
  65. $msg = 'PHP Mbstring (Multibyte String Library) is %s installed';
  66. if (extension_loaded('mbstring')) {
  67. $modules_success['mbstring'] = sprintf($msg, 'successfully');
  68. } else {
  69. $modules_errors['mbstring'] = sprintf($msg, 'required but not');
  70. }
  71. // Check for PHP Open SSL library
  72. $msg = 'PHP OpenSSL (Secure Sockets Library) is %s installed';
  73. if (defined('OPENSSL_VERSION_TEXT') && extension_loaded('openssl')) {
  74. $modules_success['openssl'] = sprintf($msg, 'successfully');
  75. } else {
  76. $modules_errors['openssl'] = sprintf($msg, 'required but not');
  77. }
  78. // Check for PHP XML library
  79. $msg = 'PHP XML Library is %s installed';
  80. if (extension_loaded('xml')) {
  81. $modules_success['xml'] = sprintf($msg, 'successfully');
  82. } else {
  83. $modules_errors['xml'] = sprintf($msg, 'required but not');
  84. }
  85. // Check for PHP Zip library
  86. $msg = 'PHP Zip extension is %s installed';
  87. if (extension_loaded('zip')) {
  88. $modules_success['zip'] = sprintf($msg, 'successfully');
  89. } else {
  90. $modules_errors['zip'] = sprintf($msg, 'required but not');
  91. }
  92. // Check Exif if enabled
  93. if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
  94. $msg = 'PHP Exif (Exchangeable Image File Format) is %s installed';
  95. if (extension_loaded('exif')) {
  96. $modules_success['exif'] = sprintf($msg, 'successfully');
  97. } else {
  98. $modules_errors['exif'] = sprintf($msg, 'required but not');
  99. }
  100. }
  101. if (empty($modules_errors)) {
  102. $this->status = true;
  103. $this->msg = 'All modules look good!';
  104. } else {
  105. $this->status = false;
  106. $this->msg = 'There were problems with required modules:';
  107. }
  108. $this->details = ['errors' => $modules_errors, 'success' => $modules_success];
  109. return $this;
  110. }
  111. }