$the_style";
}
//this just dumps the event handler for the account selector button into the head of the settings page
function AffinityClick_AccountSelector_javascript()
{
echo "";
}
//this is the code executed by wordpress when the javascript above is triggered.
//this function must end with a die() at some point. the result is not visible unless
//the user has debug turned on.
function AffinityClick_AccountSelector_callback()
{
global $AffinityClick, $wpdb; // this is how you get access to the database. probably don't need it here?
$account_key = $_POST['account'];
$username = get_option("affinityclick_email");
$password = get_option("affinityclick_password");
$login_url = $AffinityClick->getUrlFor('api')."/login.json?username=$username&password=$password";
$result = wp_remote_get($login_url, array('method'=>'GET','timeout'=>5,'redirection'=>1,'httpversion'=>'1.0','blocking'=>true,'headers'=>array(),'body'=>'','cookies'=>array()));
if( is_wp_error( $result ) ) {
die("Failed to Login. Are you sure your email and password are active?");
}
else if(json_decode($result['body'])->{"success"})
{
$cookies = $result['cookies'];
//$accounts_url = $AffinityClick->getUrlFor('api')."/accounts/".$account_key + ".json";
$accounts_url = $AffinityClick->getUrlFor('api')."/accounts/".$account_key;
$result = wp_remote_get($accounts_url, array('method'=>'GET','timeout'=>5,'redirection'=>1,'httpversion'=>'1.0','blocking'=>true,'headers'=>array(),'body'=>'','cookies'=>$cookies));
update_option("affinityclick_account_in_use",$account_key);
//do we care about the result?
}
die("success"); //wordpress expects this to happen at the end.
}
function AffinityClick_installWidgets()
{
require_once('affinityclick_intext.php');
require_once('affinityclick_banner.php');
register_widget('AffinityClick_InText');
register_widget('AffinityClick_Banner');
}
#this function goes through the plugin settings to make sure its set up correctly.
function AffinityClick_checkAPIKey()
{
global $AffinityClick;
$is_setup_correctly = false;
$username = get_option("affinityclick_email");
$password = get_option("affinityclick_password");
$login_url = $AffinityClick->getUrlFor('api')."/login.json?username=$username&password=$password";
$result = wp_remote_get($login_url, array('method'=>'GET','timeout'=>5,'redirection'=>1,'httpversion'=>'1.0','blocking'=>true,'headers'=>array(),'body'=>'','cookies'=>array()));
if( is_wp_error( $result ) ) {
$is_setup_correctly = false;
}
else
{
$obj = json_decode($result['body']);
$is_setup_correctly = $obj->{"success"};
}
if(!$is_setup_correctly)
{
echo '
The AffinityClick plugin is not configured properly:
Go to the settings page to configure your username and password.
';
}
else //successful setup complete
{}
}
//generates the affinityclick menu. the final argument to add_menu_page is an icon. I used a random one from the internet, but you guys should
//add your own here
function AffinityClick_SetupMenu()
{
add_menu_page('AffinityClick Settings', 'AffinityClick', 'manage_options', 'affinity-click-top-menu', 'AffinityClick_options_about', 'http://www.messagetostream.com/assets/images/icons/money_dollar.png');
add_submenu_page( 'affinity-click-top-menu', 'AffinityClick - Setup Plugin', 'Settings', 'manage_options', 'affinity-click-widget-settings', 'AffinityClick_options_widget_settings');
add_submenu_page( 'affinity-click-top-menu', 'AffinityClick - Login', 'Login to AffinityClick', 'manage_options', 'affinity-click-in-text', 'AffinityClick_options_in_text');
add_action( 'admin_init', 'AffinityClick_options_setup_db' );
}
//ended up not using this. leaving it here anyway in case it ends up being needed
function AffinityClick_options_about()
{
echo "";
}
function AffinityClick_options_in_text()
{
global $AffinityClick;
$page_to_show = $AffinityClick->getUrlFor('my')."/";
$username = get_option("affinityclick_email");
$password = get_option("affinityclick_password");
if($username != "")
{
$page_to_show = $AffinityClick->getUrlFor('my')."/login?username=$username&password=$password";
}
echo "";
}
//this tells wordpress what our required settngs will be
function AffinityClick_options_setup_db()
{
register_setting( 'ac_options', 'affinityclick_email' );
register_setting( 'ac_options', 'affinityclick_password' );
//this is the setting that tracks what the last set account in use was
register_setting( 'ac_options', 'affinityclick_account_in_use' );
}
function AffinityClick_options_widget_settings()
{
global $AffinityClick;
$username = get_option("affinityclick_email");
$password = get_option("affinityclick_password");
$account_in_use = get_option("affinityclick_account_in_use");
if($username == "")
{
echo "To register for a new account, visit the AffinityClick website. ";
}
echo "