From: Chuck Scott Date: Tue, 14 Jul 2015 14:34:11 +0000 (-0400) Subject: Added Image Gallery Clone feature X-Git-Tag: v1.0.0^2~1^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=caa786d6c381fdfb6b533302161f743a1b87e128;p=WP-Plugins%2Fglm-member-db.git Added Image Gallery Clone feature --- diff --git a/classes/data/dataImages.php b/classes/data/dataImages.php index 1b334769..e40e06ed 100644 --- a/classes/data/dataImages.php +++ b/classes/data/dataImages.php @@ -115,6 +115,14 @@ class GlmDataImages extends GlmDataAbstract 'use' => 'a' ), + // Original file name + 'name' => array( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + // Status 'status' => array ( 'field' => 'status', @@ -276,18 +284,24 @@ class GlmDataImages extends GlmDataAbstract // Update image entries with new sort order; $pos = 0; foreach($order as $i) { - $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET position = $pos WHERE id = $i;"; - $this->wpdb->query($sql); - $pos++; - $queryError = $this->wpdb->last_error; - if ($queryError) { + // Do sanity check on image ID + if (($i-0) > 0) { - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice("  Error setting position order for images.
$queryError", 'Alert'); - } + // Set the position for this image + $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET position = $pos WHERE id = $i;"; + $this->wpdb->query($sql); + $pos++; + + $queryError = $this->wpdb->last_error; + if ($queryError) { - return false; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  Error setting position order for images.
$queryError
$sql", 'Alert'); + } + + return false; + } } } @@ -311,62 +325,69 @@ class GlmDataImages extends GlmDataAbstract // Re-order image gallery images $this->galleryPositionOrder($refType, $refID, $orderField); - // Update text for title and descriptions - reset($_REQUEST['galleryImage_caption']); - while (list($k, $v) = each($_REQUEST['galleryImage_caption'])) { - $id = ($k -0); + // If any image gallery data is submitted + if (isset($_REQUEST['galleryImage_caption']) + && is_array($_REQUEST['galleryImage_caption']) + && count($_REQUEST['galleryImage_caption']) > 0) { - // Sanitize input - $caption = sanitize_text_field( $_REQUEST['galleryImage_caption'][$k] ); - $descr = sanitize_text_field( $_REQUEST['galleryImage_descr'][$k] ); + // Update text for title and descriptions + reset($_REQUEST['galleryImage_caption']); + while (list($k, $v) = each($_REQUEST['galleryImage_caption'])) { + $id = ($k -0); - // Update data for this image - $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET caption = '$caption', descr = '$descr' WHERE id = $id;"; - $this->wpdb->query($sql); + // Sanitize input + $caption = sanitize_text_field( $_REQUEST['galleryImage_caption'][$k] ); + $descr = sanitize_text_field( $_REQUEST['galleryImage_descr'][$k] ); - } + // Update data for this image + $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET caption = '$caption', descr = '$descr' WHERE id = $id;"; + $this->wpdb->query($sql); - // Check for an image deletion - if (isset($_REQUEST['galleryImage_delete']) && count($_REQUEST['galleryImage_delete']) > 0) { + } - // For each delete selected - reset($_REQUEST['galleryImage_delete']); - while (list($k, $v) = each($_REQUEST['galleryImage_delete'])) { - $id = ($k -0); + // Check for an image deletion + if (isset($_REQUEST['galleryImage_delete']) && count($_REQUEST['galleryImage_delete']) > 0) { - // If a valid key and delete request is in fact set - if ($id > 0 && $v == 'on') { + // For each delete selected + reset($_REQUEST['galleryImage_delete']); + while (list($k, $v) = each($_REQUEST['galleryImage_delete'])) { + $id = ($k -0); - // Get the data for this image - $sql = "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images WHERE id = $id;"; - $imgData = $this->wpdb->get_row($sql, ARRAY_A); + // If a valid key and delete request is in fact set + if ($id > 0 && $v == 'on') { - // Do we have data? - if ($imgData != null && trim($imgData['file_name']) != '') { + // Get the data for this image + $sql = "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images WHERE id = $id;"; + $imgData = $this->wpdb->get_row($sql, ARRAY_A); - // Delete the image from the gallery - $sql = "DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images WHERE id = $id;"; - $this->wpdb->query($sql); + // Do we have data? + if ($imgData != null && trim($imgData['file_name']) != '') { - // Also delete all copies of the image - reset($this->config['imageSizes']); - while (list($k, $v) = each($this->config['imageSizes'])) { + // Delete the image from the gallery + $sql = "DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images WHERE id = $id;"; + $this->wpdb->query($sql); - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { - glmMembersAdmin::addNotice("      Deleting size $k.", 'Process'); - } + // Also delete all copies of the image + reset($this->config['imageSizes']); + while (list($k, $v) = each($this->config['imageSizes'])) { - // Delete each image size - unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$imgData['file_name']); + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice("      Deleting size $k.", 'Process'); + } - } + // Delete each image size + unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$imgData['file_name']); - // Also delete the original - unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$imgData['file_name']); + } + + // Also delete the original + unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$imgData['file_name']); + } } } } + } // Get updated image gallery @@ -375,6 +396,91 @@ class GlmDataImages extends GlmDataAbstract } + + /* + * Clone an image gallery + * + * Makes a copy of all images in a gallery and assigns them to another refType and refID + * + * @param int $refTypeSrc Source Reference Type + * @param int $refIDSrc Source Reference entry ID + * @param int $refTypeDst Destination Reference Type + * @param int $refIDDst Destination Reference entry ID + * @param string $orderField Name of SUBMIT field containing sort order. + * + * @return boolean True if successful + * + */ + public function galleryImageDataClone($refTypeSrc, $refIDSrc, $refTypeDst, $refIDDst) + { + + // Get Source Image Gallery + $imageGallerySrc = $this->getGallery($refTypeSrc, $refIDSrc); + + // Get the destination target table name + $dstTable = $this->config['ref_type_table'][$refTypeDst]; + + // Get Image sizes and add original + $sizes = $this->config['imageSizes']; + $sizes['original'] = array(); + + // If we have an image gallery with any images + if ($imageGallerySrc !== false + && is_array($imageGallerySrc) + && count($imageGallerySrc) > 0) { + + // for each gallery image + foreach ($imageGallerySrc as $i) { + + $srcName = $i['file_name']; + + // Strip the source table name and ID from the file name (part after first '-') + $dstName = $dstTable.'_'.$refIDDst.'-'.substr(strchr($i['file_name'], '-'), 1); + + // For each image size + reset($sizes); + while (list($k, $v) = each($sizes)) { + + // Copy src file to dst file for this size + copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$srcName, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$dstName); + + } + + // Add this image to the images table + // 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 + ( + '".$i['name']."', + '$dstName', + '".addslashes($i['descr'])."', + '".addslashes($i['caption'])."', + ".$i['status']['value'].", + ".$i['position'].", + $refTypeDst, + $refIDDst + ); + "; + $this->wpdb->query($sql); + // $queryError = $this->wpdb->last_error; + + } + + } + + } + } ?> \ No newline at end of file diff --git a/classes/glmMemberInfoClone.php b/classes/glmMemberInfoClone.php index 5531ba0a..9c909fb2 100644 --- a/classes/glmMemberInfoClone.php +++ b/classes/glmMemberInfoClone.php @@ -105,6 +105,17 @@ class GlmMemberInfoClone $this->wpdb->query($sql); + // Load image gallery class + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php'); + $Images = new GlmDataImages($this->wpdb, $this->config); + + // Get the refType for the member_info table and use if for both src and dst + $refType = $this->config['ref_type_numb']['MemberInfo']; + + // Clone the image gallery + $Images->galleryImageDataClone($refType, $id, $refType, $newID); + + } return $newID; diff --git a/lib/GlmDataAbstract/DataAbstract.php b/lib/GlmDataAbstract/DataAbstract.php index a0e26ca0..6fb551e0 100755 --- a/lib/GlmDataAbstract/DataAbstract.php +++ b/lib/GlmDataAbstract/DataAbstract.php @@ -2353,8 +2353,11 @@ abstract class GlmDataAbstract } } - // Remove original -// unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$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); $current_img = $newFilename; diff --git a/misc/smarty/templates_c/081a36d97cdf30d438a1e104c26a275acc180da0.file.index.html.php b/misc/smarty/templates_c/081a36d97cdf30d438a1e104c26a275acc180da0.file.index.html.php index f2747bd7..5c0c5c32 100644 --- a/misc/smarty/templates_c/081a36d97cdf30d438a1e104c26a275acc180da0.file.index.html.php +++ b/misc/smarty/templates_c/081a36d97cdf30d438a1e104c26a275acc180da0.file.index.html.php @@ -1,4 +1,4 @@ - decodeProperties(array ( @@ -7,7 +7,7 @@ $_valid = $_smarty_tpl->decodeProperties(array ( '081a36d97cdf30d438a1e104c26a275acc180da0' => array ( 0 => '/var/www/server/wordpress/wp-content/plugins/glm-member-db/views/admin/members/index.html', - 1 => 1434727132, + 1 => 1435675689, 2 => 'file', ), ), diff --git a/misc/smarty/templates_c/47fb9b803e7138d215645f3c977b0b1dc2a9e718.file.index.html.php b/misc/smarty/templates_c/47fb9b803e7138d215645f3c977b0b1dc2a9e718.file.index.html.php index 1a982780..fff30a1a 100644 --- a/misc/smarty/templates_c/47fb9b803e7138d215645f3c977b0b1dc2a9e718.file.index.html.php +++ b/misc/smarty/templates_c/47fb9b803e7138d215645f3c977b0b1dc2a9e718.file.index.html.php @@ -1,4 +1,4 @@ - decodeProperties(array ( @@ -7,7 +7,7 @@ $_valid = $_smarty_tpl->decodeProperties(array ( '47fb9b803e7138d215645f3c977b0b1dc2a9e718' => array ( 0 => '/var/www/server/wordpress/wp-content/plugins/glm-member-db/views/admin/configure/index.html', - 1 => 1434554103, + 1 => 1435675689, 2 => 'file', ), ), diff --git a/models/admin/ajax/imageUpload.php b/models/admin/ajax/imageUpload.php index bcba5dd1..d765e3ed 100644 --- a/models/admin/ajax/imageUpload.php +++ b/models/admin/ajax/imageUpload.php @@ -65,35 +65,22 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages /* * Perform Model Action * - * This method does the work for this model and returns any resulting data + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. * - * @return array Status and data array + * This model action does not return, it simply does it's work then calls die(); * - * 'status' + * Images are stored in various sizes in the media/images/{size} directories + * which are created if they don't already exist. * - * True if successfull and false if there was a fatal failure. + * Image names consist of the following... * - * 'menuItemRedirect' + * {target table name}_{target table id}-{original name}_{timestamp}.{ext} * - * If not false, provides a menu item the controller should - * execute after this one. Normally if this is used, there would also be a - * modelRedirect value supplied as well. - * - * 'modelRedirect' - * - * If not false, provides an action the controller should execute after - * this one. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. + * {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 * */ public function modelAction ($actionData = false) @@ -152,7 +139,7 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages // Get the desired file name and add a timestamp to it to ensure that it's unique $fInfo = pathinfo($file['name']); - $newFilename = strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']); + $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(); diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index 286afd7c..64840440 100644 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -263,7 +263,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo // Clone the current member info $memberInfoID = $CloneMemberInfo->cloneMemberInfo($memberInfoID); - $memberInfo = $this->editEntry($memberInfoID); +// $memberInfo = $this->editEntry($memberInfoID); // Default is to display the currently selected member information record in a form for updates default: @@ -495,6 +495,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo 'haveCategories' => $haveCategories, 'categories' => $categories, 'categoryMemberInfo' => $categoryMemberInfo, + 'haveImageGallery' => $haveImageGallery, 'imageGallery' => $imageGallery, 'noActive' => $noActive, 'time' => time() diff --git a/views/admin/member/memberInfo.html b/views/admin/member/memberInfo.html index b2186c3f..03fab00f 100644 --- a/views/admin/member/memberInfo.html +++ b/views/admin/member/memberInfo.html @@ -367,7 +367,7 @@ Image Gallery + value="{if $haveImageGallery}{foreach $imageGallery as $i name=ig}{if $i.file_name}{$i.id}{if not $smarty.foreach.ig.last},{/if}{/if}{/foreach}{/if}" />
    - {foreach $imageGallery as $i} - {if $i.file_name} + {if $haveImageGallery} + {foreach $imageGallery as $i} + {if $i.file_name}
  • @@ -458,9 +459,11 @@
    - {/if} + {/if} + - {/foreach} + {/foreach} + {/if}