public function run()
 {
     $result = false;
     switch ($this->importType()) {
         case 'subscribers':
             $Subscribers = new PerchMailChimp_Subscribers($this->api);
             $result = $Subscribers->import_next($this);
             break;
         case 'campaigns':
             $Campaigns = new PerchMailChimp_Campaigns($this->api);
             $result = $Campaigns->import_next($this);
             break;
         case 'webhooks':
             $Webhooks = new PerchMailChimp_Webhooks($this->api);
             $result = $Webhooks->import_next($this);
             break;
     }
     if ($result && $result['result'] == 'success') {
         if ($result['count'] < $this->importCount()) {
             // looks like that's all the pages, so self-delete.
             PerchUtil::debug('Result count is ' . $result['count']);
             PerchUtil::debug('Import count is ' . $this->importCount());
             PerchUtil::debug('Deleting.');
             $this->delete();
             return;
         }
         $this->update(['importOffset' => $this->importOffset() + $this->importCount()]);
         return $result;
     }
     return $result;
 }
Esempio n. 2
0
function perch_mailchimp_form_handler($SubmittedForm)
{
    if ($SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_mailchimp');
        $Subscribers = new PerchMailChimp_Subscribers($API);
        $Subscribers->subscribe_from_form($SubmittedForm);
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
Esempio n. 3
0
<?php

$Form = $API->get('Form');
$Paging = $API->get('Paging');
$Paging->set_per_page(20);
$Lists = new PerchMailChimp_Lists($API);
$lists = $Lists->all();
$Subscribers = new PerchMailChimp_Subscribers($API);
// Run an import if there is one
$Imports = new PerchMailChimp_Imports($API);
$Import = $Imports->get_next_import('subscribers');
if (is_object($Import)) {
    $message = $HTML->warning_message('Subscribers are still updating.');
    $Import->run();
} else {
    if ($Form->submitted()) {
        foreach ($lists as $List) {
            $Subscribers->import($List);
        }
    }
}
$subscribers = $Subscribers->all_subscribed($Paging);
if (!PerchUtil::count($subscribers)) {
    foreach ($lists as $List) {
        $Subscribers->import($List);
    }
    $subscribers = $Subscribers->all_subscribed($Paging);
}
Esempio n. 4
0
<?php

$API = new PerchAPI(1.0, 'perch_mailchimp');
$Lang = $API->get('Lang');
// check privs
if ($CurrentUser->has_priv('perch_mailchimp')) {
    $Settings = $API->get('Settings');
    $api_key = $Settings->get('perch_mailchimp_api_key')->val();
    $Lists = new PerchMailChimp_Lists($API);
    $Subscribers = new PerchMailChimp_Subscribers($API);
    $lists = [];
    $msg = false;
    if (!$api_key || $api_key == '') {
        //need to set these
        $msg = '<p class="bd helptext"><a href="' . PERCH_LOGINPATH . '/core/settings/">' . $Lang->get('You must set your Mailchimp API Key in Settings.') . '</a></p>';
    } else {
        $lists = $Lists->all();
    }
    ?>

	<div class="widget">
		<h2><?php 
    echo $Lang->get('MailChimp');
    ?>
</h2>
		<div class="">
			<?php 
    if ($msg) {
        echo $msg;
    } else {
        if (PerchUtil::count($lists)) {
Esempio n. 5
0
<?php

use DrewM\MailChimp\Webhook as MailChimpWebhook;
include __DIR__ . '/../../env_runtime.php';
$API = new PerchAPI(1.0, 'perch_mailchimp');
$Settings = $API->get('Settings');
$secret = $Settings->get('perch_mailchimp_secret')->val();
if ($secret != perch_get('secret')) {
    die('Unauthorised.');
}
$Subscribers = new PerchMailChimp_Subscribers($API);
MailChimpWebhook::subscribe('subscribe', function ($data) use($API, $Subscribers) {
    $Subscriber = $Subscribers->get_one_by('subscriberMailChimpID', $data['id']);
    if (!$Subscriber) {
        $Subscriber = $Subscribers->lookup_and_create($data);
    }
    if ($Subscriber) {
        $Subscriber->update_subscription($data['list_id'], 'subscribe');
    }
    $Lists = new PerchMailChimp_Lists($API);
    $Lists->import();
});
MailChimpWebhook::subscribe('unsubscribe', function ($data) use($API, $Subscribers) {
    $Subscriber = $Subscribers->get_one_by('subscriberMailChimpID', $data['id']);
    if ($Subscriber) {
        $Subscriber->update_subscription($data['list_id'], 'unsubscribed');
    }
    $Lists = new PerchMailChimp_Lists($API);
    $Lists->import();
});
MailChimpWebhook::subscribe('cleaned', function ($data) use($API, $Subscribers) {