Beispiel #1
0
    /**
     * Prints a image upload field
     *
     * @param array $attr
     * @param int|null $post_id
     */
    function image_upload($attr, $post_id, $type, $form_id)
    {
        $has_featured_image = false;
        $has_images = false;
        $has_avatar = false;
        if ($post_id) {
            if ($this->is_meta($attr)) {
                $images = $this->get_meta($post_id, $attr['name'], $type, false);
                $has_images = true;
            } else {
                if ($type == 'post') {
                    // it's a featured image then
                    $thumb_id = get_post_thumbnail_id($post_id);
                    if ($thumb_id) {
                        $has_featured_image = true;
                        $featured_image = WPUF_Upload::attach_html($thumb_id, 'featured_image');
                    }
                } else {
                    // it must be a user avatar
                    $has_avatar = true;
                    $featured_image = get_avatar($post_id);
                }
            }
        }
        ?>
        <div class="wpuf-fields">
            <div id="wpuf-<?php 
        echo $attr['name'];
        ?>
-upload-container">
                <div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php 
        echo $attr['required'];
        ?>
">
                    <a id="wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles" class="button file-selector <?php 
        echo ' wpuf_' . $attr['name'] . '_' . $form_id;
        ?>
" href="#"><?php 
        _e('Select Image', 'wpuf');
        ?>
</a>
                    <div class="render-img">
                      <canvas id="uniCanvas" width="0" height="0"></canvas>
                    </div>

                    <!--modal allow resize-->
                    <div class="modal fade" tabindex="-1" role="dialog" id="resizeImageModal">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title">resize image</h4>
                                </div>
                                <div class="modal-body">
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    <button type="button" class="btn btn-primary" id="btnResize">Save changes</button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->
                    <ul class="wpuf-attachment-list thumbnails">
                        <li id="imageInfo" style="display: none;" class="wpuf-image-wrap thumbnail">
                            <div class="wpuf-file-input-wrap">
                                <input id="imageTitle" type="text" placeholder="Title">
                                <textarea id="imageCaption" placeholder="Caption"></textarea>
                                <textarea id="imageDecription" placeholder="Description"></textarea>
                            </div>
                            <input id="imageId" type="hidden" name="wpuf_files[featured_image][]">
                        </li>
                    </ul>
                </div>
            </div><!-- .container -->

            <span class="wpuf-help"><?php 
        echo stripslashes($attr['help']);
        ?>
</span>

        </div> <!-- .wpuf-fields -->
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css">
        <script type="text/javascript">
            jQuery(function($) {
                new WPUF_Uploader('wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles', '<?php 
        echo $attr['name'];
        ?>
', 'jpg,jpeg,gif,png,bmp', <?php 
        echo $attr['max_size'];
        ?>
);
            });

        </script>
    <?php 
    }
    /**
     * Prints a image upload field
     *
     * @param array $attr
     * @param int|null $post_id
     */
    function image_upload($attr, $post_id, $type, $form_id)
    {
        $has_featured_image = false;
        $has_images = false;
        $has_avatar = false;
        if ($post_id) {
            if ($this->is_meta($attr)) {
                $images = $this->get_meta($post_id, $attr['name'], $type, false);
                $has_images = true;
            } else {
                if ($type == 'post') {
                    // it's a featured image then
                    $thumb_id = get_post_thumbnail_id($post_id);
                    if ($thumb_id) {
                        $has_featured_image = true;
                        $featured_image = WPUF_Upload::attach_html($thumb_id, 'featured_image');
                    }
                } else {
                    // it must be a user avatar
                    $has_avatar = true;
                    $featured_image = get_avatar($post_id);
                }
            }
        }
        ?>

        <div class="wpuf-fields">
            <div id="wpuf-<?php 
        echo $attr['name'];
        ?>
-upload-container">
                <div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php 
        echo $attr['required'];
        ?>
">
                    <a id="wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles" class="button file-selector <?php 
        echo ' wpuf_' . $attr['name'] . '_' . $form_id;
        ?>
" href="#"><?php 
        _e('Select Image', 'wpuf');
        ?>
</a>

                    <ul class="wpuf-attachment-list thumbnails">
                        <?php 
        if ($has_featured_image) {
            echo $featured_image;
        }
        if ($has_avatar) {
            $avatar = get_user_meta($post_id, 'user_avatar', true);
            if ($avatar) {
                echo $featured_image;
                printf('<br><a href="#" data-confirm="%s" class="wpuf-button button wpuf-delete-avatar">%s</a>', __('Are you sure?', 'wpuf'), __('Delete', 'wpuf'));
            }
        }
        if ($has_images) {
            foreach ($images as $attach_id) {
                echo WPUF_Upload::attach_html($attach_id, $attr['name']);
            }
        }
        ?>
                    </ul>
                </div>
            </div><!-- .container -->

            <span class="wpuf-help"><?php 
        echo stripslashes($attr['help']);
        ?>
</span>

        </div> <!-- .wpuf-fields -->

        <script type="text/javascript">
            jQuery(function($) {
                new WPUF_Uploader('wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles', 'wpuf-<?php 
        echo $attr['name'];
        ?>
-upload-container', <?php 
        echo $attr['count'];
        ?>
, '<?php 
        echo $attr['name'];
        ?>
', 'jpg,jpeg,gif,png,bmp', <?php 
        echo $attr['max_size'];
        ?>
);
            });
        </script>
    <?php 
    }
Beispiel #3
0
    /**
     * Prints a file upload field
     *
     * @param array $attr
     * @param int|null $post_id
     */
    public static function file_upload($attr, $post_id, $type, $form_id, $obj)
    {
        $allowed_ext = '';
        $extensions = wpuf_allowed_extensions();
        if (is_array($attr['extension'])) {
            foreach ($attr['extension'] as $ext) {
                $allowed_ext .= $extensions[$ext]['ext'] . ',';
            }
        } else {
            $allowed_ext = '*';
        }
        $uploaded_items = $post_id ? $obj->get_meta($post_id, $attr['name'], $type, false) : array();
        ?>

        <div class="wpuf-fields">
            <div id="wpuf-<?php 
        echo $attr['name'];
        ?>
-upload-container">
                <div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php 
        echo $attr['required'];
        ?>
">
                    <a id="wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles" data-form_id="<?php 
        echo $form_id;
        ?>
" class="button file-selector <?php 
        echo ' wpuf_' . $attr['name'] . '_' . $form_id;
        ?>
" href="#"><?php 
        _e('Select File(s)', 'wpuf');
        ?>
</a>

                    <ul class="wpuf-attachment-list thumbnails">
                        <?php 
        if ($uploaded_items) {
            foreach ($uploaded_items as $attach_id) {
                echo WPUF_Upload::attach_html($attach_id, $attr['name']);
                if (is_admin()) {
                    printf('<a href="%s">%s</a>', wp_get_attachment_url($attach_id), __('Download File', 'wpuf'));
                }
            }
        }
        ?>
                    </ul>
                </div>
            </div><!-- .container -->

            <span class="wpuf-help"><?php 
        echo stripslashes($attr['help']);
        ?>
</span>

        </div> <!-- .wpuf-fields -->

        <script type="text/javascript">
            jQuery(function($) {
                new WPUF_Uploader('wpuf-<?php 
        echo $attr['name'];
        ?>
-pickfiles', 'wpuf-<?php 
        echo $attr['name'];
        ?>
-upload-container', <?php 
        echo $attr['count'];
        ?>
, '<?php 
        echo $attr['name'];
        ?>
', '<?php 
        echo $allowed_ext;
        ?>
', <?php 
        echo $attr['max_size'];
        ?>
);
            });
        </script>
    <?php 
    }