From fdf5a2f8ddea0b6c141e440cc86c1b079882cada Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 13 May 2016 14:22:03 -0400 Subject: [PATCH] Add b64image to data abstract --- config/plugin.ini | 5 +- controllers/admin.php | 60 +++++----- index.php | 2 +- lib/GlmDataAbstract/DataAbstract.php | 168 +++++++++++++++++++++++---- 4 files changed, 177 insertions(+), 58 deletions(-) diff --git a/config/plugin.ini b/config/plugin.ini index 9ff60f8c..826ccf99 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -7,10 +7,7 @@ ; Any sizes added to this section will used by the Data Abstract to generate that size when images are uploaded. ; Crop value: ; 1. If false (default), images will not be cropped. -; 2. If an array in the form of array( x_crop_position, y_crop_position ): -; x_crop_position accepts 'left' 'center', or 'right'. -; y_crop_position accepts 'top', 'center', or 'bottom'. -; Images will be cropped to the specified dimensions within the defined crop area. +; 2. If true, images will be cropped to the specified width/height aspect ratio. [imageSizes] diff --git a/controllers/admin.php b/controllers/admin.php index 48b433ea..ba4522f8 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -167,12 +167,12 @@ class glmMembersAdmin extends GlmPluginSupport ) ); - + // add shortcode metabox add_action('add_meta_boxes', array( $this, 'glmMembersShortcode' - ) ); + ) ); // Add AJAX image upload action add_action( 'wp_ajax_glm_members_admin_ajax', @@ -219,7 +219,7 @@ class glmMembersAdmin extends GlmPluginSupport * Create new pages containing the member DB shortcodes * @return void */ - public function createPages($requiredPages) + public function createPages($requiredPages) { foreach($requiredPages as $requiredPage => $requiredPageInfo) { $trimmedName = GLM_MEMBERS_PLUGIN_OPTION_PREFIX.$requiredPageInfo['optionSuffix']; @@ -438,7 +438,7 @@ class glmMembersAdmin extends GlmPluginSupport // Jquery DatePicker wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); - + wp_enqueue_media(); @@ -626,11 +626,11 @@ class glmMembersAdmin extends GlmPluginSupport } } public function glmMembersShortcode(){ - + // load shortcodeBuilder.js when the shortcode function has been fired add_action('admin_print_styles-post.php', 'custom_js_css'); add_action('admin_print_styles-post-new.php', 'custom_js_css'); - + // tried calling the adminScripts function here but it throws js errors in the console wp_enqueue_script('jquery', false, array(), false, true); wp_enqueue_script('jquery-style', false, array(), false, true); @@ -642,28 +642,28 @@ class glmMembersAdmin extends GlmPluginSupport // Jquery DatePicker wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); - + function custom_js_css() { - + wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true); } - - add_meta_box("shortcode_builder", - "Shortcode Builder", - array($this,'shortcode_builder_markup'), + + add_meta_box("shortcode_builder", + "Shortcode Builder", + array($this,'shortcode_builder_markup'), "page", 'normal', 'high' ); - - } + + } // // metabox content public function shortcode_builder_markup(){ - - require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'); + + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'); $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes']; $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes']; - + $glmcat = new GlmDataCategories($this->wpdb, $this->wpconfig); - $list = $glmcat->getList(); + $list = $glmcat->getList(); // get the each addOn slugs to pass to the config array later $addOns = $this->config['addOns']; foreach($addOns as $addOn){ @@ -683,15 +683,15 @@ class glmMembersAdmin extends GlmPluginSupport $shortCodes[] = $shortCode; } } - } + } // /* // * HTML Markup for the shortodes // */ // if(file_exists(GLM_MEMBERS_EVENTS_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){ // include GLM_MEMBERS_EVENTS_PLUGIN_PATH . "/setup/shortcodeBuilder.php"; // } -// -// +// +// //dropdown for shortcode names echo '
'; echo ''; - + // /* // * Member DB Shortcode Attributes // */ -// +// //dropdown for categories echo ''; - - // show list options 'scb' = shortcode builder acronym + + // show list options 'scb' = shortcode builder acronym echo '
'; echo ''; echo ''; @@ -728,7 +728,7 @@ class glmMembersAdmin extends GlmPluginSupport if($value != ''){ echo ''; } - } + } echo '
'; // show detail options @@ -739,9 +739,9 @@ class glmMembersAdmin extends GlmPluginSupport if($value != ''){ echo ''; } - } + } echo '
'; - + // packaging addOn mark up if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){ include GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php"; @@ -752,7 +752,7 @@ class glmMembersAdmin extends GlmPluginSupport echo ''; echo ''; - + } /** @@ -879,7 +879,7 @@ class glmMembersAdmin extends GlmPluginSupport $this->createPages($a['requiredPages']); } } - + // Loop till we have a final action $loopCheck = 0; $loopTracking = "

Menu: $menuItem, Action = $action

"; diff --git a/index.php b/index.php index 1e4150f3..05b8e208 100644 --- a/index.php +++ b/index.php @@ -320,7 +320,7 @@ if (count($config['addOns']) > 0) { if (isset($a['config'])) { $config = array_merge_recursive($config, $a['config']); } - + // If the add-on has additional config parameters in a plugin.ini file $iniFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.'/'.$a['slug'].'/config/plugin.ini'; if (isset($iniFile)) { diff --git a/lib/GlmDataAbstract/DataAbstract.php b/lib/GlmDataAbstract/DataAbstract.php index 58b7e419..31b18aa4 100755 --- a/lib/GlmDataAbstract/DataAbstract.php +++ b/lib/GlmDataAbstract/DataAbstract.php @@ -94,6 +94,7 @@ abstract class GlmDataAbstract 'phone', 'file', 'image', + 'b64image', 'latitude', 'longitude' ); @@ -912,9 +913,14 @@ abstract class GlmDataAbstract // Check for a list data if (!isset($f['list']) || !is_array($f['list'])) { - - echo "Field '".$f['name']."' is type list but does not have supplied 'list' data."; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "Field '".$f['name']."' is type list but does not have supplied 'list' data.", + 'Alert', + '' + ); + } + return false; } // Build list array @@ -970,9 +976,14 @@ abstract class GlmDataAbstract // Check for a list data if (!isset($f['list']) || !is_array($f['list'])) { - - echo "Field '".$f['name']."' is type list but does not have supplied 'list' data."; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "Field '".$f['name']."' is type list but does not have supplied 'list' data.", + 'Alert', + '' + ); + } + return false; } // Build list array @@ -1076,8 +1087,14 @@ abstract class GlmDataAbstract { // Check for a bitmap data if (!isset($f['bitmap']) || !is_array($f['bitmap'])) { - echo "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data."; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data.", + 'Alert', + '' + ); + } + return false; } // Build bitmap array @@ -1115,8 +1132,14 @@ abstract class GlmDataAbstract // Check for a bitmap data if (!isset($f['bitmap']) || !is_array($f['bitmap'])) { - echo "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data."; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data.", + 'Alert', + '' + ); + } + return false; } // If this is setup for a new entry, then just use default @@ -1211,8 +1234,14 @@ abstract class GlmDataAbstract $filter = FILTER_SANITIZE_STRING; if (isset($f['filter'])) { if (!is_numeric($f['filter'])) { - echo "

 

ERROR: Supplied value for option 'filter' in fields array not a defined filter for PHP filter_input();"; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "

 

ERROR: Supplied value for option 'filter' in fields array not a defined filter for PHP filter_input();", + 'Alert', + '' + ); + } + return false; } $filter = $f['filter']; @@ -1220,8 +1249,14 @@ abstract class GlmDataAbstract $filter_options = 0; //FILTER_FLAG_NO_ENCODE_QUOTES; if (isset($f['filter_options'])) { if (!is_numeric($f['filter_options']) && !is_array($f['filter_options'])) { - echo "

 

ERROR: Supplied value for 'filter_options' is not valid;"; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "

 

ERROR: Supplied value for 'filter_options' is not valid;", + 'Alert', + '' + ); + } + return false; } $filter_options = $f['filter_options']; } @@ -2461,6 +2496,64 @@ abstract class GlmDataAbstract return "'".addslashes($in)."'"; } + /* + * Base64 Image Field Processing (for inline images) + */ + function b64imageField($f) + { + return 'T.'.$f['field']; + } + function b64imageOptions($f) + { + return false; + } + function b64imageOutput($f, $d) + { + return $d; + } + function b64imageInput($as, $f, $id, $idfield, $op) + { + + $new = false; + $currentImage = ''; + + // Get the current image data + $sql = "SELECT $as + FROM $this->table + WHERE $idfield = $id;"; + $d = $this->wpdb->get_row($sql, ARRAY_A); + $b64image = $d[$as]; + + // Check if we have a new image being submitted + if (isset($_FILES[$as.'_new']) && is_array($_FILES[$as.'_new']) && $_FILES[$as.'_new']['tmp_name'] != '') { + + // Get the size of the uploaded file + $imageSize = filesize($_FILES[$as.'_new']['tmp_name']); + + // Set absolute max image size to 10K + if ($r['maxSize'] > 10000) { + $r['maxSize'] == 10; + } + + // If it's bigger than the max image size ($fileSize is in Bytes + if ($imgeSize > ($max * 1000) || $imageSize > 10000) { + $this->inputFieldStatus = false; + $this->inputErrorReason = 'Image uploaded is '.intval($imageSize/1000).' kB. The maximum image size that may be submitted for this image is '.$f['maxSize'].' kB.'; + return $in; + } + + // Get new image using temporary file name + $b64image = base64_encode(file_get_contents($_FILES[$as.'_new']['tmp_name'])); + + } + + return $b64image; + } + function b64imageStore($in, $f) + { + return $in; + } + /* * File Field Processing */ @@ -2840,8 +2933,13 @@ abstract class GlmDataAbstract // Check that we have a fields list if (!is_array($this->fields) || count($this->fields) == 0) { - echo "ALERT: Empty Fields List in data abstract buildFieldsList()! Likely programming error."; - return false; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "ALERT: Empty Fields List in data abstract buildFieldsList()! Likely programming error.", + 'Alert', + 'Member Types Data' + ); + } } // For each possible field @@ -2855,8 +2953,14 @@ abstract class GlmDataAbstract // Check for good field type if (!in_array($v['type'], $this->knownFieldTypes)) { - echo "CONFIGURATION ERROR: Unknown field type - ".$v['type']; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "CONFIGURATION ERROR: Unknown field type - ".$v['type'], + 'Alert', + '' + ); + } + return false; } // Call field processing function based on field tye @@ -2940,8 +3044,14 @@ abstract class GlmDataAbstract // Check for good field type if (!in_array($type, $this->knownFieldTypes)) { - echo "CONFIGURATION ERROR: Unknown field type - ".$v['type']; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "CONFIGURATION ERROR: Unknown field type - ".$v['type'], + 'Alert', + '' + ); + } + return false; } // Check for "as" output field name @@ -3018,8 +3128,14 @@ abstract class GlmDataAbstract // Check for good field type if (!in_array($v['type'], $this->knownFieldTypes)) { - echo "CONFIGURATION ERROR: Unknown field type - ".$v['type']; - exit; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "CONFIGURATION ERROR: Unknown field type - ".$v['type'], + 'Alert', + '' + ); + } + return false; } // Check for "as" output field name @@ -3246,7 +3362,13 @@ abstract class GlmDataAbstract { if ($id-0 == 0) { - // echo "DataAbstract.php - getEntry() called with invalid ID"; + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice( + "DataAbstract.php - getEntry() called with invalid ID", + 'Alert', + '' + ); + } return false; } -- 2.17.1