You are here

function cc::get_contacts in Constant Contact 7.3

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

Gets all contacts and allows paging of the results.

@access public

File

./class.cc.php, line 799
Constant Contact PHP Class

Class

cc
@file Constant Contact PHP Class

Code

function get_contacts($action = 'contacts') {
  $xml = $this
    ->load_url($action);
  if (!$xml) {
    return FALSE;
  }

  // Parse into nicer array.
  $contacts = array();
  $_contacts = isset($xml['feed']['entry']) ? $xml['feed']['entry'] : FALSE;
  if (isset($xml['feed']['link']['2_attr']['rel'], $xml['feed']['link']['3_attr']['href']) && $xml['feed']['link']['2_attr']['rel'] == 'first') {
    $this->contact_meta_data->first_page = $this
      ->get_id_from_link($xml['feed']['link']['2_attr']['href']);
    $this->contact_meta_data->current_page = $this
      ->get_id_from_link($xml['feed']['link']['3_attr']['href']);
    $this->contact_meta_data->next_page = '';
  }
  elseif (isset($xml['feed']['link']['2_attr']['rel'], $xml['feed']['link']['3_attr']['href'], $xml['feed']['link']['4_attr']['href']) && $xml['feed']['link']['2_attr']['rel'] == 'next') {
    $this->contact_meta_data->next_page = $this
      ->get_id_from_link($xml['feed']['link']['2_attr']['href']);
    $this->contact_meta_data->current_page = $this
      ->get_id_from_link($xml['feed']['link']['3_attr']['href']);
    $this->contact_meta_data->first_page = $this
      ->get_id_from_link($xml['feed']['link']['4_attr']['href']);
  }
  else {
    $this->contact_meta_data->next_page = NULL;
    $this->contact_meta_data->current_page = NULL;
    $this->contact_meta_data->first_page = NULL;
  }
  if (is_array($_contacts)) {
    if (isset($_contacts[0]['link_attr']['href'])) {
      foreach ($_contacts as $k => $v) {
        $id = $this
          ->get_id_from_link($v['link_attr']['href']);
        $contact = $v['content']['Contact'];
        $contact['id'] = $id;
        $contacts[] = $contact;
      }
    }
    else {
      $id = $this
        ->get_id_from_link($_contacts['link_attr']['href']);
      $contact = $_contacts['content']['Contact'];
      $contact['id'] = $id;
      $contacts[] = $contact;
    }
  }
  return $contacts;
}