function xfac_api_getPublicLink($config, $route) { $url = call_user_func_array('sprintf', array('%s/index.php?tools/link', rtrim($config['root'], '/'))); $postFields = array('oauth_token' => xfac_api_generateOneTimeToken($config), 'type' => 'public', 'route' => $route); $curl = _xfac_api_curl($url, 'POST', $postFields); extract($curl); if (!empty($parts['link'])) { return $parts['link']; } else { return _xfac_api_getFailedResponse($parts); } }
function xfac_syncComment_pushComment($wpComment, $postSyncRecord, $commentSyncRecord = null) { $config = xfac_option_getConfig(); if (empty($config)) { return null; } $accessToken = false; $extraParams = array(); if ($wpComment->user_id > 0) { $accessToken = xfac_user_getAccessToken($wpComment->user_id); } if (empty($accessToken) and intval(get_option('xfac_sync_comment_wp_xf_as_guest')) > 0) { if (intval(get_option('xfac_xf_guest_account')) > 0) { // use pre-configured guest account $accessToken = xfac_user_getAccessToken(0); } else { // use one time token for guest $accessToken = xfac_api_generateOneTimeToken($config); $extraParams['guestUsername'] = $wpComment->comment_author; } } if (empty($accessToken)) { xfac_log('xfac_syncComment_pushComment skipped pushing $wpComment (#%d) because of missing $accessToken (user #%d)', $wpComment->comment_ID, $wpComment->user_id); return null; } $commentContent = $wpComment->comment_content; if (empty($commentSyncRecord)) { $xfPost = xfac_api_postPost($config, $accessToken, $postSyncRecord->provider_content_id, $commentContent, $extraParams); xfac_log('xfac_syncComment_pushComment pushed $wpComment (#%d)', $wpComment->comment_ID); } elseif ($wpComment->comment_approved) { $xfPost = xfac_api_putPost($config, $accessToken, $commentSyncRecord->provider_content_id, $commentContent, $extraParams); xfac_log('xfac_syncComment_pushComment pushed $wpComment (#%d) as an update', $wpComment->comment_ID); } else { $xfPost = xfac_api_deletePost($config, $accessToken, $commentSyncRecord->provider_content_id); xfac_log('xfac_syncComment_pushComment pushed $wpComment (#%d) as a delete', $wpComment->comment_ID); } if (!empty($xfPost['post']['post_id'])) { if (!empty($commentSyncRecord)) { xfac_sync_updateRecordDate($commentSyncRecord); } else { xfac_sync_updateRecord('', 'post', $xfPost['post']['post_id'], $wpComment->comment_ID, 0, array('post' => $xfPost['post'], 'direction' => 'push')); } } else { if (!empty($commentSyncRecord)) { xfac_sync_deleteRecord($commentSyncRecord); } } xfac_sync_updateRecordDate($postSyncRecord); return $xfPost; }
function xfac_wp_logout() { $config = xfac_option_getConfig(); if (empty($config)) { // do nothing return; } $wpUser = wp_get_current_user(); if (empty($wpUser->ID)) { // hmm, how could guest perform log out? return; } $records = xfac_user_getRecordsByUserId($wpUser->ID); if (!empty($records)) { foreach ($records as $record) { $accessToken = xfac_user_getAccessTokenForRecord($record); $ott = xfac_api_generateOneTimeToken($config, $record->identifier, $accessToken); $redirectTo = xfac_api_getRedirectTo(); $newRedirectTo = xfac_api_getLogoutLink($config, $ott, $redirectTo); $_REQUEST['redirect_to'] = $newRedirectTo; } } }
function xfac_user_getSystemAccessToken($config, $generateOneTimeToken = false, &$isOneTime = false) { $accessToken = null; $xfGuestAccountOption = intval(get_option('xfac_xf_guest_account')); if ($xfGuestAccountOption > 0) { // use pre-configured system account $record = xfac_user_getRecordById($xfGuestAccountOption); if (!empty($record)) { $accessToken = xfac_user_getAccessTokenForRecord($record); } if (empty($accessToken)) { xfac_updateNotice('xf_guest_account', sprintf(__('XenForo Guest Account connection is interrupted. <a href="%s">Please update bridge options</a>.', 'xenforo-api-consumer'), admin_url('options-general.php?page=xfac')), 'manage_options', __('XenForo Admin Account connection is interrupted. Please notify the staff.', 'xenforo-api-consumer')); } } if (empty($accessToken) and $generateOneTimeToken) { // use one time token for guest $accessToken = xfac_api_generateOneTimeToken($config); $isOneTime = true; } return $accessToken; }