Settings.php 3.65 KB
<?php

// todo: move ext_perms to a constant somewhere

namespace Tz\WordPress\Tools\Auth\Facebook\Settings;

use Tz\WordPress\Tools, Tz\WordPress\Tools\Auth, Tz\WordPress\Tools\Auth\Facebook;

const OPTION_SECTION_CRED = 'fb_creds';
const OPTION_SECTION_SEL  = 'fb_opts';

    call_user_func(function() {
        Tools\add_actions(__NAMESPACE__ . '\Actions');
    });

function validate($data) {
    return (array)$data;
}

class Vars {
    public static $data_permissions = Array('read_insights', 'read_stream', 'read_mailbox', 'ads_management', 'xmpp_login', 'user_about_me', 'user_activities', 'user_birthday', 'user_education_history', 'user_events', 'user_groups', 'user_hometown', 'user_interests', 'user_likes', 'user_location', 'user_notes', 'user_online_presence', 'user_photo_video_tags', 'user_photos', 'user_relationships', 'user_religion_politics', 'user_status', 'user_videos', 'user_website', 'user_work_history', 'read_friendlists', 'read_requests');
}

class Actions {
    public static function admin_init() {
        register_setting(Auth\Settings\OPTION_GROUP, Facebook\OPTION_NAME, __NAMESPACE__ . '\validate');

        add_settings_section(OPTION_SECTION_CRED, 'Facebook Credentials', function(){ echo '<p>You can retreive this information from your <a href="http://www.facebook.com/developers/apps.php?app_id=' . Facebook\Vars::$options['application_id'] . '">Facebook | Developers page</a></p>'; }, Auth\Settings\ADMIN_PAGE);
        Tools\add_settings_fields(__NAMESPACE__ . '\Cred_Fields', Auth\Settings\ADMIN_PAGE, OPTION_SECTION_CRED);

        add_settings_section(OPTION_SECTION_SEL, 'Facebook Extended Data Permissions', function() { echo '<p>Select which additional data you wish to collect from the user</p>'; }, Auth\Settings\ADMIN_PAGE);
        foreach (Vars::$data_permissions as $option) {
            add_settings_field(
                $option
              , ucwords(str_replace('_', ' ', $option))
              , function() use ($option) {
                    echo '<input type="checkbox" id="' . $option . '" name="' . Facebook\OPTION_NAME . '[ext_perms][' . $option . ']" value="1" ' . checked('1', Facebook\Vars::$options['ext_perms'][$option], false) . ' />';
                }
              , Auth\Settings\ADMIN_PAGE
              , OPTION_SECTION_SEL
            );
        }
        add_settings_field('email', '', function() {
            echo '<input type="hidden" id="email" name="' . Facebook\OPTION_NAME . '[ext_perms][email]" value="1" />';
        }, Auth\Settings\ADMIN_PAGE, OPTION_SECTION_SEL);
    }
}

class Cred_Fields {
    public static function api_key() {
        echo '<input type="text" id="' . __FUNCTION__ . '" name="' . Facebook\OPTION_NAME . '[' . __FUNCTION__ . ']" value="' . Facebook\Vars::$options[__FUNCTION__] . '" size="45" />';
    }

    public static function application_secret() {
        echo '<input type="text" id="' . __FUNCTION__ . '" name="' . Facebook\OPTION_NAME . '[' . __FUNCTION__ . ']" value="' . Facebook\Vars::$options[__FUNCTION__] . '" size="45" />';
    }

    public static function application_id() {
        echo '<input type="text" id="' . __FUNCTION__ . '" name="' . Facebook\OPTION_NAME . '[' . __FUNCTION__ . ']" value="' . Facebook\Vars::$options[__FUNCTION__] . '" />';
    }

    public static function button_title() {
        echo '<input type="text" id="' . __FUNCTION__ . '" name="' . Facebook\OPTION_NAME . '[' . __FUNCTION__ . ']" value="' . Facebook\Vars::$options[__FUNCTION__] . '" />';
    }

    public static function domain() {
        echo '<input type="text" id="' . __FUNCTION__ . '" name="' . Facebook\OPTION_NAME . '[' . __FUNCTION__ . ']" value="' . Facebook\Vars::$options[__FUNCTION__] . '" />';
    }
}
?>