Example #1
0
 public static function handleRedirectReturn($data = false)
 {
     if (isset($data['error'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         $connections = CASHSystem::getSystemSettings('system_connections');
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Client.php';
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Exception.php';
         require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MC_OAuth2Client.php';
         $oauth_options = array('redirect_uri' => $connections['com.mailchimp']['redirect_uri'], 'client_id' => $connections['com.mailchimp']['client_id'], 'client_secret' => $connections['com.mailchimp']['client_secret'], 'code' => $data['code']);
         $client = new MC_OAuth2Client($oauth_options);
         $session = $client->getSession();
         if ($session) {
             require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MailChimp.class.php';
             $cn = new MC_OAuth2Client($oauth_options);
             $cn->setSession($session, false);
             $odata = $cn->api('metadata', 'GET');
             $access_token = $session['access_token'];
             $api_key = $session['access_token'] . '-' . $odata['dc'];
             $api = new MailChimp($api_key);
             $lists = $api->call('lists/list');
             $return_markup = '<h4>Connect to MailChimp</h4>' . '<p>Now just choose a list and save the connection.</p>' . '<form accept-charset="UTF-8" method="post" action="">' . '<input type="hidden" name="dosettingsadd" value="makeitso" />' . '<input id="connection_name_input" type="hidden" name="settings_name" value="(MailChimp list)" />' . '<input type="hidden" name="settings_type" value="com.mailchimp" />' . '<input type="hidden" name="key" value="' . $api_key . '" />' . '<label for="list">Choose a list to connect to:</label>' . '<select id="list_select" name="list">';
             $selected = ' selected="selected"';
             $list_name = false;
             foreach ($lists['data'] as $list) {
                 if ($selected) {
                     $list_name = $list['name'];
                 }
                 $return_markup .= '<option value="' . $list['id'] . '"' . $selected . '>' . $list['name'] . '</option>';
                 $selected = false;
             }
             $return_markup .= '</select><br /><br />' . '<div><input class="button" type="submit" value="Add The Connection" /></div>' . '</form>' . '<script type="text/javascript">' . '$("#connection_name_input").val("' . $list_name . ' (MailChimp)");' . '$("#list_select").change(function() {' . '	var newvalue = this.options[this.selectedIndex].text + " (MailChimp)";' . '	$("#connection_name_input").val(newvalue);' . '});' . '</script>';
             return $return_markup;
         } else {
             return 'There was an error. (session) Please try again.';
         }
     }
 }
<?php

require_once 'MC_OAuth2Client.php';
$client = new MC_OAuth2Client();
?>
<html>
  <head>
    <title>Oauth2 Tester</title>
  </head>
  <body>
    
        <a href="<?php 
echo $client->getLoginUri();
?>
">AUTHORIZE</a>
        
  </body>
</html>
<?php

require_once 'MC_OAuth2Client.php';
require_once 'MC_RestClient.php';
require_once 'miniMCAPI.class.php';
$client = new MC_OAuth2Client();
if (isset($_GET['error'])) {
    ?>

<html>
  <head>
    <title>Oauth2 Tester</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
        <h2>Complete Failure!: <?php 
    echo $_GET['error'];
    ?>
</h2>
        <br/><br/><br/>
        This likely means that you have entered a bad client_id or client_secret
        <em>or</em> you are being awesome and checking to see this failure occur.
        <br/><br/><br/>
        <a href="<?php 
    echo $client->getLoginUri();
    ?>
">Try Again?</a>
  </body>
</html>
<?php 
} else {