/** * Gets the footer of an idea * * @package WP Idea Stream * @subpackage ideas/tags * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance * @uses wp_idea_stream_ideas_get_the_term_list() to get the taxonomy term list * @uses wp_idea_stream_get_category() to get the category taxonomy identifier * @uses wp_idea_stream_get_tag() to get the tag taxonomy identifier * @uses mysql2date() to format the date * @uses wp_idea_stream_is_single_idea() to check if the idea is displayed on its single template * @uses wp_idea_stream_user_can() to check for user's capability * @uses esc_url() to sanitize url * @uses get_edit_post_link() to get the edit link of an idea * @uses wp_idea_stream_users_get_user_data() to get user's attribute * @uses wp_idea_stream_users_get_user_profile_url() to get user's profile link * @uses get_avatar() to get user's avatar * @uses esc_html() to sanitize the output * @uses apply_filters() call 'wp_idea_stream_ideas_get_idea_footer' to override the output * @return string output for the footer */ function wp_idea_stream_ideas_get_idea_footer() { $idea = wp_idea_stream()->query_loop->idea; $retarray = array('start' => __('This idea', 'wp-idea-stream')); $category_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_category()); if (!empty($category_list)) { $retarray['category'] = sprintf(_x('was posted in %s', 'idea categories comma separated list', 'wp-idea-stream'), $category_list); } $tag_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_tag()); if (!empty($tag_list)) { $in = _x('and tagged', 'idea tags join words', 'wp-idea-stream'); if (empty($category_list)) { $in = _x('was tagged', 'idea tags join words no category', 'wp-idea-stream'); } $retarray['tag'] = sprintf(_x('%1$s %2$s', 'idea tags comma separated list', 'wp-idea-stream'), $in, $tag_list); } if (empty($retarray['category']) && empty($retarray['tag'])) { $retarray['posted'] = _x('was posted', 'idea footer empty tags and categories', 'wp-idea-stream'); } $date = apply_filters('get_the_date', mysql2date(get_option('date_format'), $idea->post_date)); if (!wp_idea_stream_is_single_idea()) { // point at the end $retarray['date'] = sprintf(_x('on %s.', 'idea date of publication point', 'wp-idea-stream'), $date); } else { // no point at the end $retarray['date'] = sprintf(_x('on %s', 'idea date of publication no point', 'wp-idea-stream'), $date); $user = wp_idea_stream_users_get_user_data('id', $idea->post_author); $user_link = '<a class="idea-author" href="' . esc_url(wp_idea_stream_users_get_user_profile_url($idea->post_author, $user->user_nicename)) . '" title="' . esc_attr($user->display_name) . '">'; $user_link .= get_avatar($idea->post_author, 20) . esc_html($user->display_name) . '</a>'; $retarray['author'] = sprintf(_x('by %s.', 'single idea author link', 'wp-idea-stream'), $user_link); } // Init edit url $edit_url = ''; // Super admin will use the IdeaStream Administration screens if (wp_idea_stream_user_can('wp_idea_stream_ideas_admin')) { $edit_url = get_edit_post_link($idea->ID); // The author will use the front end edit form } else { if (wp_idea_stream_ideas_can_edit($idea)) { $edit_url = wp_idea_stream_get_form_url(wp_idea_stream_edit_slug(), $idea->post_name); } } if (!empty($edit_url)) { $retarray['edit'] = '<a href="' . esc_url($edit_url) . '" title="' . esc_attr__('Edit Idea', 'wp-idea-stream') . '">' . esc_html__('Edit Idea', 'wp-idea-stream') . '</a>'; } /** * @param string the footer to output * @param array $retarray the parts of the footer organized in an associative array * @param WP_Post $idea the idea object */ return apply_filters('wp_idea_stream_ideas_get_idea_footer', join(' ', $retarray), $retarray, $idea); }
/** * Check the main WordPress query to match WP Idea Stream conditions * Eventually Override query vars and set global template conditions / vars * * This the key function of the plugin, it is definining the templates * to load and is setting the displayed user. * * Inspired by bbPress 's bbp_parse_query() * * @package WP Idea Stream * @subpackage core/template-functions * * @since 2.0.0 * * @param WP_Query $posts_query The WP_Query instance * @uses WP_Query->is_main_query() to check it's the main query * @uses WP_Query->get() to get a query var * @uses wp_idea_stream_is_admin() to check if in IdeaStream's Admin territory * @uses wp_idea_stream_is_sticky_enabled() to check if sticky feature is available * @uses WP_Query->set() to set a query var * @uses wp_idea_stream_is_rating_disabled() to check if ratings feature are available * @uses wp_idea_stream_set_idea_var() to globalize a var * @uses is_admin() to check for WordPress administration * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier * @uses wp_idea_stream_user_rewrite_id() to get the user rewrite id * @uses wp_idea_stream_users_get_user_data() to get a specific user's data * @uses WP_Query->set_404() to set a 404 * @uses wp_idea_stream_user_rates_rewrite_id() to get the user rates rewrite id * @uses wp_idea_stream_user_comments_rewrite_id() to get the user comments rewrite id * @uses wp_idea_stream_action_rewrite_id() to get the action rewrite id * @uses wp_idea_stream_addnew_slug() to get the add new slug * @uses wp_idea_stream_edit_slug() to get the edit slug * @uses has_action() to check if the action 'wp_idea_stream_custom_action' is used by any plugins * @uses do_action() Calls 'wp_idea_stream_custom_action' to perform actions relative to ideas * @uses wp_idea_stream_get_category() to get the ideas category identifier * @uses wp_idea_stream_get_tag() to get the ideas tag identifier * @uses wp_idea_stream_search_rewrite_id() to get the search rewrite id */ function wp_idea_stream_parse_query($posts_query = null) { // Bail if $posts_query is not the main loop if (!$posts_query->is_main_query()) { return; } // Bail if filters are suppressed on this query if (true === $posts_query->get('suppress_filters')) { return; } // Handle the specific queries in IdeaStream Admin if (wp_idea_stream_is_admin()) { // Display sticky ideas if requested if (wp_idea_stream_is_sticky_enabled() && !empty($_GET['sticky_ideas'])) { $posts_query->set('post__in', wp_idea_stream_ideas_get_stickies()); } // Build meta_query if orderby rates is set if (!wp_idea_stream_is_rating_disabled() && !empty($_GET['orderby']) && 'rates_count' == $_GET['orderby']) { $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS'))); // Set the orderby idea var wp_idea_stream_set_idea_var('orderby', 'rates_count'); } do_action('wp_idea_stream_admin_request', $posts_query); return; } // Bail if else where in admin if (is_admin()) { return; } // Ideas post type for a later use $idea_post_type = wp_idea_stream_get_post_type(); /** User's profile ************************************************************/ // Are we requesting the user-profile template ? $user = $posts_query->get(wp_idea_stream_user_rewrite_id()); $embed_page = wp_idea_stream_is_embed_profile(); if (!empty($user)) { if (!is_numeric($user)) { // Get user by his username $user = wp_idea_stream_users_get_user_data('slug', $user); } else { // Get user by his id $user = wp_idea_stream_users_get_user_data('id', $user); } // No user id: no profile! if (empty($user->ID) || true === apply_filters('wp_idea_stream_users_is_spammy', is_multisite() && is_user_spammy($user), $user)) { $posts_query->set_404(); // Make sure the WordPress Embed Template will be used if ('true' === get_query_var('embed') || true === get_query_var('embed')) { $posts_query->is_embed = true; $posts_query->set('p', -1); } return; } // Set the displayed user id wp_idea_stream_set_idea_var('is_user', absint($user->ID)); // Make sure the post_type is set to ideas. $posts_query->set('post_type', $idea_post_type); // Are we requesting user rates $user_rates = $posts_query->get(wp_idea_stream_user_rates_rewrite_id()); // Or user comments ? $user_comments = $posts_query->get(wp_idea_stream_user_comments_rewrite_id()); if (!empty($user_rates) && !wp_idea_stream_is_rating_disabled()) { // We are viewing user's rates wp_idea_stream_set_idea_var('is_user_rates', true); // Define the Meta Query to get his rates $posts_query->set('meta_query', array(array('key' => '_ideastream_rates', 'value' => ';i:' . $user->ID . ';', 'compare' => 'LIKE'))); } else { if (!empty($user_comments)) { // We are viewing user's comments wp_idea_stream_set_idea_var('is_user_comments', true); /** * Make sure no result. * Query will be built later in user comments loop */ $posts_query->set('p', -1); } else { if ('true' === get_query_var('embed') || true === get_query_var('embed')) { $posts_query->is_embed = true; $posts_query->set('p', -1); if ($embed_page) { wp_idea_stream_set_idea_var('is_user_embed', true); } else { $posts_query->set_404(); return; } } // Default to the ideas the user submitted $posts_query->set('author', $user->ID); } } // No stickies on user's profile $posts_query->set('ignore_sticky_posts', true); // Make sure no 404 $posts_query->is_404 = false; // Set the displayed user. wp_idea_stream_set_idea_var('displayed_user', $user); } /** Actions (New Idea) ********************************************************/ $action = $posts_query->get(wp_idea_stream_action_rewrite_id()); if (!empty($action)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define a global to inform we're dealing with an action wp_idea_stream_set_idea_var('is_action', true); // Is the new idea form requested ? if (wp_idea_stream_addnew_slug() == $action) { // Yes so set the corresponding var wp_idea_stream_set_idea_var('is_new', true); /** * Make sure no result. * We are not querying any content, but creating one */ $posts_query->set('p', -1); // Edit action ? } else { if (wp_idea_stream_edit_slug() == $action) { // Yes so set the corresponding var wp_idea_stream_set_idea_var('is_edit', true); // Signup support } else { if (wp_idea_stream_signup_slug() == $action && wp_idea_stream_is_signup_allowed_for_current_blog()) { // Set the signup global var wp_idea_stream_set_idea_var('is_signup', true); /** * Make sure no result. * We are not querying any content, but creating one */ $posts_query->set('p', -1); } else { if (has_action('wp_idea_stream_custom_action')) { /** * Allow plugins to other custom idea actions * * @param string $action The requested action * @param WP_Query $posts_query The WP_Query instance */ do_action('wp_idea_stream_custom_action', $action, $posts_query); } else { $posts_query->set_404(); return; } } } } } /** Ideas by category *********************************************************/ $category = $posts_query->get(wp_idea_stream_get_category()); if (!empty($category)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the current category wp_idea_stream_set_idea_var('is_category', $category); } /** Ideas by tag **************************************************************/ $tag = $posts_query->get(wp_idea_stream_get_tag()); if (!empty($tag)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the current tag wp_idea_stream_set_idea_var('is_tag', $tag); } /** Searching ideas ***********************************************************/ $search = $posts_query->get(wp_idea_stream_search_rewrite_id()); if (!empty($search)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the query as a search one $posts_query->set('is_search', true); /** * Temporarly set the 's' parameter of WP Query * This will be reset while building ideas main_query args * @see wp_idea_stream_set_template() */ $posts_query->set('s', $search); // Set the search conditionnal var wp_idea_stream_set_idea_var('is_search', true); } /** Changing order ************************************************************/ // Here we're using built-in var $orderby = $posts_query->get('orderby'); // Make sure we are ordering ideas if (!empty($orderby) && $idea_post_type == $posts_query->get('post_type')) { if (!wp_idea_stream_is_rating_disabled() && 'rates_count' == $orderby) { /** * It's an order by rates request, set the meta query to achieve this. * Here we're not ordering yet, we simply make sure to get ideas that * have been rated. * Order will happen thanks to wp_idea_stream_set_rates_count_orderby() * filter. */ $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS'))); } // Set the order by var wp_idea_stream_set_idea_var('orderby', $orderby); } // Set the idea archive var if viewing ideas archive if ($posts_query->is_post_type_archive()) { wp_idea_stream_set_idea_var('is_idea_archive', true); } /** * Finally if post_type is ideas, then we're in IdeaStream's * territory so set this */ if ($idea_post_type === $posts_query->get('post_type')) { wp_idea_stream_set_idea_var('is_ideastream', true); // Reset the pagination if (-1 !== $posts_query->get('p')) { $posts_query->set('posts_per_page', wp_idea_stream_ideas_per_page()); } } }
/** * Displays the Sharing button inside a user's profile * * So that WordPress can build the sharing dialog and embed codes * we need to temporarly set the Utility page as the current post * for the displayed user's profile. * Then, we intercept the permalink and the title of the utility page * using filters and we override them with the ones of the displayed * user profile. Tada! * * @since 2.3.0 * * @global WP_Post $post * @return bool False in case the Embed profile is disabled */ function wp_idea_stream_users_embed_content_meta() { global $post; $reset_post = get_post(wp_idea_stream_is_embed_profile()); if (!empty($post->ID) && !empty($reset_post->ID) && (int) $post->ID === (int) $reset_post->ID || empty($reset_post->ID)) { return false; } if (!empty($reset_post->ID)) { // Globalize the post wp_idea_stream_set_idea_var('embed_reset_post', $post); // Reset it to our utility page $post = $reset_post; // Globalize the user wp_idea_stream_set_idea_var('embed_user_data', wp_idea_stream_users_get_user_data('id', wp_idea_stream_users_displayed_user_id())); // Make sure the post link will be the one of the user's displayed profile add_filter('post_type_link', 'wp_idea_stream_users_oembed_link', 10, 2); add_filter('the_title', 'wp_idea_stream_users_oembed_title', 10, 2); add_action('embed_footer', 'wp_idea_stream_users_embed_content_reset_post', 40); // Add WordPress Sharing Button print_embed_sharing_button(); } }
/** * Removes recipients from the moderation notification if needed * * @package WP Idea Stream * @subpackage comments/classes * * @since 2.0.0 * * @param array $emails list of emails that will receive the moderation notification * @param integer $comment_id the comment ID * @uses wp_idea_stream_comments_get_comment() to get the comment object * @uses wp_idea_stream_get_post_type() to get the idea post type identifier * @uses wp_idea_stream_users_get_user_data() to get datas about the user * @return array the emails, without the author */ public function moderation_recipients($emails = array(), $comment_id = 0) { // Return if no comment ID if (empty($comment_id)) { return $emails; } // Get the comment $comment = wp_idea_stream_comments_get_comment($comment_id); // check if it relates to an idea if (empty($comment->comment_post_type) || wp_idea_stream_get_post_type() != $comment->comment_post_type) { return $emails; } // We have a comment about an idea, catch it for a later use $this->{'comment_post_' . $comment_id} = $comment; /** * Idea's author will receive a moderation email but won't be able * to moderate it in WordPress Admin, so we need to remove their * email from recipients list. */ $author_email = wp_idea_stream_users_get_user_data('id', $comment->comment_post_author, 'user_email'); // Found author's email in the list ? If so, let's remove it. if (!empty($author_email) && in_array($author_email, $emails)) { $emails = array_diff($emails, array($author_email)); } return $emails; }
/** * WordPress requires a post id to allow content to be Embed, As our users are not organized * into a post type, we need to use an utility page to get a post ID, and then filter its permalink * and title so that the ones of the user's profile will be used instead * * @since 2.3.0 * * @global WP_Rewrite $wp_rewrite * @param int $post_id the requested post id (should be empty for our users profiles) * @param string $url the requested url which can contain an IdeaStream user's profile */ function wp_idea_stream_users_oembed_request_post_id($post_id = 0, $url = '') { // The post is not empty leave WordPress deal with it! if (!empty($post_id)) { return $post_id; } $utility_page = wp_idea_stream_is_embed_profile(); // No utility page, stop! if (!$utility_page) { return $post_id; } // Get the WP Rewrites global $wp_rewrite; $extra_rules = $wp_rewrite->extra_rules_top; if (empty($extra_rules)) { return $post_id; } // Parse the url $parse_url = parse_url($url); // Pretty permalinks: Loop through each extra rules to find the username or user id if ($wp_rewrite->using_permalinks() && isset($parse_url['path']) && false !== strpos($parse_url['path'], wp_idea_stream_user_slug())) { // Loop through each extra rules to find the username or user id foreach ((array) $extra_rules as $match => $query) { if (preg_match("#^{$match}#", str_replace(trailingslashit(home_url()), '', $url), $matches)) { if (isset($matches[1])) { $user = $matches[1]; break; } } } // Default permalinks: find the query var containing the user_id } elseif (isset($parse_url['query'])) { // Parse the query string parse_str($parse_url['query'], $query_vars); if (!empty($query_vars[wp_idea_stream_user_rewrite_id()])) { $user = (int) $query_vars[wp_idea_stream_user_rewrite_id()]; } } // No username or user id found stop if (empty($user)) { return $post_id; } if (!is_numeric($user)) { // Get user by his username $user = wp_idea_stream_users_get_user_data('slug', $user); } else { // Get user by his id $user = wp_idea_stream_users_get_user_data('id', $user); } // A user was found globalize it for a latter use and init some filters if (is_a($user, 'WP_User')) { // If the user is a spammer, do not allow his profile to be embed if (true === apply_filters('wp_idea_stream_users_is_spammy', is_multisite() && is_user_spammy($user), $user)) { return $post_id; } // Set the utility page as the post id $post_id = $utility_page; wp_idea_stream_set_idea_var('embed_user_data', $user); // Temporarly only! add_filter('post_type_link', 'wp_idea_stream_users_oembed_link', 10, 2); add_filter('the_title', 'wp_idea_stream_users_oembed_title', 10, 2); } return $post_id; }