PopulatorData
2 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
2 weeks ago
Capabilities.php
2 months ago
Changelog.php
2 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
2 months ago
Env.php
6 months ago
Hooks.php
1 month ago
HooksWooCommerce.php
1 month ago
Initializer.php
1 month ago
Installer.php
10 months ago
Localizer.php
3 years ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
2 weeks ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
2 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
1 month ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
2 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
4 days ago
index.php
3 years ago
RequirementsChecker.php
131 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Router\Endpoints\ExportDownload; |
| 9 | use MailPoet\Util\Helpers; |
| 10 | use MailPoet\WP\Notice as WPNotice; |
| 11 | |
| 12 | class RequirementsChecker { |
| 13 | const TEST_FOLDER_PERMISSIONS = 'TempFolderCreation'; |
| 14 | const TEST_XML_EXTENSION = 'XmlExtension'; |
| 15 | const TEST_VENDOR_SOURCE = 'VendorSource'; |
| 16 | |
| 17 | public $displayErrorNotice; |
| 18 | public $vendorClasses = [ |
| 19 | '\Cron\CronExpression', |
| 20 | ]; |
| 21 | |
| 22 | public function __construct( |
| 23 | $displayErrorNotice = true |
| 24 | ) { |
| 25 | $this->displayErrorNotice = $displayErrorNotice; |
| 26 | } |
| 27 | |
| 28 | public function checkAllRequirements() { |
| 29 | $availableTests = [ |
| 30 | self::TEST_FOLDER_PERMISSIONS, |
| 31 | self::TEST_XML_EXTENSION, |
| 32 | self::TEST_VENDOR_SOURCE, |
| 33 | ]; |
| 34 | $results = []; |
| 35 | foreach ($availableTests as $test) { |
| 36 | $results[$test] = call_user_func([$this, 'check' . $test]); |
| 37 | } |
| 38 | return $results; |
| 39 | } |
| 40 | |
| 41 | public function checkTempFolderCreation() { |
| 42 | $paths = [ |
| 43 | 'temp_path' => Env::$tempPath, |
| 44 | ]; |
| 45 | if (!is_dir($paths['temp_path']) && !wp_mkdir_p($paths['temp_path'])) { |
| 46 | $error = Helpers::replaceLinkTags( |
| 47 | __('MailPoet requires write permissions inside the /wp-content/uploads folder. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet'), |
| 48 | 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#folder_permissions', |
| 49 | ['target' => '_blank'] |
| 50 | ); |
| 51 | return $this->processError($error); |
| 52 | } |
| 53 | foreach ($paths as $path) { |
| 54 | $indexFile = $path . '/index.php'; |
| 55 | if (!file_exists($indexFile)) { |
| 56 | file_put_contents( |
| 57 | $path . '/index.php', |
| 58 | str_replace('\n', PHP_EOL, '<?php\n\n// Silence is golden') |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | try { |
| 63 | ExportDownload::ensureExportDirectory(); |
| 64 | } catch (\RuntimeException $e) { |
| 65 | $error = Helpers::replaceLinkTags( |
| 66 | __('MailPoet requires write permissions inside the /wp-content/uploads folder. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet'), |
| 67 | 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#folder_permissions', |
| 68 | ['target' => '_blank'] |
| 69 | ); |
| 70 | return $this->processError($error); |
| 71 | } |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | public function checkXmlExtension() { |
| 76 | if (extension_loaded('xml')) return true; |
| 77 | $error = Helpers::replaceLinkTags( |
| 78 | __('MailPoet requires an XML PHP extension. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet'), |
| 79 | 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#php_extension', |
| 80 | ['target' => '_blank'] |
| 81 | ); |
| 82 | return $this->processError($error); |
| 83 | } |
| 84 | |
| 85 | public function checkVendorSource() { |
| 86 | foreach ($this->vendorClasses as $dependency) { |
| 87 | $dependencyPath = $this->getDependencyPath($dependency); |
| 88 | if (!$dependencyPath) { |
| 89 | $error = sprintf( |
| 90 | // translators: %s is the dependency. |
| 91 | __('A MailPoet dependency (%s) does not appear to be loaded correctly, thus MailPoet will not work correctly. Please reinstall the plugin.', 'mailpoet'), |
| 92 | $dependency |
| 93 | ); |
| 94 | |
| 95 | return $this->processError($error); |
| 96 | } |
| 97 | |
| 98 | $pattern = '#' . preg_quote(Env::$path) . '[\\\/]#'; |
| 99 | $isLoadedByPlugin = preg_match($pattern, $dependencyPath); |
| 100 | if (!$isLoadedByPlugin) { |
| 101 | $error = sprintf( |
| 102 | // translators: %1$s is the dependency and %2$s the plugin. |
| 103 | __('MailPoet has detected a dependency conflict (%1$s) with another plugin (%2$s), which may cause unexpected behavior. Please disable the offending plugin to fix this issue.', 'mailpoet'), |
| 104 | $dependency, |
| 105 | $dependencyPath |
| 106 | ); |
| 107 | |
| 108 | return $this->processError($error); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | private function getDependencyPath($namespacedClass) { |
| 116 | try { |
| 117 | $reflector = new \ReflectionClass($namespacedClass); |
| 118 | return $reflector->getFileName(); |
| 119 | } catch (\ReflectionException $ex) { |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | public function processError($error) { |
| 125 | if ($this->displayErrorNotice) { |
| 126 | WPNotice::displayError($error); |
| 127 | } |
| 128 | return false; |
| 129 | } |
| 130 | } |
| 131 |