function civicrm_api3_speakcivi_sendconfirm($params) { $confirmationBlock = $params['confirmation_block']; $contactId = $params['contact_id']; $campaignId = $params['campaign_id']; $activityId = $params['activity_id']; $campaignObj = new CRM_Speakcivi_Logic_Campaign($campaignId); $locale = $campaignObj->getLanguage(); $params['from'] = $campaignObj->getSenderMail(); $params['format'] = null; if ($confirmationBlock) { $params['subject'] = $campaignObj->getSubjectNew(); $message = $campaignObj->getMessageNew(); } else { $params['subject'] = $campaignObj->getSubjectCurrent(); $message = $campaignObj->getMessageCurrent(); } if (!$message) { if ($confirmationBlock) { $message = CRM_Speakcivi_Tools_Dictionary::getMessageNew($locale); $campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageNew, $message); } else { $message = CRM_Speakcivi_Tools_Dictionary::getMessageCurrent($locale); $campaignObj->setCustomFieldBySQL($campaignId, $campaignObj->fieldMessageCurrent, $message); } } $contact = array(); $params_contact = array('id' => $contactId, 'sequential' => 1); $result = civicrm_api3('Contact', 'get', $params_contact); if ($result['count'] == 1) { $contact = $result['values'][0]; } /* CONFIRMATION_BLOCK */ $hash = sha1(CIVICRM_SITE_KEY . $contactId); $utm_content = 'version_' . $contactId % 2; $utm_campaign = $campaignObj->getUtmCampaign(); $url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true); $url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', "id={$contactId}&aid={$activityId}&cid={$campaignId}&hash={$hash}&utm_source=civicrm&utm_medium=email&utm_campaign={$utm_campaign}&utm_content={$utm_content}", true); $template = CRM_Core_Smarty::singleton(); $template->assign('url_confirm_and_keep', $url_confirm_and_keep); $template->assign('url_confirm_and_not_receive', $url_confirm_and_not_receive); $locales = getLocale($locale); $confirmation_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['html'] . '.html.tpl'); $confirmation_block_text = $template->fetch('../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['text'] . '.text.tpl'); /* SHARING_BLOCK */ $template->clearTemplateVars(); $template->assign('url_campaign', $campaignObj->getUrlCampaign()); $template->assign('url_campaign_fb', prepareCleanUrl($campaignObj->getUrlCampaign())); $template->assign('utm_campaign', $campaignObj->getUtmCampaign()); $template->assign('share_facebook', CRM_Speakcivi_Tools_Dictionary::getShareFacebook($locale)); $template->assign('share_twitter', CRM_Speakcivi_Tools_Dictionary::getShareTwitter($locale)); $template->assign('twitter_share_text', urlencode($campaignObj->getTwitterShareText())); $sharing_block_html = $template->fetch('../templates/CRM/Speakcivi/Page/SharingBlock.html.tpl'); $template->clearTemplateVars(); $template->assign('contact', $contact); $message = $template->fetch('string:' . $message); $message_html = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_html), $message); $message_text = str_replace("#CONFIRMATION_BLOCK", html_entity_decode($confirmation_block_text), $message); $message_html = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_html); $message_text = str_replace("#SHARING_BLOCK", html_entity_decode($sharing_block_html), $message_text); $params['html'] = $message_html; $params['text'] = convertHtmlToText($message_text); $sent = CRM_Utils_Mail::send($params); return civicrm_api3_create_success($sent, $params); }
/** * Setting up new campaign in CiviCRM if this is necessary. * * @param $externalIdentifier * @param $campaign * * @return array * @throws CiviCRM_API3_Exception */ public function setCampaign($externalIdentifier, $campaign) { if (!$this->isValidCampaign($campaign)) { if ($externalIdentifier > 0) { $this->urlSpeakout = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'url_speakout'); $externalCampaign = (object) json_decode(@file_get_contents("https://" . $this->urlSpeakout . "/{$externalIdentifier}.json")); if (is_object($externalCampaign) && property_exists($externalCampaign, 'name') && $externalCampaign->name != '' && property_exists($externalCampaign, 'id') && $externalCampaign->id > 0) { $this->defaultCampaignTypeId = CRM_Core_OptionGroup::getValue('campaign_type', 'Petitions', 'name', 'String', 'value'); $this->from = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'from'); $locale = $this->determineLanguage($externalCampaign->internal_name); $utmCampaign = $externalCampaign->slug != '' ? $externalCampaign->slug : 'speakout_' . $externalCampaign->id; $params = array('sequential' => 1, 'title' => $externalCampaign->name, 'external_identifier' => $externalCampaign->id, 'campaign_type_id' => $this->defaultCampaignTypeId, 'start_date' => date('Y-m-d H:i:s'), $this->fieldLanguage => $this->determineLanguage($externalCampaign->internal_name), $this->fieldSenderMail => $this->from, $this->fieldUrlCampaign => "https://" . $this->urlSpeakout . "/" . $utmCampaign, $this->fieldUtmCampaign => $utmCampaign, $this->fieldTwitterShareText => $externalCampaign->twitter_share_text, $this->fieldSubjectNew => CRM_Speakcivi_Tools_Dictionary::getSubjectConfirm($locale), $this->fieldSubjectCurrent => CRM_Speakcivi_Tools_Dictionary::getSubjectImpact($locale)); $result = civicrm_api3('Campaign', 'create', $params); if ($result['count'] == 1) { $this->setCustomFieldBySQL($result['id'], $this->fieldMessageNew, CRM_Speakcivi_Tools_Dictionary::getMessageNew($locale)); $this->setCustomFieldBySQL($result['id'], $this->fieldMessageCurrent, CRM_Speakcivi_Tools_Dictionary::getMessageCurrent($locale)); return $result['values'][0]; } } } return array(); } else { return $campaign; } }
/** * Preparing params for API Contact.create based on retrieved result. * @param array $param * @param array $contact * @param array $result * @param int $basedOnContactId * * @return mixed */ function prepareParamsContact($param, $contact, $result, $basedOnContactId = 0) { $h = $param->cons_hash; $optInMapGroupStatus = array(0 => 'Added', 1 => 'Pending'); unset($contact['return']); unset($contact[$this->apiAddressGet]); unset($contact[$this->apiGroupContactGet]); $existingContact = array(); if ($basedOnContactId > 0) { foreach ($result['values'] as $id => $res) { if ($res['id'] == $basedOnContactId) { $existingContact = $res; break; } } } if (is_array($existingContact) && count($existingContact) > 0) { $contact['id'] = $existingContact['id']; if ($existingContact['first_name'] == '') { $contact['first_name'] = $h->firstname; } if ($existingContact['last_name'] == '') { $contact['last_name'] = $h->lastname; } $contact = $this->prepareParamsAddress($contact, $existingContact); if ($existingContact[$this->apiGroupContactGet]['count'] == 0) { $contact[$this->apiGroupContactCreate] = array('group_id' => $this->groupId, 'contact_id' => '$value.id', 'status' => $optInMapGroupStatus[$this->optIn]); } } else { $genderId = $this->getGenderId($h->lastname); $genderShortcut = $this->getGenderShortcut($h->lastname); $lastname = $this->cleanLastname($h->lastname); $contact['first_name'] = $h->firstname; $contact['last_name'] = $lastname; $contact['gender_id'] = $genderId; $contact['prefix_id'] = CRM_Speakcivi_Tools_Dictionary::getPrefix($genderShortcut); $dict = new CRM_Speakcivi_Tools_Dictionary(); $dict->parseGroupEmailGreeting(); $emailGreetingId = $dict->getEmailGreetingId($this->locale, $genderShortcut); if ($emailGreetingId) { $contact['email_greeting_id'] = $emailGreetingId; } $contact['preferred_language'] = $this->locale; $contact['source'] = 'speakout ' . $param->action_type . ' ' . $param->external_id; $contact = $this->prepareParamsAddressDefault($contact); $contact[$this->apiGroupContactCreate] = array('group_id' => $this->groupId, 'contact_id' => '$value.id', 'status' => $optInMapGroupStatus[$this->optIn]); } return $contact; }
$settingsFile = trim(implode('', file('path.inc'))) . '/civicrm.settings.php'; define('CIVICRM_SETTINGS_PATH', $settingsFile); $error = @(include_once $settingsFile); if ($error == false) { echo "Could not load the settings file at: {$settingsFile}\n"; exit; } // Load class loader global $civicrm_root; require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; CRM_Core_ClassLoader::singleton()->register(); require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); CRM_Core_OptionGroup::getAssoc('email_greeting', $group, false, 'name'); print_r($group); $dict = new CRM_Speakcivi_Tools_Dictionary(); $dict->parseGroupEmailGreeting(); print_r($dict->emailGreetingIds); $locales = array('fr_FR:', 'fr_FR:F', 'fr_FR:M', 'de_DE:', 'de_DE:M', 'de_DE:FG'); foreach ($locales as $loc) { echo $loc . ' -> ' . print_r($dict->parseLocaleGenderShortcut($loc), true) . "\n"; } echo $dict->getEmailGreetingId('fr_FR', '') . "\n"; echo $dict->getEmailGreetingId('fr_FR', 'F') . "\n"; echo $dict->getEmailGreetingId('fr_FR', 'M') . "\n"; echo $dict->getEmailGreetingId('de_DE', '') . "\n"; echo $dict->getEmailGreetingId('de_DE', 'F') . "\n"; echo $dict->getEmailGreetingId('de_DE', 'M') . "\n"; echo $dict->getEmailGreetingId('es_ES', '') . "\n"; echo $dict->getEmailGreetingId('es_ES', 'F') . "\n"; echo $dict->getEmailGreetingId('es_ES', 'M') . "\n";