示例#1
0
文件: post.php 项目: burtay/bdApi
function xfac_syncPost_processThreads($config, array $threads, array $mappedTags)
{
    $threadIds = array();
    foreach ($threads as $thread) {
        $threadIds[] = $thread['thread_id'];
    }
    $syncRecords = xfac_sync_getRecordsByProviderTypeAndIds('', 'thread', $threadIds);
    foreach ($threads as $thread) {
        $synced = false;
        foreach ($syncRecords as $syncRecord) {
            if ($syncRecord->provider_content_id == $thread['thread_id']) {
                $synced = true;
            }
        }
        if (!$synced) {
            $tagNames = array();
            if (!empty($thread['forum_id']) && isset($mappedTags[$thread['forum_id']])) {
                $tagNames = $mappedTags[$thread['forum_id']];
            }
            if (!empty($tagNames)) {
                xfac_syncPost_pullPost($config, $thread, $tagNames);
            }
        }
    }
}
示例#2
0
function _xfac_subscription_handleCallback_userNotification($config, $ping)
{
    $accessToken = xfac_user_getSystemAccessToken($config);
    if (empty($accessToken)) {
        return false;
    }
    if (empty($ping['object_data']['notification_id'])) {
        return false;
    }
    $notification = $ping['object_data'];
    if (empty($notification['notification_type'])) {
        return false;
    }
    if (!preg_match('/^post_(?<postId>\\d+)_insert$/', $notification['notification_type'], $matches) || intval(get_option('xfac_sync_post_xf_wp')) == 0) {
        // currently we only handle post pull here
        return false;
    }
    $postId = $matches['postId'];
    $xfPost = xfac_api_getPost($config, $postId, $accessToken);
    if (empty($xfPost['post']['thread_id'])) {
        return false;
    }
    $postSyncRecords = xfac_sync_getRecordsByProviderTypeAndIds('', 'thread', array($xfPost['post']['thread_id']));
    if (!empty($postSyncRecords)) {
        return false;
    }
    $xfThread = xfac_api_getThread($config, $xfPost['post']['thread_id'], $accessToken);
    if (empty($xfThread['thread'])) {
        return false;
    }
    $wpTags = xfac_syncPost_getMappedTags($xfThread['thread']['forum_id']);
    if (empty($wpTags)) {
        return false;
    }
    $wpPostId = xfac_syncPost_pullPost($config, $xfThread['thread'], $wpTags, 'subscription');
    if ($wpPostId > 0) {
        return 'created new post';
    }
    return false;
}