hook ('plugins_loaded'); } static function is_wpna_installed () { return file_exists (WPNAUTH_PLUGIN_HELPER); } static function is_wpna_active () { return is_plugin_active (WPNAUTH_PLUGIN_PATH); } function plugins_loaded () { register_activation_hook (__FILE__, array ($this, 'add_settings')); $this->hook ('init'); $this->hook ('widgets_init'); if (is_admin ()) { $this->hook ('admin_init'); $this->hook ('admin_menu'); $this->hook ('admin_print_scripts'); $this->hook ('admin_print_styles'); add_filter ('plugin_action_links_' . plugin_basename (__FILE__), array ($this, 'admin_settings_link')); } } function init () { $lang_dir = basename (dirname (__FILE__)) . DIRECTORY_SEPARATOR . 'lang'; load_plugin_textdomain ('wp-quadratum', false, $lang_dir); } function widgets_init () { return register_widget ('WPQuadratumWidget'); } function add_settings () { $settings = $this->get_option (); if (!is_array ($settings)) { $settings = apply_filters ('wp_quadratum_default_settings', array ( "installed" => "on", "version" => self::VERSION, "client_id" => "", "client_secret" => "", "oauth_token" => "" ) ); update_option (self::OPTIONS, $settings); } } function get_option () { $num_args = func_num_args (); $options = get_option (self::OPTIONS); if ($num_args > 0) { $args = func_get_args (); $key = $args[0]; $value = ""; if (isset ($options[$key])) { $value = $options[$key]; } return $value; } else { return $options; } } function set_option ($key, $value) { $options = get_options (self::OPTIONS); $options[$key] = $value; update_option (self::OPTIONS, $options); } function admin_init () { $this->admin_upgrade (); $settings = $this->get_option (); if (empty ($settings['oauth_token'])) { $this->hook ('admin_notices'); } } function admin_notices () { if (current_user_can ('manage_options')) { $content = sprintf (__('You need to grant WP Quadratum access to your Foursquare account to show your checkins; you can go to the WP Quadratum Settings And Options page to do this now'), admin_url ('options-general.php?page=wp-quadratum/wp-quadratum.php')); echo '
' . $content . '
'; } } function admin_menu () { if (function_exists ('add_options_page')) { $page_title = __('WP Quadratum'); $menu_title = __('WP Quadratum'); add_options_page ($page_title, $menu_title, 'manage_options', __FILE__, array ($this, 'admin_display_settings')); } } function admin_print_scripts () { global $pagenow; if ($pagenow == 'options-general.php' && isset ($_GET['page']) && strstr ($_GET['page'], 'wp-quadratum')) { wp_enqueue_script ('postbox'); wp_enqueue_script ('dashboard'); wp_enqueue_script ('custom-background'); } } function admin_print_styles () { global $pagenow; if ($pagenow == 'options-general.php' && isset ($_GET['page']) && strstr ($_GET['page'], 'wp-quadratum')) { wp_enqueue_style ('dashboard'); wp_enqueue_style ('global'); wp_enqueue_style ('wp-admin'); wp_enqueue_style ('farbtastic'); wp_enqueue_style ('wp-quadratum-admin', WPQUADRATUM_URL . 'css/wp-quadratum-admin.css'); } } function admin_settings_link ($links) { $settings_link = '' . __('Settings') . ''; array_unshift ($links, $settings_link); return $links; } function admin_upgrade () { $options = null; $upgrade_settings = false; $current_plugin_version = NULL; $options = $this->get_option (); if (is_array ($options) && !empty ($options['version']) && $options['version'] == self::VERSION) { return; } if (!is_array ($options)) { $this->add_settings (); } else { if (!empty ($options['version'])) { $current_plugin_version = $options['version']; } else { $current_plugin_version = '00'; } switch ($current_plugin_version) { case '00': case '10': $options['version'] = self::VERSION; $upgrade_settings = true; default: break; } // end-switch if ($upgrade_settings) { update_option (self::OPTIONS, $options); } } } function admin_display_settings () { $options = $this->admin_save_settings (); $auth_plugin_installed = self::is_wpna_installed (); $auth_plugin_active = self::is_wpna_active (); $wrapped_content = array (); $foursquare_settings = array (); $foursquare_title = __('Foursquare OAuth Settings'); $nokia_settings = array (); $nokia_title = __('Nokia Location API Settings'); if (empty ($options['oauth_token'])) { $foursquare_title .= __(' (Not Authenticated)'); } else { $foursquare_title .= __(' (Successfully Authenticated)'); } if (empty ($options['oauth_token'])) { $foursquare_settings[] = '
' . __('You are not currently authenticated with the Foursquare API.') . '
'; $foursquare_settings[] = '

' . __('To display your Foursquare checkins, WP Quadratum needs to be authorised to access your Foursquare account information; this is a simple, safe and secure 3 step process. QP Quadratum never sees your account login information and cannot store any personally identifiable information.') . '

' . sprintf (__('Step 1. Register this WordPress site as a Foursquare application on the Foursquare OAuth Consumer Registration page'), 'https://foursquare.com/oauth/register') . '

' . __('If you\'re not currently logged into your Foursquare account, you\'ll need to login with the Foursquare account whose checkins you want WP Quadratum to display.') . '

    ' . '
  1. ' . __('The Application Name is a label you want to use to identify this connection to your Foursquare account') . '
  2. ' . '
  3. ' . sprintf (__('The Application Web Site is the URL of this Wordpress site, which is %s'), get_bloginfo ('url')) . '
  4. ' . '
  5. ' . sprintf (__('The Callback URL should be set to %s'), plugins_url() . '/wp-quadratum/includes/wp-quadratum-callback.php') . '
  6. ' . '
' . __('Once you have successfully registered your site, you\'ll be provided with two keys, the client id and the client secret') . '

' . '

' . __('Step 2. Copy and paste the supplied Client ID and Client Secret below') . '

'; $foursquare_settings[] = '

' . __('Foursquare Client ID') . '

Your Foursquare API Client ID

'; $foursquare_settings[] = '

' . __('Foursquare Client Secret') . '

Your Foursquare API Client Secret

'; $foursquare_settings[] = '

' . __('Step 3. You should now be authorised and ready to go; click on the Connect button below.') . '

'; $foursquare_settings[] = '

'; if (!empty ($options['client_id'])) { $fh = new FoursquareHelper ($options['client_id'], $options['client_secret'], plugins_url () . '/' . dirname (plugin_basename (__FILE__)) . '/includes/wp-quadratum-callback.php'); $foursquare_settings[] = '

' . '' . __('Connect to Foursquare') . '' . '

'; } } else { $foursquare_settings[] = '
' . __('You are currently successfully authenticated with the Foursquare API.') . '
'; } if ($auth_plugin_installed) { if ($auth_plugin_active) { $helper = new WPNokiaAuthHelper (); $nokia_settings[] = '
' . __('WP Nokia Auth is installed and active') . '
'; $nokia_settings[] = '

' . __('App ID') . '


'; $nokia_settings[] = '

' . __('App Token') . '


'; $nokia_settings[] = '

' . __('App Secret') . '


'; } else { $nokia_settings[] = '
' . __('WP Nokia Auth is installed but not currently active') . '
'; } } else { $nokia_settings[] = '

' . sprintf (__('You can use the WP Nokia Auth plugin to manage your Nokia Location Platform API credentials. Or you can obtain Nokia Location API credentials from the Nokia API Registration site.'), 'http://wordpress.org/extend/plugins/wp-nokia-auth/', 'http://api.developer.nokia.com/') . '

'; $nokia_settings[] = '

' . __('Application ID') . '

' . __('Enter your registered Nokia Location API App ID') . '

'; $nokia_settings[] = '

' . __('Application Token') . '

' . __('Enter your registered Nokia Location API App Token') . '

'; $nokia_settings[] = '

' . __('Application Secret') . '

' . __('Enter your registered Nokia Location API App Secret') . '

'; } if (function_exists ('wp_nonce_field')) { $wrapped_content[] = wp_nonce_field ( 'wp-quadratum-update-options', '_wpnonce', true, false); } $wrapped_content[] = $this->admin_postbox ('wp-quadratum-foursquare-settings', $foursquare_title, implode('', $foursquare_settings)); $wrapped_content[] = $this->admin_postbox ('wp-quadratum-nokia-settings', $nokia_title, implode ('', $nokia_settings)); $this->admin_wrap ( sprintf (__('WP Quadratum %s - Settings And Options'), self::DISPLAY_VERSION), implode ('', $wrapped_content)); } function admin_option ($field) { return (isset ($_POST[$field]) ? $_POST[$field] : ""); } function admin_save_settings () { $options = $this->get_option (); if (!empty ($_POST['wp_quadratum_option_submitted'])) { if (strstr ($_GET['page'], 'wp-quadratum') && check_admin_referer ('wp-quadratum-update-options')) { $options['client_id'] = $this->admin_option('wp_quadratum_client_id'); $options['client_secret'] = $this->admin_option('wp_quadratum_client_secret'); $options['app_id'] = html_entity_decode ($this->admin_option ('wp_quadratum_app_id')); $options['app_token'] = html_entity_decode ($this->admin_option ('wp_quadratum_app_token')); $options['app_secret'] = html_entity_decode ($this->admin_option ('wp_quadratum_app_secret')); echo "

"; _e('WP Quadratum Settings And Options Updated.'); echo "

\n"; echo ""; update_option (self::OPTIONS, $options); } } $options = $this->get_option (); return $options; } function admin_postbox ($id, $title, $content) { $handle_title = __('Click to toggle'); $postbox_wrap = '
'; $postbox_wrap .= '

'; $postbox_wrap .= '

' . $title . '

'; $postbox_wrap .= '
' . $content . '
'; $postbox_wrap .= '
'; return $postbox_wrap; } function admin_wrap ($title, $content) { ?>



admin_help_and_support (); echo $this->admin_show_colophon (); ?>
' . __('For help and support with WP Quadratum, here\'s what you can do:') . '' . '

' . '

' . __('But ... help and support is a two way street; here\'s what you might want to do:') . '

' . '

'; return $this->admin_postbox ('wp-quadratum-support', __('Help & Support'), $content); } /** * Emits the plugin's colophon side-box for the plugin's admin settings/options page. */ function admin_show_colophon() { $content = '

"When it comes to software, I much prefer free software, because I have very seldom seen a program that has worked well enough for my needs and having sources available can be a life-saver" … Linus Torvalds

'; $content .= '

' . __('For the inner nerd in you, the latest version of WP Quadratum was written using TextMate on a MacBook Pro running OS X 10.7.3 Lion and tested on the same machine running MAMP (Mac/Apache/MySQL/PHP) before being let loose on the author\'s blog.') . '

'; $content .= '

' . __('The official home for WP Quadratum is on Gary\'s Codeage; it\'s also available from the official WordPress plugins repository. If you\'re interested in what lies under the hood, the code is also on GitHub to download, fork and otherwise hack around.') . '

'; $content .= '

' . __('WP Quadratum is named after both the Latin words quattor, meaning four and quadratum, meaning square.') . '

'; return $this->admin_postbox ('wp-quadratum-colophon', __('Colophon'), $content); } } // end-class WPQuadratum $__wp_quadratum_instance = new WPQuadratum; ?>