PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Mails/Edition.php +278 -0 trunk → 11.1.0 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace AcyMailing\Controllers\Mails;
4 4
5 +use AcyMailing\Classes\CampaignClass;
5 6 use AcyMailing\Classes\FollowupClass;
6 7 use AcyMailing\Classes\ListClass;
7 8 use AcyMailing\Classes\MailClass;
8 9 use AcyMailing\Classes\TagClass;
@@ -729,8 +730,110 @@
729 730 acym_redirect($return);
730 731 }
731 732 }
732 733
734 + public function autoSave(): void
735 + {
736 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
737 +
738 + $mailClass = new MailClass();
739 + $mail = new \stdClass();
740 +
741 + $language = acym_getVar('string', 'language', 'main');
742 + $mail->id = acym_getVar('int', 'mailId', 0);
743 + $mail->autosave = base64_decode(acym_getVar('string', 'autoSave', '', 'REQUEST', ACYM_ALLOWRAW));
744 +
745 + if (empty($mail->id) || !$mailClass->hasUserAccess($mail->id, true) || !$mailClass->autoSave($mail, $language)) {
746 + acym_sendAjaxResponse('', [], false);
747 + } else {
748 + acym_sendAjaxResponse();
749 + }
750 + }
751 +
752 + public function ajaxCheckVideoUrl(): void
753 + {
754 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
755 + $videoUrl = acym_getVar('string', 'url', '');
756 +
757 + if (!acym_isValidUrl($videoUrl)) {
758 + acym_sendAjaxResponse('', [], false);
759 + }
760 +
761 + $image = '';
762 + $imageName = '';
763 +
764 + $youtubeMatch = '';
765 + $vimeoMatch = '';
766 + $dailymotionMatch = '';
767 +
768 + preg_match('/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/', $videoUrl, $youtubeMatch);
769 + preg_match('/^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/', $videoUrl, $vimeoMatch);
770 + preg_match('/^(?:(?:http|https):\/\/)?(?:www.)?(dailymotion\.com|dai\.ly)\/((video\/([^_]+))|(hub\/([^_]+)|([^\/_]+)))$/', $videoUrl, $dailymotionMatch);
771 +
772 + if (!empty($youtubeMatch)) {
773 + $image = 'https://img.youtube.com/vi/'.$youtubeMatch[1].'/0.jpg';
774 + $imageName = $youtubeMatch[1];
775 + } elseif (!empty($dailymotionMatch)) {
776 + $dailymotionImage = $dailymotionMatch[4] ?? $dailymotionMatch[2];
777 +
778 + $image = 'https://www.dailymotion.com/thumbnail/video/'.$dailymotionImage;
779 + $imageName = $dailymotionMatch[2];
780 + } elseif (!empty($vimeoMatch)) {
781 + $image = unserialize(file_get_contents('https://vimeo.com/api/v2/video/'.$vimeoMatch[5].'.php'));
782 + $image = $image[0]['thumbnail_large'];
783 + $imageName = $vimeoMatch[5];
784 + }
785 +
786 + if (empty($image) || !acym_isValidUrl($image)) {
787 + acym_sendAjaxResponse('', [], false);
788 + }
789 +
790 + acym_sendAjaxResponse('', ['new_image_name' => $this->saveVideoPreview($image, urlencode($imageName).'.jpg')]);
791 + }
792 +
793 + private function saveVideoPreview(string $image, string $fileName): string
794 + {
795 + if (!$this->config->get('add_play_button_video', 1)) {
796 + return $image;
797 + }
798 +
799 + $imageVideo = imagecreatefromjpeg($image);
800 + $playButton = @imagecreatefrompng(ACYM_ROOT.ACYM_MEDIA_FOLDER.'images'.DS.'editor'.DS.'video_insertion'.DS.'play_button.png');
801 + if ($playButton === false || $imageVideo === false) {
802 + return $image;
803 + }
804 + $imageWidth = imagesx($imageVideo);
805 + $imageHeight = imagesy($imageVideo);
806 + $logoWidth = imagesx($playButton);
807 + $logoHeight = imagesy($playButton);
808 +
809 + $left = round(($imageWidth - $logoWidth) / 2);
810 + $top = round(($imageHeight - $logoHeight) / 2);
811 + imagecopy($imageVideo, $playButton, $left, $top, 0, 0, $logoWidth, $logoHeight);
812 + $tmpFilePath = ACYM_TMP_FOLDER.'tmp.jpg';
813 + acym_createFolder(ACYM_TMP_FOLDER);
814 + imagepng($imageVideo, $tmpFilePath, 9);
815 + $input = imagecreatefrompng($tmpFilePath);
816 + $output = imagecreatetruecolor($imageWidth, $imageHeight);
817 + $white = imagecolorallocate($output, 255, 255, 255);
818 +
819 + imagefilledrectangle($output, 0, 0, $imageWidth, $imageHeight, $white);
820 + imagecopy($output, $input, 0, 0, 0, 0, $imageWidth, $imageHeight);
821 +
822 + ob_start();
823 + $status = imagejpeg($output, null, 95);
824 + $imageContent = ob_get_clean();
825 + if ($status && acym_writeFile(ACYM_ROOT.ACYM_UPLOAD_FOLDER.$fileName, $imageContent)) {
826 + acym_deleteFile($tmpFilePath);
827 +
828 + return ACYM_UPLOADS_URL.$fileName;
829 + }
830 +
831 + acym_deleteFile($tmpFilePath);
832 +
833 + return '';
834 + }
835 +
733 836 public function getTemplateAjax(): void
734 837 {
735 838 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
736 839
@@ -832,8 +935,90 @@
832 935 acym_sendAjaxResponse('', ['pagination' => $return]);
833 936 exit;
834 937 }
835 938
939 + public function setNewThumbnail(): void
940 + {
941 + if (!acym_isAdmin() || (!acym_isAllowed('mails') && !acym_isAllowed('campaigns'))) {
942 + die('Access denied for thumbnail creation');
943 + }
944 +
945 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
946 + $contentThumbnail = acym_getVar('string', 'content', '');
947 + if (strpos($contentThumbnail, 'data:image/png') !== 0) {
948 + acym_sendAjaxResponse('This file is not allowed.', [], false);
949 + }
950 +
951 + $mailId = acym_getVar('int', 'mailId', 0);
952 + if (!empty($mailId)) {
953 + $mailClass = new MailClass();
954 + $mail = $mailClass->getOneById($mailId);
955 + if (!empty($mail)) {
956 + $file = $mail->thumbnail;
957 + }
958 + }
959 +
960 + if (empty($file) || strpos($file, 'http') === 0) {
961 + $thumbNb = $this->config->get('numberThumbnail', 2);
962 + $file = 'thumbnail_'.($thumbNb + 1).'.png';
963 + $this->config->saveConfig(['numberThumbnail' => $thumbNb + 1]);
964 + }
965 +
966 + $extension = acym_fileGetExt($file);
967 + if (strpos($file, 'thumbnail_') === false || !in_array($extension, ['png', 'jpeg', 'jpg', 'gif', 'webp'])) {
968 + acym_sendAjaxResponse('This file is not allowed.', [], false);
969 + }
970 +
971 + acym_createFolder(ACYM_UPLOAD_FOLDER_THUMBNAIL);
972 + file_put_contents(ACYM_UPLOAD_FOLDER_THUMBNAIL.$file, base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $contentThumbnail)));
973 +
974 + acym_sendAjaxResponse('', ['fileName' => $file]);
975 + }
976 +
977 + public function setNewIconShare(): void
978 + {
979 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
980 + $socialName = acym_getVar('string', 'social', '');
981 + $socialMedias = acym_getSocialMedias();
982 + if (!in_array($socialName, $socialMedias)) {
983 + acym_sendAjaxResponse(acym_translationSprintf('ACYM_UNKNOWN_SOCIAL', $socialName), [], false);
984 + }
985 +
986 + $file = acym_getVar('array', 'file', [], 'FILES');
987 + $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
988 + $newPath = ACYM_UPLOAD_FOLDER.'socials'.DS.$socialName;
989 + $newPathComplete = $newPath.'.'.$extension;
990 +
991 + $allowedExtensions = acym_getImageFileExtensions(true);
992 + if (!in_array($extension, $allowedExtensions)) {
993 + $errorMessage = acym_translationSprintf('ACYM_ACCEPTED_TYPE', esc_html($extension), implode(', ', $allowedExtensions));
994 + } elseif (!acym_uploadFile($file['tmp_name'], ACYM_ROOT.$newPathComplete)) {
995 + $errorMessage = acym_translationSprintf('ACYM_ERROR_UPLOADING_FILE_X', $newPathComplete);
996 + } elseif (strtolower($extension) === 'svg' && !acym_isSvgFileSafe(ACYM_ROOT.$newPathComplete)) {
997 + acym_deleteFile(ACYM_ROOT.$newPathComplete);
998 + $errorMessage = acym_translationSprintf('ACYM_ERROR_UPLOADING_FILE_X', $newPathComplete);
999 + }
1000 +
1001 + if (!empty($errorMessage)) {
1002 + acym_sendAjaxResponse($errorMessage, [], false);
1003 + }
1004 +
1005 + $newImg = acym_rootURI().$newPathComplete;
1006 + $newImgWithoutExtension = acym_rootURI().$newPath;
1007 +
1008 + $socialIcons = json_decode($this->config->get('social_icons', '{}'), true);
1009 + $socialIcons[$socialName] = $newImg;
1010 + $this->config->saveConfig(['social_icons' => json_encode($socialIcons)]);
1011 +
1012 + acym_sendAjaxResponse(
1013 + acym_translation('ACYM_ICON_IMPORTED'),
1014 + [
1015 + 'url' => $newImgWithoutExtension,
1016 + 'extension' => $extension,
1017 + ]
1018 + );
1019 + }
1020 +
836 1021 public function saveAjax(): void
837 1022 {
838 1023 $mailId = $this->store(true);
839 1024
@@ -900,8 +1085,101 @@
900 1085 acym_enqueueMessage(acym_translationSprintf('ACYM_SEND_ERROR', $mail->name, $currentEmail), 'error', true, [$notification]);
901 1086 }
902 1087
903 1088 $this->edit();
1089 + }
1090 +
1091 + public function sendTest(): void
1092 + {
1093 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
1094 + $controller = acym_getVar('string', 'controller', 'mails');
1095 + $level = 'info';
1096 +
1097 + $testNote = acym_getVar('string', 'test_note', '');
1098 + $mailClass = new MailClass();
1099 + $mailerHelper = new MailerHelper();
1100 + $mailerHelper->autoAddUser = true;
1101 + $mailerHelper->report = false;
1102 +
1103 + if (in_array($controller, ['mails', 'frontmails'])) {
1104 + $mailId = acym_getVar('int', 'id', 0);
1105 + } else {
1106 + $campaignId = acym_getVar('int', 'id', 0);
1107 + $campaignClass = new CampaignClass();
1108 + $campaign = $campaignClass->getOneById($campaignId);
1109 + if (empty($campaign)) {
1110 + acym_sendAjaxResponse('', ['level' => 'error', 'message' => acym_translation('ACYM_CAMPAIGN_NOT_FOUND')], false);
1111 + }
1112 + if (!$campaignClass->hasUserAccess($campaignId)) {
1113 + die('A test of this campaign cannot be sent');
1114 + }
1115 +
1116 + $mailId = $campaign->mail_id;
1117 + $mailerHelper->isAbTest = $campaignClass->isAbTestMail($mailId);
1118 +
1119 + $campaignVersion = acym_getVar('string', 'lang_version', 'main');
1120 + if (!empty($campaignVersion) && $campaignVersion !== 'main') {
1121 + if ($campaignVersion === 'B') {
1122 + $versions = $mailClass->getVersionsById($mailId);
1123 + if (!empty($versions)) {
1124 + $mailIds = array_keys($versions);
1125 + $mailId = array_pop($mailIds);
1126 + }
1127 + } else {
1128 + $translationId = $mailClass->getTranslationId($mailId, $campaignVersion);
1129 + if (!empty($translationId)) {
1130 + $mailId = $translationId;
1131 + }
1132 + }
1133 + }
1134 + }
1135 +
1136 + $mail = $mailClass->getOneById($mailId);
1137 +
1138 + if (empty($mail) || !$mailClass->hasUserAccess($mailId)) {
1139 + acym_sendAjaxResponse('', ['level' => 'error', 'message' => acym_translation('ACYM_EMAIL_NOT_FOUND')], false);
1140 + }
1141 +
1142 + $report = [];
1143 +
1144 + $testEmails = explode(',', acym_getVar('string', 'test_emails'));
1145 + $options = [
1146 + 'isTest' => true,
1147 + 'testNote' => $testNote,
1148 + ];
1149 + foreach ($testEmails as $oneAddress) {
1150 + if (!$mailerHelper->sendOne($mail->id, $oneAddress, $options)) {
1151 + $level = 'error';
1152 + }
1153 +
1154 + if (!empty($mailerHelper->reportMessage)) {
1155 + $report[] = $mailerHelper->reportMessage;
1156 + }
1157 + }
1158 +
1159 + acym_sendAjaxResponse('', ['level' => $level, 'message' => implode('<br/>', $report)], $level !== 'error');
1160 + }
1161 +
1162 + public function getMailContent(): void
1163 + {
1164 + $from = acym_getVar('int', 'from', 0);
1165 +
1166 + if (empty($from)) {
1167 + acym_sendAjaxResponse(acym_translation('ACYM_EMAIL_NOT_FOUND'), [], false);
1168 + }
1169 +
1170 + $mailClass = new MailClass();
1171 + $mail = $mailClass->getOneById($from);
1172 +
1173 + if (empty($mail)) {
1174 + acym_sendAjaxResponse(acym_translation('ACYM_EMAIL_NOT_FOUND'), [], false);
1175 + }
1176 +
1177 + if ($mail->drag_editor == 0) {
1178 + acym_sendAjaxResponse('Only available for the drag and drop editor.', [], false);
1179 + }
1180 +
1181 + acym_sendAjaxResponse();
904 1182 }
905 1183
906 1184 protected function setFrontEndParamsForTemplateChoose(): int
907 1185 {