Example #1
0
function wpcf7_cm_subscribe($obj)
{
    $cf7_cm = get_option('cf7_cm_' . $obj->id());
    $submission = WPCF7_Submission::get_instance();
    if ($cf7_cm) {
        $subscribe = false;
        $regex = '/\\[\\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\\s*\\]/';
        $callback = array(&$obj, 'cf7_cm_callback');
        $email = cf7_cm_tag_replace($regex, $cf7_cm['email'], $submission->get_posted_data());
        $name = cf7_cm_tag_replace($regex, $cf7_cm['name'], $submission->get_posted_data());
        $lists = cf7_cm_tag_replace($regex, $cf7_cm['list'], $submission->get_posted_data());
        $listarr = explode(',', $lists);
        if (isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0) {
            $accept = cf7_cm_tag_replace($regex, $cf7_cm['accept'], $submission->get_posted_data());
            if ($accept != $cf7_cm['accept']) {
                if (strlen($accept) > 0) {
                    $subscribe = true;
                }
            }
        } else {
            $subscribe = true;
        }
        for ($i = 1; $i <= 20; $i++) {
            if (isset($cf7_cm['CustomKey' . $i]) && isset($cf7_cm['CustomValue' . $i]) && strlen(trim($cf7_cm['CustomValue' . $i])) != 0) {
                $CustomFields[] = array('Key' => trim($cf7_cm['CustomKey' . $i]), 'Value' => cf7_cm_tag_replace($regex, trim($cf7_cm['CustomValue' . $i]), $submission->get_posted_data()));
            }
        }
        if (isset($cf7_cm['resubscribeoption']) && strlen($cf7_cm['resubscribeoption']) != 0) {
            $ResubscribeOption = true;
        } else {
            $ResubscribeOption = false;
        }
        if ($subscribe && $email != $cf7_cm['email']) {
            require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../api/csrest_subscribers.php';
            $wrap = new SPARTAN_CS_REST_Subscribers(trim($listarr[0]), $cf7_cm['api']);
            foreach ($listarr as $listid) {
                $wrap->set_list_id(trim($listid));
                $wrap->add(array('EmailAddress' => $email, 'Name' => $name, 'CustomFields' => $CustomFields, 'Resubscribe' => $ResubscribeOption));
            }
        }
    }
}
Example #2
0
function wpcf7_cm_subscribe($obj)
{
    $cf7_cm = get_option('cf7_cm_' . $obj->id());
    $submission = WPCF7_Submission::get_instance();
    $logfileEnabled = $cf7_cm['logfileEnabled'];
    $logfileEnabled = is_null($logfileEnabled) ? false : $logfileEnabled;
    if ($cf7_cm) {
        $subscribe = false;
        $regex = '/\\[\\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\\s*\\]/';
        $callback = array(&$obj, 'cf7_cm_callback');
        $email = cf7_cm_tag_replace($regex, $cf7_cm['email'], $submission->get_posted_data());
        $name = cf7_cm_tag_replace($regex, $cf7_cm['name'], $submission->get_posted_data());
        $lists = cf7_cm_tag_replace($regex, $cf7_cm['list'], $submission->get_posted_data());
        $listarr = explode(',', $lists);
        if (isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0) {
            $accept = cf7_cm_tag_replace($regex, $cf7_cm['accept'], $submission->get_posted_data());
            if ($accept != $cf7_cm['accept']) {
                if (strlen($accept) > 0) {
                    $subscribe = true;
                }
            }
        } else {
            $subscribe = true;
        }
        for ($i = 1; $i <= 20; $i++) {
            if (isset($cf7_cm['CustomKey' . $i]) && isset($cf7_cm['CustomValue' . $i]) && strlen(trim($cf7_cm['CustomValue' . $i])) != 0) {
                $CustomFields[] = array('Key' => trim($cf7_cm['CustomKey' . $i]), 'Value' => cf7_cm_tag_replace($regex, trim($cf7_cm['CustomValue' . $i]), $submission->get_posted_data()));
            }
        }
        if (isset($cf7_cm['resubscribeoption']) && strlen($cf7_cm['resubscribeoption']) != 0) {
            $ResubscribeOption = true;
        } else {
            $ResubscribeOption = false;
        }
        if ($subscribe && $email != $cf7_cm['email']) {
            try {
                require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../api/csrest_subscribers.php';
                $wrap = new SPARTAN_CS_REST_Subscribers(trim($listarr[0]), $cf7_cm['api']);
                foreach ($listarr as $listid) {
                    if (empty($CustomFields)) {
                        $CustomFields = array();
                    }
                    $wrap->set_list_id(trim($listid));
                    $result = $wrap->add(array('EmailAddress' => $email, 'Name' => $name, 'CustomFields' => $CustomFields, 'Resubscribe' => $ResubscribeOption));
                }
                // $resultsend = $result->response;
                // $resultfinal = $resultsend->Message;
                // $resultfinal = ( is_null( $resultfinal ) or trim( $resultfinal )==''   ) ? 'Email sent Ok' : $resultfinal;
                // $cme_debug_logger = new cme_Debug_Logger();
                // $cme_debug_logger->log_cme_debug( 'Email submission - Result: ' . $resultfinal ,1,$logfileEnabled );
            } catch (Exception $e) {
                //echo 'Error, check your error log file for details';
                $cme_debug_logger = new cme_Debug_Logger();
                $cme_debug_logger->log_cme_debug('Email submission - Result: ' . $e->getMessage(), 4, $logfileEnabled);
            }
        }
    }
}