009e30cb888529424ff3085d11785d71b244b472.svn-base 11.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
<?php if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access pages directly.
/**
 *
 * Field: Upload
 *
 */
/**
 * Info about JavaScript uploaders
 *
 * https://codex.wordpress.org/Function_Reference/wp_handle_upload
 * https://codex.wordpress.org/Function_Reference/media_handle_upload
 * http://www.kvcodes.com/2013/12/create-front-end-multiple-file-upload-wordpress/
 * https://wordpress.stackexchange.com/questions/173197/upload-multiple-files-with-media-handle-upload
 * https://www.ibenic.com/wordpress-file-upload-with-ajax/
 * https://www.theaveragedev.com/wordpress-files-ajax/
 *
 * Dropzone
 * https://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php
 * http://www.dropzonejs.com/
 * https://github.com/enyo/dropzone/wiki/FAQ
 * https://wordpress.org/plugins/wp-dropzone/
 *
 * FineUploader
 * wp-multi-file-uploader
 * https://docs.fineuploader.com/integrating/jquery.html
 * https://github.com/FineUploader/fine-uploader
 *
 * PlUpload
 * http://www.plupload.com/examples/events
 *
 * JQuery Drag and Drop Files
 * https://danielmg.org/demo/java-script/bootstrap-drag-and-drop-uploader
 *
 * jQuery File Upload
 * https://blueimp.github.io/jQuery-File-Upload/jquery-ui.html
 */
if ( ! class_exists( 'Exopite_Simple_Options_Framework_Field_upload' ) ) {

	class Exopite_Simple_Options_Framework_Field_upload extends Exopite_Simple_Options_Framework_Fields {

		public function __construct( $field, $value = '', $unique = '', $config = array() ) {

			parent::__construct( $field, $value, $unique, $config );

			$defaults = array(
				'attach'                   => false,
				'filecount'                => 1,
				'delete-enabled'           => true,
				'delete-force-confirm'     => true,
				'retry-enable-auto'        => true,
				'retry-max-auto-attempts'  => 1,
				'retry-auto-attempt-delay' => 2,
				'auto-upload'              => false,
			);

			$options = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();

			$this->field['options'] = wp_parse_args( $options, $defaults );

		}

		public function output() {

			echo $this->element_before();

			?>
            <!-- Fine Uploader Thumbnails template w/ customization
            ====================================================================== -->
            <script type="text/template" id="qq-template-manual-trigger">
                <div class="qq-uploader-selector qq-uploader"
                     qq-drop-area-text="<?php esc_html_e( 'Drop files here', 'exopite-sof' ); ?>">
                    <div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
                        <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                             class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
                    </div>
                    <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
                        <span class="qq-upload-drop-area-text-selector"></span>
                    </div>
                    <div class="buttons">
                        <div class="qq-upload-button-selector exopite-sof-btn">
                            <div><?php esc_html_e( 'Select files', 'exopite-sof' ); ?></div>
                        </div>
                        <div class="exopite-sof-btn trigger-upload">
                            <i class="icon-upload icon-white"></i> <?php esc_html_e( 'Upload', 'exopite-sof' ); ?>
                        </div>
                    </div>
                    <span class="qq-drop-processing-selector qq-drop-processing">
                        <span><?php esc_html_e( 'Processing dropped files...', 'exopite-sof' ); ?></span>
                        <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
                    </span>
                    <ul class="qq-upload-list-selector qq-upload-list" aria-live="polite"
                        aria-relevant="additions removals">
                        <li>
                            <div class="qq-progress-bar-container-selector">
                                <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"
                                     class="qq-progress-bar-selector qq-progress-bar"></div>
                            </div>
                            <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
                            <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
                            <span class="qq-upload-file-selector qq-upload-file"></span>
                            <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"
                                  aria-label="Edit filename"></span>
                            <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
                            <span class="qq-upload-size-selector qq-upload-size"></span>
                            <button type="button"
                                    class="qq-btn qq-upload-cancel-selector qq-upload-cancel"><?php esc_html_e( 'Cancel', 'exopite-sof' ); ?></button>
                            <button type="button"
                                    class="qq-btn qq-upload-retry-selector qq-upload-retry"><?php esc_html_e( 'Retry', 'exopite-sof' ); ?></button>
                            <button type="button"
                                    class="qq-btn qq-upload-delete-selector qq-upload-delete"><?php esc_html_e( 'Delete', 'exopite-sof' ); ?></button>
                            <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
                        </li>
                    </ul>

                    <dialog class="qq-alert-dialog-selector">
                        <div class="qq-dialog-message-selector"></div>
                        <div class="qq-dialog-buttons">
                            <button type="button"
                                    class="qq-cancel-button-selector"><?php esc_html_e( 'Close', 'exopite-sof' ); ?></button>
                        </div>
                    </dialog>

                    <dialog class="qq-confirm-dialog-selector">
                        <div class="qq-dialog-message-selector"></div>
                        <div class="qq-dialog-buttons">
                            <button type="button"
                                    class="qq-cancel-button-selector"><?php esc_html_e( 'No', 'exopite-sof' ); ?></button>
                            <button type="button"
                                    class="qq-ok-button-selector"><?php esc_html_e( 'Yes', 'exopite-sof' ); ?></button>
                        </div>
                    </dialog>

                    <dialog class="qq-prompt-dialog-selector">
                        <div class="qq-dialog-message-selector"></div>
                        <input type="text">
                        <div class="qq-dialog-buttons">
                            <button type="button"
                                    class="qq-cancel-button-selector"><?php esc_html_e( 'Cancel', 'exopite-sof' ); ?></button>
                            <button type="button"
                                    class="qq-ok-button-selector"><?php esc_html_e( 'Ok', 'exopite-sof' ); ?></button>
                        </div>
                    </dialog>
                </div>
            </script>
			<?php

			$maxsize = Exopite_Simple_Options_Framework_Upload::file_upload_max_size();
			if ( isset( $this->field['options']['maxsize'] ) && Exopite_Simple_Options_Framework_Upload::file_upload_max_size() >= $this->field['options']['maxsize'] ) {
				$maxsize = $this->field['options']['maxsize'];
			}

			$allowed_mime_types = ( gettype( Exopite_Simple_Options_Framework_Upload::allowed_mime_types() ) == 'array' ) ? implode( ',', Exopite_Simple_Options_Framework_Upload::allowed_mime_types() ) : Exopite_Simple_Options_Framework_Upload::allowed_mime_types();

			if ( isset( $this->field['options']['allowed'] ) && is_array( $this->field['options']['allowed'] ) ) {
				$allowed_mime_types_array = explode( ',', $allowed_mime_types );
				$allowed_mime_types_array = array_intersect( $allowed_mime_types_array, $this->field['options']['allowed'] );
				$allowed_mime_types       = implode( ',', $allowed_mime_types_array );
			}


			?>
            <div class="qq-template" <?php
			echo 'data-filecount="' . $this->field['options']['filecount'] . '" ';
			echo 'data-mimetypes="' . $allowed_mime_types . '" ';
			echo 'data-maxsize="' . $maxsize . '" ';
			echo ( $this->field['options']['attach'] && $this->config['type'] == 'metabox' ) ? 'data-postid="' . get_the_ID() . '" ' : '';
			echo 'data-ajaxurl="' . site_url( 'wp-admin/admin-ajax.php' ) . '" ';
			echo 'data-delete-enabled="' . $this->field['options']['delete-enabled'] . '" ';
			echo 'data-delete-force-confirm="' . $this->field['options']['delete-force-confirm'] . '" ';
			echo 'data-retry-enable-auto="' . $this->field['options']['retry-enable-auto'] . '" ';
			echo 'data-retry-max-auto-attempts="' . $this->field['options']['retry-max-auto-attempts'] . '" ';
			echo 'data-retry-auto-attempt-delay="' . $this->field['options']['retry-auto-attempt-delay'] . '" ';
			echo 'data-auto-upload="' . $this->field['options']['auto-upload'] . '" ';
			?>>
            </div>
            <div class="qq-template-info">
				<?php

				echo esc_attr__( 'Max amount of files: ', 'exopite-sof' ) . $this->field['options']['filecount'] . '<br>';
				echo esc_attr__( 'Max file upload size: ', 'exopite-sof' ) . number_format( (float) ( Exopite_Simple_Options_Framework_Upload::file_upload_max_size() / 1048576 ), 2, '.', '' ) . 'Mb<br><br>';
				// echo '<i style="font-size:.9em;">' . esc_attr__( 'To increase file upload limit in the standard built-in WordPress media uploader up as large as available disk space allows, you could use', 'exopite-sof' ) . ' <a target="_blank" href="' . admin_url() . 'plugin-install.php?tab=plugin-information&plugin=tuxedo-big-file-uploads">Tuxedo Big File Uploads</a> ' . esc_attr__( 'Plugin', 'exopite-sof' ) . '</i>';

				?>
            </div>
			<?php

			echo $this->element_after();

		}

		public static function enqueue( $args ) {

			if ( ! wp_script_is( 'fine-uploader' ) ) {

				/**
				 * https://fineuploader.com/
				 */

				$resources = array(
					array(
						'name'       => 'fine-uploader',
						'fn'         => 'fine-uploader-new.min.css',
						'type'       => 'style',
						'dependency' => array(),
						'version'    => '5.15.5',
						'attr'       => 'all',
					),
					array(
						'name'       => 'fine-uploader',
						'fn'         => 'jquery.fine-uploader.min.js',
						'type'       => 'script',
						'dependency' => array(),
						'version'    => '5.15.5',
						'attr'       => true,
					),
					array(
						'name'       => 'exopite-sof-fine-uploader-loader',
						'fn'         => 'loader-fine-uploader.min.js',
						'type'       => 'script',
						'dependency' => array( 'fine-uploader' ),
						'version'    => '',
						'attr'       => true,
					),
				);

				parent::do_enqueue( $resources, $args );

			}

		}

	}

}