Example #1
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;
 }
Example #2
0
function wpu_newpost($post_ID, $post)
{
    $connSettings = get_settings('wputd_connection');
    global $user_ID, $wpdb, $wp_version;
    $did_xPost = false;
    if ($post->post_status == 'publish') {
        if (!defined('suppress_newpost_action')) {
            //This should only happen ONCE, when the post is initially created.
            update_usermeta($post->post_author, 'wpu_last_post', $post->post_author);
        }
        if (!defined('IN_PHPBB') && !empty($connSettings['logins_integrated'])) {
            global $db, $wpuAbs, $user, $phpEx;
            wpu_enter_phpbb();
            // Update blog link column
            if (!empty($post->post_author)) {
                $sql = 'UPDATE ' . USERS_TABLE . ' SET user_wpublog_id = ' . $post->post_author . " WHERE user_wpuint_id = '{$post->post_author}'";
                if (!($result = $db->sql_query($sql))) {
                    $wpuAbs->err_msg(CRITICAL_ERROR, $wpuAbs->lang('WP_DBErr_Retrieve'), __LINE__, __FILE__, $sql);
                }
                $db->sql_freeresult($result);
            }
            //X-Posting
            mysql_select_db(DBNAME);
            // Cross-post to forums if necessary
            if (isset($_POST['chk_wpuxpost']) && $wpuAbs->user_logged_in() && !isset($_POST['wpu_already_xposted_post'])) {
                if ((int) $_POST['chk_wpuxpost'] && ($forum_id = (int) $_POST['sel_wpuxpost']) && $connSettings['wpu_enable_xpost']) {
                    $can_crosspost_list = wpu_forum_xpost_list();
                    //Check that we have the authority to cross-post there
                    if (in_array($forum_id, $can_crosspost_list['forum_id'])) {
                        require_once $connSettings['path_to_phpbb'] . 'wp-united/wpu-helper-funcs.' . $phpEx;
                        // Get the post excerpt
                        if (!($excerpt = $post->post_excerpt)) {
                            $excerpt = $post->post_content;
                            if (preg_match('/<!--more(.*?)?-->/', $excerpt, $matches)) {
                                $excerpt = explode($matches[0], $excerpt, 2);
                                $excerpt = $excerpt[0];
                            }
                        }
                        $subject = $wpuAbs->lang('blog_title_prefix') . $post->post_title;
                        $cats = array();
                        $tags = array();
                        $tag_list = '';
                        $cat_list = '';
                        $cats = get_the_category($post_ID);
                        if (sizeof($cats)) {
                            foreach ($cats as $cat) {
                                $cat_list .= empty($cat_list) ? $cat->cat_name : ', ' . $cat->cat_name;
                            }
                        }
                        if ((double) $wp_version >= 2.3) {
                            // Get tags for WP >= 2.3
                            $tags = get_the_term_list($post->ID, 'post_tag', '', ', ', '');
                            if ($tags == "") {
                                $tags = "No tags definied.";
                            }
                        }
                        mysql_select_db($GLOBALS['dbname']);
                        $excerpt = sprintf($wpuAbs->lang('blog_post_intro'), '[url=' . get_permalink($post_ID) . ']', '[/url]') . "\n\n" . $excerpt . "\n\n" . '[b]' . $wpuAbs->lang('blog_post_tags') . '[/b]' . $tag_list . "\n" . '[b]' . $wpuAbs->lang('blog_post_cats') . '[/b]' . $cat_list . "\n" . sprintf($wpuAbs->lang('read_more'), '[url=' . get_permalink($post_ID) . ']', '[/url]');
                        if ($wpuAbs->ver == 'PHPBB3') {
                            $excerpt = utf8_normalize_nfc($excerpt, '', true);
                            $subject = utf8_normalize_nfc($subject, '', true);
                            wpu_html_to_bbcode($excerpt, 0);
                            //$uid=0, but will get removed)
                            $uid = $poll = $bitfield = $options = '';
                            generate_text_for_storage($excerpt, $uid, $bitfield, $options, true, true, true);
                            //fix phpBB SEO mod
                            global $phpbb_seo;
                            if (!empty($phpbb_seo)) {
                                require_once $connSettings['path_to_phpbb'] . 'phpbb_seo/phpbb_seo_class.' . $phpEx;
                                $phpbb_seo = new phpbb_seo();
                            }
                            require_once $connSettings['path_to_phpbb'] . 'includes/functions_posting.' . $phpEx;
                            $data = array('forum_id' => $forum_id, 'icon_id' => false, 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $excerpt, 'message_md5' => md5($excerpt), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'post_edit_locked' => ITEM_LOCKED, 'topic_title' => $subject, 'notify_set' => false, 'notify' => false, 'post_time' => 0, 'forum_name' => '', 'enable_indexing' => true);
                            $topic_url = submit_post('post', $subject, $wpuAbs->phpbb_username(), POST_NORMAL, $poll, $data);
                            //Update the post table with WP post ID so we can remain "in sync" with it (yawn... another query..... need to cut down on these).
                            if (!empty($data['post_id'])) {
                                $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_wpu_xpost = ' . $post_ID . " WHERE post_id = {$data['post_id']}";
                                if (!($result = $db->sql_query($sql))) {
                                    $wpuAbs->err_msg(CRITICAL_ERROR, $wpuAbs->lang('WP_DBErr_Retrieve'), __LINE__, __FILE__, $sql);
                                }
                                $db->sql_freeresult($result);
                                $did_xPost = true;
                            }
                        }
                        //end if phpBB3
                    }
                    //end have authority to x-post
                }
            }
            //end isset & user_logged_in
            wpu_exit_phpbb();
            if ($did_xPost) {
                //Need to do this after we exit phpBB code
                $topic_url = explode("/", $topic_url);
                array_shift($topic_url);
                $topic_url = implode("/", $topic_url);
                if (!empty($connSettings['autolink_xpost'])) {
                    $thePost = array('ID' => $post_ID, 'comment_status' => 'closed', 'post_content' => $post->post_content . "<br /><br /><a href=\"{$topic_url}\" title=\"" . __('Comments') . "\">" . __('Comment on this post in our forums') . "</a>");
                    wp_update_post($thePost);
                }
            }
            define('suppress_newpost_action', TRUE);
        }
        //end ? logins integrated
    }
    //post status: publish
}