Пример #1
0
 /**
  * Override comments query args to only onclude comments about ideas
  *
  * @package WP Idea Stream
  * @subpackage comments/widgets
  *
  * @since 2.0.0
  *
  * @param  array  $comment_args
  * @uses   wp_idea_stream_get_post_type() to get the idea post type identifier
  * @return array  the comments query args to display comments about ideas
  */
 public function override_comment_args($comment_args = array())
 {
     // It's that simple !!
     $comment_args['post_type'] = wp_idea_stream_get_post_type();
     // Now return these args
     return $comment_args;
 }
Пример #2
0
 /**
  * @group admin_created
  */
 public function test_wp_idea_stream_activity_password()
 {
     // Generate a password protected idea
     $idea_id = $this->factory->post->create(array('post_type' => wp_idea_stream_get_post_type(), 'post_password' => 'password', 'post_author' => 1));
     $component = buddypress()->blogs->id;
     $a = bp_activity_get(array('filter' => array('action' => 'new_ideas', 'object' => $component, 'primary_id' => get_current_blog_id(), 'secondary_id' => $idea_id), 'show_hidden' => true));
     $this->assertTrue(empty($a['activities']), 'No activity should be generated for a password protected idea');
 }
Пример #3
0
 /**
  * Setups some globals
  *
  * @package WP Idea Stream
  * @subpackage admin/admin
  *
  * @since 2.0.0
  *
  * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier
  * @uses wp_idea_stream() to get WP Idea Stream instance
  */
 private function setup_globals()
 {
     $this->post_type = wp_idea_stream_get_post_type();
     $this->includes_dir = trailingslashit(wp_idea_stream()->includes_dir . 'admin');
     $this->parent_slug = false;
     $this->metaboxes = array();
     $this->is_plugin_settings = false;
     $this->downloading_csv = false;
 }
Пример #4
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));
 }
Пример #5
0
/**
 * Process a spammed user
 *
 * @package WP Idea Stream
 * @subpackage buddypress/functions
 *
 * @since  2.0.0
 *
 * @param  int $user_id the user ID
 * @uses   add_filter() to avoid ideas to be permanently deleted
 * @uses   wp_idea_stream_users_delete_user_data() to remove user's IdeaStream Data.
 * @uses   get_comments() to get user's comment
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   wp_spam_comment() to spam user's comments
 */
function wp_idea_stream_buddypress_spam_user($user_id = 0)
{
    if (empty($user_id)) {
        return;
    }
    // Let's trash ideas instead of completely removed them.
    add_filter('wp_idea_stream_users_delete_user_force_delete', '__return_false');
    // Remove IdeaStream Data
    wp_idea_stream_users_delete_user_data($user_id);
    // Spam approved comments about ideas
    $comments = get_comments(array('fields' => 'ids', 'user_id' => $user_id, 'post_type' => wp_idea_stream_get_post_type(), 'status' => 'approve'));
    if (!empty($comments)) {
        foreach ($comments as $comment) {
            wp_spam_comment($comment);
        }
    }
}
Пример #6
0
 /**
  * Reset activities component and item id
  *
  * Used when one or more activities are removed from a group.
  *
  * @package WP Idea Stream
  * @subpackage buddypress/activity
  *
  * @since 2.0.0
  *
  * @param  integer $item_id      the item id activities are attached to
  * @param  string  $component_id the BuddyPress component id activities are attached to
  * @param  WP_Post $idea         the idea object
  * @uses   get_post()           to get the idea object if not set
  * @uses   WP_Idea_Stream_Activity->get_idea_and_comments() to get activities to manage
  * @uses   bp_activity_get() to get activities
  * @uses   wp_idea_stream_get_post_type() to get the idea post type
  * @uses   wp_list_pluck() to pluck a certain field out of each object in a list.
  * @uses   self::bulk_edit_activity to edit activities (component and item)
  */
 public function reset_activity_item_id($item_id = 0, $component_id = '', $idea = null)
 {
     if (empty($item_id) || empty($component_id)) {
         return false;
     }
     $activities = array();
     // Get activities about the idea ( secondary_id )
     if (!empty($idea)) {
         if (!is_a($idea, 'WP_Post')) {
             $idea = get_post((int) $idea);
         }
         // Avoid some troubles in activity table
         if (empty($idea->ID)) {
             return false;
         }
         $activities = $this->get_idea_and_comments($idea->ID, $idea->post_status);
     } else {
         $get_activities = bp_activity_get(array('filter' => array('action' => array('new_' . wp_idea_stream_get_post_type(), 'new_' . wp_idea_stream_get_post_type() . '_comment'), 'object' => $component_id, 'item_id' => $item_id), 'show_hidden' => true, 'spam' => 'all', 'per_page' => false));
         if (!empty($get_activities['activities'])) {
             $activities = wp_list_pluck($get_activities['activities'], 'id');
         }
     }
     if (empty($activities)) {
         return false;
     } else {
         return self::bulk_edit_activity($activities, -1, buddypress()->blogs->id, get_current_blog_id());
     }
 }
Пример #7
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');
    }
}
Пример #8
0
/**
 * Mark notification(s) as read
 *
 * @package WP Idea Stream
 * @subpackage buddypress/notifications
 *
 * @since  2.0.0
 *
 * @uses   wp_idea_stream_is_single_idea() to check if viewing the single template of an idea
 * @uses   bp_notifications_mark_notifications_by_item_id() to mark notifications as read
 * @uses   bp_loggedin_user_id() to get the logged in user ID
 * @uses   wp_idea_stream_get_single_idea_id() to get the ID of the idea being viewed
 * @uses   buddypress() to get BuddyPress instance
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   bp_is_user() to check a user's profile is displayed
 * @uses   bp_is_current_component( 'ideastream' ) to check it's an IdeaStream part of the profile
 * @uses   bp_notifications_mark_notifications_by_type() to mark notifications as read
 */
function wp_idea_stream_buddypress_comments_mark_notifications_read()
{
    if (!empty($_GET['notif'])) {
        if (wp_idea_stream_is_single_idea()) {
            bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment');
            bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate');
        }
        if (bp_is_user() && bp_is_current_component('ideastream')) {
            bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment');
            bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate');
        }
    }
}
/**
 * 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: "%s" 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;
}
Пример #10
0
/**
 * Maps Ideas capabilities
 *
 * @package WP Idea Stream
 * @subpackage core/capabilities
 *
 * @since 2.0.0
 *
 * @param  array $caps Capabilities for meta capability
 * @param  string $cap Capability name
 * @param  int $user_id User id
 * @param  mixed $args Arguments
 * @uses   get_post() To get the post
 * @uses   get_comment() To get the comment object
 * @uses   apply_filters() Filter mapped results
 * @return array Actual capabilities for meta capability
 */
function wp_idea_stream_map_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        case 'publish_ideas':
        case 'rate_ideas':
            if (!empty($user_id)) {
                $caps = array('exist');
            } else {
                $caps = array('publish_posts');
            }
            break;
        case 'read_idea':
        case 'edit_idea':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                $caps = array();
                if (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps = array('exist');
                    // Unknown, so map to manage_options
                } else {
                    $caps[] = 'manage_options';
                }
            }
            break;
        case 'edit_ideas':
        case 'edit_others_ideas':
        case 'edit_private_ideas':
        case 'edit_published_ideas':
        case 'read_private_ideas':
            $caps = array('manage_options');
            break;
        case 'edit_comment':
            if (!is_admin()) {
                // Get the comment
                $_comment = get_comment($args[0]);
                if (!empty($_comment) && wp_idea_stream_get_post_type() == get_post_type($_comment->comment_post_ID)) {
                    $caps = array('manage_options');
                }
            }
            break;
        case 'delete_idea':
        case 'delete_ideas':
        case 'delete_others_ideas':
        case 'delete_private_ideas':
        case 'delete_published_ideas':
            $caps = array('manage_options');
            break;
            /** Taxonomies ****************************************************************/
        /** Taxonomies ****************************************************************/
        case 'manage_idea_tags':
        case 'edit_idea_tags':
        case 'delete_idea_tags':
        case 'manage_idea_categories':
        case 'edit_idea_categories':
        case 'delete_idea_categories':
            $caps = array('manage_options');
            break;
            // Open to all users that have an ID
        // Open to all users that have an ID
        case 'assign_idea_tags':
        case 'assign_idea_categories':
            if (!empty($user_id)) {
                $caps = array('exist');
            } else {
                $caps = array('manage_options');
            }
            break;
            /** Admin *********************************************************************/
        /** Admin *********************************************************************/
        case 'wp_idea_stream_ideas_admin':
            $caps = array('manage_options');
            break;
    }
    /**
     * @param  array $caps Capabilities for meta capability
     * @param  string $cap Capability name
     * @param  int $user_id User id
     * @param  mixed $args Arguments
     */
    return apply_filters('wp_idea_stream_map_meta_caps', $caps, $cap, $user_id, $args);
}
Пример #11
0
 /**
  * Setups the post type global
  *
  * @package WP Idea Stream
  * @subpackage admin/sticky
  *
  * @since 2.0.0
  *
  * @uses  wp_idea_stream_get_post_type() The ideas post type identifier
  */
 private function setup_globals()
 {
     $this->post_type = wp_idea_stream_get_post_type();
 }
Пример #12
0
 /**
  * Registers 2 new activity actions for the groups component
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @param  array  $activity_actions the existing IdeaStream activity actions
  * @uses   WP_Idea_Stream_Group::groups_activated() to check if Groups Integration is on
  * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
  * @uses   get_post_type_object() to get the ideas post type labels
  * @uses   buddypress() to get BuddyPress instance
  * @return array  the activity actions with the ones specific to groups component if needed
  */
 public static function group_activity_context($activity_actions = array())
 {
     // If groups integration is not active, stop
     if (empty($activity_actions) || !self::groups_activated()) {
         return $activity_actions;
     }
     self::$post_type = wp_idea_stream_get_post_type();
     self::$post_type_object = get_post_type_object(self::$post_type);
     $group_activity_actions = array('new_group_idea' => (object) array('component' => buddypress()->groups->id, 'type' => 'new_' . self::$post_type, 'admin_caption' => sprintf(_x('New %s published', 'activity admin dropdown caption', 'wp-idea-stream'), mb_strtolower(self::$post_type_object->labels->singular_name, 'UTF-8')), 'action_callback' => array(__CLASS__, 'group_format_idea_action'), 'front_caption' => sprintf(_x('%s', 'activity front dropdown caption', 'wp-idea-stream'), self::$post_type_object->labels->name), 'contexts' => array('activity', 'group', 'member', 'member_groups')), 'new_group_comment' => (object) array('component' => buddypress()->groups->id, 'type' => 'new_' . self::$post_type . '_comment', 'admin_caption' => sprintf(_x('New %s comment posted', 'activity comment admin dropdown caption', 'wp-idea-stream'), mb_strtolower(self::$post_type_object->labels->singular_name, 'UTF-8')), 'action_callback' => array(__CLASS__, 'group_format_comment_action'), 'front_caption' => sprintf(_x('%s comments', 'activity comments front dropdown caption', 'wp-idea-stream'), self::$post_type_object->labels->singular_name), 'contexts' => array('activity', 'group', 'member', 'member_groups')));
     return array_merge($activity_actions, $group_activity_actions);
 }
Пример #13
0
 /**
  * Registers the ideas taxonomies
  *
  * @package WP Idea Stream
  *
  * @since 2.0.0
  *
  * @uses register_taxonomy() to register the taxonomy
  * @uses wp_idea_stream_get_category() to get the category taxonomy identifier
  * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier
  * @uses wp_idea_stream_category_register_labels() to the category taxonomy labels
  * @uses wp_idea_stream_category_register_args() to the category taxonomy arguments
  * @uses wp_idea_stream_get_tag() to get the tag taxonomy identifier
  * @uses wp_idea_stream_tag_register_labels() to the tag taxonomy labels
  * @uses wp_idea_stream_tag_register_args() to the tag taxonomy arguments
  */
 public function register_taxonomies()
 {
     // Register the category taxonomy
     register_taxonomy(wp_idea_stream_get_category(), wp_idea_stream_get_post_type(), array_merge(wp_idea_stream_category_register_labels(), wp_idea_stream_category_register_args()));
     // Register the tag taxonomy
     register_taxonomy(wp_idea_stream_get_tag(), wp_idea_stream_get_post_type(), array_merge(wp_idea_stream_tag_register_labels(), wp_idea_stream_tag_register_args()));
 }
Пример #14
0
/**
 * Get the stat for the the requested type (number of ideas, comments or rates)
 *
 * @since 2.3.0
 *
 * @param string $type    the type of stat to get (eg: 'profile', 'comments', 'rates')
 * @param int    $user_id the User ID to get the stat for
 */
function wp_idea_stream_users_get_stat_for($type = '', $user_id = 0)
{
    $count = 0;
    if (empty($type)) {
        return $count;
    }
    if (empty($user_id)) {
        $user_id = wp_idea_stream_users_displayed_user_id();
    }
    if (empty($user_id)) {
        return ${$count};
    }
    if ('profile' === $type) {
        $count = count_user_posts($user_id, wp_idea_stream_get_post_type());
    } elseif ('comments' === $type) {
        $count = wp_idea_stream_comments_count_comments($user_id);
    } elseif ('rates' === $type) {
        $count = wp_idea_stream_count_user_rates($user_id);
    }
    /**
     * Filter the user stats by type (number of ideas "profile", "comments" or "rates").
     *
     * @since 2.3.0
     *
     * @param  int    $count the stat for the requested type.
     * @param  string $type "profile", "comments" or "rates".
     * @param  int    $user_id The user ID.
     */
    return (int) apply_filters('wp_idea_stream_users_get_stat_for', $count, $type, $user_id);
}
/**
 * Are we viewing ideas archive ?
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @uses   is_post_type_archive() to check if displaying the ideas archive
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   wp_idea_stream_get_idea_var() to get a globalized var
 * @uses   apply_filters() call 'wp_idea_stream_is_idea_archive' to override condition
 * @return bool true if on ideas archive, false otherwise
 */
function wp_idea_stream_is_idea_archive()
{
    $retval = false;
    if (is_post_type_archive(wp_idea_stream_get_post_type()) || wp_idea_stream_get_idea_var('is_idea_archive')) {
        $retval = true;
    }
    return apply_filters('wp_idea_stream_is_idea_archive', $retval);
}
Пример #16
0
/**
 * Handles updating an idea
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @uses   check_admin_referer() to check the request has been done from current site
 * @uses   wp_idea_stream_get_redirect_url() to get default redirect url
 * @uses   get_query_var() to get the value of a specific query var
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   get_queried_object() to try to get the idea object WordPress built
 * @uses   wp_idea_stream_ideas_get_idea_by_name() to get an idea object out of its post name
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   wp_idea_stream_add_message() to add a feddback message to user
 * @uses   wp_safe_redirect() to safely redirect the user and avoid duplicates
 * @uses   wp_idea_stream_ideas_save_idea() to save the idea
 * @uses   wp_idea_stream_get_form_url() to get the add new form url
 * @uses   wp_idea_stream_ideas_get_idea_permalink() to get the idea link
 */
function wp_idea_stream_ideas_update_idea()
{
    global $wp_query;
    // Bail if not a post request
    if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if not a post idea request
    if (empty($_POST['wp_idea_stream']) || !is_array($_POST['wp_idea_stream'])) {
        return;
    }
    // Bail if it's not an update
    if (empty($_POST['wp_idea_stream']['_the_id'])) {
        return;
    }
    // Check nonce
    check_admin_referer('wp_idea_stream_save');
    $redirect = wp_idea_stream_get_redirect_url();
    // Get idea name
    $idea_name = get_query_var(wp_idea_stream_get_post_type());
    // Get Idea Object
    $idea = get_queried_object();
    // If queried object doesn't match or wasn't helpfull, try to get the idea using core function
    if (empty($idea->post_name) || empty($idea_name) || $idea_name != $idea->post_name) {
        $idea = wp_idea_stream_ideas_get_idea_by_name($idea_name);
    }
    // Found no idea, redirect and inform the user
    if (empty($idea->ID)) {
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('The idea you are trying to edit does not seem to exist.', 'wp-idea-stream')));
        // Redirect to main archive page
        wp_safe_redirect($redirect);
        exit;
    }
    // Checks if the user can edit the idea
    if (!wp_idea_stream_ideas_can_edit($idea)) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to edit this idea.', 'wp-idea-stream')));
        // Redirect to main archive page
        wp_safe_redirect($redirect);
        exit;
    }
    $updated = array_diff_key($_POST['wp_idea_stream'], array('save' => 'submit'));
    // Title & content are required
    if (empty($updated['_the_title']) || empty($updated['_the_content'])) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Title and description are required fields.', 'wp-idea-stream')));
        // Simply stop, so that the user keeps the posted values.
        return;
    }
    // Reset '_the_id' param to the ID of the idea found
    $updated['_the_id'] = $idea->ID;
    $feedback_message = array();
    $featured_error = __('There was a problem saving the featured image, sorry.', 'wp-idea-stream');
    $featured_type = 'info';
    // Take care of the featured image
    $thumbnail_id = (int) get_post_thumbnail_id($idea);
    if (!empty($updated['_the_thumbnail'])) {
        $thumbnail_src = key($updated['_the_thumbnail']);
        $thumbnail = reset($updated['_the_thumbnail']);
        // Update the Featured image
        if (!is_numeric($thumbnail) || $thumbnail_id !== (int) $thumbnail) {
            if (is_numeric($thumbnail)) {
                // validate the attachment
                if (!get_post($thumbnail)) {
                    $feedback_message[] = $featured_error;
                    // Set the new Featured image
                } else {
                    set_post_thumbnail($idea->ID, $thumbnail);
                }
            } else {
                $sideload = WP_Idea_Stream_Ideas_Thumbnail::start($thumbnail_src, $idea->ID);
                if (is_wp_error($sideload->result)) {
                    $feedback_message[] = $featured_error;
                }
            }
        }
        // Delete the featured image
    } elseif (!empty($thumbnail_id)) {
        delete_post_thumbnail($idea);
    }
    // Update the idea
    $id = wp_idea_stream_ideas_save_idea($updated);
    if (empty($id)) {
        // Set the feedback for the user
        $featured_type = 'error';
        $feedback_message = __('Something went wrong while trying to update your idea.', 'wp-idea-stream');
        // Redirect to the form
        $redirect = wp_idea_stream_get_form_url(wp_idea_stream_edit_slug(), $idea_name);
        // Redirect to the idea
    } else {
        $redirect = wp_idea_stream_ideas_get_idea_permalink($id);
    }
    if (!empty($feedback_message)) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => $featured_type, 'content' => join(' ', $feedback_message)));
    }
    wp_safe_redirect($redirect);
    exit;
}
Пример #17
0
/**
 * Adds a shortcut to Idea Stream Backend using the appearence menus
 *
 * While developing the plugin i've found it usefull to be able to easily access
 * to IdeaStream backend from front end, so i've left it. You can disable it by using
 * the filer.
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @param  WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance
 * @uses   apply_filters() call 'wp_idea_stream_adminbar_menu' to disable the menu by returning false
 * @uses   wp_idea_stream_user_can() to check for user's capability
 * @uses   add_query_arg()
 * @uses   wp_idea_stream_get_post_type()
 * @uses   admin_url()
 */
function wp_idea_stream_adminbar_menu($wp_admin_bar = null)
{
    $use_admin_bar = apply_filters('wp_idea_stream_adminbar_menu', true);
    if (empty($use_admin_bar)) {
        return;
    }
    if (!empty($wp_admin_bar) && wp_idea_stream_user_can('edit_ideas')) {
        $menu_url = add_query_arg('post_type', wp_idea_stream_get_post_type(), admin_url('edit.php'));
        $wp_admin_bar->add_menu(array('parent' => 'appearance', 'id' => 'ideastream', 'title' => _x('IdeaStream', 'Admin bar menu', 'wp-idea-stream'), 'href' => $menu_url));
    }
}
Пример #18
0
/**
 * Output the Idea Ratings if needed into the Embedded idea
 *
 * @since  2.3.0
 *
 * @return string HTML output
 */
function wp_idea_stream_ideas_embed_meta()
{
    $idea = get_post();
    if (!isset($idea->post_type) || wp_idea_stream_get_post_type() !== $idea->post_type || wp_idea_stream_is_rating_disabled()) {
        return;
    }
    // Get the Average Rate
    $average_rate = wp_idea_stream_ideas_get_average_rating($idea->ID);
    if (!$average_rate) {
        return;
    }
    // Get rating link
    $rating_link = wp_idea_stream_ideas_get_idea_permalink($idea) . '#rate';
    ?>
	<div class="wp-idea-stream-embed-ratings">
		<a href="<?php 
    echo esc_url($rating_link);
    ?>
" target="_top">
			<span class="dashicons ideastream-star-filled"></span>
			<?php 
    printf(esc_html__('%1$sAverage Rating:%2$s%3$s', 'wp-idea-stream'), '<span class="screen-reader-text">', '</span>', $average_rate);
    ?>
		</a>
	</div>
	<?php 
}
Пример #19
0
 /**
  * Get an idea using its post name.
  *
  * @package WP Idea Stream
  * @subpackage ideas/classes
  *
  * @since 2.0.0
  *
  * @global $wpdb
  * @param  string name of the idea
  * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
  * @uses   get_post() to get the idea object
  * @return WP_Post the idea object
  */
 public static function get_idea_by_name($name = '')
 {
     global $wpdb;
     $where = $wpdb->prepare('post_name = %s AND post_type = %s', $name, wp_idea_stream_get_post_type());
     $id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE {$where}");
     return get_post($id);
 }
Пример #20
0
/**
 * Make sure the comment edit link about an ideas post type will
 * open the Ideastream Comments Submenu once cliked on.
 *
 * @package WP Idea Stream
 * @subpackage comments/functions
 *
 * @since 2.0.0
 *
 * @param  string $location the comment edit link
 * @uses   wp_idea_stream_comments_get_comment() to get the Idea comment object
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   add_query_arg() to add the post type query arg to the comment edit link
 * @uses   apply_filters() call 'wp_idea_stream_edit_comment_link' to override the url
 * @return string           the new comment edit link if about an idea, unchanged otherwise
 */
function wp_idea_stream_edit_comment_link($location = '')
{
    if (empty($location)) {
        return $location;
    }
    // Too bad WordPres is not sending the comment object or ID in the filter :(
    if (!preg_match('/[&|&amp;]c=(\\d+)/', $location, $matches)) {
        return $location;
    }
    if (empty($matches[1])) {
        return $location;
    }
    $comment_id = absint($matches[1]);
    $comment = wp_idea_stream_comments_get_comment($comment_id);
    if (empty($comment->comment_post_type) || wp_idea_stream_get_post_type() != $comment->comment_post_type) {
        return $location;
    }
    $new_location = add_query_arg('post_type', wp_idea_stream_get_post_type(), $location);
    /**
     * @param  string $new_location the new comment edit link
     * @param  string $location     the original comment edit link
     * @param  object $comment      the idea's comment object
     */
    return apply_filters('wp_idea_stream_edit_comment_link', $new_location, $location, $comment);
}
Пример #21
0
 /**
  * Sets some globals
  *
  * @package WP Idea Stream
  * @subpackage admin/comments
  *
  * @since 2.0.0
  *
  * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier
  */
 private function setup_globals()
 {
     $this->post_type = wp_idea_stream_get_post_type();
     $this->idea_comment_count = false;
 }