You are here

function cc::create_campaign in Constant Contact 6.2

Same name and namespace in other branches
  1. 6.3 class.cc.php \cc::create_campaign()
  2. 7.3 class.cc.php \cc::create_campaign()

* Creates a new campaign * * @access public

File

./class.cc.php, line 1139

Class

cc
@file

Code

function create_campaign($title, $email_subject, $email_html, $email_text, $contact_lists = array(), $options = array(), $content_type = 'HTML') {
  $dynamic_fields = array(
    'GreetingSalutation',
    'GreetingName',
    'GreetingString',
    'OrganizationName',
    'OrganizationAddress1',
    'OrganizationAddress2',
    'OrganizationAddress3',
    'OrganizationCity',
    'OrganizationInternationalState',
    'OrganizationCountry',
    'OrganizationPostalCode',
    'StyleSheet',
  );

  // build the XML post data
  $xml_post = '
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/' . $this->api_username . '/campaigns" />
  <id>' . $this
    ->get_http_api_url() . 'campaigns</id>
  <title type="text">' . $title . '</title>
  <updated>2009-10-28T14:11:40.881Z</updated>
  <author/>
  <content type="application/vnd.ctct+xml">
    <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="' . $this
    ->get_http_api_url() . 'campaigns">
      <Name>' . $title . '</Name>
      <Status>Draft</Status>
      <Date>2009-10-28T14:11:40.881Z</Date>
      <Subject>' . $email_subject . '</Subject>
	  ';
  if (isset($options['ViewAsWebpage'])) {
    $xml_post .= '
			<ViewAsWebpage>YES</ViewAsWebpage>
			<ViewAsWebpageLinkText>' . $options['ViewAsWebpageLinkText'] . '</ViewAsWebpageLinkText>
			<ViewAsWebpageText>' . $options['ViewAsWebpageLinkText'] . '</ViewAsWebpageText>
			';
  }
  if (isset($options['PermissionReminder'])) {
    $xml_post .= '
			<PermissionReminder>YES</PermissionReminder>
			<PermissionReminderText>' . $options['PermissionReminderText'] . '</PermissionReminderText>
			';
  }
  if (isset($options['IncludeForwardEmail'])) {
    $xml_post .= '
			<IncludeForwardEmail>YES</IncludeForwardEmail>
			<ForwardEmailLinkText>' . $options['ForwardEmailLinkText'] . '</ForwardEmailLinkText>
			';
  }
  if (isset($options['IncludeSubscribeLink'])) {
    $xml_post .= '
			<IncludeSubscribeLink>YES</IncludeSubscribeLink>
			<SubscribeLinkText>' . $options['SubscribeLinkText'] . '</SubscribeLinkText>
			';
  }
  foreach ($dynamic_fields as $field) {
    if (isset($options[$field])) {
      $xml_post .= "<{$field}>{$options[$field]}</{$field}>";
    }
  }
  $xml_post .= '
			<EmailContentFormat>' . $content_type . '</EmailContentFormat>
			<EmailContent>' . htmlentities($email_html) . '</EmailContent>
			<EmailTextContent>' . htmlentities($email_text) . '</EmailTextContent>
		';
  if (is_array($contact_lists)) {
    $xml_post .= '<ContactLists>';
    foreach ($contact_lists as $id) {
      $xml_post .= '
				<ContactList id="' . $this
        ->get_list_url($id) . '">
				<link xmlns="http://www.w3.org/2005/Atom" href="' . $this
        ->get_list_url($id, 0) . '" rel="self" />
				</ContactList>
			  ';
    }
    $xml_post .= '</ContactLists>';
  }
  if (isset($options['FromName'])) {
    $xml_post .= '<FromName>' . $options['FromName'] . '</FromName>';
  }
  if (isset($options['EmailAddress'], $options['EmailID'])) {
    $xml_post .= '
			<FromEmail>
			<Email id="' . $this
      ->get_http_api_url() . 'settings/emailaddresses/' . $options['EmailID'] . '">
			<link xmlns="http://www.w3.org/2005/Atom" href="' . $this->api_uri . 'settings/emailaddresses/' . $options['EmailID'] . '" rel="self" />
			</Email>
			<EmailAddress>' . $options['EmailAddress'] . '</EmailAddress>
			</FromEmail>
			<ReplyToEmail>
			<Email id="' . $this
      ->get_http_api_url() . 'settings/emailaddresses/' . $options['EmailID'] . '">
			<link xmlns="http://www.w3.org/2005/Atom" href="' . $this->api_uri . 'settings/emailaddresses/' . $options['EmailID'] . '" rel="self" />
			</Email>
			<EmailAddress>' . $options['EmailAddress'] . '</EmailAddress>
			</ReplyToEmail>
			';
  }
  $xml_post .= '</Campaign></content></entry>';
  $this
    ->http_set_content_type('application/atom+xml');
  $xml = $this
    ->load_url("campaigns", 'post', $xml_post, 201);
  if (isset($this->http_response_headers['Location']) && trim($this->http_response_headers['Location']) != '') {
    return $this
      ->get_id_from_link($this->http_response_headers['Location']);
  }
  return false;
}