/** * Function for validation * * @param array $params (ref.) an assoc array of name/value pairs * * @return mixed true or array of errors * @access public * @static */ function dataRule(&$params, &$files, &$options) { if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) { return true; } $errors = array(); require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getCurrentDomain(); $mailing = null; $session =& CRM_Core_Session::singleton(); $values = array('contact_id' => $session->get('userID')); $contact = array(); $ids = array(); CRM_Contact_BAO_Contact::retrieve($values, $contact, $id); $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'owner')); foreach ($verp as $key => $value) { $verp[$key]++; } $urls = array_flip(array('forward')); foreach ($urls as $key => $value) { $urls[$key]++; } require_once 'CRM/Mailing/BAO/Component.php'; $header =& new CRM_Mailing_BAO_Component(); $header->id = $params['header_id']; $header->find(true); $footer =& new CRM_Mailing_BAO_Component(); $footer->id = $params['footer_id']; $footer->find(true); list($headerBody['htmlFile'], $headerBody['textFile']) = array($header->body_html, $header->body_text); list($footerBody['htmlFile'], $footerBody['textFile']) = array($footer->body_html, $footer->body_text); require_once 'CRM/Utils/Token.php'; if (!file_exists($files['textFile']['tmp_name'])) { $errors['textFile'] = ts('Please provide at least the text message.'); } foreach (array('textFile', 'htmlFile') as $file) { if (!file_exists($files[$file]['tmp_name'])) { continue; } $str = file_get_contents($files[$file]['tmp_name']); $name = $files[$file]['name']; /* append header/footer */ $str = $headerBody[$file] . $str . $footerBody[$file]; $dataErrors = array(); /* First look for missing tokens */ $err = CRM_Utils_Token::requiredTokens($str); if ($err !== true) { foreach ($err as $token => $desc) { $dataErrors[] = '<li>' . ts('Missing required token') . ' {' . $token . "}: {$desc}</li>"; } } /* Do a full token replacement on a dummy verp, the current contact * and domain. */ $str = CRM_Utils_Token::replaceDomainTokens($str, $domain); $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing); $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls); $str = CRM_Utils_Token::replaceContactTokens($str, $contact); $unmatched = CRM_Utils_Token::unmatchedTokens($str); if (!empty($unmatched)) { foreach ($unmatched as $token) { $dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>'; } } if (!empty($dataErrors)) { $errors[$file] = ts('The following errors were detected in %1:', array(1 => $name)) . ': <ul>' . implode('', $dataErrors) . '</ul>'; } } return empty($errors) ? true : $errors; }
/** * Ask a contact for subscription confirmation (opt-in) * * @param string $email The email address * @return void * @access public */ function send_confirm_request($email) { $config =& CRM_Core_Config::singleton(); require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getCurrentDomain(); require_once 'CRM/Utils/Verp.php'; $confirm = CRM_Utils_Verp::encode(implode($config->verpSeparator, array('confirm', $this->contact_id, $this->id, $this->hash)) . "@{$domain->email_domain}", $email); require_once 'CRM/Contact/BAO/Group.php'; $group =& new CRM_Contact_BAO_Group(); $group->id = $this->group_id; $group->find(true); require_once 'CRM/Mailing/BAO/Component.php'; $component =& new CRM_Mailing_BAO_Component(); $component->domain_id = $domain->id; $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Subscribe'; $component->find(true); $headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <do-not-reply@%2>', array(1 => $domain->name, 2 => $domain->email_domain)), 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$domain->email_domain}"); $html = $component->body_html; require_once 'CRM/Utils/Token.php'; $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true); $html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->name, true); $text = $component->body_text; $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false); $text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->name, false); $message =& new Mail_Mime("\n"); $message->setHTMLBody($html); $message->setTxtBody($text); $b = $message->get(); $h = $message->headers($headers); $mailer =& $config->getMailer(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP')); $mailer->send($email, $h, $b); CRM_Core_Error::setCallback(); }