+++ /dev/null
-/*
- * HTML5 Image Upload Support
- *
- * Developed from information in http://www.sitepoint.com/html5-file-drag-and-drop/
- */
-
-jQuery(document).ready(function($) {
-
- // output information
- function Output(msg) {
- var m = $id("imageDragMessages");
- m.innerHTML = msg + m.innerHTML;
- }
-
- // Setup Drag and Drop when Add and
- $('#newImageButton').click( function() {
- //call initialization function if drag/drop supported by browser
- if (window.File && window.FileList && window.FileReader) {
- ImageDragInit();
- }
- });
-
- //initialize
- function ImageDragInit() {
-
- // is XHR2 available?
- var xhr = new XMLHttpRequest();
- if (xhr.upload) {
-
- // Change from Drag/Drop not supported to drop here display
- $('#noImageDrop').css('display', 'none');
- $('#noImageDrop').css('display', 'none');
- $('#imageDrop').css('display', 'block');
-
- // file drop
-// imageDrop.addEventListener("dragover", FileDragHover, false);
-// imageDrop.addEventListener("dragleave", FileDragHover, false);
-// imageDrop.addEventListener("drop", FileSelectHandler, false);
-
- // remove submit button
- newImageSubmit.style.display = "none";
-
- }
-
- }
-
- /*
- $(window).on('dragenter', function(){
- $(this).preventDefault();
- });
-*/
-
- // Change drop destination appearance only when dragging over a file.
- $('#imageDrop').on('dragenter', function(){
- $('#imageDropText').css('display', 'none');
- $('#imageDrop').addClass('imageDropDragOver');
- });
-
- $('#imageDrop').on('dragleave', function(){
- $('#imageDropText').css('display', 'block');
- $('#imageDrop').removeClass('imageDropDragOver');
- });
-
- // file drag hover
- $('#imageDrop').mouseover( function(e) {
- e.stopPropagation();
-// e.preventDefault();
-// $('#imageDrop').css('display', 'block');
- e.target.className = (e.type == "dragover" ? "hover" : "");
- });
-
- // file selection
- $('#newImage').change( function() {
-
- // cancel event and hover styling
- FileDragHover(e);
-
- // fetch FileList object
- var files = e.target.files || e.dataTransfer.files;
-
- // process all File objects
- for (var i = 0, f; f = files[i]; i++) {
- ParseFile(f);
- }
-
- });
-
-});
+++ /dev/null
-; http://editorconfig.org
-
-root = true
-
-[*]
-indent_style = space
-indent_size = 4
-end_of_line = lf
-charset = utf-8
-trim_trailing_whitespace = true
-insert_final_newline = true
\ No newline at end of file
+++ /dev/null
-node_modules
-tmp
-
-.DS_Store
-._*
\ No newline at end of file
+++ /dev/null
-language: node_js
-node_js:
- - 0.10
-
-before_script:
- - npm install -g grunt-cli
-
-script: "grunt test"
+++ /dev/null
-ezdz-multiple
-
-jQuery File Input plugin ezdz multiple files and grid preview
-
-It is based on Ezdz jQuery File Input plugin. new features have been added as follows.
-
- support multiple file upload.
- support grid preview of image.
-
-All other settings pls refer to ezdz documentation https://github.com/jaysalvat/ezdz
-
-index.html file demostrates multiple file upload features and preview of image features.
-
-remember add multiple attribute to input tag.
-Sample Usage
-
-in the html head section
-
-<link rel="stylesheet" href="src/jquery.ezdz.css">
-<script type="text/javascript" src= "node_modules/jquery/dist/jquery.min.js"></script>
-<script src="src/jquery.ezdz.js"></script>
-
-in the body section, simply add normal input tag, the plugin will automatically convert it into dropzone.
-
-<input type="file" name="file_upload[]" accept="image/png, image/jpeg" multiple/>
-
-add javascript pointing to input tag, add customize configuration.
-
-$('input[type="file"]').ezdz({
- text: 'drop cover photos',
- validators: {
- maxWidth: 2000,
- maxHeight: 2000,
- maxNumber: 6
- },
- reject: function(file, errors) {
- if (errors.mimeType) {
- alert(file.name + ' must be an image.');
- return;
- }
-
- if (errors.maxWidth) {
- alert(file.name + ' must be width:2000px max.');
- return;
- }
-
- if (errors.maxHeight) {
- alert(file.name + ' must be height:2000px max.');
- return;
- }
-
- if (errors.maxNumber) {
- alert('you can upload maximum of 6 images');
- return;
- }
- }
- });
-
-if you looking for modify preview image grid, editing jquery.ezdz.css, for example, the code represent 3 columns grid.
-
-.image-g li {
- float: left;
- max-width: 32%;
- max-height: 48%;
- padding: 0.10em;
-}
-
-.image-g li:nth-child(3n+1) {
- clear: left;
-}
+++ /dev/null
-/* ----------------------------------------------------------------------------
-// Ezdz [izy-dizy]
-// Licensed under the MIT license.
-// http://github.com/jaysalvat/ezdz/
-// ----------------------------------------------------------------------------
-// Copyright (C) 2014 Jay Salvat
-// http://jaysalvat.com/
-// --------------------------------------------------------------------------*/
-
-.ezdz-dropzone {
- position: relative;
-/* font: bold 24px arial; */
- text-align: center;
- width: 100%;
- height: 400px; /* Width of entire drop area */
- line-height: 100px;
- color: #;
- overflow: hidden;
-}
-
-.ezdz-dropzone div {
- color: lightgray;
-/* font: bold 24px arial; */
- line-height: 100px;
- /* */
-}
-
-.ezdz-dropzone span {
- border-radius: 20px;
- background: black;
- background: rgba(0,0,0,0.7);
- color: white;
- font-size: 13px;
- font-weight: normal;
- max-width: 90%;
- vertical-align: middle;
- padding: 4%;
- line-height: 10px;
- display: inline-block;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
-}
-
-.ezdz-dropzone img {
- border-radius: 5px;
-
-}
-
-.ezdz-dropzone [type="file"] {
- cursor: pointer;
- position: absolute;
- width: 100%;
- height: 100%;
- opacity: 0;
- margin: 0;
- padding: 0;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
-}
-
-.ezdz-focus {
-/* border: 10px dotted darkgray; */
- color: darkgray;
-}
-
-.ezdz-focus div {
- color: darkgray;
-
-}
-
-.ezdz-enter {
-/* border: 10px solid black; */
- color: black;
-}
-
-.ezdz-enter div {
- color: black;
-
-}
-.ezdz-accept {
-/* border: 10px solid gray; */
- color: gray;
-}
-
-.ezdz-accept div {
- color: gray;
-}
-
-.ezdz-reject {
-/* border: 10px solid darkred; */
- color: darkred;
-}
-
-.ezdz-reject div {
- color: darkred;
-}
-
-.image-g {
- list-style-type: none;
- padding: 0.25em;
- overflow: hidden;
- white-space: nowrap;
-}
-
-.image-g li {
- float: left;
- width: 360px;
-/* max-width: 32%;
- max-height: 48%; */
- padding: 0.10em;
-}
-
-.image-g img {
- display: block;
- width: 40%;
- height: auto;
- border: 2px solid black;
-}
-
-.image-g li:nth-child(3n+1) {
- clear: left;
-}
-
\ No newline at end of file
+++ /dev/null
-/* ----------------------------------------------------------------------------
-// Ezdz [izy-dizy]
-// Licensed under the MIT license.
-// http://github.com/jaysalvat/ezdz/
-// ----------------------------------------------------------------------------
-// Copyright (C) 2014 Jay Salvat
-// http://jaysalvat.com/
-// --------------------------------------------------------------------------*/
-
-/* global define: true, require: true, jQuery */
-
-(function (factory) {
- "use strict";
-
- if (typeof define === 'function' && define.amd) {
- define(['jquery'], factory);
- } else if (typeof exports === 'object') {
- factory(require('jquery'));
- } else {
- factory(jQuery);
- }
-}(function ($) {
- "use strict";
-
- // Default settings
- var defaults = {
- className: '',
- text: 'Drop a file',
- previewImage: true,
- value: null,
- classes: {
- main: 'ezdz-dropzone',
- enter: 'ezdz-enter',
- reject: 'ezdz-reject',
- accept: 'ezdz-accept',
- focus: 'ezdz-focus'
- },
- validators: {
- maxSize: null,
- width: null,
- maxWidth: null,
- minWidth: null,
- height: null,
- maxHeight: null,
- minHeight: null,
- maxNumber: null
- },
- init: function() {},
- enter: function() {},
- leave: function() {},
- reject: function() {},
- accept: function() {},
- format: function(filename) {
- return filename;
- }
- };
-
- // Main plugin
- $.ezdz = function(element, options) {
- this.settings = $.extend(true, {}, defaults, $.ezdz.defaults, options);
- this.$input = $(element);
-
- var self = this,
- settings = self.settings,
- $input = self.$input;
-
- if (!$input.is('input[type="file"]')) {
- return;
- }
-
- // Stop if not compatible with HTML5 file API
- if (!$.ezdz.isBrowserCompatible()) {
- return;
- }
-
- // private: Init the plugin
- var init = function() {
- var $ezdz, $container, value;
-
- // Build the container
- $container = $('<div class="' + settings.classes.main + '" />')
-
- .on('dragover.ezdz', function() {
- $(this).addClass(settings.classes.enter);
-
- if ($.isFunction(settings.enter)) {
- settings.enter.apply(this);
- }
- })
-
- .on('dragleave.ezdz', function() {
- $(this).removeClass(settings.classes.enter);
-
- if ($.isFunction(settings.leaved)) {
- settings.leaved.apply(this);
- }
- })
-
- .addClass(settings.className);
-
- // Build the whole dropzone
- $input
- .wrap($container)
- .before('<div>' + settings.text + '</div>');
-
- $ezdz = $input.parent('.' + settings.classes.main);
-
- // Preview a file at start if it's defined
- value = settings.value || $input.data('value');
-
- if (value) {
- self.preview(value);
- }
-
- // Trigger the init callback
- if ($.isFunction(settings.init)) {
- settings.init.apply($input, [ value ]);
- }
-
- // Events on the input
- $input
-
- .on('focus.ezdz', function() {
- $ezdz.addClass(settings.classes.focus);
- })
-
- .on('blur.ezdz', function() {
- $ezdz.removeClass(settings.classes.focus);
- })
-
- .on('change.ezdz', function() {
-
-
- // No file, so user has cancelled
- if (this.files.length == 0) {
- return;
- }
-
- // Mime-Types
- var allowed = $input.attr('accept'),
- accepted = false,
- valid = true,
- errors = {
- 'mimeType': false,
- 'maxSize': false,
- 'width': false,
- 'minWidth': false,
- 'maxWidth': false,
- 'height': false,
- 'minHeight': false,
- 'maxHeight': false,
- 'maxNumber': false
- };
-
- //Check the maximum number of files
-
- if (settings.validators.maxNumber && this.files.length > settings.validators.maxNumber) {
- valid = false;
- errors.maxNumber = true;
- }
-
- var imgArr = new Array();
- var isImage = true;
-
- var i=0;
- for(i=0;i<this.files.length;i++){
-
- var file = this.files[i];
-
-
- // Info about the dropped or selected file
- var basename = file.name.replace(/\\/g,'/').replace( /.*\//, ''),
- extension = file.name.split('.').pop(),
- formatted = settings.format(basename);
-
- file.extension = extension;
-
-
- // Check the accepted Mime-Types from the input file
- if (allowed) {
- var types = allowed.split(/[,|]/);
-
- $.each(types, function(i, type) {
- type = $.trim(type);
-
- if (file.type === type) {
- accepted = true;
- return false;
- }
-
- // Mime-Type with wildcards ex. image/*
- if (type.indexOf('/*') !== false) {
- var a = type.replace('/*', ''),
- b = file.type.replace(/(\/.*)$/g, '');
-
- if (a === b) {
- accepted = true;
- return false;
- }
- }
- });
-
- if (accepted === false) {
- errors.mimeType = true;
- }
- } else {
- accepted = true;
- }
-
- // Reset the accepted / rejected classes
- $ezdz.removeClass(settings.classes.reject + ' ' + settings.classes.accept);
-
- // If the Mime-Type is not accepted
- if (accepted !== true) {
- $input.val('');
-
- $ezdz.addClass(settings.classes.reject);
-
- // Trigger the reject callback
- if ($.isFunction(settings.reject)) {
- settings.reject.apply($input, [ file, errors ]);
- }
- return false;
- }
-
- // Read the added file
- var reader = new FileReader(file);
-
- reader.readAsDataURL(file);
-
- reader.onload = function(e) {
- var img = new Image();
-
- imgArr.push(img);
-
- file.data = e.target.result;
- img.src = file.data;
-
- setTimeout(function() {
- if(img.width && img.height){
-
- }else{
- isImage = false;
- }
-
- // Validator
- if (settings.validators.maxSize && file.size > settings.validators.maxSize) {
- valid = false;
- errors.maxSize = true;
- }
-
- if (isImage) {
- file.width = img.width;
- file.height = img.height;
-
- if (settings.validators.width && img.width !== settings.validators.width) {
- valid = false;
- errors.width = true;
- }
-
- if (settings.validators.maxWidth && img.width > settings.validators.maxWidth) {
- valid = false;
- errors.maxWidth = true;
- }
-
- if (settings.validators.minWidth && img.width < settings.validators.minWidth) {
- valid = false;
- errors.minWidth = true;
- }
-
- if (settings.validators.height && img.height !== settings.validators.height) {
- valid = false;
- errors.height = true;
- }
-
- if (settings.validators.maxHeight && img.height > settings.validators.maxHeight) {
- valid = false;
- errors.maxHeight = true;
- }
-
- if (settings.validators.minHeight && img.height < settings.validators.minHeight) {
- valid = false;
- errors.minHeight = true;
- }
- }
-
-
- }, 100);
- };
- }
-
- setTimeout(function() {
-
- // The file is validated, so added to input
- if (valid === true) {
- $ezdz.find('img').remove();
-
- if (isImage && settings.previewImage === true) {
- var $image_wrapper = $("<ul></ul>");
- $image_wrapper.addClass("image-g");
- var i;
- for (i=0;i<imgArr.length;i++){
- var img_obj = imgArr[i];
- var $image_item = $("<li></li>").append(img_obj);
- $image_wrapper.append($image_item);
- }
- $ezdz.find('div').html($image_wrapper.fadeIn());
- } else {
- $ezdz.find('div').html('<span>' + formatted + '</span>');
- }
-
- $ezdz.addClass(settings.classes.accept);
-
- // Trigger the accept callback
- if ($.isFunction(settings.accept)) {
- settings.accept.apply($input, [ file ]);
- }
-
- // The file is invalidated, so rejected
- } else {
- $input.val('');
-
- $ezdz.addClass(settings.classes.reject);
-
- // Trigger the reject callback
- if ($.isFunction(settings.reject)) {
- settings.reject.apply($input, [ file, errors ]);
- }
- }
-
- }, 1000);
-
-
- });
- };
-
- init();
- };
-
- // Inject a file or image in the preview
- $.ezdz.prototype.preview = function(path, callback) {
- var settings = this.settings,
- $input = this.$input,
- $ezdz = $input.parent('.' + settings.classes.main),
- basename = path.replace(/\\/g,'/').replace( /.*\//, ''),
- formatted = settings.format(basename);
-
- var img = new Image();
- img.src = path;
-
- // Is an image
- img.onload = function() {
- $ezdz.find('div').html($(img).fadeIn());
-
- if ($.isFunction(callback)) {
- callback.apply(this);
- }
- };
-
- // Is not an image
- img.onerror = function() {
- $ezdz.find('div').html('<span>' + formatted + '</span>');
-
- if ($.isFunction(callback)) {
- callback.apply(this);
- }
- };
-
- $ezdz.addClass(settings.classes.accept);
- };
-
- // Destroy ezdz
- $.ezdz.prototype.destroy = function() {
- var settings = this.settings,
- $input = this.$input;
-
- $input.parent('.' + settings.classes.main).replaceWith($input);
- $input.off('*.ezdz');
- $input.removeData('ezdz');
- };
-
- // Extend settings
- $.ezdz.prototype.options = function(options) {
- var settings = this.settings;
-
- if (!options) {
- return settings;
- }
-
- $.extend(true, this.settings, options);
- };
-
- // Get input container
- $.ezdz.prototype.container = function() {
- var settings = this.settings,
- $input = this.$input;
-
- return $input.parent('.' + settings.classes.main);
- };
-
- // Is browser compatible
- $.ezdz.isBrowserCompatible = function() {
- return !!(window.File && window.FileList && window.FileReader);
- };
-
- // Default options
- $.ezdz.defaults = defaults;
-
- // jQuery plugin
- $.fn.ezdz = function(options) {
- var args = arguments,
- plugin = $(this).data('ezdz');
-
- if (!plugin) {
- return $(this).data('ezdz', new $.ezdz(this, options));
- } if (plugin[options]) {
- return plugin[options].apply(plugin, Array.prototype.slice.call(args, 1));
- } else {
- $.error('Ezdz error - Method ' + options + ' does not exist.');
- }
- };
-}));
*
* This model action does not return, it simply does it's work then calls die();
*
- * Images are stored in various sizes in the media/images/{size} directories
- * which are created if they don't already exist.
- *
- * Image names consist of the following...
- *
- * {target table name}_{target table id}-{original name}_{timestamp}.{ext}
- *
- * {target table name} The name of the table were the gallery target is located
- * {target table id} The ID of the record in the target table associated with the gallery
- * {original name} The base original name of the file
- * {ext} The file extension related to the type of the image
+ * @param $actionData
*
+ * Echos JSON string as response and does not return
*/
public function modelAction ($actionData = false)
{
die();
}
-
+ // For each submitted file (usually only one)
foreach( $_FILES as $file ) {
// Is there a file of the right type with a temp file that exists
if (isset($file['name']) && is_file($file['tmp_name'])) {
- // Get new image using temporary file name
- $newImage = wp_get_image_editor($file['tmp_name']);
-
- // If we have a good image
- if ( ! is_wp_error( $newImage ) ) {
-
- // Get the desired file name and add a timestamp to it to ensure that it's unique
- $fInfo = pathinfo($file['name']);
- $newFilename = $refTable.'_'.$refDest.'-'.strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
-
- // Get image temp file name - Not currently using, but should be using to check for resizing sanity
- $size = $newImage->get_size();
-
- // Try to store the image using that file name in the 'original' directory
- $storedImage = $newImage->save( GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename );
-
- // Now resize the images using $sizeArray
- $sizes = $newImage->multi_resize($this->config['imageSizes']);
-
- // Finally, move the files to the various size directories and rename them back to the correct name
- while (list($k, $v) = each($this->config['imageSizes'])) {
-
- // Check if size directory needs to be made
- if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) {
- mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k);
- }
-
- // If there's an entry in the $sizes array, it means that the image resized to this size
- if (isset($sizes[$k])) {
- // Move resized file to desired direectory
- rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
- } else {
- // Image didn't resize to this size, probably because it was smaller than the destination size (silly WP Image Editor class) - so just use the original
- copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
- }
-
- }
-
- // Move the original to original directory
- if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original')) {
- mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original');
- }
- rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$newFilename);
-
- $file['newFileName'] = $newFilename;
-
- // Store image name in images table
- $sql = "
- INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images
- (
- name,
- file_name,
- descr,
- caption,
- status,
- position,
- ref_type,
- ref_dest
- )
- VALUES
- (
- '".$file['name']."',
- '".$file['newFileName']."',
- '',
- '',
- ".$this->config['status_numb']['Inactive'].",
- 99,
- $refType,
- $refDest
- );
- ";
- $this->wpdb->query($sql);
- $queryError = $this->wpdb->last_error;
-
- if ($queryError) {
- $file['error'] = true;
- $file['message'] = $queryError."\n".$sql;
- }
-
- // Get new ID and data from the new record
- $file['id'] = $this->wpdb->insert_id;
- $return['files'][] = $file;
-
- // Indicate that we actually stored an image
- $return['status'] = true;
+ // Store the image
+ $file = $this->storeImage($file, $refType, $refTable, $refDest);
- } else {
+ $return['files'][] = $file;
- // File was not uploaded or of the wrong type
- $file['message'] = 'Image file "'.$file['name'].'" was not uploaded or is not a valid image file!';
- $file['status'] = false;
+ // Indicate if we actually stored an image
+ $return['status'] = ($file != false);
- }
+ } else {
+
+ // File was not uploaded or of the wrong type
+ $file['message'] = 'Image file "'.$file['name'].'" was not uploaded or is not a valid image file!';
+ $file['status'] = false;
}
}
+ /*
+ * Store a single image file using a reference table to link to a table.
+ *
+ * Images are stored in various sizes in the media/images/{size} directories
+ * which are created if they don't already exist.
+ *
+ * Image names consist of the following...
+ *
+ * {target table name}_{target table id}-{original name}_{timestamp}.{ext}
+ *
+ * {target table name} The name of the table were the gallery target is located
+ * {target table id} The ID of the record in the target table associated with the gallery
+ * {original name} The base original name of the file
+ * {ext} The file extension related to the type of the image
+ *
+ * @param $file array Array containing uploaded file data
+ * @param $refType integer What this image is related to
+ * @param $refTable string Table name where the reference data for this image is stored
+ * @param $refDest integer Pointer to table entry this image is for
+ *
+ * @return array
+ *
+ */
+ public function storeImage ($file, $refType = false, $refTable = false, $refDest = false)
+ {
+
+ // If $file is just a URL to an image, the simulate the file array from a form submission
+ if (!is_array($file)) {
+ $file = array(
+ 'tmp_name' => $file,
+ 'name' => $file
+ );
+ }
+
+ // Get the desired file name and add a timestamp to it to ensure that it's unique
+ $fInfo = pathinfo($file['name']);
+
+ // Build new file name
+ if ($refType != false) {
+ $newFilename = $refTable.'_'.$refDest.'-'.strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
+ } else {
+ $newFilename = strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
+ }
+
+ // Get new image using temporary file name
+ $newImage = wp_get_image_editor($file['tmp_name']);
+
+ // If we have a good image
+ if ( ! is_wp_error( $newImage ) ) {
+
+ // Get image temp file name - Not currently using, but should be using to check for resizing sanity
+ $size = $newImage->get_size();
+
+ // Try to store the image using that file name in the 'original' directory
+ $storedImage = $newImage->save( GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename );
+
+ // Now resize the images using $sizeArray
+ $sizes = $newImage->multi_resize($this->config['imageSizes']);
+
+ // Finally, move the files to the various size directories and rename them back to the correct name
+ reset ($this->config['imageSizes']);
+ while (list($k, $v) = each($this->config['imageSizes'])) {
+
+ // Check if size directory needs to be made
+ if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) {
+ mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k);
+ }
+
+ // If there's an entry in the $sizes array, it means that the image resized to this size
+ if (isset($sizes[$k])) {
+ // Move resized file to desired direectory
+ rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
+ } else {
+ // Image didn't resize to this size, probably because it was smaller than the destination size (silly WP Image Editor class) - so just use the original
+ copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
+ }
+
+ }
+
+ // Move the original to original directory
+ if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original')) {
+ mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original');
+ }
+ rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$newFilename);
+
+ $file['newFileName'] = $newFilename;
+
+ // If using a reference tab,e, Store image name in images table
+ if ($refType != false) {
+ $sql = "
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images
+ (
+ name,
+ file_name,
+ descr,
+ caption,
+ status,
+ position,
+ ref_type,
+ ref_dest
+ )
+ VALUES
+ (
+ '".$file['name']."',
+ '".$file['newFileName']."',
+ '',
+ '',
+ ".$this->config['status_numb']['Inactive'].",
+ 99,
+ $refType,
+ $refDest
+ );
+ ";
+ $this->wpdb->query($sql);
+ $queryError = $this->wpdb->last_error;
+
+ if ($queryError) {
+ $file['error'] = true;
+ $file['message'] = $queryError."\n".$sql;
+ }
+
+ // Get new ID and data from the new record
+ $file['id'] = $this->wpdb->insert_id;
+
+ }
+
+ return $file;
+
+ // Otherwise we don't have a good image, so fail
+ } else {
+ return false;
+ }
+
+
+ }
+
}
?>
}
// Read in member/amenity cross-reference table
+ $numbAmenityMembers = 0;
if (!$failure) {
$sql = "
SELECT *
}
$membAmen[$x['member_id']][] = $x;
+ $numbAmenityMembers++;
}
}
}
}
// Read in member/credit card cross-reference table
+ $numbCcardMembers = 0;
if (!$failure) {
$sql = "
SELECT *
}
$membCcard[$x['member_id']][] = $x;
+ $numbCcardMembers++;
}
}
}
}
}
-
-
// Read in all cities
if (!$failure) {
$sql = "
}
}
-
-
// Read in all member photos for member image gallery
+ $numbImagesFound = 0;
if (!$failure) {
$sql = "
SELECT *
// If member entry hasn't been created yet, add it now
if (!isset($image[$x['member_id']])) {
- $image[$x['member_id']] = array();
+ $image[$x['member_id']] = array(
+ 'member_id' => $x['member_id'],
+ 'images' => array()
+ );
}
- $image[$x['member_id']][] = $x;
+ $image[$x['member_id']]['images'][] = $x;
+ $numbImagesFound++;
}
}
}
// Import Categories
$catTrans = array();
+ $numbCategories = 0;
while (list ($key, $val) = each ($category) ) {
+ $numbCategories++;
+
$res = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
array(
}
}
+ // Add logo to image array
+ if ($val['logo'] != '') {
+ // If member entry hasn't been created yet, add it now
+ if (!isset($image[$val['member_id']])) {
+ $image[$val['member_id']] = array(
+ 'member_id' => $val['member_id'],
+ 'images' => false
+ );
+ }
+ $image[$val['member_id']]['logo'] = $val['logo'];
+ }
+
+ // Update image list with new member IDs
+ if (isset($image[$val['member_id']])) {
+ $image[$val['member_id']]['new_memberinfo_id'] = $membID;
+ }
}
// If everything is OK, make data available to the template
if (!$failure) {
+
+ update_option( 'glm-member-db-import-imageurl', $dbImageURL);
+ update_option( 'glm-member-db-import-image', $image );
+
+ $templateData['numbCities'] = count($city);
+ $templateData['numbStates'] = count($state);
+ $templateData['numbRegions'] = count($region);
+ $templateData['numbMembers'] = count($member);
+ $templateData['numbCategories'] = count($catTrans);
+ $templateData['numbCategoryMembers'] = count($membCat);
+ $templateData['numbAmenities'] = count($amenity);
+ $templateData['numbAmenityMembers'] = $numbAmenityMembers;
+ $templateData['numbImagesFound'] = $numbImagesFound;
+ $templateData['numbCcards'] = count($ccard);
+ $templateData['numbCcardMembers'] = $numbCcardMembers;
+
+ // For testing only
$templateData['member'] = $member;
$templateData['defaultMemberType'] = $defaultMemberType;
$templateData['amenity'] = $amenity;
break;
+ case 'importImages':
+
+ require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
+ $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+ $refType = $this->config['ref_type_numb']['MemberInfo'];
+ $refTable = $this->config['ref_type_table'][$refType];
+
+ // Get image array stored in a WordPress option
+ $imageBaseURL = get_option( 'glm-member-db-import-imageurl', false );
+ $image = get_option( 'glm-member-db-import-image', false );
+
+ delete_option( 'glm-member-db-import-imageurl', false );
+ delete_option( 'glm-member-db-import-image', false );
+
+ // If we have image URLs
+ if ($image != false) {
+
+ // For each member
+ foreach ($image as $m) {
+
+ // Import member logo
+ if (isset($m['logo'])) {
+ $imageURL = $imageBaseURL.$m['logo'];
+ $res = $ImageUpload->storeImage ($imageURL);
+
+ // If we got a good new filename back, then it should be a good image store
+ if ($res['newFileName']) {
+
+ // Update the member record with the logo image name
+ $res = $this->wpdb->update(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'logo' => $res['newFileName']
+ ),
+ array( 'id' => $m['new_memberinfo_id'] ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+ // For each image in this member's gallery
+ if ($m['images']) {
+ foreach ($m['images'] as $i) {
+ $imageURL = $imageBaseURL.$i['image'];
+ $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $m['new_memberinfo_id']);
+ }
+ }
+
+ }
+
+ }
+
+ $requestedView = 'import/importImages.html';
+
default:
break;
{include file='admin/management/header.html'}
- <p>Note: Customers will not have access to this tab.</p>
-
<h2>Data Import</h2>
<p>
- This process export data from a legacy Gaslight Media Member DB database and imports that data into this plugin. It will only work with a Postgres database.
+ This process exports data from a Postgres legacy Gaslight Media Member DB database and imports that data into this plugin.
+ </p>
+ <p>
The process will include the following steps.
</p>
<ol>
- <li class="glm-ol-selected">Provide information on the legacy database from which we'll be extracting data.</li>
- <li>Test that database to make sure it's compatible with this process.</li>
- <li>Read the needed data from the legacy database.</li>
- <li>Review the extracted data to make sure it looks like the data you want to import.</li>
- <li>Import the extracted data into is plugin</li>
- <li>Review resulst</li>
+ <li class="glm-ol-selected">Provide legacy database information and import member data.</li>
+ <li>Import any images.</li>
+ <li>Review results</li>
</ol>
- <h3>Data Import Step 1</h3>
+ <h3>Data Import Step 1: Supply database access information.</h3>
{if isset($genError)}
<p>
<h3 class="glm-error">Oops!</h3>
<th>Base Original Image URL: </th>
<td>
<input class="glm-form-text-input-medium-long" type="text" name="dbImageURL" placeholder="(i.e. http://is0.gaslightmedia.com/mountpleasantwow/original/)" value="{if isset($dbImageURL)}{$dbImageURL.value}{/if}">
+ <br><span class="glm-notice">WARNING:</span> Do not point to original images. They may be too large to be processed. Instead point to the largest reasonable image size available.
{if isset($dbImageURL)}
<p class="glm-error">{$dbImageURL.problem}</p>
{/if}
</tr>
</table>
- <input type="submit" value="Select Member" class="button-primary">
+ <input type="submit" value="Continue" class="button-primary">
</form>
--- /dev/null
+{include file='admin/management/header.html'}
+
+ <h2>Data Import - Test Database</h2>
+ <ol>
+ <li>Provide legacy database information and import member data.</li>
+ <li>Import any images.</li>
+ <li class="glm-ol-selected">Review results</li>
+ </ol>
+
+
+ <h3>Data Import Step 3: Review Results.</h3>
+{if isset($genError)}
+ <p>
+ <h3 class="glm-error">Oops!</h3>
+ <p class="glm-error">{$genError}</p>
+ </p>
+{/if}
+
+ <h2>Process Complete</h2>
+ <p>
+ The data and image import process is complete. You should now have all member data and images imported.
+ <p>
+ <p>
+ You should now go to the "Member List" and make sure the data and images have been imported properly.
+ </p>
+
+{include file='admin/footer.html'}
{include file='admin/management/header.html'}
- <p>Note: Customers will not have access to this tab.</p>
-
<h2>Data Import - Test Database</h2>
<ol>
- <li>Provide information on the legacy database from which we'll be extracting data.</li>
- <li class="glm-ol-selected">Test database to make sure it's compatible with this process.</li>
- <li>Read the needed data from the legacy database.</li>
- <li>Review the extracted data to make sure it looks like the data you want to import.</li>
- <li>Import the extracted data into is plugin</li>
- <li>Review resulst</li>
+ <li>Provide legacy database information and import member data.</li>
+ <li class="glm-ol-selected">Import any images.</li>
+ <li>Review results</li>
</ol>
+ <h2>Data Import Results</h2>
+ <table class="glm-admin-table">
+ <tr><th>Cities:</th><td>{$numbCities}</td></tr>
+ <tr><th>States:</th><td>{$numbStates}</td></tr>
+ <tr><th>Regions:</th><td>{$numbRegions}</td></tr>
+ <tr><th>Members:</th><td>{$numbMembers}</td></tr>
+ <tr><th>Categories:</th><td>{$numbCategories}</td></tr>
+ <tr><th>Member Category Entires:</th><td>{$numbCategoryMembers}</td></tr>
+ <tr><th>Amenities:</th><td>{$numbAmenities}</td></tr>
+ <tr><th>Member Amenity Entries:</th><td>{$numbAmenityMembers}</td></tr>
+ <tr><th>Credit Card Types:</th><td>{$numbCcards}</td></tr>
+ <tr><th>Member Credit Card Entries:</th><td>{$numbCcardMembers}</td></tr>
+ <tr><th>Images Found:</th><td>{$numbImagesFound}</td></tr>
+ </table>
- <h3>Data Import Step 2</h3>
+ <h3>Data Import Step 2: Import images.</h3>
{if isset($genError)}
<p>
<h3 class="glm-error">Oops!</h3>
{/if}
<form action="{$thisURL}?page={$thisPage}" method="post" enctype="multipart/form-data">
<input type="hidden" name="glm_action" value="import">
- <input type="hidden" name="option" value="testDatabase">
-
- <table class="glm-admin-table">
-
- <!-- Debug Settings -->
-
- <tr>
- <th>Database Server: </th>
- <td>
- <input type="text" name="dbServer" placeholder="(complete host name or IP address)">
- </td>
- </tr>
- <tr>
- <th>Database Name: </th>
- <td>
- <input type="text" name="dbName" placeholder="(name of database}">
- </td>
- </tr>
- <tr>
- <th>Database User: </th>
- <td>
- <input type="text" name="dbUser" placeholder="(user with read access to this database)">
- </td>
- </tr>
- </table>
-
- <input type="submit" value="Select Member" class="button-primary">
-
+ <input type="hidden" name="option" value="importImages">
+ <p><span class="glm-notice">WARNING:</span> This process may take a very long time!<br>Do not interrupt or re-submit this page.</p>
+ <input type="submit" value="Continue" class="button-primary">
</form>