Esempio n. 1
0
 /**
  * @group signup
  */
 public function test_wp_idea_stream_users_signup_user_success()
 {
     if (function_exists('buddypress')) {
         $this->markTestSkipped('wp_idea_stream_users_signup_user() is not used when BuddyPress is activated.');
     }
     $this->post_signup_form(array('user_login' => 'foobar', 'user_email' => '*****@*****.**'));
     wp_idea_stream_users_signup_user(false);
     $this->assertContains('success', wp_idea_stream_get_idea_var('feedback'));
 }
Esempio n. 2
0
/**
 * Builds a checkboxes list of categories
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   wp_get_object_terms() to get the categories for the idea
 * @uses   wp_idea_stream_get_category() to get the category taxonomy identifier
 * @uses   wp_idea_stream_get_idea_var() to get the globalized category terms
 * @uses   apply_filters() call 'wp_idea_stream_ideas_get_category_edit_none' to override the output when no categories
 *                         call 'wp_idea_stream_ideas_get_category_edit' to override the output when has categories
 * @uses   esc_attr() to sanitize an attribute
 * @uses   esc_html() to sanitize an output
 * @uses   checked() to add the checked attribute to the checkbox if needed
 * @return string  output for the list of categories
 */
function wp_idea_stream_ideas_get_category_edit()
{
    $wp_idea_stream = wp_idea_stream();
    // Did the user submitted categories ?
    if (!empty($_POST['wp_idea_stream']['_the_category'])) {
        $edit_categories = (array) $_POST['wp_idea_stream']['_the_category'];
        // Are we editing an idea ?
    } else {
        if (!empty($wp_idea_stream->query_loop->idea->ID)) {
            $edit_categories = (array) wp_get_object_terms($wp_idea_stream->query_loop->idea->ID, wp_idea_stream_get_category(), array('fields' => 'ids'));
            // Default to en empty array
        } else {
            $edit_categories = array();
        }
    }
    $terms = wp_idea_stream_get_idea_var('edit_form_terms');
    // Default output
    $output = esc_html__('No categories are available.', 'wp-idea-stream');
    if (empty($terms)) {
        /**
         * @param  string $output the output when no categories
         */
        echo apply_filters('wp_idea_stream_ideas_get_category_edit_none', $output);
        return;
    }
    $output = '<ul class="category-list">';
    foreach ($terms as $term) {
        $output .= '<li><label for="_wp_idea_stream_the_category_' . esc_attr($term->term_id) . '">';
        $output .= '<input type="checkbox" name="wp_idea_stream[_the_category][]" id="_wp_idea_stream_the_category_' . esc_attr($term->term_id) . '" value="' . esc_attr($term->term_id) . '" ' . checked(true, in_array($term->term_id, $edit_categories), false) . '/>';
        $output .= ' ' . esc_html($term->name) . '</label></li>';
    }
    $output .= '</ul>';
    /**
     * @param  string $output the output when has categories
     * @param  array  $edit_categories selected term ids
     * @param  array  $terms available terms for the category taxonomy
     */
    echo apply_filters('wp_idea_stream_ideas_get_category_edit', $output, $edit_categories, $terms);
}
/**
 * Set the template to use, buffers the needed template parts
 * and resets post vars.
 *
 * @package WP Idea Stream
 * @subpackage core/template-loader
 *
 * @since 2.0.0
 *
 * @global $wp_query
 * @param  string $template name of the template to use
 * @uses   is_buddypress() to bail early if it's this plugin's territory
 * @uses   wp_idea_stream_get_idea_var() to get a globalized var
 * @uses   is_404() to check for a 404
 * @uses   get_query_template() to get a specific template
 * @uses   get_index_template() to get the index template
 * @uses   wp_idea_stream_set_idea_var() to set a globalized var
 * @uses   is_post_type_archive() to check if it's ideas post type archive
 * @uses   wp_idea_stream_get_post_type() to get ideas post type identifier
 * @uses   set_query_var() to get a query var
 * @uses   remove_all_filters() to remove all filters on a specific hook
 * @uses   wp_idea_stream_reset_post() to reset WordPress $post global and avoid notices
 * @uses   wp_idea_stream_reset_post_title() to reset the title depending on the context
 * @uses   wp_idea_stream_buffer_template_part() to buffer the content to display
 * @uses   wp_idea_stream_is_edit() to check if the idea is to be edited
 * @uses   wp_idea_stream_ideas_lock_idea() to check if the idea to edit is not currently edited by another user
 * @uses   wp_idea_stream_add_message() to give a user some feedback
 * @uses   wp_idea_stream_ideas_can_edit() to check current user can edit an idea
 * @uses   wp_safe_redirect() to safely redirect the user
 * @uses   wp_idea_stream_get_redirect_url() to get the default redirect url
 * @uses   wp_idea_stream_buffer_single_idea() to buffer the idea content to display
 * @uses   do_action() Calls 'wp_idea_stream_set_core_template' to perform actions once a core template is set
 *                     Calls 'wp_idea_stream_set_single_template' to perform actions relative to the single idea template
 *                     Calls 'wp_idea_stream_set_template' to perform actions when no template matched
 * @uses   apply_filters() Calls 'wp_idea_stream_template_args' to override template args in case of custom idea action
 *                         Calls 'wp_idea_stream_single_template_args' to override single template args
 * @return string $template.
 */
function wp_idea_stream_set_template($template = '')
{
    global $wp_query;
    /**
     * Bail if BuddyPress, we'll use its theme compatibility
     * feature.
     */
    if (function_exists('is_buddypress') && is_buddypress()) {
        return $template;
    }
    if (wp_idea_stream_get_idea_var('is_ideastream') && !is_404()) {
        // Try to see if the theme has a specific template for WP Idea Stream
        $template = get_query_template('ideastream');
        if (empty($template)) {
            // else Try the page template
            $template = get_query_template('page', array('page.php'));
        }
        if (empty($template)) {
            // finally fall back to the index template
            $template = get_index_template();
        }
        // Define it into plugin's vars
        wp_idea_stream_set_idea_var('template_file', $template);
        /**
         * First get results of the main query if not on a single idea.
         * and build plugin's main_query var.
         */
        if (!wp_idea_stream_is_single_idea()) {
            wp_idea_stream_set_idea_var('main_query', array('ideas' => $wp_query->posts, 'total' => $wp_query->found_posts, 'query_vars' => array('author' => $wp_query->query_vars['author'], 'per_page' => $wp_query->query_vars['posts_per_page'], 'page' => !empty($wp_query->query_vars['paged']) ? $wp_query->query_vars['paged'] : 1, 'search' => $wp_query->query_vars['s'], 'exclude' => $wp_query->query_vars['post__not_in'], 'include' => $wp_query->query_vars['post__in'], 'orderby' => !empty($wp_query->query_vars['orderby']) ? $wp_query->query_vars['orderby'] : 'date', 'order' => $wp_query->query_vars['order'], 'meta_query' => $wp_query->meta_query->queries, 'tax_query' => $wp_query->tax_query->queries)));
            // Resetting the 's' query var now we got main query's result.
            set_query_var('s', '');
            // Init template args
            $template_args = array('post_title' => '', 'comment_status' => 'closed', 'is_archive' => true, 'is_tax' => false, 'template_slug' => 'archive', 'template_name' => '', 'context' => '');
            // Main plugin's archive page
            if (is_post_type_archive(wp_idea_stream_get_post_type())) {
                $template_args['context'] = 'archive';
            }
            // Category / tag archive pages
            if (wp_idea_stream_get_idea_var('is_category') || wp_idea_stream_get_idea_var('is_tag')) {
                $template_args['is_tax'] = true;
                $template_args['context'] = 'taxonomy';
            }
            // User's profile pages
            if (wp_idea_stream_get_idea_var('is_user')) {
                $template_args['template_slug'] = 'user';
                $template_args['template_name'] = 'profile';
                $template_args['context'] = 'user-profile';
            }
            if (wp_idea_stream_get_idea_var('is_action')) {
                $template_args['is_archive'] = false;
                // New idea form
                if (wp_idea_stream_is_addnew()) {
                    $template_args['template_slug'] = 'idea';
                    $template_args['template_name'] = 'form';
                    $template_args['context'] = 'new-idea';
                } else {
                    if (wp_idea_stream_is_signup()) {
                        $template_args['template_slug'] = 'signup';
                        $template_args['context'] = 'signup';
                        // Allow plugins to add custom action
                    } else {
                        if (has_filter('wp_idea_stream_template_args')) {
                            /**
                             * Custom action ?
                             *
                             * @param array $template_args the template arguments used to reset the post
                             */
                            $template_args = apply_filters('wp_idea_stream_template_args', $template_args);
                        }
                    }
                }
            }
            // Reset WordPress $post global.
            wp_idea_stream_reset_post(array('ID' => 0, 'post_title' => wp_idea_stream_reset_post_title($template_args['context']), 'post_author' => 0, 'post_date' => 0, 'post_type' => 'ideas', 'post_status' => 'publish', 'is_archive' => $template_args['is_archive'], 'comment_status' => $template_args['comment_status'], 'post_password' => false, 'is_tax' => $template_args['is_tax']));
            /**
             * Internally used to redirect to BuddyPress member's profile
             * if needed
             *
             * @param  string $context to help choosing the best template to use
             */
            do_action('wp_idea_stream_set_core_template', $template_args['context'], $template_args);
        } else {
            $query_loop = new stdClass();
            $query_loop->idea = $wp_query->post;
            // Should we use a custom template for single ideas ?
            $specific_single_template = get_query_template('single-ideastream');
            if (!empty($specific_single_template)) {
                $template = $specific_single_template;
            }
            // Populate the global query loop with current idea
            wp_idea_stream_set_idea_var('query_loop', $query_loop);
            // Add the id to globals
            wp_idea_stream_set_idea_var('single_idea_id', $wp_query->post->ID);
            // Are we editing an idea ?
            if (wp_idea_stream_is_edit()) {
                // Check if the idea is currently being edited by someone else
                $user_is_editing = wp_idea_stream_ideas_lock_idea($query_loop->idea->ID);
                if (!empty($user_is_editing)) {
                    wp_idea_stream_add_message(array('type' => 'info', 'content' => sprintf(__('The idea: &#34;%s&#34; is already being edited by another user.', 'wp-idea-stream'), $query_loop->idea->post_title)));
                    // Redirect the user
                    wp_safe_redirect(wp_idea_stream_get_redirect_url());
                    exit;
                }
                // Bail if user can't edit the idea
                if (!wp_idea_stream_ideas_can_edit($query_loop->idea)) {
                    wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to edit this idea.', 'wp-idea-stream')));
                    // Redirect the user
                    wp_safe_redirect(wp_idea_stream_get_redirect_url());
                    exit;
                }
                // Inform the idea is to display in an edit form
                $query_loop->idea->is_edit = true;
                $template_args = array('template_slug' => 'idea', 'template_name' => 'form', 'context' => 'edit-idea');
                $single_args = array('ID' => 0, 'post_title' => wp_idea_stream_reset_post_title($template_args['context']), 'post_author' => 0, 'post_date' => 0, 'post_type' => 'ideas', 'post_status' => 'publish', 'is_archive' => false, 'comment_status' => false, 'post_password' => false);
                // Or simply viewing one ?
            } else {
                $template_args = array('context' => 'single-idea');
                $single_args = array('is_single' => true);
            }
            /**
             * @param array $single_args the single arguments used to reset the post
             */
            wp_idea_stream_reset_post(apply_filters('wp_idea_stream_single_template_args', $single_args));
            /**
             * Internally used to redirect to Buddypress Group's
             * single idea template if needed
             *
             * @param  WP_Post $query_loop->idea the idea to display
             */
            do_action('wp_idea_stream_set_single_template', $query_loop->idea, $template_args);
        }
    }
    /**
     * No IdeaStream template matched
     */
    do_action('wp_idea_stream_set_template');
    return $template;
}
Esempio n. 4
0
/**
 * Registers a new ideas meta
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @param  string $meta_key  the identifier of the meta key to register
 * @param  string $meta_args the arguments (array of callback functions)
 * @uses   wp_idea_stream_get_idea_var() to get the globalized array of registered metas
 * @uses   sanitize_key() to sanitize the new meta key
 * @uses   wp_parse_args() to merge args with defaults
 * @uses   wp_idea_stream_set_idea_var() to update the globalized array of registered metas
 */
function wp_idea_stream_ideas_register_meta($meta_key = '', $meta_args = '')
{
    if (empty($meta_key) || !is_array($meta_args)) {
        return false;
    }
    $ideastream_metas = wp_idea_stream_get_idea_var('ideastream_metas');
    if (empty($ideastream_metas)) {
        $ideastream_metas = array();
    }
    $key = sanitize_key($meta_key);
    $args = wp_parse_args($meta_args, array('meta_key' => $key, 'label' => '', 'admin' => 'wp_idea_stream_meta_admin_display', 'form' => '', 'single' => 'wp_idea_stream_meta_single_display'));
    $ideastream_metas[$key] = (object) $args;
    wp_idea_stream_set_idea_var('ideastream_metas', $ideastream_metas);
}
/**
 * Use the Embed Profile template when an Embed profile is requested
 *
 * @since 2.3.0
 *
 * @param  string $template The WordPress Embed template
 * @return string           The appropriate template to use
 */
function wp_idea_stream_embed_profile($template = '')
{
    if (!wp_idea_stream_get_idea_var('is_user_embed') || !wp_idea_stream_get_idea_var('is_user')) {
        return $template;
    }
    return wp_idea_stream_get_template_part('embed', 'profile', false);
}
Esempio n. 6
0
        /**
         * Displays IdeaStream notices if any
         *
         * @package WP Idea Stream
         * @subpackage admin/admin
         *
         * @since 2.0.0
         *
         * @uses   wp_idea_stream_get_idea_var() to get a globalized IdeaStream var
         * @uses   esc_html() to sanitize output
         * @return string HTML output
         */
        public function admin_notices()
        {
            $notices = wp_idea_stream_get_idea_var('feedback');
            if (empty($notices['admin_notices'])) {
                return;
            }
            ?>
		<div class="update-nag">
			<?php 
            foreach ($notices['admin_notices'] as $notice) {
                ?>
				<p><?php 
                echo $notice;
                ?>
</p>
			<?php 
            }
            ?>
		</div>
		<?php 
        }
Esempio n. 7
0
/**
 * Redirect IdeaStream profile to BuddyPress one
 *
 * @package WP Idea Stream
 * @subpackage buddypress/functions
 *
 * @since  2.0.0
 *
 * @param  string $context the context of the template
 * @uses   wp_idea_stream_users_displayed_user_id() to get displayed user ID
 * @uses   wp_idea_stream_users_get_displayed_user_username() to get displayed user nicename
 * @uses   bp_core_redirect() to redirect the user to BuddyPress profile
 * @uses   wp_idea_stream_buddypress_get_user_profile_url() to get the BuddyPressified user's profile
 */
function wp_idea_stream_buddypress_profile_redirect($context = '')
{
    if (empty($context) || 'user-profile' != $context || wp_idea_stream_get_idea_var('is_user_embed')) {
        return;
    }
    // Be sure it's a user's profile
    $user_id = wp_idea_stream_users_displayed_user_id();
    // Bail if not on WP Idea Stream built in profile
    if (empty($user_id)) {
        return;
    }
    // Get user nicename
    $user_nicename = wp_idea_stream_users_get_displayed_user_username();
    // Safely redirect the user to his BuddyPress profile.
    bp_core_redirect(wp_idea_stream_buddypress_get_user_profile_url($user_id, $user_nicename));
}
Esempio n. 8
0
 /**
  * Checks if idea metas are registered and hooks to some key actions/filters
  *
  * @package WP Idea Stream
  * @subpackage ideas/classes
  *
  * @since 2.0.0
  *
  * @uses add_action() to perform custom actions at key points
  * @uses add_filter() to override some key vars
  */
 private function do_metas()
 {
     $this->metas = wp_idea_stream_get_idea_var('ideastream_metas');
     if (empty($this->metas) || !is_array($this->metas)) {
         return;
     }
     /** Admin *********************************************************************/
     add_filter('wp_idea_stream_admin_get_meta_boxes', array($this, 'register_metabox'), 10, 1);
     add_action('wp_idea_stream_save_metaboxes', array($this, 'save_metabox'), 10, 3);
     /** Front *********************************************************************/
     add_action('wp_idea_stream_ideas_the_idea_meta_edit', array($this, 'front_output'));
     add_action('wp_idea_stream_before_idea_footer', array($this, 'single_output'));
 }
Esempio n. 9
0
/**
 * Order the ideas by rates when requested
 *
 * This function is hooking to WordPress 'posts_clauses' filter. As the
 * rating query is first built by using a specific WP_Meta_Query, we need
 * to also make sure the ORDER BY clause of the sql query is customized.
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @param  array    $clauses  the idea query sql parts
 * @param  WP_Query $wp_query the WordPress query object
 * @uses   wp_idea_stream_is_ideastream() to check it's front end plugin's territory
 * @uses   wp_idea_stream_is_admin() to check it's back end plugin's territory
 * @uses   wp_idea_stream_is_orderby() to check the rates count is the requested order
 * @return array              new order clauses if needed
 */
function wp_idea_stream_set_rates_count_orderby($clauses = array(), $wp_query = null)
{
    if ((wp_idea_stream_is_ideastream() || wp_idea_stream_is_admin() || wp_idea_stream_get_idea_var('rating_widget')) && wp_idea_stream_is_orderby('rates_count')) {
        preg_match('/\\(?(\\S*).meta_key = \'_ideastream_average_rate\'/', $clauses['where'], $matches);
        if (!empty($matches[1])) {
            // default order
            $order = 'DESC';
            // Specific case for IdeaStream administration.
            if (!empty($clauses['orderby']) && 'ASC' == strtoupper(substr($clauses['orderby'], -3))) {
                $order = 'ASC';
            }
            $clauses['orderby'] = "{$matches[1]}.meta_value + 0 {$order}";
        }
    }
    return $clauses;
}
Esempio n. 10
0
 /**
  * Make sure moving an idea to a group is also moving the corresponding activities
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @param  array   $edit_args the arguments of the edited idea
  * @param  WP_Post $idea      the idea object
  * @uses   buddypress() to get BuddyPress instance
  * @uses   get_current_blog_id() to get current blog ID
  * @uses   wp_idea_stream_get_idea_var() to get globalized group id
  * @uses   wp_idea_stream_set_idea_var() to set the globalized var
  * @uses   get_post_meta() to get the idea post meta
  * @uses   WP_Idea_Stream_Group::check_idea_match_group() to check idea's status is consistent with group's visibility
  * @uses   delete_post_meta() to remove the idea's group ID post meta if needed
  * @return array   the edit arguments with component set to groups and item id to the group's item
  */
 public function update_group_activity($edit_args = array(), $idea = null)
 {
     if (empty($idea->ID)) {
         return $edit_args;
     }
     $edit_args = array('component' => buddypress()->blogs->id, 'item_id' => get_current_blog_id());
     $idea_group_id = wp_idea_stream_get_idea_var('idea_activity_group_id');
     if (!empty($idea_group_id[$idea->ID])) {
         $group_id = $idea_group_id[$idea->ID];
         // Reset the global
         wp_idea_stream_set_idea_var('idea_activity_group_id', array());
         // Try to get post meta :
     } else {
         $group_id = get_post_meta($idea->ID, '_ideastream_group_id', true);
     }
     // No proof it's an idea posted/edited within a group
     if (empty($group_id)) {
         return $edit_args;
     }
     // If group status is not consistent with idea one, remove meta before returning
     if (!self::check_idea_match_group($idea, $group_id)) {
         delete_post_meta($idea->ID, '_ideastream_group_id');
         return $edit_args;
     }
     // It's a group activity !
     return array('component' => buddypress()->groups->id, 'item_id' => $group_id);
 }
Esempio n. 11
0
/**
 * Make sure to play nice with WordPress by resetting the post global the way it was
 * before overriding it with our utility page.
 *
 * @since 2.3.0
 *
 * @global WP_Post $post
 */
function wp_idea_stream_users_embed_content_reset_post()
{
    global $post;
    // Reset post the way it was.
    $post = wp_idea_stream_get_idea_var('embed_reset_post');
    // Reset the embed user & post
    wp_idea_stream_set_idea_var('embed_user_data', null);
    wp_idea_stream_set_idea_var('embed_reset_post', null);
    // Stop filtering...
    remove_filter('post_type_link', 'wp_idea_stream_users_oembed_link', 10, 2);
    remove_filter('the_title', 'wp_idea_stream_users_oembed_title', 10, 2);
}
Esempio n. 12
0
/**
 * In case a user's profile is embed, replace the Utility page title with
 * the user's title
 *
 * @since 2.3.0
 *
 * @param  string  $title   the title of the post
 * @param  int     $post_id the post ID relative to the title
 * @return string  Unchanged link or the link to the user's title if needed
 */
function wp_idea_stream_users_oembed_title($title, $post_id)
{
    if (!isset($post_id) || wp_idea_stream_is_embed_profile() !== (int) $post_id) {
        return $title;
    }
    $user = wp_idea_stream_get_idea_var('embed_user_data');
    if (!is_a($user, 'WP_User')) {
        return $title;
    }
    return sprintf(esc_attr__('%s&#39;s profile', 'wp-idea-stream'), $user->display_name);
}
Esempio n. 13
0
/**
 * Fire the 'wp_idea_stream_enqueue_embed_scripts' action.
 * But do it only if needed
 *
 * Used to register and enqueue custom scripts for the WordPress
 * & IdeaStream embed templates
 *
 * @since 2.3.0
 */
function wp_idea_stream_enqueue_embed_scripts()
{
    // Bail if not an idea or not an embed profile
    if (wp_idea_stream_get_post_type() === get_query_var('post_type') && !wp_idea_stream_is_rating_disabled() || wp_idea_stream_get_idea_var('is_user_embed') && wp_idea_stream_is_embed_profile()) {
        do_action('wp_idea_stream_enqueue_embed_scripts');
    }
}
Esempio n. 14
0
/**
 * Checks whether the current site is using default permalink settings or custom one
 *
 * @package WP Idea Stream
 * @subpackage core/rewrites
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_get_idea_var() to get global value
 * @uses   apply_filters() call 'wp_idea_stream_is_pretty_links' to override permalink settings
 * @return bool True if custom permalink are one, false otherwise
 */
function wp_idea_stream_is_pretty_links()
{
    $pretty_links = wp_idea_stream_get_idea_var('pretty_links');
    return (bool) apply_filters('wp_idea_stream_is_pretty_links', !empty($pretty_links));
}
Esempio n. 15
0
 /**
  * Creates a comments submenu to the IdeaStream menu
  *
  * @package WP Idea Stream
  * @subpackage admin/comments
  *
  * @since 2.0.0
  *
  * @param  array  $menus list of menu items to add
  * @uses   wp_idea_stream_get_idea_var() to get a globalized value
  * @uses   wp_idea_stream_comments_count_comments() to build stats about idea comments
  * @uses   WP_Idea_Stream_Admin_Comments->bubbled_menu() to build the pending count bubble
  * @uses   add_query_arg() to build the parent slug
  * @return array         the new menu items
  */
 public function comments_menu($menus = array())
 {
     // Comments menu title
     $comments_menu_title = esc_html__('Comments', 'wp-idea-stream');
     $this->idea_comment_count = wp_idea_stream_get_idea_var('idea_comment_count');
     if (empty($this->idea_comment_count)) {
         $this->idea_comment_count = wp_idea_stream_comments_count_comments();
     }
     $comments_menu_title = $this->bubbled_menu($comments_menu_title . ' ', $this->idea_comment_count->moderated);
     $menus[0] = array('type' => 'comments', 'parent_slug' => wp_idea_stream()->admin->parent_slug, 'page_title' => esc_html__('Comments', 'wp-idea-stream'), 'menu_title' => $comments_menu_title, 'capability' => 'edit_ideas', 'slug' => add_query_arg('post_type', $this->post_type, 'edit-comments.php'), 'function' => '', 'alt_screen_id' => 'edit-comments.php', 'actions' => array('admin_head-%page%' => array($this, 'comments_menu_highlight')));
     return $menus;
 }