Settings'; return $links; } // add the admin settings and such add_action('admin_init', 'ap_admin_init',9); // 9 to force it first, subplugins should use default function ap_admin_init(){ $options = get_option('ap_options'); if (empty($options['consumer_key']) || empty($options['consumer_secret'])) { add_action('admin_notices', create_function( '', "echo '

".sprintf('AllPlayers.com Connect needs configuration information on its settings page.', admin_url('options-general.php?page=ap'))."

';" ) ); } wp_enqueue_script('jquery'); register_setting( 'ap_options', 'ap_options', 'ap_options_validate' ); add_settings_section('ap_main', 'Main Settings', 'ap_section_text', 'ap'); if (!defined('AP_CONSUMER_KEY')) add_settings_field('ap_consumer_key', 'AllPlayers.com Consumer Key', 'ap_setting_consumer_key', 'ap', 'ap_main'); if (!defined('AP_CONSUMER_SECRET')) add_settings_field('ap_consumer_secret', 'AllPlayers.com Consumer Secret', 'ap_setting_consumer_secret', 'ap', 'ap_main'); add_settings_field('ap_default_button', 'AllPlayers.com Default Button', 'ap_setting_default_button', 'ap', 'ap_main'); } // add the admin options page add_action('admin_menu', 'ap_admin_add_page'); function ap_admin_add_page() { global $ap_options_page; $ap_options_page = add_options_page('AllPlayers.com Connect', 'AllPlayers.com Connect', 'manage_options', 'ap', 'ap_options_page'); } function ap_plugin_help($contextual_help, $screen_id, $screen) { global $ap_options_page; if ($screen_id == $ap_options_page) { $home = home_url('/'); $contextual_help = <<< END

To connect your site to AllPlayers.com, you will need tokens. If you already have a set of tokens, please insert your Consumer Key and Consumer Secret below.

Haven't created an application yet? Don't worry, it's easy!

  1. AllPlayers.com OAuth documentation.
  2. Important Settings:
    1. Callback URL must be set to {$home}
  3. After creating the application, copy and paste the Consumer Key and Consumer Secret from the Application Details page.
END; } return $contextual_help; } add_action('contextual_help', 'ap_plugin_help', 10, 3); // display the admin options page function ap_options_page() { ?>

AllPlayers.com Connect

Options relating to the AllPlayers.com Connect plugins.

getRequestToken(); $token = $tok['oauth_token']; $_SESSION['ap_req_token'] = $token; $_SESSION['ap_req_secret'] = $tok['oauth_token_secret']; $_SESSION['ap_callback'] = $_GET['loc']; $_SESSION['ap_callback_action'] = $_GET['apaction']; if ($_GET['type'] == 'authorize') $url=$to->getAuthorizeURL($token); else $url=$to->getAuthenticateURL($token); wp_redirect($url); exit; } function ap_oauth_confirm() { $options = get_option('ap_options'); if (empty($options['consumer_key']) || empty($options['consumer_secret'])) return false; include_once "AllPlayersOAuth.php"; $to = new AllPlayersOAuth($options['consumer_key'], $options['consumer_secret'], $_SESSION['ap_req_token'], $_SESSION['ap_req_secret']); $tok = $to->getAccessToken(); $_SESSION['ap_acc_token'] = $tok['oauth_token']; $_SESSION['ap_acc_secret'] = $tok['oauth_token_secret']; $to = new AllPlayersOAuth($options['consumer_key'], $options['consumer_secret'], $tok['oauth_token'], $tok['oauth_token_secret']); // this lets us do things actions on the return from AllPlayers.com and such if ($_SESSION['ap_callback_action']) { do_action('ap_'.$_SESSION['ap_callback_action']); $_SESSION['ap_callback_action'] = ''; // clear the action } wp_redirect($_SESSION['ap_callback']); exit; } // get the user credentials from AllPlayers.com function ap_get_credentials($force_check = false) { // cache the results in the session so we don't do this over and over //if (!$force_check && $_SESSION['ap_credentials']) return $_SESSION['ap_credentials']; $_SESSION['ap_credentials'] = ap_do_request('https://www.allplayers.com/api/v1/rest/users/current'); return $_SESSION['ap_credentials']; } // json is assumed for this, so don't add .xml or .json to the request URL function ap_do_request($url, $args = array(), $type = NULL) { if ($args['acc_token']) { $acc_token = $args['acc_token']; unset($args['acc_token']); } else { $acc_token = $_SESSION['ap_acc_token']; } if ($args['acc_secret']) { $acc_secret = $args['acc_secret']; unset($args['acc_secret']); } else { $acc_secret = $_SESSION['ap_acc_secret']; } $options = get_option('ap_options'); if (empty($options['consumer_key']) || empty($options['consumer_secret']) || empty($acc_token) || empty($acc_secret) ) return false; include_once "AllPlayersOAuth.php"; $to = new AllPlayersOAuth($options['consumer_key'], $options['consumer_secret'], $acc_token, $acc_secret); $json = $to->OAuthRequest($url.'.json', $args, $type); return json_decode($json); } function ap_section_text() { $options = get_option('ap_options'); if (empty($options['consumer_key']) || empty($options['consumer_secret'])) { ?>

To connect your site to AllPlayers.com, you will need tokens. If you already have a set of tokens, please insert your Consumer Key and Consumer Secret below.

Haven't created an application yet? Don't worry, it's easy!

  1. AllPlayers.com OAuth documentation.
  2. Important Settings:
    1. Callback URL must be set to
  3. After creating the application, copy and paste the Consumer Key and Consumer Secret from the Application Details page.
'. ''. ''; } function ap_get_current_url() { // build the URL in the address bar $requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; return $requested_url; } function ap_setting_consumer_key() { if (defined('ap_CONSUMER_KEY')) return; $options = get_option('ap_options'); echo " (required)"; } function ap_setting_consumer_secret() { if (defined('AP_CONSUMER_SECRET')) return; $options = get_option('ap_options'); echo " (required)"; } function ap_setting_default_button() { $options = get_option('ap_options'); if (empty($options['default_button'])) $options['default_button'] = 'Sign-in-with-AllPlayers-darker'; ?>