#Uis', '', $mail->$oneAttribute);
$mail->$oneAttribute = str_replace(' contenteditable="true"', '', $mail->$oneAttribute);
} else {
$mail->$oneAttribute = strip_tags($mail->$oneAttribute);
}
}
$mailID = parent::save($mail);
if (!empty($mailID) && isset($tags)) {
$tagClass = new TagClass();
$tagClass->setTags(TagClass::TYPE_MAIL, intval($mailID), $tags);
}
return $mailID;
}
public function autoSave(object $mail, string $language = 'main'): bool
{
if (empty($mail->id)) {
return false;
}
$mail->autosave = str_replace(' contenteditable="true"', '', $mail->autosave);
if (acym_isMultilingual() && $language !== 'main') {
$translationId = $this->getTranslationId($mail->id, $language);
if (empty($translationId)) {
$parentCopy = $this->getOneById($mail->id);
if (empty($parentCopy)) {
return false;
}
unset($parentCopy->id);
$parentCopy->parent_id = $mail->id;
$parentCopy->language = $language;
$translationId = $this->save($parentCopy);
}
$mail->id = $translationId;
}
$mail = $this->encode($mail);
return (bool)parent::save($mail);
}
public function delete(array $elements): int
{
if (empty($elements)) return 0;
$this->deleteMediaFolder($elements);
acym_arrayToInteger($elements);
$favoriteTemplate = (int)$this->config->get('favorite_template', 0);
if (in_array($favoriteTemplate, $elements)) {
$this->config->saveConfig(['favorite_template' => 0]);
}
$allThumbnailToDelete = acym_loadResultArray('SELECT DISTINCT thumbnail FROM #__acym_mail WHERE id IN ('.implode(',', $elements).')');
$translations = acym_loadResultArray('SELECT id FROM #__acym_mail WHERE parent_id IN ('.implode(',', $elements).')');
$elements = array_merge($elements, $translations);
if (!empty($translations)) {
acym_query('UPDATE #__acym_mail SET `parent_id` = null WHERE `id` IN ('.implode(',', $translations).')');
}
acym_query('UPDATE #__acym_list SET welcome_id = null WHERE welcome_id IN ('.implode(',', $elements).')');
acym_query('UPDATE #__acym_list SET unsubscribe_id = null WHERE unsubscribe_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_queue WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_mail_has_list WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_tag WHERE `type` = "mail" AND `id_element` IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_user_stat WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_url_click WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_mail_stat WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_followup_has_mail WHERE mail_id IN ('.implode(',', $elements).')');
acym_query('DELETE FROM #__acym_mail_archive WHERE mail_id IN ('.implode(',', $elements).')');
$return = parent::delete($elements);
$this->deleteUnusedThumbnails($allThumbnailToDelete);
return $return;
}
public function deleteMediaFolder(array $elements): void
{
if (empty($elements)) {
return;
}
acym_arrayToInteger($elements);
$results = acym_loadResultArray('SELECT mail_settings FROM #__acym_mail WHERE mail_settings IS NOT NULL AND id IN ('.implode(',', $elements).')');
foreach ($results as $template) {
$settings = json_decode($template, true);
if (empty($settings['media_folder']) || !file_exists(ACYM_TEMPLATE.$settings['media_folder'])) {
continue;
}
acym_deleteFolder(ACYM_TEMPLATE.$settings['media_folder']);
}
}
public function deleteUnusedThumbnails(array $thumbnails): void
{
if (empty($thumbnails)) {
return;
}
foreach ($thumbnails as $key => $oneThumb) {
$thumbnails[$key] = acym_escapeDB($oneThumb);
}
$stillUsedThumbnails = acym_loadResultArray('SELECT thumbnail FROM #__acym_mail WHERE thumbnail IN ('.implode(',', $thumbnails).')');
$thumbnailToDelete = array_diff($thumbnails, $stillUsedThumbnails);
foreach ($thumbnailToDelete as $one) {
if (!empty($one) && file_exists(ACYM_UPLOAD_FOLDER_THUMBNAIL.$one)) {
unlink(ACYM_UPLOAD_FOLDER_THUMBNAIL.$one);
}
}
}
public function deleteOneAttachment(int $mailId, int $idAttachment): bool
{
if (empty($mailId)) {
return false;
}
$mail = $this->getOneById($mailId);
$attachments = $mail->attachments;
if (empty($attachments)) {
return false;
}
$decodedAttach = json_decode($attachments, true);
unset($decodedAttach[$idAttachment]);
$newAttachments = [];
if (!empty($decodedAttach)) {
foreach ($decodedAttach as $oneAttach) {
$newAttachments[] = $oneAttach;
}
}
$attachDb = json_encode($newAttachments);
return (bool)acym_query('UPDATE #__acym_mail SET attachments = '.acym_escapeDB($attachDb).' WHERE id = '.intval($mailId).' OR parent_id = '.intval($mailId));
}
public function createTemplateFile(int $id): string
{
if (empty($id)) {
return '';
}
$template = $this->getOneById($id);
if (empty($template->id)) {
return '';
}
$css = $this->buildCSS($template->stylesheet);
if (empty($css)) {
return '';
}
acym_createDir(ACYM_TEMPLATE.'css');
$cssfile = ACYM_TEMPLATE.'css'.DS.'template_'.$id.'.css';
if (acym_writeFile($cssfile, $css)) {
return $cssfile;
} else {
acym_enqueueMessage('Could not create the file '.$cssfile, 'error');
return '';
}
}
public function buildCSS(?string $stylesheet): string
{
if (empty($stylesheet)) {
return '';
}
$inline = '';
if (preg_match_all('#@import[^;]*;#is', $stylesheet, $results)) {
foreach ($results[0] as $oneResult) {
$inline .= trim($oneResult)."\n";
$stylesheet = str_replace($oneResult, '', $stylesheet);
}
}
$inline .= $stylesheet;
return $inline;
}
public function doupload(): bool
{
$zipFilePath = $this->uploadTemplate();
if (empty($zipFilePath)) {
return false;
}
$templateFolder = $this->extractTemplate($zipFilePath);
if (empty($templateFolder)) {
return false;
}
if (!$this->installExtractedTemplate($templateFolder)) {
return false;
}
return true;
}
private function uploadTemplate(): ?string
{
$importFile = acym_getVar('file', 'uploadedfile', '', 'files');
$fileError = $importFile['error'];
if ($fileError > 0) {
switch ($fileError) {
case 1:
acym_enqueueMessage(acym_translation('ACYM_FILE_UPLOAD_ERROR_1'), 'error');
return null;
case 2:
acym_enqueueMessage(acym_translation('ACYM_FILE_UPLOAD_ERROR_2'), 'error');
return null;
case 3:
acym_enqueueMessage(acym_translation('ACYM_FILE_UPLOAD_ERROR_3'), 'error');
return null;
case 4:
acym_enqueueMessage(acym_translation('ACYM_FILE_UPLOAD_ERROR_4'), 'error');
return null;
default:
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_5', $fileError), 'error');
return null;
}
}
if (empty($importFile['name'])) {
acym_enqueueMessage(acym_translation('ACYM_BROWSE_FILE'), 'error');
return null;
}
$uploadPath = acym_cleanPath(ACYM_ROOT.ACYM_MEDIA_FOLDER.'templates');
if (!is_writable($uploadPath)) {
@chmod($uploadPath, '0755');
if (!is_writable($uploadPath)) {
acym_enqueueMessage(acym_translationSprintf('ACYM_WRITABLE_FOLDER', $uploadPath), 'warning');
}
}
if (!(bool)ini_get('file_uploads')) {
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_6'), 'error');
return null;
}
if (!extension_loaded('zlib')) {
acym_raiseError(500, acym_translation('ACYM_MISSING_ZLIB'));
return null;
}
$filename = strtolower(acym_makeSafeFile($importFile['name']));
$extension = strtolower(substr($filename, strrpos($filename, '.') + 1));
$allowedFileType = true;
if ($extension !== 'zip') {
$allowedFileType = false;
} elseif (!in_array($importFile['type'], ['application/zip', 'application/x-zip-compressed'])) {
$allowedFileType = false;
} elseif (function_exists('mime_content_type') && !in_array(mime_content_type($importFile['tmp_name']), ['application/zip', 'application/x-zip-compressed'])) {
$allowedFileType = false;
}
if (!$allowedFileType) {
acym_enqueueMessage(acym_translationSprintf('ACYM_ACCEPTED_TYPE', $extension, 'zip'), 'error');
return null;
}
if (class_exists('ZipArchive')) {
$zip = new \ZipArchive();
if (filesize($importFile['tmp_name']) > self::MAX_ALLOWED_TEMPLATE_SIZE || !$zip->open($importFile['tmp_name']) || $zip->count() > self::MAX_ALLOWED_TEMPLATE_FILES) {
acym_enqueueMessage(acym_translation('ACYM_UPLOADED_ARCHIVE_NOT_ALLOWED'), 'error');
return null;
}
$zip->close();
}
$tmpPath = acym_getCMSConfig('tmp_path', ACYM_MEDIA.'tmp'.DS);
$zipFilePath = acym_cleanPath($tmpPath.DS.$filename);
$uploaded = acym_uploadFile($importFile['tmp_name'], $zipFilePath);
if (!$uploaded) {
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_7', $importFile['tmp_name'], $zipFilePath), 'error');
return null;
}
return $zipFilePath;
}
private function extractTemplate(string $zipFilePath, bool $deleteZip = true): ?string
{
$extractdir = acym_cleanPath(dirname($zipFilePath).DS.uniqid().uniqid().uniqid().'_template');
$result = acym_extractArchive($zipFilePath, $extractdir);
if (!$result) {
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_9', $zipFilePath, $extractdir), 'error');
return null;
}
if ($deleteZip) {
acym_deleteFile($zipFilePath);
}
$allFiles = acym_getFiles($extractdir, '.', true, true, [], []);
foreach ($allFiles as $oneFile) {
if (function_exists('mime_content_type')) {
$fileType = mime_content_type($oneFile);
if (in_array($fileType, self::ALLOWED_TEMPLATE_FILE_TYPES) && preg_match('#\.(jpg|gif|png|jpeg|ico|bmp|html|htm|css|webp)$#i', $oneFile)) {
continue;
}
} elseif (preg_match('#\.(jpg|gif|png|jpeg|ico|bmp|html|htm|css|webp)$#i', $oneFile)) {
continue;
}
if (acym_deleteFile($oneFile)) {
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_8', $oneFile), 'warning');
}
}
return $extractdir;
}
public function installExtractedTemplate(string $templateFolder, bool $deleteFolder = true): bool
{
if ($this->detectTemplates($templateFolder)) {
$messages = $this->templateNames;
array_unshift($messages, acym_translationSprintf('ACYM_TEMPLATES_INSTALL', count($this->templateNames)));
acym_enqueueMessage($messages);
if ($deleteFolder && is_dir($templateFolder)) {
acym_deleteFolder($templateFolder);
}
return true;
}
acym_enqueueMessage(acym_translationSprintf('ACYM_FILE_UPLOAD_ERROR_10'), 'error');
if ($deleteFolder && is_dir($templateFolder)) {
acym_deleteFolder($templateFolder);
}
return false;
}
public function detectTemplates(string $folder): bool
{
$allFiles = acym_getFiles($folder);
if (!empty($allFiles)) {
$keyTmpl = array_search('template.html', $allFiles);
if ($keyTmpl !== false) {
if ($this->installTemplate($folder.DS.$allFiles[$keyTmpl])) {
return true;
}
}
foreach ($allFiles as $oneFile) {
if (preg_match('#^.*(html|htm)$#i', $oneFile)) {
if ($this->installTemplate($folder.DS.$oneFile)) {
return true;
}
}
}
}
$status = false;
$allFolders = acym_getFolders($folder);
if (!empty($allFolders)) {
foreach ($allFolders as $oneFolder) {
$status = $this->detectTemplates($folder.DS.$oneFolder) || $status;
}
}
return $status;
}
private function installTemplate(string $filepath): bool
{
$fileContent = acym_fileGetContent($filepath);
$newTemplate = new \stdClass();
if (strpos($filepath, '_template') === false) {
$newTemplate->name = basename(dirname($filepath));
} else {
$newTemplate->name = basename($filepath);
$newTemplate->name = substr($newTemplate->name, 0, strrpos($newTemplate->name, '.'));
}
$newTemplate->name = trim(preg_replace('#[^a-z0-9]#i', ' ', $newTemplate->name));
if (preg_match('#< *title[^>]*>(.*)< */ *title *>#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->name = $results[1];
if (preg_match('#< *meta *name="fromname" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->fromname = $results[1];
if (preg_match('#< *meta *name="fromemail" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->fromemail = $results[1];
if (preg_match('#< *meta *name="replyname" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->replyname = $results[1];
if (preg_match('#< *meta *name="replyemail" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->replyemail = $results[1];
if (preg_match('#< *meta *name="subject" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) $newTemplate->subject = $results[1];
if (preg_match('#< *meta *name="settings" *content="([^"]*)"#Uis', $fileContent, $results) && !empty($results[1])) {
$newTemplate->settings = htmlspecialchars_decode($results[1]);
}
$newFolder = preg_replace('#[^a-z0-9]#i', '_', strtolower($newTemplate->name));
$newTemplateFolder = $newFolder;
$i = 1;
while (is_dir(ACYM_TEMPLATE.$newTemplateFolder)) {
$newTemplateFolder = $newFolder.'_'.$i;
$i++;
}
$newTemplate->mail_settings = ['media_folder' => $newTemplateFolder];
$moveResult = acym_copyFolder(dirname($filepath), ACYM_TEMPLATE.$newTemplateFolder);
if ($moveResult !== true) {
acym_display([acym_translationSprintf('ACYM_ERROR_COPYING_FOLDER_TO', dirname($filepath), ACYM_TEMPLATE.$newTemplateFolder), $moveResult], 'error');
return false;
}
if (!file_exists(ACYM_TEMPLATE.$newTemplateFolder.DS.'index.html')) {
$indexFile = '';
acym_writeFile(ACYM_TEMPLATE.$newTemplateFolder.DS.'index.html', $indexFile);
}
$fileContent = str_replace(
[
'src="./',
'src="../',
'src="images/',
'url("images/',
'url("images/',
],
[
'src="'.ACYM_TEMPLATE_URL.$newTemplateFolder.'/',
'src="'.ACYM_TEMPLATE_URL,
'src="'.ACYM_TEMPLATE_URL.$newTemplateFolder.'/images/',
'url("'.ACYM_TEMPLATE_URL.$newTemplateFolder.'/images/',
'url("'.ACYM_TEMPLATE_URL.$newTemplateFolder.'/images/',
],
$fileContent
);
$fileContent = preg_replace('#(src|background)[ ]*=[ ]*\"(?!(https?://|/))(?:\.\./|\./)?#', '$1="'.ACYM_TEMPLATE_URL.$newTemplateFolder.'/', $fileContent);
if (preg_match('#< *body[^>]*>(.*)< */ *body *>#Uis', $fileContent, $results)) {
$newTemplate->body = $results[1];
} else {
$newTemplate->body = $fileContent;
}
$newTemplate->stylesheet = '';
if (preg_match_all('#< *style[^>]*>(.*)< */ *style *>#Uis', $fileContent, $results)) {
$newTemplate->stylesheet .= preg_replace('#()#s', '', implode("\n", $results[1]));
}
$cssFiles = [];
$cssFiles[ACYM_TEMPLATE.$newTemplateFolder] = acym_getFiles(ACYM_TEMPLATE.$newTemplateFolder, '\.css$');
$subFolders = acym_getFolders(ACYM_TEMPLATE.$newTemplateFolder);
foreach ($subFolders as $oneFolder) {
$cssFiles[ACYM_TEMPLATE.$newTemplateFolder.DS.$oneFolder] = acym_getFiles(ACYM_TEMPLATE.$newTemplateFolder.DS.$oneFolder, '\.css$');
}
foreach ($cssFiles as $cssFolder => $cssFile) {
if (empty($cssFile)) continue;
$newTemplate->stylesheet .= "\n".acym_fileGetContent($cssFolder.DS.reset($cssFile));
}
if (!empty($newTemplate->stylesheet)) {
if (preg_match('#body *\{[^\}]*background-color:([^;\}]*)[;\}]#Uis', $newTemplate->stylesheet, $backgroundresults)) {
$newTemplate->stylesheet = preg_replace('#(body *\{[^\}]*)background-color:[^;\}]*[;\}]#Uis', '$1', $newTemplate->stylesheet);
}
$quickstyle = [
'tag_h1' => 'h1',
'tag_h2' => 'h2',
'tag_h3' => 'h3',
'tag_h4' => 'h4',
'tag_h5' => 'h5',
'tag_h6' => 'h6',
'tag_a' => 'a',
'tag_ul' => 'ul',
'tag_li' => 'li',
'acym_unsub' => '\.acym_unsub',
'acym_online' => '\.acym_online',
'acym_title' => '\.acym_title',
'acym_content' => '\.acym_content',
'acym_readmore' => '\.acym_readmore',
];
foreach ($quickstyle as $styledb => $oneStyle) {
if (preg_match('#[^a-z\. ,] *'.$oneStyle.' *{([^}]*)}#Uis', $newTemplate->stylesheet, $quickstyleresults)) {
$newTemplate->stylesheet = str_replace($quickstyleresults[0], '', $newTemplate->stylesheet);
}
}
}
$foldersForPicts = [$newTemplateFolder];
$otherFolders = acym_getFolders(ACYM_TEMPLATE.$newTemplateFolder);
foreach ($otherFolders as $oneFold) {
$foldersForPicts[] = $newTemplateFolder.DS.$oneFold;
}
$allPictures = [];
foreach ($foldersForPicts as $oneFolder) {
$allPictures[$oneFolder] = acym_getFiles(ACYM_TEMPLATE.$oneFolder);
}
$uploadsFolder = ACYM_UPLOAD_FOLDER_THUMBNAIL;
$thumbNb = intval($this->config->get('numberThumbnail', 2));
foreach ($allPictures as $folder => $pictfolders) {
foreach ($pictfolders as $onePict) {
if (!preg_match('#\.(jpg|gif|png|jpeg|ico|bmp)$#i', $onePict)) continue;
if (preg_match('#(thumbnail|screenshot|muestra)#i', $onePict)) {
$thumbNb++;
$newNamePict = 'thumbnail_'.$thumbNb.'.png';
copy(ACYM_TEMPLATE.str_replace(DS, '/', $folder).'/'.$onePict, $uploadsFolder.$newNamePict);
$newTemplate->thumbnail = $newNamePict;
}
}
}
$this->config->saveConfig(['numberThumbnail' => $thumbNb]);
$newTemplate->drag_editor = strpos($newTemplate->body, 'acym__wysid__template__content') !== false ? 1 : 0;
$newTemplate->type = self::TYPE_TEMPLATE;
$newTemplate->creation_date = acym_date('now', 'Y-m-d H:i:s', false);
$this->save($newTemplate);
$this->templateNames[] = $newTemplate->name;
return true;
}
public function sendAutomation(int $mailId, array $userIds, string $sendingDate, array $automationAdmin = [])
{
if (empty($mailId)) {
return acym_translationSprintf('ACYM_EMAILS_ADDED_QUEUE', 0);
}
if (empty($sendingDate)) {
return acym_translation('ACYM_WRONG_DATE');
}
if (empty($userIds)) {
return acym_translation('ACYM_USER_NOT_FOUND');
}
acym_arrayToInteger($userIds);
$nbSent = $this->sendNotification($mailId, $userIds, $automationAdmin);
if (!is_null($nbSent)) {
return $nbSent;
}
$result = acym_query(
'INSERT IGNORE INTO #__acym_queue (`mail_id`, `user_id`, `sending_date`)
SELECT '.intval($mailId).', user.id, '.acym_escapeDB($sendingDate).'
FROM #__acym_user AS user
WHERE user.active = 1 AND user.id IN ('.implode(',', $userIds).')'
);
if ($result === 0) {
return acym_translation('ACYM_CAMPAIGN_ALREADY_QUEUED');
}
$mailStatClass = new MailStatClass();
$mailStat = $mailStatClass->getOneRowByMailId($mailId);
$newMailStat = new \stdClass();
$newMailStat->mail_id = intval($mailId);
$newMailStat->total_subscribers = intval($result);
if (empty($mailStat)) {
$newMailStat->send_date = $sendingDate;
}
$mailStatClass->save($newMailStat);
return $result;
}
private function sendNotification(int $mailId, array $userIds, array $automationAdmin): ?int
{
if (empty($automationAdmin['user_id'])) {
return null;
}
$userClass = new UserClass();
$mail = $this->getOneById($mailId);
$user = $userClass->getOneById($automationAdmin['user_id']);
if (empty($mail) || empty($user)) {
return 0;
}
$mailerHelper = new MailerHelper();
$pluginHelper = new PluginHelper();
$extractedTags = $pluginHelper->extractTags($mail, 'subscriber');
$isNotification = false;
foreach ($extractedTags as $dtext => $oneTag) {
if (empty($oneTag->info) || $oneTag->info !== 'current') {
continue;
}
$isNotification = true;
if (!empty($user->{$oneTag->id})) {
$mailerHelper->addParam(str_replace(['{', '}'], '', $dtext), $user->{$oneTag->id});
}
}
if (!$isNotification) {
if (isset($automationAdmin['automationAdmin']) && $automationAdmin['automationAdmin']) {
return 0;
} else {
return null;
}
}
$userFields = $userClass->getAllUserFields($user);
foreach ($userFields as $map => $value) {
$mailerHelper->addParam('subscriber:'.$map.'|info:current', $value);
$mailerHelper->addParam('user:'.$map, $value);
}
$emailsSent = 0;
foreach ($userIds as $userId) {
if ($mailerHelper->sendOne($mail->id, $userId)) {
$emailsSent++;
}
}
return $emailsSent;
}
public function encode($mails = [])
{
$isArray = true;
if (!is_array($mails)) {
$mails = [$mails];
$isArray = false;
}
$encodedMails = array_map([$this, 'removePoweredByAcyMailing'], $mails);
$encodedMails = array_map([$this, 'utf8Encode'], $encodedMails);
return $isArray ? $encodedMails : $encodedMails[0];
}
public function decode($mails = [])
{
if (is_null($mails)) {
return null;
}
$isArray = true;
if (!is_array($mails)) {
$mails = [$mails];
$isArray = false;
}
$decodedMails = array_map([$this, 'utf8Decode'], $mails);
$decodedMails = array_map([$this, 'addPoweredByAcyMailing'], $decodedMails);
foreach ($decodedMails as $i => $oneMail) {
if (!isset($oneMail->access) || is_array($oneMail->access)) continue;
$decodedMails[$i]->access = empty($oneMail->access) ? '' : explode(',', $oneMail->access);
}
return $isArray ? $decodedMails : $decodedMails[0];
}
protected function utf8Decode($mail)
{
if (!empty($mail)) {
foreach (self::FIELDS_ENCODING as $oneField) {
if (in_array($oneField, $this->exceptKeysDecode)) {
continue;
}
if (is_array($mail)) {
if (empty($mail[$oneField])) continue;
$value = &$mail[$oneField];
} else {
if (empty($mail->$oneField)) continue;
$value = &$mail->$oneField;
}
$value = acym_utf8Decode($value);
}
}
return $mail;
}
private function addPoweredByAcyMailing(object $mail): object
{
if (empty($mail->body)) {
return $mail;
}
if ($this->config->get('display_built_by', 0) != 1) {
if (strpos($mail->body, 'acym__powered_by_acymailing') !== false) {
$mailBodyDom = new \DOMDocument();
@$mailBodyDom->loadHTML(''.$mail->body);
$tables = $mailBodyDom->getElementsByTagName('table');
foreach ($tables as $table) {
if ($table->getAttribute('id') != 'acym__powered_by_acymailing') continue;
$table->parentNode->removeChild($table);
break;
}
$mail->body = $mailBodyDom->saveHTML();
}
return $mail;
}
if (strpos($mail->body, 'acym__powered_by_acymailing') !== false) {
return $mail;
}
$isWysidEditor = strpos($mail->body, 'acym__wysid__template') !== false;
$urlPoweredByImage = ACYM_IMAGES.'editor/poweredby_black.png';
if (!$isWysidEditor) {
$poweredByHTML = '';
$poweredByHTML .= '';
$poweredByHTML .= '
';
$poweredByHTML .= '
';
$mail->body = $mail->body.$poweredByHTML;
} else {
$poweredByWYSID = '';
$mailBodyDom = new \DOMDocument();
@$mailBodyDom->loadHTML(''.$mail->body);
$htmlToAddDom = new \DOMDocument();
@$htmlToAddDom->loadHTML(''.$poweredByWYSID);
$tableToAdd = $htmlToAddDom->getElementById('acym__powered_by_acymailing');
$tds = $mailBodyDom->getElementsByTagName('td');
foreach ($tds as $td) {
$classes = explode(' ', $td->getAttribute('class'));
if (!in_array('acym__wysid__row', $classes)) continue;
if (!empty($tableToAdd)) $td->appendChild($mailBodyDom->importNode($tableToAdd, true));
break;
}
$mail->body = $mailBodyDom->saveHTML();
}
return $mail;
}
protected function removePoweredByAcyMailing(object $mail): object
{
if (empty($mail->body) || strpos($mail->body, 'acym__wysid__template') !== false) {
return $mail;
}
$regexPoweredByAcyMailing = '#