function bbps_is_reply_premium()
{
    $is_premium = get_post_meta(bbp_get_reply_forum_id(), '_bbps_is_premium');
    if ($is_premium[0] == 1) {
        return true;
    } else {
        return false;
    }
}
Example #2
0
 /**
  * @covers ::bbp_update_reply_forum_id
  */
 public function test_bbp_update_reply_forum_id()
 {
     bbp_create_initial_content();
     $forum_id = 36;
     $topic_id = 37;
     $reply_id = 38;
     bbp_update_reply_forum_id($reply_id, $forum_id);
     $reply_forum_id = bbp_get_reply_forum_id($reply_id);
     $this->assertSame(36, $reply_forum_id);
 }
 /**
  * Verify access to the current content.
  *
  * @since  1.0.0
  *
  * @param int $id The content post ID to verify access.
  * @return bool|null True if has access, false otherwise.
  *     Null means: Rule not relevant for current page.
  */
 public function has_access($id, $admin_has_access = true)
 {
     global $wp_query;
     $has_access = null;
     if (empty($id)) {
         $id = $this->get_current_post_id();
     }
     if (!empty($id)) {
         $post_type = get_post_type($id);
         if (in_array($post_type, self::get_bb_cpt())) {
             $has_access = false;
             // Only verify permission if addon is enabled.
             if (MS_Addon_Bbpress::is_active()) {
                 switch ($post_type) {
                     case self::CPT_BB_FORUM:
                         $has_access = parent::has_access($id, $admin_has_access);
                         break;
                     case self::CPT_BB_TOPIC:
                         if (function_exists('bbp_get_topic_forum_id')) {
                             $forum_id = bbp_get_topic_forum_id($id);
                             $has_access = parent::has_access($forum_id, $admin_has_access);
                         }
                         break;
                     case self::CPT_BB_REPLY:
                         if (function_exists('bbp_get_reply_forum_id')) {
                             $forum_id = bbp_get_reply_forum_id($id);
                             $has_access = parent::has_access($forum_id, $admin_has_access);
                         }
                         break;
                 }
             } else {
                 $has_access = true;
             }
         }
     } else {
         /*
          * If post type is forum and no post_id, it is the forum list page, give access.
          * @todo Find another way to verify if the current page is the forum list page.
          */
         if (self::CPT_BB_FORUM === $wp_query->get('post_type')) {
             $has_access = true;
         }
     }
     return apply_filters('ms_addon_bbpress_model_rule_has_access', $has_access, $id, $this);
 }
Example #4
0
 static function nav_menu_css_class($classes, $item, $args, $depth)
 {
     if ($item->object == bbp_get_forum_post_type() && is_bbpress()) {
         if (bbp_is_topic_edit() || bbp_is_single_topic()) {
             $forum_id = bbp_get_topic_forum_id();
             if ($forum_id == $item->object_id) {
                 $classes[] = 'current-menu-parent';
                 $classes[] = 'current-' . bbp_get_topic_post_type() . '-parent';
             } elseif ($ancestors = self::forum_ancestors($forum_id, array())) {
                 if (in_array($item->object_id, $ancestors)) {
                     $classes[] = 'current-menu-ancestor';
                     $classes[] = 'current-' . bbp_get_topic_post_type() . '-ancestor';
                 }
             }
         } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) {
             $forum_id = bbp_get_reply_forum_id();
         }
     }
     return $classes;
 }
function tehnik_bpp_get_forum_id_from_post_id($post_id, $post_type)
{
    $forum_id = 0;
    // Check post type
    switch ($post_type) {
        // Forum
        case bbp_get_forum_post_type():
            $forum_id = bbp_get_forum_id($post_id);
            break;
            // Topic
        // Topic
        case bbp_get_topic_post_type():
            $forum_id = bbp_get_topic_forum_id($post_id);
            break;
            // Reply
        // Reply
        case bbp_get_reply_post_type():
            $forum_id = bbp_get_reply_forum_id($post_id);
            break;
    }
    return $forum_id;
}
/**
 * Checks if a post (or any post type) has the given meta key of 'Stylesheet' when on the singular view of 
 * the post on the front of the site.  If found, the function checks within the '/css' folder of the stylesheet 
 * directory (child theme) and the template directory (parent theme).  If the file exists, it is used rather 
 * than the typical style.css file.
 *
 * @since 0.1.0
 * @todo Use features from Ticket #18302 when available. http://core.trac.wordpress.org/ticket/18302
 * @access public
 * @param string $stylesheet_uri The URI of the active theme's stylesheet.
 * @param string $stylesheet_dir_uri The directory URI of the active theme's stylesheet.
 * @return string $stylesheet_uri
 */
function post_stylesheets_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri)
{
    /* Check if viewing a singular post. */
    if (is_singular()) {
        /* If viewing a bbPress topic, use its forum object. */
        if (function_exists('bbp_is_single_topic') && bbp_is_single_topic()) {
            $post = get_post(bbp_get_topic_forum_id(get_queried_object_id()));
        } elseif (function_exists('bbp_is_single_reply') && bbp_is_single_reply()) {
            $post = get_post(bbp_get_reply_forum_id(get_queried_object_id()));
        } else {
            $post = get_queried_object();
        }
        /* Check if the post type supports 'post-stylesheets' before proceeding. */
        if (post_type_supports($post->post_type, 'post-stylesheets')) {
            /* Check if the user has set a value for the post stylesheet. */
            $stylesheet = get_post_stylesheet($post->ID);
            /* If a meta value was given and the file exists, set $stylesheet_uri to the new file. */
            if (!empty($stylesheet)) {
                /* If the stylesheet is found in the child theme, use it. */
                if (file_exists(trailingslashit(get_stylesheet_directory()) . $stylesheet)) {
                    $stylesheet_uri = trailingslashit($stylesheet_dir_uri) . $stylesheet;
                } elseif (file_exists(trailingslashit(get_template_directory()) . $stylesheet)) {
                    $stylesheet_uri = trailingslashit(get_template_directory_uri()) . $stylesheet;
                } else {
                    /* If the stylesheet is found in the child theme '/css' folder, use it. */
                    if (file_exists(trailingslashit(get_stylesheet_directory()) . "css/{$stylesheet}")) {
                        $stylesheet_uri = trailingslashit($stylesheet_dir_uri) . "css/{$stylesheet}";
                        /* Set the post stylesheet to the correct directory. */
                        set_post_stylesheet($post->ID, str_replace(get_stylesheet_directory_uri(), 'css/', $stylesheet_uri));
                    } elseif (file_exists(trailingslashit(get_template_directory()) . "css/{$stylesheet}")) {
                        $stylesheet_uri = trailingslashit(get_template_directory_uri()) . "css/{$stylesheet}";
                        /* Set the post stylesheet to the correct directory. */
                        set_post_stylesheet($post->ID, str_replace(get_template_directory_uri(), 'css/', $stylesheet_uri));
                    }
                }
            }
        }
    }
    /* Return the stylesheet URI. */
    return $stylesheet_uri;
}
Example #7
0
/**
 * Check if it's a private forum or a topic or reply of a private forum and if
 * the user can't view it, then sets a 404
 *
 * @since bbPress (r2996)
 *
 * @uses current_user_can() To check if the current user can read private forums
 * @uses is_singular() To check if it's a singular page
 * @uses bbp_is_user_keymaster() To check if user is a keymaster
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() TO get the reply post type
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses bbp_is_forum_private() To check if the forum is private or not
 * @uses bbp_set_404() To set a 404 status
 */
function bbp_forum_enforce_private()
{
    // Bail if not viewing a single item or if user has caps
    if (!is_singular() || bbp_is_user_keymaster() || current_user_can('read_private_forums')) {
        return;
    }
    global $wp_query;
    // Define local variable
    $forum_id = 0;
    // Check post type
    switch ($wp_query->get('post_type')) {
        // Forum
        case bbp_get_forum_post_type():
            $forum_id = bbp_get_forum_id($wp_query->post->ID);
            break;
            // Topic
        // Topic
        case bbp_get_topic_post_type():
            $forum_id = bbp_get_topic_forum_id($wp_query->post->ID);
            break;
            // Reply
        // Reply
        case bbp_get_reply_post_type():
            $forum_id = bbp_get_reply_forum_id($wp_query->post->ID);
            break;
    }
    // If forum is explicitly hidden and user not capable, set 404
    if (!empty($forum_id) && bbp_is_forum_private($forum_id) && !current_user_can('read_private_forums')) {
        bbp_set_404();
    }
}
/**
 * Walk up the ancestor tree from the current reply, and update all the counts
 *
 * @since bbPress (r2884)
 *
 * @param int $reply_id Optional. Reply id
 * @param string $last_active_time Optional. Last active time
 * @param int $forum_id Optional. Forum id
 * @param int $topic_id Optional. Topic id
 * @param bool $refresh If set to true, unsets all the previous parameters.
 *                       Defaults to true
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses get_post_ancestors() To get the ancestors of the reply
 * @uses bbp_is_reply() To check if the ancestor is a reply
 * @uses bbp_is_topic() To check if the ancestor is a topic
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_get_topic_last_active_id() To get the topic last active id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
 * @uses bbp_update_forum_last_active_id() To update the forum last active id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_update_forum_last_active_time() To update the forum last active time
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 */
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
    // Verify the reply ID
    $reply_id = bbp_get_reply_id($reply_id);
    // Reply was passed
    if (!empty($reply_id)) {
        // Get the topic ID if none was passed
        if (empty($topic_id)) {
            $topic_id = bbp_get_reply_topic_id($reply_id);
        }
        // Get the forum ID if none was passed
        if (empty($forum_id)) {
            $forum_id = bbp_get_reply_forum_id($reply_id);
        }
    }
    // Set the active_id based on topic_id/reply_id
    $active_id = empty($reply_id) ? $topic_id : $reply_id;
    // Setup ancestors array to walk up
    $ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
    // If we want a full refresh, unset any of the possibly passed variables
    if (true === $refresh) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    }
    // Walk up ancestors
    if (!empty($ancestors)) {
        foreach ($ancestors as $ancestor) {
            // Reply meta relating to most recent reply
            if (bbp_is_reply($ancestor)) {
                // @todo - hierarchical replies
                // Topic meta relating to most recent reply
            } elseif (bbp_is_topic($ancestor)) {
                // Last reply and active ID's
                bbp_update_topic_last_reply_id($ancestor, $reply_id);
                bbp_update_topic_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $topic_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
                }
                // Counts
                bbp_update_topic_voice_count($ancestor);
                bbp_update_topic_reply_count($ancestor);
                bbp_update_topic_reply_count_hidden($ancestor);
                // Forum meta relating to most recent topic
            } elseif (bbp_is_forum($ancestor)) {
                // Last topic and reply ID's
                bbp_update_forum_last_topic_id($ancestor, $topic_id);
                bbp_update_forum_last_reply_id($ancestor, $reply_id);
                // Last Active
                bbp_update_forum_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $forum_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
                }
                // Counts
                bbp_update_forum_reply_count($ancestor);
            }
        }
    }
}
Example #9
0
 /**
  * Update the activity stream entry when a reply status changes
  *
  * @param int $post_id
  * @param obj $post
  * @uses get_post_type()
  * @uses bbp_get_reply_post_type()
  * @uses bbp_get_reply_id()
  * @uses bbp_is_reply_anonymous()
  * @uses bbp_get_public_status_id()
  * @uses bbp_get_closed_status_id()
  * @uses bbp_get_reply_topic_id()
  * @uses bbp_get_reply_forum_id()
  * @uses bbp_get_reply_author_id()
  * @return Bail early if not a reply, or reply is by anonymous user
  */
 public function reply_update($reply_id, $post)
 {
     // Bail early if not a reply
     if (get_post_type($post) != bbp_get_reply_post_type()) {
         return;
     }
     $reply_id = bbp_get_reply_id($reply_id);
     // Bail early if reply is by anonymous user
     if (bbp_is_reply_anonymous($reply_id)) {
         return;
     }
     $anonymous_data = array();
     // Action based on new status
     if ($post->post_status == bbp_get_public_status_id()) {
         // Validate reply data
         $topic_id = bbp_get_reply_topic_id($reply_id);
         $forum_id = bbp_get_reply_forum_id($reply_id);
         $reply_author_id = bbp_get_reply_author_id($reply_id);
         $this->reply_create($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author_id);
     } else {
         $this->reply_delete($reply_id);
     }
 }
Example #10
0
/**
 * Replace forum author details for users that cannot view them.
 *
 * @since bbPress (r3162)
 *
 * @param string $retval
 * @param int $forum_id
 *
 * @uses bbp_is_forum_private()
 * @uses get_post_field()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_is_forum_private()
 * @uses bbp_get_topic_forum_id()
 * @uses bbp_get_reply_post_type()
 * @uses bbp_get_reply_forum_id()
 *
 * @return string
 */
function bbp_suppress_private_author_link($author_link, $args)
{
    // Assume the author link is the return value
    $retval = $author_link;
    // Show the normal author link
    if (!empty($args['post_id']) && !current_user_can('read_private_forums')) {
        // What post type are we looking at?
        $post_type = get_post_field('post_type', $args['post_id']);
        switch ($post_type) {
            // Topic
            case bbp_get_topic_post_type():
                if (bbp_is_forum_private(bbp_get_topic_forum_id($args['post_id']))) {
                    $retval = '';
                }
                break;
                // Reply
            // Reply
            case bbp_get_reply_post_type():
                if (bbp_is_forum_private(bbp_get_reply_forum_id($args['post_id']))) {
                    $retval = '';
                }
                break;
                // Post
            // Post
            default:
                if (bbp_is_forum_private($args['post_id'])) {
                    $retval = '';
                }
                break;
        }
    }
    return apply_filters('bbp_suppress_private_author_link', $retval);
}
Example #11
0
 /**
  * Display the contents of a specific reply ID in an output buffer
  * and return to ensure that post/page contents are displayed first.
  *
  * @since bbPress (r3031)
  *
  * @param array $attr
  * @param string $content
  * @uses get_template_part()
  * @return string
  */
 public function display_reply($attr, $content = '')
 {
     // Sanity check required info
     if (!empty($content) || (empty($attr['id']) || !is_numeric($attr['id']))) {
         return $content;
     }
     // Unset globals
     $this->unset_globals();
     // Set passed attribute to $reply_id for clarity
     $reply_id = bbpress()->current_reply_id = $attr['id'];
     $forum_id = bbp_get_reply_forum_id($reply_id);
     // Bail if ID passed is not a reply
     if (!bbp_is_reply($reply_id)) {
         return $content;
     }
     // Reset the queries if not in theme compat
     if (!bbp_is_theme_compat_active()) {
         $bbp = bbpress();
         // Reset necessary forum_query attributes for replys loop to function
         $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
         $bbp->forum_query->in_the_loop = true;
         $bbp->forum_query->post = get_post($forum_id);
         // Reset necessary reply_query attributes for replys loop to function
         $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
         $bbp->reply_query->in_the_loop = true;
         $bbp->reply_query->post = get_post($reply_id);
     }
     // Start output buffer
     $this->start('bbp_single_reply');
     // Check forum caps
     if (bbp_user_can_view_forum(array('forum_id' => $forum_id))) {
         bbp_get_template_part('content', 'single-reply');
         // Forum is private and user does not have caps
     } elseif (bbp_is_forum_private($forum_id, false)) {
         bbp_get_template_part('feedback', 'no-access');
     }
     // Return contents of output buffer
     return $this->end();
 }
 /**
  * @since 1.4
  */
 private function _build_email($type, $post_id)
 {
     $email_subject = get_option("bbpress_notify_new{$type}_email_subject");
     $email_body = get_option("bbpress_notify_new{$type}_email_body");
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $excerpt_size = apply_filters('bpnns_excerpt_size', 100);
     // Replace shortcodes
     if ('topic' === $type) {
         $content = bbp_get_topic_content($post_id);
         $title = html_entity_decode(strip_tags(bbp_get_topic_title($post_id)), ENT_NOQUOTES, 'UTF-8');
         $excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
         $author = bbp_get_topic_author($post_id);
         $url = apply_filters('bbpnns_topic_url', bbp_get_topic_permalink($post_id), $post_id, $title);
         $forum = html_entity_decode(strip_tags(get_the_title(bbp_get_topic_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
     } elseif ('reply' === $type) {
         $content = bbp_get_reply_content($post_id);
         $title = html_entity_decode(strip_tags(bbp_get_reply_title($post_id)), ENT_NOQUOTES, 'UTF-8');
         $excerpt = html_entity_decode(strip_tags(bbp_get_reply_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
         $author = bbp_get_reply_author($post_id);
         $url = apply_filters('bbpnns_reply_url', bbp_get_reply_permalink($post_id), $post_id, $title);
         $forum = html_entity_decode(strip_tags(get_the_title(bbp_get_reply_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
     } else {
         wp_die('Invalid type!');
     }
     $content = preg_replace('/<br\\s*\\/?>/is', PHP_EOL, $content);
     $content = preg_replace('/(?:<\\/p>\\s*<p>)/ism', PHP_EOL . PHP_EOL, $content);
     $content = html_entity_decode(strip_tags($content), ENT_NOQUOTES, 'UTF-8');
     $topic_reply = apply_filters('bbpnns_topic_reply', bbp_get_reply_url($post_id), $post_id, $title);
     $email_subject = str_replace('[blogname]', $blogname, $email_subject);
     $email_subject = str_replace("[{$type}-title]", $title, $email_subject);
     $email_subject = str_replace("[{$type}-content]", $content, $email_subject);
     $email_subject = str_replace("[{$type}-excerpt]", $excerpt, $email_subject);
     $email_subject = str_replace("[{$type}-author]", $author, $email_subject);
     $email_subject = str_replace("[{$type}-url]", $url, $email_subject);
     $email_subject = str_replace("[{$type}-replyurl]", $topic_reply, $email_subject);
     $email_subject = str_replace("[{$type}-forum]", $forum, $email_subject);
     $email_body = str_replace('[blogname]', $blogname, $email_body);
     $email_body = str_replace("[{$type}-title]", $title, $email_body);
     $email_body = str_replace("[{$type}-content]", $content, $email_body);
     $email_body = str_replace("[{$type}-excerpt]", $excerpt, $email_body);
     $email_body = str_replace("[{$type}-author]", $author, $email_body);
     $email_body = str_replace("[{$type}-url]", $url, $email_body);
     $email_body = str_replace("[{$type}-replyurl]", $topic_reply, $email_body);
     $email_body = str_replace("[{$type}-forum]", $forum, $email_body);
     /**
      * Allow subject and body modifications
      * @since 1.6.6
      */
     $email_subject = apply_filters('bbpnns_filter_email_subject_in_build', $email_subject, $type, $post_id);
     $email_body = apply_filters('bbpnns_filter_email_body_in_build', $email_body, $type, $post_id);
     return array($email_subject, $email_body);
 }
Example #13
0
 static function can_download($attachment)
 {
     $attachment = get_post($attachment);
     if (!$attachment || $attachment->post_type != 'attachment') {
         return false;
     }
     $post = get_post($attachment->post_parent);
     $post_type = get_post_type($post);
     $bbp_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
     if (in_array($post_type, $bbp_types)) {
         if (current_user_can('moderate')) {
             return true;
         }
         $forum_id = $post_type == bbp_get_topic_post_type() ? bbp_get_topic_forum_id() : bbp_get_reply_forum_id();
         $allowed_roles = (array) get_option('_bbpkr_download_perms', self::$download_perms);
         if ($use_custom = Permissions::use_custom($forum_id)) {
             $allowed_roles = Permissions::get_forum_perms($use_custom, 'download');
         }
         $can = in_array(bbpresskr()->get_user_role(), $allowed_roles);
     } else {
         // TODO: default user level for download, currently for all
         $can = self::check_user(self::$wp_download_level);
     }
     return $can;
 }
Example #14
0
/**
 * Walk up the ancestor tree from the current reply, and update all the counts
 *
 * @since 2.0.0 bbPress (r2884)
 *
 * @param int $reply_id Optional. Reply id
 * @param string $last_active_time Optional. Last active time
 * @param int $forum_id Optional. Forum id
 * @param int $topic_id Optional. Topic id
 * @param bool $refresh If set to true, unsets all the previous parameters.
 *                       Defaults to true
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses get_post_ancestors() To get the ancestors of the reply
 * @uses bbp_is_reply() To check if the ancestor is a reply
 * @uses bbp_is_topic() To check if the ancestor is a topic
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_get_topic_last_active_id() To get the topic last active id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
 * @uses bbp_update_forum_last_active_id() To update the forum last active id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_update_forum_last_active_time() To update the forum last active time
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 */
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
    // Verify the reply ID
    $reply_id = bbp_get_reply_id($reply_id);
    // Reply was passed
    if (!empty($reply_id)) {
        // Get the topic ID if none was passed
        if (empty($topic_id)) {
            $topic_id = bbp_get_reply_topic_id($reply_id);
            // Make every effort to get topic id
            // https://bbpress.trac.wordpress.org/ticket/2529
            if (empty($topic_id) && current_filter() === 'bbp_deleted_reply') {
                $topic_id = get_post_field('post_parent', $reply_id);
            }
        }
        // Get the forum ID if none was passed
        if (empty($forum_id)) {
            $forum_id = bbp_get_reply_forum_id($reply_id);
        }
    }
    // Set the active_id based on topic_id/reply_id
    $active_id = empty($reply_id) ? $topic_id : $reply_id;
    // Setup ancestors array to walk up
    $ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
    // If we want a full refresh, unset any of the possibly passed variables
    if (true === $refresh) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    }
    // Walk up ancestors
    if (!empty($ancestors)) {
        foreach ($ancestors as $ancestor) {
            // Reply meta relating to most recent reply
            if (bbp_is_reply($ancestor)) {
                // @todo - hierarchical replies
                // Topic meta relating to most recent reply
            } elseif (bbp_is_topic($ancestor)) {
                // Last reply and active ID's
                bbp_update_topic_last_reply_id($ancestor, $reply_id);
                bbp_update_topic_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $topic_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
                }
                // Update the topic last active time regardless of reply status.
                // See https://bbpress.trac.wordpress.org/ticket/2838
                bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
                // Counts
                bbp_update_topic_voice_count($ancestor);
                // Only update reply count if we're deleting a reply, or in the dashboard.
                if (in_array(current_filter(), array('bbp_deleted_reply', 'save_post'), true)) {
                    bbp_update_topic_reply_count($ancestor);
                    bbp_update_topic_reply_count_hidden($ancestor);
                }
                // Forum meta relating to most recent topic
            } elseif (bbp_is_forum($ancestor)) {
                // Last topic and reply ID's
                bbp_update_forum_last_topic_id($ancestor, $topic_id);
                bbp_update_forum_last_reply_id($ancestor, $reply_id);
                // Last Active
                bbp_update_forum_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $forum_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
                }
                // Counts
                // Only update reply count if we're deleting a reply, or in the dashboard.
                if (in_array(current_filter(), array('bbp_deleted_reply', 'save_post'), true)) {
                    bbp_update_forum_reply_count($ancestor);
                }
            }
        }
    }
}
Example #15
0
/**
 * Maps primary capabilities
 *
 * @since 2.2.0 bbPress (r4242)
 *
 * @param array  $caps Capabilities for meta capability.
 * @param string $cap Capability name.
 * @param int    $user_id User id.
 * @param array  $args Arguments.
 * @uses bbp_is_user_inactive() To check if user is spammer or deleted
 * @uses get_post() To get the post
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses bbp_is_user_forum_mod() To check if the user is a forum moderator
 * @uses apply_filters() Filter mapped results
 *
 * @return array Actual capabilities for meta capability
 */
function bbp_map_primary_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        case 'spectate':
            // Do not allow inactive users.
            if (bbp_is_user_inactive($user_id)) {
                $caps = array('do_not_allow');
                // Default to the current cap.
            } else {
                $caps = array($cap);
            }
            break;
        case 'participate':
            // Do not allow inactive users.
            if (bbp_is_user_inactive($user_id)) {
                $caps = array('do_not_allow');
                // Default to the current cap.
            } else {
                $caps = array($cap);
            }
            break;
        case 'moderate':
            // Do not allow inactive users.
            if (bbp_is_user_inactive($user_id)) {
                $caps = array('do_not_allow');
                // Default to the current cap.
            } else {
                $caps = array($cap);
                // Bail if no post to check.
                if (empty($args[0])) {
                    break;
                }
                // Get the post.
                $_post = get_post($args[0]);
                if (empty($_post)) {
                    break;
                }
                // Get forum ID for specific type of post.
                switch ($_post->post_type) {
                    // Forum.
                    case bbp_get_forum_post_type():
                        $forum_id = $_post->ID;
                        break;
                        // Topic.
                    // Topic.
                    case bbp_get_topic_post_type():
                        $forum_id = bbp_get_topic_forum_id($_post->ID);
                        break;
                        // Reply.
                    // Reply.
                    case bbp_get_reply_post_type():
                        $forum_id = bbp_get_reply_forum_id($_post->ID);
                        break;
                        // Any other post type defaults to 0.
                    // Any other post type defaults to 0.
                    default:
                        $forum_id = 0;
                        break;
                }
                // Bail if no forum ID.
                if (empty($forum_id)) {
                    break;
                }
                // If user is a per-forum moderator, make sure they can spectate.
                if (bbp_is_user_forum_mod($user_id, $forum_id)) {
                    $caps = array('spectate');
                }
            }
            break;
    }
    return apply_filters('bbp_map_primary_meta_caps', $caps, $cap, $user_id, $args);
}
Example #16
0
 /**
  * @covers ::bbp_admin_repair_forum_meta
  */
 public function test_bbp_admin_repair_forum_meta()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Forums should NOT have a _bbp_forum_id meta key
     $this->assertEquals(array(), get_post_meta($f, '_bbp_forum_id', false));
     // Topics should have a _bbp_forum_id meta key
     $this->assertSame($f, bbp_get_topic_forum_id($t));
     // Replies should have a _bbp_forum_id meta key
     $this->assertSame($f, bbp_get_reply_forum_id($r));
     // Delete the topic and reply _bbp_forum_id meta key
     $this->assertTrue(delete_post_meta_by_key('_bbp_forum_id'));
     // Check the _bbp_forum_id meta key is deleted
     $this->assertEquals(array(), get_post_meta($f, '_bbp_forum_id', false));
     $this->assertEquals(array(), get_post_meta($t, '_bbp_forum_id', false));
     $this->assertEquals(array(), get_post_meta($r, '_bbp_forum_id', false));
     // Repair the forum meta
     bbp_admin_repair_forum_meta();
     bbp_clean_post_cache($f);
     bbp_clean_post_cache($t);
     bbp_clean_post_cache($r);
     // Forums should NOT have a _bbp_forum_id meta key
     $this->assertEquals(array(), get_post_meta($f, '_bbp_forum_id', false));
     // Topics should have a _bbp_forum_id meta key
     $this->assertEquals(array($f), get_post_meta($t, '_bbp_forum_id', false));
     $this->assertSame($f, bbp_get_topic_forum_id($t));
     // Replies should have a _bbp_forum_id meta key
     $this->assertEquals(array($f), get_post_meta($r, '_bbp_forum_id', false));
     $this->assertSame($f, bbp_get_reply_forum_id($r));
 }
Example #17
0
/**
 * Reply metabox
 *
 * The metabox that holds all of the additional reply information
 *
 * @since 2.0.0 bbPress (r2464)
 *
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses do_action() Calls 'bbp_reply_metabox'
 */
function bbp_reply_metabox()
{
    // Post ID
    $post_id = get_the_ID();
    $status = get_post_status($post_id);
    // Get some meta
    $reply_topic_id = bbp_get_reply_topic_id($post_id);
    $reply_forum_id = bbp_get_reply_forum_id($post_id);
    $topic_forum_id = bbp_get_topic_forum_id($reply_topic_id);
    /** Status ****************************************************************/
    ?>

	<p>
		<strong class="label"><?php 
    esc_html_e('Status:', 'bbpress');
    ?>
</strong>
		<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php 
    echo esc_attr('auto-draft' === $status ? 'draft' : $status);
    ?>
" />
		<label class="screen-reader-text" for="post_status"><?php 
    esc_html_e('Select what status to give the reply.', 'bbpress');
    ?>
</label>
		<?php 
    bbp_form_reply_status_dropdown(array('select_id' => 'post_status', 'reply_id' => $post_id));
    ?>
	</p>

	<hr />

	<?php 
    /** Forum *****************************************************************/
    // Only allow individual manipulation of reply forum if there is a mismatch
    if ($reply_forum_id !== $topic_forum_id && (current_user_can('edit_others_replies') || current_user_can('moderate'))) {
        ?>

		<p>
			<strong class="label"><?php 
        esc_html_e('Forum:', 'bbpress');
        ?>
</strong>
			<label class="screen-reader-text" for="bbp_forum_id"><?php 
        esc_html_e('Forum', 'bbpress');
        ?>
</label>
			<?php 
        bbp_dropdown(array('post_type' => bbp_get_forum_post_type(), 'selected' => $reply_forum_id, 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'walker' => '', 'exclude' => '', 'select_id' => 'bbp_forum_id', 'options_only' => false, 'show_none' => __('&mdash; No reply &mdash;', 'bbpress'), 'disable_categories' => current_user_can('edit_forums'), 'disabled' => ''));
        ?>
		</p>

	<?php 
    }
    /** Topic *****************************************************************/
    ?>

	<p>
		<strong class="label"><?php 
    esc_html_e('Topic:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="parent_id"><?php 
    esc_html_e('Topic', 'bbpress');
    ?>
</label>
		<input name="parent_id" id="bbp_topic_id" type="text" value="<?php 
    echo esc_attr($reply_topic_id);
    ?>
" data-ajax-url="<?php 
    echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'bbp_suggest_topic'), admin_url('admin-ajax.php', 'relative')), 'bbp_suggest_topic_nonce'));
    ?>
" />
	</p>

	<?php 
    /** Reply To **************************************************************/
    ?>

	<p>
		<strong class="label"><?php 
    esc_html_e('Reply To:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="bbp_reply_to"><?php 
    esc_html_e('Reply To', 'bbpress');
    ?>
</label>
		<?php 
    bbp_reply_to_dropdown($post_id);
    ?>
	</p>

	<input name="ping_status" type="hidden" id="ping_status" value="open" />

	<?php 
    wp_nonce_field('bbp_reply_metabox_save', 'bbp_reply_metabox');
    do_action('bbp_reply_metabox', $post_id);
}
/**
 * Maps topic capabilities
 *
 * @since 2.2.0 bbPress (r4242)
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param array $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_is_user_forum_moderator() To check if the user is a forum moderator
 * @uses bbp_get_reply_forum_id() To get the repliy forum id
 * @uses apply_filters() Filter mapped results
 *
 * @return array Actual capabilities for meta capability
 */
function bbp_map_reply_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        /** Reading ***********************************************************/
        case 'read_reply':
            // User cannot spectate
            if (!user_can($user_id, 'spectate')) {
                $caps = array('do_not_allow');
                // Do some post ID based logic
            } else {
                // Get the post
                $_post = get_post($args[0]);
                if (!empty($_post)) {
                    // Get post type object
                    $post_type = get_post_type_object($_post->post_type);
                    // Post is public
                    if (bbp_get_public_status_id() === $_post->post_status) {
                        $caps = array('spectate');
                        // User is author so allow read
                    } elseif ((int) $user_id === (int) $_post->post_author) {
                        $caps = array('spectate');
                        // Unknown so map to private posts
                    } else {
                        $caps = array($post_type->cap->read_private_posts);
                    }
                }
            }
            break;
            /** Publishing ********************************************************/
        /** Publishing ********************************************************/
        case 'publish_replies':
            // Moderators can always publish
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
            }
            break;
            /** Editing ***********************************************************/
            // Used primarily in wp-admin
        /** Editing ***********************************************************/
        // Used primarily in wp-admin
        case 'edit_replies':
        case 'edit_others_replies':
            // Moderators can always edit
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
                // Otherwise, block
            } else {
                $caps = array('do_not_allow');
            }
            break;
            // Used everywhere
        // Used everywhere
        case 'edit_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // User is author so allow edit if not in admin
                } elseif (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps[] = $post_type->cap->edit_posts;
                    // User is a per-forum moderator, make sure they can spectate.
                } elseif (bbp_is_user_forum_moderator($user_id, bbp_get_reply_forum_id($_post->ID))) {
                    $caps = array('spectate');
                    // Fallback to edit_others_posts.
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
            }
            break;
            /** Deleting **********************************************************/
        /** Deleting **********************************************************/
        case 'delete_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // Moderators can always edit forum content
                } elseif (user_can($user_id, 'moderate')) {
                    $caps[] = 'moderate';
                    // User is author so allow edit if not in admin
                } elseif (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps[] = $post_type->cap->delete_posts;
                    // Unknown so map to delete_others_posts
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
            }
            break;
            // Moderation override
        // Moderation override
        case 'delete_replies':
        case 'delete_others_replies':
            // Moderators can always delete
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
            }
            break;
            /** Admin *************************************************************/
        /** Admin *************************************************************/
        case 'bbp_replies_admin':
            $caps = array('moderate');
            break;
    }
    return apply_filters('bbp_map_reply_meta_caps', $caps, $cap, $user_id, $args);
}
Example #19
0
 /**
  * @covers ::bbp_move_topic_handler
  */
 public function test_bbp_move_topic_handler()
 {
     $old_current_user = 0;
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'administrator')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
     $old_forum_id = $this->factory->forum->create();
     $topic_id = $this->factory->topic->create(array('post_parent' => $old_forum_id, 'topic_meta' => array('forum_id' => $old_forum_id)));
     $reply_id = $this->factory->reply->create(array('post_parent' => $topic_id, 'reply_meta' => array('forum_id' => $old_forum_id, 'topic_id' => $topic_id)));
     // Topic post parent
     $topic_parent = wp_get_post_parent_id($topic_id);
     $this->assertSame($old_forum_id, $topic_parent);
     // Forum meta
     $this->assertSame(1, bbp_get_forum_topic_count($old_forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($old_forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($old_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($old_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($old_forum_id));
     // Topic meta
     $this->assertSame($old_forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     // Reply Meta
     $this->assertSame($old_forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
     // Create a new forum
     $new_forum_id = $this->factory->forum->create();
     // Move the topic into the new forum
     bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id);
     // Topic post parent
     $topic_parent = wp_get_post_parent_id($topic_id);
     $this->assertSame($new_forum_id, $topic_parent);
     // Forum meta
     $this->assertSame(1, bbp_get_forum_topic_count($new_forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($new_forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($new_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($new_forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($new_forum_id));
     // Topic meta
     $this->assertSame($new_forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     // Reply Meta
     $this->assertSame($new_forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
     // Retore the user
     $this->set_current_user($this->old_current_user);
 }
Example #20
0
/**
 * Reply metabox
 *
 * The metabox that holds all of the additional reply information
 *
 * @since bbPress (r2464)
 *
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_dropdown() To show a dropdown of the topics for reply parent
 * @uses do_action() Calls 'bbp_reply_metabox'
 */
function bbp_reply_metabox()
{
    // Post ID
    $post_id = get_the_ID();
    // Get some meta
    $reply_topic_id = bbp_get_reply_topic_id($post_id);
    $reply_forum_id = bbp_get_reply_forum_id($post_id);
    // Allow individual manipulation of reply forum
    if (current_user_can('edit_others_replies') || current_user_can('moderate')) {
        // Forums
        $args = array('selected' => $reply_forum_id, 'select_id' => 'bbp_forum_id', 'show_none' => __('(Use Forum of Topic)', 'bbpress'));
        ?>

		<p><strong><?php 
        _e('Forum', 'bbpress');
        ?>
</strong></p>

		<p>
			<label class="screen-reader-text" for="bbp_forum_id"><?php 
        _e('Forum', 'bbpress');
        ?>
</label>

			<?php 
        bbp_dropdown($args);
        ?>

		</p>

	<?php 
    }
    // Topics
    $args = array('post_type' => bbp_get_topic_post_type(), 'selected' => $reply_topic_id, 'select_id' => 'parent_id', 'orderby' => 'post_date', 'numberposts' => '250', 'show_none' => is_super_admin() ? __('(No Topic)', 'bbpress') : '');
    // Allow the dropdown to be filtered, to extend or limit the available
    // topics to choose as the reply parent.
    $args = apply_filters('bbp_reply_parent_dropdown', $args);
    ?>

	<p><strong><?php 
    _e('Topic', 'bbpress');
    ?>
</strong></p>

	<p>
		<label class="screen-reader-text" for="parent_id"><?php 
    _e('Topic', 'bbpress');
    ?>
</label>

		<?php 
    bbp_dropdown($args);
    ?>

	</p>

	<?php 
    wp_nonce_field('bbp_reply_metabox_save', 'bbp_reply_metabox');
    do_action('bbp_reply_metabox', $post_id);
}
Example #21
0
 function hook_bbp_new_reply($reply_id)
 {
     $topic_id = bbp_get_reply_topic_id($reply_id);
     $topic_url = bbp_get_topic_permalink($topic_id);
     //$dir = $this->get_folder() . '' . substr($topic_url, strlen(get_option('home'))) . '/';
     $dir = $this->get_folder() . '/' . substr($topic_url, strpos($topic_url, '://') + 3) . '/';
     $this->remove_dir($dir);
     $forum_id = bbp_get_reply_forum_id($reply_id);
     $forum_url = bbp_get_forum_permalink($forum_id);
     //$dir = $this->get_folder() . '' . substr($forum_url, strlen(get_option('home'))) . '/';
     $dir = $this->get_folder() . '/' . substr($topic_url, strpos($forum_url, '://') + 3) . '/';
     $this->remove_dir($dir);
 }
Example #22
0
 /**
  * @covers ::bbp_reply_forum_id
  * @covers ::bbp_get_reply_forum_id
  */
 public function test_bbp_get_reply_forum_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $reply_forum_id = bbp_get_reply_forum_id($r);
     $this->assertSame($f, $reply_forum_id);
 }
							<?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_reply_forum_id(bbp_get_reply_id()), 'post__not_in' => array(bbp_get_reply_topic_id(bbp_get_reply_id()))))) {
        ?>

								<div>
									<input name="bbp_reply_move_option" id="bbp_reply_move_option_existing" type="radio" value="existing" tabindex="<?php 
        bbp_tab_index();
        ?>
" />
									<label for="bbp_reply_move_option_existing"><?php 
        _e('Use an existing topic in this forum:', 'firmasite');
        ?>
</label>

									<?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_reply_forum_id(bbp_get_reply_id()), 'selected' => -1, 'exclude' => bbp_get_reply_topic_id(bbp_get_reply_id()), 'select_id' => 'bbp_destination_topic', 'none_found' => __('No other topics found!', 'firmasite')));
        ?>

								</div>

							<?php 
    }
    ?>

						</fieldset>

						<div class="bbp-template-notice error alert alert-warning">
							<p><?php 
    _e('<strong>WARNING:</strong> This process cannot be undone.', 'firmasite');
    ?>
</p>
Example #24
0
/**
 * Reply metabox
 *
 * The metabox that holds all of the additional reply information
 *
 * @since bbPress (r2464)
 *
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses do_action() Calls 'bbp_reply_metabox'
 */
function bbp_reply_metabox()
{
    // Post ID
    $post_id = get_the_ID();
    // Get some meta
    $reply_topic_id = bbp_get_reply_topic_id($post_id);
    $reply_forum_id = bbp_get_reply_forum_id($post_id);
    $reply_to = bbp_get_reply_to($post_id);
    // Allow individual manipulation of reply forum
    if (current_user_can('edit_others_replies') || current_user_can('moderate')) {
        ?>

		<p>
			<strong class="label"><?php 
        esc_html_e('Forum:', 'bbpress');
        ?>
</strong>
			<label class="screen-reader-text" for="bbp_forum_id"><?php 
        esc_html_e('Forum', 'bbpress');
        ?>
</label>
			<?php 
        bbp_dropdown(array('post_type' => bbp_get_forum_post_type(), 'selected' => $reply_forum_id, 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'walker' => '', 'exclude' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => __('&mdash; No parent &mdash;', 'bbpress'), 'disable_categories' => current_user_can('edit_forums'), 'disabled' => ''));
        ?>
		</p>

	<?php 
    }
    ?>

	<p>
		<strong class="label"><?php 
    esc_html_e('Topic:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="parent_id"><?php 
    esc_html_e('Topic', 'bbpress');
    ?>
</label>
		<input name="parent_id" id="bbp_topic_id" type="text" value="<?php 
    echo esc_attr($reply_topic_id);
    ?>
" />
	</p>

	<p>
		<strong class="label"><?php 
    esc_html_e('Reply To:', 'bbpress');
    ?>
</strong>
		<label class="screen-reader-text" for="bbp_reply_to"><?php 
    esc_html_e('Reply To', 'bbpress');
    ?>
</label>
		<input name="bbp_reply_to" id="bbp_reply_to" type="text" value="<?php 
    echo esc_attr($reply_to);
    ?>
" />
	</p>

	<input name="ping_status" type="hidden" id="ping_status" value="open" />

	<?php 
    wp_nonce_field('bbp_reply_metabox_save', 'bbp_reply_metabox');
    do_action('bbp_reply_metabox', $post_id);
}
Example #25
0
/**
 * Return the row class of a reply
 *
 * @since bbPress (r2678)
 *
 * @param int $reply_id Optional. Reply ID
 * @param array Extra classes you can pass when calling this function
 * @uses bbp_get_reply_id() To validate the reply id
 * @uses bbp_get_reply_forum_id() To get the reply's forum id
 * @uses bbp_get_reply_topic_id() To get the reply's topic id
 * @uses get_post_class() To get all the classes including ours
 * @uses apply_filters() Calls 'bbp_get_reply_class' with the classes
 * @return string Row class of the reply
 */
function bbp_get_reply_class($reply_id = 0, $classes = array())
{
    $bbp = bbpress();
    $reply_id = bbp_get_reply_id($reply_id);
    $count = isset($bbp->reply_query->current_post) ? $bbp->reply_query->current_post : 1;
    $classes = (array) $classes;
    $classes[] = (int) $count % 2 ? 'even' : 'odd';
    $classes[] = 'bbp-parent-forum-' . bbp_get_reply_forum_id($reply_id);
    $classes[] = 'bbp-parent-topic-' . bbp_get_reply_topic_id($reply_id);
    $classes[] = 'bbp-reply-position-' . bbp_get_reply_position($reply_id);
    $classes[] = 'user-id-' . bbp_get_reply_author_id($reply_id);
    $classes[] = bbp_get_reply_author_id($reply_id) === bbp_get_topic_author_id(bbp_get_reply_topic_id($reply_id)) ? 'topic-author' : '';
    $classes = array_filter($classes);
    $classes = get_post_class($classes, $reply_id);
    $classes = apply_filters('bbp_get_reply_class', $classes, $reply_id);
    $retval = 'class="' . implode(' ', $classes) . '"';
    return $retval;
}
Example #26
0
 /**
  * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
  *
  * @param int $post_id
  * @uses get_post()
  * @uses bbp_is_reply()
  * @uses bbp_get_reply_topic_id()
  * @uses bbp_get_reply_forum_id()
  * @uses bbp_is_topic()
  * @uses bbp_get_topic_forum_id()
  * @uses bbp_is_forum()
  * @uses get_post_field()
  * @uses bbp_get_forum_group_ids()
  * @uses groups_get_group()
  * @uses bp_get_group_admin_permalink()
  * @uses bp_get_group_permalink()
  * @return Bail early if not a group forum post
  * @return string
  */
 private function maybe_map_permalink_to_group($post_id = 0, $url = false)
 {
     switch (get_post_type($post_id)) {
         // Reply
         case bbp_get_reply_post_type():
             $topic_id = bbp_get_reply_topic_id($post_id);
             $forum_id = bbp_get_reply_forum_id($post_id);
             $url_end = trailingslashit($this->reply_slug) . get_post_field('post_name', $post_id);
             break;
             // Topic
         // Topic
         case bbp_get_topic_post_type():
             $topic_id = $post_id;
             $forum_id = bbp_get_topic_forum_id($post_id);
             $url_end = trailingslashit($this->topic_slug) . get_post_field('post_name', $post_id);
             break;
             // Forum
         // Forum
         case bbp_get_forum_post_type():
             $forum_id = $post_id;
             $url_end = '';
             //get_post_field( 'post_name', $post_id );
             break;
             // Unknown
         // Unknown
         default:
             return $url;
             break;
     }
     // Get group ID's for this forum
     $group_ids = bbp_get_forum_group_ids($forum_id);
     // Bail if the post isn't associated with a group
     if (empty($group_ids)) {
         return $url;
     }
     // @todo Multiple group forums/forum groups
     $group_id = $group_ids[0];
     $group = groups_get_group(array('group_id' => $group_id));
     if (bp_is_group_admin_screen($this->slug)) {
         $group_permalink = trailingslashit(bp_get_group_admin_permalink($group));
     } else {
         $group_permalink = trailingslashit(bp_get_group_permalink($group));
     }
     return trailingslashit(trailingslashit($group_permalink . $this->slug) . $url_end);
 }
Example #27
0
 /**
  * Print extra columns for the replies page
  *
  * @since 2.0.0 bbPress (r2577)
  *
  * @param string $column Column
  * @param int $reply_id reply id
  * @uses bbp_get_reply_topic_id() To get the topic id of the reply
  * @uses bbp_topic_title() To output the reply's topic title
  * @uses apply_filters() Calls 'reply_topic_row_actions' with an array
  *                        of reply topic actions
  * @uses bbp_get_topic_permalink() To get the topic permalink
  * @uses bbp_get_topic_forum_id() To get the forum id of the topic of
  *                                 the reply
  * @uses bbp_get_forum_permalink() To get the forum permalink
  * @uses admin_url() To get the admin url of post.php
  * @uses apply_filters() Calls 'reply_topic_forum_row_actions' with an
  *                        array of reply topic forum actions
  * @uses bbp_reply_author_display_name() To output the reply author name
  * @uses get_the_date() Get the reply creation date
  * @uses get_the_time() Get the reply creation time
  * @uses esc_attr() To sanitize the reply creation time
  * @uses bbp_get_reply_last_active_time() To get the time when the reply was
  *                                    last active
  * @uses do_action() Calls 'bbp_admin_replies_column_data' with the
  *                    column and reply id
  */
 public function column_data($column, $reply_id)
 {
     if ($this->bail()) {
         return;
     }
     // Get topic ID
     $topic_id = bbp_get_reply_topic_id($reply_id);
     // Populate Column Data
     switch ($column) {
         // Topic
         case 'bbp_reply_topic':
             // Output forum name
             if (!empty($topic_id)) {
                 // Topic Title
                 $topic_title = bbp_get_topic_title($topic_id);
                 if (empty($topic_title)) {
                     $topic_title = esc_html__('No Topic', 'bbpress');
                 }
                 // Output the title
                 echo $topic_title;
                 // Reply has no topic
             } else {
                 esc_html_e('No Topic', 'bbpress');
             }
             break;
             // Forum
         // Forum
         case 'bbp_reply_forum':
             // Get Forum ID's
             $reply_forum_id = bbp_get_reply_forum_id($reply_id);
             $topic_forum_id = bbp_get_topic_forum_id($topic_id);
             // Output forum name
             if (!empty($reply_forum_id)) {
                 // Forum Title
                 $forum_title = bbp_get_forum_title($reply_forum_id);
                 if (empty($forum_title)) {
                     $forum_title = esc_html__('No Forum', 'bbpress');
                 }
                 // Alert capable users of reply forum mismatch
                 if ($reply_forum_id !== $topic_forum_id) {
                     if (current_user_can('edit_others_replies') || current_user_can('moderate')) {
                         $forum_title .= '<div class="attention">' . esc_html__('(Mismatch)', 'bbpress') . '</div>';
                     }
                 }
                 // Output the title
                 echo $forum_title;
                 // Reply has no forum
             } else {
                 _e('No Forum', 'bbpress');
             }
             break;
             // Author
         // Author
         case 'bbp_reply_author':
             bbp_reply_author_display_name($reply_id);
             break;
             // Freshness
         // Freshness
         case 'bbp_reply_created':
             // Output last activity time and date
             printf('%1$s <br /> %2$s', get_the_date(), esc_attr(get_the_time()));
             break;
             // Do action for anything else
         // Do action for anything else
         default:
             do_action('bbp_admin_replies_column_data', $column, $reply_id);
             break;
     }
 }
Example #28
0
 function get_forum_id($forum_id)
 {
     if (!$forum_id) {
         if (bbp_is_topic_edit()) {
             $forum_id = bbp_get_topic_forum_id();
         } elseif (bbp_is_single_reply() || bbp_is_reply_edit()) {
             $forum_id = bbp_get_reply_forum_id();
         }
     }
     return $forum_id;
 }
							<?php 
    if (bbp_has_topics(array('show_stickies' => false, 'post_parent' => bbp_get_reply_forum_id(bbp_get_reply_id()), 'post__not_in' => array(bbp_get_reply_topic_id(bbp_get_reply_id()))))) {
        ?>

								<div>
									<input name="bbp_reply_move_option" id="bbp_reply_move_option_existing" type="radio" value="existing" tabindex="<?php 
        bbp_tab_index();
        ?>
" />
									<label for="bbp_reply_move_option_existing"><?php 
        _e('Use an existing topic in this forum:', 'bbpress');
        ?>
</label>

									<?php 
        bbp_dropdown(array('post_type' => bbp_get_topic_post_type(), 'post_parent' => bbp_get_reply_forum_id(bbp_get_reply_id()), 'selected' => -1, 'exclude' => bbp_get_reply_topic_id(bbp_get_reply_id()), 'select_id' => 'bbp_destination_topic'));
        ?>

								</div>

							<?php 
    }
    ?>

						</fieldset>

						<div class="bbp-template-notice error">
							<p><?php 
    _e('<strong>WARNING:</strong> This process cannot be undone.', 'bbpress');
    ?>
</p>
Example #30
0
 /**
  * @group canonical
  * @covers ::bbp_create_initial_content
  */
 public function test_bbp_create_initial_content()
 {
     $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open')));
     bbp_create_initial_content(array('forum_parent' => $category_id));
     $forum_id = bbp_forum_query_subforum_ids($category_id);
     $forum_id = (int) $forum_id[0];
     $topic_id = bbp_get_forum_last_topic_id($forum_id);
     $reply_id = bbp_get_forum_last_reply_id($forum_id);
     // Forum post
     $this->assertSame('General', bbp_get_forum_title($forum_id));
     $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id));
     $this->assertSame('open', bbp_get_forum_status($forum_id));
     $this->assertTrue(bbp_is_forum_public($forum_id));
     $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id));
     // Topic post
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame('Hello World!', bbp_get_topic_title($topic_id));
     remove_all_filters('bbp_get_topic_content');
     $topic_content = "I am the first topic in your new forums.";
     $this->assertSame($topic_content, bbp_get_topic_content($topic_id));
     $this->assertSame('publish', bbp_get_topic_status($topic_id));
     $this->assertTrue(bbp_is_topic_published($topic_id));
     // Reply post
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id));
     $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id));
     remove_all_filters('bbp_get_reply_content');
     $reply_content = "Oh, and this is what a reply looks like.";
     $this->assertSame($reply_content, bbp_get_reply_content($reply_id));
     $this->assertSame('publish', bbp_get_reply_status($reply_id));
     $this->assertTrue(bbp_is_reply_published($reply_id));
     // Category meta
     $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true));
     $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true));
     $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true));
     $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id));
     // Forum meta
     $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id));
     // Topic meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id));
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id));
     // Reply Meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id));
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
 }