Ejemplo n.º 1
0
if ($listids[0] !== '') {
    $campaign['ListIDs'] = $listids;
}
if ($segmentids[0] !== '') {
    $campaign['SegmentIDs'] = $segmentids;
}
$content = $modx->getOption('content', $_POST, '');
$content = str_replace('<p> </p>', '<br/>', $content);
// CM doesn't like that non breaking space TinyMCE adds between the p tags
$cm = new CMHandler($modx);
$fileId = $cm->setCampaignFiles($content);
if (!$fileId) {
    return $modx->error->failure('Problem saving cache file');
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . $modx->getOption('cmx.assets_url') . 'cache/';
$campaign['TextUrl'] = $url . $fileId . '.txt';
$campaign['HtmlUrl'] = $url . $fileId . '.html';
FB::log($campaign);
$results = $cm->createCampaign($campaign);
$cm->removeCampaignFiles($fileId);
if ($results->http_status_code == 201) {
    // grab campaign ID
    $campaignID = $results->response;
    FB::log($campaignID);
    // save a copy of everything in cache since we can't get this through the API
    $campaign['Content'] = $content;
    $cm->setCampaignCache($campaignID, $campaign);
    return $modx->error->success('', $results);
} else {
    return $modx->error->failure('Campaign Monitor rejected the campaign: ' . $results->response->Message);
}