示例#1
0
/**
 * Creates a new integrated user in phpBB to match a given WordPress user
 * @param int $userID the WordPress userID
 * @return int < 1 on failure; >=1 phpbb User ID on success
 */
function wpu_create_phpbb_user($userID)
{
    global $phpbbForum, $config, $db;
    if (!$userID) {
        return -1;
    }
    $wpUsr = get_userdata($userID);
    $fStateChanged = $phpbbForum->foreground();
    $password = wpu_convert_password_format($wpUsr->user_pass, 'to-phpbb');
    // validates and finds a unique username
    if (!($signUpName = wpu_find_next_avail_name($wpUsr->user_login, 'phpbb'))) {
        $phpbbForum->restore_state($fStateChanged);
        return -1;
    }
    $userToAdd = array('username' => $signUpName, 'user_password' => $password, 'user_email' => $wpUsr->user_email, 'user_type' => USER_NORMAL);
    // add to newly registered group if needed
    if ($config['new_member_post_limit']) {
        $userToAdd['user_new'] = 1;
    }
    // Which group by default?
    $sql = 'SELECT group_id
		FROM ' . GROUPS_TABLE . "\n\t\tWHERE group_name = '" . $db->sql_escape('REGISTERED') . "'\n\t\t\tAND group_type = " . GROUP_SPECIAL;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $groupID = (int) $row['group_id'];
    $userToAdd['group_id'] = empty($groupID) ? 2 : $groupID;
    $pUserID = 0;
    if ($pUserID = user_add($userToAdd)) {
        wpu_update_int_id($pUserID, $wpUsr->ID);
        update_user_meta($wpUsr->ID, 'phpbb_userid', $pUserID);
    }
    $phpbbForum->restore_state($fStateChanged);
    return $pUserID;
}
示例#2
0
 /**
  * If the blog post is cross-posted, and comments are redirected from phpBB,
  * this catches posted comments and sends them to the forum
  */
 function post_comment($postID)
 {
     global $phpbb_root_path, $phpEx, $phpbbForum, $auth, $user, $db;
     if (!$this->is_working()) {
         return;
     }
     $wpUserID = 0;
     if ($wpUser = wp_get_current_user()) {
         $wpUserID = $u->ID;
     }
     $requireNameEmail = get_option('require_name_email');
     $fStateChanged = $phpbbForum->foreground();
     $dets = $this->get_xposted_details($postID);
     if (!$dets) {
         $phpbbForum->restore_state($fStateChanged);
         return;
     }
     $isValidEmail = true;
     $guestPosting = false;
     if ($phpbbForum->user_logged_in()) {
         $username = $phpbbForum->get_username();
         $website = $phpbbForum->get_userdata('user_website');
         $email = $phpbbForum->get_userdata('user_email');
     } else {
         $guestPosting = true;
         $username = strip_tags(stripslashes(request_var('author', 'Anonymous')));
         $website = request_var('url', '');
         $email = request_var('email', '');
         if ($email) {
             // use wordpress to sanitize email
             $phpbbForum->background();
             $isValidEmail = is_email($email);
             $phpbbForum->foreground();
         }
         $username = wpu_find_next_avail_name($username, 'phpbb');
     }
     if (empty($dets['topic_approved'])) {
         $phpbbForum->restore_state($fStateChanged);
         wp_die($phpbbForum->lang['ITEM_LOCKED']);
     }
     if ($dets['topic_status'] == ITEM_LOCKED) {
         $phpbbForum->restore_state($fStateChanged);
         wp_die($phpbbForum->lang['TOPIC_LOCKED']);
     }
     if ($dets['forum_id'] == 0) {
         // global announcement
         if (!$auth->acl_getf_global('f_wpu_xpost_comment')) {
             $phpbbForum->restore_state($fStateChanged);
             wp_die(__('You do not have permission to respond to this announcement', 'wp-united'));
         }
     } else {
         if (!$auth->acl_get('f_wpu_xpost_comment', $dets['forum_id'])) {
             $phpbbForum->restore_state($fStateChanged);
             wp_die(__('You do not have permission to comment in this forum', 'wp-united'));
         }
     }
     $content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
     if (empty($content)) {
         $phpbbForum->restore_state($fStateChanged);
         wp_die(__('Error: Please type a comment!', 'wp-united'));
     }
     // taken from wp-comment-post.php, native WP translation of strings
     if ($requireNameEmail && $guestPosting) {
         if (6 > strlen($email) || '' == $username) {
             wp_die(__('<strong>ERROR</strong>: please fill in the required fields (name, email).', 'wp-united'));
         } elseif (!$isValidEmail) {
             wp_die(__('<strong>ERROR</strong>: please enter a valid email address.', 'wp-united'));
         }
     }
     $commentParent = (int) request_var('comment_parent', 0);
     // create a wordpress comment and run some checks on it
     // send comment thru akismet, other spam filtering, if user is logged out
     $phpbbForum->background();
     $commentData = array('comment_post_ID' => $postID, 'comment_author' => $username, 'comment_author_email' => $email, 'comment_author_url' => $website, 'comment_parent' => $commentParent, 'comment_type' => '', 'user_ID' => $wpUserID);
     $checkSpam = $this->get_setting('xpostspam');
     $checkSpam = !empty($checkSpam);
     if ($guestPosting && $checkSpam) {
         $commentData = apply_filters('preprocess_comment', $commentData);
     }
     $commentData = array_merge($commentData, array('comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254), 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1), 'comment_karma' => 0));
     $forceModeration = false;
     $overrideApproval = false;
     if ($guestPosting && $checkSpam) {
         $commentData['comment_approved'] = wp_allow_comment($commentData);
         if (!$commentData['comment_approved'] || $commentData['comment_approved'] == 'spam') {
             $forceModeration = true;
         } else {
             // if the comment has passed checks, and we are overriding phpBB approval settings
             if ($this->get_setting('xpostspam') == 'all') {
                 $overrideApproval = true;
             }
         }
     }
     $phpbbForum->foreground();
     wpu_html_to_bbcode($content);
     $content = utf8_normalize_nfc($content);
     $uid = $poll = $bitfield = $options = '';
     generate_text_for_storage($content, $uid, $bitfield, $options, true, true, true);
     require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
     $subject = $dets['post_subject'];
     $data = array('forum_id' => $dets['forum_id'], 'topic_id' => $dets['topic_id'], 'icon_id' => false, 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $content, 'message_md5' => md5($content), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'post_edit_locked' => 0, 'notify_set' => false, 'notify' => false, 'post_time' => 0, 'forum_name' => '', 'enable_indexing' => true, 'topic_title' => $subject, 'post_approved' => 1, 'poster_ip' => '');
     if ($forceModeration) {
         $data['force_approved_state'] = false;
     } else {
         if ($overrideApproval) {
             $data['force_approved_state'] = true;
         }
     }
     $postUrl = submit_post('reply', $subject, $username, POST_NORMAL, $poll, $data);
     // update threading and guest post user data
     if ($postUrl !== false) {
         if ($commentParent || $guestPosting) {
             $sql = 'UPDATE ' . POSTS_TABLE . " SET \n\t\t\t\t\t\tpost_wpu_xpost_parent = {$commentParent}, \n\t\t\t\t\t\tpost_wpu_xpost_meta1 = '" . $db->sql_escape($website) . "', \n\t\t\t\t\t\tpost_wpu_xpost_meta2 = '" . $db->sql_escape($email) . "' \n\t\t\t\t\t\tWHERE post_id = " . (int) $data['post_id'];
             $db->sql_query($sql);
         }
     }
     $commentData = array_merge($commentData, array('comment_ID' => $data['post_id'] + $this->integComments->get_id_offset()));
     $wpComment = (object) $commentData;
     $phpbbForum->restore_state($fStateChanged);
     //set comment cookie
     do_action('set_comment_cookies', $wpComment, $wpUser);
     //prime the comment cache
     if (function_exists('wp_cache_incr')) {
         wp_cache_incr('last_changed', 1, 'comment');
     } else {
         $last_changed = wp_cache_get('last_changed', 'comment');
         wp_cache_set('last_changed', $last_changed + 1, 'comment');
     }
     /**
      * Redirect back to WP if we can.
      * NOTE: if the comment was the first on a new page, this will redirect to the old page, rather than the new
      * one. 
      * @todo: increment page var if necessary, or remove it if comment order is reversed, by adding hidden field with # of comments
      */
     if (!empty($_POST['redirect_to'])) {
         $location = $_POST['redirect_to'] . '#comment-' . $wpComment->comment_ID;
     } else {
         if (!empty($_POST['wpu-comment-redirect'])) {
             $location = urldecode($_POST['wpu-comment-redirect']);
         }
     }
     $location = apply_filters('comment_post_redirect', $location, $wpComment);
     wp_safe_redirect($location);
     exit;
 }