Пример #1
0
/**
 * Displays the form submit/reset buttons
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's instance
 * @uses   wp_nonce_field() to add a security token to check upon once submitted
 * @uses   do_action() call 'wp_idea_stream_ideas_the_form_submit' to add custom actions before buttons
 * @uses   wp_idea_stream_is_addnew() to check if using the add new form
 * @uses   wp_idea_stream_is_edit() to check if using the edit form
 * @return string output for submit/reset buttons
 */
function wp_idea_stream_ideas_the_form_submit()
{
    $wp_idea_stream = wp_idea_stream();
    wp_nonce_field('wp_idea_stream_save');
    do_action('wp_idea_stream_ideas_the_form_submit');
    ?>

	<?php 
    if (wp_idea_stream_is_addnew()) {
        ?>

		<input type="reset" value="<?php 
        esc_attr_e('Reset', 'wp-idea-stream');
        ?>
"/>
		<input type="submit" value="<?php 
        esc_attr_e('Submit', 'wp-idea-stream');
        ?>
" name="wp_idea_stream[save]"/>

	<?php 
    } elseif (wp_idea_stream_is_edit() && !empty($wp_idea_stream->query_loop->idea->ID)) {
        ?>

		<input type="hidden" value="<?php 
        echo esc_attr($wp_idea_stream->query_loop->idea->ID);
        ?>
" name="wp_idea_stream[_the_id]"/>
		<input type="submit" value="<?php 
        esc_attr_e('Update', 'wp-idea-stream');
        ?>
" name="wp_idea_stream[save]"/>

	<?php 
    }
    ?>

	<?php 
}
/**
 * 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;
}
/**
 * Filters the <title> content
 *
 * Inspired by bbPress's bbp_title()
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @param array $title the title parts
 * @uses  wp_idea_stream_is_ideastream() to make sure it's plugin's territory
 * @uses  wp_idea_stream_is_addnew() to check the submit form is displayed
 * @uses  wp_idea_stream_is_user_profile() to check if a user's profile is displayed
 * @uses  wp_idea_stream_users_get_displayed_user_displayname() to get the display name of the user being viewed
 * @uses  wp_idea_stream_is_single_idea() to check whether page is displaying the single idea template
 * @uses  is_tax() to check if a taxonomy is in queried objects
 * @uses  wp_idea_stream_get_current_term() to get the current term
 * @uses  get_taxonomy() to get the taxonomy
 * @uses  wp_idea_stream_set_idea_var() to globalize the current term
 * @uses  wp_idea_stream_is_signup() to check if on the signup page
 * @uses  apply_filters() call 'wp_idea_stream_title' to override the title meta tag of the page
 * @return string the page title meta tag
 */
function wp_idea_stream_title($title_array = array())
{
    if (!wp_idea_stream_is_ideastream()) {
        return $title_array;
    }
    $new_title = array();
    if (wp_idea_stream_is_addnew()) {
        $new_title[] = esc_attr__('New idea', 'wp-idea-stream');
    } elseif (wp_idea_stream_is_edit()) {
        $new_title[] = esc_attr__('Edit idea', 'wp-idea-stream');
    } elseif (wp_idea_stream_is_user_profile()) {
        $new_title[] = sprintf(esc_html__('%s&#39;s profile', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname());
    } elseif (wp_idea_stream_is_single_idea()) {
        $new_title[] = single_post_title('', false);
    } elseif (is_tax()) {
        $term = wp_idea_stream_get_current_term();
        if ($term) {
            $tax = get_taxonomy($term->taxonomy);
            // Catch the term for later use
            wp_idea_stream_set_idea_var('current_term', $term);
            $new_title[] = single_term_title('', false);
            $new_title[] = $tax->labels->name;
        }
    } elseif (wp_idea_stream_is_signup()) {
        $new_title[] = esc_html__('Create an account', 'wp-idea-stream');
    } else {
        $new_title[] = esc_html__('Ideas', 'wp-idea-stream');
    }
    // Compare new title with original title
    if (empty($new_title)) {
        return $title_array;
    }
    $title_array = array_diff($title_array, $new_title);
    $new_title_array = array_merge($title_array, $new_title);
    /**
     * @param  string $new_title the filtered title
     * @param  string $sep
     * @param  string $seplocation
     * @param  string $title the original title meta tag
     */
    return apply_filters('wp_idea_stream_title', $new_title_array, $title_array, $new_title);
}
Пример #4
0
/**
 * Simulate a tinymce plugin to intercept images once added to the
 * WP Editor
 *
 * @since 2.3.0
 *
 * @param  array $tinymce_plugins Just what the name of the param says!
 * @return array Tiny MCE plugins + IdeaStream one if needed
 */
function wp_idea_stream_ideas_tiny_mce_plugins($tinymce_plugins = array())
{
    if (!wp_idea_stream_featured_images_allowed() || !current_theme_supports('post-thumbnails')) {
        return $tinymce_plugins;
    }
    if (!wp_idea_stream_is_addnew() && !wp_idea_stream_is_edit()) {
        return $tinymce_plugins;
    }
    return array_merge($tinymce_plugins, array('wpIdeaStreamListImages' => wp_idea_stream_get_js_script('featured-images')));
}
        /**
         * Register scripts
         */
        public function register_scripts()
        {
            // Register the script
            wp_register_script('fe-attachments-script', $this->js_url . 'script.js', array(), $this->version, true);
            wp_register_style('fe-attachments-style', $this->css_url . 'style.css', array('dashicons'), $this->version);
            if (function_exists('wp_idea_stream_is_addnew') && wp_idea_stream_is_addnew()) {
                wp_add_inline_style('wp-idea-stream-style', '
				#wp-wp_idea_stream_the_content-wrap {
					border: none;
				}
				#wp-wp_idea_stream_the_content-editor-container {
					border: 1px solid #ccc;
				}

				#wp-wp_idea_stream_the_content-media-buttons {
					padding: 10px 0;
				}

				#wp-wp_idea_stream_the_content-media-buttons #insert-media-button {
					padding: 0 10px 1px;
					border-radius: 0;
				}
			');
            }
        }