| @@ -1,0 +1,514 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Helpers\Update; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\ActionClass; | |
| 6 | +use AcyMailing\Classes\AutomationClass; | |
| 7 | +use AcyMailing\Classes\ConditionClass; | |
| 8 | +use AcyMailing\Classes\FieldClass; | |
| 9 | +use AcyMailing\Classes\ListClass; | |
| 10 | +use AcyMailing\Classes\MailClass; | |
| 11 | +use AcyMailing\Classes\OverrideClass; | |
| 12 | +use AcyMailing\Classes\PluginClass; | |
| 13 | +use AcyMailing\Classes\RuleClass; | |
| 14 | +use AcyMailing\Classes\StepClass; | |
| 15 | +use AcyMailing\Classes\UserClass; | |
| 16 | + | |
| 17 | +trait DefaultData | |
| 18 | +{ | |
| 19 | + public function installBounceRules(): void | |
| 20 | + { | |
| 21 | + $ruleClass = new RuleClass(); | |
| 22 | + if ($ruleClass->getOrderingNumber() > 0) { | |
| 23 | + return; | |
| 24 | + } | |
| 25 | + $replyTo = $this->config->get('replyto_email'); | |
| 26 | + $bounce = $this->config->get('bounce_email'); | |
| 27 | + $from = $this->config->get('from_email'); | |
| 28 | + | |
| 29 | + $forwardEmail = $replyTo != $bounce ? $replyTo : $from; | |
| 30 | + if (empty($forwardEmail)) { | |
| 31 | + $forwardEmail = acym_currentUserEmail(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + $forwardAction = acym_escapeDB(json_encode(['0' => 'delete_message', '1' => 'forward_message', 'forward_to' => $forwardEmail])); | |
| 35 | + | |
| 36 | + $query = "INSERT INTO `#__acym_rule` (`id`, `name`, `description`, `ordering`, `regex`, `executed_on`, `action_message`, `action_user`, `active`, `increment_stats`, `execute_action_after`) VALUES "; | |
| 37 | + $query .= "(1, 'ACYM_LIST_UNSUBSCRIBE_HANDLING', 'ACYM_LIST_UNSUBSCRIBE_HANDLING_DESC', 1, 'Please unsubscribe user ID \\\\d+', '[\"body\"]', '[\"delete_message\"]', '[\"unsubscribe_user\"]', 1, 0, 0),"; | |
| 38 | + $query .= "(2, 'ACYM_SUPPRESSION_LIST', 'ACYM_SUPPRESSION_LIST_DESC', 2, 'suppression list', '[\"body\"]', '[\"delete_message\"]', '[\"unsubscribe_user\",\"block_user\",\"empty_queue_user\"]', 1, 1, 0),"; | |
| 39 | + $query .= "(3, 'ACYM_ACTION_REQUIRED', 'ACYM_ACTION_REQUIRED_DESC', 3, 'action *requ|verif', '[\"subject\"]', ".$forwardAction.", '[]', 1, 0, 0),"; | |
| 40 | + $query .= "(4, 'ACYM_ACKNOWLEDGMENT_RECEIPT_SUBJECT', 'ACYM_ACKNOWLEDGMENT_RECEIPT_SUBJECT_DESC', 4, '(out|away) *(of|from)|vacation|vacanze|vacaciones|holiday|absen|congés|recept|acknowledg|thank you for|Auto *Response|Incident|Automati|Ticket|Resposta *automática', '[\"subject\"]', '[\"delete_message\"]', '[]', 1, 0, 0),"; | |
| 41 | + $query .= "(5, 'ACYM_FEEDBACK_LOOP', 'ACYM_FEEDBACK_LOOP_DESC', 5, 'feedback|[email protected]|complaints@.{0,15}email-abuse.amazonses.com|complaint about message', '[\"senderInfo\",\"subject\"]', '[\"save_message\",\"delete_message\"]', '[\"unsubscribe_user\",\"block_user\",\"empty_queue_user\"]', 1, 0, 0),"; | |
| 42 | + $query .= "(6, 'ACYM_FEEDBACK_LOOP_BODY', 'ACYM_FEEDBACK_LOOP_BODY_DESC', 6, 'Feedback-Type.{1,5}abuse', '[\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"unsubscribe_user\"]', 1, 1, 0),"; | |
| 43 | + $query .= "(7, 'ACYM_MAILBOX_FULL', 'ACYM_MAILBOX_FULL_DESC', 7, '((mailbox|mailfolder|storage|quota|space|inbox) *(is)? *(over)? *(exceeded|size|storage|allocation|full|quota|maxi))|status(-code)? *(:|=)? *5.2.2|quota-issue|not *enough.{1,20}space|((over|exceeded|full|exhausted) *(allowed)? *(mail|storage|quota))|Space shortage', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 0),"; | |
| 44 | + $query .= "(8, 'ACYM_BLOCKED_GOOGLE_GROUPS', 'ACYM_BLOCKED_GOOGLE_GROUPS_DESC', 8, 'message *rejected *by *Google *Groups', '[\"body\"]', '[\"delete_message\"]', '[\"block_user\"]', 1, 1, 3),"; | |
| 45 | + $query .= "(9, 'ACYM_REJECTED', 'ACYM_REJECTED_DESC', 9, 'rejected *your *message|email *provider *rejected *it', '[\"body\"]', '[\"delete_message\"]', '[\"block_user\"]', 1, 1, 3),"; | |
| 46 | + $query .= "(10, 'ACYM_MAILBOX_DOESNT_EXIST_1', 'ACYM_MAILBOX_DOESNT_EXIST_1_DESC', 10, '(Invalid|no such|unknown|bad|des?activated|inactive|unrouteable) *(mail|destination|recipient|user|address|person)|bad-mailbox|inactive-mailbox|not listed in.{1,20}directory|RecipNotFound|(user|mailbox|address|recipients?|host|account|domain) *(is|has been)? *(error|disabled|failed|unknown|unavailable|not *(found|available)|.{1,30}inactiv)|no *mailbox *here|user does.?n.t have.{0,30}account|no *longer *(active|working|in *use)|mail( *foi)? *desativado|recipient \'[^\']+\' not known', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 0),"; | |
| 47 | + $query .= "(11, 'ACYM_MESSAGE_BLOCKED_RECIPIENTS', 'ACYM_MESSAGE_BLOCKED_RECIPIENTS_DESC', 11, 'blocked *by|block *list|look(ed)? *like *spam|spam-related|spam *detected| CXBL | CDRBL | IPBL | URLBL |(unacceptable|banned|offensive|filtered|blocked|unsolicited) *(content|message|e?-?mail)|service refused|(status(-code)?|554) *(:|=)? *5.7.1|administratively *denied|blacklisted *IP|policy *reasons|rejected.{1,10}spam|junkmail *rejected|throttling *constraints|exceeded.{1,10}max.{1,40}hour|comply with required standards|421 RP-00|550 SC-00|550 DY-00|550 OU-00|client *[0-9.]* *blocked *using', '[\"body\"]', ".$forwardAction.", '[\"block_user\"]', 1, 1, 3),"; | |
| 48 | + $query .= "(12, 'ACYM_MAILBOX_DOESNT_EXIST_2', 'ACYM_MAILBOX_DOESNT_EXIST_2_DESC', 12, 'status(-? ?code)? *(:|=)? *(550)? *5.(1.[1-6]|0.0|4.[0123467])|recipient *(address *)?rejected|does *not *like *recipient|recipient *unknown *to *address|email *account *that *you *tried *to *reach *is *disabled|no *mail-enabled *subscriptions', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 0),"; | |
| 49 | + $query .= "(13, 'ACYM_DOMAIN_NOT_EXIST', 'ACYM_DOMAIN_NOT_EXIST_DESC', 13, 'No.{1,10}MX *(record|host)|host *does *not *receive *any *mail|bad-domain|connection.{1,10}mail.{1,20}fail|domain.{1,10}not *exist|fail.{1,10}establish *connection|Unable *to *lookup *DNS *for|Unable *to *connect *to *remote *host', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 0),"; | |
| 50 | + $query .= "(14, 'ACYM_TEMPORARY_FAILURES', 'ACYM_TEMPORARY_FAILURES_DESC', 14, 'has.*been.*delayed|delayed *mail|message *delayed|message-expired|temporar(il)?y *(failure|unavailable|disable|offline|unable)|deferred|delayed *([0-9]*) *(hour|minut)|possible *mail *loop|too *many *hops|delivery *time *expired|Action.php: *delayed|status(-code)? *(:|=)? *4.4.6|will continue to be attempted|unable to deliver in.*Status: 4.4.7|Connection *closed *unexpectedly', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 3),"; | |
| 51 | + $query .= "(15, 'ACYM_FAILED_PERM', 'ACYM_FAILED_PERM_DESC', 15, 'failed *permanently|permanent.{1,20}(failure|error)|not *accepting *(any)? *mail|does *not *exist|no *valid *route|delivery *failure', '[\"subject\",\"body\"]', '[\"save_message\",\"delete_message\"]', '[\"block_user\"]', 1, 1, 0),"; | |
| 52 | + $query .= "(16, 'ACYM_ACKNOWLEDGMENT_RECEIPT_BODY', 'ACYM_ACKNOWLEDGMENT_RECEIPT_BODY_DESC', 16, 'vacanc|holiday|vacation|absen|urlaub|ferie|feriado|vacanz|vacaciones|(out *of|not *in|outside)( *the)? *office|automatisch *(generierte)? *Antwort|confirm *we(\\'ve| *have) *received|den *Ferien|automática|RISPOSTA AUTOMATICA|vakantie|recepcionado *(su *)?requerimiento|Kiitos viestistäsi|nicht im Büro|nicht am Arbeitsplatz|automatic *reply|auto(-|mated *|matic *)reply|Email *has *been *recived|ricevuto *il *Suo *messaggio|ticket|poza *biurem|Automatic *respon|Case *Number|Αυτόματη *απάντηση', '[\"body\"]', '[\"delete_message\"]', '[]', 1, 0, 0),"; | |
| 53 | + $query .= "(17, 'ACYM_FINAL_RULE', 'ACYM_FINAL_RULE_DESC', 17, '.', '[\"senderInfo\",\"subject\"]', ".$forwardAction.", '[]', 1, 0, 0);"; | |
| 54 | + | |
| 55 | + acym_query($query); | |
| 56 | + | |
| 57 | + $this->config->saveConfig(['bounceVersion' => self::BOUNCE_VERSION]); | |
| 58 | + } | |
| 59 | + | |
| 60 | + public function installFields(): void | |
| 61 | + { | |
| 62 | + $query = "INSERT IGNORE INTO #__acym_field (`id`, `name`, `type`, `value`, `active`, `default_value`, `required`, `ordering`, `option`, `core`, `backend_edition`, `backend_listing`, `frontend_edition`, `frontend_listing`, `namekey`) VALUES | |
| 63 | + (1, 'ACYM_NAME', 'text', NULL, 1, NULL, 0, 1, '{\"error_message\":\"\",\"error_message_invalid\":\"\",\"size\":\"\",\"rows\":\"\",\"columns\":\"\",\"format\":\"\",\"custom_text\":\"\",\"css_class\":\"\",\"authorized_content\":{\"0\":\"all\",\"regex\":\"\"}}', 1, 1, 1, 1, 1, 'acym_name'), | |
| 64 | + (2, 'ACYM_EMAIL', 'text', NULL, 1, NULL, 1, 2, '{\"error_message\":\"\",\"error_message_invalid\":\"\",\"size\":\"\",\"rows\":\"\",\"columns\":\"\",\"format\":\"\",\"custom_text\":\"\",\"css_class\":\"\",\"authorized_content\":{\"0\":\"all\",\"regex\":\"\"}}', 1, 1, 1, 1, 1, 'acym_email');"; | |
| 65 | + acym_query($query); | |
| 66 | + | |
| 67 | + $fieldClass = new FieldClass(); | |
| 68 | + $fieldClass->insertLanguageField(); | |
| 69 | + } | |
| 70 | + | |
| 71 | + public function installTemplates(): void | |
| 72 | + { | |
| 73 | + $mailClass = new MailClass(); | |
| 74 | + $installedTemplates = 0; | |
| 75 | + | |
| 76 | + $templates = acym_getFolders(ACYM_BACK.'templates'.DS, '.', false, true); | |
| 77 | + foreach ($templates as $oneTemplateFolderPath) { | |
| 78 | + $templateName = substr($oneTemplateFolderPath, strrpos($oneTemplateFolderPath, DS) + 1); | |
| 79 | + $templateName = str_replace('_', ' ', $templateName); | |
| 80 | + | |
| 81 | + $oneMail = $mailClass->getOneByName($templateName, false, MailClass::TYPE_TEMPLATE); | |
| 82 | + if (!empty($oneMail)) { | |
| 83 | + continue; | |
| 84 | + } | |
| 85 | + | |
| 86 | + if ($mailClass->installExtractedTemplate($oneTemplateFolderPath, false)) { | |
| 87 | + $installedTemplates++; | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + if ($installedTemplates === 0) { | |
| 92 | + acym_enqueueMessage(acym_translation('ACYM_DEFAULT_TEMPLATES_ALREADY_INSTALL'), 'info'); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + public function installDefaultAutomations(): void | |
| 97 | + { | |
| 98 | + $this->newAutomationAdmin('ACYM_ADMIN_USER_CREATE'); | |
| 99 | + $this->newAutomationAdmin('ACYM_ADMIN_USER_MODIFICATION'); | |
| 100 | + } | |
| 101 | + | |
| 102 | + public function installList(): void | |
| 103 | + { | |
| 104 | + $listClass = new ListClass(); | |
| 105 | + $listClass->addDefaultList(); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public function installNotifications(): bool | |
| 109 | + { | |
| 110 | + $searchSettings = [ | |
| 111 | + 'offset' => 0, | |
| 112 | + 'mailsPerPage' => 9000, | |
| 113 | + 'key' => 'name', | |
| 114 | + ]; | |
| 115 | + | |
| 116 | + $mailClass = new MailClass(); | |
| 117 | + $notifications = $mailClass->getMailsByType(MailClass::TYPE_NOTIFICATION, $searchSettings); | |
| 118 | + $notifications = $notifications['mails']; | |
| 119 | + $user = $this->getCurrentUser(); | |
| 120 | + if (empty($user)) { | |
| 121 | + return false; | |
| 122 | + } | |
| 123 | + | |
| 124 | + $addNotif = []; | |
| 125 | + | |
| 126 | + // Email sent with the cron report | |
| 127 | + if (empty($notifications['acy_report'])) { | |
| 128 | + $addNotif[] = [ | |
| 129 | + 'name' => 'acy_report', | |
| 130 | + 'subject' => 'AcyMailing Cron Report {mainreport}', | |
| 131 | + 'content' => '<p>{report}</p><p>{detailreport}</p>', | |
| 132 | + ]; | |
| 133 | + } | |
| 134 | + | |
| 135 | + // Confirmation email for double opt-in | |
| 136 | + if (empty($notifications['acy_confirm'])) { | |
| 137 | + $addNotif[] = [ | |
| 138 | + 'name' => 'acy_confirm', | |
| 139 | + 'subject' => '{subscriber:name|ucfirst}, {trans:ACYM_PLEASE_CONFIRM_SUBSCRIPTION}', | |
| 140 | + 'content' => $this->getFormatedNotification( | |
| 141 | + '<h1 style="font-size: 24px;">{trans:ACYM_HELLO} '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 142 | + <p>{trans:ACYM_CONFIRM_MESSAGE}</p> | |
| 143 | + <p>{trans:ACYM_CONFIRM_MESSAGE_ACTIVATE}</p> | |
| 144 | + <p style="text-align: center;"><strong>{confirm}{trans:ACYM_CONFIRM_SUBSCRIPTION}{/confirm}</strong></p>' | |
| 145 | + ), | |
| 146 | + ]; | |
| 147 | + } | |
| 148 | + | |
| 149 | + if (empty($notifications['acy_notification_create'])) { | |
| 150 | + $addNotif[] = [ | |
| 151 | + 'name' => 'acy_notification_create', | |
| 152 | + 'subject' => acym_translation('ACYM_NOTIFICATION_CREATE_SUBJECT').': {user:email}', | |
| 153 | + 'content' => $this->getFormatedNotification( | |
| 154 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 155 | + <p>'.acym_translation('ACYM_NOTIFICATION_CREATE_BODY').'</p> | |
| 156 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 157 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p> | |
| 158 | + <p>'.acym_translation('ACYM_SOURCE').': '.$this->getDTextDisplay('{user:source}', 'registration_form').'</p> | |
| 159 | + <p>'.acym_translation('ACYM_SUBSCRIPTION').': '.$this->getDTextDisplay('{user:subscription}', 'Newsletters - 2020-11-02 14:38:24').'</p>' | |
| 160 | + ), | |
| 161 | + ]; | |
| 162 | + } | |
| 163 | + | |
| 164 | + if (empty($notifications['acy_notification_unsub'])) { | |
| 165 | + $addNotif[] = [ | |
| 166 | + 'name' => 'acy_notification_unsub', | |
| 167 | + 'subject' => acym_translation('ACYM_NOTIFICATION_UNSUB_SUBJECT').': {user:email}', | |
| 168 | + 'content' => $this->getFormatedNotification( | |
| 169 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 170 | + <p>'.acym_translation('ACYM_NOTIFICATION_UNSUB_BODY').'</p> | |
| 171 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 172 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p> | |
| 173 | + <p>'.acym_translation('ACYM_LISTS').': '.$this->getDTextDisplay('{lists}', 'Newsletters, Tips').'</p>' | |
| 174 | + ), | |
| 175 | + ]; | |
| 176 | + } | |
| 177 | + | |
| 178 | + if (empty($notifications['acy_notification_unsuball'])) { | |
| 179 | + $addNotif[] = [ | |
| 180 | + 'name' => 'acy_notification_unsuball', | |
| 181 | + 'subject' => acym_translation('ACYM_NOTIFICATION_UNSUBALL_SUBJECT').': {user:email}', | |
| 182 | + 'content' => $this->getFormatedNotification( | |
| 183 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 184 | + <p>'.acym_translation('ACYM_NOTIFICATION_UNSUBALL_BODY').'</p> | |
| 185 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 186 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p>' | |
| 187 | + ), | |
| 188 | + ]; | |
| 189 | + } | |
| 190 | + | |
| 191 | + if (empty($notifications['acy_notification_subform'])) { | |
| 192 | + $addNotif[] = [ | |
| 193 | + 'name' => 'acy_notification_subform', | |
| 194 | + 'subject' => acym_translation('ACYM_NOTIFICATION_SUBFORM_SUBJECT').': {user:email}', | |
| 195 | + 'content' => $this->getFormatedNotification( | |
| 196 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 197 | + <p>'.acym_translation('ACYM_NOTIFICATION_SUBFORM_BODY').'</p> | |
| 198 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 199 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p> | |
| 200 | + <p>'.acym_translation('ACYM_SUBSCRIPTION').': '.$this->getDTextDisplay('{user:subscription}', 'Newsletters - 2025-11-02 14:38:24').'</p>' | |
| 201 | + ), | |
| 202 | + ]; | |
| 203 | + } | |
| 204 | + | |
| 205 | + if (empty($notifications['acy_notification_profile'])) { | |
| 206 | + $addNotif[] = [ | |
| 207 | + 'name' => 'acy_notification_profile', | |
| 208 | + 'subject' => acym_translation('ACYM_NOTIFICATION_PROFILE_SUBJECT').': {user:email}', | |
| 209 | + 'content' => $this->getFormatedNotification( | |
| 210 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 211 | + <p>'.acym_translation('ACYM_NOTIFICATION_PROFILE_BODY').'</p> | |
| 212 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 213 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p> | |
| 214 | + <p>'.acym_translation('ACYM_SUBSCRIPTION').': '.$this->getDTextDisplay('{user:subscription}', 'Newsletters - 2025-11-02 14:38:24').'</p>' | |
| 215 | + ), | |
| 216 | + ]; | |
| 217 | + } | |
| 218 | + | |
| 219 | + if (empty($notifications['acy_notification_confirm'])) { | |
| 220 | + $addNotif[] = [ | |
| 221 | + 'name' => 'acy_notification_confirm', | |
| 222 | + 'subject' => acym_translation('ACYM_NOTIFICATION_CONFIRM_SUBJECT').': {user:email}', | |
| 223 | + 'content' => $this->getFormatedNotification( | |
| 224 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 225 | + <p>'.acym_translation('ACYM_NOTIFICATION_CONFIRM_BODY').'</p> | |
| 226 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{user:name}', 'Julia').'</p> | |
| 227 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{user:email}', '[email protected]').'</p> | |
| 228 | + <p>'.acym_translation('ACYM_IP').': '.$this->getDTextDisplay('{user:confirmation_ip}', '127.0.0.1').'</p> | |
| 229 | + <p>'.acym_translation('ACYM_SUBSCRIPTION').': '.$this->getDTextDisplay('{user:subscription}', 'Newsletters - 2025-11-02 14:38:24').'</p>' | |
| 230 | + ), | |
| 231 | + ]; | |
| 232 | + } | |
| 233 | + | |
| 234 | + if (empty($notifications['acy_notification_cms'])) { | |
| 235 | + $addNotif[] = [ | |
| 236 | + 'name' => 'acy_notification_cms', | |
| 237 | + 'subject' => '{subject}', | |
| 238 | + 'content' => '{body}', | |
| 239 | + 'drag_editor' => 0, | |
| 240 | + ]; | |
| 241 | + } | |
| 242 | + | |
| 243 | + if (empty($notifications['acy_notification_auto_campaign_admin'])) { | |
| 244 | + $addNotif[] = [ | |
| 245 | + 'name' => 'acy_notification_auto_campaign_admin', | |
| 246 | + 'subject' => acym_translation('ACYM_NOTIFICATION_AUTO_CAMPAIGN_SUBJECT'), | |
| 247 | + 'content' => $this->getFormatedNotification( | |
| 248 | + '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 249 | + <p>'.acym_translation('ACYM_NOTIFICATION_AUTO_CAMPAIGN_BODY').'</p>' | |
| 250 | + ), | |
| 251 | + ]; | |
| 252 | + } | |
| 253 | + | |
| 254 | + $firstEmail = $mailClass->getOneByName(acym_translation(self::FIRST_EMAIL_NAME_KEY)); | |
| 255 | + if (empty($firstEmail)) { | |
| 256 | + $body = '<div id="acym__wysid__template" class="cell"><table class="body"><tbody><tr><td align="center" class="center acym__wysid__template__content" valign="top" style="background-color: rgb(239, 239, 239); padding: 30px 0px 120px;"><center><table align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="acym__wysid__row ui-droppable ui-sortable" bgcolor="#ffffff" style="background-color: rgb(255, 255, 255); min-height: 0px; display: table-cell;"><table class="row acym__wysid__row__element" border="0" cellpadding="0" cellspacing="0" style="z-index: 100; background-color: rgb(238, 238, 238);" bgcolor="#eeeeee"><tbody bgcolor="" style="background-color: inherit;"><tr><th class="small-12 medium-12 large-12 columns" style="height: auto;"><table class="acym__wysid__column" style="min-height: 0px; display: table; height: auto;" border="0" cellpadding="0" cellspacing="0"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group; height: auto;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--text mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_41"><p style="font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; word-break: break-word; text-align: center; line-height: inherit;"><span style="font-size: 12px;">Having trouble seeing this email? <span class="mceNonEditable acym_dynamic" contenteditable="false" data-dynamic="{readonline}View it online{/readonline}"><a style="text-decoration: none; font-family: Helvetica; font-size: 12px; font-weight: normal; line-height: inherit; font-style: normal; color: #38c2f3;" href="view_it_online_link" target="_blank" rel="noopener"><span class="acym_online">View it online</span></a><em class="acym_remove_dynamic acymicon-close"></em></span> </span></p></div></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#ffffff" style="background-color: rgb(255, 255, 255); z-index: 100;" cellpadding="0" cellspacing="0" border="0"><tbody bgcolor="" style="background-color: inherit;"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th" valign="top"><table class="acym__wysid__column" border="0" cellpadding="0" cellspacing="0" style="min-height: 0px; display: table;"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="height: 21px; outline-width: 0px;"><span class="acy-editor__space" style="display:block; padding: 0;margin: 0; height: 100%"></span></td></tr><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--image mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_45"><p style="font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; word-break: break-word; line-height: inherit;"><img class="acym__wysid__media__inserted" style="max-width: 100%; height: 85px; box-sizing: border-box; padding: 0px 5px; display: block; margin-left: auto; margin-right: auto; width: 306px;" src="'.ACYM_LIVE.ACYM_UPLOAD_FOLDER.'logo_acymailing_step_email.png" alt="logo_acymailing_step_email.png" height="85" width="306"></p></div></td></tr><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="height: 29px; outline-width: 0px;"><span class="acy-editor__space" style="display:block; padding: 0;margin: 0; height: 100%"></span></td></tr><tr class="acym__wysid__column__element acym__wysid__column__element__separator cursor-pointer ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><hr style="border-bottom: 3px solid rgb(214, 214, 214); width: 24%; border-top: none; border-left: none; border-right: none; size: 3px;" class="acym__wysid__row__separator"></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#ffffff" style="background-color: rgb(255, 255, 255); z-index: 100;" cellpadding="0" cellspacing="0" border="0"><tbody bgcolor="" style="background-color: inherit;"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th" valign="top"><table class="acym__wysid__column" border="0" cellpadding="0" cellspacing="0" style="min-height: 0px; display: table;"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--text mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_42"><h1 style="font-family: Helvetica; font-size: 20px; font-weight: normal; font-style: normal; color: #000000; line-height: inherit; text-align: left;">Dear <span class="mceNonEditable acym_dynamic" contenteditable="false" data-dynamic="{subscriber:name|part:first|ucfirst}">Admin<em class="acym_remove_dynamic acymicon-close"></em></span>,</h1></div></td></tr><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--text mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_43"><p style="word-break: break-word; font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; line-height: inherit; text-align: left;"><span style="color: #000000;"><span style="font-family: Helvetica;">Feel free to drag & drop some content and </span><span style="font-family: Helvetica;">try the AcyMailing editor.</span></span></p><p style="word-break: break-word; font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; line-height: inherit; text-align: left;"><span style="color: #000000; font-family: Helvetica;">Once it is done, click on the "Apply" button.</span></p></div></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#ffffff" style="background-color: rgb(255, 255, 255); z-index: 100; padding: 0px;" cellpadding="0" cellspacing="0" border="0"><tbody bgcolor="" style="background-color: inherit;"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th" valign="top"><table class="acym__wysid__column" border="0" cellpadding="0" cellspacing="0" style="min-height: 0px; display: table;"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--image mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_46"><p style="font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; word-break: break-word; line-height: inherit;"><img class="acym__wysid__media__inserted" style="max-width: 100%; height: auto; box-sizing: border-box; padding: 0px 5px; display: block; margin-left: auto; margin-right: auto; width: 580px;" src="'.ACYM_LIVE.ACYM_UPLOAD_FOLDER.'image_mailing_step_email.jpg" alt="image_mailing_step_email.jpg" height="400.68" width="580"></p></div></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#303e47" style="background-color: rgb(48, 62, 71); z-index: 100;" cellpadding="0" cellspacing="0" border="0"><tbody bgcolor="" style="background-color: inherit;"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th" valign="top"><table class="acym__wysid__column" border="0" cellpadding="0" cellspacing="0" style="min-height: 0px; display: table;"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline-width: 0px;"><div class="acym__wysid__tinymce--text mce-content-body" style="position: relative;" spellcheck="false" contenteditable="false" id="mce_44"><p style="font-family: Helvetica; font-size: 12px; font-weight: normal; font-style: normal; color: #000000; text-align: center; word-break: break-word; line-height: inherit;"><span style="color: #ffffff;">If you\'re not interested anymore, you can</span> <span class="mceNonEditable acym_dynamic" data-dynamic="{unsubscribe}unsubscribe{/unsubscribe}" contenteditable="false"><a style="text-decoration: none; font-family: Helvetica; font-size: 12px; font-weight: normal; line-height: inherit; font-style: normal; color: #38c2f3;" target="_blank" href="'.acym_frontendLink( | |
| 257 | + 'frontusers&task=unsubscribe&id='.$user->id.'&key='.$user->key.'&'.acym_noTemplate() | |
| 258 | + ).'" rel="noopener"><span class="acym_unsubscribe acym_link" style="font-family: Helvetica; font-size: 12px; font-weight: normal; line-height: inherit; font-style: normal; color: #ffffff;">unsubscribe</span></a><em class="acym_remove_dynamic acymicon-close"></em></span></p></div></td></tr></tbody></table></th></tr></tbody></table></td></tr></tbody></table></center></td></tr></tbody></table></div>'; | |
| 259 | + | |
| 260 | + $addNotif[] = [ | |
| 261 | + 'name' => acym_translation(self::FIRST_EMAIL_NAME_KEY), | |
| 262 | + 'subject' => acym_translation('ACYM_YOUR_FIRST_EMAIL'), | |
| 263 | + 'content' => $body, | |
| 264 | + 'settings' => '{"default":{"font-family":"Helvetica"},"p":{"font-family":"Helvetica","font-size":"12px","overridden":{"font-size":true,"line-height":true},"line-height":"inherit"},"a":{"font-family":"Helvetica","font-size":"12px","overridden":{"font-size":true,"line-height":true,"color":true},"line-height":"inherit","color":"#38c2f3"},"span.acym_link":{"font-family":"Helvetica","font-size":"12px","overridden":{"font-size":true,"line-height":true,"color":true},"line-height":"inherit","color":"#ffffff"},"h1":{"font-family":"Helvetica","font-size":"20px","overridden":{"font-size":true,"line-height":true},"line-height":"inherit"}}', | |
| 265 | + 'type' => MailClass::TYPE_TEMPLATE, | |
| 266 | + 'thumbnail' => 'thumbnail_first_email.png', | |
| 267 | + ]; | |
| 268 | + $mailingImage = 'image_mailing_step_email.jpg'; | |
| 269 | + $logoAcymailing = 'logo_acymailing_step_email.png'; | |
| 270 | + $thumbnailFirstStep = 'thumbnail_first_email.png'; | |
| 271 | + | |
| 272 | + $uploadFolder = ACYM_ROOT.ACYM_UPLOAD_FOLDER; | |
| 273 | + $defaultImagesFolder = ACYM_ROOT.ACYM_MEDIA_FOLDER.'images'.DS.'templates'.DS.'first_email'.DS; | |
| 274 | + | |
| 275 | + acym_createFolder($uploadFolder); | |
| 276 | + acym_createFolder(ACYM_UPLOAD_FOLDER_THUMBNAIL); | |
| 277 | + | |
| 278 | + if (!file_exists($uploadFolder.$mailingImage)) { | |
| 279 | + copy( | |
| 280 | + $defaultImagesFolder.$mailingImage, | |
| 281 | + $uploadFolder.$mailingImage | |
| 282 | + ); | |
| 283 | + } | |
| 284 | + if (!file_exists($uploadFolder.$logoAcymailing)) { | |
| 285 | + copy( | |
| 286 | + $defaultImagesFolder.$logoAcymailing, | |
| 287 | + $uploadFolder.$logoAcymailing | |
| 288 | + ); | |
| 289 | + } | |
| 290 | + if (!file_exists(ACYM_UPLOAD_FOLDER_THUMBNAIL.$thumbnailFirstStep)) { | |
| 291 | + copy( | |
| 292 | + $defaultImagesFolder.$thumbnailFirstStep, | |
| 293 | + ACYM_UPLOAD_FOLDER_THUMBNAIL.$thumbnailFirstStep | |
| 294 | + ); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + if (!empty($addNotif)) { | |
| 299 | + foreach ($addNotif as $oneNotif) { | |
| 300 | + $notif = new \stdClass(); | |
| 301 | + $notif->type = $oneNotif['type'] ?? MailClass::TYPE_NOTIFICATION; | |
| 302 | + $notif->settings = $oneNotif['settings'] ?? ''; | |
| 303 | + $notif->drag_editor = $oneNotif['drag_editor'] ?? 1; | |
| 304 | + $notif->creator_id = acym_currentUserId(); | |
| 305 | + $notif->creation_date = gmdate('Y-m-d H:i:s', time()); | |
| 306 | + $notif->name = $oneNotif['name']; | |
| 307 | + $notif->subject = $oneNotif['subject']; | |
| 308 | + $notif->body = $oneNotif['content']; | |
| 309 | + $notif->thumbnail = $oneNotif['thumbnail'] ?? ''; | |
| 310 | + | |
| 311 | + $notif->id = $mailClass->save($notif); | |
| 312 | + if (empty($notif->id)) { | |
| 313 | + acym_enqueueMessage(acym_translationSprintf('ACYM_ERROR_INSTALLING_X_TEMPLATE', $notif->name), 'error'); | |
| 314 | + | |
| 315 | + return false; | |
| 316 | + } | |
| 317 | + | |
| 318 | + if (strpos($notif->body, 'view_it_online_link') !== false) { | |
| 319 | + $viewItOnlineLink = 'archive&task=view&id='.$notif->id.'&userid='.$user->id.'-'.$user->key.'&'.acym_noTemplate(); | |
| 320 | + $notif->body = str_replace('view_it_online_link', acym_frontendLink($viewItOnlineLink), $notif->body); | |
| 321 | + $mailClass->save($notif); | |
| 322 | + } | |
| 323 | + } | |
| 324 | + } | |
| 325 | + | |
| 326 | + return true; | |
| 327 | + } | |
| 328 | + | |
| 329 | + public function installAddons(): void | |
| 330 | + { | |
| 331 | + $pluginClass = new PluginClass(); | |
| 332 | + $installedAddons = array_keys($pluginClass->getAll('folder_name')); | |
| 333 | + $coreAddons = acym_coreAddons(); | |
| 334 | + | |
| 335 | + foreach ($coreAddons as $oneAddon) { | |
| 336 | + if (in_array($oneAddon->folder_name, $installedAddons)) { | |
| 337 | + continue; | |
| 338 | + } | |
| 339 | + | |
| 340 | + $pluginClass->save($oneAddon); | |
| 341 | + } | |
| 342 | + } | |
| 343 | + | |
| 344 | + public function installOverrideEmails(): void | |
| 345 | + { | |
| 346 | + $overrideClass = new OverrideClass(); | |
| 347 | + $mailClass = new MailClass(); | |
| 348 | + $currentUserId = acym_currentUserId(); | |
| 349 | + | |
| 350 | + $emailOverrides = acym_getEmailOverrides(); | |
| 351 | + $existingOverrides = $mailClass->getMailsByType(MailClass::TYPE_OVERRIDE, ['offset' => 0, 'mailsPerPage' => 9000, 'key' => 'name']); | |
| 352 | + $existingOverrides = $existingOverrides['mails']; | |
| 353 | + | |
| 354 | + foreach ($emailOverrides as $oneOverride) { | |
| 355 | + if (!empty($existingOverrides[$oneOverride['name']])) { | |
| 356 | + continue; | |
| 357 | + } | |
| 358 | + | |
| 359 | + $mail = new \stdClass(); | |
| 360 | + $mail->name = $oneOverride['name']; | |
| 361 | + $mail->creation_date = gmdate('Y-m-d H:i:s', time()); | |
| 362 | + $mail->type = MailClass::TYPE_OVERRIDE; | |
| 363 | + $mail->subject = $oneOverride['new_subject']; | |
| 364 | + $mail->body = $this->getFormatedNotification($oneOverride['new_body']); | |
| 365 | + $mail->drag_editor = 1; | |
| 366 | + $mail->creator_id = $currentUserId; | |
| 367 | + $mailId = $mailClass->save($mail); | |
| 368 | + | |
| 369 | + if (empty($mailId)) { | |
| 370 | + continue; | |
| 371 | + } | |
| 372 | + | |
| 373 | + $override = new \stdClass(); | |
| 374 | + $override->mail_id = $mailId; | |
| 375 | + $override->description = $oneOverride['description']; | |
| 376 | + $override->source = $oneOverride['source']; | |
| 377 | + $override->active = 0; | |
| 378 | + $override->base_subject = json_encode($oneOverride['base_subject']); | |
| 379 | + $override->base_body = empty($oneOverride['base_body']) ? '' : json_encode($oneOverride['base_body']); | |
| 380 | + | |
| 381 | + $overrideClass->save($override); | |
| 382 | + } | |
| 383 | + } | |
| 384 | + | |
| 385 | + private function newAutomationAdmin(string $title): void | |
| 386 | + { | |
| 387 | + $automationClass = new AutomationClass(); | |
| 388 | + $stepClass = new StepClass(); | |
| 389 | + $conditionClass = new ConditionClass(); | |
| 390 | + $mailClass = new MailClass(); | |
| 391 | + $actionClass = new ActionClass(); | |
| 392 | + | |
| 393 | + $adminCreate = new \stdClass(); | |
| 394 | + $adminCreate->desc = 'ACYM_ADMIN_USER_CREATE_DESC'; | |
| 395 | + $adminCreate->triggers = '{"user_creation":[""],"type_trigger":"user"}'; | |
| 396 | + $adminCreate->conditions = '{"type_condition":"user"}'; | |
| 397 | + $adminCreate->emailTitle = acym_translation('ACYM_SUBSCRIBER_CREATION'); | |
| 398 | + $adminCreate->emailSubject = acym_translation('ACYM_SUBSCRIBER_CREATION'); | |
| 399 | + $adminCreate->emailContent = '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 400 | + <p>'.acym_translation('ACYM_NEW_USER_ACYMAILING').':</p> | |
| 401 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{subscriber:name|info:current}', 'Roger').'</p> | |
| 402 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{subscriber:email|info:current}', '[email protected]').'</p>'; | |
| 403 | + | |
| 404 | + $adminModif = new \stdClass(); | |
| 405 | + $adminModif->desc = 'ACYM_ADMIN_USER_MODIFICATION_DESC'; | |
| 406 | + $adminModif->triggers = '{"user_modification":[""],"type_trigger":"user"}'; | |
| 407 | + $adminModif->conditions = '{"type_condition":"user"}'; | |
| 408 | + $adminModif->emailTitle = acym_translation('ACYM_SUBSCRIBER_MODIFICATION'); | |
| 409 | + $adminModif->emailSubject = acym_translation('ACYM_SUBSCRIBER_MODIFICATION'); | |
| 410 | + $adminModif->emailContent = '<h1 style="font-size: 24px;">'.acym_translation('ACYM_HELLO').' '.$this->getDTextDisplay('{subscriber:name|ucfirst}', 'Marc').',</h1> | |
| 411 | + <p>'.acym_translation('ACYM_USER_MODIFY_ACYMAILING').':</p> | |
| 412 | + <p>'.acym_translation('ACYM_NAME').': '.$this->getDTextDisplay('{subscriber:name|info:current}', 'Roger').'</p> | |
| 413 | + <p>'.acym_translation('ACYM_EMAIL').': '.$this->getDTextDisplay('{subscriber:email|info:current}', '[email protected]').'</p>'; | |
| 414 | + | |
| 415 | + $info = [ | |
| 416 | + 'ACYM_ADMIN_USER_CREATE' => $adminCreate, | |
| 417 | + 'ACYM_ADMIN_USER_MODIFICATION' => $adminModif, | |
| 418 | + ]; | |
| 419 | + | |
| 420 | + $newAutomation = new \stdClass(); | |
| 421 | + $newAutomation->name = acym_translation($title); | |
| 422 | + $newAutomation->description = acym_translation($info[$title]->desc); | |
| 423 | + $newAutomation->active = 0; | |
| 424 | + $newAutomation->admin = 1; | |
| 425 | + $newAutomation->id = $automationClass->save($newAutomation); | |
| 426 | + if (empty($newAutomation->id)) { | |
| 427 | + return; | |
| 428 | + } | |
| 429 | + | |
| 430 | + $newStep = new \stdClass(); | |
| 431 | + $newStep->name = acym_translation($title); | |
| 432 | + $newStep->triggers = $info[$title]->triggers; | |
| 433 | + $newStep->automation_id = $newAutomation->id; | |
| 434 | + $newStep->id = $stepClass->save($newStep); | |
| 435 | + if (empty($newStep->id)) { | |
| 436 | + return; | |
| 437 | + } | |
| 438 | + | |
| 439 | + $newCondition = new \stdClass(); | |
| 440 | + $newCondition->step_id = $newStep->id; | |
| 441 | + $newCondition->conditions = $info[$title]->conditions; | |
| 442 | + $newCondition->id = $conditionClass->save($newCondition); | |
| 443 | + if (empty($newCondition->id)) { | |
| 444 | + return; | |
| 445 | + } | |
| 446 | + | |
| 447 | + $mailAutomation = new \stdClass(); | |
| 448 | + $mailAutomation->type = MailClass::TYPE_AUTOMATION; | |
| 449 | + $mailAutomation->drag_editor = 1; | |
| 450 | + $mailAutomation->creator_id = acym_currentUserId(); | |
| 451 | + $mailAutomation->creation_date = gmdate('Y-m-d H:i:s', time()); | |
| 452 | + $mailAutomation->name = acym_translation($info[$title]->emailTitle); | |
| 453 | + $mailAutomation->subject = acym_translation($info[$title]->emailSubject); | |
| 454 | + $mailAutomation->body = $this->getFormatedNotification($info[$title]->emailContent); | |
| 455 | + | |
| 456 | + $mailAutomation->id = $mailClass->save($mailAutomation); | |
| 457 | + if (empty($mailAutomation->id)) { | |
| 458 | + return; | |
| 459 | + } | |
| 460 | + | |
| 461 | + $newAction = new \stdClass(); | |
| 462 | + $newAction->condition_id = $newCondition->id; | |
| 463 | + $newAction->actions = '[{"acy_add_queue":{"mail_id":"'.intval($mailAutomation->id).'","time":"[time]"}}]'; | |
| 464 | + $newAction->filters = '{"0":{"1":{"acy_field":{"field":"email","operator":"=","value":"'.acym_currentUserEmail().'"}}},"type_filter":"classic"}'; | |
| 465 | + $newAction->order = 1; | |
| 466 | + $actionClass->save($newAction); | |
| 467 | + } | |
| 468 | + | |
| 469 | + private function getDTextDisplay(string $dtext, string $preview): string | |
| 470 | + { | |
| 471 | + $display = '<span class="acym_dynamic mceNonEditable" contenteditable="false" data-dynamic="'.esc_attr($dtext).'" data-mce-selected="1">'; | |
| 472 | + $display .= $preview; | |
| 473 | + $display .= '<em class="acym_remove_dynamic acymicon-close">‍</em>'; | |
| 474 | + $display .= '</span>'; | |
| 475 | + | |
| 476 | + return $display; | |
| 477 | + } | |
| 478 | + | |
| 479 | + private function getFormatedNotification(string $content): string | |
| 480 | + { | |
| 481 | + $beginning = '<div id="acym__wysid__template" class="cell"><table class="body"><tbody><tr><td align="center" class="center acym__wysid__template__content" valign="top" style="background-color: rgb(239, 239, 239); padding: 40px 0 120px 0;"><center><table align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="acym__wysid__row ui-droppable ui-sortable" style="min-height: 0px; display: table-cell;"><table class="row acym__wysid__row__element" bgcolor="#dadada" border="0" cellpadding="0" cellspacing="0"><tbody style="background-color: rgb(218,218,218);" bgcolor="#ffffff"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th"><table class="acym__wysid__column" style="min-height: 0px; display: table;" border="0" cellpadding="0" cellspacing="0"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline: rgb(0,163,254) dashed 0px; outline-offset: -1px;"><span class="acy-editor__space acy-editor__space--focus" style="display: block; padding: 0px; margin: 0px; height: 10px;"></span></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0"><tbody style="background-color: transparent;" bgcolor="#ffffff"><tr><th class="small-12 medium-12 large-12 columns"><table class="acym__wysid__column" style="min-height: 0px; display: table;" border="0" cellpadding="0" cellspacing="0"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline: rgb(0, 163, 254) dashed 0px; outline-offset: -1px;"><div class="acym__wysid__tinymce--text mce-content-body" style="position: relative;" spellcheck="false">'; | |
| 482 | + $ending = '</div></td></tr></tbody></table></th></tr></tbody></table><table class="row acym__wysid__row__element" bgcolor="#dadada" style="position: relative; z-index: 100; top: 0; left: 0;" border="0" cellpadding="0" cellspacing="0"><tbody style="background-color: rgb(218, 218, 218);" bgcolor="#ffffff"><tr><th class="small-12 medium-12 large-12 columns acym__wysid__row__element__th"><table class="acym__wysid__column" style="min-height: 0px; display: table;" border="0" cellpadding="0" cellspacing="0"><tbody class="ui-sortable" style="min-height: 0px; display: table-row-group;"><tr class="acym__wysid__column__element ui-draggable" style="position: relative; top: inherit; left: inherit; right: inherit; bottom: inherit; height: auto;"><td class="large-12 acym__wysid__column__element__td" style="outline: rgb(0, 163, 254) dashed 0px; outline-offset: -1px;"><span class="acy-editor__space acy-editor__space--focus" style="display: block; padding: 0px; margin: 0px; height: 10px;"></span></td></tr></tbody></table></th></tr></tbody></table></td></tr></tbody></table></center></td></tr></tbody></table></div>'; | |
| 483 | + | |
| 484 | + return $beginning.$content.$ending; | |
| 485 | + } | |
| 486 | + | |
| 487 | + private function getCurrentUser(): ?object | |
| 488 | + { | |
| 489 | + $currentCMSId = acym_currentUserId(); | |
| 490 | + $userClass = new UserClass(); | |
| 491 | + $user = $userClass->getOneByCMSId($currentCMSId); | |
| 492 | + if (!empty($user)) { | |
| 493 | + return $user; | |
| 494 | + } | |
| 495 | + | |
| 496 | + $currentCMSEmail = acym_currentUserEmail(); | |
| 497 | + $user = $userClass->getOneByEmail($currentCMSEmail); | |
| 498 | + if (!empty($user)) { | |
| 499 | + return $user; | |
| 500 | + } | |
| 501 | + | |
| 502 | + $newUser = new \stdClass(); | |
| 503 | + $newUser->email = $currentCMSEmail; | |
| 504 | + $newUser->confirmed = 1; | |
| 505 | + $newUser->cms_id = $currentCMSId; | |
| 506 | + $newUser->id = $userClass->save($newUser); | |
| 507 | + | |
| 508 | + if (empty($newUser->id)) { | |
| 509 | + return null; | |
| 510 | + } | |
| 511 | + | |
| 512 | + return $userClass->getOneById($newUser->id); | |
| 513 | + } | |
| 514 | +} | |