Ejemplo n.º 1
0
$listids = $modx->getOption('lists', $_POST, array(''));
$segmentids = $modx->getOption('segments', $_POST, array(''));
if ($listids[0] === '' && $segmentids[0] === '') {
    return $modx->error->failure('Select a list or segment for this campaign');
}
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;