Exemplo n.º 1
0
 function form($instance)
 {
     static $forums = null;
     $config = xfac_option_getConfig();
     if (!empty($config) and $forums === null) {
         $forums = xfac_api_getForums($config);
     }
     $availableTypes = $this->_getAvailableTypes();
     $title = !empty($instance['title']) ? esc_attr($instance['title']) : '';
     $type = !empty($instance['type']) ? esc_attr($instance['type']) : '';
     $forumIds = array();
     if (!empty($instance['forumIds'])) {
         $forumIds = $instance['forumIds'];
     }
     if (empty($instance['limit'])) {
         $limit = 5;
     } else {
         $limit = esc_attr($instance['limit']);
     }
     require xfac_template_locateTemplate('widget_threads_form.php');
 }
Exemplo n.º 2
0
function xfac_option_getMeta($config)
{
    static $rebuiltCount = 0;
    if (empty($config)) {
        return array();
    }
    $meta = get_option('xfac_meta');
    $rebuild = false;
    if (empty($meta) or empty($meta['linkIndex'])) {
        $rebuild = true;
    } else {
        foreach ($config as $configKey => $configValue) {
            if (empty($meta[$configKey]) or $meta[$configKey] !== $configValue) {
                $rebuild = true;
                break;
            }
        }
    }
    $xfAdminAccountOption = intval(get_option('xfac_xf_admin_account'));
    $xfAdminAccountMeta = empty($meta['xfac_xf_admin_account']) ? 0 : intval($meta['xfac_xf_admin_account']);
    if ($xfAdminAccountMeta !== $xfAdminAccountOption) {
        $rebuild = true;
    }
    if ($rebuild and !empty($_REQUEST['oauth_token'])) {
        // looks like admin enter WordPress url as the root, abort rebuilding
        $rebuild = false;
    }
    if ($rebuild and $rebuiltCount > 0) {
        // we rebuild once, only retry if $meta is empty
        if (!empty($meta)) {
            $rebuild = false;
        }
    }
    if ($rebuild) {
        xfac_updateNotice('xf_guest_account');
        xfac_updateNotice('xf_admin_account');
        $meta = $config;
        $meta['linkIndex'] = xfac_api_getPublicLink($config, 'index');
        $meta['modules'] = array();
        $meta['forums'] = array();
        if (!empty($meta['linkIndex'])) {
            if ($xfAdminAccountOption) {
                $adminAccessToken = xfac_user_getAdminAccessToken($config);
                if (empty($adminAccessToken)) {
                    // unable to obtain admin access token
                    // probably a missing record or expired refresh token
                    // reset the option
                    update_option('xfac_xf_admin_account', 0);
                    $xfAdminAccountOption = 0;
                }
            }
            $xfGuestAccountOption = intval(get_option('xfac_xf_guest_account'));
            if ($xfGuestAccountOption) {
                $guestAccessToken = xfac_user_getSystemAccessToken($config);
                if (empty($guestAccessToken)) {
                    // unable to obtain guest access token
                    // probably an expired refresh token
                    // reset the option
                    update_option('xfac_xf_guest_account', 0);
                } else {
                    $mappedTags = xfac_syncPost_getMappedTags();
                    if (!empty($mappedTags)) {
                        // make sures the guest account follows required forums
                        // and have the needed notification subscription
                        xfac_syncPost_followForums($config, $guestAccessToken, array_keys($mappedTags));
                    }
                }
            }
            $meta['modules'] = xfac_api_getModules($config);
            $meta['linkAlerts'] = xfac_api_getPublicLink($config, 'account/alerts');
            $meta['linkConversations'] = xfac_api_getPublicLink($config, 'conversations');
            $meta['linkLogin'] = xfac_api_getPublicLink($config, 'login');
            $meta['linkLoginLogin'] = xfac_api_getPublicLink($config, 'login/login');
            $meta['linkRegister'] = xfac_api_getPublicLink($config, 'register');
            $forums = xfac_api_getForums($config);
            if (!empty($forums['forums'])) {
                $meta['forums'] = $forums['forums'];
            }
            $meta['xfac_xf_admin_account'] = $xfAdminAccountOption;
            if (!empty($meta['xfac_xf_admin_account'])) {
                $userGroups = xfac_api_getUserGroups($config, 0, xfac_user_getAdminAccessToken($config));
                if (!empty($userGroups['user_groups'])) {
                    $meta['userGroups'] = $userGroups['user_groups'];
                }
            }
        }
        $rebuiltCount++;
        update_option('xfac_meta', $meta);
        xfac_log('xfac_option_getMeta rebuilt $meta=%s', $meta);
    }
    return $meta;
}