예제 #1
0
/**
 * Replace or Add the user's profile link to the comment authors
 *
 * @package WP Idea Stream
 * @subpackage comments/functions
 *
 * @since 2.0.0
 *
 * @param  array   $comments the list of comments in an array
 * @param  int     $idea_id  the ID of the idea
 * @uses   wp_idea_stream_is_single_idea() to make sure the single template of an idea is displayed
 * @uses   esc_url() to sanitize the url
 * @uses   wp_idea_stream_users_get_user_profile_url() to build the link to user's profile
 * @return array             the list of comments, author links replaced by their IdeaStream profile if needed
 */
function wp_idea_stream_comments_append_profile_url($comments = array(), $idea_id = 0)
{
    // Only filter comments arry if on a single idea
    if (!wp_idea_stream_is_single_idea() || empty($comments) || empty($idea_id)) {
        return $comments;
    }
    foreach ($comments as $key => $comment) {
        if (empty($comment->user_id)) {
            continue;
        }
        $comments[$key]->comment_author_url = esc_url(wp_idea_stream_users_get_user_profile_url($comment->user_id));
    }
    return $comments;
}
예제 #2
0
/**
 * Gets the footer of an idea
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   wp_idea_stream_ideas_get_the_term_list() to get the taxonomy term list
 * @uses   wp_idea_stream_get_category() to get the category taxonomy identifier
 * @uses   wp_idea_stream_get_tag() to get the tag taxonomy identifier
 * @uses   mysql2date() to format the date
 * @uses   wp_idea_stream_is_single_idea() to check if the idea is displayed on its single template
 * @uses   wp_idea_stream_user_can() to check for user's capability
 * @uses   esc_url() to sanitize url
 * @uses   get_edit_post_link() to get the edit link of an idea
 * @uses   wp_idea_stream_users_get_user_data() to get user's attribute
 * @uses   wp_idea_stream_users_get_user_profile_url() to get user's profile link
 * @uses   get_avatar() to get user's avatar
 * @uses   esc_html() to sanitize the output
 * @uses   apply_filters() call 'wp_idea_stream_ideas_get_idea_footer' to override the output
 * @return string  output for the footer
 */
function wp_idea_stream_ideas_get_idea_footer()
{
    $idea = wp_idea_stream()->query_loop->idea;
    $retarray = array('start' => __('This idea', 'wp-idea-stream'));
    $category_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_category());
    if (!empty($category_list)) {
        $retarray['category'] = sprintf(_x('was posted in %s', 'idea categories comma separated list', 'wp-idea-stream'), $category_list);
    }
    $tag_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_tag());
    if (!empty($tag_list)) {
        $in = _x('and tagged', 'idea tags join words', 'wp-idea-stream');
        if (empty($category_list)) {
            $in = _x('was tagged', 'idea tags join words no category', 'wp-idea-stream');
        }
        $retarray['tag'] = sprintf(_x('%1$s %2$s', 'idea tags comma separated list', 'wp-idea-stream'), $in, $tag_list);
    }
    if (empty($retarray['category']) && empty($retarray['tag'])) {
        $retarray['posted'] = _x('was posted', 'idea footer empty tags and categories', 'wp-idea-stream');
    }
    $date = apply_filters('get_the_date', mysql2date(get_option('date_format'), $idea->post_date));
    if (!wp_idea_stream_is_single_idea()) {
        // point at the end
        $retarray['date'] = sprintf(_x('on %s.', 'idea date of publication point', 'wp-idea-stream'), $date);
    } else {
        // no point at the end
        $retarray['date'] = sprintf(_x('on %s', 'idea date of publication no point', 'wp-idea-stream'), $date);
        $user = wp_idea_stream_users_get_user_data('id', $idea->post_author);
        $user_link = '<a class="idea-author" href="' . esc_url(wp_idea_stream_users_get_user_profile_url($idea->post_author, $user->user_nicename)) . '" title="' . esc_attr($user->display_name) . '">';
        $user_link .= get_avatar($idea->post_author, 20) . esc_html($user->display_name) . '</a>';
        $retarray['author'] = sprintf(_x('by %s.', 'single idea author link', 'wp-idea-stream'), $user_link);
    }
    // Init edit url
    $edit_url = '';
    // Super admin will use the IdeaStream Administration screens
    if (wp_idea_stream_user_can('wp_idea_stream_ideas_admin')) {
        $edit_url = get_edit_post_link($idea->ID);
        // The author will use the front end edit form
    } else {
        if (wp_idea_stream_ideas_can_edit($idea)) {
            $edit_url = wp_idea_stream_get_form_url(wp_idea_stream_edit_slug(), $idea->post_name);
        }
    }
    if (!empty($edit_url)) {
        $retarray['edit'] = '<a href="' . esc_url($edit_url) . '" title="' . esc_attr__('Edit Idea', 'wp-idea-stream') . '">' . esc_html__('Edit Idea', 'wp-idea-stream') . '</a>';
    }
    /**
     * @param  string  the footer to output
     * @param  array   $retarray the parts of the footer organized in an associative array
     * @param  WP_Post $idea the idea object
     */
    return apply_filters('wp_idea_stream_ideas_get_idea_footer', join(' ', $retarray), $retarray, $idea);
}
예제 #3
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: &#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
/**
 * Adds needed scripts to rate the idea or add tags to it
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_is_ideastream() to check it's plugin territory
 * @uses   wp_idea_stream_is_single_idea() to check if a single idea is displayed
 * @uses   wp_idea_stream_is_edit() to check if the idea is being edited
 * @uses   wp_idea_stream_is_rating_disabled() to check if ratings are enabled
 * @uses   wp_idea_stream_count_ratings() to get the idea rating stats
 * @uses   wp_idea_stream_get_hint_list() to get the rating captions
 * @uses   wp_idea_stream_users_current_user_id() to get current user ID
 * @uses   wp_create_nonce() to create a nonce to be check when rating an idea
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   wp_enqueue_script() to add the needed scripts to WordPress queue
 * @uses   wp_idea_stream_get_js_script() to get a specific javascript
 * @uses   wp_idea_stream_get_version() to get plugin's version
 * @uses   wp_localize_script() to localized script datas
 * @uses   wp_idea_stream_is_addnew() to check the form is displayed
 * @uses   wp_idea_stream_get_single_idea_id() to get current idea ID
 * @uses   apply_filters() call 'wp_idea_stream_ideas_single_script' to add data to scripts used on single idea
 *                         call 'wp_idea_stream_ideas_form_script_vars' to add data to scripts used when using the form
 */
function wp_idea_stream_ideas_enqueue_scripts()
{
    if (!wp_idea_stream_is_ideastream()) {
        return;
    }
    // Single idea > ratings
    if (wp_idea_stream_is_single_idea() && !wp_idea_stream_is_edit() && !wp_idea_stream_is_rating_disabled()) {
        $ratings = (array) wp_idea_stream_count_ratings();
        $users_nb = count($ratings['users']);
        $hintlist = (array) wp_idea_stream_get_hint_list();
        $js_vars = array('raty_loaded' => 1, 'ajaxurl' => admin_url('admin-ajax.php', 'relative'), 'wait_msg' => esc_html__('Saving your rating, please wait', 'wp-idea-stream'), 'success_msg' => esc_html__('Thanks, the average rating is now:', 'wp-idea-stream'), 'error_msg' => esc_html__('OOps, something went wrong', 'wp-idea-stream'), 'average_rate' => $ratings['average'], 'rate_nb' => $users_nb, 'one_rate' => esc_html__('One rate', 'wp-idea-stream'), 'x_rate' => esc_html__('% rates', 'wp-idea-stream'), 'readonly' => true, 'can_rate' => wp_idea_stream_user_can('rate_ideas'), 'not_rated' => esc_html__('Not rated yet', 'wp-idea-stream'), 'hints' => $hintlist, 'hints_nb' => count($hintlist), 'wpnonce' => wp_create_nonce('wp_idea_stream_rate'));
        $user_id = wp_idea_stream_users_current_user_id();
        if (wp_idea_stream_user_can('rate_ideas')) {
            $js_vars['readonly'] = 0 != $users_nb ? in_array($user_id, $ratings['users']) : false;
        }
        wp_enqueue_script('wp-idea-stream-script', wp_idea_stream_get_js_script('script'), array('jquery-raty'), wp_idea_stream_get_version(), true);
        wp_localize_script('wp-idea-stream-script', 'wp_idea_stream_vars', apply_filters('wp_idea_stream_ideas_single_script', $js_vars));
    }
    // Form > tags
    if (wp_idea_stream_is_addnew() || wp_idea_stream_is_edit()) {
        // Default dependencies
        $deps = array('tagging');
        // Defaul js vars
        $js_vars = array('tagging_loaded' => 1, 'taginput_name' => 'wp_idea_stream[_the_tags][]', 'duplicate_tag' => __('Duplicate tag:', 'wp-idea-stream'), 'forbidden_chars' => __('Forbidden character:', 'wp-idea-stream'), 'forbidden_words' => __('Forbidden word:', 'wp-idea-stream'));
        // Add HeartBeat if idea is being edited
        if (wp_idea_stream_is_edit()) {
            $deps = array_merge($deps, array('heartbeat'));
            $js_vars = array_merge($js_vars, array('idea_id' => wp_idea_stream_get_single_idea_id(), 'pulse' => 'fast', 'warning' => esc_html__('An admin is currently editing this idea, please try to edit your idea later.', 'wp-idea-stream')));
        }
        // Enqueue and localize script
        wp_enqueue_script('wp-idea-stream-script', wp_idea_stream_get_js_script('script'), $deps, wp_idea_stream_get_version(), true);
        wp_localize_script('wp-idea-stream-script', 'wp_idea_stream_vars', apply_filters('wp_idea_stream_ideas_form_script_vars', $js_vars));
    }
}
/**
 * Set the document title for IdeaStream pages
 *
 * @since  2.3.0
 *
 * @param  array  $document_title The WordPress Document title
 * @return array                  The IdeaStream Document title
 */
function wp_idea_stream_document_title_parts($document_title = array())
{
    if (!wp_idea_stream_is_ideastream()) {
        return $document_title;
    }
    $new_document_title = $document_title;
    // Reset the document title if needed
    if (!wp_idea_stream_is_single_idea()) {
        $title = (array) wp_idea_stream_title();
        // On user's profile, add some piece of info
        if (wp_idea_stream_is_user_profile() && count($title) === 1) {
            // Seeing comments of the user
            if (wp_idea_stream_is_user_profile_comments()) {
                $title[] = __('Idea Comments', 'wp-idea-stream');
                // Get the pagination page
                if (get_query_var(wp_idea_stream_cpage_rewrite_id())) {
                    $cpage = get_query_var(wp_idea_stream_cpage_rewrite_id());
                } elseif (!empty($_GET[wp_idea_stream_cpage_rewrite_id()])) {
                    $cpage = $_GET[wp_idea_stream_cpage_rewrite_id()];
                }
                if (!empty($cpage)) {
                    $title['page'] = sprintf(__('Page %s', 'wp-idea-stream'), (int) $cpage);
                }
                // Seeing Ratings for the user
            } elseif (wp_idea_stream_is_user_profile_rates()) {
                $title[] = __('Idea Ratings', 'wp-idea-stream');
                // Seeing The root profile
            } else {
                $title[] = __('Ideas', 'wp-idea-stream');
            }
        }
        // Get WordPress Separator
        $sep = apply_filters('document_title_separator', '-');
        $new_document_title['title'] = implode(" {$sep} ", array_filter($title));
    }
    // Set the site name if not already set.
    if (!isset($new_document_title['site'])) {
        $new_document_title['site'] = get_bloginfo('name', 'display');
    }
    // Unset tagline for IdeaStream Pages
    if (isset($new_document_title['tagline'])) {
        unset($new_document_title['tagline']);
    }
    return apply_filters('wp_idea_stream_document_title_parts', $new_document_title, $document_title);
}
예제 #7
0
 /**
  * Displays metas for single display
  *
  * @package WP Idea Stream
  * @subpackage ideas/classes
  *
  * @since 2.0.0
  *
  * @uses   WP_Idea_Stream_Idea_Metas->front_output() to display the meta output
  * @return string          HTML Output
  */
 public function single_output()
 {
     if (!wp_idea_stream_is_single_idea()) {
         return;
     }
     return $this->front_output('single');
 }
예제 #8
0
        /**
         * Display the Featured image for the current idea
         *
         * @since  2.3.0
         *
         * @return string HTML Output
         */
        public function featured_image()
        {
            if (!wp_idea_stream_featured_images_allowed() || !current_theme_supports('post-thumbnails') || !bp_is_group() || !wp_idea_stream_is_single_idea()) {
                return;
            }
            $args = bp_parse_args(array(), array('size' => 'post-thumbnail', 'attr' => '', 'container_class' => 'post-thumbnail'), 'wp_idea_stream_featured_image');
            ?>
		<div class="<?php 
            echo sanitize_html_class($args['container_class']);
            ?>
">
			<?php 
            echo get_the_post_thumbnail(wp_idea_stream_ideas_get_id(), $args['size'], $args['attr']);
            ?>
		</div><!-- .post-thumbnail -->
		<?php 
        }