/**
  * fetch CjwNewsletterBlacklistItem object by id
  * return false if not found
  *
  * @param integer $id
  * @param boolean $asObject
  * @return CjwNewsletterBlacklistItem
  */
 public static function create($email, $note)
 {
     $newsletterUserObject = CjwNewsletterUser::fetchByEmail($email);
     $newsletterUserId = 0;
     if (is_object($newsletterUserObject)) {
         $newsletterUserId = $newsletterUserObject->attribute('id');
     }
     $row = array('email' => strtolower($email), 'note' => $note, 'created' => time(), 'creator_contentobject_id' => eZUser::currentUserID(), 'email_hash' => self::generateEmailHash($email), 'newsletter_user_id' => $newsletterUserId);
     $object = new CjwNewsletterBlacklistItem($row);
     return $object;
 }
 /**
  * fetch current data from contentobject for use in newsletter user object
  * @return array if success , false if user_account is not found in dataMap
  */
 private function fetchCurrentContentObjectData(&$contentObjectAttribute)
 {
     $http = eZHTTPTool::instance();
     // mapping of user data from contentobject for the newsletter user
     // the current object must be a User!!!
     $contentObject = $contentObjectAttribute->attribute('object');
     $contentObjectCurrentVersionId = (int) $contentObjectAttribute->attribute('version');
     $contentObjectIsPublished = $contentObject->attribute('is_published');
     // only for user/register  if version = 1 and published = false
     // don't fetch existing nl user because
     // otherwise you will see his registration
     $isNewObjectDraft = false;
     if ($contentObjectCurrentVersionId == 1 && $contentObjectIsPublished == false) {
         $isNewObjectDraft = true;
     }
     $dataMap = $contentObject->attribute('data_map');
     $userAccount = null;
     $subscriptionDataArr = array('ez_user_id' => 0, 'email' => '', 'salutation' => 0, 'first_name' => '', 'last_name' => '', 'id_array' => array(), 'list_array' => array());
     if (isset($dataMap['user_account'])) {
         $userAccount = $dataMap['user_account'];
     } else {
         return false;
     }
     if (isset($dataMap['salutation'])) {
         $subscriptionDataArr['salutation'] = (int) $dataMap['salutation']->content();
     }
     if (isset($dataMap['first_name'])) {
         $subscriptionDataArr['first_name'] = $dataMap['first_name']->content();
     }
     if (isset($dataMap['last_name'])) {
         $subscriptionDataArr['last_name'] = $dataMap['last_name']->content();
     }
     if (is_object($userAccount)) {
         $userAccountContent = $userAccount->content();
         // we are fetching the email directly from Post because we need this for checking
         // $subscriptionDataArr['email'] = $userAccountContent->attribute( 'email' );
         // has the value stored in db but not this from Post => onPublish has the Post value
         // only need for email
         // only in edit mode
         $base = 'ContentObjectAttribute';
         if ($http->hasPostVariable($base . "_data_user_email_" . $userAccount->attribute("id"))) {
             $subscriptionDataArr['email'] = $http->postVariable($base . "_data_user_email_" . $userAccount->attribute("id"));
         } else {
             $subscriptionDataArr['email'] = $userAccountContent->attribute('email');
         }
         $subscriptionDataArr['ez_user_id'] = (int) $userAccountContent->attribute('contentobject_id');
         // is_eabled is modified in user/register after this call
         // so we can't use this here
         //$newsletterUserDataArray['ez_user_is_enabled'] = $userAccount->attribute( 'is_enabled' );
     }
     if ($http->hasPostVariable('Subscription_IdArray')) {
         $subscriptionDataArr['id_array'] = $http->postVariable('Subscription_IdArray');
     }
     if ($http->hasPostVariable('Subscription_ListArray')) {
         $subscriptionDataArr['list_array'] = $http->postVariable('Subscription_ListArray');
     }
     foreach ($subscriptionDataArr['id_array'] as $listId) {
         if ($http->hasPostVariable("Subscription_OutputFormatArray_{$listId}")) {
             $subscriptionDataArr['list_output_format_array'][$listId] = $http->postVariable("Subscription_OutputFormatArray_{$listId}");
         } else {
             $defaultOutputFormatId = 0;
             $subscriptionDataArr['list_output_format_array'][$listId] = array($defaultOutputFormatId);
         }
     }
     if ($isNewObjectDraft === true) {
         $existingNewsletterUser = false;
     } elseif ($subscriptionDataArr['ez_user_id'] > 0) {
         $existingNewsletterUser = CjwNewsletterUser::fetchByEzUserId($subscriptionDataArr['ez_user_id']);
         if (is_object($existingNewsletterUser) === false) {
             if ($subscriptionDataArr['email'] != '') {
                 $existingNewsletterUser = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
             }
         }
     } elseif ($subscriptionDataArr['email'] != '') {
         $existingNewsletterUser = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
     } else {
         $existingNewsletterUser = false;
     }
     $returnArray = array('is_new_object_draft' => $isNewObjectDraft, 'subscription_data_array' => $subscriptionDataArr, 'existing_newsletter_user' => $existingNewsletterUser);
     // var_dump( $returnArray );
     return $returnArray;
 }
     $existingNewsletterUserObject = CjwNewsletterUser::fetchByRemoteId($remote_id);
     if (is_object($existingNewsletterUserObject)) {
         // sicherstellen, dass wir keine duplicate emails haben
         if ($email != $existingNewsletterUserObject->attribute('email')) {
             $tmpUserObject = CjwNewsletterUser::fetchByEmail($email);
             if (is_object($tmpUserObject)) {
                 // houston, we've got a problem - $tmpUserObject löschen???
                 // ToDo
                 CjwNewsletterLog::writeError('CSV Import: duplicate E-Mail Adress', 'user', 'email', array('email_cur' => $existingNewsletterUserObject->attribute('email'), 'email_imp' => $email, 'remote_id' => $remoteId));
             }
         }
     }
     // user hat sich selbst per subscription angelegt?
     // sonst nach email suchen
     if (!is_object($existingNewsletterUserObject)) {
         $existingNewsletterUserObject = CjwNewsletterUser::fetchByEmail($email);
     }
 }
 // update existing
 if (is_object($existingNewsletterUserObject)) {
     $userObject = $existingNewsletterUserObject;
     $updateUserDataIfExists = true;
     $existingUserStatus = $userObject->attribute('status');
     if ($userObject->isOnBlacklist() || $userObject->isRemovedSelf()) {
         $userIsBlacklistedOrRemoved = true;
     }
     // only user which are not blacklisted or not self removed
     // can get a new subscription
     if ($userIsBlacklistedOrRemoved === true) {
         // 0
         $createNewUser = 0;
Пример #4
0
    $viewParameters = array_merge($viewParameters, $Params['UserParameters']);
}
$tpl->setVariable('view_parameters', $viewParameters);
// validate data if new user will be created
if ($module->isCurrentAction('CreateEdit')) {
    $newsletterUserId = -1;
    $msg = 'edit_new';
    $requiredSubscriptionFields = array('email');
    foreach ($requiredSubscriptionFields as $fieldName) {
        switch ($fieldName) {
            case 'email':
                if (!eZMail::validate($subscriptionDataArr['email']) || $subscriptionDataArr['email'] == '') {
                    $warningArr['email'] = array('field_key' => ezi18n('cjw_newsletter/subscription', 'Email'), 'message' => ezi18n('cjw_newsletter/subscription', 'You must provide a valid email address.'));
                } else {
                    // check if email already exists
                    $existingNewsletterUserObject = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
                    if (is_object($existingNewsletterUserObject)) {
                        // If email exists redirect to user_edit
                        $newsletterUserId = $existingNewsletterUserObject->attribute('id');
                        $msg = 'edit_existing';
                        /*   $warningArr['email'] = array( 'field_key'   => ezi18n( 'cjw_newsletter/subscription', 'Email' ),
                             'message'     => ezi18n( 'cjw_newsletter/subscription', 'Email is already used by an other newsletter user.' ) );
                             */
                    }
                }
                break;
            default:
        }
    }
    // only store changes if all is ok
    if ($module->isCurrentAction('CreateEdit') && count($warningArr) == 0) {
Пример #5
0
 /**
  * check if $email and $ezUserId can update/create
  * negative value fail
  * @see CjwNewsletterSubscription::createSubscriptionByArray
  */
 public static function checkIfUserCanBeUpdated($email, $ezUserId, $updateNewEmail = false)
 {
     // TODO cache fetches
     // check if new email exists in the system
     $idNlUser = CjwNewsletterUser::fetchByEzUserId($ezUserId);
     $emailNlUser = CjwNewsletterUser::fetchByEmail($email);
     $idNlUserEmail = false;
     $idNlUserEzUserId = 0;
     $idNlUserId = 0;
     $idNlUserExists = false;
     $emailNlUserEmail = false;
     $emailNlUserEzUserId = 0;
     $emailNlUserId = 0;
     $emailNlUserExists = false;
     if (is_object($idNlUser)) {
         $idNlUserEmail = strtolower(trim($idNlUser->attribute('email')));
         $idNlUserEzUserId = $idNlUser->attribute('ez_user_id');
         $idNlUserId = $idNlUser->attribute('id');
         if ($idNlUserEzUserId > 0) {
             $idNlUserExists = true;
         }
     } else {
         if ($ezUserId > 0) {
             $idNlUserEzUserId = $ezUserId;
         }
     }
     if (is_object($emailNlUser)) {
         $emailNlUserEmail = strtolower(trim($emailNlUser->attribute('email')));
         $emailNlUserEzUserId = $emailNlUser->attribute('ez_user_id');
         $emailNlUserId = $emailNlUser->attribute('id');
         $emailNlUserExists = true;
     } else {
         $emailNlUserEmail = $email;
     }
     // new user => email + ezUserId not found in any nl user objects  => 40
     // update user => ezUserId == 0 or found + email not found + email1 == email2 => 41
     // update user with new email => ez_user_id found + email1 != email2 => 42
     $returnStatus = -1;
     $returnObject = false;
     // email is already used by an other nl_user with other ez_user_id
     if ($emailNlUserExists && $emailNlUserEmail != $idNlUserEmail && $emailNlUserEzUserId != $idNlUserEzUserId) {
         $returnStatus = -20;
     } elseif (!$idNlUserExists && !$emailNlUserExists && $emailNlUserEmail == '') {
         $returnStatus = -21;
     } elseif (!$idNlUserExists && !$emailNlUserExists && $emailNlUserEmail != '') {
         $returnStatus = 40;
     } elseif ($idNlUserExists && $emailNlUserExists && $idNlUserId == $emailNlUserId) {
         $returnStatus = 41;
     } elseif ($idNlUserExists && !$emailNlUserExists && $emailNlUserEmail != '') {
         $returnStatus = 42;
         if ($updateNewEmail === true) {
             // check if email has is not set by an other user
             // this could happend when the nl user is imported
             // check this in where the user can change the email address
             // for example in datatype validation
             $idNlUser->setAttribute('email', $emailNlUserEmail);
             $idNlUser->store();
         }
     }
     /*
              echo "ezUserId = $ezUserId <br>
     idNlUserEmail = $idNlUserEmail <br>
     idNlUserId = $idNlUserId <br>
     idNlUserEzUserId = $idNlUserEzUserId <br>
     idNlUserExists = $idNlUserExists <br><hr>
     
     email = $email<br>
     emailNlUserEmail = $emailNlUserEmail<br>
     emailNlUserId = $emailNlUserId <br>
     emailNlUserEzUserId = $emailNlUserEzUserId<br>
     emailNlUserExists = $emailNlUserExists<br>
     <hr> return stratus = $returnStatus <hr>";
     */
     //
     return $returnStatus;
 }
//  ezuser, anonym oder per hash
$templateFile = "design:newsletter/subscribe_infomail.tpl";
$warningArr = array();
if ($module->isCurrentAction('SubscribeInfoMail')) {
    if ($module->hasActionParameter('Email')) {
        $backUrl = '/';
        if ($module->hasActionParameter('BackUrl')) {
            $backUrl = $module->actionParameter('BackUrl');
        }
        // Wenn email ok
        // Wenn user existiert zu email
        // infomail schicken
        $email = $module->actionParameter('Email');
        if (eZMail::validate($email)) {
            // ansonsten tue nix
            $newsletterUser = CjwNewsletterUser::fetchByEmail($email);
            if ($newsletterUser) {
                $sendResult = $newsletterUser->sendSubcriptionInformationMail();
            }
            // immer erfolgstemplate zeigen auch wenn email falsch ist
            $tpl->setVariable('email_input', $email);
            $tpl->setVariable('back_url_input', $backUrl);
            $templateFile = "design:newsletter/subscribe_infomail_success.tpl";
        } else {
            $warningArr[] = array('field_key' => ezi18n('cjw_newsletter/subscribe_infomail', 'email'), 'message' => ezi18n('cjw_newsletter/subscribe_infomail', 'Please input a valid e-mail address!'));
        }
    }
}
$tpl->setVariable('warning_array', $warningArr);
$Result = array();
//$Result['content'] = $tpl->fetch( "design:newsletter/subscribe.tpl" );
Пример #7
0
            // $existingNewsletterUserObject->sendSubriptionInfoMail();
            $mailSendResult = $existingNewsletterUserObject->sendSubcriptionInformationMail();
            $tpl->setVariable('newsletter_user', $existingNewsletterUserObject);
            $tpl->setVariable('mail_send_result', $mailSendResult);
            $tpl->setVariable('subscription_result_array', false);
            $tpl->setVariable('back_url_input', $backUrl);
            if ($mailSendResult['send_result'] === true) {
                $templateFile = "design:newsletter/subscribe_success.tpl";
            } else {
                $templateFile = "design:newsletter/subscribe_success_not.tpl";
            }
        } else {
            if (count($warningArr) == 0) {
                // subscribe to all selected lists
                $subscriptionResultArray = CjwNewsletterSubscription::createSubscriptionByArray($subscriptionDataArr, CjwNewsletterUser::STATUS_PENDING, true, $context);
                $newNewsletterUser = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
                $mailSendResult = $newNewsletterUser->sendSubcriptionConfirmationMail();
                $tpl->setVariable('user_email_already_exists', false);
                $tpl->setVariable('mail_send_result', $mailSendResult);
                $tpl->setVariable('newsletter_user', $newNewsletterUser);
                $tpl->setVariable('subscription_result_array', $subscriptionResultArray);
                $tpl->setVariable('back_url_input', $backUrl);
                $templateFile = 'design:newsletter/subscribe_success.tpl';
            }
        }
    }
}
if ($user) {
    $tpl->setVariable('user', $user);
}
if (isset($existingNewsletterUserObject)) {
Пример #8
0
 /**
  * Mainfunction for mail send
  *
  * @param unknown_type $emailSender
  * @param unknown_type $emailSenderName
  * @param unknown_type $emailReceiver
  * @param unknown_type $emailReceiverName
  * @param unknown_type $emailSubject
  * @param unknown_type $emailBodyArray
  * @param boolean $isPreview
  * @param string $emailCharset
  * @return array
  */
 public function sendEmail($emailSender, $emailSenderName, $emailReceiver, $emailReceiverName, $emailSubject, $emailBodyArray, $isPreview = false, $emailCharset = 'utf-8', $emailReplyTo = false, $emailReturnPath = false)
 {
     $transportMethod = $this->transportMethod;
     //$mail = new ezcMailComposer();
     $mail = new CjwNewsletterMailComposer();
     // Encode the UTF-8 as base64 or QUOTED_PRINTABLE for 7 bit MTAs
     // $mail->encoding = ezcMail::BASE64;
     // $mail->encoding = ezcMail::QUOTED_PRINTABLE;
     $mail->encoding = $this->ContentTransferEncoding;
     $mail->charset = $emailCharset;
     $mail->subjectCharset = $emailCharset;
     // from and to addresses, and subject
     $mail->from = new ezcMailAddress(trim($emailSender), $emailSenderName, $mail->charset);
     // returnpath for email bounces
     if (!($emailReturnPath && $emailReturnPath != '')) {
         $mail->returnPath = $mail->from;
     } else {
         $mail->returnPath = new ezcMailAddress(trim($emailReturnPath), '', $mail->charset);
     }
     $mail->setHeader('Errors-To', $mail->returnPath);
     // reply-to
     if (!($emailReplyTo && $emailReplyTo != '')) {
         $mail->setHeader('Reply-To', $mail->from);
     } else {
         $mail->setHeader('Reply-To', new ezcMailAddress(trim($emailReplyTo), '', $mail->charset));
     }
     if ($isPreview) {
         $explodeReceiverArr = explode(';', $emailReceiver);
         foreach ($explodeReceiverArr as $index => $receiver) {
             // check if email
             if ($receiver != '') {
                 $mail->addTo(new ezcMailAddress(trim($receiver), 'NL Test Receiver' . $index, $mail->charset));
             }
         }
     } else {
         $mail->addTo(new ezcMailAddress(trim($emailReceiver), $emailReceiverName, $mail->charset));
     }
     if (array_key_exists('html', $emailBodyArray) == false) {
         $emailBodyArray['html'] = '';
     }
     if (array_key_exists('text', $emailBodyArray) == false) {
         $emailBodyArray['text'] = '';
     }
     $mail->subject = $emailSubject;
     if ($emailBodyArray['html'] == '') {
         // tue nix - da kein html da ist
     } else {
         $mail->htmlText = $emailBodyArray['html'];
     }
     // body: plain
     // $mail->plainText = "Here is the text version of the mail.";
     if ($emailBodyArray['text'] == '') {
         // $mail->plainText = "Text version of this mail does not exists.";
     } else {
         $mail->plainText = $emailBodyArray['text'];
     }
     $emailContentType = '';
     if ($emailBodyArray['html'] != '' && $emailBodyArray['text'] != '') {
         $emailContentType = 'multipart/alternative';
     } else {
         if ($emailBodyArray['html'] != '') {
             $emailContentType = 'text/html';
         } elseif ($emailBodyArray['text'] != '') {
             $emailContentType = 'text/plain';
         }
     }
     // http://ezcomponents.org/docs/api/latest/introduction_Mail.html#mta-qmail
     // HeaderLineEnding=auto
     // CRLF - windows - \r\n
     // CR - mac - \r
     // LF - UNIX-MACOSX - \n
     // default LF
     //ezcMailTools::setLineBreak( "\n" );
     ezcMailTools::setLineBreak($this->HeaderLineEnding);
     // set 'x-cjwnl-' mailheader
     foreach ($this->ExtraEmailHeaderItemArray as $key => $value) {
         $mail->setHeader($key, $value, $mail->charset);
     }
     $mail->build();
     $transport = new CjwNewsletterTransport($transportMethod);
     $sendResult = $transport->send($mail);
     $emailResult = array('send_result' => $sendResult, 'email_sender' => $emailSender, 'email_receiver' => $emailReceiver, 'email_subject' => $emailSubject, 'email_content_type' => $emailContentType, 'email_charset' => $emailCharset, 'transport_method' => $transportMethod);
     // ok
     if ($sendResult === true) {
         CjwNewsletterLog::writeInfo('email send ok', 'CjwNewsletterMail', 'sendEmail', $emailResult);
     } else {
         // An error occured while sending or receiving mail. RCPT TO failed with error: 450 4.1.2
         // <*****@*****.**>: Recipient address rejected: Domain not found
         // is string ' 450 ' included in emailResult
         $searchString = ' 450 ';
         $addErrorMessage = '';
         if (strpos($sendResult, $searchString) !== false) {
             // check if we found an email nl user for emailReceiver
             $nlUserToBounce = CjwNewsletterUser::fetchByEmail($emailReceiver);
             if (is_object($nlUserToBounce)) {
                 // hardbounce user
                 // alle active element will be aborted, too
                 $nlUserToBounce->setBounced(true);
                 $emailResult['nluser_id'] = $nlUserToBounce->attribute('id');
                 $addErrorMessage = ' - HARD BOUNCE (450)';
             } else {
                 $addErrorMessage = ' - NL User for email not found';
             }
         }
         CjwNewsletterLog::writeError('email send failed to ' . $emailReceiver . $addErrorMessage, 'CjwNewsletterMail', 'sendEmail', $emailResult);
     }
     // $LogFile->write( $message, $logName, $logFolder );
     return $emailResult;
 }