/** * 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(); }
/** * Set the document title for IdeaStream pages * * @since 2.3.0 * * @param array $document_title The WordPress Document title * @return array The IdeaStream Document title */ function wp_idea_stream_document_title_parts($document_title = array()) { if (!wp_idea_stream_is_ideastream()) { return $document_title; } $new_document_title = $document_title; // Reset the document title if needed if (!wp_idea_stream_is_single_idea()) { $title = (array) wp_idea_stream_title(); // On user's profile, add some piece of info if (wp_idea_stream_is_user_profile() && count($title) === 1) { // Seeing comments of the user if (wp_idea_stream_is_user_profile_comments()) { $title[] = __('Idea Comments', 'wp-idea-stream'); // Get the pagination page if (get_query_var(wp_idea_stream_cpage_rewrite_id())) { $cpage = get_query_var(wp_idea_stream_cpage_rewrite_id()); } elseif (!empty($_GET[wp_idea_stream_cpage_rewrite_id()])) { $cpage = $_GET[wp_idea_stream_cpage_rewrite_id()]; } if (!empty($cpage)) { $title['page'] = sprintf(__('Page %s', 'wp-idea-stream'), (int) $cpage); } // Seeing Ratings for the user } elseif (wp_idea_stream_is_user_profile_rates()) { $title[] = __('Idea Ratings', 'wp-idea-stream'); // Seeing The root profile } else { $title[] = __('Ideas', 'wp-idea-stream'); } } // Get WordPress Separator $sep = apply_filters('document_title_separator', '-'); $new_document_title['title'] = implode(" {$sep} ", array_filter($title)); } // Set the site name if not already set. if (!isset($new_document_title['site'])) { $new_document_title['site'] = get_bloginfo('name', 'display'); } // Unset tagline for IdeaStream Pages if (isset($new_document_title['tagline'])) { unset($new_document_title['tagline']); } return apply_filters('wp_idea_stream_document_title_parts', $new_document_title, $document_title); }
/** * 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)); }