예제 #1
0
파일: search.php 프로젝트: codeversed/bdApi
function xfac_search_indexComment($config, $commentId, $latestSyncDate = 0)
{
    $comment = get_comment($commentId);
    if (empty($comment->comment_approved)) {
        return false;
    }
    $date = mysql2date('U', $comment->comment_date_gmt);
    if ($date <= $latestSyncDate) {
        return false;
    }
    $post = get_post($comment->comment_post_ID);
    if (empty($post)) {
        return false;
    }
    $accessToken = '';
    if ($comment->user_id > 0) {
        $accessToken = xfac_user_getAccessToken($comment->user_id);
    }
    if (empty($accessToken)) {
        $accessToken = xfac_user_getSystemAccessToken($config, true);
    }
    $link = get_comment_link($comment);
    return xfac_api_postSearchIndexing($config, $accessToken, 'comment', $comment->comment_ID, $post->post_title, $comment->comment_content, $date, $link);
}
예제 #2
0
function xfac_syncComment_processPostSyncRecord($config, $postSyncRecord)
{
    $page = 1;
    $pulledSomething = false;
    if (time() - $postSyncRecord->sync_date < 60) {
        // do not try to sync every minute...
        return false;
    }
    if (!empty($postSyncRecord->syncData['subscribed'])) {
        if (time() - $postSyncRecord->sync_date < 86400) {
            // do not try to sync every day with subscribed thread
            return false;
        }
    }
    $wpUserData = xfac_user_getUserDataByApiData($config['root'], $postSyncRecord->syncData['thread']['creator_user_id']);
    $accessToken = xfac_user_getAccessToken($wpUserData->ID);
    $xfPosts = xfac_api_getPostsInThread($config, $postSyncRecord->provider_content_id, $accessToken);
    if (empty($xfPosts['subscription_callback']) and !empty($xfPosts['_headerLinkHub'])) {
        if (xfac_api_postSubscription($config, $accessToken, $xfPosts['_headerLinkHub'])) {
            $postSyncRecord->syncData['subscribed'] = array('hub' => $xfPosts['_headerLinkHub'], 'time' => time());
            xfac_sync_updateRecord('', $postSyncRecord->provider_content_type, $postSyncRecord->provider_content_id, $postSyncRecord->sync_id, 0, $postSyncRecord->syncData);
            xfac_log('xfac_syncComment_processPostSyncRecord subscribed for posts in thread (#%d)', $postSyncRecord->provider_content_id);
        } else {
            xfac_log('xfac_syncComment_processPostSyncRecord failed subscribing for posts in thread (#%d)', $postSyncRecord->provider_content_id);
        }
    }
    if (empty($xfPosts['posts'])) {
        return false;
    }
    $xfPostIds = array();
    foreach ($xfPosts['posts'] as $xfPost) {
        $xfPostIds[] = $xfPost['post_id'];
    }
    $commentSyncRecords = xfac_sync_getRecordsByProviderTypeAndIds('', 'post', $xfPostIds);
    foreach ($xfPosts['posts'] as $xfPost) {
        if (!empty($xfPost['post_is_first_post'])) {
            // do not pull first post
            continue;
        }
        $synced = false;
        foreach ($commentSyncRecords as $commentSyncRecord) {
            if ($commentSyncRecord->provider_content_id == $xfPost['post_id']) {
                $synced = true;
            }
        }
        if (!$synced) {
            $commentId = xfac_syncComment_pullComment($config, $xfPost, $postSyncRecord->sync_id);
            if ($commentId > 0) {
                $pulledSomething = true;
            }
        }
    }
    if ($pulledSomething) {
        xfac_sync_updateRecordDate($postSyncRecord);
    }
    return $pulledSomething;
}
예제 #3
0
파일: post.php 프로젝트: burtay/bdApi
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;
}
예제 #4
0
파일: login.php 프로젝트: billyprice1/bdApi
function xfac_set_user_role($wpUserId, $newRole, $oldRoles)
{
    if (!empty($GLOBALS['XFAC_SKIP_xfac_set_user_role'])) {
        return;
    }
    $config = xfac_option_getConfig();
    $accessToken = xfac_user_getAccessToken($wpUserId);
    if (empty($accessToken)) {
        return;
    }
    $me = xfac_api_getUsersMe($config, $accessToken);
    if (empty($me['user'])) {
        return;
    }
    $xfUser = $me['user'];
    $wpUser = new WP_User($wpUserId);
    xfac_syncLogin_syncRole($config, $wpUser, $xfUser, false);
}
예제 #5
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;
    }
}