| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Classes\PluginClass; |
| 4 |
|
| 5 |
global $acymPlugins; |
| 6 |
global $acymAddonsForSettings; |
| 7 |
|
| 8 |
function acym_trigger(string $method, array $args = [], ?string $plugin = null, ?callable $callbackOnePlugin = null): ?array |
| 9 |
{ |
| 10 |
if (!in_array(acym_getPrefix().'acym_configuration', acym_getTableList())) { |
| 11 |
return null; |
| 12 |
} |
| 13 |
|
| 14 |
if (in_array($method, ['replaceContent', 'replaceUserInformation']) && !empty($args[0]->language)) { |
| 15 |
$previousLanguage = acym_setLanguage($args[0]->language); |
| 16 |
acym_loadLanguage($args[0]->language); |
| 17 |
} |
| 18 |
|
| 19 |
global $acymPlugins; |
| 20 |
global $acymAddonsForSettings; |
| 21 |
if (empty($acymPlugins)) { |
| 22 |
acym_loadPlugins(); |
| 23 |
} |
| 24 |
|
| 25 |
$result = []; |
| 26 |
$listAddons = $acymPlugins; |
| 27 |
if ($method === 'onAcymAddSettings') { |
| 28 |
$listAddons = $acymAddonsForSettings; |
| 29 |
} |
| 30 |
|
| 31 |
foreach ($listAddons as $class => $onePlugin) { |
| 32 |
if (is_callable($callbackOnePlugin)) $callbackOnePlugin($onePlugin); |
| 33 |
if (!method_exists($onePlugin, $method)) continue; |
| 34 |
if (!empty($plugin) && $class !== $plugin) continue; |
| 35 |
|
| 36 |
try { |
| 37 |
$value = call_user_func_array([$onePlugin, $method], $args); |
| 38 |
if (isset($value)) { |
| 39 |
$result[] = $value; |
| 40 |
} |
| 41 |
|
| 42 |
if (!empty($onePlugin->errors)) { |
| 43 |
$onePlugin->errorCallback(); |
| 44 |
} |
| 45 |
} catch (\Throwable $e) { |
| 46 |
acym_logError('An error occurred when triggering the method '.$method.': '.$e->getMessage()); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
if (!empty($previousLanguage)) { |
| 51 |
acym_setLanguage($previousLanguage); |
| 52 |
acym_loadLanguage($previousLanguage); |
| 53 |
} |
| 54 |
|
| 55 |
return $result; |
| 56 |
} |
| 57 |
|
| 58 |
function acym_checkPluginsVersion(): bool |
| 59 |
{ |
| 60 |
$pluginClass = new PluginClass(); |
| 61 |
$pluginsInstalled = $pluginClass->getMatchingElements(); |
| 62 |
$pluginsInstalled = $pluginsInstalled['elements']; |
| 63 |
|
| 64 |
if (empty($pluginsInstalled)) { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
$response = acym_fileGetContent(ACYM_UPDATEME_API_URL.'public/addons'); |
| 69 |
$pluginsAvailable = @json_decode($response, true); |
| 70 |
if (empty($pluginsAvailable)) { |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
foreach ($pluginsInstalled as $key => $pluginInstalled) { |
| 75 |
foreach ($pluginsAvailable as $pluginAvailable) { |
| 76 |
if ($pluginAvailable['file_name'] === $pluginInstalled->folder_name && !version_compare($pluginInstalled->version, $pluginAvailable['version'], '>=')) { |
| 77 |
$pluginInstalled->uptodate = 0; |
| 78 |
$pluginInstalled->latest_version = $pluginAvailable['version']; |
| 79 |
$pluginClass->save($pluginInstalled); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return true; |
| 85 |
} |
| 86 |
|