Example #1
0
        /**
         * Displays the ratings metabox
         *
         * @package WP Idea Stream
         * @subpackage admin/admin
         *
         * @since 2.0.0
         *
         * @param  WP_Post $idea the idea object
         * @uses   wp_idea_stream_count_ratings() to get the rating stats for the idea
         * @uses   get_edit_post_link() to get the idea edit link
         * @uses   wp_idea_stream_get_hint_list() to get the captions for the rates
         * @uses   esc_html() to sanitize output
         * @uses   number_format_i18n() to format numbers
         * @uses   wp_idea_stream_users_get_user_profile_url() to get a user's IdeaStream profile url
         * @uses   esc_url() to sanitize url
         * @uses   get_avatar() to get user's avatar
         * @uses   wp_nonce_url() to add a security token to check upon once the link clicked
         * @uses   add_query_arg() to add query vars to an url
         * @return string HTML output
         */
        public function ratings_do_metabox($idea = null)
        {
            $id = $idea->ID;
            $ratings_stats = wp_idea_stream_count_ratings($id, 0, true);
            $users_count = count($ratings_stats['users']);
            $edit_link = get_edit_post_link($id);
            if (empty($users_count)) {
                esc_html_e('Not rated yet', 'wp-idea-stream');
            } else {
                $hintlabels = wp_idea_stream_get_hint_list();
                $hintlist = array_keys($hintlabels);
                ?>
			<p class="description">
				<?php 
                echo esc_html(sprintf(_n('%1$s member rated the idea. Its Average rating is: %2$s', '%1$s members rated the idea. Its Average rating is: %2$s', $users_count, 'wp-idea-stream'), number_format_i18n($users_count), number_format_i18n($ratings_stats['average'], 1)));
                ?>
			</p>
			<ul class="admin-idea-rates">
				<?php 
                foreach ($hintlist as $hintlabel) {
                    $hint = $hintlabel + 1;
                    ?>
				<li>
					<div class="admin-idea-rates-star"><?php 
                    echo esc_html(ucfirst($hintlabels[$hintlabel]));
                    ?>
</div>
					<div class="admin-idea-rates-users">
						<?php 
                    if (empty($ratings_stats['details'][$hint])) {
                        ?>
							&#8212;
						<?php 
                    } else {
                        foreach ($ratings_stats['details'][$hint] as $user_id) {
                            ?>
							<span class="user-rated">
								<a href="<?php 
                            echo esc_url(wp_idea_stream_users_get_user_profile_url($user_id));
                            ?>
"><?php 
                            echo get_avatar($user_id, 40);
                            ?>
</a>

								<?php 
                            $edit_user_link = wp_nonce_url(add_query_arg('remove_vote', $user_id, $edit_link), 'idea_remove_vote_' . $user_id);
                            ?>

								<a href="<?php 
                            echo esc_url($edit_user_link);
                            ?>
" class="del-rate" title="<?php 
                            esc_attr_e('Delete this rating', 'wp-idea-stream');
                            ?>
" data-userid="<?php 
                            echo $user_id;
                            ?>
">
									<div class="dashicons dashicons-trash"></div>
								</a>
							</span>
						<?php 
                        }
                    }
                    ?>
					</div>
				</li>
				<?php 
                }
                ?>
			</ul>
			<?php 
            }
        }
/**
 * 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));
    }
}
Example #3
0
/**
 * List of captions for the rating stars
 *
 * @package WP Idea Stream
 * @subpackage admin/settings
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_get_hint_list() to get the active hint list
 * @uses   esc_attr() to sanitize the attribute
 * @return string HTML output
 */
function wp_idea_stream_hint_list_setting_callback()
{
    $hintlist = wp_idea_stream_get_hint_list();
    $csv_hinlist = join(',', $hintlist);
    ?>

	<label for="_ideastream_hint_list"><?php 
    esc_html_e('You can customize the hover captions used for stars by using a comma separated list of captions', 'wp-idea-stream');
    ?>
</label>
	<input name="_ideastream_hint_list" id="_ideastream_hint_list" type="text" class="large-text code" value="<?php 
    echo esc_attr($csv_hinlist);
    ?>
" />

	<?php 
}