示例#1
0
/**
 * Checks if the category taxonomy has terms
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   apply_filters() call 'wp_idea_stream_ideas_pre_has_terms' to disable the category checkboxes
 *                         call 'wp_idea_stream_ideas_get_terms_args' to customize the terms to retrieve
 * @uses   wp_idea_stream_ideas_get_terms() to get the terms
 * @uses   wp_idea_stream_get_category() to get the category taxonomy identifier
 * @uses   wp_idea_stream_set_idea_var() to globalize the terms for a later use
 * @return bool true if category has terms, false otherwise
 */
function wp_idea_stream_ideas_has_terms()
{
    // Allow hiding cats
    $pre_has_terms = apply_filters('wp_idea_stream_ideas_pre_has_terms', true);
    if (empty($pre_has_terms)) {
        return false;
    }
    // Allow category listing override
    $args = apply_filters('wp_idea_stream_ideas_get_terms_args', array());
    // Get all terms matching args
    $terms = wp_idea_stream_ideas_get_terms(wp_idea_stream_get_category(), $args);
    if (empty($terms)) {
        return false;
    }
    // Catch terms
    wp_idea_stream_set_idea_var('edit_form_terms', $terms);
    // Inform we have categories
    return true;
}
示例#2
0
/**
 * Finally Loads the component into BuddyPress instance
 *
 * @package WP Idea Stream
 * @subpackage buddypress/loader
 *
 * @since 2.0.0
 *
 * @uses  wp_idea_stream() to get plugin's main instance
 * @uses  buddypress() to get BuddyPress main instance
 * @uses  get_option() to check for BuddyPress integration setting
 * @uses  is_admin() to check for the Administration context
 * @uses  wp_idea_stream_get_includes_dir() to get plugin's include dir
 * @uses  wp_idea_stream_set_idea_var() to globalize a value for a later use
 * @uses  add_query_arg(), admin_url() to build an url
 * @uses  WP_Idea_Stream_BuddyPress to launch the IdeaStream BuddyPress component
 */
function wp_idea_stream_buddypress()
{
    // Init a dummy BuddyPress version
    $bp_version = 0;
    // Set the required version
    $required_buddypress_version = '2.4.0';
    // Get main plugin instance
    $wp_idea_stream = wp_idea_stream();
    // Try to get buddypress()
    if (function_exists('buddypress')) {
        $bp_version = buddypress()->version;
    }
    // Should we load ? Yes, try by default!
    if (!get_option('_ideastream_buddypress_integration', 1)) {
        // Include at least BuddyPress filters & settings in order to extend
        // WP Idea Stream Settings and let the Admin deactivate/activate BuddyPress
        // integration.
        if (is_admin()) {
            require wp_idea_stream_get_includes_dir() . 'buddypress/settings.php';
        }
        // Prevent BuddyPress Integration load
        return;
    }
    // If BuddyPress required version does not match, provide a feedback
    // Does not fire if BuddyPress integration is disabled.
    if (!version_compare($bp_version, $required_buddypress_version, '>=')) {
        if (is_admin()) {
            wp_idea_stream_set_idea_var('feedback', array('admin_notices' => array(sprintf(esc_html__('To benefit of WP Idea Stream in BuddyPress, version %s of BuddyPress is required. Please upgrade or deactivate %s.', 'wp-idea-stream'), $required_buddypress_version, '<a href="' . esc_url(add_query_arg(array('page' => 'ideastream'), admin_url('options-general.php'))) . '#buddypress">"BuddyPress integration"</a>'))));
            require wp_idea_stream_get_includes_dir() . 'buddypress/settings.php';
        }
        // Prevent BuddyPress Integration load.
        return;
    }
    buddypress()->ideastream = new WP_Idea_Stream_BuddyPress();
}
示例#3
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);
}
/**
 * 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;
}
示例#5
0
/**
 * Merge legacy options and do some clean up
 *
 * @package WP Idea Stream
 * @subpackage core/upgrade
 *
 * @since 2.0.0
 *
 * @uses  get_option() to get legacy options
 * @uses  delete_option() to remove no more used options
 * @uses  update_option() to reset page on front if needed
 * @uses  wp_idea_stream_set_idea_var() to set the admin notices
 * @uses  set_transient() to inform a redirect is needed at next page load
 */
function wp_idea_stream_merge_legacy_options($default_options = array())
{
    // First, as previously root slug was "is", let's keep it to avoid 404 in tag & category archive
    if (!empty($default_options['_ideastream_root_slug'])) {
        $default_options['_ideastream_root_slug'] = 'is';
    }
    $options_to_remove = array('_ideastream_builtin_rating', '_ideastream_sharing_options', '_ideastream_twitter_account', '_ideastream_feature_from_comments', '_ideastream_allowed_featuring_members', '_ideastream_editor_config', '_ideastream_vestion', '_ideastream_image_width');
    $editor_settings = get_option('_ideastream_editor_config');
    if (!empty($editor_settings) && is_array($editor_settings)) {
        if (empty($editor_settings['image'])) {
            $default_options['_ideastream_editor_image'] = 0;
        }
        if (empty($editor_settings['link'])) {
            $default_options['_ideastream_editor_link'] = 0;
        }
    }
    foreach ($options_to_remove as $to_remove) {
        delete_option($to_remove);
    }
    $options_to_keep = array('_ideastream_version', '_ideastream_submit_status', '_ideastream_moderation_message', '_ideastream_login_message', '_ideastream_hint_list');
    foreach ($options_to_keep as $to_keep) {
        unset($default_options[$to_keep]);
    }
    $notice = array('admin_notices' => array(sprintf(esc_html__('Please take a few minutes to read the WP Idea Stream %s page: version 2.0.0 introduced some new features and stopped supporting some others.', 'wp-idea-stream'), '<a href="' . esc_url(add_query_arg(array('page' => 'about-ideastream'), admin_url('index.php'))) . '">' . esc_html__('About', 'wp-idea-stream') . '</a>')));
    // Check if page on front is set to all-ideas
    if ('all-ideas' == get_option('page_on_front')) {
        update_option('page_on_front', false);
        // Bring back posts to front
        update_option('show_on_front', 'posts');
        // Add a notice
        $notice['admin_notices'][] = esc_html__('For instance, having the ideas directly on your site&#39;s front page is no more supported in 2.0.0, sorry.', 'wp-idea-stream');
    }
    wp_idea_stream_set_idea_var('feedback', $notice);
    // If the plugin was deactivated while 1.2 and reactivated with 2.0.0
    set_transient('_ideastream_reactivated_upgrade', true, 60);
    return $default_options;
}
/**
 * Filters the <title> content
 *
 * Inspired by bbPress's bbp_title()
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @param array $title the title parts
 * @uses  wp_idea_stream_is_ideastream() to make sure it's plugin's territory
 * @uses  wp_idea_stream_is_addnew() to check the submit form is displayed
 * @uses  wp_idea_stream_is_user_profile() to check if a user's profile is displayed
 * @uses  wp_idea_stream_users_get_displayed_user_displayname() to get the display name of the user being viewed
 * @uses  wp_idea_stream_is_single_idea() to check whether page is displaying the single idea template
 * @uses  is_tax() to check if a taxonomy is in queried objects
 * @uses  wp_idea_stream_get_current_term() to get the current term
 * @uses  get_taxonomy() to get the taxonomy
 * @uses  wp_idea_stream_set_idea_var() to globalize the current term
 * @uses  wp_idea_stream_is_signup() to check if on the signup page
 * @uses  apply_filters() call 'wp_idea_stream_title' to override the title meta tag of the page
 * @return string the page title meta tag
 */
function wp_idea_stream_title($title_array = array())
{
    if (!wp_idea_stream_is_ideastream()) {
        return $title_array;
    }
    $new_title = array();
    if (wp_idea_stream_is_addnew()) {
        $new_title[] = esc_attr__('New idea', 'wp-idea-stream');
    } elseif (wp_idea_stream_is_edit()) {
        $new_title[] = esc_attr__('Edit idea', 'wp-idea-stream');
    } elseif (wp_idea_stream_is_user_profile()) {
        $new_title[] = sprintf(esc_html__('%s&#39;s profile', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname());
    } elseif (wp_idea_stream_is_single_idea()) {
        $new_title[] = single_post_title('', false);
    } elseif (is_tax()) {
        $term = wp_idea_stream_get_current_term();
        if ($term) {
            $tax = get_taxonomy($term->taxonomy);
            // Catch the term for later use
            wp_idea_stream_set_idea_var('current_term', $term);
            $new_title[] = single_term_title('', false);
            $new_title[] = $tax->labels->name;
        }
    } elseif (wp_idea_stream_is_signup()) {
        $new_title[] = esc_html__('Create an account', 'wp-idea-stream');
    } else {
        $new_title[] = esc_html__('Ideas', 'wp-idea-stream');
    }
    // Compare new title with original title
    if (empty($new_title)) {
        return $title_array;
    }
    $title_array = array_diff($title_array, $new_title);
    $new_title_array = array_merge($title_array, $new_title);
    /**
     * @param  string $new_title the filtered title
     * @param  string $sep
     * @param  string $seplocation
     * @param  string $title the original title meta tag
     */
    return apply_filters('wp_idea_stream_title', $new_title_array, $title_array, $new_title);
}
示例#7
0
/**
 * Sets the edit idea form global to load needed scripts
 *
 * @package WP Idea Stream
 * @subpackage buddypress/functions
 *
 * @since  2.0.0
 *
 * @uses bp_is_group() to check a group is displayed
 * @uses wp_idea_stream_set_idea_var() to set the new form global
 */
function wp_idea_stream_buddypress_set_is_edit()
{
    if (!bp_is_group()) {
        return;
    }
    wp_idea_stream_set_idea_var('is_edit', true);
}
示例#8
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));
 }
示例#9
0
/**
 * Sets a new message to inform user
 *
 * Inspired by BuddyPress's bp_core_setup_message() function
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_get_idea_var() to get the feedback
 * @uses   wp_idea_stream_set_idea_var() to globalize the feedback
 */
function wp_idea_stream_set_user_feedback()
{
    // Check Global if any
    $feedback = wp_idea_stream_get_idea_var('feedback');
    // Check cookies if any
    if (empty($feedback) && !empty($_COOKIE['wp-idea-stream-feedback'])) {
        wp_idea_stream_set_idea_var('feedback', array('type' => wp_unslash($_COOKIE['wp-idea-stream-feedback-type']), 'content' => wp_unslash($_COOKIE['wp-idea-stream-feedback'])));
    }
    // Remove cookies if set.
    if (isset($_COOKIE['wp-idea-stream-feedback'])) {
        @setcookie('wp-idea-stream-feedback', false, time() - 1000, COOKIEPATH);
    }
    if (isset($_COOKIE['wp-idea-stream-feedback-type'])) {
        @setcookie('wp-idea-stream-feedback-type', false, time() - 1000, COOKIEPATH);
    }
}
示例#10
0
 /**
  * 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));
 }
示例#11
0
 /**
  * Saves the sticky preference for the idea
  *
  * @package WP Idea Stream
  * @subpackage admin/sticky
  *
  * @since 2.0.0
  *
  * @param  int      $id     the idea ID
  * @param  WP_Post  $idea   the idea object
  * @param  bool     $update whether it's an update or not
  * @uses   wp_idea_stream_set_idea_var() to set an IdeaStream global for a later use
  * @uses   check_admin_referer() to check the request was made on the site
  * @uses   wp_idea_stream_ideas_get_stickies() to get the sticky ideas (list of IDs)
  * @uses   update_option() to update the list of sticky ideas
  * @return int          the idea ID
  */
 public function sticky_metabox_save($id = 0, $idea = null, $update = false)
 {
     $updated_message = false;
     // Private post or password protected ideas cant be sticky
     if ('private' == $idea->post_status || !empty($idea->post_password)) {
         // Eventually add a message
         if (!empty($_POST['wp_idea_stream_sticky'])) {
             wp_idea_stream_set_idea_var('feedback', array('updated_message' => 14));
         }
         return $id;
     }
     // Nonce check
     if (!empty($_POST['wp_idea_stream_sticky_metabox']) && check_admin_referer('wp_idea_stream_sticky_metabox_save', 'wp_idea_stream_sticky_metabox')) {
         $sticky_ideas = wp_idea_stream_ideas_get_stickies();
         $updated_stickies = $sticky_ideas;
         // The idea is no more sticky
         if (empty($_POST['wp_idea_stream_sticky']) && in_array($id, $sticky_ideas)) {
             $updated_stickies = array_diff($updated_stickies, array($id));
             $updated_message = 15;
         }
         // The idea is to mark as sticky
         if (!empty($_POST['wp_idea_stream_sticky']) && !in_array($id, $sticky_ideas)) {
             $updated_stickies = array_merge($updated_stickies, array($id));
             $updated_message = 16;
         }
         if ($sticky_ideas != $updated_stickies) {
             update_option('sticky_ideas', $updated_stickies);
         }
     }
     if (!empty($updated_message)) {
         wp_idea_stream_set_idea_var('feedback', array('updated_message' => $updated_message));
     }
     return $id;
 }
示例#12
0
 /**
  * Saves the preferences set in the Group's metabox
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @param  int      $id     the idea ID
  * @param  WP_Post  $idea   the idea object
  * @param  boolean $update  whether it's an idea update or not
  * @uses   buddypress() to get BuddyPress instance
  * @uses   check_admin_referer() to check the request was made on the site
  * @uses   get_post_meta() to get the idea's attached group
  * @uses   delete_post_meta() to remove the attached group
  * @uses   groups_is_user_member() to check the author is member of the group
  * @uses   groups_get_group() to get a group's object thanks to its ID
  * @uses   wp_idea_stream_set_idea_var() to set an IdeaStream global for a later use
  * @uses   do_action() Calls 'wp_idea_stream_buddypress_group_changed' to perform custom actions
  */
 public function save_group_idea_metabox($id = 0, $idea = null, $update = false)
 {
     // Initialize vars
     $component_id = buddypress()->groups->id;
     $updated_message = false;
     $new_group = null;
     // Nonce check
     if (!empty($_POST['wp_idea_stream_group_metabox']) && check_admin_referer('wp_idea_stream_group_metabox_save', 'wp_idea_stream_group_metabox')) {
         $current_group_id = (int) get_post_meta($id, '_ideastream_group_id', true);
         $group_id = 0;
         if (!empty($_POST['_ideastream_group_id'])) {
             $group_id = absint($_POST['_ideastream_group_id']);
         }
         // The idea is no more linked to any group
         if (empty($group_id) && !empty($current_group_id)) {
             delete_post_meta($id, '_ideastream_group_id');
             $updated_message = 18;
             // Reset the BuddyPress component
             $component_id = '';
             // Update the group association if group exists and is consistent with idea status.
         } else {
             /**
              * No message in this case, idea was not attached to a group
              * and it's still the case
              */
             if (empty($group_id)) {
                 return $id;
             }
             // Author is not a member of the group, inform but do not touch to meta
             if (!groups_is_user_member($idea->post_author, $group_id)) {
                 wp_idea_stream_set_idea_var('feedback', array('updated_message' => 17));
                 return $id;
             }
             $new_group = groups_get_group(array('group_id' => $group_id, 'populate_extras' => false));
             if (!empty($new_group->id)) {
                 switch ($idea->post_status) {
                     case 'private':
                         if ($new_group->status == 'public') {
                             $updated_message = 20;
                             $group_id = 0;
                         }
                         break;
                     case 'publish':
                         if ($new_group->status != 'public' || !empty($idea->post_password)) {
                             $updated_message = 20;
                             $group_id = 0;
                         }
                         break;
                         /* pending, draft...*/
                     /* pending, draft...*/
                     default:
                         $group_id = 0;
                         break;
                 }
             } else {
                 // No group found, inform but do not touch to meta
                 wp_idea_stream_set_idea_var('feedback', array('updated_message' => 21));
                 return $id;
             }
             // Idea moves into another group
             if (!empty($group_id) && $group_id != $current_group_id) {
                 update_post_meta($id, '_ideastream_group_id', $group_id);
                 $updated_message = 19;
             }
             /**
              * Status of the idea is not matching the visibility
              * of the group.
              */
             if (20 == $updated_message) {
                 // delete post meta one was saved.
                 if (!empty($current_group_id)) {
                     delete_post_meta($id, '_ideastream_group_id');
                 }
                 // Reset the BuddyPress component
                 $component_id = '';
             }
         }
         /**
          * Internally used to update/delete activities if Blogs & Activity component
          * are active.
          *
          * - $component_id is '' : no more attached to the groups component
          *   -> status dont match anymore
          *   -> link to group is removed
          *
          * - $current_group_id and $new_group->id are set but != : idea has moved into another group
          * - $current_group_id and $new_group->id are set and == : nothing has changed
          *
          * @param  WP_Post             $idea              Idea object
          * @param  string              $component_id      the groups component id
          * @param  int 	               $current_group_id  the previous group id
          * @param  BP_Groups_Group 	   $new_group         the new group
          */
         do_action('wp_idea_stream_buddypress_group_changed', $idea, $component_id, $current_group_id, $new_group);
     }
     if (!empty($updated_message)) {
         wp_idea_stream_set_idea_var('feedback', array('updated_message' => $updated_message));
     }
     return $id;
 }
示例#13
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);
}
示例#14
0
/**
 * In case a user's profile is embed, we need to reset all the parts we've altered
 * to make the user's embed profile works.
 *
 * @since 2.3.0
 *
 * @param  string  $output  the HTML output for the embed object
 * @param  WP_Post $post    the post object relative to the output
 * @return string  Unchanged the HTML output for the embed object
 */
function wp_idea_stream_embed_html($output, $post)
{
    if (isset($post->ID) && wp_idea_stream_is_embed_profile() === (int) $post->ID) {
        // Remove temporarly filters
        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);
        // Reset the globalized user.
        wp_idea_stream_set_idea_var('embed_user_data', null);
    }
    return $output;
}
示例#15
0
        /**
         * Display the widget on front end
         *
         * @package WP Idea Stream
         * @subpackage ideas/widgets
         *
         * @since 2.0.0
         *
         * @uses   apply_filters() call 'widget_title' to override the widget title
         *                         call 'wp_idea_stream_ideas_popular_args' to customize args
         * @uses   wp_idea_stream_set_idea_var() to globalized a value
         * @uses   a new Ideas loop
         * @uses   wp_idea_stream_maybe_reset_postdata() to reset post data
         */
        public function widget($args = array(), $instance = array())
        {
            // Default to comment_count
            $orderby = 'comment_count';
            if (!empty($instance['orderby'])) {
                $orderby = $instance['orderby'];
            }
            // Default per_page is 5
            $number = 5;
            // No nav items to show !? Stop!
            if (!empty($instance['number'])) {
                $number = (int) $instance['number'];
            }
            // Default title is nothing
            $title = '';
            if (!empty($instance['title'])) {
                $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
            }
            echo $args['before_widget'];
            if (!empty($title)) {
                echo $args['before_title'] . $title . $args['after_title'];
            }
            // Popular argumments.
            $idea_args = apply_filters('wp_idea_stream_ideas_popular_args', array('per_page' => $number, 'orderby' => $orderby, 'is_widget' => true));
            if ('rates_count' == $orderby) {
                wp_idea_stream_set_idea_var('rating_widget', true);
            }
            // Display the popular ideas
            if (wp_idea_stream_ideas_has_ideas($idea_args)) {
                ?>

		<ul>

			<?php 
                while (wp_idea_stream_ideas_the_ideas()) {
                    wp_idea_stream_ideas_the_idea();
                    ?>

				<li>
					<a href="<?php 
                    wp_idea_stream_ideas_the_permalink();
                    ?>
" title="<?php 
                    wp_idea_stream_ideas_the_title_attribute();
                    ?>
"><?php 
                    wp_idea_stream_ideas_the_title();
                    ?>
</a>
					<span class="count">
						<?php 
                    if ('comment_count' == $orderby) {
                        ?>
							(<?php 
                        wp_idea_stream_ideas_the_comment_number();
                        ?>
)
						<?php 
                    } else {
                        ?>
							(<?php 
                        wp_idea_stream_ideas_the_average_rating();
                        ?>
)
						<?php 
                    }
                    ?>
					</span>
				</li>

		<?php 
                }
                // Reset post data
                wp_idea_stream_maybe_reset_postdata();
                ?>

		</ul>
		<?php 
            }
            if ('rates_count' == $orderby) {
                wp_idea_stream_set_idea_var('rating_widget', false);
            }
            echo $args['after_widget'];
        }