예제 #1
0
파일: api.php 프로젝트: burtay/bdApi
function xfac_api_hasModuleVersion($config, $module, $version = 0)
{
    $meta = xfac_option_getMeta($config);
    if (empty($meta['modules'])) {
        return false;
    }
    if (!isset($meta['modules'][$module])) {
        return false;
    }
    if ($version > 0 && $meta['modules'][$module] < $version) {
        return false;
    }
    return true;
}
예제 #2
0
function xfac_whitelist_options($whitelist_options)
{
    if (xfac_option_getWorkingMode() === 'blog') {
        $whitelist_options['xfac'][] = 'xfac_root';
        $whitelist_options['xfac'][] = 'xfac_client_id';
        $whitelist_options['xfac'][] = 'xfac_client_secret';
    }
    $config = xfac_option_getConfig();
    $meta = xfac_option_getMeta($config);
    if (!empty($meta['linkIndex'])) {
        $whitelist_options['xfac'][] = 'xfac_tag_forum_mappings';
        $whitelist_options['xfac'][] = 'xfac_sync_post_wp_xf';
        $whitelist_options['xfac'][] = 'xfac_sync_post_wp_xf_excerpt';
        $whitelist_options['xfac'][] = 'xfac_sync_post_wp_xf_link';
        $whitelist_options['xfac'][] = 'xfac_sync_post_xf_wp';
        $whitelist_options['xfac'][] = 'xfac_sync_post_xf_wp_publish';
        $whitelist_options['xfac'][] = 'xfac_search_index_post';
        $whitelist_options['xfac'][] = 'xfac_sync_comment_wp_xf';
        $whitelist_options['xfac'][] = 'xfac_sync_comment_wp_xf_as_guest';
        $whitelist_options['xfac'][] = 'xfac_sync_comment_xf_wp';
        $whitelist_options['xfac'][] = 'xfac_sync_comment_xf_wp_as_guest';
        $whitelist_options['xfac'][] = 'xfac_search_index_comment';
        $whitelist_options['xfac'][] = 'xfac_sync_avatar_xf_wp';
        $whitelist_options['xfac'][] = 'xfac_bypass_users_can_register';
        $whitelist_options['xfac'][] = 'xfac_sync_password';
        $whitelist_options['xfac'][] = 'xfac_sync_login';
        $whitelist_options['xfac'][] = 'xfac_sync_user_wp_xf';
        $whitelist_options['xfac'][] = 'xfac_sync_user_wp_xf_as_admin';
        $whitelist_options['xfac'][] = 'xfac_sync_user_wp_xf_password';
        $whitelist_options['xfac'][] = 'xfac_sync_role';
        $whitelist_options['xfac'][] = 'xfac_sync_role_wp_xf';
        $whitelist_options['xfac'][] = 'xfac_top_bar_forums';
        $whitelist_options['xfac'][] = 'xfac_top_bar_notifications';
        $whitelist_options['xfac'][] = 'xfac_top_bar_conversations';
        $whitelist_options['xfac'][] = 'xfac_top_bar_replace';
        $whitelist_options['xfac'][] = 'xfac_top_bar_always';
        $whitelist_options['xfac'][] = 'xfac_xf_guest_account';
        $whitelist_options['xfac'][] = 'xfac_xf_admin_account';
    }
    // always show advanced sections
    $whitelist_options['xfac'][] = 'xfac_server_ip';
    return $whitelist_options;
}
예제 #3
0
function xfac_admin_bar_login_menu($wpAdminBar)
{
    $wpUser = wp_get_current_user();
    if ($wpUser->ID > 0) {
        // don't add menu for users
        return;
    }
    $config = xfac_option_getConfig();
    if (empty($config)) {
        // don't add menu for site without configuration
        return;
    }
    $meta = xfac_option_getMeta($config);
    if (!empty($meta['linkRegister'])) {
        $wpAdminBar->add_menu(array('id' => 'xfac-register', 'parent' => 'top-secondary', 'title' => __('Register', 'xenforo-api-consumer'), 'href' => $meta['linkRegister']));
    }
    if (!empty($meta['linkLogin'])) {
        $wpAdminBar->add_menu(array('id' => 'xfac-login', 'parent' => 'top-secondary', 'title' => __('Log in', 'xenforo-api-consumer'), 'href' => $meta['linkLogin']));
        if (!empty($meta['linkLoginLogin'])) {
            $loginFormAction = $meta['linkLoginLogin'];
            $redirect = site_url('wp-login.php?xfac=1');
            ob_start();
            require xfac_template_locateTemplate('top_bar_login_form.php');
            $loginForm = ob_get_clean();
            $wpAdminBar->add_menu(array('id' => 'xfac-loginForm', 'parent' => 'xfac-login', 'title' => $loginForm));
        }
    }
}
예제 #4
0
파일: login.php 프로젝트: billyprice1/bdApi
function xfac_syncLogin_syncRole($config, WP_User $wpUser, array $xfUser, $xfToWp = true)
{
    $meta = xfac_option_getMeta($config);
    if (empty($meta['userGroups'])) {
        return false;
    }
    $syncRoleOption = get_option('xfac_sync_role');
    if (empty($syncRoleOption)) {
        return false;
    }
    if ($xfToWp) {
        // good
    } elseif (!get_option('xfac_sync_role_wp_xf')) {
        // requested for WordPress to XenForo sync
        // but it is not enabled
        return false;
    }
    if ($xfToWp) {
        $currentRoles = $wpUser->roles;
        $targetRoles = array();
        if (!empty($xfUser['user_groups'])) {
            foreach ($xfUser['user_groups'] as $xfUserGroup) {
                foreach ($syncRoleOption as $optionRoleName => $optionUserGroupId) {
                    if ($xfUserGroup['user_group_id'] == $optionUserGroupId) {
                        $targetRoles[] = $optionRoleName;
                    }
                }
            }
        }
        foreach ($currentRoles as $currentRole) {
            if (isset($syncRoleOption[$currentRole]) and $syncRoleOption[$currentRole] == -1) {
                // do not sync if role is set to be protected
                $targetRoles = array();
            }
        }
        if (!empty($currentRoles) and !empty($targetRoles)) {
            // TODO: improve this
            // we put a safe guard against unexpected error here
            // and do not sync if one of the arrays is empty
            // they should not be right? Right!?
            $newRole = _xfac_syncLogin_syncRole_getMostPowerfulRoleName($targetRoles);
            $XFAC_SKIP_xfac_set_user_role_before = !empty($GLOBALS['XFAC_SKIP_xfac_set_user_role']);
            $GLOBALS['XFAC_SKIP_xfac_set_user_role'] = true;
            $wpUser->set_role($newRole);
            xfac_log('xfac_syncLogin_syncRole $wpUser->set_role(%s);', $newRole);
            $GLOBALS['XFAC_SKIP_xfac_set_user_role'] = $XFAC_SKIP_xfac_set_user_role_before;
        } else {
            xfac_log('xfac_syncLogin_syncRole skipped setting role for $wpUser (#%d)', $wpUser->ID);
        }
    } else {
        $currentPrimaryGroupId = 0;
        $currentGroupIds = array();
        if (!empty($xfUser['user_groups'])) {
            foreach ($xfUser['user_groups'] as $xfUserGroup) {
                $currentGroupIds[] = intval($xfUserGroup['user_group_id']);
                if (!empty($xfUserGroup['is_primary_group'])) {
                    $currentPrimaryGroupId = intval($xfUserGroup['user_group_id']);
                }
            }
        }
        asort($currentGroupIds);
        $optionGroupIds = array();
        foreach ($syncRoleOption as $optionRoleName => $optionGroupId) {
            $optionGroupId = intval($optionGroupId);
            if ($optionGroupId > 0) {
                $optionGroupIds[$optionRoleName] = $optionGroupId;
            }
        }
        $targetGroupIds = _xfac_syncLogin_syncRole_getTargetGroupIds($wpUser->roles, $optionGroupIds);
        foreach ($currentGroupIds as $currentGroupId) {
            if (!in_array($currentGroupId, $optionGroupIds, true)) {
                // some group is not configured at all, keep them untouched
                $targetGroupIds[] = $currentGroupId;
            }
        }
        asort($targetGroupIds);
        if (!empty($targetGroupIds) and serialize($currentGroupIds) !== serialize($targetGroupIds)) {
            if (in_array($currentPrimaryGroupId, $targetGroupIds, true)) {
                $newPrimaryGroupId = $currentPrimaryGroupId;
            } else {
                $newPrimaryGroupId = array_shift($targetGroupIds);
            }
            $newSecondaryGroupIds = array();
            foreach ($targetGroupIds as $groupId) {
                if ($groupId !== $newPrimaryGroupId) {
                    $newSecondaryGroupIds[] = $groupId;
                }
            }
            $accessToken = xfac_user_getAdminAccessToken($config);
            if (!empty($accessToken)) {
                xfac_api_postUserGroups($config, $accessToken, $xfUser['user_id'], $newPrimaryGroupId, $newSecondaryGroupIds);
                xfac_log('xfac_syncLogin_syncRole pushed groups for $xfUser (#%d): %s %s', $xfUser['user_id'], $newPrimaryGroupId, $newSecondaryGroupIds);
            } else {
                xfac_log('xfac_syncLogin_syncRole failed setting role for $xfUser (#%d) because of missing $accessToken', $xfUser['user_id']);
            }
        } else {
            xfac_log('xfac_syncLogin_syncRole skipped setting role for $xfUser (#%d)', $xfUser['user_id']);
        }
    }
    return true;
}
예제 #5
0
파일: post.php 프로젝트: burtay/bdApi
function xfac_post_meta_box_info($post)
{
    $config = xfac_option_getConfig();
    $meta = xfac_option_getMeta($config);
    $records = xfac_sync_getRecordsByProviderTypeAndSyncId('', 'thread', $post->ID);
    require xfac_template_locateTemplate('post_meta_box_info.php');
}
예제 #6
0
function xfac_wpmu_options()
{
    $config = xfac_option_getConfig();
    $meta = xfac_option_getMeta($config);
    require xfac_template_locateTemplate('dashboard_wpmu_options.php');
}