From 980cfcdcca6e50c0f6856dbfc4eec3f369aa5615 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 23 Sep 2015 13:40:51 -0400 Subject: [PATCH] Added image import --- js/imageUpload/OLD_SAVE_imageUpload.js | 88 ---- .../.editorconfig | 11 - .../.gitignore | 5 - .../.travis.yml | 8 - js/jqueryDragAndDrop-ForReferenceOnly/README | 70 --- .../jquery.ezdz.css | 126 ------ .../jquery.ezdz.js | 422 ------------------ models/admin/ajax/imageUpload.php | 251 ++++++----- models/admin/management/import.php | 109 ++++- views/admin/management/import.html | 20 +- .../admin/management/import/importImages.html | 27 ++ .../admin/management/import/readDatabase.html | 58 +-- 12 files changed, 309 insertions(+), 886 deletions(-) delete mode 100644 js/imageUpload/OLD_SAVE_imageUpload.js delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/.editorconfig delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/.gitignore delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/.travis.yml delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/README delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.css delete mode 100644 js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.js create mode 100644 views/admin/management/import/importImages.html diff --git a/js/imageUpload/OLD_SAVE_imageUpload.js b/js/imageUpload/OLD_SAVE_imageUpload.js deleted file mode 100644 index 61d26885..00000000 --- a/js/imageUpload/OLD_SAVE_imageUpload.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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); - } - - }); - -}); diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/.editorconfig b/js/jqueryDragAndDrop-ForReferenceOnly/.editorconfig deleted file mode 100644 index ad446fa0..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -; 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 diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/.gitignore b/js/jqueryDragAndDrop-ForReferenceOnly/.gitignore deleted file mode 100644 index 14fe67f0..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules -tmp - -.DS_Store -._* \ No newline at end of file diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/.travis.yml b/js/jqueryDragAndDrop-ForReferenceOnly/.travis.yml deleted file mode 100644 index 7f22ed18..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: node_js -node_js: - - 0.10 - -before_script: - - npm install -g grunt-cli - -script: "grunt test" diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/README b/js/jqueryDragAndDrop-ForReferenceOnly/README deleted file mode 100644 index f3ac9e54..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/README +++ /dev/null @@ -1,70 +0,0 @@ -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 - - - - - -in the body section, simply add normal input tag, the plugin will automatically convert it into dropzone. - - - -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; -} diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.css b/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.css deleted file mode 100644 index b2607eb3..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.css +++ /dev/null @@ -1,126 +0,0 @@ -/* ---------------------------------------------------------------------------- -// 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 diff --git a/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.js b/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.js deleted file mode 100644 index e30ab877..00000000 --- a/js/jqueryDragAndDrop-ForReferenceOnly/jquery.ezdz.js +++ /dev/null @@ -1,422 +0,0 @@ -/* ---------------------------------------------------------------------------- -// 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 = $('
') - - .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('
' + settings.text + '
'); - - $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 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 = $("
    "); - $image_wrapper.addClass("image-g"); - var i; - for (i=0;i").append(img_obj); - $image_wrapper.append($image_item); - } - $ezdz.find('div').html($image_wrapper.fadeIn()); - } else { - $ezdz.find('div').html('' + formatted + ''); - } - - $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('' + formatted + ''); - - 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.'); - } - }; -})); diff --git a/models/admin/ajax/imageUpload.php b/models/admin/ajax/imageUpload.php index a5d2d0ef..0c3566a7 100644 --- a/models/admin/ajax/imageUpload.php +++ b/models/admin/ajax/imageUpload.php @@ -70,18 +70,9 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages * * 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) { @@ -125,105 +116,25 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages 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; } @@ -235,5 +146,141 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages } + /* + * 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; + } + + + } + } ?> diff --git a/models/admin/management/import.php b/models/admin/management/import.php index db7b9591..b098ac50 100644 --- a/models/admin/management/import.php +++ b/models/admin/management/import.php @@ -274,6 +274,7 @@ class GlmMembersAdmin_management_import } // Read in member/amenity cross-reference table + $numbAmenityMembers = 0; if (!$failure) { $sql = " SELECT * @@ -307,6 +308,7 @@ class GlmMembersAdmin_management_import } $membAmen[$x['member_id']][] = $x; + $numbAmenityMembers++; } } } @@ -346,6 +348,7 @@ class GlmMembersAdmin_management_import } // Read in member/credit card cross-reference table + $numbCcardMembers = 0; if (!$failure) { $sql = " SELECT * @@ -379,6 +382,7 @@ class GlmMembersAdmin_management_import } $membCcard[$x['member_id']][] = $x; + $numbCcardMembers++; } } } @@ -482,8 +486,6 @@ class GlmMembersAdmin_management_import } } - - // Read in all cities if (!$failure) { $sql = " @@ -585,9 +587,8 @@ class GlmMembersAdmin_management_import } } - - // Read in all member photos for member image gallery + $numbImagesFound = 0; if (!$failure) { $sql = " SELECT * @@ -617,10 +618,14 @@ class GlmMembersAdmin_management_import // 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++; } } } @@ -728,8 +733,11 @@ class GlmMembersAdmin_management_import // Import Categories $catTrans = array(); + $numbCategories = 0; while (list ($key, $val) = each ($category) ) { + $numbCategories++; + $res = $this->wpdb->insert( GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories', array( @@ -954,6 +962,22 @@ class GlmMembersAdmin_management_import } } + // 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; + } } @@ -963,6 +987,23 @@ class GlmMembersAdmin_management_import // 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; @@ -994,6 +1035,62 @@ class GlmMembersAdmin_management_import 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; diff --git a/views/admin/management/import.html b/views/admin/management/import.html index 6fda5793..84ef6414 100644 --- a/views/admin/management/import.html +++ b/views/admin/management/import.html @@ -1,23 +1,20 @@ {include file='admin/management/header.html'} -

    Note: Customers will not have access to this tab.

    -

    Data Import

    - 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. +

    +

    The process will include the following steps.

      -
    1. Provide information on the legacy database from which we'll be extracting data.
    2. -
    3. Test that database to make sure it's compatible with this process.
    4. -
    5. Read the needed data from the legacy database.
    6. -
    7. Review the extracted data to make sure it looks like the data you want to import.
    8. -
    9. Import the extracted data into is plugin
    10. -
    11. Review resulst
    12. +
    13. Provide legacy database information and import member data.
    14. +
    15. Import any images.
    16. +
    17. Review results
    -

    Data Import Step 1

    +

    Data Import Step 1: Supply database access information.

    {if isset($genError)}

    Oops!

    @@ -72,6 +69,7 @@ Base Original Image URL: +
    WARNING: 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)}

    {$dbImageURL.problem}

    {/if} @@ -87,7 +85,7 @@ - + diff --git a/views/admin/management/import/importImages.html b/views/admin/management/import/importImages.html new file mode 100644 index 00000000..6dc7faa5 --- /dev/null +++ b/views/admin/management/import/importImages.html @@ -0,0 +1,27 @@ +{include file='admin/management/header.html'} + +

    Data Import - Test Database

    +
      +
    1. Provide legacy database information and import member data.
    2. +
    3. Import any images.
    4. +
    5. Review results
    6. +
    + + +

    Data Import Step 3: Review Results.

    +{if isset($genError)} +

    +

    Oops!

    +

    {$genError}

    +

    +{/if} + +

    Process Complete

    +

    + The data and image import process is complete. You should now have all member data and images imported. +

    +

    + You should now go to the "Member List" and make sure the data and images have been imported properly. +

    + +{include file='admin/footer.html'} diff --git a/views/admin/management/import/readDatabase.html b/views/admin/management/import/readDatabase.html index 2f3b8dbc..e3dc7788 100644 --- a/views/admin/management/import/readDatabase.html +++ b/views/admin/management/import/readDatabase.html @@ -1,19 +1,28 @@ {include file='admin/management/header.html'} -

    Note: Customers will not have access to this tab.

    -

    Data Import - Test Database

      -
    1. Provide information on the legacy database from which we'll be extracting data.
    2. -
    3. Test database to make sure it's compatible with this process.
    4. -
    5. Read the needed data from the legacy database.
    6. -
    7. Review the extracted data to make sure it looks like the data you want to import.
    8. -
    9. Import the extracted data into is plugin
    10. -
    11. Review resulst
    12. +
    13. Provide legacy database information and import member data.
    14. +
    15. Import any images.
    16. +
    17. Review results
    +

    Data Import Results

    + + + + + + + + + + + + +
    Cities:{$numbCities}
    States:{$numbStates}
    Regions:{$numbRegions}
    Members:{$numbMembers}
    Categories:{$numbCategories}
    Member Category Entires:{$numbCategoryMembers}
    Amenities:{$numbAmenities}
    Member Amenity Entries:{$numbAmenityMembers}
    Credit Card Types:{$numbCcards}
    Member Credit Card Entries:{$numbCcardMembers}
    Images Found:{$numbImagesFound}
    -

    Data Import Step 2

    +

    Data Import Step 2: Import images.

    {if isset($genError)}

    Oops!

    @@ -22,34 +31,9 @@ {/if}
    - - - - - - - - - - - - - - - - - - -
    Database Server: - -
    Database Name: - -
    Database User: - -
    - - - + +

    WARNING: This process may take a very long time!
    Do not interrupt or re-submit this page.

    +
    -- 2.17.1