Beispiel #1
0
 function run()
 {
     $this->setValues();
     $this->setIsOptOut($this->contactId, 0);
     $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $activityStatus = 'Completed';
     // Completed existing member
     if (!$this->isGroupContactAdded($this->contactId, $groupId)) {
         CRM_Speakcivi_Logic_Activity::join($this->contactId, 'confirmation_link', $this->campaignId);
         $this->setGroupContactAdded($this->contactId, $groupId);
         $activityStatus = 'optin';
         // Completed new member
     }
     if ($this->campaignId) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId);
         $locale = $campaign->getLanguage();
         $language = substr($locale, 0, 2);
         $this->setLanguageGroup($this->contactId, $language);
         $this->setLanguageTag($this->contactId, $language);
     }
     $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId);
     $this->setActivitiesStatuses($this->activityId, $aids, $activityStatus);
     $email = CRM_Speakcivi_Logic_Contact::getEmail($this->contactId);
     $speakcivi = new CRM_Speakcivi_Page_Speakcivi();
     $speakcivi->sendConfirm($email, $this->contactId, $this->activityId, $this->campaignId, false);
     $country = $this->getCountry($this->campaignId);
     $url = "{$country}/post_confirm";
     CRM_Utils_System::redirect($url);
 }
Beispiel #2
0
 function run()
 {
     $this->setActivityStatusIds();
     $this->setValues();
     $contactParams = array('is_opt_out' => 1);
     $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $location = '';
     if ($this->isGroupContactAdded($this->contactId, $groupId)) {
         $this->setGroupContactRemoved($this->contactId, $groupId);
         $location = 'removed from Members after optout link';
         if (CRM_Speakcivi_Cleanup_Leave::hasJoins($this->contactId)) {
             CRM_Speakcivi_Logic_Activity::leave($this->contactId, 'confirmation_link', $this->campaignId, $this->activityId, '', 'Added by SpeakCivi Optout');
         }
     }
     if ($this->campaignId) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId);
         $locale = $campaign->getLanguage();
         $language = substr($locale, 0, 2);
         $this->setLanguageTag($this->contactId, $language);
     }
     CRM_Speakcivi_Logic_Contact::set($this->contactId, $contactParams);
     $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId);
     $this->setActivitiesStatuses($this->activityId, $aids, 'optout', $location);
     $country = $this->getCountry($this->campaignId);
     $url = "{$country}/post_optout";
     CRM_Utils_System::redirect($url);
 }
Beispiel #3
0
 /**
  * Get country prefix based on campaign id.
  *
  * @param int $campaignId
  *
  * @return string
  */
 public function getCountry($campaignId)
 {
     $country = '';
     if ($campaignId > 0) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($campaignId);
         $language = $campaign->getLanguage();
         if ($language != '') {
             $tab = explode('_', $language);
             if (strlen($tab[0]) == 2) {
                 $country = '/' . $tab[0];
             }
         }
     }
     return $country;
 }
Beispiel #4
0
 function run()
 {
     $this->setValues();
     $this->setIsOptOut($this->contact_id, 0);
     $group_id = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $this->setGroupStatus($this->contact_id, $group_id);
     if ($this->campaign_id) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaign_id);
         $locale = $campaign->getLanguage();
         $language = substr($locale, 0, 2);
         $this->setLanguageGroup($this->contact_id, $language);
         $this->setLanguageTag($this->contact_id, $language);
     }
     $aids = $this->findActivitiesIds($this->activity_id, $this->campaign_id, $this->contact_id);
     $this->setActivitiesStatuses($this->activity_id, $aids, 'Completed');
     $country = $this->getCountry($this->campaign_id);
     $url = "{$country}/post_confirm";
     CRM_Utils_System::redirect($url);
 }
Beispiel #5
0
 function run()
 {
     $this->setValues();
     $this->setIsOptOut($this->contactId, 1);
     $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $location = '';
     if ($this->isGroupContactAdded($this->contactId, $groupId)) {
         $this->setGroupContactRemoved($this->contactId, $groupId);
         $location = 'removed from Members after optout link';
     }
     if ($this->campaignId) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId);
         $locale = $campaign->getLanguage();
         $language = substr($locale, 0, 2);
         $this->setLanguageGroup($this->contactId, $language);
         $this->setLanguageTag($this->contactId, $language);
     }
     $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId);
     $this->setActivitiesStatuses($this->activityId, $aids, 'optout', $location);
     $country = $this->getCountry($this->campaignId);
     $url = "{$country}/post_optout";
     CRM_Utils_System::redirect($url);
 }
Beispiel #6
0
 function run()
 {
     $this->setActivityStatusIds();
     $this->setValues();
     $contactParams = array('is_opt_out' => 0);
     $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $activityStatus = 'optin';
     // default status: Completed new member
     if (!$this->isGroupContactAdded($this->contactId, $groupId)) {
         if (!CRM_Speakcivi_Logic_Activity::hasJoin($this->activityId)) {
             CRM_Speakcivi_Logic_Activity::join($this->contactId, 'confirmation_link', $this->campaignId, $this->activityId);
         }
         $this->setGroupContactAdded($this->contactId, $groupId);
     } else {
         $activityStatus = 'Completed';
         // Completed existing member
     }
     if ($this->campaignId) {
         $campaign = new CRM_Speakcivi_Logic_Campaign($this->campaignId);
         $locale = $campaign->getLanguage();
         $language = substr($locale, 0, 2);
         $rlg = $this->setLanguageGroup($this->contactId, $language);
         $this->setLanguageTag($this->contactId, $language);
         if ($rlg == 1) {
             $contactParams['preferred_language'] = $locale;
         }
     }
     CRM_Speakcivi_Logic_Contact::set($this->contactId, $contactParams);
     $aids = $this->findActivitiesIds($this->activityId, $this->campaignId, $this->contactId);
     $this->setActivitiesStatuses($this->activityId, $aids, $activityStatus);
     $email = CRM_Speakcivi_Logic_Contact::getEmail($this->contactId);
     $speakcivi = new CRM_Speakcivi_Page_Speakcivi();
     $speakcivi->sendConfirm($email, $this->contactId, $this->activityId, $this->campaignId, false, 'new_member');
     $country = $this->getCountry($this->campaignId);
     $url = "{$country}/post_confirm";
     CRM_Utils_System::redirect($url);
 }
Beispiel #7
0
<?php

session_start();
$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();
$post = new CRM_Speakcivi_Page_Confirm();
$post->contactId = 100;
$post->campaignId = 8;
$campaign = new CRM_Speakcivi_Logic_Campaign($post->campaignId);
$locale = $campaign->getLanguage();
$language = substr($locale, 0, 2);
$post->setLanguageGroup($post->contactId, $language);
$post->setLanguageTag($post->contactId, $language);
echo "\n\n";
Beispiel #8
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);
}
Beispiel #9
0
session_start();
$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();
// tests:
$urlSpeakout = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'url_speakout');
echo '$urlSpeakout: ' . $urlSpeakout . "\n\n";
if ($urlSpeakout) {
    $campaignObj = new CRM_Speakcivi_Logic_Campaign();
    $param = (object) array('external_id' => 49);
    $campaign = $campaignObj->getCampaign($param->external_id);
    echo '$campaign GET: ';
    print_r($campaign);
    $campaign = $campaignObj->setCampaign($param->external_id, $campaign);
    echo '$campaign NEW: ';
    print_r($campaign);
    $campaignObj->customFields = $campaignObj->getCustomFields($campaign['id']);
    echo 'customFields: ';
    print_r($campaignObj->customFields);
}
Beispiel #10
0
function civicrm_api3_speakcivi_remind($params)
{
    // how old not confirmed petitions
    $start = microtime(true);
    $days = $params['days'];
    $daysContact = $params['days_contact'];
    if ($daysContact < $days) {
        $daysContact = $days;
    }
    $groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
    $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Petition', 'name', 'String', 'value');
    $adminId = 1;
    $query = "SELECT acp.activity_id, ap.campaign_id, acp.contact_id\n            FROM civicrm_activity ap\n              JOIN civicrm_activity_contact acp ON acp.activity_id = ap.id\n              JOIN civicrm_contact c ON c.id = acp.contact_id\n              LEFT JOIN civicrm_group_contact gc ON gc.contact_id = acp.contact_id AND gc.group_id = %1 AND gc.status = 'Added'\n            WHERE ap.activity_type_id = %2 AND ap.status_id = 1 AND ap.activity_date_time <= date_add(current_date, INTERVAL -%3 DAY)\n                AND c.created_date >= date_add(current_date, INTERVAL -%4 DAY)\n                AND c.is_opt_out = 0 AND c.is_deleted = 0 AND c.is_deceased = 0 AND c.do_not_email = 0 AND gc.id IS NULL";
    $params = array(1 => array($groupId, 'Integer'), 2 => array($activityTypeId, 'Integer'), 3 => array($days, 'Integer'), 4 => array($daysContact, 'Integer'));
    $dao = CRM_Core_DAO::executeQuery($query, $params);
    $contacts = array();
    $campaigns = array();
    while ($dao->fetch()) {
        $contacts[$dao->campaign_id][$dao->contact_id] = $dao->contact_id;
        $campaigns[$dao->campaign_id] = $dao->campaign_id;
    }
    $message = array();
    $subject = array();
    $utmCampaign = array();
    $locale = array();
    $language = array();
    $email = array();
    foreach ($campaigns as $cid) {
        $campaignObj = new CRM_Speakcivi_Logic_Campaign($cid);
        $message[$cid] = $campaignObj->getMessageNew();
        $subject[$cid] = substr(removeSmartyIfClause(convertTokens($campaignObj->getSubjectNew())), 0, 128);
        $utmCampaign[$cid] = $campaignObj->getUtmCampaign();
        $locale[$cid] = $campaignObj->getLanguage();
        $language[$cid] = strtoupper(substr($locale[$cid], 0, 2));
        $email[$cid] = parseSenderEmail($campaignObj->getSenderMail());
    }
    // fetch confirmation block
    $messageHtml = array();
    $messageText = array();
    foreach ($message as $cid => $msg) {
        $url_confirm_and_keep = CRM_Utils_System::url('civicrm/speakcivi/confirm', null, true) . "?id={contact.contact_id}&cid={$cid}&hash={speakcivi.confirmation_hash}&utm_source=civicrm&utm_medium=email&utm_campaign=" . $utmCampaign[$cid];
        $url_confirm_and_not_receive = CRM_Utils_System::url('civicrm/speakcivi/optout', null, true) . "?id={contact.contact_id}&cid={$cid}&hash={speakcivi.confirmation_hash}&utm_source=civicrm&utm_medium=email&utm_campaign=" . $utmCampaign[$cid];
        $locales = getLocale($locale[$cid]);
        $confirmationBlockHtml = implode('', file(dirname(__FILE__) . '/../../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['html'] . '.html.tpl'));
        $confirmationBlockText = implode('', file(dirname(__FILE__) . '/../../templates/CRM/Speakcivi/Page/ConfirmationBlock.' . $locales['text'] . '.text.tpl'));
        $confirmationBlockHtml = str_replace('{$url_confirm_and_keep}', $url_confirm_and_keep, $confirmationBlockHtml);
        $confirmationBlockHtml = str_replace('{$url_confirm_and_not_receive}', $url_confirm_and_not_receive, $confirmationBlockHtml);
        $confirmationBlockText = str_replace('{$url_confirm_and_keep}', $url_confirm_and_keep, $confirmationBlockText);
        $confirmationBlockText = str_replace('{$url_confirm_and_not_receive}', $url_confirm_and_not_receive, $confirmationBlockText);
        $messageHtml[$cid] = removeSmartyIfClause(convertTokens(removeDelim(str_replace("#CONFIRMATION_BLOCK", $confirmationBlockHtml, $msg))));
        $messageText[$cid] = convertHtmlToText(removeSmartyIfClause(convertTokens(removeDelim(str_replace("#CONFIRMATION_BLOCK", $confirmationBlockText, $msg)))));
    }
    foreach ($campaigns as $cid) {
        $sentContacts = findSentContacts($cid);
        $contacts[$cid] = excludeContacts($contacts[$cid], $sentContacts);
        if (is_array($contacts[$cid]) && count($contacts[$cid]) > 0) {
            if ($mailingId = findNotCompletedMailing($cid)) {
                if ($linkedGroupId = findLinkedGroup($mailingId)) {
                    addContactsToGroup($contacts[$cid], $linkedGroupId);
                } else {
                    $includeGroupId = createGroup($cid, $language[$cid]);
                    addContactsToGroup($contacts[$cid], $includeGroupId);
                    includeGroup($mailingId, $includeGroupId);
                }
            } else {
                $name = determineMailingName($cid, $language[$cid]);
                $params = array('name' => $name, 'subject' => $subject[$cid], 'body_text' => $messageText[$cid], 'body_html' => $messageHtml[$cid], 'created_id' => $adminId, 'created_date' => date('YmdHis'), 'campaign_id' => $cid, 'mailing_type' => 'standalone', 'unsubscribe_id' => 5, 'resubscribe_id' => 6, 'optout_id' => 7, 'reply_id' => 8, 'open_tracking' => 1, 'url_tracking' => 1, 'dedupe_email' => 1, 'from_name' => $email[$cid]['from_name'], 'from_email' => $email[$cid]['from_email'], 'footer_id' => chooseFooter($language[$cid]));
                $mailing = new CRM_Mailing_BAO_Mailing();
                $mm = $mailing->add($params);
                excludeGroup($mm->id, $groupId);
                if ($existingGroupId = findExistingGroup($cid)) {
                    cleanGroup($existingGroupId);
                    addContactsToGroup($contacts[$cid], $existingGroupId);
                    includeGroup($mm->id, $existingGroupId);
                } else {
                    $includeGroupId = createGroup($cid, $language[$cid]);
                    addContactsToGroup($contacts[$cid], $includeGroupId);
                    includeGroup($mm->id, $includeGroupId);
                }
            }
        }
    }
    $results = array('time' => microtime(true) - $start);
    return civicrm_api3_create_success($results, $params);
}