| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Classes\MailClass; |
| 4 |
use AcyMailing\Classes\FieldClass; |
| 5 |
|
| 6 |
trait SubscriberInsertion |
| 7 |
{ |
| 8 |
public function dynamicText(?int $mailId): ?object |
| 9 |
{ |
| 10 |
return $this->pluginDescription; |
| 11 |
} |
| 12 |
|
| 13 |
public function textPopup(): void |
| 14 |
{ |
| 15 |
?> |
| 16 |
<script type="text/javascript"> |
| 17 |
let selectedSubscriberDText; |
| 18 |
|
| 19 |
function changeSubscriberTag(tagname, element) { |
| 20 |
if (!tagname) return; |
| 21 |
|
| 22 |
selectedSubscriberDText = tagname; |
| 23 |
|
| 24 |
let baseTag = '<?php echo esc_html($this->name); ?>'; |
| 25 |
const $inputType = jQuery('input[name="typeInfoSubscriber"]:checked'); |
| 26 |
if ($inputType.length > 0 && $inputType.val() === 'current') { |
| 27 |
baseTag = 'user'; |
| 28 |
} |
| 29 |
let finalTag = '{' + baseTag + ':' + tagname; |
| 30 |
|
| 31 |
if ($inputType.length > 0 && $inputType.val() !== 'current') { |
| 32 |
finalTag += '|info:' + $inputType.val() + ''; |
| 33 |
} |
| 34 |
finalTag += '}'; |
| 35 |
|
| 36 |
setTag(finalTag, element); |
| 37 |
} |
| 38 |
</script> |
| 39 |
<?php |
| 40 |
$fieldClass = new FieldClass(); |
| 41 |
$fieldsUser = acym_getColumns('user'); |
| 42 |
$fieldsStats = acym_getColumns('user_stat'); |
| 43 |
$fields = array_merge($fieldsUser, $fieldsStats); |
| 44 |
$customFields = $fieldClass->getAllFieldsForUser(); |
| 45 |
$descriptions = []; |
| 46 |
$isAutomationAdmin = acym_getVar('string', 'automation'); |
| 47 |
$mailType = acym_getVar('string', 'mail_type', MailClass::TYPE_STANDARD); |
| 48 |
$typeNotif = acym_getVar('string', 'notification', ''); |
| 49 |
|
| 50 |
foreach ($customFields as $one) { |
| 51 |
$descriptions[$one->namekey] = acym_translation('ACYM_CUSTOM_FIELD'); |
| 52 |
$fields[] = $one; |
| 53 |
} |
| 54 |
|
| 55 |
$descriptions['id'] = acym_translation('ACYM_USER_ID'); |
| 56 |
$descriptions['email'] = acym_translation('ACYM_USER_EMAIL'); |
| 57 |
$descriptions['name'] = acym_translation('ACYM_USER_NAME'); |
| 58 |
$descriptions['cms_id'] = acym_translation('ACYM_USER_CMSID'); |
| 59 |
$descriptions['source'] = acym_translation('ACYM_USER_SOURCE'); |
| 60 |
$descriptions['confirmed'] = acym_translation('ACYM_USER_CONFIRMED'); |
| 61 |
$descriptions['active'] = acym_translation('ACYM_USER_ACTIVE'); |
| 62 |
$descriptions['creation_date'] = acym_translation('ACYM_USER_CREATION_DATE'); |
| 63 |
$descriptions['open_date'] = acym_translation('ACYM_USER_OPEN_DATE'); |
| 64 |
$descriptions['date_click'] = acym_translation('ACYM_USER_CLICK_DATE'); |
| 65 |
$descriptions['send_date'] = acym_translation('ACYM_USER_SEND_DATE'); |
| 66 |
|
| 67 |
echo '<div class="acym__popup__listing text-center grid-x">'; |
| 68 |
if (!empty($isAutomationAdmin) || ($mailType === 'notification' && $typeNotif !== 'acy_confirm')) { |
| 69 |
$textTrigger = $mailType == 'notification' ? 'ACYM_USER_TRIGGERING_NOTIFICATION' : 'ACYM_USER_TRIGGERING_AUTOMATION'; |
| 70 |
$typeinfo = []; |
| 71 |
$typeinfo[] = acym_selectOption('receiver', 'ACYM_RECEIVER_INFORMATION'); |
| 72 |
$typeinfo[] = acym_selectOption('current', $textTrigger); |
| 73 |
acym_radio( |
| 74 |
$typeinfo, |
| 75 |
'typeInfoSubscriber', |
| 76 |
'receiver', |
| 77 |
['onclick' => 'changeSubscriberTag(selectedSubscriberDText, jQuery(this))'] |
| 78 |
); |
| 79 |
} |
| 80 |
echo '<h1 class="acym__title acym__title__secondary text-center cell">'.esc_html(acym_translation('ACYM_RECEIVER_INFORMATION')).'</h1>'; |
| 81 |
|
| 82 |
$others = []; |
| 83 |
$others['name|part:first|ucfirst'] = ['name' => acym_translation('ACYM_USER_FIRSTPART'), 'desc' => acym_translation('ACYM_USER_FIRSTPART_DESC')]; |
| 84 |
$others['name|part:last|ucfirst'] = ['name' => acym_translation('ACYM_USER_LASTPART'), 'desc' => acym_translation('ACYM_USER_LASTPART_DESC')]; |
| 85 |
|
| 86 |
foreach ($others as $tagname => $tag) { |
| 87 |
echo '<div style="cursor:pointer" class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriberTag(\''.esc_attr( |
| 88 |
$tagname |
| 89 |
).'\', jQuery(this));"> |
| 90 |
<div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($tag['name']).'</div> |
| 91 |
<div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($tag['desc']).'</div> |
| 92 |
</div>'; |
| 93 |
} |
| 94 |
|
| 95 |
foreach ($fields as $field) { |
| 96 |
$fieldKey = is_object($field) ? $field->namekey : $field; |
| 97 |
$fieldName = is_object($field) ? acym_translation($field->name) : $field; |
| 98 |
if (empty($descriptions[$fieldKey])) { |
| 99 |
continue; |
| 100 |
} |
| 101 |
|
| 102 |
$type = ''; |
| 103 |
if (in_array($fieldKey, ['creation_date', 'open_date', 'date_click', 'send_date'])) { |
| 104 |
$type = '|type:time'; |
| 105 |
} |
| 106 |
|
| 107 |
echo '<div style="cursor:pointer" class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriberTag(\''.esc_attr( |
| 108 |
$fieldKey.$type |
| 109 |
).'\', jQuery(this));"> |
| 110 |
<div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($fieldName).'</div> |
| 111 |
<div class="cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($descriptions[$fieldKey]).'</div> |
| 112 |
</div>'; |
| 113 |
} |
| 114 |
|
| 115 |
echo '</div>'; |
| 116 |
} |
| 117 |
|
| 118 |
public function replaceUserInformation(object &$email, ?object &$user, bool $send = true): void |
| 119 |
{ |
| 120 |
$extractedTags = $this->pluginHelper->extractTags($email, $this->name); |
| 121 |
$backwardsTags = $this->pluginHelper->extractTags($email, 'subtag'); |
| 122 |
foreach ($backwardsTags as $tag => $params) { |
| 123 |
$extractedTags[$tag] = $params; |
| 124 |
} |
| 125 |
|
| 126 |
if (empty($extractedTags)) return; |
| 127 |
|
| 128 |
$fieldClass = new FieldClass(); |
| 129 |
$fields = $fieldClass->getFieldsByNameKey(array_column($extractedTags, 'id')); |
| 130 |
$fieldsData = empty($user->id) ? [] : $fieldClass->getAllFieldsListingByUserIds([$user->id], array_keys($fields)); |
| 131 |
$fieldsNameKeyIdMap = array_combine(array_column($fields, 'namekey'), array_column($fields, 'id')); |
| 132 |
|
| 133 |
$tags = []; |
| 134 |
foreach ($extractedTags as $i => $oneTag) { |
| 135 |
if (isset($tags[$i]) || (!empty($oneTag->info) && $oneTag->info === 'current')) { |
| 136 |
continue; |
| 137 |
} |
| 138 |
|
| 139 |
$fieldNameKey = $oneTag->id === 'acym_language' ? 'language' : $oneTag->id; |
| 140 |
|
| 141 |
if ($fieldNameKey === 'autologin_token' && !empty($user->id) && !empty($user->key)) { |
| 142 |
$fieldValue = acym_generateAutologinToken(intval($user->id), $user->key); |
| 143 |
$this->pluginHelper->formatString($fieldValue, $oneTag); |
| 144 |
$tags[$i] = $fieldValue; |
| 145 |
continue; |
| 146 |
} |
| 147 |
|
| 148 |
$fieldId = $fieldsNameKeyIdMap[$fieldNameKey] ?? 0; |
| 149 |
$fieldValue = $user->$fieldNameKey ?? ''; |
| 150 |
|
| 151 |
if (strlen($fieldValue) === 0 && !empty($user->id) && !empty($fieldId)) { |
| 152 |
$fieldValue = $fieldsData[$fieldId.'-'.$user->id] ?? $oneTag->default; |
| 153 |
} |
| 154 |
|
| 155 |
if (strlen($fieldValue) === 0) { |
| 156 |
$fieldValue = $oneTag->default; |
| 157 |
} |
| 158 |
|
| 159 |
$fieldValue = acym_translation(nl2br($fieldValue)); |
| 160 |
$this->pluginHelper->formatString($fieldValue, $oneTag); |
| 161 |
$tags[$i] = $fieldValue; |
| 162 |
} |
| 163 |
|
| 164 |
$this->pluginHelper->replaceTags($email, $tags); |
| 165 |
} |
| 166 |
} |
| 167 |
|