'use' => 'a'
),
+ // Original file name
+ 'name' => array(
+ 'field' => 'name',
+ 'type' => 'text',
+ 'required' => true,
+ 'use' => 'a'
+ ),
+
// Status
'status' => array (
'field' => 'status',
// 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("<b> Error setting position order for images.</b><br>$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("<b> Error setting position order for images.</b><br>$queryError<br>$sql", 'Alert');
+ }
+
+ return false;
+ }
}
}
// 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
}
+
+ /*
+ * 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
/*
* 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)
// 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();