/** * Gets a message in case no idea was found * * @package WP Idea Stream * @subpackage ideas/tags * * @since 2.0.0 * * @uses wp_idea_stream_is_user_profile() to check if on a user's profile * @uses wp_idea_stream_is_user_profile_rates() to check if the rates part of a user's profile * @uses wp_idea_stream_users_get_displayed_user_displayname() to get the displayed user's display name * @uses wp_idea_stream_is_category() to check if a category is displayed * @uses wp_idea_stream_is_tag() to check if a tag is displayed * @uses wp_idea_stream_is_search() to check if a search is being performed * @uses wp_idea_stream_is_orderby() to check if a specific order is being requested * @uses wp_idea_stream_user_can() to check for user's capability * @uses wp_idea_stream_get_form_url() to get the form url to add new ideas * @uses apply_filters() call 'wp_idea_stream_ideas_get_not_found' to override the output * @return string the message to output */ function wp_idea_stream_ideas_get_not_found() { // general feedback $output = esc_html__('It looks like no idea has been submitted yet, please sign in or sign up to add yours!', 'wp-idea-stream'); if (wp_idea_stream_is_user_profile()) { if (!wp_idea_stream_is_user_profile_rates()) { $output = sprintf(__('It looks like %s has not submitted any idea yet', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname()); // We're viewing the idea the user rated } else { $output = sprintf(__('It looks like %s has not rated any idea yet', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname()); } } else { if (wp_idea_stream_is_category()) { $output = __('It looks like no idea has been published in this category yet', 'wp-idea-stream'); } else { if (wp_idea_stream_is_tag()) { $output = __('It looks like no idea has been marked with this tag yet', 'wp-idea-stream'); } else { if (wp_idea_stream_is_search()) { $output = __('It looks like no idea match your search terms.', 'wp-idea-stream'); } else { if (wp_idea_stream_is_search()) { $output = __('It looks like no idea match your search terms.', 'wp-idea-stream'); } else { if (wp_idea_stream_is_orderby('rates_count')) { $output = __('It looks like no idea has been rated yet.', 'wp-idea-stream'); } else { if (wp_idea_stream_user_can('publish_ideas')) { $output = sprintf(__('It looks like no idea has been submitted yet, <a href="%s" title="Submit your idea">add yours</a>', 'wp-idea-stream'), esc_url(wp_idea_stream_get_form_url())); } } } } } } } /** * @param string $output the message to output */ return apply_filters('wp_idea_stream_ideas_get_not_found', $output); }
/** * 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); }
/** * Gets displayed user's rating for a given idea * * @package WP Idea Stream * @subpackage users/tags * * @since 2.0.0 * * @param int $id the idea ID * @param int $user_id the user ID * @uses wp_idea_stream_is_user_profile_rates() to check we're on the rates part of a user's profile * @uses wp_idea_stream_get_idea_var() to get a globalized value * @uses wp_idea_stream_users_displayed_user_id() to get displayed user's ID * @uses wp_idea_stream_users_get_displayed_user_username() to get displayed user's username * @uses wp_idea_stream_users_get_user_profile_url() to get user's profile url * @uses get_avatar() to get user's avatar * @uses apply_filters() call 'wp_idea_stream_users_get_user_idea_rating' to override output */ function wp_idea_stream_users_get_user_idea_rating($id = 0, $user_id = 0) { if (!wp_idea_stream_is_user_profile_rates()) { return; } if (empty($id)) { $query_loop = wp_idea_stream_get_idea_var('query_loop'); if (!empty($query_loop->idea->ID)) { $id = $query_loop->idea->ID; } } if (empty($user_id)) { $user_id = wp_idea_stream_users_displayed_user_id(); } if (empty($user_id) || empty($id)) { return; } $user_rating = wp_idea_stream_count_ratings($id, $user_id); if (empty($user_rating) || is_array($user_rating)) { return false; } $username = wp_idea_stream_users_get_displayed_user_username(); $output = '<a class="user-rating-link" href="' . esc_url(wp_idea_stream_users_get_user_profile_url($user_id, $username)) . '" title="' . esc_attr($username) . '">'; $output .= get_avatar($user_id, 20) . sprintf(_n('rated 1 star', 'rated %s stars', $user_rating, 'wp-idea-stream'), $user_rating) . '</a>'; /** * Filter the user idea rating output * * @param string $output the rating * @param int $id the idea ID * @param int $user_id the user ID */ return apply_filters('wp_idea_stream_users_get_user_idea_rating', $output, $id, $user_id); }
/** * Constructor * * @package WP Idea Stream * @subpackage idea/tags * * @since 2.0.0 * * @param array $args the loop args * @uses get_query_var() * @uses wp_idea_stream_get_idea_var() to get the globalized query loop * @uses wp_idea_stream_ideas_get_idea_by_name() to get the idea object thanks to its post_name * @uses wp_idea_stream_reset_post() to reset the $wp_query->post data * @uses wp_idea_stream_set_idea_var() to globalized the need for a reset postdata * @uses wp_idea_stream_ideas_get_ideas() get all matching ideas * @uses wp_idea_stream_is_pretty_links() do we have a custom permalink structure ? * @uses add_query_arg() to build the url in case default permalink is set * @uses wp_idea_stream_is_idea_archive() to check an idea archive page is being displayed * @uses wp_idea_stream_get_root_url() to get ideas archive url * @uses wp_idea_stream_is_category() to check a category page is being displayed * @uses wp_idea_stream_get_category_url() to get the category url * @uses wp_idea_stream_is_tag() to check a tag page is being displayed * @uses wp_idea_stream_get_tag_url() to get the category url * @uses wp_idea_stream_is_user_profile_rates() to check the rates user's profile page is displayed * @uses wp_idea_stream_users_get_displayed_profile_url() to get user's profile url * @uses wp_idea_stream_is_user_profile_ideas() to check the main user's profile page is displayed * @uses wp_idea_stream_paged_slug() to get the pagination slug * @uses wp_idea_stream_search_rewrite_id() to get the search rewrite id * @uses WP_Idea_Stream_Loop::start() to launch the loop * @uses apply_filters() call 'wp_idea_stream_ideas_pagination_args' to override paginate args */ public function __construct($args = array()) { if (!empty($args) && empty($args['is_widget'])) { $paged = get_query_var('paged'); // Set which pagination page if (!empty($paged)) { $args['page'] = $paged; // Checking query string just in case } else { if (!empty($_GET['paged'])) { $args['page'] = absint($_GET['paged']); // Checking in page args } else { if (!empty($args['page'])) { $args['page'] = absint($args['page']); // Default to first page } else { $args['page'] = 1; } } } } // Only get the idea requested if (!empty($args['idea_name'])) { $query_loop = wp_idea_stream_get_idea_var('query_loop'); if (empty($query_loop->idea)) { $idea = wp_idea_stream_ideas_get_idea_by_name($args['idea_name']); } else { $idea = $query_loop->idea; } // can't do this too ealy $reset_data = array_merge((array) $idea, array('is_page' => true)); wp_idea_stream_reset_post($reset_data); // this needs a "reset postdata"! wp_idea_stream_set_idea_var('needs_reset', true); $ideas = array('ideas' => array($idea), 'total' => 1, 'get_args' => array('page' => 1, 'per_page' => 1)); // Get the ideas } else { $ideas = wp_idea_stream_ideas_get_ideas($args); } if (!empty($ideas['get_args'])) { foreach ($ideas['get_args'] as $key => $value) { $this->{$key} = $value; } } else { return false; } $params = array('plugin_prefix' => 'wp_idea_stream', 'item_name' => 'idea', 'item_name_plural' => 'ideas', 'items' => $ideas['ideas'], 'total_item_count' => $ideas['total'], 'page' => $this->page, 'per_page' => $this->per_page); $paginate_args = array(); // No pretty links if (!wp_idea_stream_is_pretty_links()) { $paginate_args['base'] = add_query_arg('paged', '%#%'); } else { // Is it the main archive page ? if (wp_idea_stream_is_idea_archive()) { $base = trailingslashit(wp_idea_stream_get_root_url()) . '%_%'; // Or the category archive page ? } else { if (wp_idea_stream_is_category()) { $base = trailingslashit(wp_idea_stream_get_category_url()) . '%_%'; // Or the tag archive page ? } else { if (wp_idea_stream_is_tag()) { $base = trailingslashit(wp_idea_stream_get_tag_url()) . '%_%'; // Or the displayed user rated ideas ? } else { if (wp_idea_stream_is_user_profile_rates()) { $base = trailingslashit(wp_idea_stream_users_get_displayed_profile_url('rates')) . '%_%'; // Or the displayed user published ideas ? } else { if (wp_idea_stream_is_user_profile_ideas()) { $base = trailingslashit(wp_idea_stream_users_get_displayed_profile_url()) . '%_%'; // Or nothing i've planed ? } else { /** * Create your own pagination base if not handled by the plugin * * @param string empty string */ $base = apply_filters('wp_idea_stream_ideas_pagination_base', ''); } } } } } $paginate_args['base'] = $base; $paginate_args['format'] = wp_idea_stream_paged_slug() . '/%#%/'; } // Is this a search ? if (wp_idea_stream_get_idea_var('is_search')) { $paginate_args['add_args'] = array(wp_idea_stream_search_rewrite_id() => $_GET[wp_idea_stream_search_rewrite_id()]); } // Do we have a specific order to use ? $orderby = wp_idea_stream_get_idea_var('orderby'); if (!empty($orderby) && 'date' != $orderby) { $merge = array(); if (!empty($paginate_args['add_args'])) { $merge = $paginate_args['add_args']; } $paginate_args['add_args'] = array_merge($merge, array('orderby' => $orderby)); } /** * Use this filter to override the pagination * * @param array $paginate_args the pagination arguments */ parent::start($params, apply_filters('wp_idea_stream_ideas_pagination_args', $paginate_args)); }
/** * Builds user's profile nav * * @package WP Idea Stream * @subpackage users/functions * * @since 2.0.0 * @since 2.3.0 Added the $nofilter parameter to skip filters * * @param int $user_id User id * @param string $user_nicename Optional. User nicename * @param bool $nofilter. Whether to fire filters or not. * @uses wp_idea_stream_users_get_user_profile_url() to get user main profile url * @uses wp_idea_stream_is_user_profile_ideas() to check whether main profile is currently displayed * @uses sanitize_title() to sanitize the nav slug * @uses wp_idea_stream_users_get_user_comments_url() to get user comments profile url * @uses wp_idea_stream_is_user_profile_comments() to check whether comments profile is currently displayed * @uses wp_idea_stream_user_comments_slug() to get user comments slug * @uses wp_idea_stream_is_rating_disabled() to check ratings functionnality is available * @uses wp_idea_stream_users_get_user_rates_url() to get user rates profile url * @uses wp_idea_stream_is_user_profile_rates() to check whether rates profile is currently displayed * @uses wp_idea_stream_user_rates_slug() to get user rates slug * @uses apply_filters() Calls 'wp_idea_stream_users_get_profile_nav_items' to override/add new datas * @return array the nav items organized in an associative array */ function wp_idea_stream_users_get_profile_nav_items($user_id = 0, $username = '', $nofilter = false) { // Bail if no id or username are provided. if (empty($user_id) || empty($username)) { return array(); } $nav_items = array('profile' => array('title' => __('Published', 'wp-idea-stream'), 'url' => wp_idea_stream_users_get_user_profile_url($user_id, $username), 'current' => wp_idea_stream_is_user_profile_ideas(), 'slug' => sanitize_title(_x('ideas', 'user ideas profile slug for BuddyPress use', 'wp-idea-stream'))), 'comments' => array('title' => __('Commented', 'wp-idea-stream'), 'url' => wp_idea_stream_users_get_user_comments_url($user_id, $username), 'current' => wp_idea_stream_is_user_profile_comments(), 'slug' => wp_idea_stream_user_comments_slug())); if (!wp_idea_stream_is_rating_disabled()) { $nav_items['rates'] = array('title' => __('Rated', 'wp-idea-stream'), 'url' => wp_idea_stream_users_get_user_rates_url($user_id, $username), 'current' => wp_idea_stream_is_user_profile_rates(), 'slug' => wp_idea_stream_user_rates_slug()); } if (false === $nofilter) { /** * Filter the available user's profile nav items * * @param array $nav_items the nav items * @param int $user_id the user ID * @param string $username the username */ return apply_filters('wp_idea_stream_users_get_profile_nav_items', $nav_items, $user_id, $username); } else { return $nav_items; } }