Beispiel #1
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);
}
/**
 * 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;
}
/**
 * Handles posting ideas
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @uses   check_admin_referer() to check the request has been done from current site
 * @uses   wp_idea_stream_get_redirect_url() to get default redirect url
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   wp_idea_stream_add_message() to add a feddback message to user
 * @uses   wp_safe_redirect() to safely redirect the user and avoid duplicates
 * @uses   wp_idea_stream_ideas_save_idea() to save the idea
 * @uses   wp_idea_stream_get_form_url() to get the add new form url
 * @uses   get_post() to get the idea object
 * @uses   wp_idea_stream_moderation_message() to check for a custom moderation message
 * @uses   wp_idea_stream_ideas_get_idea_permalink() to get the idea link
 */
function wp_idea_stream_ideas_post_idea()
{
    // Bail if not a post request
    if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if not a post idea request
    if (empty($_POST['wp_idea_stream']) || !is_array($_POST['wp_idea_stream'])) {
        return;
    }
    // Bail if it's an update
    if (!empty($_POST['wp_idea_stream']['_the_id'])) {
        return;
    }
    // Check nonce
    check_admin_referer('wp_idea_stream_save');
    $redirect = wp_idea_stream_get_redirect_url();
    // Check capacity
    if (!wp_idea_stream_user_can('publish_ideas')) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to publish ideas', 'wp-idea-stream')));
        // Redirect to main archive page
        wp_safe_redirect($redirect);
        exit;
    }
    $posted = array_diff_key($_POST['wp_idea_stream'], array('save' => 'submit'));
    // Title & content are required
    if (empty($posted['_the_title']) || empty($posted['_the_content'])) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Title and description are required fields.', 'wp-idea-stream')));
        // Simply stop, so that the user keeps the posted values.
        return;
    }
    $id = wp_idea_stream_ideas_save_idea($posted);
    if (empty($id)) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Something went wrong while trying to save your idea.', 'wp-idea-stream')));
        // Redirect to an empty form
        wp_safe_redirect(wp_idea_stream_get_form_url());
        exit;
    } else {
        $idea = get_post($id);
        $feedback_message = array();
        if (!empty($posted['_the_thumbnail'])) {
            $thumbnail = reset($posted['_the_thumbnail']);
            $sideload = WP_Idea_Stream_Ideas_Thumbnail::start($thumbnail, $id);
            if (is_wp_error($sideload->result)) {
                $feedback_message[] = __('There was a problem saving the featured image, sorry.', 'wp-idea-stream');
            }
        }
        if ('pending' == $idea->post_status) {
            // Build pending message.
            $feedback_message['pending'] = __('Your idea is currently awaiting moderation.', 'wp-idea-stream');
            // Check for a custom pending message
            $custom_pending_message = wp_idea_stream_moderation_message();
            if (!empty($custom_pending_message)) {
                $feedback_message['pending'] = $custom_pending_message;
            }
            // redirect to the idea
        } else {
            $redirect = wp_idea_stream_ideas_get_idea_permalink($idea);
        }
        if (!empty($feedback_message)) {
            // Add feedback to the user
            wp_idea_stream_add_message(array('type' => 'info', 'content' => join(' ', $feedback_message)));
        }
        wp_safe_redirect($redirect);
        exit;
    }
}
/**
 * Redirect to the Welcome Screen after activation
 *
 * @package WP Idea Stream
 * @subpackage core/upgrade
 *
 * @since 2.0.0
 *
 * @uses  get_transient() to check if a redirect is needed
 * @uses  delete_transient() to remove this redirect info
 * @uses  is_network_admin() to avoid playing in the network admin
 * @uses  wp_idea_stream_user_can() to check user's capability
 * @uses  wp_safe_redirect() to redirect the user to the Welcome Screen
 * @uses  add_query_arg() to build the url to the about page
 * @uses  admin_url() to get admin url
 */
function wp_idea_stream_activation_redirect()
{
    $redirect = get_transient('_ideastream_activation_redirect');
    // Bail if no activation redirect
    if (empty($redirect)) {
        return;
    }
    // Delete the redirect transient
    delete_transient('_ideastream_activation_redirect');
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Bail if the current user cannot see the about page
    if (!wp_idea_stream_user_can('manage_options')) {
        return;
    }
    // Redirect to bbPress about page
    wp_safe_redirect(add_query_arg(array('page' => 'about-ideastream'), admin_url('index.php')));
}
Beispiel #5
0
 /**
  * Checks if a rate is to be deleted
  *
  * @package WP Idea Stream
  * @subpackage admin/admin
  *
  * @since 2.0.0
  *
  * @uses   wp_idea_stream_is_admin() to check if on an IdeaStream Administration screen
  * @uses   wp_idea_stream_user_can() to check for user's capabilities
  * @uses   check_admin_referer() to check the request was made on the site
  * @uses   wp_idea_stream_delete_rate() to delete a rate
  * @uses   add_query_arg() to add query vars to an url
  * @uses   get_edit_post_link() to get the idea edit link
  * @uses   wp_safe_redirect() to safely redirect the user
  */
 public function maybe_delete_rate()
 {
     if (!wp_idea_stream_is_admin()) {
         return;
     }
     if (!wp_idea_stream_user_can('edit_ideas')) {
         return;
     }
     if (empty($_GET['remove_vote']) || empty($_GET['post']) || empty($_GET['action'])) {
         return;
     }
     $idea_id = absint($_GET['post']);
     $user_id = absint($_GET['remove_vote']);
     // nonce check
     check_admin_referer('idea_remove_vote_' . $user_id);
     if (false !== wp_idea_stream_delete_rate($idea_id, $user_id)) {
         $message = 11;
     } else {
         $message = 12;
     }
     // Utimate and not necessary check...
     if (!empty($_GET['remove_vote'])) {
         $redirect = add_query_arg('message', $message, get_edit_post_link($idea_id, 'url'));
         wp_safe_redirect($redirect);
         exit;
     }
 }
Beispiel #6
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);
}
 *
 * @package Front End Attachments
 * @subpackage inc/templates
 */
?>
<div id="wp-idea-stream">
	<?php 
do_action('wp_idea_stream_ideas_before_form');
?>

	<?php 
wp_idea_stream_user_feedback();
?>

	<?php 
if (wp_idea_stream_user_can('publish_ideas')) {
    ?>

		<form class="standard-form" id="wp-idea-stream-form" action="" method="post">

			<?php 
    wp_idea_stream_ideas_the_title_edit();
    ?>

			<?php 
    front_end_attachments_editor_ideas_the_editor();
    ?>

			<?php 
    wp_idea_stream_ideas_the_images_list();
    ?>
/**
 * Adds a shortcut to Idea Stream Backend using the appearence menus
 *
 * While developing the plugin i've found it usefull to be able to easily access
 * to IdeaStream backend from front end, so i've left it. You can disable it by using
 * the filer.
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @param  WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance
 * @uses   apply_filters() call 'wp_idea_stream_adminbar_menu' to disable the menu by returning false
 * @uses   wp_idea_stream_user_can() to check for user's capability
 * @uses   add_query_arg()
 * @uses   wp_idea_stream_get_post_type()
 * @uses   admin_url()
 */
function wp_idea_stream_adminbar_menu($wp_admin_bar = null)
{
    $use_admin_bar = apply_filters('wp_idea_stream_adminbar_menu', true);
    if (empty($use_admin_bar)) {
        return;
    }
    if (!empty($wp_admin_bar) && wp_idea_stream_user_can('edit_ideas')) {
        $menu_url = add_query_arg('post_type', wp_idea_stream_get_post_type(), admin_url('edit.php'));
        $wp_admin_bar->add_menu(array('parent' => 'appearance', 'id' => 'ideastream', 'title' => _x('IdeaStream', 'Admin bar menu', 'wp-idea-stream'), 'href' => $menu_url));
    }
}
Beispiel #9
0
/**
 * Return the excerpt of the comment currently being iterated on.
 *
 * @package WP Idea Stream
 * @subpackage comments/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   get_post() to get the idea the comment is linked to
 * @uses   get_comment_excerpt() to get the comment excerpt
 * @uses   apply_filters() call 'wp_idea_stream_comments_get_comment_excerpt' to override the output
 * @return string the excerpt.
 */
function wp_idea_stream_comments_get_comment_excerpt()
{
    $comment = wp_idea_stream()->comment_query_loop->comment;
    $title = '';
    $idea = $comment->comment_post_ID;
    if (!empty($comment->idea)) {
        $idea = $comment->idea;
    }
    $idea = get_post($idea);
    if (post_password_required($idea)) {
        $excerpt = __('The idea, the comment was posted on, is password protected, you will need it to view its content.', 'wp-idea-stream');
        // Private
    } else {
        if (!empty($idea->post_status) && 'private' == $idea->post_status && !wp_idea_stream_user_can('read_idea', $idea->ID)) {
            $excerpt = __('The idea, the comment was posted on is private, you cannot view its content.', 'wp-idea-stream');
            // Public
        } else {
            $excerpt = get_comment_excerpt(wp_idea_stream()->comment_query_loop->comment->comment_ID);
        }
    }
    /**
     * @param  string   $excerpt the comment excerpt
     */
    return apply_filters('wp_idea_stream_comments_get_comment_excerpt', $excerpt);
}
Beispiel #10
0
 /**
  * Validate and sanitize the parameters for the suggestion service query.
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @uses   sanitize_key() to sanitize the meta key
  * @uses   sanitize_text_field() to sanitize the meta value
  * @uses   wp_idea_stream_user_can() to check for user's capability
  * @uses   is_user_logged_in() to be extra sure the user is logged in
  * @uses   apply_filters() Calls 'wp_idea_stream_groups_suggestions_args' to do extra sanitization
  *                         Calls 'wp_idea_stream_groups_suggestions_validate_args' to override the validation result
  * @return true|WP_Error If validation fails, return a WP_Error object. On success, return true (bool).
  */
 public function validate()
 {
     $this->args['show_hidden'] = (bool) $this->args['show_hidden'];
     $this->args['meta_key'] = sanitize_key($this->args['meta_key']);
     $this->args['meta_value'] = sanitize_text_field($this->args['meta_value']);
     $this->args['author'] = absint($this->args['author']);
     /**
      * @param array $this->args the arguments to do extra sanitization
      * @param WP_Idea_Stream_Groups_Suggestions $this the current class
      */
     $this->args = apply_filters('wp_idea_stream_groups_suggestions_args', $this->args, $this);
     // Check for invalid or missing parameters.
     if ($this->args['show_hidden'] && (!wp_idea_stream_user_can('edit_ideas') || !is_user_logged_in())) {
         return new WP_Error('missing_requirement');
     }
     /**
      * @param bool    true if success, false otherwise
      * @param WP_Idea_Stream_Groups_Suggestions $this the current class
      */
     return apply_filters('wp_idea_stream_groups_suggestions_validate_args', parent::validate(), $this);
 }