示例#1
0
/**
 * What to do when the user is logged out of phpBB
 * in WP-United prior to v0.9.0, we would forcibly log them out
 * However this is left open as a prelude to bi-directional user integration
 */
function wpu_int_phpbb_logged_out()
{
    global $wpuDebug, $phpbbForum, $wpUnited, $current_user;
    // Check if user is logged into WP
    get_currentuserinfo();
    $wpUser = $current_user;
    if (!$wpUser->ID) {
        $wpuDebug->add('phpBB & WP both logged out.');
        return false;
    }
    // no native way to tell if login is persistent
    $persist = (bool) get_user_meta($wpUser->ID, 'wpu-remember-login', true);
    $wpuDebug->add('WP already logged in, phpBB logged out.');
    $createdUser = false;
    $phpbbId = wpu_get_integrated_phpbbuser($wpUser->ID);
    if (!$phpbbId) {
        // The user has no account in phpBB, so we create one:
        if (!$wpUnited->get_setting('integcreatephpbb')) {
            $wpuDebug->add('No integrated phpBB account, leaving unintegrated.');
            return $wpUser->ID;
        }
        $wpuDebug->add('No integrated phpBB account. Creating.');
        // We just create standard users here for now, no setting of roles
        $phpbbId = wpu_create_phpbb_user($wpUser->ID);
        if ($phpbbId == 0) {
            $wpuDebug->add("Couldn't create phpBB user. Giving up.");
            //We couldn't create a user in phPBB. Before we wp_die()d. But just handle it silently.
            return $wpUser->ID;
        }
        $createdUser = true;
        $wpuDebug->add("Created phpBB user ID = {$phpbbId}.");
    }
    $wpuDebug->add("Logging in to integrated phpBB account, user ID = {$phpbbId}.");
    // the user now has an integrated phpBB account, log them into it
    if (headers_sent()) {
        $wpuDebug->add("WARNING: headers have already been sent, won't be able to set phpBB cookie!");
    }
    if ($phpbbForum->create_phpbb_session($phpbbId, $persist)) {
        $wpuDebug->add("Established Session for user {$phpbbId}.");
    } else {
        $wpuDebug->add("Could not establish session for user {$phpbbId}. Maybe they were deleted? Giving up.");
        return $wpUser->ID;
    }
    if ($createdUser) {
        wpu_sync_profiles($wpUsr, $phpbbForum->get_userdata(), 'sync');
    }
    // if this is a phpBB-in-WordPress page, this has probably just been called after phpBB has already been generated.
    if ($wpUnited->should_do_action('template-p-in-w')) {
        wpu_reload_page_if_no_post();
    }
    return $wpUser->ID;
}
示例#2
0
    /**
     * Populates the class with phpBB comments or a count result, according to the query requirements.
     * the query must already have been processed.
     * @return bool true if it is possible to read cross-posted comments here, even if there are none.
     */
    private function perform_phpbb_comment_query()
    {
        global $wpuDebug, $phpbbForum, $auth, $db, $phpEx, $user, $phpbb_root_path;
        $fStateChanged = $phpbbForum->foreground();
        // pull some permissions
        $permissions = array('read_forum' => array_unique(array_keys($auth->acl_getf('f_read', true))), 'edit_own' => array(), 'delete_own' => array(), 'edit_forum' => array(), 'delete_forum' => array(), 'approve_forum' => array());
        // user can't read any forums -- don't bother proceding unless this is a count request.
        // TODO: WordPress sometimes prepares a count based on pulling all records. We may need to move check until later
        if (!sizeof($permissions['read_forum'])) {
            if (!$this->count) {
                $phpbbForum->restore_state($fStateChanged);
                return false;
            }
        } else {
            //Add global topics
            $permissions['read_forum'][] = 0;
            $permissions['edit_own'] = array_unique(array_keys($auth->acl_getf('f_edit')));
            $permissions['delete_own'] = array_unique(array_keys($auth->acl_getf('f_delete')));
            $permissions['edit_forum'] = array_unique(array_keys($auth->acl_getf('m_edit')));
            $permissions['delete_forum'] = array_unique(array_keys($auth->acl_getf('m_delete')));
            if ($this->status != 'approved') {
                $permissions['approve_forum'] = array_unique(array_keys($auth->acl_getf('m_approve')));
            }
        }
        // What are the user's edit permissions?
        // edit own posts
        $canEditIn = array_unique(array_keys($auth->acl_getf('f_edit', true)));
        // edit others
        $canEditOthersIn = array_unique(array_keys($auth->acl_getf('m_edit', true)));
        $phpbbID = $phpbbForum->get_userdata('user_id');
        // Now, time to build the query.... It's a many-faceted one but can be done in one go....
        $where = array();
        if ($this->count) {
            if ($this->groupByStatus) {
                $query = array('SELECT' => 'p.post_approved, COUNT(p.post_id) AS num_total', 'GROUP_BY' => 'p.post_approved');
            } else {
                $query = array('SELECT' => 'COUNT(p.post_id) AS num_total');
            }
        } else {
            $query = array('SELECT' => 'p.post_id, p.poster_id, p.poster_ip, p.post_time, 
								p.post_approved, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, 
								p.enable_sig, p.post_username, p.post_subject, 
								p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.post_edit_locked,
								p.post_wpu_xpost_parent, p.post_wpu_xpost_meta1, p.post_wpu_xpost_meta2,
								t.topic_approved, t.topic_wpu_xpost, t.topic_first_post_id, t.topic_type, 
								t.forum_id, t.topic_id, t.topic_status, t.topic_replies AS all_replies, t.topic_replies_real AS replies, 
								u.user_id, u.username, u.user_wpuint_id, u.user_email', 'ORDER_BY' => $this->phpbbOrderBy . ' ' . $this->order);
            $where[] = '(' . $db->sql_in_set('t.forum_id', $permissions['read_forum']) . ')';
        }
        $query['FROM'] = array(TOPICS_TABLE => 't', POSTS_TABLE => 'p', USERS_TABLE => 'u');
        if ($this->postID) {
            $where[] = sprintf('(t.topic_wpu_xpost = %d)', $this->postID);
        } else {
            $where[] = '(t.topic_wpu_xpost > 0)';
        }
        if ($this->userID) {
            $where[] = sprintf('(u.user_wpuint_id = %d)', $this->userID);
        }
        if ($this->userEmail) {
            $string = esc_sql(like_escape($this->userEmail));
            $where[] = "(u.user_email LIKE '%" . $db->sql_escape($string) . "%')";
        }
        if ($this->topicUser) {
            $where[] = sprintf("(t.topic_poster = %d)", wpu_get_integrated_phpbbuser($this->topicUser));
        }
        if ($this->parentID) {
            $where[] = sprintf("(p.post_wpu_xpost_parent = %d)");
        }
        $canViewUnapproved = sizeof($permissions['approve_forum']) ? $db->sql_in_set('t.forum_id', $permissions['approve_forum']) . ' OR ' : '';
        if ($this->status == 'unapproved') {
            $where[] = '(p.post_approved = 0 AND (' . $canViewUnapproved . ' 
				u.user_id = ' . $phpbbID . ' 
				))';
        } else {
            if ($this->status == 'approved') {
                $where[] = '(p.post_approved = 1)';
            } else {
                $where[] = '(p.post_approved = 1 OR ( 
				p.post_approved = 0 AND (' . $canViewUnapproved . ' 
				u.user_id = ' . $phpbbID . '
				)))';
            }
        }
        $where[] = '
			((p.poster_id = u.user_id) AND 
			(p.topic_id = t.topic_id) AND 
			(t.topic_first_post_id <> p.post_id) AND 
			(t.topic_replies > 0)) ';
        $query['WHERE'] = implode(' AND ', $where);
        // Phew. Done. Now run it.
        $sql = $db->sql_build_query('SELECT', $query);
        $wpuDebug->add('Performing cross-post query: ' . htmlentities(str_replace(array("\n", "\t"), '', $sql . ' LIMIT ' . $this->limit . ' OFFSET ' . $this->offset . ' [real limit: (' . $this->realLimit . ', ' . $this->realOffset . ')]')));
        if (!($result = $db->sql_query_limit($sql, $this->limit, $this->offset))) {
            $db->sql_freeresult($result);
            $phpbbForum->restore_state($fStateChanged);
            return false;
        }
        if ($this->count) {
            if ($this->groupByStatus) {
                // start with inited object
                $stats = $this->result['count-grouped'];
                while ($stat = $db->sql_fetchrow($result)) {
                    if ($stat['post_approved'] == 0) {
                        $stats->moderated = $stat['num_total'];
                    } else {
                        $stats->approved = $stat['num_total'];
                    }
                    $stats->total_comments = $stats->total_comments + $stat['num_total'];
                }
                $this->result['count-phpbb'] = $stats->total_comments;
                $db->sql_freeresult($result);
                // Now we fetch the native WP count
                $phpbbForum->background();
                $wpCount = wp_count_comments($this->postID);
                if (is_object($wpCount)) {
                    $stats->{'post-trashed'} = $wpCount->{'post-trashed'};
                    $stats->trash = $wpCount->trash;
                    $stats->spam = $wpCount->spam;
                    $stats->moderated = $stats->moderated + $wpCount->moderated;
                    $stats->approved = $stats->approved + $wpCount->approved;
                    $stats->total_comments = $stats->total_comments + $wpCount->total_comments;
                }
                $this->result['count-grouped'] = $stats;
                $this->result['count'] = $this->result['count-grouped']->total_comments;
                $this->result['count-wp'] = $wpCount->total_comments;
            } else {
                $countRow = $db->sql_fetchrow($result);
                $count = $countRow['num_total'];
                $this->result['count'] = (int) $count + (int) $this->passedResult;
                $this->result['count-phpbb'] = (int) $count;
                $this->result['count-wp'] = (int) ($count = (int) $this->passedResult);
                $db->sql_freeresult($result);
            }
            $phpbbForum->restore_state($fStateChanged);
            return true;
        }
        $currentCommenter = wp_get_current_commenter();
        $pUsername = $phpbbForum->get_username();
        // Now fill the comments and links arrays
        while ($row = $db->sql_fetchrow($result)) {
            $row['bbcode_options'] = ($row['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($row['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
            // TODO: THIS IS DISABLED, AS COUNTS/LIMITS WERE UNRELIABLE!!!
            if ($row['topic_first_post_id'] == $row['post_id']) {
                // this is a cross-post, not a comment.
                $forumName = $row['forum_id'];
                if ($row['topic_type'] == POST_GLOBAL) {
                    $forumName = $phpbbForum->lang['VIEW_TOPIC_GLOBAL'];
                }
                $args = array('topic_id' => $row['topic_id'], 'post_id' => $row['post_id'], 'subject' => $row['post_subject'], 'forum_id' => $row['forum_id'], 'user_id' => $row['poster_id'], 'replies' => $row['replies'], 'time' => $user->format_date($row['post_time'], "Y-m-d H:i:s"), 'approved' => $row['topic_approved'], 'type' => $row['topic_type'], 'status' => $row['topic_status'], 'forum_name' => $forumName);
                $this->result['xposts'][] = (object) $args;
                $this->result['has_xposts'] = true;
            } else {
                if ($row['user_id'] == ANONYMOUS && !empty($row['post_username'])) {
                    $username = $row['post_username'];
                } else {
                    $username = $row['username'];
                }
                if ($row['user_id'] == ANONYMOUS && !empty($row['post_wpu_xpost_meta1'])) {
                    $website = $row['post_wpu_xpost_meta1'];
                } else {
                    $website = $phpbbForum->get_board_url() . "memberlist.{$phpEx}?mode=viewprofile&amp;u=" . $row['poster_id'];
                }
                if ($row['user_id'] == ANONYMOUS && !empty($row['post_wpu_xpost_meta2'])) {
                    $email = $row['post_wpu_xpost_meta2'];
                } else {
                    $email = $row['user_email'];
                }
                if (!$row['post_approved'] && $this->hideOtherUnapproved) {
                    if ($row['user_id'] == ANONYMOUS && (empty($currentCommenter['comment_author']) || $currentCommenter['comment_author'] != $username)) {
                        continue;
                    } else {
                        if ($row['user_id'] != ANONYMOUS && (empty($pUsername) || $pUsername != $username)) {
                            continue;
                        }
                    }
                }
                $parentPost = empty($this->postID) ? $row['topic_wpu_xpost'] : $this->postID;
                $commentID = $this->idOffset + $row['post_id'];
                $args = array('comment_ID' => $commentID, 'comment_post_ID' => $parentPost, 'comment_author' => $username, 'comment_author_email' => $email, 'comment_author_url' => $website, 'comment_author_IP' => $row['poster_ip'], 'comment_date' => $user->format_date($row['post_time'], "Y-m-d H:i:s"), 'comment_date_gmt' => $user->format_date($row['post_time'] - ($user->timezone + $user->dst), "Y-m-d H:i:s"), 'comment_content' => generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'comment_karma' => 0, 'comment_approved' => $row['post_approved'], 'comment_agent' => 'phpBB forum', 'comment_type' => '', 'comment_parent' => (int) $row['post_wpu_xpost_parent'], 'user_id' => $row['user_wpuint_id'], 'phpbb_id' => $row['poster_id']);
                // Fix relative paths in comment text
                $pathsToFix = array('src="' . $phpbb_root_path, 'href="' . $phpbb_root_path);
                $pathsFixed = array('src="' . $phpbbForum->get_board_url(), 'href="' . $phpbbForum->get_board_url());
                $args['comment_content'] = str_replace($pathsToFix, $pathsFixed, $args['comment_content']);
                $this->result['comments'][] = (object) $args;
                $this->result['has-xposted-comments'] = true;
                // calculate counts anyway, even though this wasn't an explicit count request.
                if ($row['post_approved'] == 0) {
                    $this->result['count-grouped']->moderated++;
                } else {
                    $this->result['count-grouped']->approved++;
                }
                $this->result['count-grouped']->total_comments++;
                // prepare links
                //don't use numerical keys to avoid renumbering on array_merge
                $cID = 'comment' . $commentID;
                $r = $phpbbForum->get_board_url();
                foreach (array('view', 'edit', 'delete', 'approve') as $linkType) {
                    $this->links[$linkType][$cID] = false;
                }
                $this->links['view'][$cID] = $r . ($phpbbForum->seo ? "post{$row['post_id']}.html#p{$row['post_id']}" : "viewtopic.{$phpEx}?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}");
                if (in_array($row['forum_id'], $permissions['edit_own']) && $row['poster_id'] == $phpbbID || in_array($row['forum_id'], $permissions['edit_forum'])) {
                    $this->links['edit'][$cID] = $r . $phpbbForum->append_sid("posting.{$phpEx}?mode=edit&amp;f={$row['forum_id']}&amp;p={$row['post_id']}#start_here");
                }
                if (in_array($row['forum_id'], $permissions['delete_own']) && $row['poster_id'] == $phpbbID || in_array($row['forum_id'], $permissions['delete_forum'])) {
                    $this->links['delete'][$cID] = $r . $phpbbForum->append_sid("posting.{$phpEx}?mode=delete&amp;f={$row['forum_id']}&amp;p={$row['post_id']}");
                }
                if (in_array($row['forum_id'], $permissions['approve_forum'])) {
                    $this->links['approve'][$cID] = $r . $phpbbForum->append_sid("mcp.{$phpEx}?i=queue&amp;mode=approve_details&amp;f={$row['forum_id']}&amp;p={$row['post_id']}#start_here");
                }
            }
            $this->result['count'] = $this->result['count-grouped']->total_comments;
        }
        $db->sql_freeresult($result);
        $phpbbForum->restore_state($fStateChanged);
        return true;
    }
示例#3
0
 /**
  * Sync details when a user's password is reset
  * Note that this happens before the new pw is in the DB.
  * @param object $user user row from DB
  * @param string $new_pass new, unhashed password
  */
 public function password_reset($user, $new_pass)
 {
     global $phpbbForum;
     if ($this->get_setting('integrateLogin')) {
         $wpData = get_userdata($user->ID);
         //user phpBB password format for syncing
         set_var($phpbbPass, stripslashes($new_pass), 'string', true);
         $wpData->data->user_pass = wp_hash_password($phpbbPass);
         $phpbbID = wpu_get_integrated_phpbbuser($userID);
         if ($phpbbID) {
             wpu_sync_profiles($wpData, $phpbbForum->get_userdata('', $phpbbID), 'wp-update', false);
         }
     }
 }
示例#4
0
/**
 * Returns a link to the user's phpBB profile without displaying it
 * @param int $wpID the WordPress ID, leave blank for currently logged-in user
 */
function get_wpu_phpbb_profile_link($wpID = false)
{
    global $phpbbForum, $wpUnited, $phpEx;
    if (!$wpUnited->is_working()) {
        return false;
    }
    if ($wpID == false) {
        if (!$phpbbForum->user_logged_in()) {
            return false;
        } else {
            $phpbbID = $phpbbForum->get_userdata('user_id');
        }
    } else {
        if (!$wpUnited->get_setting('integrateLogin')) {
            return false;
        } else {
            $phpbbID = wpu_get_integrated_phpbbuser($wpID);
        }
    }
    if ($phpbbID) {
        $profile_path = "memberlist.{$phpEx}";
        return add_trailing_slash($phpbbForum->get_board_url()) . "{$profile_path}?mode=viewprofile&amp;u={$phpbbID}";
    }
    return false;
}