Exemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     // Create new forum
     $this->forum_id = bbp_insert_forum(array('post_title' => 'test-forum', 'post_status' => 'publish'));
     // Create new topic
     $this->topic_id = bbp_insert_topic(array('post_parent' => $this->forum_id, 'post_title' => 'test-topic', 'post_content' => $this->topic_body, 'post_author' => 1), array('forum_id' => $this->forum_id));
     // Create new reply
     $this->reply_id = bbp_insert_reply(array('post_parent' => $this->topic_id, 'post_title' => 'test-reply', 'post_content' => $this->reply_body, 'post_author' => 1), array('forum_id' => $this->forum_id, 'topic_id' => $this->topic_id));
     add_filter('bbpnns_dry_run', '__return_true');
     // Non-spam, non-empty recipents
     $recipients = array('administrator', 'subscriber');
     update_option('bbpress_notify_newtopic_recipients', $recipients);
     $subs_id = $this->factory->user->create(array('role' => 'subscriber'));
 }
Exemplo n.º 2
0
 public function handle_insert($value, Falcon_Reply $reply)
 {
     if (!empty($value)) {
         return $value;
     }
     $post = get_post($reply->post);
     if (!$this->is_allowed_type($post->post_type)) {
         return $value;
     }
     $user = $reply->get_user();
     if ($reply->is_valid()) {
         Falcon::notify_invalid($user, bbp_get_topic_title($reply->post));
         return false;
     }
     $new_reply = array('post_parent' => $reply->post, 'post_author' => $user->ID, 'post_content' => $reply->parse_body(), 'post_title' => $reply->subject);
     $meta = array('author_ip' => '127.0.0.1', 'forum_id' => bbp_get_topic_forum_id($reply->post), 'topic_id' => $reply->post);
     $reply_id = bbp_insert_reply($new_reply, $meta);
     do_action('bbp_new_reply', $reply_id, $meta['topic_id'], $meta['forum_id'], false, $new_reply['post_author']);
     // bbPress removes the user's subscription because bbp_update_reply() is hooked to 'bbp_new_reply' and it checks for $_POST['bbp_topic_subscription']
     bbp_add_user_subscription($new_reply['post_author'], $meta['topic_id']);
     return $reply_id;
 }
Exemplo n.º 3
0
/**
 * Create a default forum, topic, and reply
 *
 * @since bbPress (r3767)
 * @param array $args Array of arguments to override default values
 */
function bbp_create_initial_content($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('forum_parent' => 0, 'forum_status' => 'publish', 'forum_title' => __('General', 'bbpress'), 'forum_content' => __('General chit-chat', 'bbpress'), 'topic_title' => __('Hello World!', 'bbpress'), 'topic_content' => __('I am the first topic in your new forums.', 'bbpress'), 'reply_title' => __('Re: Hello World!', 'bbpress'), 'reply_content' => __('Oh, and this is what a reply looks like.', 'bbpress')), 'create_initial_content');
    // Create the initial forum
    $forum_id = bbp_insert_forum(array('post_parent' => $r['forum_parent'], 'post_status' => $r['forum_status'], 'post_title' => $r['forum_title'], 'post_content' => $r['forum_content']));
    // Create the initial topic
    $topic_id = bbp_insert_topic(array('post_parent' => $forum_id, 'post_title' => $r['topic_title'], 'post_content' => $r['topic_content']), array('forum_id' => $forum_id));
    // Create the initial reply
    $reply_id = bbp_insert_reply(array('post_parent' => $topic_id, 'post_title' => $r['reply_title'], 'post_content' => $r['reply_content']), array('forum_id' => $forum_id, 'topic_id' => $topic_id));
    return array('forum_id' => $forum_id, 'topic_id' => $topic_id, 'reply_id' => $reply_id);
}
 function Comments_array($comments, $post_ID)
 {
     $post = get_post($post_ID);
     $user_ID = self::Get_user_ID($post);
     update_option(c_al2fb_log_importing, true);
     // Integration?
     if ($user_ID && !self::Is_excluded($post) && $post->post_type != 'reply' && !get_post_meta($post->ID, c_al2fb_meta_nointegrate, true) && $post->comment_status == 'open') {
         // Get time zone offset
         $tz_off = get_option('gmt_offset');
         if (empty($tz_off)) {
             $tz_off = 0;
         }
         $tz_off = apply_filters('al2fb_gmt_offset', $tz_off);
         $tz_off = $tz_off * 3600;
         // Get Facebook comments
         if (self::Is_recent($post) && get_user_meta($user_ID, c_al2fb_meta_fb_comments, true)) {
             $fb_comments = WPAL2Int::Get_comments_or_likes($post, false);
             if ($fb_comments && $fb_comments->data) {
                 // Get WordPress comments
                 $stored_comments = get_comments('post_id=' . $post->ID);
                 $stored_comments = array_merge($stored_comments, get_comments('status=spam&post_id=' . $post->ID));
                 $stored_comments = array_merge($stored_comments, get_comments('status=trash&post_id=' . $post->ID));
                 $stored_comments = array_merge($stored_comments, get_comments('status=hold&post_id=' . $post->ID));
                 $deleted_fb_comment_ids = get_post_meta($post->ID, c_al2fb_meta_fb_comment_id, false);
                 foreach ($fb_comments->data as $fb_comment) {
                     if (!empty($fb_comment->id)) {
                         $search_comment_id = end(explode('_', $fb_comment->id));
                         // Check if stored comment
                         $stored = false;
                         if ($stored_comments) {
                             foreach ($stored_comments as $comment) {
                                 $fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true);
                                 if ($search_comment_id == end(explode('_', $fb_comment_id))) {
                                     $stored = true;
                                     break;
                                 }
                             }
                         }
                         // Check if deleted comment
                         if (!$stored && $deleted_fb_comment_ids) {
                             foreach ($deleted_fb_comment_ids as $deleted_fb_comment_id) {
                                 if ($search_comment_id == end(explode('_', $deleted_fb_comment_id))) {
                                     $stored = true;
                                     break;
                                 }
                             }
                         }
                         // Create new comment
                         if (!$stored) {
                             $name = $fb_comment->from->name . ' ' . __('on Facebook', c_al2fb_text_domain);
                             if ($post->post_type == 'topic') {
                                 // bbPress
                                 $reply_id = bbp_insert_reply(array('post_parent' => $post_ID, 'post_content' => $fb_comment->message, 'post_status' => 'draft'), array('forum_id' => bbp_get_topic_forum_id($post_ID), 'topic_id' => $post_ID, 'anonymous_name' => $name));
                                 // Add data
                                 add_post_meta($reply_id, c_al2fb_meta_link_id, $fb_comment->id);
                                 add_post_meta($post_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id);
                                 // Publish
                                 $reply = array();
                                 $reply['ID'] = $reply_id;
                                 $reply['post_status'] = 'publish';
                                 wp_update_post($reply);
                             } else {
                                 $comment_ID = $fb_comment->id;
                                 $commentdata = array('comment_post_ID' => $post_ID, 'comment_author' => $name, 'comment_author_email' => $fb_comment->from->id . '@facebook.com', 'comment_author_url' => WPAL2Int::Get_fb_profilelink($fb_comment->from->id), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time) + $tz_off), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time)), 'comment_content' => $fb_comment->message, 'comment_karma' => 0, 'comment_approved' => 1, 'comment_agent' => 'AL2FB', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 0);
                                 // Assign parent comment id
                                 if (!empty($fb_comment->parent->id)) {
                                     $parent_args = array('post_id' => $post_ID, 'meta_query' => array(array('key' => c_al2fb_meta_fb_comment_id, 'value' => $fb_comment->parent->id)));
                                     $parent_comments_query = new WP_Comment_Query();
                                     $parent_comments = $parent_comments_query->query($parent_args);
                                     if (isset($parent_comments) && count($parent_comments) == 1) {
                                         $commentdata['comment_parent'] = $parent_comments[0]->comment_ID;
                                     }
                                 }
                                 $commentdata = apply_filters('al2fb_preprocess_comment', $commentdata, $post);
                                 // Copy Facebook comment to WordPress database
                                 if (get_user_meta($user_ID, c_al2fb_meta_fb_comments_copy, true)) {
                                     // Apply filters
                                     if (get_option(c_al2fb_option_nofilter_comments)) {
                                         $commentdata['comment_approved'] = '1';
                                     } else {
                                         $commentdata = apply_filters('preprocess_comment', $commentdata);
                                         $commentdata = wp_filter_comment($commentdata);
                                         $commentdata['comment_approved'] = wp_allow_comment($commentdata);
                                     }
                                     // Insert comment in database
                                     $comment_ID = wp_insert_comment($commentdata);
                                     add_comment_meta($comment_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id);
                                     do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
                                     // Notify
                                     if ('spam' !== $commentdata['comment_approved']) {
                                         if ('0' == $commentdata['comment_approved']) {
                                             wp_notify_moderator($comment_ID);
                                         }
                                         if (get_option('comments_notify') && $commentdata['comment_approved']) {
                                             wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
                                         }
                                     }
                                 } else {
                                     $commentdata['comment_approved'] = '1';
                                 }
                                 // Add comment to array
                                 if ($commentdata['comment_approved'] == 1) {
                                     $new = new stdClass();
                                     $new->comment_ID = $comment_ID;
                                     $new->comment_post_ID = $commentdata['comment_post_ID'];
                                     $new->comment_author = $commentdata['comment_author'];
                                     $new->comment_author_email = $commentdata['comment_author_email'];
                                     $new->comment_author_url = $commentdata['comment_author_url'];
                                     $new->comment_author_ip = $commentdata['comment_author_IP'];
                                     $new->comment_date = $commentdata['comment_date'];
                                     $new->comment_date_gmt = $commentdata['comment_date_gmt'];
                                     $new->comment_content = stripslashes($commentdata['comment_content']);
                                     $new->comment_karma = $commentdata['comment_karma'];
                                     $new->comment_approved = $commentdata['comment_approved'];
                                     $new->comment_agent = $commentdata['comment_agent'];
                                     $new->comment_type = $commentdata['comment_type'];
                                     $new->comment_parent = $commentdata['comment_parent'];
                                     $new->user_id = $commentdata['user_id'];
                                     $comments[] = $new;
                                 }
                             }
                         }
                     } else {
                         if ($this->debug) {
                             add_post_meta($post->ID, c_al2fb_meta_log, date('c') . ' Missing FB comment id: ' . print_r($fb_comment, true));
                         }
                     }
                 }
             }
         }
         // Get likes
         if (self::Is_recent($post) && $post->ping_status == 'open' && get_user_meta($user_ID, c_al2fb_meta_fb_likes, true)) {
             $fb_likes = WPAL2Int::Get_comments_or_likes($post, true);
             if ($fb_likes && $fb_likes->data) {
                 foreach ($fb_likes->data as $fb_like) {
                     // Create new virtual comment
                     $link = WPAL2Int::Get_fb_profilelink($fb_like->id);
                     $new = new stdClass();
                     $new->comment_ID = $fb_like->id;
                     $new->comment_post_ID = $post_ID;
                     $new->comment_author = $fb_like->name . ' ' . __('on Facebook', c_al2fb_text_domain);
                     $new->comment_author_email = '';
                     $new->comment_author_url = $link;
                     $new->comment_author_ip = '';
                     $new->comment_date_gmt = date('Y-m-d H:i:s', time());
                     $new->comment_date = $new->comment_date_gmt;
                     $new->comment_content = '<em>' . __('Liked this post', c_al2fb_text_domain) . '</em>';
                     $new->comment_karma = 0;
                     $new->comment_approved = 1;
                     $new->comment_agent = 'AL2FB';
                     $new->comment_type = 'pingback';
                     $new->comment_parent = 0;
                     $new->user_id = 0;
                     $comments[] = $new;
                 }
             }
         }
         // Sort comments by time
         if (!empty($fb_comments) || !empty($fb_likes)) {
             usort($comments, array(&$this, 'Comment_compare'));
             if (get_option('comment_order') == 'desc') {
                 array_reverse($comments);
             }
         }
     }
     // Comment link type
     $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true);
     $comments_nolink = get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true);
     if (empty($comments_nolink)) {
         $comments_nolink = 'author';
     } else {
         if ($comments_nolink == 'on' || empty($link_id)) {
             $comments_nolink = 'none';
         }
     }
     if ($comments_nolink == 'none' || $comments_nolink == 'link') {
         $link = WPAL2Int::Get_fb_permalink($link_id);
         if ($comments) {
             foreach ($comments as $comment) {
                 if ($comment->comment_agent == 'AL2FB') {
                     if ($comments_nolink == 'none') {
                         $comment->comment_author_url = '';
                     } else {
                         if ($comments_nolink == 'link') {
                             $comment->comment_author_url = $link;
                         }
                     }
                 }
             }
         }
     }
     // Permission to view?
     $min_cap = get_option(c_al2fb_option_min_cap_comment);
     if ($min_cap && !current_user_can($min_cap)) {
         if ($comments) {
             for ($i = 0; $i < count($comments); $i++) {
                 if ($comments[$i]->comment_agent == 'AL2FB') {
                     unset($comments[$i]);
                 }
             }
         }
     }
     return $comments;
 }
Exemplo n.º 5
0
function custom_bbp_reply_create()
{
    $reply_id = bbp_insert_reply(array('post_parent' => $_POST['bbp_topic_id'], 'post_content' => $_POST['content'], 'post_title' => mb_strlen($_POST['content']) > 100 ? mb_substr($_POST['content'], 0, 100) . '...' : $_POST['content']), array('forum_id' => $_POST['bbp_forum_id'], 'topic_id' => $_POST['bbp_topic_id']));
    echo $reply_id;
    update_comment_meta($reply_id, 'attaches', $_POST['attaches']);
    do_action('nbbi_insert_any', $reply_id);
}
Exemplo n.º 6
0
 /**
  * Perform the export
  *
  * @access public
  * @since 1.0
  * @uses bbp_Export::csv_rows_out()
  * @return void
  */
 public function import()
 {
     if (!$this->can_import()) {
         wp_die(__('You do not have permission to import data.', 'bbp-export-import'), __('Error', 'bbp-export-import'));
     }
     $csv_array = $this->csv_to_array($_FILES['bbp_csv_file']['tmp_name'], ';');
     foreach ($csv_array as $key => $line) {
         $post_args = $line;
         $meta_args = array();
         // Setup author date
         if ($post_args['anonymous'] == '1') {
             $meta_args['anonymous_email'] = $line['post_author'];
         } else {
             $user = get_user_by('email', $post_args['post_author']);
             if (!$user) {
                 // The user doesn't exist, so create them
                 $user = wp_insert_user(array('user_email' => $post_args['post_author'], 'user_login' => $post_args['user_login']));
             }
             $post_args['post_author'] = $user->ID;
         }
         // Decode content
         $post_args['post_content'] = html_entity_decode($post_args['post_content']);
         $topic_type = bbp_get_topic_post_type();
         $reply_type = bbp_get_reply_post_type();
         // Remove the post args we don't want sent to wp_insert_post
         unset($post_args['anonymous']);
         unset($post_args['user_login']);
         switch ($line['post_type']) {
             case $topic_type:
                 // Set the forum parent for topics
                 $post_args['post_parent'] = $this->forum_id;
                 $meta_args['voice_count'] = $line['voices'];
                 $meta_args['reply_count'] = $post_args['reply_count'];
                 $topic_id = bbp_insert_topic($post_args, $meta_args);
                 // Subscribe the original poster to the topic
                 bbp_add_user_subscription($post_args['post_author'], $topic_id);
                 // Add the topic to the user's favorites
                 if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) {
                     bbp_add_user_favorite($post_args['post_author'], $topic_id);
                 }
                 // Set topic as resolved if GetShopped Support Forum is active
                 if ($post_args['resolved'] == '1') {
                     add_post_meta($topic_id, '_bbps_topic_status', '2');
                 }
                 break;
             case $reply_type:
                 // Set the forum parent for replies. The topic ID is created above when the replie's topic is first created
                 $post_args['post_parent'] = $topic_id;
                 $reply_id = bbp_insert_reply($post_args, $meta_args);
                 // Subscribe reply author, if not already
                 if (!bbp_is_user_subscribed($post_args['post_author'], $topic_id)) {
                     bbp_add_user_subscription($post_args['post_author'], $topic_id);
                 }
                 // Mark as favorite
                 if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) {
                     bbp_add_user_favorite($post_args['post_author'], $topic_id);
                 }
                 // Check if the next row is a topic, meaning we have reached the last reply and need to update the last active time
                 if ($csv_array[$key + 1]['post_type'] == bbp_get_topic_post_type()) {
                     bbp_update_forum_last_active_time($this->forum_id, $post_args['post_date']);
                 }
                 break;
         }
     }
     // Recount forum topic / reply counts
     bbp_admin_repair_forum_topic_count();
     bbp_admin_repair_forum_reply_count();
     wp_redirect(admin_url('post.php?post=' . $this->forum_id . '&action=edit'));
     exit;
 }
Exemplo n.º 7
0
 public function create_object($args)
 {
     $reply_meta = isset($args['reply_meta']) ? $args['reply_meta'] : array();
     $reply_data = bbp_insert_reply($args, $reply_meta);
     return $reply_data;
 }
Exemplo n.º 8
0
/**
 * Create bbPress replies with existing comments on a post
 * 
 * @author javiarques
 * @param int $post_id ID of the post whose comments to import to topic
 * @param int $topic_id ID of the topic where comments will be added as replies
 */
function bbppt_import_comments($post_id, $topic_id)
{
    $topic_forum = bbp_get_topic_forum_id($topic_id);
    /** getting post comments */
    $post_comments = get_comments(array('post_id' => $post_id, 'order' => 'ASC'));
    $imported_comment_count = 0;
    if ($post_comments) {
        foreach ($post_comments as $post_comment) {
            if (!empty($post_comment->comment_type)) {
                continue;
            }
            /** Allow individual comments to be skipped with `bbppt_do_import_comment` filter
             *  By default, skip comments that have already been imported
             */
            if (!apply_filters('bbppt_do_import_comment', !get_comment_meta($post_comment->comment_ID, 'bbppt_imported', true), $post_comment)) {
                continue;
            }
            // If user is not registered
            if (empty($post_comment->user_id)) {
                // 1. Check if user exists by email
                if (!empty($post_comment->comment_author_email)) {
                    $existing_user = get_user_by('email', $post_comment->comment_author_email);
                    if ($existing_user) {
                        $post_comment->user_id = $existing_user->ID;
                    }
                }
            }
            // Reply data
            $reply_data = array('post_parent' => $topic_id, 'post_status' => bbp_get_public_status_id(), 'post_type' => bbp_get_reply_post_type(), 'post_author' => $post_comment->user_id, 'post_content' => apply_filters('bbppt_imported_comment_content', $post_comment->comment_content, $post_comment), 'post_date' => $post_comment->comment_date, 'post_date_gmt' => $post_comment->comment_date_gmt, 'post_modified' => $post_comment->comment_date, 'post_modified_gmt' => $post_comment->comment_date_gmt);
            // Reply meta
            $reply_meta = array('author_ip' => $post_comment->comment_author_IP, 'forum_id' => $topic_forum, 'topic_id' => $topic_id, 'imported_comment_id' => $post_comment->comment_ID);
            // If not registered user, add anonymous user information
            if (empty($post_comment->user_id)) {
                // Parse args
                $anonymous = array('anonymous_name' => $post_comment->comment_author, 'anonymous_email' => $post_comment->comment_author_email, 'anonymous_website' => $post_comment->comment_author_url);
                $reply_meta = wp_parse_args($reply_meta, $anonymous);
            }
            $reply_id = bbp_insert_reply($reply_data, $reply_meta);
            update_comment_meta($post_comment->comment_ID, 'bbppt_imported', true);
            do_action('bbppt_comment_imported', $post_comment, $post_id, $topic_id);
            $imported_comment_count++;
        }
        // Update the reply count meta value to reflect imported comments
        bbp_bump_topic_reply_count($topic_id, $imported_comment_count - 1);
    }
}