| @@ -1,0 +1,167 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\PluginClass; | |
| 6 | + | |
| 7 | +function acym_isExtensionActive(string $extension): bool | |
| 8 | +{ | |
| 9 | + // Test first as mu-plugins don't have an active status for WP | |
| 10 | + if (acym_isMuPlugin($extension)) return true; | |
| 11 | + | |
| 12 | + if (function_exists('is_plugin_active')) return is_plugin_active($extension); | |
| 13 | + | |
| 14 | + return file_exists(WP_PLUGIN_DIR.DS.$extension); | |
| 15 | +} | |
| 16 | + | |
| 17 | +function acym_isMuPlugin(string $extension): bool | |
| 18 | +{ | |
| 19 | + return file_exists(WPMU_PLUGIN_DIR.DS.$extension); | |
| 20 | +} | |
| 21 | + | |
| 22 | +function acym_getPluginPath(string $plugin): string | |
| 23 | +{ | |
| 24 | + $corePath = ACYM_BACK.'dynamics'.DS.$plugin.DS.'plugin.php'; | |
| 25 | + if (file_exists($corePath)) return $corePath; | |
| 26 | + | |
| 27 | + return ACYM_ADDONS_FOLDER_PATH.$plugin.DS.'plugin.php'; | |
| 28 | +} | |
| 29 | + | |
| 30 | +function acym_coreAddons(): array | |
| 31 | +{ | |
| 32 | + return [ | |
| 33 | + (object)[ | |
| 34 | + 'title' => acym_translation('ACYM_ARTICLE'), | |
| 35 | + 'folder_name' => 'post', | |
| 36 | + 'version' => '11.1.0', | |
| 37 | + 'active' => '1', | |
| 38 | + 'category' => 'Content management', | |
| 39 | + 'level' => 'starter', | |
| 40 | + 'uptodate' => '1', | |
| 41 | + 'description' => '- Insert WordPress posts in your emails<br/>- Insert the latest posts of a category in an automatic email', | |
| 42 | + 'latest_version' => '11.1.0', | |
| 43 | + 'type' => 'CORE', | |
| 44 | + ], | |
| 45 | + (object)[ | |
| 46 | + 'title' => acym_translation('ACYM_PAGE'), | |
| 47 | + 'folder_name' => 'page', | |
| 48 | + 'version' => '11.1.0', | |
| 49 | + 'active' => '1', | |
| 50 | + 'category' => 'Content management', | |
| 51 | + 'level' => 'starter', | |
| 52 | + 'uptodate' => '1', | |
| 53 | + 'description' => '- Insert pages in your emails', | |
| 54 | + 'latest_version' => '11.1.0', | |
| 55 | + 'type' => 'CORE', | |
| 56 | + ], | |
| 57 | + (object)[ | |
| 58 | + 'title' => acym_translation('ACYM_CREATE_USER'), | |
| 59 | + 'folder_name' => 'createuser', | |
| 60 | + 'version' => '11.1.0', | |
| 61 | + 'active' => '1', | |
| 62 | + 'category' => 'User management', | |
| 63 | + 'level' => 'starter', | |
| 64 | + 'uptodate' => '1', | |
| 65 | + 'description' => '- Automatically creates a site user when an AcyMailing subscriber is created', | |
| 66 | + 'latest_version' => '11.1.0', | |
| 67 | + 'type' => 'CORE', | |
| 68 | + ], | |
| 69 | + ]; | |
| 70 | +} | |
| 71 | + | |
| 72 | +function acym_isTrackingSalesActive(): bool | |
| 73 | +{ | |
| 74 | + $trackingWoocommerce = false; | |
| 75 | + acym_trigger('onAcymIsTrackingWoocommerce', [&$trackingWoocommerce], 'plgAcymWoocommerce'); | |
| 76 | + | |
| 77 | + return $trackingWoocommerce; | |
| 78 | +} | |
| 79 | + | |
| 80 | +function acym_loadPlugins(): void | |
| 81 | +{ | |
| 82 | + $dynamicsLoadedLast = ['managetext']; | |
| 83 | + $dynamics = acym_getFolders(ACYM_BACK.'dynamics'); | |
| 84 | + | |
| 85 | + $pluginClass = new PluginClass(); | |
| 86 | + $plugins = $pluginClass->getPlugins(); | |
| 87 | + | |
| 88 | + foreach ($dynamics as $key => $oneDynamic) { | |
| 89 | + if (!empty($plugins[$oneDynamic]) && 0 === intval($plugins[$oneDynamic]->active)) { | |
| 90 | + unset($dynamics[$key]); | |
| 91 | + } | |
| 92 | + | |
| 93 | + if ('managetext' === $oneDynamic) { | |
| 94 | + unset($dynamics[$key]); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + $pluginsLoadedLast = ['tableofcontents']; | |
| 99 | + foreach ($plugins as $pluginFolder => $onePlugin) { | |
| 100 | + if (in_array($pluginFolder, $dynamics) || 0 === intval($onePlugin->active)) { | |
| 101 | + continue; | |
| 102 | + } | |
| 103 | + | |
| 104 | + if (in_array($pluginFolder, $pluginsLoadedLast)) { | |
| 105 | + array_unshift($dynamicsLoadedLast, $pluginFolder); | |
| 106 | + } else { | |
| 107 | + $dynamics[] = $pluginFolder; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | + // Some plugins need to be called last | |
| 112 | + $dynamics = array_merge($dynamics, $dynamicsLoadedLast); | |
| 113 | + | |
| 114 | + global $acymPlugins; | |
| 115 | + global $acymAddonsForSettings; | |
| 116 | + | |
| 117 | + // Load the installed integrations | |
| 118 | + $integrationsRaw = []; | |
| 119 | + $acyVersion = acym_config()->get('version'); | |
| 120 | + do_action_ref_array('acym_load_installed_integrations', [&$integrationsRaw, $acyVersion]); | |
| 121 | + | |
| 122 | + $integrations = []; | |
| 123 | + foreach ($integrationsRaw as $oneIntegration) { | |
| 124 | + $addonName = strtolower(substr($oneIntegration['className'], 7)); | |
| 125 | + $integrations[$addonName] = $oneIntegration; | |
| 126 | + | |
| 127 | + if (!in_array($addonName, $dynamics)) { | |
| 128 | + $dynamics[] = $addonName; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + $integrationsClasses = array_keys($integrations); | |
| 132 | + | |
| 133 | + foreach ($dynamics as $oneDynamic) { | |
| 134 | + if (in_array($oneDynamic, $integrationsClasses)) { | |
| 135 | + $dynamicFile = $integrations[$oneDynamic]['path'].DS.'plugin.php'; | |
| 136 | + } else { | |
| 137 | + $dynamicFile = acym_getPluginPath($oneDynamic); | |
| 138 | + } | |
| 139 | + $className = 'plgAcym'.ucfirst($oneDynamic); | |
| 140 | + | |
| 141 | + // Load the plugin | |
| 142 | + if (isset($acymPlugins[$className]) || !file_exists($dynamicFile) || (!class_exists($className) && !include_once $dynamicFile)) { | |
| 143 | + continue; | |
| 144 | + } | |
| 145 | + | |
| 146 | + if (!class_exists($className)) { | |
| 147 | + continue; | |
| 148 | + } | |
| 149 | + | |
| 150 | + $plugin = new $className(); | |
| 151 | + | |
| 152 | + if (in_array($oneDynamic, $integrationsClasses)) { | |
| 153 | + $pluginClass->addIntegrationIfMissing($plugin); | |
| 154 | + } | |
| 155 | + | |
| 156 | + // If it's for another CMS or if the related extension isn't installed, skip it | |
| 157 | + if (in_array($plugin->cms, ['all', 'WordPress'])) { | |
| 158 | + $acymAddonsForSettings[$className] = $plugin; | |
| 159 | + } | |
| 160 | + | |
| 161 | + if (!in_array($plugin->cms, ['all', 'WordPress']) || !$plugin->installed) { | |
| 162 | + continue; | |
| 163 | + } | |
| 164 | + | |
| 165 | + $acymPlugins[$className] = $plugin; | |
| 166 | + } | |
| 167 | +} | |