예제 #1
0
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);
}
예제 #2
0
 /**
  * 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;
     }
 }