Add b64image to data abstract
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 13 May 2016 18:22:03 +0000 (14:22 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 13 May 2016 18:22:03 +0000 (14:22 -0400)
config/plugin.ini
controllers/admin.php
index.php
lib/GlmDataAbstract/DataAbstract.php

index 9ff60f8..826ccf9 100644 (file)
@@ -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]
 
index 48b433e..ba4522f 100644 (file)
@@ -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 '<div id="shortcodeBuilder">';
             echo '<select id="shortcodeDropdown">
@@ -700,11 +700,11 @@ class glmMembersAdmin extends GlmPluginSupport
                 echo '<option value = "' . $code . '">' . $code . '</option>';
             }
             echo '</select>';
-        
+
 //            /*
 //             * Member DB Shortcode Attributes
 //             */
-//            
+//
             //dropdown for categories
             echo '<select id="category-scDropdown">';
             echo '<option value=""> Select Category </option>';
@@ -719,8 +719,8 @@ class glmMembersAdmin extends GlmPluginSupport
             <option selected="selected" value="False"> False </option>
             <option value = "True"> True </option>';
             echo '</select>';
-            
-            // show list options 'scb' = shortcode builder acronym 
+
+            // show list options 'scb' = shortcode builder acronym
             echo '<div id="showList" title="List Options">';
             echo '<label><input class="listBox" type="checkbox" name="list-scb" value="all">All</label>';
             echo '<label><input class="listBox" type="checkbox" name="list-scb" value="none">None</label>';
@@ -728,7 +728,7 @@ class glmMembersAdmin extends GlmPluginSupport
                 if($value != ''){
                     echo '<label><input class="showLists" type="checkbox" name="listBox" value='. $key . '>' . $key .'</label>';
                 }
-            }           
+            }
             echo '</div>';
 
             // show detail options
@@ -739,9 +739,9 @@ class glmMembersAdmin extends GlmPluginSupport
                 if($value != ''){
                     echo '<label><input class="showDetails" type="checkbox" name="detailBox" value='. $key . '>' . $key .'</label>';
                 }
-            }           
+            }
             echo '</div>';
-           
+
            // 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 '<button id="detailBtn" class="glm-button" type="button"> Show Detail Options </button>';
 
             echo '<button id="generate" class="glm-button" type="button"> Insert Shortcode </button>';
-                
+
         }
 
     /**
@@ -879,7 +879,7 @@ class glmMembersAdmin extends GlmPluginSupport
                 $this->createPages($a['requiredPages']);
             }
         }
-        
+
         // Loop till we have a final action
         $loopCheck = 0;
         $loopTracking = "<p>Menu: $menuItem, Action = $action</p>";
index 1e4150f..05b8e20 100644 (file)
--- 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)) {
index 58b7e41..31b18aa 100755 (executable)
@@ -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
     {\r
        // Check for a bitmap data\r
        if (!isset($f['bitmap']) || !is_array($f['bitmap'])) {\r
-               echo "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data.";\r
-               exit;\r
+            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                glmMembersAdmin::addNotice(
+                    "Field '".$f['name']."' is type bitmap but does not have supplied 'bitmap' data.",
+                    'Alert',
+                    ''
+                );
+            }
+            return false;
        }\r
 \r
        // Build bitmap array\r
@@ -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 "<P>&nbsp;</p><strong>ERROR:</strong> 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(
+                        "<P>&nbsp;</p><strong>ERROR:</strong> 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 "<P>&nbsp;</p><strong>ERROR:</strong> Supplied value for 'filter_options' is not valid;";
-                    exit;
+                    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                        glmMembersAdmin::addNotice(
+                            "<P>&nbsp;</p><strong>ERROR:</strong> 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;
         }