Пример #1
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));
    }
}
Пример #2
0
/**
 * Should we display the comments form ?
 *
 * @package WP Idea Stream
 * @subpackage comments/functions
 *
 * @since 2.0.0
 *
 * @param  bool $open   true if comments are opened, false otherwise
 * @param  int $idea_id the ID of the idea
 * @uses   wp_idea_stream_is_ideastream() to make sure it's plugin's territory
 * @uses   wp_idea_stream_is_comments_allowed() to check if comments about ideas is globally allowed
 * @uses   apply_filters() call 'wp_idea_stream_comments_open' to override the value
 * @return bool          true if comments are opened, false otherwise
 */
function wp_idea_stream_comments_open($open = true, $idea_id = 0)
{
    if (!wp_idea_stream_is_ideastream()) {
        return $open;
    }
    if ($open != wp_idea_stream_is_comments_allowed()) {
        $open = false;
    }
    /**
     * Used internally in BuddyPress parts
     *
     * @param  bool $open true if comments are opened, false otherwise
     * @param  int $idea_id the ID of the idea
     */
    return apply_filters('wp_idea_stream_comments_open', $open, $idea_id);
}
/**
 * Filters edit post link to avoid its display when needed
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @param  string $edit_link the link to edit the post
 * @param  int    $post_id   the post ID
 * @uses   wp_idea_stream_is_ideastream() to make sure it's plugin's territory
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   apply_filters() call 'wp_idea_stream_edit_post_link' to override the false value applyed by the plugin
 * @return mixed false if needed, original edit link otherwise
 */
function wp_idea_stream_edit_post_link($edit_link = '', $post_id = 0)
{
    /**
     * using the capability check prevents edit link to display in case current user is the
     * author of the idea and don't have the minimal capability to open the idea in WordPress
     * Administration edit screen
     */
    if (wp_idea_stream_is_ideastream() && (0 === $post_id || !wp_idea_stream_user_can('edit_ideas'))) {
        /**
         * @param  bool false to be sure the edit link won't show
         * @param  string $edit_link
         * @param  int $post_id
         */
        return apply_filters('wp_idea_stream_edit_post_link', false, $edit_link, $post_id);
    }
    return $edit_link;
}
Пример #4
0
/**
 * Checks if an idea can be commented
 *
 * @package WP Idea Stream
 * @subpackage buddypress/functions
 *
 * @since  2.0.0
 *
 * @param  bool $open    true if comments opened, false otherwise
 * @param  int  $idea_id the idea ID
 * @uses   wp_idea_stream_is_ideastream() to check if it's the plugin's territory
 * @uses   is_buddypress() to check if it's BuddyPress territory
 * @uses   wp_idea_stream_is_comments_allowed() to get IdeaStream global setting
 * @uses   get_post_field() to get the idea comments opened setting
 * @uses   apply_filters() call 'wp_idea_stream_buddypress_comments_open' to override the comments opened setting
 * @return bool          the comments opened status for the idea
 */
function wp_idea_stream_buddypress_comments_open($open = true, $idea_id = 0)
{
    $retval = true;
    if (!wp_idea_stream_is_ideastream() || !is_buddypress()) {
        return $open;
    }
    // Comments can be disabled globally
    if (!wp_idea_stream_is_comments_allowed()) {
        $retval = false;
    }
    // We need to recheck as BuddyPress is forcing comment status to be closed
    // on its directory pages.
    if ('open' != get_post_field('comment_status', $idea_id)) {
        $retval = false;
    }
    /**
     * Used internally to check the group's comments opened setting
     *
     * @param  bool $retval  the comments opened setting
     * @param  int  $idea_id the ID of the idea
     */
    return apply_filters('wp_idea_stream_buddypress_comments_open', $retval, $idea_id);
}
Пример #5
0
/**
 * Default publishing status (publish/pending)
 *
 * If BuddyPress Groupes are enabled, this option is overriden
 * and only publish status is available
 *
 * @package WP Idea Stream
 * @subpackage core/options
 *
 * @since 2.0.0
 *
 * @param  string $default default value
 * @uses   get_option() to get customized value
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   apply_filters() call 'wp_idea_stream_default_idea_status' to override default or customized value
 * @return string       default value or customized one
 */
function wp_idea_stream_default_idea_status($default = 'publish')
{
    $default_status = get_option('_ideastream_submit_status', $default);
    // Make sure admins will have a publish status whatever the settings choice
    if (wp_idea_stream_is_ideastream() && wp_idea_stream_user_can('wp_idea_stream_ideas_admin')) {
        $default_status = 'publish';
    }
    /**
     * @param  string $default_status
     */
    return apply_filters('wp_idea_stream_default_idea_status', $default_status);
}
Пример #6
0
/**
 * 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;
}
 /**
  * Registers external javascript libraries to be linked later
  * using the wp_enqueue_script() function, & adds the plugin's stylesheet
  *
  * @package WP Idea Stream
  *
  * @since 2.0.0
  *
  * @uses  wp_idea_stream_is_ideastream() to check if it's plugin's territory
  * @uses  wp_register_script() to register the external library
  * @uses  wp_idea_stream_get_js_script() to get the javascript url
  * @uses  wp_idea_stream_enqueue_style() to add plugin's stylesheet to WordPress queue
  */
 public function enqueue_scripts()
 {
     if (!wp_idea_stream_is_ideastream()) {
         return;
     }
     // Register jquery Raty
     wp_register_script('jquery-raty', wp_idea_stream_get_js_script('jquery.raty'), array('jquery'), '2.7.0.imath', true);
     // Register tagging
     wp_register_script('tagging', wp_idea_stream_get_js_script('tagging'), array('jquery'), '1.3.1', true);
     wp_idea_stream_enqueue_style();
 }