public function is_public() { $Lists = new PerchMailChimp_Lists($this->api); $List = $Lists->find((int) $this->listID()); if ($List) { if ($List->listPublic()) { return true; } } return false; }
public function import_next(PerchMailChimp_Import $Import) { $Lists = new PerchMailChimp_Lists($this->api); $List = $Lists->find($Import->importSourceID()); if (!is_object($List)) { return false; } $MailChimpAPI = $this->get_api_instance(); $listID = $List->listMailChimpID(); $webhooks = $MailChimpAPI->get("lists/{$listID}/webhooks", ['count' => $Import->importCount(), 'offset' => $Import->importOffset()]); if ($MailChimpAPI->success()) { if (isset($webhooks['webhooks']) && PerchUtil::count($webhooks['webhooks'])) { $all_webhooks = $webhooks['webhooks']; foreach ($all_webhooks as $webhook) { $data = $this->map_fields($webhook); $data['listID'] = $List->id(); if (!$this->remote_webhook_exists_locally($webhook['id'])) { $Webhook = $this->create($data); } else { // Webhook exists $Webhook = $this->get_one_by('webhookMailChimpID', $webhook['id']); if ($Webhook) { $Webhook->update($data); } } } // Return so that the cursor within the import is moved forward return ['result' => 'success', 'count' => PerchUtil::count($webhooks['webhooks']), 'message' => sprintf('Imported %d webhooks to list %s.', PerchUtil::count($webhooks['webhooks']), $List->listTitle())]; } else { return ['result' => 'success', 'count' => 0, 'message' => sprintf('Imported all webhooks to list %s.', $List->listTitle())]; } } else { PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error'); } return false; }
<?php $Lists = new PerchMailChimp_Lists($API); $edit_mode = false; $List = false; $list_id = false; $message = false; $details = false; if (PerchUtil::get('id')) { if (!$CurrentUser->has_priv('perch_mailchimp.lists.edit')) { PerchUtil::redirect($API->app_path()); } $list_id = PerchUtil::get('id'); $List = $Lists->find($list_id); $edit_mode = true; } else { if (!$CurrentUser->has_priv('perch_mailchimp.lists.create')) { PerchUtil::redirect($API->app_path()); } } // Template $Template = $API->get('Template'); $Template->set('mailchimp/lists/list.html', 'mailchimp'); $tags = $Template->find_all_tags_and_repeaters(); $Form = $API->get('Form'); $Form->handle_empty_block_generation($Template); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $data = $Form->get_posted_content($Template, $Lists, $List); if ($List) { $List->update($data);
public function import_next(PerchMailChimp_Import $Import) { $Lists = new PerchMailChimp_Lists($this->api); $List = $Lists->find($Import->importSourceID()); if (!is_object($List)) { return false; } $MailChimpAPI = $this->get_api_instance(); $listID = $List->listMailChimpID(); $members = $MailChimpAPI->get("lists/{$listID}/members", ['count' => $Import->importCount(), 'offset' => $Import->importOffset()]); if ($MailChimpAPI->success()) { if (isset($members['members']) && PerchUtil::count($members['members'])) { $Subscriptions = new PerchMailChimp_Subscriptions($this->api); $all_members = $members['members']; foreach ($all_members as $member) { $data = $this->map_fields($member); if (!$this->remote_subscriber_exists_locally($member['unique_email_id'])) { //PerchUtil::debug('Importing subscriber: '.$member['email_address']); $Subscriber = $this->create($data); } else { // subscriber exists $Subscriber = $this->get_one_by('subscriberMailChimpID', $member['unique_email_id']); $Subscriber->update($data); } if ($Subscriber) { // create subscription $Subscriptions->create_from_import($List, $Subscriber, $member); } } // Return so that the cursor within the import is moved forward return ['result' => 'success', 'count' => PerchUtil::count($members['members']), 'message' => sprintf('Imported %d subscribers to list %s.', PerchUtil::count($members['members']), $List->listTitle())]; } else { return ['result' => 'success', 'count' => 0, 'message' => sprintf('Imported all subscribers to list %s.', $List->listTitle())]; } } else { PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error'); } return false; }