コード例 #1
0
    /**
     * Display the upload post form
     *
     * @param array  $atts shortcode attributes
     * @param string $content content that is enclosed in [fu-upload-form][/fu-upload-form]
     */
    function upload_form($atts, $content = null)
    {
        static $inst = 0;
        add_shortcode('input', array($this, 'shortcode_content_parser'));
        add_shortcode('textarea', array($this, 'shortcode_content_parser'));
        add_shortcode('select', array($this, 'shortcode_content_parser'));
        add_shortcode('checkboxes', array($this, 'shortcode_content_parser'));
        add_shortcode('radio', array($this, 'shortcode_content_parser'));
        add_shortcode('recaptcha', 'fu_get_recaptcha_markup');
        // Reset postdata in case it got polluted somewhere
        wp_reset_postdata();
        $form_post_id = get_the_id();
        extract(shortcode_atts(array('description' => '', 'title' => __('Submit a new post', 'frontend-uploader'), 'type' => '', 'class' => 'validate', 'success_page' => '', 'form_layout' => 'image', 'post_id' => get_the_ID(), 'post_type' => 'post', 'category' => '', 'suppress_default_fields' => false, 'append_to_post' => false), $atts));
        $post_id = (int) $post_id;
        $this->enqueue_scripts();
        $form_layout = in_array($form_layout, array('post', 'image', 'media', 'post_image', 'post_media')) ? $form_layout : 'media';
        ob_start();
        ?>
	<form action="<?php 
        echo admin_url('admin-ajax.php');
        ?>
" method="post" id="ugc-media-form-<?php 
        echo $inst++;
        ?>
" class="<?php 
        echo esc_attr($class);
        ?>
 fu-upload-form" enctype="multipart/form-data">
	 <div class="ugc-inner-wrapper">
		 <h2><?php 
        echo esc_html($title);
        ?>
</h2>
<?php 
        if (!empty($_GET)) {
            $this->_display_response_notices($_GET);
        }
        $textarea_desc = __('Description', 'frontend-uploader');
        $file_desc = __('Your Media Files', 'frontend-uploader');
        $submit_button = __('Submit', 'frontend-uploader');
        // Set post type for layouts that include uploading of posts
        // Put it in front of the main form to allow to override it
        if (in_array($form_layout, array("post_media", "post_image", "post"))) {
            echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'post_type', 'value' => $post_type), null, 'input');
        }
        echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'post_ID', 'value' => $post_id), null, 'input');
        if (isset($category) && 0 !== (int) $category) {
            echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'post_category', 'value' => $category), null, 'input');
        }
        if (!(isset($this->settings['suppress_default_fields']) && 'on' == $this->settings['suppress_default_fields']) && $suppress_default_fields === false) {
            // Display title field
            echo $this->shortcode_content_parser(array('type' => 'text', 'role' => 'title', 'name' => 'post_title', 'id' => 'ug_post_title', 'class' => 'required', 'description' => __('Title', 'frontend-uploader')), null, 'input');
            /**
             * Render default fields
             * Looks gross but somewhat faster than using do_shortcode
             */
            switch ($form_layout) {
                case 'post_image':
                case 'post_media':
                case 'image':
                case 'media':
                    // post_content
                    echo $this->shortcode_content_parser(array('role' => 'content', 'name' => 'post_content', 'id' => 'ug_content', 'class' => 'required', 'description' => __('Post content or file description', 'frontend-uploader')), null, 'textarea');
                    break;
                case 'post':
                    // post_content
                    echo $this->shortcode_content_parser(array('role' => 'content', 'name' => 'post_content', 'id' => 'ug_content', 'class' => 'required', 'description' => __('Post content', 'frontend-uploader')), null, 'textarea');
                    break;
            }
        }
        // Parse nested shortcodes
        if ($content) {
            echo do_shortcode($content);
        }
        if (!(isset($this->settings['suppress_default_fields']) && 'on' == $this->settings['suppress_default_fields']) && $suppress_default_fields === false) {
            if (in_array($form_layout, array('image', 'media', 'post_image', 'post_media'))) {
                // Default upload field
                echo $this->shortcode_content_parser(array('type' => 'file', 'role' => 'file', 'name' => 'files', 'id' => 'ug_photo', 'multiple' => 'multiple', 'description' => $file_desc, 'help' => ''), null, 'input');
            }
            if ($this->settings['enable_recaptcha_protection'] == 'on') {
                echo fu_get_recaptcha_markup();
            }
            do_action('fu_additional_html', $this);
            echo $this->shortcode_content_parser(array('type' => 'submit', 'role' => 'internal', 'id' => 'ug_submit_button', 'class' => 'btn', 'value' => $submit_button), null, 'input');
        } else {
            do_action('fu_additional_html', $this);
        }
        // wp_ajax_ hook
        echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'action', 'value' => 'upload_ugc'), null, 'input');
        // Redirect to specified url if valid
        if (!empty($success_page) && filter_var($success_page, FILTER_VALIDATE_URL)) {
            echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'success_page', 'value' => $success_page), null, 'input');
        }
        // One of supported form layouts
        echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'form_layout', 'value' => $form_layout), null, 'input');
        if (in_array($form_layout, array('post_media', 'post_image'))) {
            // One of supported form layouts
            echo $this->shortcode_content_parser(array('type' => 'hidden', 'role' => 'internal', 'name' => 'append_to_post', 'value' => (bool) $append_to_post), null, 'input');
        }
        ?>
		<?php 
        wp_nonce_field(FU_NONCE, 'fu_nonce');
        ?>
		<input type="hidden" name="ff" value="<?php 
        echo esc_attr($this->_get_fields_hash());
        ?>
" />
		<input type="hidden" name="form_post_id" value="<?php 
        echo (int) $form_post_id;
        ?>
" />
		<div class="clear"></div>
	 </div>
	 </form>
<?php 
        $this->maybe_update_fields_map($form_post_id);
        return ob_get_clean();
    }
コード例 #2
0
function fu_recaptcha_additional_html()
{
    echo fu_get_recaptcha_markup();
}