Ejemplo n.º 1
0
 function widget($args, $instance)
 {
     if (!is_search()) {
         return '';
     }
     /** @var WP_Query $wp_query */
     global $wp_query;
     extract($args);
     $limit = !empty($instance['limit']) ? absint($instance['limit']) : 5;
     if (empty($limit)) {
         $limit = 5;
     }
     $title = !empty($instance['title']) ? $instance['title'] : __('Forum Results');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $config = xfac_option_getConfig();
     $threads = array();
     if (!empty($config)) {
         $accessToken = xfac_user_getSystemAccessToken($config, true);
         $results = xfac_api_postSearchThreads($config, $accessToken, $wp_query->get('s'), $limit);
         if (!empty($results['data'])) {
             $threads = $results['data'];
         }
     }
     require xfac_template_locateTemplate('widget_search.php');
 }
Ejemplo n.º 2
0
function xfac_user_edit($wpUser)
{
    $config = xfac_option_getConfig();
    if (empty($config)) {
        return;
    }
    $apiRecords = xfac_user_getRecordsByUserId($wpUser->ID);
    if (get_current_user_id() == $wpUser->ID) {
        require xfac_template_locateTemplate('dashboard_profile.php');
    } else {
        if (empty($apiRecords)) {
            $xfUsers = array();
            if (xfac_api_hasModuleVersion($config, 'forum', 2015030901) && xfac_api_hasModuleVersion($config, 'oauth2', 2015030902)) {
                $userLoginUsers = xfac_api_getUsersFind($config, $wpUser->user_login);
                if (!empty($userLoginUsers['users'])) {
                    foreach ($userLoginUsers['users'] as $userLoginUser) {
                        // compare strlen instead of strtolower to avoid unicode complication
                        if (strlen($userLoginUser['username']) == strlen($wpUser->user_login)) {
                            $xfUsers[$userLoginUser['user_id']] = $userLoginUser;
                        }
                    }
                }
                $adminAccessToken = xfac_user_getAdminAccessToken($config);
                if (!empty($adminAccessToken)) {
                    $emailUsers = xfac_api_getUsersFind($config, '', $wpUser->user_email, $adminAccessToken);
                    if (!empty($emailUsers['users'])) {
                        foreach ($emailUsers['users'] as $emailUser) {
                            $xfUsers[$emailUser['user_id']] = $emailUser;
                        }
                    }
                }
            }
        }
        require xfac_template_locateTemplate('dashboard_user.php');
    }
}
Ejemplo n.º 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));
        }
    }
}
Ejemplo n.º 4
0
 function widget($args, $instance)
 {
     $cache = wp_cache_get(__CLASS__);
     if (!is_array($cache)) {
         $cache = array();
     }
     if (empty($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     ob_start();
     extract($args);
     $limit = !empty($instance['limit']) ? absint($instance['limit']) : 5;
     if (empty($limit)) {
         $limit = 5;
     }
     $title = !empty($instance['title']) ? $instance['title'] : false;
     $availableTypes = $this->_getAvailableTypes();
     if (empty($instance['type']) or !isset($availableTypes[$instance['type']])) {
         $tmp = array_keys($availableTypes);
         $instance['type'] = reset($tmp);
     }
     if ($title === false) {
         $title = $availableTypes[$instance['type']];
     }
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $config = xfac_option_getConfig();
     $threads = array();
     if (!empty($config) && !empty($instance['forumIds'])) {
         $forumId = implode(',', $instance['forumIds']);
         $extraParams = array('_xfac' => 'threads.php', 'limit' => $limit, 'sticky' => 0);
         switch ($instance['type']) {
             case 'recent':
                 $extraParams['order'] = 'thread_update_date_reverse';
                 break;
             case 'most_viewed':
                 $extraParams['order'] = 'thread_view_count_reverse';
                 break;
             case 'most_replied':
                 $extraParams['order'] = 'thread_post_count_reverse';
                 break;
             case 'new':
             default:
                 // this is the default order
                 // $extraParams['order'] = 'thread_create_date_reverse';
                 break;
         }
         $extraParams = http_build_query($extraParams);
         $results = xfac_api_getThreadsInForums($config, $forumId, '', $extraParams);
         if (!empty($results['threads'])) {
             $threads = $results['threads'];
         }
     }
     require xfac_template_locateTemplate('widget_threads.php');
     $cache[$args['widget_id']] = ob_get_flush();
     wp_cache_set(__CLASS__, $cache);
 }
Ejemplo n.º 5
0
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');
}
Ejemplo n.º 6
0
function xfac_wpmu_options()
{
    $config = xfac_option_getConfig();
    $meta = xfac_option_getMeta($config);
    require xfac_template_locateTemplate('dashboard_wpmu_options.php');
}
Ejemplo n.º 7
0
function _xfac_login_renderAssociateForm(WP_User $wpUser, array $xfUser, $refreshToken, $scope, $redirectTo)
{
    $title = __('Associate Account', 'xenforo-api-consumer');
    $message = sprintf(__('Enter your password to associate the account "%1$s" with your profile.', 'xenforo-api-consumer'), $xfUser['username']);
    require xfac_template_locateTemplate('login_associate.php');
}