Ejemplo n.º 1
0
function xfac_user_getUserByApiData($root, $xfUserId)
{
    $userdata = xfac_user_getUserDataByApiData($root, $xfUserId);
    if (empty($userdata)) {
        return false;
    }
    $user = new WP_User();
    $user->init($userdata);
    return $user;
}
Ejemplo n.º 2
0
function xfac_syncComment_pullComment($config, $xfPost, $wpPostId, $direction = 'pull')
{
    $wpUserUrl = '';
    $wpUserId = 0;
    $wpUserData = xfac_user_getUserDataByApiData($config['root'], $xfPost['poster_user_id']);
    if (empty($wpUserData)) {
        if (intval(get_option('xfac_sync_comment_xf_wp_as_guest')) == 0) {
            return 0;
        }
        // no wordpress user found but as_guest option is enabled
        // sync as guest now
        $wpDisplayName = $xfPost['poster_username'];
        $wpUserEmail = sprintf('*****@*****.**', $xfPost['poster_username'], $xfPost['poster_user_id']);
    } else {
        $wpDisplayName = $wpUserData->display_name;
        $wpUserEmail = $wpUserData->user_email;
        $wpUserUrl = $wpUserData->user_url;
        $wpUserId = $wpUserData->ID;
    }
    $commentDateGmt = gmdate('Y-m-d H:i:s', $xfPost['post_create_date']);
    $commentDate = get_date_from_gmt($commentDateGmt);
    $commentContent = xfac_api_filterHtmlFromXenForo($xfPost['post_body_html']);
    $comment = array('comment_post_ID' => $wpPostId, 'comment_author' => $wpDisplayName, 'comment_author_email' => $wpUserEmail, 'comment_author_url' => $wpUserUrl, 'comment_content' => $commentContent, 'user_id' => $wpUserId, 'comment_date_gmt' => $commentDateGmt, 'comment_date' => $commentDate, 'comment_approved' => 1);
    $XFAC_SKIP_xfac_save_comment_before = !empty($GLOBALS['XFAC_SKIP_xfac_save_comment']);
    $GLOBALS['XFAC_SKIP_xfac_save_comment'] = true;
    $commentId = wp_insert_comment($comment);
    $GLOBALS['XFAC_SKIP_xfac_save_comment'] = $XFAC_SKIP_xfac_save_comment_before;
    if ($commentId > 0) {
        xfac_sync_updateRecord('', 'post', $xfPost['post_id'], $commentId, 0, array('post' => $xfPost, 'direction' => $direction));
        xfac_log('xfac_syncComment_pullComment pulled $xfPost (#%d) -> $wpComment (#%d)', $xfPost['post_id'], $commentId);
    } else {
        xfac_log('xfac_syncComment_pullComment failed pulling $xfPost (#%d)', $xfPost['post_id']);
    }
    return $commentId;
}
Ejemplo n.º 3
0
function xfac_syncPost_pullPost($config, $thread, $tags, $direction = 'pull')
{
    if (empty($thread['creator_user_id'])) {
        return 0;
    }
    $wpUserData = xfac_user_getUserDataByApiData($config['root'], $thread['creator_user_id']);
    if (empty($wpUserData)) {
        return 0;
    }
    $postAuthor = $wpUserData->ID;
    $wpUser = new WP_User($wpUserData);
    $postTypeObj = get_post_type_object('post');
    if (empty($postTypeObj)) {
        // no post type object?!
        return 0;
    }
    if (!$wpUser->has_cap($postTypeObj->cap->create_posts)) {
        // no permission to create posts
        xfac_log('xfac_syncPost_pullPost skipped pulling post because of lack of create_posts capability (user #%d)', $wpUser->ID);
        return 0;
    }
    $postDateGmt = gmdate('Y-m-d H:i:s', $thread['thread_create_date']);
    $postDate = get_date_from_gmt($postDateGmt);
    $postStatus = 'draft';
    if (intval(get_option('xfac_sync_post_xf_wp_publish')) > 0) {
        $postStatus = 'publish';
    }
    $postContent = xfac_api_filterHtmlFromXenForo($thread['first_post']['post_body_html']);
    $wpPost = array('post_author' => $postAuthor, 'post_content' => $postContent, 'post_date' => $postDate, 'post_date_gmt' => $postDateGmt, 'post_status' => $postStatus, 'post_title' => $thread['thread_title'], 'post_type' => 'post', 'tags_input' => implode(', ', $tags));
    $XFAC_SKIP_xfac_save_post_before = !empty($GLOBALS['XFAC_SKIP_xfac_save_post']);
    $GLOBALS['XFAC_SKIP_xfac_save_post'] = true;
    $wpPostId = wp_insert_post($wpPost);
    $GLOBALS['XFAC_SKIP_xfac_save_post'] = $XFAC_SKIP_xfac_save_post_before;
    if ($wpPostId > 0) {
        $subscribed = array();
        if (intval(get_option('xfac_sync_comment_xf_wp')) > 0) {
            $accessToken = xfac_user_getAccessToken($wpUser->ID);
            if (!empty($accessToken)) {
                $xfPosts = xfac_api_getPostsInThread($config, $thread['thread_id'], $accessToken);
                if (empty($xfPosts['subscription_callback']) and !empty($xfPosts['_headerLinkHub'])) {
                    if (xfac_api_postSubscription($config, $accessToken, $xfPosts['_headerLinkHub'])) {
                        $subscribed = array('hub' => $xfPosts['_headerLinkHub'], 'time' => time());
                    }
                }
            }
        }
        xfac_sync_updateRecord('', 'thread', $thread['thread_id'], $wpPostId, $thread['thread_create_date'], array('forumId' => $thread['forum_id'], 'thread' => $thread, 'direction' => $direction, 'sticky' => !empty($thread['thread_is_sticky']), 'subscribed' => $subscribed));
        xfac_log('xfac_syncPost_pullPost pulled $xfThread (#%d) as $wpPost (#%d)', $thread['thread_id'], $wpPostId);
    } else {
        xfac_log('xfac_syncPost_pullPost failed pulling $xfThread (#%d)');
    }
    return $wpPostId;
}
Ejemplo n.º 4
0
function _xfac_subscription_handleCallback_user($config, $ping)
{
    $wpUserData = xfac_user_getUserDataByApiData($config['root'], $ping['object_data']);
    if (empty($wpUserData)) {
        return false;
    }
    $accessToken = xfac_user_getAccessToken($wpUserData->ID);
    if (empty($accessToken)) {
        return false;
    }
    $me = xfac_api_getUsersMe($config, $accessToken, false);
    if (empty($me)) {
        return false;
    }
    $xfUser = $me['user'];
    $wpUser = new WP_User($wpUserData);
    xfac_syncLogin_syncBasic($config, $wpUser, $xfUser);
    xfac_syncLogin_syncRole($config, $wpUser, $xfUser);
    if (xfac_user_updateRecord($wpUserData->ID, $config['root'], $xfUser['user_id'], $xfUser)) {
        return 'updated user record';
    } else {
        return false;
    }
}