/** * @param string $listId * @param string $emailAddress * @param array $mergeFields * @param bool|false $confirm * @return bool */ public function subscribe(string $listId, string $emailAddress, array $mergeFields = [], bool $confirm = false) { // Check the list exists if (!$this->checkListExists($listId)) { if ($this->error) { return false; // callApi() error } return $this->errorResponse('Subscribe called on list that does not exist: ' . $listId); } // Check address is valid for subscription $status = $this->checkStatus($listId, $emailAddress); if (in_array($status, ['subscribed', 'pending', 'cleaned'])) { $this->logger->warning("Attempt to subscribe {$emailAddress} to list#{$listId}, already on the list and marked {$status} - no action taken"); return true; } // Add/update the subscriber - PUT does both $id = md5(strtolower($emailAddress)); $endpoint = "lists/{$listId}/members/{$id}"; $status = $confirm ? 'pending' : 'subscribed'; $data = ['email_address' => $emailAddress, 'status' => $status]; if (!empty($mergeFields)) { $data['merge_fields'] = $mergeFields; } $response = $this->callApi('put', $endpoint, $data); if (!$response) { return false; } if (empty($response['status']) || !in_array($response['status'], ['subscribed', 'pending'])) { return $this->errorResponse('Subscribe received unexpected response:' . json_encode($response)); } return true; }
function loger($level, $file, $line, $string, $ar = NULL) { // если системный level ниже notice, то при включеном KINT_DUMP, ставим уровень notice if ($GLOBALS['KINT_DUMP'] && $this->agiconfig['verbosity_level'] < 2) { $this->agiconfig['verbosity_level'] = 2; } if ($this->agiconfig['verbosity_level'] < $level) { return; } if ($GLOBALS['KINT_DUMP']) { ~d("{$level} | {$file} | {$line}"); if (!is_null($string)) { d($string); } if (!is_null($ar)) { d($ar); } return; } if (!is_null($string)) { $this->agi->verbose($string); } if (!is_null($ar)) { $this->agi->verbose($ar); } if ((int) $this->agiconfig['logging_write_file'] === 1) { $logger = new Writer(new Logger('local')); $logger->useFiles($this->config['logs_patch']); if (!is_null($ar)) { $string .= "\n"; $string .= var_export($string, true); } switch ($level) { case 'error': $logger->error("[" . $this->uniqueid . "] [{$file}] [{$line}]: -- {$string}"); break; case 'warning': $logger->warning("[" . $this->uniqueid . "] [{$file}] [{$line}]: -- {$string}"); break; case 'notice': $logger->notice("[" . $this->uniqueid . "] [{$file}] [{$line}]: -- {$string}"); break; case 'info': $logger->info("[" . $this->uniqueid . "] [{$file}] [{$line}]: {$string}"); break; default: $logger->debug("[" . $this->uniqueid . "] [{$file}] [{$line}]: {$string}"); break; } } }