예제 #1
0
/**
 * Displays the list of inserted images to let the user
 * choose the one he wishes to use as the Idea Featured image
 *
 * @since 2.3.0
 *
 * @return string HTML Output
 */
function wp_idea_stream_ideas_the_images_list()
{
    if (!wp_idea_stream_featured_images_allowed() || !current_theme_supports('post-thumbnails')) {
        return;
    }
    $selected = false;
    $content = '';
    $srcs = array();
    $wp_idea_stream = wp_idea_stream();
    $class = ' class="hidden"';
    // There was an error eg: missing title
    if (!empty($_POST['wp_idea_stream']['_the_content'])) {
        $content = wp_unslash($_POST['wp_idea_stream']['_the_content']);
        // Did the user selected a featured image ?
        if (!empty($_POST['wp_idea_stream']['_the_thumbnail'])) {
            $selected = (array) $_POST['wp_idea_stream']['_the_thumbnail'];
            $selected = reset($selected);
        }
        // Are we editing an idea ?
    } else {
        if (!empty($wp_idea_stream->query_loop->idea->post_content)) {
            $idea = $wp_idea_stream->query_loop->idea;
            $content = $idea->post_content;
            // Try to get the current featured image
            $selected = (int) get_post_thumbnail_id($idea);
            if (!empty($selected)) {
                $original_url = get_post_meta($selected, '_ideastream_original_src', true);
                if (empty($original_url)) {
                    $original_url = wp_get_attachment_url($selected);
                }
                $srcs = array($original_url => $selected);
            }
            /**
             * Get all idea attachments (those who have an _ideastream_original_url meta)
             *
             * We need to do this in case the featured image was edited and for some reason the
             * user deleted one or more images from the content
             */
            $srcs = array_replace($srcs, WP_Idea_Stream_Ideas_Thumbnail::get_idea_attachments($idea->ID));
        }
    }
    // Find image into the content
    if (!empty($content)) {
        $class = '';
        if (false !== stripos($content, 'src=')) {
            preg_match_all('#src=(["\'])([^"\']+)\\1#i', $content, $img_srcs);
            if (!empty($img_srcs[2])) {
                // Avoid duplicates
                $content_srcs = array_unique($img_srcs[2]);
                // Create a non numeric keys array
                $content_srcs = array_combine($content_srcs, $content_srcs);
                /**
                 * Make sure to use attachment ids if some were found earlier
                 */
                $srcs = array_replace($content_srcs, $srcs);
            }
        }
    }
    // Can be an attachment ID
    if (!empty($selected)) {
        if (is_numeric($selected)) {
            $selected = (int) $selected;
            // Or an url
        } else {
            $selected = esc_url($selected);
        }
    }
    ?>
	<div id="idea-images-list"<?php 
    echo $class;
    ?>
>
		<label><?php 
    esc_html_e('Select the featured image for your idea.', 'wp-idea-stream');
    ?>
</label>
		<?php 
    if (!empty($srcs)) {
        ?>
			<ul>
			<?php 
        foreach ($srcs as $ksrc => $src) {
            ?>
				<li>
					<img src="<?php 
            echo esc_url($ksrc);
            ?>
"/>

					<?php 
            if (is_numeric($src)) {
                $thumbnail = (int) $src;
            } else {
                $thumbnail = esc_url($src);
            }
            ?>

					<div class="cb-container">
						<input type="checkbox" name="wp_idea_stream[_the_thumbnail][<?php 
            echo esc_url_raw($ksrc);
            ?>
]" value="<?php 
            echo $thumbnail;
            ?>
" <?php 
            checked($selected, $thumbnail);
            ?>
/>
					</div>
				</li>
			<?php 
        }
        ?>
			</ul>
		<?php 
    }
    ?>
	</div>
	<?php 
}
예제 #2
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')));
}
예제 #3
0
        /**
         * Display the Featured image for the current idea
         *
         * @since  2.3.0
         *
         * @return string HTML Output
         */
        public function featured_image()
        {
            if (!wp_idea_stream_featured_images_allowed() || !current_theme_supports('post-thumbnails') || !bp_is_group() || !wp_idea_stream_is_single_idea()) {
                return;
            }
            $args = bp_parse_args(array(), array('size' => 'post-thumbnail', 'attr' => '', 'container_class' => 'post-thumbnail'), 'wp_idea_stream_featured_image');
            ?>
		<div class="<?php 
            echo sanitize_html_class($args['container_class']);
            ?>
">
			<?php 
            echo get_the_post_thumbnail(wp_idea_stream_ideas_get_id(), $args['size'], $args['attr']);
            ?>
		</div><!-- .post-thumbnail -->
		<?php 
        }
예제 #4
0
/**
 * Gets plugin's main post type init arguments
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream_get_post_type() to get the post type identifier and set the query var
 * @uses   wp_idea_stream_idea_slug() can be customized through plugin's settings
 * @uses   wp_idea_stream_root_slug() can be customized through plugin's settings
 * @uses   wp_idea_stream_user_can() to check if the user can access to admin bar menu
 * @uses   wp_idea_stream_get_category() to get the hierarchical taxonomy identifier of the post type
 * @uses   wp_idea_stream_get_tag() to get the non-hierarchical taxonomy identifier of the post type
 * @uses   wp_idea_stream_get_post_type_caps() to get the ideas post type capabilities
 * @uses   apply_filters() call 'wp_idea_stream_post_type_register_args' to customize post type init arguments
 * @return array the init arguments for the 'ideas' post type
 */
function wp_idea_stream_post_type_register_args()
{
    $supports = array('title', 'editor', 'author', 'comments', 'revisions');
    if (wp_idea_stream_featured_images_allowed()) {
        $supports[] = 'thumbnail';
    }
    return apply_filters('wp_idea_stream_post_type_register_args', array('public' => true, 'query_var' => wp_idea_stream_get_post_type(), 'rewrite' => array('slug' => wp_idea_stream_idea_slug(), 'with_front' => false), 'has_archive' => wp_idea_stream_root_slug(), 'exclude_from_search' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => wp_idea_stream_user_can('wp_idea_stream_ideas_admin'), 'menu_icon' => 'dashicons-lightbulb', 'supports' => $supports, 'taxonomies' => array(wp_idea_stream_get_category(), wp_idea_stream_get_tag()), 'capability_type' => array('idea', 'ideas'), 'capabilities' => wp_idea_stream_get_post_type_caps(), 'delete_with_user' => true, 'can_export' => true));
}
예제 #5
0
/**
 * WP Editor's Featured images callback
 *
 * @since 2.3.0
 *
 * @return string HTML output
 */
function wp_idea_stream_editor_featured_images_setting_callback()
{
    ?>

	<input name="_ideastream_featured_images" id="_ideastream_featured_images" type="checkbox" value="1" <?php 
    checked(wp_idea_stream_featured_images_allowed());
    ?>
 <?php 
    disabled(wp_idea_stream_idea_editor_image(), false);
    ?>
/>
	<label for="_ideastream_featured_images"><?php 
    esc_html_e('If users can add images, you can allow them to choose the featured image for their ideas', 'wp-idea-stream');
    ?>
</label>

	<?php 
}