Example #1
0
/**
 * Gets a message in case no idea was found
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_is_user_profile() to check if on a user's profile
 * @uses   wp_idea_stream_is_user_profile_rates() to check if the rates part of a user's profile
 * @uses   wp_idea_stream_users_get_displayed_user_displayname() to get the displayed user's display name
 * @uses   wp_idea_stream_is_category() to check if a category is displayed
 * @uses   wp_idea_stream_is_tag() to check if a tag is displayed
 * @uses   wp_idea_stream_is_search() to check if a search is being performed
 * @uses   wp_idea_stream_is_orderby() to check if a specific order is being requested
 * @uses   wp_idea_stream_user_can() to check for user's capability
 * @uses   wp_idea_stream_get_form_url() to get the form url to add new ideas
 * @uses   apply_filters() call 'wp_idea_stream_ideas_get_not_found' to override the output
 * @return string the message to output
 */
function wp_idea_stream_ideas_get_not_found()
{
    // general feedback
    $output = esc_html__('It looks like no idea has been submitted yet, please sign in or sign up to add yours!', 'wp-idea-stream');
    if (wp_idea_stream_is_user_profile()) {
        if (!wp_idea_stream_is_user_profile_rates()) {
            $output = sprintf(__('It looks like %s has not submitted any idea yet', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname());
            // We're viewing the idea the user rated
        } else {
            $output = sprintf(__('It looks like %s has not rated any idea yet', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname());
        }
    } else {
        if (wp_idea_stream_is_category()) {
            $output = __('It looks like no idea has been published in this category yet', 'wp-idea-stream');
        } else {
            if (wp_idea_stream_is_tag()) {
                $output = __('It looks like no idea has been marked with this tag yet', 'wp-idea-stream');
            } else {
                if (wp_idea_stream_is_search()) {
                    $output = __('It looks like no idea match your search terms.', 'wp-idea-stream');
                } else {
                    if (wp_idea_stream_is_search()) {
                        $output = __('It looks like no idea match your search terms.', 'wp-idea-stream');
                    } else {
                        if (wp_idea_stream_is_orderby('rates_count')) {
                            $output = __('It looks like no idea has been rated yet.', 'wp-idea-stream');
                        } else {
                            if (wp_idea_stream_user_can('publish_ideas')) {
                                $output = sprintf(__('It looks like no idea has been submitted yet, <a href="%s" title="Submit your idea">add yours</a>', 'wp-idea-stream'), esc_url(wp_idea_stream_get_form_url()));
                            }
                        }
                    }
                }
            }
        }
    }
    /**
     * @param  string $output the message to output
     */
    return apply_filters('wp_idea_stream_ideas_get_not_found', $output);
}
/**
 * Order the ideas by rates when requested
 *
 * This function is hooking to WordPress 'posts_clauses' filter. As the
 * rating query is first built by using a specific WP_Meta_Query, we need
 * to also make sure the ORDER BY clause of the sql query is customized.
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @param  array    $clauses  the idea query sql parts
 * @param  WP_Query $wp_query the WordPress query object
 * @uses   wp_idea_stream_is_ideastream() to check it's front end plugin's territory
 * @uses   wp_idea_stream_is_admin() to check it's back end plugin's territory
 * @uses   wp_idea_stream_is_orderby() to check the rates count is the requested order
 * @return array              new order clauses if needed
 */
function wp_idea_stream_set_rates_count_orderby($clauses = array(), $wp_query = null)
{
    if ((wp_idea_stream_is_ideastream() || wp_idea_stream_is_admin() || wp_idea_stream_get_idea_var('rating_widget')) && wp_idea_stream_is_orderby('rates_count')) {
        preg_match('/\\(?(\\S*).meta_key = \'_ideastream_average_rate\'/', $clauses['where'], $matches);
        if (!empty($matches[1])) {
            // default order
            $order = 'DESC';
            // Specific case for IdeaStream administration.
            if (!empty($clauses['orderby']) && 'ASC' == strtoupper(substr($clauses['orderby'], -3))) {
                $order = 'ASC';
            }
            $clauses['orderby'] = "{$matches[1]}.meta_value + 0 {$order}";
        }
    }
    return $clauses;
}