public function CampaignMonitor::getSubscriber in Campaign Monitor 7
Get values entered by the subscriber.
Parameters
string $list_id: The unique Campaign Monitor list ID.
string $email: The e-mail address that identifies the subscriber.
Return value
array|bool An array containing subscriber information or FALSE on failure.
1 call to CampaignMonitor::getSubscriber()
- CampaignMonitor::isSubscribed in lib/
campaignmonitor.class.inc - Check if a given user, identified by e-mail address, is subscribed.
File
- lib/
campaignmonitor.class.inc, line 793 - Implementation of the CampaignMonitor class.
Class
- CampaignMonitor
- Implementation of the CampaignMonitor class.
Code
public function getSubscriber($list_id, $email) {
$fetch = FALSE;
if (!isset($this->subscribers[$list_id . $email])) {
// Not found inside object, try the cache.
if (($cache = cache_get('campaignmonitor_subscribers')) && !empty($cache->data)) {
// Cache information found.
$this->subscribers = $cache->data;
if (!isset($this->subscribers[$list_id . $email])) {
// Not found inside cache either.
$fetch = TRUE;
}
}
else {
// No cache found or expired.
$fetch = TRUE;
}
}
if ($fetch) {
if ($obj = $this
->createSubscriberObj($list_id)) {
$this->subscribers[$list_id . $email] = [];
$result = $obj
->get($email);
if ($result
->was_successful()) {
foreach ($result->response as $key => $value) {
if ($key == 'CustomFields') {
// Convert the custom fields object into a keyed array.
$this->subscribers[$list_id . $email][$key] = [];
foreach ($value as $field) {
// Check if the field has been set. If not, set the value.
if (!isset($this->subscribers[$list_id . $email][$key][$field->Key])) {
$this->subscribers[$list_id . $email][$key][$field->Key] = $field->Value;
}
elseif (!is_array($this->subscribers[$list_id . $email][$key][$field->Key])) {
// If the field is not an array, assign an array to the
// field, containing the previous value of the field and
// this new value.
$this->subscribers[$list_id . $email][$key][$field->Key] = [
$this->subscribers[$list_id . $email][$key][$field->Key],
$field->Value,
];
}
else {
$this->subscribers[$list_id . $email][$key][$field->Key][] = $field->Value;
}
}
}
else {
$this->subscribers[$list_id . $email][$key] = $value;
}
}
// Save the subscriber information in the cache.
cache_set('campaignmonitor_subscribers', $this->subscribers, 'cache', $this
->getCacheTimeout());
}
else {
$this
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
return [];
}
}
else {
return FALSE;
}
}
return $this->subscribers[$list_id . $email];
}