Esempio n. 1
0
 function pmpro_bbp_is_forum($forum_id = NULL)
 {
     global $post;
     if (bbp_is_forum($post->ID)) {
         if (!empty($forum_id) && $post->ID == $forum_id) {
             return true;
         } elseif (empty($forum_id)) {
             return true;
         } else {
             return false;
         }
     } elseif (bbp_is_topic($post->ID)) {
         if (!empty($forum_id) && $post->post_parent == $forum_id) {
             return true;
         } elseif (empty($forum_id)) {
             return true;
         } else {
             return false;
         }
     } elseif (bbp_is_reply($post->ID)) {
         if (!empty($forum_id) && in_array($forum_id, $post->ancestors)) {
             return true;
         } elseif (empty($forum_id)) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Esempio n. 2
0
/**
 * Returns link to the most recent activity inside a forum.
 *
 * Returns a complete link with attributes and content.
 *
 * @since bbPress (r2625)
 *
 * @param int $forum_id Optional. Forum id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_get_forum_last_reply_id() To get the forum last reply id
 * @uses bbp_get_forum_last_topic_id() To get the forum last topic id
 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
 * @uses bbp_get_forum_last_reply_title() To get the forum last reply
 *                                         title
 * @uses bbp_get_forum_last_topic_permalink() To get the forum last
 *                                             topic permalink
 * @uses bbp_get_forum_last_topic_title() To get the forum last topic
 *                                         title
 * @uses bbp_get_forum_last_active_time() To get the time when the forum
 *                                         was last active
 * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the
 *                        link and forum id
 */
function bbp_get_forum_freshness_link($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $active_id = bbp_get_forum_last_active_id($forum_id);
    if (empty($active_id)) {
        $active_id = bbp_get_forum_last_reply_id($forum_id);
    }
    if (empty($active_id)) {
        $active_id = bbp_get_forum_last_topic_id($forum_id);
    }
    if (bbp_is_topic($active_id)) {
        $link_url = bbp_get_forum_last_topic_permalink($forum_id);
        $title = bbp_get_forum_last_topic_title($forum_id);
    } elseif (bbp_is_reply($active_id)) {
        $link_url = bbp_get_forum_last_reply_url($forum_id);
        $title = bbp_get_forum_last_reply_title($forum_id);
    }
    $time_since = bbp_get_forum_last_active_time($forum_id);
    if (!empty($time_since) && !empty($link_url)) {
        $anchor = '<a href="' . $link_url . '" title="' . esc_attr($title) . '">' . $time_since . '</a>';
    } else {
        $anchor = __('No Topics', 'bbpress');
    }
    return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id);
}
Esempio n. 3
0
/**
 * Return the author link of the post
 *
 * @since 2.0.0 bbPress (r2875)
 *
 * @param array $args Optional. If an integer, it is used as reply id.
 * @uses bbp_is_topic() To check if it's a topic page
 * @uses bbp_get_topic_author_link() To get the topic author link
 * @uses bbp_is_reply() To check if it's a reply page
 * @uses bbp_get_reply_author_link() To get the reply author link
 * @uses get_post_field() To get the post author
 * @uses bbp_is_reply_anonymous() To check if the reply is by an
 *                                 anonymous user
 * @uses get_the_author_meta() To get the author name
 * @uses bbp_get_user_profile_url() To get the author profile url
 * @uses get_avatar() To get the author avatar
 * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the
 *                        author link and args
 * @return string Author link of reply
 */
function bbp_get_author_link($args = array())
{
    $post_id = is_numeric($args) ? (int) $args : 0;
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('post_id' => $post_id, 'link_title' => '', 'type' => 'both', 'size' => 80), 'get_author_link');
    // Confirmed topic
    if (bbp_is_topic($r['post_id'])) {
        return bbp_get_topic_author_link($r);
        // Confirmed reply
    } elseif (bbp_is_reply($r['post_id'])) {
        return bbp_get_reply_author_link($r);
    }
    // Get the post author and proceed
    $user_id = get_post_field('post_author', $r['post_id']);
    // Neither a reply nor a topic, so could be a revision
    if (!empty($r['post_id'])) {
        // Generate title with the display name of the author
        if (empty($r['link_title'])) {
            $r['link_title'] = sprintf(!bbp_is_reply_anonymous($r['post_id']) ? __('View %s\'s profile', 'bbpress') : __('Visit %s\'s website', 'bbpress'), get_the_author_meta('display_name', $user_id));
        }
        // Assemble some link bits
        $link_title = !empty($r['link_title']) ? ' title="' . esc_attr($r['link_title']) . '"' : '';
        $anonymous = bbp_is_reply_anonymous($r['post_id']);
        // Declare empty array
        $author_links = array();
        // Get avatar
        if ('avatar' === $r['type'] || 'both' === $r['type']) {
            $author_links[] = get_avatar($user_id, $r['size']);
        }
        // Get display name
        if ('name' === $r['type'] || 'both' === $r['type']) {
            $author_links[] = esc_html(get_the_author_meta('display_name', $user_id));
        }
        // Add links if not anonymous
        if (empty($anonymous) && bbp_user_has_profile($user_id)) {
            $author_url = bbp_get_user_profile_url($user_id);
            foreach ($author_links as $link_text) {
                $author_link[] = sprintf('<a href="%1$s"%2$s>%3$s</a>', esc_url($author_url), $link_title, $link_text);
            }
            $author_link = implode('&nbsp;', $author_link);
            // No links if anonymous
        } else {
            $author_link = implode('&nbsp;', $author_links);
        }
        // No post so link is empty
    } else {
        $author_link = '';
    }
    return apply_filters('bbp_get_author_link', $author_link, $r);
}
 /**
  * Get the Post ID
  * Added support for sale of bbPress items.
  * @since 1.3.3.2
  * @version 1.0
  */
 public function get_post_ID()
 {
     $post_id = $bbp_topic_id = $bbp_reply_id = 0;
     if (function_exists('bbpress')) {
         global $wp_query;
         $bbp = bbpress();
         // Currently inside a topic loop
         if (!empty($bbp->topic_query->in_the_loop) && isset($bbp->topic_query->post->ID)) {
             $bbp_topic_id = $bbp->topic_query->post->ID;
         } elseif (!empty($bbp->search_query->in_the_loop) && isset($bbp->search_query->post->ID) && bbp_is_topic($bbp->search_query->post->ID)) {
             $bbp_topic_id = $bbp->search_query->post->ID;
         } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && !empty($bbp->current_topic_id)) {
             $bbp_topic_id = $bbp->current_topic_id;
         } elseif ((bbp_is_single_topic() || bbp_is_topic_edit()) && isset($wp_query->post->ID)) {
             $bbp_topic_id = $wp_query->post->ID;
         }
         // So far, no topic found, check if we are in a reply
         if ($bbp_topic_id == 0) {
             // Currently inside a replies loop
             if (!empty($bbp->reply_query->in_the_loop) && isset($bbp->reply_query->post->ID)) {
                 $bbp_reply_id = $bbp->reply_query->post->ID;
             } elseif (!empty($bbp->search_query->in_the_loop) && isset($bbp->search_query->post->ID) && bbp_is_reply($bbp->search_query->post->ID)) {
                 $bbp_reply_id = $bbp->search_query->post->ID;
             } elseif ((bbp_is_single_reply() || bbp_is_reply_edit()) && !empty($bbp->current_reply_id)) {
                 $bbp_reply_id = $bbp->current_reply_id;
             } elseif ((bbp_is_single_reply() || bbp_is_reply_edit()) && isset($wp_query->post->ID)) {
                 $bbp_reply_id = $wp_query->post->ID;
             }
             if ($bbp_reply_id != 0) {
                 $post_id = $bbp_reply_id;
             }
         } else {
             $post_id = $bbp_topic_id;
         }
     }
     if ($post_id == 0 && isset($GLOBALS['post'])) {
         $post_id = $GLOBALS['post']->ID;
     }
     return apply_filters('mycred_sell_this_get_post_ID', $post_id, $this);
 }
/**
 * Custom function from bbp_get_author_link(), returns only author name
 * -------------------------------------------------------------------------------------------*/
function aq_get_author($post_id = 0)
{
    // Confirmed topic
    if (bbp_is_topic($post_id)) {
        return bbp_get_topic_author($post_id);
        // Confirmed reply
    } elseif (bbp_is_reply($post_id)) {
        return bbp_get_reply_author($post_id);
        // Get the post author and proceed
    } else {
        $user_id = get_post_field('post_author', $post_id);
    }
    // Neither a reply nor a topic, so could be a revision
    if (!empty($post_id)) {
        // Assemble some link bits
        $anonymous = bbp_is_reply_anonymous($post_id);
        // Add links if not anonymous
        if (empty($anonymous) && bbp_user_has_profile($user_id)) {
            $author_link = get_the_author_meta('display_name', $user_id);
            // No links if anonymous
        } else {
            $author_link = join('&nbsp;', $author_links);
        }
        // No post so link is empty
    } else {
        $author_link = '';
    }
    return $author_link;
}
Esempio n. 6
0
/**
 * Return the author link of the post
 *
 * @since bbPress (r2875)
 *
 * @param mixed $args Optional. If an integer, it is used as reply id.
 * @uses bbp_is_topic() To check if it's a topic page
 * @uses bbp_get_topic_author_link() To get the topic author link
 * @uses bbp_is_reply() To check if it's a reply page
 * @uses bbp_get_reply_author_link() To get the reply author link
 * @uses get_post_field() To get the post author
 * @uses bbp_is_reply_anonymous() To check if the reply is by an
 *                                 anonymous user
 * @uses get_the_author_meta() To get the author name
 * @uses bbp_get_user_profile_url() To get the author profile url
 * @uses get_avatar() To get the author avatar
 * @uses apply_filters() Calls 'bbp_get_reply_author_link' with the
 *                        author link and args
 * @return string Author link of reply
 */
function bbp_get_author_link($args = '')
{
    // Default arguments
    $defaults = array('post_id' => 0, 'link_title' => '', 'type' => 'both', 'size' => 80);
    $r = bbp_parse_args($args, $defaults, 'get_author_link');
    extract($r);
    // Used as reply_id
    if (is_numeric($args)) {
        $post_id = $args;
    }
    // Confirmed topic
    if (bbp_is_topic($post_id)) {
        return bbp_get_topic_author_link($args);
    } elseif (bbp_is_reply($post_id)) {
        return bbp_get_reply_author_link($args);
    } else {
        $user_id = get_post_field('post_author', $post_id);
    }
    // Neither a reply nor a topic, so could be a revision
    if (!empty($post_id)) {
        // Generate title with the display name of the author
        if (empty($link_title)) {
            $link_title = sprintf(!bbp_is_reply_anonymous($post_id) ? __('View %s\'s profile', 'bbpress') : __('Visit %s\'s website', 'bbpress'), get_the_author_meta('display_name', $user_id));
        }
        // Assemble some link bits
        $link_title = !empty($link_title) ? ' title="' . $link_title . '"' : '';
        $author_url = bbp_get_user_profile_url($user_id);
        $anonymous = bbp_is_reply_anonymous($post_id);
        // Get avatar
        if ('avatar' == $type || 'both' == $type) {
            $author_links[] = get_avatar($user_id, $size);
        }
        // Get display name
        if ('name' == $type || 'both' == $type) {
            $author_links[] = get_the_author_meta('display_name', $user_id);
        }
        // Add links if not anonymous
        if (empty($anonymous)) {
            foreach ($author_links as $link_text) {
                $author_link[] = sprintf('<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text);
            }
            $author_link = join('&nbsp;', $author_link);
            // No links if anonymous
        } else {
            $author_link = join('&nbsp;', $author_links);
        }
        // No post so link is empty
    } else {
        $author_link = '';
    }
    return apply_filters('bbp_get_author_link', $author_link, $args);
}
Esempio n. 7
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param array $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam, reply move, and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_reply_move_link() To get the reply move link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()), 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = apply_filters('bbp_reply_admin_links', array('edit' => bbp_get_reply_edit_link($r), 'move' => bbp_get_reply_move_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r), 'reply' => bbp_get_reply_to_link($r)), $r['id']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if (bbp_get_trash_status_id() === $reply_status) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (bbp_get_spam_status_id() === $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $r, $args);
}
Esempio n. 8
0
/**
 * Called after untrashing (restoring) a reply
 *
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_is_reply() To check if the passed id is a reply
 * @uses do_action() Calls 'bbp_untrashed_reply' with the reply id
 */
function bbp_untrashed_reply($reply_id = 0)
{
    $reply_id = bbp_get_reply_id($reply_id);
    if (empty($reply_id) || !bbp_is_reply($reply_id)) {
        return false;
    }
    do_action('bbp_untrashed_reply', $reply_id);
}
Esempio n. 9
0
/**
 * Display nested subforums with a hierarchical structure using their parent category
 * @version 2.0
 */
function apoc_loop_subforums()
{
    // Exclude private forums
    $private = apoc_private_forum_ids();
    // Check for subforums
    $subs = bbp_forum_get_subforums(array('post__not_in' => $private));
    if (empty($subs)) {
        return;
    }
    // Buffer output
    ob_start();
    // Print a header
    ?>
	<header class="forum-header">
		<div class="forum-content"><h2><?php 
    bbp_forum_title();
    ?>
</h2></div>
		<div class="forum-count">Topics</div>
		<div class="forum-freshness">Latest Post</div>
	</header>
	<ol class="forums category <?php 
    bbp_forum_status();
    ?>
"><?php 
    // Loop over forums
    foreach ($subs as $count => $sub) {
        // Get forum details
        $sub_id = $sub->ID;
        $title = $sub->post_title;
        $desc = $sub->post_content;
        $permalink = bbp_get_forum_permalink($sub_id);
        // Get topic counts
        $topics = bbp_get_forum_topic_count($sub_id, false);
        // Get the most recent reply and its topic
        $reply_id = bbp_get_forum_last_reply_id($sub_id);
        $topic_id = bbp_is_reply($reply_id) ? bbp_get_reply_topic_id($reply_id) : $reply_id;
        $topic_title = bbp_get_topic_title($topic_id);
        $link = bbp_get_reply_url($reply_id);
        // Get the author avatar
        $user_id = bbp_get_reply_author_id($reply_id);
        $avatar = apoc_get_avatar(array('user_id' => $user_id, 'link' => true, 'size' => 50));
        // Toggle html class
        $class = $count % 2 ? 'odd' : 'even';
        // Print output
        ?>
		<li id="forum-<?php 
        echo $sub_id;
        ?>
" class="forum <?php 
        echo $class;
        ?>
">
			<div class="forum-content">
				<h3 class="forum-title"><a href="<?php 
        echo $permalink;
        ?>
" title="Browse <?php 
        echo $title;
        ?>
"><?php 
        echo $title;
        ?>
</a></h3>
				<p class="forum-description"><?php 
        echo $desc;
        ?>
</p>
			</div>

			<div class="forum-count">
				<?php 
        echo $topics;
        ?>
			</div>

			<div class="forum-freshness">
				<?php 
        echo $avatar;
        ?>
				<div class="freshest-meta">
					<a class="freshest-title" href="<?php 
        echo $link;
        ?>
" title="<?php 
        echo $topic_title;
        ?>
"><?php 
        echo $topic_title;
        ?>
</a>
					<span class="freshest-author">By <?php 
        bbp_author_link(array('post_id' => $reply_id, 'type' => 'name'));
        ?>
</span>
					<span class="freshest-time"><?php 
        bbp_topic_last_active_time($topic_id);
        ?>
</span>
				</div>
			</div>
		</li>
	<?php 
    }
    ?>
	</ol>
		
	<?php 
    // Retrieve from buffer
    $output = ob_get_contents();
    ob_end_clean();
    echo $output;
}
Esempio n. 10
0
		
			// Loop over forums
		foreach ( $subs as $count => $sub ) :

				// Get forum details
			$sub_id			= $sub->ID;
			$title			= $sub->post_title;
			$desc			= $sub->post_content;
			$permalink		= bbp_get_forum_permalink( $sub_id );

					// Get topic counts
			$topics	 		= bbp_get_forum_topic_count( $sub_id , true );

					// Get the most recent reply and its topic
			$reply_id		= bbp_get_forum_last_reply_id( $sub_id );
			$topic_id		= bbp_is_reply( $reply_id ) ? bbp_get_reply_topic_id( $reply_id ) : $reply_id;
			$topic_title	= bbp_get_topic_title( $topic_id );
			$link 			= bbp_get_reply_url( $reply_id );

					// Get the author 
			$user_id 		= bbp_get_reply_author_id( $reply_id );

					// Toggle html class?>

			<tr>
				<td><a class="bbp-forum-title" href="<?php echo $permalink; ?>"><?php echo $title; ?></a></td>
				<td><?php echo $topics; ?></td>
				<td><?php bbp_forum_post_count( $sub_id, true ); ?></td>
				<td><p class="bbp-topic-meta">

					<?php do_action( 'bbp_theme_before_topic_author' ); ?>
Esempio n. 11
0
/**
 * Decrease the total reply count of a forum by one.
 *
 * @since 2.6.0 bbPress (r6036)
 *
 * @param int $forum_id The forum id.
 *
 * @uses bbp_is_reply() To get the reply id
 * @uses bbp_get_reply_forum_id() To get the replies forum id
 * @uses bbp_bump_forum_reply_count() To bump the forum reply count
 *
 * @return void
 */
function bbp_decrease_forum_reply_count($forum_id = 0)
{
    // Bail early if no id is passed.
    if (empty($forum_id)) {
        return;
    }
    // If it's a reply, get the forum id.
    if (bbp_is_reply($forum_id)) {
        $forum_id = bbp_get_reply_forum_id($forum_id);
    }
    bbp_bump_forum_reply_count($forum_id, -1);
}
Esempio n. 12
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param mixed $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = '')
{
    $defaults = array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array());
    $r = bbp_parse_args($args, $defaults, 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // Make sure user can edit this reply
    if (!current_user_can('edit_reply', $r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = array('edit' => bbp_get_reply_edit_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r));
    }
    // Check caps for trashing the topic
    if (!current_user_can('delete_reply', $r['id']) && !empty($r['links']['trash'])) {
        unset($r['links']['trash']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if ($reply_status == bbp_get_trash_status_id()) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (isset($r['links']['trash']) && bbp_get_spam_status_id() == $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $args);
}
Esempio n. 13
0
 public static function user_has_cap($allcaps, $caps, $args, $user)
 {
     if (!in_array('upload_files', $caps)) {
         return $allcaps;
     }
     $can = isset($allcaps['upload_files']) ? $allcaps['upload_files'] : false;
     // async-upload.php, admin-ajax.php 를 통해서 업로드할 때 권한 체크가 어려움
     $ajax_attachment_actions = apply_filters('bbpkr_ajax_attachment_actions', array('upload-attachment', 'query-attachments'));
     if ((isset($_REQUEST['post_id']) || !empty(self::$forum_id)) && empty($allcaps['upload_files']) && (defined('DOING_AJAX') && true === DOING_AJAX) && (isset($_REQUEST['action']) && in_array($_REQUEST['action'], $ajax_attachment_actions))) {
         if (isset($_REQUEST['post_id'])) {
             $the_id = (int) $_REQUEST['post_id'];
             if (bbp_is_forum($the_id)) {
                 self::$forum_id = $the_id;
             } elseif (bbp_is_topic($the_id)) {
                 self::$forum_id = (int) bbp_get_topic_forum_id($the_id);
             } elseif (bbp_is_reply($the_id)) {
                 self::$forum_id = (int) bbp_get_reply_forum_id($the_id);
             }
         }
         if (!self::$forum_id) {
             return $allcaps;
         }
         $forum_id = self::$forum_id;
         // unset post_id to avoid edit_post check( DO NOT UNSET $_POST['post_id'] )
         $_REQUEST['post_id'] = null;
         $allcaps['upload_files'] = self::can_upload($can, $forum_id);
         return $allcaps;
     }
     $allcaps['upload_files'] = self::can_upload($can);
     return $allcaps;
 }
function pg_get_author_link()
{
    $user_id2 = wp_get_current_user()->ID;
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('post_id' => $post_id, 'link_title' => '', 'type' => 'both', 'size' => 14), 'pg_get_author_link');
    //confirmed topic
    if (bbp_is_topic($post_id)) {
        $topic = bbp_get_topic_post_type();
        $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $topic);
        //now we can check if the user can view this
        if (!private_groups_can_user_view_post($user_id2, $forum_id_check)) {
            return;
        }
        return bbp_get_topic_author_link($r);
        // Confirmed reply
    } elseif (bbp_is_reply($post_id)) {
        $reply = bbp_get_reply_post_type();
        $forum_id_check = private_groups_get_forum_id_from_post_id($post_id, $reply);
        //now we can check if the user can view this
        if (!private_groups_can_user_view_post($user_id2, $forum_id_check)) {
            return;
        }
        return bbp_get_reply_author_link($r);
    }
    // Neither a reply nor a topic, so could be a revision
    //if it isn't a topic or reply, not sure so better to just not display the author in this case
    //could be revised to look up the post_parent of this post and then churn that round the code above if required return ;
    return;
}
/**
 * Validate a `reply_to` field for hierarchical replies
 * 
 * Checks for 2 scenarios:
 * -- The reply to ID is actually a reply
 * -- The reply to ID does not match the current reply
 *
 * @since bbPress (r5377)
 *
 * @param int $reply_to
 * @param int $reply_id
 *
 * @return int $reply_to
 */
function bbp_validate_reply_to($reply_to = 0, $reply_id = 0)
{
    // The parent reply must actually be a reply
    if (!bbp_is_reply($reply_to)) {
        $reply_to = 0;
    }
    // The parent reply cannot be itself
    if ($reply_id === $reply_to) {
        $reply_to = 0;
    }
    return (int) $reply_to;
}
Esempio n. 16
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();
 }
Esempio n. 17
0
 public function delete_post($id)
 {
     if (d4p_has_bbpress()) {
         if (bbp_is_reply($id) || bbp_is_topic($id)) {
             if ($this->o['delete_attachments'] == 'delete') {
                 $files = d4p_get_post_attachments($id);
                 if (is_array($files) && !empty($files)) {
                     foreach ($files as $file) {
                         wp_delete_attachment($file->ID);
                     }
                 }
             } else {
                 if ($this->o['delete_attachments'] == 'detach') {
                     global $wpdb;
                     $wpdb->update($wpdb->posts, array('post_parent' => 0), array('post_parent' => $id, 'post_type' => 'attachment'));
                 }
             }
         }
     }
 }
Esempio n. 18
0
/**
 * Adjust the total anonymous reply count of a topic
 *
 * @since 2.0.0 bbPress (r2567)
 *
 * @param int $topic_id Optional. Topic id to update
 * @uses bbp_is_reply() To check if the passed topic id is a reply
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_var() To execute our query and get the column back
 * @uses update_post_meta() To update the topic anonymous reply count meta
 * @uses apply_filters() Calls 'bbp_update_topic_anonymous_reply_count' with the
 *                        anonymous reply count and topic id
 * @return int Anonymous reply count
 */
function bbp_update_topic_anonymous_reply_count($topic_id = 0)
{
    // If it's a reply, then get the parent (topic id)
    if (bbp_is_reply($topic_id)) {
        $topic_id = bbp_get_reply_topic_id($topic_id);
    } elseif (bbp_is_topic($topic_id)) {
        $topic_id = bbp_get_topic_id($topic_id);
    } else {
        return;
    }
    // Query the DB to get anonymous replies in this topic
    $bbp_db = bbp_db();
    $query = $bbp_db->prepare("SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type());
    $replies = (int) $bbp_db->get_var($query);
    update_post_meta($topic_id, '_bbp_anonymous_reply_count', $replies);
    return (int) apply_filters('bbp_update_topic_anonymous_reply_count', $replies, $topic_id);
}
Esempio n. 19
0
/**
 * Adjust the total anonymous reply count of a topic
 *
 * @since bbPress (r2567)
 *
 * @param int $topic_id Optional. Topic id to update
 * @uses bbp_is_reply() To check if the passed topic id is a reply
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_col() To execute our query and get the column back
 * @uses update_post_meta() To update the topic anonymous reply count meta
 * @uses apply_filters() Calls 'bbp_update_topic_anonymous_reply_count' with the
 *                        anonymous reply count and topic id
 * @return int Anonymous reply count
 */
function bbp_update_topic_anonymous_reply_count($topic_id = 0)
{
    global $wpdb;
    // If it's a reply, then get the parent (topic id)
    if (bbp_is_reply($topic_id)) {
        $topic_id = bbp_get_reply_topic_id($topic_id);
    } elseif (bbp_is_topic($topic_id)) {
        $topic_id = bbp_get_topic_id($topic_id);
    } else {
        return;
    }
    $anonymous_replies = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type()));
    update_post_meta($topic_id, '_bbp_anonymous_reply_count', (int) $anonymous_replies);
    return apply_filters('bbp_update_topic_anonymous_reply_count', (int) $anonymous_replies, $topic_id);
}
Esempio n. 20
0
function firmasite_social_bbp_get_forum_freshness_link($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $active_id = bbp_get_forum_last_active_id($forum_id);
    if (empty($active_id)) {
        $active_id = bbp_get_forum_last_reply_id($forum_id);
    }
    if (empty($active_id)) {
        $active_id = bbp_get_forum_last_topic_id($forum_id);
    }
    if (bbp_is_topic($active_id)) {
        $link_url = bbp_get_forum_last_topic_permalink($forum_id);
        $title = bbp_get_forum_last_topic_title($forum_id);
    } elseif (bbp_is_reply($active_id)) {
        $link_url = bbp_get_forum_last_reply_url($forum_id);
        $title = bbp_get_forum_last_reply_title($forum_id);
    }
    $time_since = bbp_get_forum_last_active_time($forum_id);
    if (!empty($time_since) && !empty($link_url)) {
        $anchor = '<a href="' . $link_url . '" data-toggle="popover" data-rel="popover" data-placement="left" data-trigger="hover" data-html="true" data-original-title="' . __('Freshness', 'firmasite') . '" data-content="' . esc_attr($time_since) . '"><i class="icon-time"></i></a>&nbsp;' . __('Freshness', 'firmasite') . ':';
    } else {
        $anchor = __('No Topics', 'firmasite');
    }
    return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id);
}