Plugin Directory

Changeset 1688580


Ignore:
Timestamp:
07/01/2017 12:18:35 AM (8 years ago)
Author:
rinatkhaziev
Message:

Merge 1.2 from github

Location:
frontend-uploader/trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • frontend-uploader/trunk/frontend-uploader.php

    r1468826 r1688580  
    44Description: Allow your visitors to upload content and moderate it.
    55Author: Rinat Khaziev, Daniel Bachhuber
    6 Version: 1.1
     6Version: 1.2
    77Author URI: http://digitallyconscious.com
    88
     
    2626
    2727// Define consts and bootstrap and dependencies
    28 define( 'FU_VERSION', '1.1' );
     28define( 'FU_VERSION', '1.2' );
    2929define( 'FU_ROOT' , dirname( __FILE__ ) );
    3030define( 'FU_FILE_PATH' , FU_ROOT . '/' . basename( __FILE__ ) );
     
    4444    public $settings_slug = 'frontend_uploader_settings';
    4545    public $is_debug = false;
     46    public $lang = 'en_US';
     47    public $lang_short = 'en';
    4648    /**
    4749     * Should consist of fields to be proccessed automatically on content submission
     
    110112        add_filter( 'posts_where', array( $this, 'filter_posts_where' ) );
    111113
    112 
    113114        $this->allowed_mime_types = $this->_get_mime_types();
    114115        // Configuration filter to change manage permissions
     
    119120        add_action( 'fu_after_upload', array( $this, '_maybe_insert_images_into_post' ), 10, 3 );
    120121
     122        $this->_set_language();
     123
    121124        // Maybe enable Akismet protection
    122125        $this->_enable_akismet_protection();
     
    126129    }
    127130
    128     /**
    129      * Slightly convoluted workaround to allow modifying of allowed MIME types for WP < 3.5,
    130      * Workaround for IE sometimes setting image/pjepg and image/x-png for JPEGs and PNGs respectively
     131
     132    /**
     133     * Set current language (used for captcha and jquery validate l18n )
     134     */
     135    function _set_language() {
     136        // Filter is needed for wordpress.com
     137        $this->lang = apply_filters( 'fu_wplang', get_bloginfo( 'language' ) );
     138        $this->lang_short = substr( $this->lang, 0, 2 );
     139    }
     140
     141
     142    /**
     143     * Add extra mime-types
     144     *
     145     * This is mostly legacy, and really should be deprecated or refactored due to unneccessary complexity
     146     *
     147     * @return [type] [description]
    131148     */
    132149    function _get_mime_types() {
    133         // Use wp_get_mime_types if available, fallback to get_allowed_mime_types()
    134         $mime_types = function_exists( 'wp_get_mime_types' ) ? wp_get_mime_types() : get_allowed_mime_types() ;
     150        $mime_types = wp_get_mime_types();
    135151        $fu_mime_types = fu_get_mime_types();
    136         // Workaround for IE
    137         $mime_types['jpg|jpe|jpeg|pjpg'] = 'image/pjpeg';
    138         $mime_types['png|xpng'] = 'image/x-png';
     152
    139153        $enabled = isset( $this->settings['enabled_files'] ) && is_array( $this->settings['enabled_files'] ) ?  $this->settings['enabled_files'] : array();
    140         // Iterate through default extensions
     154
     155        // $fu_mime_types holds extra mimes that are not allowed by WP
    141156        foreach ( $fu_mime_types as $extension => $details ) {
    142157            // Skip if it's not in the settings
     
    144159                continue;
    145160
    146             // Iterate through mime-types for this extension
     161            // Files have multiple mimes sometimes, we need to cover all of them
    147162            foreach ( $details['mimes'] as $ext_mime ) {
    148163                $mime_types[ $extension . '|' . $extension . sanitize_title_with_dashes( $ext_mime ) ] = $ext_mime;
     
    158173                unset( $mime_types[$ext_key] );
    159174        }
     175
    160176        return $mime_types;
    161177    }
     
    191207    }
    192208
    193 
    194209    /**
    195210     * Since 4.01 shortcode contents is texturized by default,
     
    244259        add_filter( 'upload_mimes', array( $this, '_get_mime_types' ), 999 );
    245260
    246 
    247261        $media_ids = $errors = array();
    248262        // Bail if there are no files
    249263        if ( empty( $_FILES ) )
    250             return false;
     264            return array();
    251265
    252266        // File field name could be user defined, so we just get the first file
     
    263277            $k['name'] = sanitize_file_name( $k['name'] );
    264278
     279            //
     280            if ( $k['error'] === 4 ) {
     281                continue;
     282            }
     283
    265284            // Skip to the next file if upload went wrong
    266             if ( $k['tmp_name'] == "" ) {
     285            if ( $k['error'] !== 0  ) {
     286                $errors['fu-error-media'][] = array( 'name' => $k['name'], 'code' => $k['error'] );
    267287                continue;
    268288            }
     
    291311            elseif ( isset( $_POST['post_content'] ) )
    292312                $caption = sanitize_text_field( $_POST['post_content'] );
    293             // TODO: remove or refactor
    294             $filename = !empty( $this->settings['default_file_name'] ) ? $this->settings['default_file_name'] : pathinfo( $k['name'], PATHINFO_FILENAME );
     313
     314            $filename = pathinfo( $k['name'], PATHINFO_FILENAME );
    295315            $post_overrides = array(
    296316                'post_status' => $this->_is_public() ? 'publish' : 'private',
     
    300320            );
    301321
    302             // Obfuscate filename, just in case
    303322            $m = $k;
    304             $fn = explode( '.', $k['name'] );
    305             $k['name'] = uniqid() . '.' . end( $fn );
     323
     324            // Obfuscate filename if setting is present
     325            if (  isset( $this->settings['obfuscate_file_name'] ) && 'on' == $this->settings['obfuscate_file_name']  ){
     326                $fn = explode( '.', $k['name'] );
     327                $m['name'] = uniqid( mt_rand( 1, 1000 ) , true ) . '.' . end( $fn );
     328            }
    306329
    307330            // Trying to upload the file
    308             $upload_id = media_handle_sideload( $k, (int) $post_id, $post_overrides['post_title'], $post_overrides );
    309             $m = $k;
     331            $upload_id = media_handle_sideload( $m, (int) $post_id, $post_overrides['post_title'], $post_overrides );
    310332
    311333            if ( !is_wp_error( $upload_id ) )
     
    432454
    433455        $post_id = wp_insert_post( $post_array, true );
     456
     457
     458
    434459        // Something went wrong
    435460        if ( is_wp_error( $post_id ) ) {
    436             $errors[] = 'fu-error-post';
     461            $errors = array( 'fu-error-post' => 1 );
    437462            $success = false;
    438463        } else {
     
    485510        // Bail if something fishy is going on
    486511        if ( !wp_verify_nonce( $_POST['fu_nonce'], FU_NONCE ) ) {
    487             wp_safe_redirect( add_query_arg( array( 'response' => 'fu-error', 'errors' => 'fu-nonce-failure' ), wp_get_referer() ) );
     512            wp_safe_redirect( add_query_arg( array( 'response' => 'fu-error', 'errors' =>  array( 'fu-nonce-failure' => 1 ) ), wp_get_referer() ) );
     513            exit;
     514        }
     515
     516        // Bail if supplied post type is not allowed
     517        if ( isset( $_POST['post_type'] ) && ! $this->is_allowed_post_type( sanitize_key( $_POST['post_type'] ) ) ) {
     518            wp_safe_redirect( add_query_arg( array( 'response' => 'fu-error', 'errors' => array( 'fu-disallowed-post-type' => sanitize_key( $_POST['post_type'] ) ) ), wp_get_referer() ) );
    488519            exit;
    489520        }
     
    517548        case 'post_media';
    518549            $result = $this->_upload_post();
     550
     551
    519552            if ( ! is_wp_error( $result['post_id'] ) ) {
    520553                $media_result = $this->_upload_files( $result['post_id'] );
    521 
    522554                // Make sure we don't merge a non-array (_upload_files might return null, false or WP_Error)
    523                 if ( $media_result && is_array( $media_result ) )
     555                if ( is_array( $media_result ) )
    524556                    $result = array_merge( $result, $media_result );
    525557            }
     
    557589            return;
    558590
     591
    559592        // TODO: It'd be nice to add the list of upload files
    560593        $to = !empty( $this->settings['notification_email'] ) && filter_var( $this->settings['notification_email'], FILTER_VALIDATE_EMAIL ) ? $this->settings['notification_email'] : get_option( 'admin_email' );
    561594        $subj = __( 'New content was uploaded on your site', 'frontend-uploader' );
    562         wp_mail( $to, $subj, $this->settings['admin_notification_text'] );
    563     }
     595
     596        add_filter( 'wp_mail_content_type', 'fu_email_content_type' );
     597
     598        wp_mail( $to, $subj, $this->_get_html_email_template( $result ) );
     599
     600        remove_filter( 'wp_mail_content_type', 'fu_email_content_type' );
     601    }
     602
     603    /**
     604     * Get html template
     605     *
     606     * @since 1.2
     607     *
     608     * @param  array  $result [description]
     609     * @return [type]         [description]
     610     */
     611    function _get_html_email_template( $result = array() ) {
     612        global $fu_result;
     613        $fu_result = $result;
     614        ob_start();
     615        include_once FU_ROOT . "/lib/views/html-email.tpl.php";
     616        return ob_get_clean();
     617    }
     618
    564619
    565620    /**
     
    706761     * Approve a media file
    707762     *
    708      * TODO: refactor in 0.6
    709      *
    710763     * @return [type] [description]
    711764     */
     
    714767        if ( false === $this->_check_perms_and_nonce() || 0 === (int) $_GET['id'] ) {
    715768            wp_safe_redirect( get_admin_url( null, 'upload.php?page=manage_frontend_uploader&error=id_or_perm' ) );
     769            exit;
    716770        }
    717771
     
    724778            do_action( 'fu_media_approved', $post );
    725779
    726             $this->update_35_gallery_shortcode( $post->post_parent, $post->ID );
     780            $this->update_gallery_shortcode( $post->post_parent, $post->ID );
    727781            wp_safe_redirect( get_admin_url( null, 'upload.php?page=manage_frontend_uploader&approved=1' ) );
     782            exit;
    728783        }
    729784
     
    740795        // check for permissions and id
    741796        $url = get_admin_url( null, 'edit.php?page=manage_frontend_uploader_posts&error=id_or_perm' );
    742         if ( !current_user_can( $this->manage_permissions ) || intval( $_GET['id'] ) === 0 )
     797        if ( !current_user_can( $this->manage_permissions ) || intval( $_GET['id'] ) === 0 ) {
    743798            wp_safe_redirect( $url );
     799            exit;
     800        }
    744801
    745802        $post = get_post( $_GET['id'] );
    746803
    747         if ( !is_wp_error( $post ) ) {
     804        if ( is_object( $post ) ) {
    748805            $post->post_status = 'publish';
    749806            wp_update_post( $post );
     
    9961053     */
    9971054    function upload_form( $atts, $content = null ) {
     1055        static $inst = 0;
     1056
    9981057        add_shortcode( 'input', array( $this, 'shortcode_content_parser' ) );
    9991058        add_shortcode( 'textarea', array( $this, 'shortcode_content_parser' ) );
     
    10251084        $this->enqueue_scripts();
    10261085
    1027         $form_layout = in_array( $form_layout, array( 'post', 'image', 'media', 'post_image', 'post_media' ) ) ? $form_layout : 'media';
     1086        $form_layout = in_array( $form_layout, array( 'post', 'image', 'media', 'post_image', 'post_media' ), true ) ? $form_layout : 'media';
    10281087
    10291088        ob_start();
    10301089?>
    1031     <form action="<?php echo admin_url( 'admin-ajax.php' ) ?>" method="post" id="ugc-media-form" class="<?php echo esc_attr( $class )?> fu-upload-form" enctype="multipart/form-data">
     1090    <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">
    10321091     <div class="ugc-inner-wrapper">
    10331092         <h2><?php echo esc_html( $title ) ?></h2>
     
    12771336
    12781337        $output = '';
    1279         $map = array(
     1338        $map = apply_filters( 'fu_response_notices', array(
    12801339            'fu-sent' => array(
    12811340                'text' => __( 'Your file was successfully uploaded!', 'frontend-uploader' ),
     
    12941353                'class' => 'failure',
    12951354            ),
    1296         );
     1355        ) );
    12971356
    12981357        if ( isset( $res['response'] ) && isset( $map[ $res['response'] ] ) )
    12991358            $output .= $this->_notice_html( $map[ $res['response'] ]['text'] , $map[ $res['response'] ]['class'] );
    13001359
    1301         if ( !empty( $res['errors' ] ) )
     1360        if ( !empty( $res['errors' ] ) && 'fu-error' === $res['response'] )
    13021361            $output .= $this->_display_errors( $res['errors' ] );
    13031362
     
    13081367     *
    13091368     * @since 0.4
    1310      * @param string $errors [description]
     1369     * @param mixed $errors either a comma separated string of error codes or
    13111370     * @return string HTML
    13121371     */
    13131372    function _display_errors( $errors ) {
     1373        if ( ! $errors )
     1374            return;
     1375
    13141376        $output = '';
    13151377        $map = array(
     
    13191381            'fu-disallowed-mime-type' => array(
    13201382                'text' => __( 'This kind of file is not allowed. Please, try again selecting other file.', 'frontend-uploader' ),
    1321                 'format' => $this->is_debug ? '%1$s: <br/> File name: %2$s <br> MIME-TYPE: %3$s' : '%1$s: <br> %2$s',
     1383                'format' => $this->is_debug ? '%1$s File name: %2$s  MIME-TYPE: %3$s' : '%1$s: %2$s',
    13221384            ),
    1323             'fu-invalid-post' => array(
    1324                 'text' =>__( 'The content you are trying to post is invalid.', 'frontend-uploader' ),
     1385            'fu-disallowed-post-type' => array(
     1386                'text' =>__( 'This post type is not allowed.', 'frontend-uploader' ),
    13251387            ),
    13261388            'fu-error-media' => array(
    1327                 'text' =>__( "Couldn't upload the file", 'frontend-uploader' ),
     1389                'text' =>__( "Couldn't upload the file due to server error", 'frontend-uploader' ),
     1390                'format' => '%1$s - %2$s'
    13281391            ),
    13291392            'fu-error-post' => array(
    1330                 'text' =>__( "Couldn't create the post", 'frontend-uploader' ),
     1393                'text' =>__( "Couldn't create the post due to server error", 'frontend-uploader' ),
    13311394            ),
    13321395            'fu-suspicious-file' => array(
     
    13381401        // $error is the key of error, $details - additional information about the error
    13391402        foreach ( (array) $errors as $error => $details ) {
     1403
     1404            if ( ! isset( $map[ $error] ) ) {
     1405                continue;
     1406            }
    13401407
    13411408            // We might have multiple errors of the same type, let's walk through them
     
    13531420            }
    13541421        }
     1422
    13551423        return $output;
    13561424    }
     
    13661434        wp_enqueue_script( 'frontend-uploader-js', FU_URL . 'lib/js/frontend-uploader.js', array( 'jquery', 'jquery-validate' ) );
    13671435        // Include localization strings for default messages of validation plugin
    1368         // Filter is needed for wordpress.com
    1369         $wplang = apply_filters( 'fu_wplang', defined( 'WPLANG' ) ? WPLANG : '' );
    1370         if ( $wplang ) {
    1371             $lang = explode( '_', $wplang );
    1372             $relative_path = "lib/js/validate/localization/messages_{$lang[0]}.js";
     1436        if ( $this->lang ) {
     1437            $relative_path = "lib/js/validate/localization/messages_{$this->lang_short}.js";
    13731438            $url = FU_URL . $relative_path;
    13741439            if ( file_exists( FU_ROOT . "/{$relative_path}" ) )
     
    13911456
    13921457    /**
    1393      * 3.5 brings new Media UI
    1394      * Unfortunately, we have to specify ids of approved attachments explicitly,
     1458     * We have to specify ids of approved attachments explicitly in shortcode,
    13951459     * Otherwise, editors have to pick photos after they have already approved them in "Manage UGC"
    13961460     *
     
    13991463     * @return post id/wp_error
    14001464     */
    1401     function update_35_gallery_shortcode( $post_id, $attachment_id ) {
     1465    function update_gallery_shortcode( $post_id, $attachment_id ) {
    14021466        global $wp_version;
    14031467        // Bail of wp is older than 3.5
  • frontend-uploader/trunk/lib/php/frontend-uploader-settings.php

    r1402587 r1688580  
    163163                ),
    164164                array(
    165                     'name' => 'default_file_name',
    166                     'label' => __( 'Default file name', 'frontend-uploader' ),
    167                     'desc' => __( 'Leave blank to use original file name', 'frontend-uploader' ),
    168                     'type' => 'text',
    169                     'default' => 'Unnamed',
    170                     /* No need to set a sanitize callback. It is handled automagically. */
     165                    'name' => 'obfuscate_file_name',
     166                    'label' => __( 'Obfuscate file name', 'frontend-uploader' ),
     167                    'desc' => __( 'Yes', 'frontend-uploader' ),
     168                    'type' => 'checkbox',
     169                    'default' => '',
    171170                ),
    172171                array(
  • frontend-uploader/trunk/lib/php/functions.php

    r1402587 r1688580  
    1111    // Generated with dyn_php class: http://www.phpclasses.org/package/2923-PHP-Generate-PHP-code-programmatically.html
    1212    $mimes_exts = array(
    13         'doc'=>
    14         array(
    15             'label'=> 'Microsoft Word Document',
    16             'mimes'=>
    17             array(
    18                 'application/msword',
    19             ),
    20         ),
    21         'docx'=>
    22         array(
    23             'label'=> 'Microsoft Word Open XML Document',
    24             'mimes'=>
    25             array(
    26                 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    27             ),
    28         ),
    29         'xls'=>
    30         array(
    31             'label'=> 'Excel Spreadsheet',
    32             'mimes'=>
    33             array(
    34                 'application/vnd.ms-excel',
    35                 'application/msexcel',
    36                 'application/x-msexcel',
    37                 'application/x-ms-excel',
    38                 'application/vnd.ms-excel',
    39                 'application/x-excel',
    40                 'application/x-dos_ms_excel',
    41                 'application/xls',
    42             ),
    43         ),
    44         'xlsx'=>
    45         array(
    46             'label'=> 'Microsoft Excel Open XML Spreadsheet',
    47             'mimes'=>
    48             array(
    49                 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    50             ),
    51         ),
    52         'pdf'=>
    53         array(
    54             'label'=> 'Portable Document Format File',
    55             'mimes'=>
    56             array(
    57                 'application/pdf',
    58                 'application/x-pdf',
    59                 'application/acrobat',
    60                 'applications/vnd.pdf',
    61                 'text/pdf',
    62                 'text/x-pdf',
    63             ),
    64         ),
    65         'psd'=>
    66         array(
    67             'label'=> 'Adobe Photoshop Document',
    68             'mimes'=>
    69             array(
    70                 'image/photoshop',
    71                 'image/x-photoshop',
    72                 'image/psd',
    73                 'application/photoshop',
    74                  'application/psd',
    75                 'zz-application/zz-winassoc-psd',
    76                 'image/vnd.adobe.photoshop',
    77             ),
    78         ),
    7913        'csv'=>
    8014        array(
     
    8923                'application/vnd.msexcel',
    9024                'text/anytext',
    91             ),
    92         ),
    93         'ppt'=>
    94         array(
    95             'label'=> 'PowerPoint Presentation',
    96             'mimes'=>
    97             array(
    98                 'application/vnd.ms-powerpoint',
    99                 'application/mspowerpoint',
    100                 'application/ms-powerpoint',
    101                 'application/mspowerpnt',
    102                 'application/vnd-mspowerpoint',
    103             ),
    104         ),
    105         'pptx'=>
    106         array(
    107             'label'=> 'PowerPoint Open XML Presentation',
    108             'mimes'=>
    109             array(
    110                 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    11125            ),
    11226        ),
     
    14256            ),
    14357        ),
    144         'mp4'=>
    145         array(
    146             'label'=> 'MPEG-4 Video File',
    147             'mimes'=>
    148             array(
    149                 'video/mp4v-es',
    150                 'audio/mp4',
    151                 'application/mp4',
    152             ),
    153         ),
    154         'm4a'=> array(
    155             'label'=> 'MPEG-4 Audio File',
    156             'mimes'=> array(
    157                 'audio/aac', 'audio/aacp', 'audio/3gpp', 'audio/3gpp2', 'audio/mp4', 'audio/MP4A-LATM','audio/mpeg4-generic', 'audio/x-m4a', 'audio/m4a'
    158             ) ),
    159         'mov'=>
    160         array(
    161             'label'=> 'Apple QuickTime Movie',
    162             'mimes'=>
    163             array(
    164                 'video/quicktime',
    165                 'video/x-quicktime',
    166                 'image/mov',
    167                 'audio/aiff',
    168                 'audio/x-midi',
    169                 'audio/x-wav',
    170                 'video/avi',
    171             ),
    172         ),
    173         'mpg'=>
    174         array(
    175             'label'=> 'MPEG Video File',
    176             'mimes'=>
    177             array(
    178                 'video/mpeg',
    179                 'video/mpg',
    180                 'video/x-mpg',
    181                 'video/mpeg2',
    182                 'application/x-pn-mpg',
    183                 'video/x-mpeg',
    184                 'video/x-mpeg2a',
    185                 'audio/mpeg',
    186                 'audio/x-mpeg',
    187                 'image/mpg',
    188             ),
    189         ),
     58
    19059        'mid'=>
    19160        array(
     
    22190            ),
    22291        ),
    223         'wmv'=>
    224         array(
    225             'label'=> 'Windows Media Video File',
    226             'mimes'=>
    227             array(
    228                 'video/x-ms-wmv',
    229             ),
    230         ),
    23192    );
    23293
     
    260121    return '<div class="g-recaptcha" data-sitekey="' . esc_attr( fu_get_option( 'recaptcha_site_key' ) ) . '"></div>';
    261122}
     123
     124function fu_get_file_array() {
     125    $walker = function ($arr, $fileInfokey, callable $walker) {
     126        $ret = array();
     127        foreach ($arr as $k => $v) {
     128            if (is_array($v)) {
     129                $ret[$k] = $walker($v, $fileInfokey, $walker);
     130            } else {
     131                $ret[$k][$fileInfokey] = $v;
     132            }
     133        }
     134        return $ret;
     135    };
     136
     137    $files = array();
     138    foreach ($_FILES as $name => $values) {
     139        // init for array_merge
     140        if (!isset($files[$name])) {
     141            $files[$name] = array();
     142        }
     143        if (!is_array($values['error'])) {
     144            // normal syntax
     145            $files[$name] = $values;
     146        } else {
     147            // html array feature
     148            foreach ($values as $fileInfoKey => $subArray) {
     149                $files[$name] = array_replace_recursive($files[$name], $walker($subArray, $fileInfoKey, $walker));
     150            }
     151        }
     152    }
     153
     154    return $files;
     155}
     156
     157function fu_email_content_type( $content_type ) {
     158    return 'text/html';
     159}
  • frontend-uploader/trunk/lib/php/recaptcha.php

    r1468826 r1688580  
    55
    66function fu_add_recaptcha_js() {
     7    global $frontend_uploader;
    78    ?>
    8     <script src='https://www.google.com/recaptcha/api.js' async defer></script>
     9    <script src='<?php echo esc_url( add_query_arg( array( 'hl' => $frontend_uploader->lang_short ), 'https://www.google.com/recaptcha/api.js' ) ) ?>' async defer></script>
    910    <?php
    1011}
    11 
    1212function fu_recaptcha_check_submission( $should_process, $layout ) {
    1313
  • frontend-uploader/trunk/readme.txt

    r1468826 r1688580  
    44Tags: frontend, image, images, media, uploader, upload, video, audio, photo, photos, picture, pictures, file, user generated content, ugc, frontend upload
    55Requires at least: 4.1
    6 Tested up to: 4.6
    7 Stable tag: 1.1
     6Tested up to: 4.8
     7Stable tag: 1.2
    88License: GPLv2 or later
    99
     
    1616This plugin is a simple way for users to submit content to your site. The plugin uses a set of shortcodes to let you create highly customizable submission forms to your posts and pages. Once the content is submitted, it is held for moderation until you approve it. It’s that easy!
    1717
    18 **Exploring Customizations**
     18= Exploring Customizations =
    1919
    2020* You can modify the submission form as needed, and have users submit posts. Please visit the FAQ page for more information.
    2121* This plugin can be applied to Posts, Pages, and Custom Post Types. You can enable this via Settings > Frontend Uploader Settings.
    22 * In addition to the WordPress whitelisted file types, this also supports uploading of Microsoft Office and Adobe files, as well as various video and audio files. You can enable these file types via Settings > Frontend Uploader Settings.
    23 * The plugin allows you to upload all filetypes that are whitelisted in WordPress. If you’d like to add more file types and are comfortable with theme development, there's a filter that'll allow you to add some exotic MIME-type.
    24 
    25 You can also manage UGC for selected custom post types (Please refer to the plugin's settings page). By default, UGC is enabled for posts and attachments. If you want to be able to get any other post types UGC submissions just select desired post types at the plugin's settings page, and pass post_type='my_post_type' to the **[fu-upload-form]** shortcode.
     22* Form can be used in 3 modes: upload files, submit posts/custom post types, and mixed - submit a post and attach files to it.
     23* Form supports following fields: text, textarea, select, radio buttons, and checkboxes
    2624
    2725**Customizing Your Form with Shortcode Parameters**
    2826
    29 Frontend Uploader uses shortcodes to insert a form into a page or post. The default form shortcode is **[fu-upload-form]** but you can modify the plugin's behavior with additional parameters.
    30 
    31 If you would like to build a custom form, it must begin with *[fu-upload-form]* and end with *[/fu-upload-form]*.
    32 
    33 The **[fu-upload-form]** shortcode has several parameters important parameters:
     27Frontend Uploader is flexible and powerful, but unfortunately there's no visual form constructor at the moment - you have to use shortcodes. Please read this documentation carefully in order to leverage the plugin's features.
     28
     29At it's most basic form, the shortcode would look like this
     30`[fu-upload-form]`
     31
     32This will render a default form for media upload that has title, description and upload fields. (See screenshot 2)
     33
     34The same shortcode with some customizations would look like this:
     35
     36`[fu-upload-form class="html-wrapper-class" form_layout="media" title="Upload your media"]
     37[input type="text" name="post_title" id="title" class="required" description="Title"]
     38[textarea name="post_content" class="textarea" id="my-textarea" description="Description (optional)"]
     39[input type="file" name="photo" id="my-photo-submission" class="required" description="Your Photo" multiple="multiple"]
     40[input type="submit" class="btn" value="Submit"]
     41[/fu-upload-form]`
     42
     43As you can see, form elements are represented by shortcodes: [input], [textarea], [radio], [checkboxes], [file]. Each of them has a set of attributes, e.g. `id, class, name, value, values, type, description, minlength, maxlength. Please refer to "Form Elements" section of this readme for more details on elements and their attributes.
     44
     45= Main shortcode: [fu-upload-form] =
     46
     47The main shortcode, it has many important parameters that modify form behavior.
     48
     49In the following example we are creating a form with title "Upload your story and image". The form will allow to submit a custom post type *story* with an image which is going to be automatically inserted at the end of the story. The story will have a category with ID 1. On successful submission user will be redirected to http://example.com/success-page/
     50
     51`[fu-upload-form form_layout="post_media" title="Upload your story and image" class="my-class validate" post_type="story" append_to_post="true" success_page="http://example.com/success-page/" category="1" ][/fu-upload-form]`
     52
     53* The list of all parameters for [fu-upload-form] *
    3454
    3555 `form_layout`
    36  This determines whether the form is saved as a post/custom post type (‘post’), as a media file (`media`), or as a post with images (`post_media`).  Default value is `media`. Example: **[fu-upload-form class="your-class" title="Upload your media" form_layout=”post”]**
     56
     57 This determines whether the form is saved as a post/custom post type (‘post’), as a media file (`media`), or as a post with images (`post_media`).  Default value is `media`.
     58 Example: *[fu-upload-form form_layout=”post”]*
    3759
    3860 `title`
    39  Add this *[fu-upload-form]* shortcode, and this will be the Headline that will be displayed before the form. Example: **[fu-upload-form class="your-class" title="Upload your media"]**
     61
     62 Add this *[fu-upload-form]* shortcode, and this will be the Headline that will be displayed before the form.
     63 Example: **[fu-upload-form class="your-class" title="Upload your media"]**
    4064
    4165 `class`
    42  HTML class of the form, defaults to 'validate'. If you want your form being validated - do not remove validate class. If you would like to item to be required before a user can submit, you can set it to ‘required.’ Example: **[input type="text" name="post_title" id="title" class="required"]**
     66
     67 HTML class of the form, defaults to 'validate'. If you want your form being validated - do not remove validate class. If you would like to item to be required before a user can submit, you can set it to ‘required.’
     68 Example: *[input type="text" name="post_title" id="title" class="required"]*
    4369
    4470 `post_type`
    45  Any post whitelisted in settings post type. Defaults to 'post'. Example: **[fu-upload-form post_type="my-custom-post-type-slug"]**
    46 
     71
     72 Any post whitelisted in settings post type. Defaults to 'post'.
     73 Example: *[fu-upload-form post_type="my-custom-post-type-slug"]*
    4774
    4875 `append_to_post`
     76
    4977 Automatically insert images into uploaded post *(true or false)*
    5078
    5179 `success_page`
     80
    5281 URL to redirect on successful submission, defaults to the URL where the form is being displayed. For security reasons this should be an URL on your site (no external links). You can use **[fu-upload-response]** shortcode to display success/error messages on the redirect page.
    5382
    5483 `category`
     84
    5585 ID of category the post should be attached (only in post or post+media mode).
    5686
    5787 `post_id`
     88
    5889 ID of the post the image should be attached to. Defaults to the post ID of the post the shortcode is on.
    5990
    6091 `suppress_default_fields`
    61  In it's basic form shortcode adds some default fields for you - Title, Description, and file upload. However, you can create a customized shortcode.
    62  Override global setting for supressing default form fields *(true or false)*. Example: **[fu-upload-form suppress_default_fields="true"] ... inner shortcodes omitted... [/fu-upload-form]**
    63 
    64 
    65 Within **[fu-upload-form]**, you can add form fields.
    66 
    67 * `[input type="text" ]` A text box for one line of text
    68 * `[textarea]` => A text box for multiple lines of text
    69 * `[input type="file"]` => A file uploader
    70 * `[checkboxes values="value:Description,124:Banana,cherry:Cherry"]` => A set of checkboxes
    71 * `[radio name="foo" class="checkboxes" description="Pick a fruit" values="value:Description,124:Banana,cherry:Cherry"]` => A set of radio buttons
    72 * `[select name="foo" class="select" description="Pick a fruit" values="apple:Apple,banana:Banana,cherry:Cherry"]` => A select
     92
     93 Override global setting for supressing default form fields *(true or false)*.
     94 Example: `[fu-upload-form suppress_default_fields="true"] ... inner shortcodes omitted... [/fu-upload-form]`
     95
     96
     97= Form Elements =
     98
     99* `[input type="text" name="post_title" class="my-class" ]` A text box for one line of text
     100* `[textarea name="post_content" class="my-text-area"]` => A text box for multiple lines of text
     101* `[input type="file" name="my-file"]` => A file uploader
     102* `[checkboxes name="fruits" values="value:Description,124:Banana,cherry:Cherry"]` => A set of checkboxes
     103* `[radio name="fruit" class="checkboxes" description="Pick a fruit" values="value:Description,124:Banana,cherry:Cherry"]` => A set of radio buttons
     104* `[select name="select-fruit" class="select" description="Pick a fruit" values="apple:Apple,banana:Banana,cherry:Cherry"]` => A select
    73105* `[input type="submit" class="btn" value="Submit"]` => A submit button
    74106
     
    102134
    103135
    104 ** Support **
     136== Support ==
    105137
    106138Please make sure to read this readme including FAQ section before posting in support forum.
    107139
    108140
    109 ** Development **
     141**Development**
    110142
    111143[Fork the plugin or report an issue on Github](https://github.com/rinatkhaziev/wp-frontend-uploader/)
     
    145177You can modify the form as you'd like but you have to make sure that 'post_title' field is present, otherwise upload might fail
    146178
    147 = Example of default media upload form =
    148 
    149 Here's example of default form (*you don't need to enter all that if you want to use default form, just use `[fu-upload-form]`*):
    150 
    151 `[fu-upload-form class="your-class" title="Upload your media"]
    152 [input type="text" name="post_title" id="title" class="required" description="Title"]
    153 [textarea name="post_content" class="textarea" id="ug_caption" description="Description (optional)"]
    154 [input type="file" name="photo" id="ug_photo" class="required" description="Your Photo" multiple="multiple"]
    155 [input type="submit" class="btn" value="Submit"]
    156 [/fu-upload-form]`
    157 
    158179= I get a white screen or "0" when trying to upload a file =
    159 The major cause of this is either request timeout or request exceeding maximum request size. This  means that either the file was uploading for too long or it was too big. Two PHP settings to look at are:
    160 [max_execution_time](http://us1.php.net/manual/en/info.configuration.php#ini.max-execution-time) and [upload_max_filesize](http://us3.php.net/manual/en/ini.core.php#ini.upload-max-filesize). If you don't have any ability to modify these settings, please contact your hosting company's support.
     180The major cause of this is either request timeout or request exceeding maximum request size. This  means that either the file was uploading for too long or it was too big. PHP settings to look at are:
     181[max_execution_time](http://us1.php.net/manual/en/info.configuration.php#ini.max-execution-time) and [upload_max_filesize](http://us3.php.net/manual/en/ini.core.php#ini.upload-max-filesize), and [post_max_size](http://us3.php.net/manual/en/ini.core.php#ini.post-max-size). If you don't have any ability to modify these settings, please contact your hosting company's support.
    161182
    162183= Where are the plugin's settings? =
     
    180201You can suppress rendering of default form fields with "Suppress default fields" checkbox in settings
    181202
    182 = I want to customize my form =
    183 You can include additional elements with a set of shortcodes
    184 [input type="text" name="post_title" id="title" class="required" description="Title" multiple=""]
    185 [select name="foo" class="select" id="ug_select" description="Pick a fruit" values="Apple,Banana,Cherry"]
    186 [textarea name="post_content" class="textarea" id="ug_caption" description="Description (optional)"]
    187 [checkboxes name="foo" class="checkboxes" description="Pick a fruit" values="value:Description,124:Banana,cherry:Cherry"]
    188203
    189204= I want to be allow users to upload mp3, psd, or any other file restricted by default. =
     
    224239}`
    225240
    226 = There's no captcha! =
    227 The plugin uses Akismet as spam protection (you have to have Akismet installed and configured). Just enable Akismet support in the plugin's settings and voila.
     241= What about spam protection? =
     242The plugin supports Akismet (must be installed and configured properly) and Recaptcha. Just enable it in plugin settings.
    228243
    229244= Configuration Filters =
     
    287302== Changelog ==
    288303
     304= 1.2 (Jun 30, 2017) =
     305* Added image preview in email notification
     306* Minor bugfixes and cleanup
     307
    289308= 1.1 (Aug 5, 2016) =
    290309* Refactored admin list tables to prevent "Headers already sent error"
Note: See TracChangeset for help on using the changeset viewer.