Esempio n. 1
0
        /**
         * Set the content part of the template
         *
         * @package WP Idea Stream
         * @subpackage buddypress/screens
         *
         * @since  2.0.0
         *
         * @uses   bp_action_variable() to get an action variable
         * @uses   wp_idea_stream_cpage_slug() to get the pagination slug for user comments
         * @uses   wp_idea_stream_paged_slug() to get the pagination slug
         * @uses   bp_is_my_profile() to check if logged in user is displaying his own profile
         * @uses   add_filter() to temporarly customize IdeaStream Loop
         * @uses   wp_idea_stream_template_part() to get the needed IdeaStream template part
         * @uses   remove_filter() to remove the temporary filters
         */
        public function set_content()
        {
            // Init vars
            $this->user_args = array();
            $template_slug = 'idea';
            $template_name = 'loop';
            $filters = array('is_user_profile', 'ideas_query_args');
            /**
             * Make sure the pagination is set
             *
             * For idea queries the pagination slug is the same than WordPress
             * the paged query var is set to it's not necessary.
             * For comments queries, as the pagination slug is different then the one
             * of WordPress, it's necessary.
             */
            if (in_array(bp_action_variable(0), array(wp_idea_stream_cpage_slug(), wp_idea_stream_paged_slug())) && is_numeric(bp_action_variable(1))) {
                $this->user_args['page'] = (int) bp_action_variable(1);
            }
            /**
             * About rates, we don't need the ideas the user submitted
             * but the ideas he rated, so the author must not be set.
             */
            if ('rates' == $this->screen) {
                // Building the meta query, no need to edit query orderby
                // for user rates.
                $this->user_args['meta_query'] = array(array('key' => '_ideastream_rates', 'value' => ';i:' . $this->user_id . ';', 'compare' => 'LIKE'));
                $filters = array_merge($filters, array('is_user_profile_rates', 'users_displayed_user_id'));
                /**
                 * About comments, we are using specific loop, template
                 * and filter.
                 */
            } else {
                if ('comments' == $this->screen) {
                    $template_slug = 'user';
                    $template_name = 'comments';
                    $this->user_args['user_id'] = $this->user_id;
                    $filters = array('comments_query_args');
                    // Default is user ideas, we need to set the author.
                } else {
                    $this->user_args['author'] = $this->user_id;
                    // Show private ideas only if on current user is on his profile
                    if (bp_is_my_profile()) {
                        $filters = array_merge($filters, array('ideas_get_status'));
                    }
                }
            }
            // Add temporary filters
            foreach ($filters as $filter) {
                $this_filter = str_replace(array('ideas', 'comments', '_rates', 'users_'), array('filter', 'filter', '', ''), $filter);
                add_filter('wp_idea_stream_' . $filter, array($this, $this_filter), 10, 1);
            }
            ?>

		<div id="wp-idea-stream">

			<?php 
            wp_idea_stream_template_part($template_slug, $template_name);
            ?>

		</div>

		<?php 
            // Remove temporary filters
            foreach ($filters as $filter) {
                $this_filter = str_replace(array('ideas', 'comments', '_rates', 'users_'), array('filter', 'filter', '', ''), $filter);
                remove_filter('wp_idea_stream_' . $filter, array($this, $this_filter), 10, 1);
            }
        }
Esempio n. 2
0
 /**
  * Setup the rewrite ids and slugs
  *
  * @package WP Idea Stream
  * @subpackage core/classes
  *
  * @since 2.0.0
  *
  * @uses  wp_idea_stream_user_rewrite_id()
  * @uses  wp_idea_stream_user_rates_rewrite_id()
  * @uses  wp_idea_stream_user_comments_rewrite_id()
  * @uses  wp_idea_stream_cpage_rewrite_id()
  * @uses  wp_idea_stream_action_rewrite_id()
  * @uses  wp_idea_stream_search_rewrite_id()
  * @uses  wp_idea_stream_user_slug()
  * @uses  wp_idea_stream_user_rates_slug()
  * @uses  wp_idea_stream_user_comments_slug()
  * @uses  wp_idea_stream_cpage_slug()
  * @uses  wp_idea_stream_action_slug()
  */
 private function setup_globals()
 {
     /** Rewrite ids ***************************************************************/
     $this->page_rid = 'paged';
     // WordPress built-in global var
     $this->user_rid = wp_idea_stream_user_rewrite_id();
     $this->user_rates_rid = wp_idea_stream_user_rates_rewrite_id();
     $this->user_comments_rid = wp_idea_stream_user_comments_rewrite_id();
     $this->cpage_rid = wp_idea_stream_cpage_rewrite_id();
     $this->action_rid = wp_idea_stream_action_rewrite_id();
     $this->search_rid = wp_idea_stream_search_rewrite_id();
     /** Rewrite slugs *************************************************************/
     $this->user_slug = wp_idea_stream_user_slug();
     $this->user_rates_slug = wp_idea_stream_user_rates_slug();
     $this->user_comments_slug = wp_idea_stream_user_comments_slug();
     $this->cpage_slug = wp_idea_stream_cpage_slug();
     $this->action_slug = wp_idea_stream_action_slug();
 }
Esempio n. 3
0
 /**
  * Constructor
  *
  * @package WP Idea Stream
  * @subpackage comment/tags
  *
  * @since 2.0.0
  *
  * @param  array $args the loop args
  * @uses   wp_idea_stream_ideas_per_page() to get the per page setting
  * @uses   wp_idea_stream_is_current_user_profile() to check if on a user's profile
  * @uses   wp_idea_stream_cpage_rewrite_id() to get the comment pagination rewrite id
  * @uses   get_query_var() to get the value of a query var
  * @uses   wp_parse_args() to merge custom args with default ones
  * @uses   wp_idea_stream_get_post_type() to get the idea post type identifier
  * @uses   wp_idea_stream_comments_count_comments() to count the comments for the user
  * @uses   get_comments() to get the comments matching the arguments
  * @uses   wp_list_pluck() to pluck a certain field out of each object in a list.
  * @uses   get_posts() to get the posts corresponding to comments
  * @uses   wp_idea_stream_set_idea_var() to globalize a value for a later use
  * @uses   wp_idea_stream_is_pretty_links() to check if permalink structure is not default one
  * @uses   add_query_arg() to build an url
  * @uses   wp_idea_stream_users_get_user_comments_url() to get user's profile comment part url
  * @uses   wp_idea_stream_users_displayed_user_id() to get the displayed user ID
  * @uses   wp_idea_stream_users_get_displayed_user_username() to get the displayed user nicename
  * @uses   wp_idea_stream_cpage_slug() to get the slug for the comments pagination
  * @uses   WP_Idea_Stream_Loop::start() to build the user comments loop
  */
 public function __construct($args = array())
 {
     $default = array('post_status' => 'publish', 'status' => 'approve', 'user_id' => 0, 'number' => wp_idea_stream_ideas_per_page());
     // All post status if user is viewing his profile
     if (wp_idea_stream_is_current_user_profile() || current_user_can('read_private_ideas')) {
         $default['post_status'] = '';
     }
     //Merge default with requested
     $r = wp_parse_args($args, $default);
     // Set which pagination page
     if (get_query_var(wp_idea_stream_cpage_rewrite_id())) {
         $paged = get_query_var(wp_idea_stream_cpage_rewrite_id());
     } else {
         if (!empty($_GET[wp_idea_stream_cpage_rewrite_id()])) {
             $paged = absint($_GET[wp_idea_stream_cpage_rewrite_id()]);
         } else {
             if (!empty($r['page'])) {
                 $paged = absint($r['page']);
                 // Set default page (first page)
             } else {
                 $paged = 1;
             }
         }
     }
     $comments_args = array('post_type' => wp_idea_stream_get_post_type(), 'post_status' => $r['post_status'], 'status' => $r['status'], 'user_id' => (int) $r['user_id'], 'number' => (int) $r['number'], 'offset' => intval(($paged - 1) * $r['number']), 'page' => (int) $paged);
     if (!empty($comments_args)) {
         foreach ($comments_args as $key => $value) {
             $this->{$key} = $value;
         }
     } else {
         return false;
     }
     if (empty($this->user_id)) {
         $comment_count = 0;
     } else {
         $comment_count = wp_idea_stream_comments_count_comments($this->user_id);
     }
     // Get the comments
     $comments = get_comments($comments_args);
     if (!empty($comments)) {
         $post_ids = wp_list_pluck($comments, 'comment_post_ID');
         // Get all posts in the object cache.
         $posts = get_posts(array('include' => $post_ids, 'post_type' => wp_idea_stream_get_post_type()));
         // Reset will need to be done at the end of the loop
         wp_idea_stream_set_idea_var('needs_reset', true);
         // Build a new post array indexed by post ID
         $p = array();
         foreach ($posts as $post) {
             $p[$post->ID] = $post;
         }
         // Attach the corresponding post to each comment
         foreach ($comments as $key => $comment) {
             if (!empty($p[$comment->comment_post_ID])) {
                 $comments[$key]->idea = $p[$comment->comment_post_ID];
             }
         }
     }
     $params = array('plugin_prefix' => 'wp_idea_stream', 'item_name' => 'comment', 'item_name_plural' => 'comments', 'items' => $comments, 'total_item_count' => $comment_count, 'page' => $this->page, 'per_page' => $this->number);
     $paginate_args = array();
     if (!wp_idea_stream_is_pretty_links()) {
         $paginate_args['base'] = add_query_arg(wp_idea_stream_cpage_rewrite_id(), '%#%');
     } else {
         $paginate_args['base'] = trailingslashit(wp_idea_stream_users_get_displayed_profile_url('comments')) . '%_%';
         $paginate_args['format'] = wp_idea_stream_cpage_slug() . '/%#%/';
     }
     parent::start($params, apply_filters('wp_idea_stream_comments_pagination_args', $paginate_args));
 }
Esempio n. 4
0
/**
 * User comments pagination slug of the plugin
 *
 * @package WP Idea Stream
 * @subpackage admin/settings
 *
 * @since 2.0.0
 *
 * @uses   esc_attr() to sanitize the attribute
 * @uses   wp_idea_stream_cpage_slug() to get the active slug
 * @uses   wp_idea_stream_paged_slug() to get the default pagination slug
 * @return string HTML output
 */
function wp_idea_stream_cpage_slug_setting_callback()
{
    ?>

	<input name="_ideastream_cpage_slug" id="_ideastream_cpage_slug" type="text" class="regular-text code" value="<?php 
    echo esc_attr(wp_idea_stream_cpage_slug());
    ?>
" />
	<p class="description"><?php 
    printf(esc_html__('&#39;%s&#39; slug cannot be used here.', 'wp-idea-stream'), wp_idea_stream_paged_slug());
    ?>
</p>

	<?php 
}