| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Helpers\Update; |
| 4 |
|
| 5 |
use AcyMailing\Helpers\UpdatemeHelper; |
| 6 |
|
| 7 |
trait Cms |
| 8 |
{ |
| 9 |
public function installTables(): void |
| 10 |
{ |
| 11 |
$queries = file_get_contents(ACYM_BACK.'tables.sql'); |
| 12 |
$tables = explode('CREATE TABLE IF NOT EXISTS', $queries); |
| 13 |
|
| 14 |
foreach ($tables as $oneTable) { |
| 15 |
$oneTable = trim($oneTable); |
| 16 |
if (empty($oneTable)) { |
| 17 |
continue; |
| 18 |
} |
| 19 |
acym_query('CREATE TABLE IF NOT EXISTS'.$oneTable); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public function installLanguages(): void |
| 24 |
{ |
| 25 |
$siteLanguages = acym_getLanguages(); |
| 26 |
if (!empty($siteLanguages[ACYM_DEFAULT_LANGUAGE])) { |
| 27 |
unset($siteLanguages[ACYM_DEFAULT_LANGUAGE]); |
| 28 |
} |
| 29 |
|
| 30 |
$installedLanguages = array_keys($siteLanguages); |
| 31 |
if (empty($installedLanguages) || !class_exists(UpdatemeHelper::class)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
ob_start(); |
| 36 |
$languagesContent = UpdatemeHelper::call('public/download/translations?version=latest&codes='.implode(',', $installedLanguages)); |
| 37 |
$warnings = ob_get_clean(); |
| 38 |
if (!empty($warnings) && acym_isDebug()) { |
| 39 |
acym_enqueueMessage($warnings, 'warning'); |
| 40 |
} |
| 41 |
|
| 42 |
if (empty($languagesContent) || $languagesContent['status'] === 'error') { |
| 43 |
acym_enqueueMessage(acym_translation('ACYM_ERROR_LOAD_LANGUAGES'), 'error'); |
| 44 |
|
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$decodedLanguages = $languagesContent['translations']; |
| 49 |
|
| 50 |
$success = []; |
| 51 |
$error = []; |
| 52 |
$errorLoad = []; |
| 53 |
|
| 54 |
foreach ($decodedLanguages as $code => $content) { |
| 55 |
if (empty($content)) { |
| 56 |
$errorLoad[] = $code; |
| 57 |
continue; |
| 58 |
} |
| 59 |
|
| 60 |
$path = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.'.ACYM_LANGUAGE_FILE.'.ini'; |
| 61 |
if (acym_writeFile($path, $content)) { |
| 62 |
$this->installBackLanguages($code); |
| 63 |
$success[] = $code; |
| 64 |
} else { |
| 65 |
$error[] = acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $path); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
if (!empty($success)) acym_enqueueMessage(acym_translationSprintf('ACYM_TRANSLATION_INSTALLED', implode(', ', $success))); |
| 70 |
if (!empty($error)) acym_enqueueMessage($error, 'error'); |
| 71 |
if (!empty($errorLoad)) acym_enqueueMessage(acym_translationSprintf('ACYM_ERROR_LOAD_LANGUAGE', implode(', ', $errorLoad)), 'warning'); |
| 72 |
} |
| 73 |
|
| 74 |
public function installBackLanguages(string $onlyCode = ''): void |
| 75 |
{ |
| 76 |
if (ACYM_CMS !== 'joomla') { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
$menuStrings = [ |
| 81 |
'ACYM_DASHBOARD', |
| 82 |
'ACYM_SUBSCRIBERS', |
| 83 |
'ACYM_CUSTOM_FIELDS', |
| 84 |
'ACYM_LISTS', |
| 85 |
'ACYM_SEGMENTS', |
| 86 |
'ACYM_EMAILS', |
| 87 |
'ACYM_TEMPLATES', |
| 88 |
'ACYM_AUTOMATION', |
| 89 |
'ACYM_QUEUE', |
| 90 |
'ACYM_STATISTICS', |
| 91 |
'ACYM_BOUNCE_HANDLING', |
| 92 |
'ACYM_ADD_ONS', |
| 93 |
'ACYM_CONFIGURATION', |
| 94 |
'ACYM_MENU_PROFILE', |
| 95 |
'ACYM_MENU_PROFILE_DESC', |
| 96 |
'ACYM_MENU_ARCHIVE', |
| 97 |
'ACYM_MENU_ARCHIVE_DESC', |
| 98 |
'ACYM_MENU_LISTS', |
| 99 |
'ACYM_MENU_LISTS_DESC', |
| 100 |
'ACYM_MENU_SUBSCRIBERS', |
| 101 |
'ACYM_MENU_SUBSCRIBERS_DESC', |
| 102 |
'ACYM_MENU_CAMPAIGNS', |
| 103 |
'ACYM_MENU_CAMPAIGNS_DESC', |
| 104 |
'ACYM_SUBSCRIPTION_FORMS', |
| 105 |
'ACYM_EMAILS_OVERRIDE', |
| 106 |
'ACYM_MAILBOX_ACTIONS', |
| 107 |
'ACYM_GOPRO', |
| 108 |
'ACYM_SCENARIO', |
| 109 |
]; |
| 110 |
|
| 111 |
$siteLanguages = empty($onlyCode) ? array_keys(acym_getLanguages()) : [$onlyCode]; |
| 112 |
|
| 113 |
foreach ($siteLanguages as $code) { |
| 114 |
|
| 115 |
$path = acym_getLanguagePath(ACYM_ROOT, $code).DS.$code.'.com_acym.ini'; |
| 116 |
if (!file_exists($path)) continue; |
| 117 |
|
| 118 |
$content = file_get_contents($path); |
| 119 |
if (empty($content)) continue; |
| 120 |
|
| 121 |
$menuFileContent = 'ACYM="AcyMailing"'."\r\n"; |
| 122 |
$menuFileContent .= 'COM_ACYM="AcyMailing"'."\r\n"; |
| 123 |
$menuFileContent .= 'COM_ACYM_CONFIGURATION="AcyMailing"'."\r\n"; |
| 124 |
|
| 125 |
foreach ($menuStrings as $oneString) { |
| 126 |
preg_match('#[^_]'.$oneString.'="(.*)"#i', $content, $matches); |
| 127 |
if (empty($matches[1])) continue; |
| 128 |
|
| 129 |
$menuFileContent .= $oneString.'="'.$matches[1].'"'."\r\n"; |
| 130 |
} |
| 131 |
|
| 132 |
$menuPath = ACYM_ROOT.'administrator'.DS.'language'.DS.$code.DS.$code.'.com_acym.sys.ini'; |
| 133 |
|
| 134 |
if (!acym_writeFile($menuPath, $menuFileContent)) { |
| 135 |
acym_enqueueMessage(acym_translationSprintf('ACYM_FAIL_SAVE_FILE', $menuPath), 'error'); |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|