Replacement of each() deprecated function calls.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Jan 2019 15:46:09 +0000 (10:46 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Jan 2019 15:46:09 +0000 (10:46 -0500)
Replacing each each() line with proper foreach.

classes/data/dataCategories.php
classes/data/dataFiles.php
classes/data/dataImages.php
classes/glmMemberImportFromConnections.php
lib/GeoCalculations.php
lib/GlmDataAbstract/DataAbstract.php
models/admin/ajax/imageUpload.php
models/admin/member/memberInfo.php
models/admin/members/list.php
models/front/members/detail.php
models/front/members/list.php

index 66d18bf..7fb5074 100644 (file)
@@ -358,9 +358,9 @@ class GlmDataCategories extends GlmDataAbstract
         $categoriesSorted = $this->sortParentChild($categories);
 
         if (!$forEdit && is_array($categoriesSorted)) {
-            while (list($k, $v) = each($categoriesSorted)) {
-            $categoriesSorted[$k]['parent_id'] = $v['parent']['value'];
-            $categoriesSorted[$k]['parent'] = $v['parent']['name'];
+            foreach ( $categoriesSorted as $k => $v ) {
+                $categoriesSorted[$k]['parent_id'] = $v['parent']['value'];
+                $categoriesSorted[$k]['parent'] = $v['parent']['name'];
             }
         }
 
index 5a90407..0d18e04 100644 (file)
@@ -327,16 +327,16 @@ class GlmDataFiles extends GlmDataAbstract
 
             // Update other data for this image
             reset($_REQUEST['file_caption']);
-            while (list($k, $v) = each($_REQUEST['file_caption'])) {
-            $id = ($k -0);
+            foreach ( $_REQUEST['file_caption'] as $k => $v ) {
+                $id = ($k -0);
 
-            // Sanitize input
-            $caption = sanitize_text_field( $_REQUEST['file_caption'][$k] );
-            $descr   = (isset($_REQUEST['file_descr'])) ? sanitize_text_field( $_REQUEST['file_descr'][$k] ):'';
+                // Sanitize input
+                $caption = sanitize_text_field( $_REQUEST['file_caption'][$k] );
+                $descr   = (isset($_REQUEST['file_descr'])) ? sanitize_text_field( $_REQUEST['file_descr'][$k] ):'';
 
-            // Update data for this image
-            $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files SET caption = '$caption', descr = '$descr' WHERE id = $id;";
-            $this->wpdb->query($sql);
+                // Update data for this image
+                $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."files SET caption = '$caption', descr = '$descr' WHERE id = $id;";
+                $this->wpdb->query($sql);
             }
 
             // Check for an image deletion
@@ -344,8 +344,8 @@ class GlmDataFiles extends GlmDataAbstract
 
                 // For each delete requested
                 reset($_REQUEST['file_delete']);
-                while (list($k, $v) = each($_REQUEST['file_delete'])) {
-                $id = ($k -0);
+                foreach ( $_REQUEST['file_delete'] as $k => $v ) {
+                    $id = ($k -0);
 
                     // If a valid key and delete request is in fact set
                     if ($id > 0 && $v == 'on') {
index 8b03f6d..58eb01f 100644 (file)
@@ -245,7 +245,7 @@ class GlmDataImages extends GlmDataAbstract
             $where .= ' AND featured = true';
         }
         $imageGallery = $this->getList($where, 'T.position');
-        
+
         // Check if we found anything
         if (!is_array($imageGallery) || count($imageGallery) == 0) {
             return false;
@@ -342,20 +342,20 @@ class GlmDataImages extends GlmDataAbstract
 
             // Update other data for this image
             reset($_REQUEST['galleryImage_caption']);
-            while (list($k, $v) = each($_REQUEST['galleryImage_caption'])) {
-            $id = ($k -0);
+            foreach ( $_REQUEST['galleryImage_caption'] as $k => $v ) {
+                $id = ($k -0);
 
-            // Sanitize input
-            $caption = sanitize_text_field( $_REQUEST['galleryImage_caption'][$k] );
-            $descr = sanitize_text_field( $_REQUEST['galleryImage_descr'][$k] );
-//            $featured = (isset($_REQUEST['galleryImage_featured']) && isset($_REQUEST['galleryImage_featured'][$k]) && $_REQUEST['galleryImage_featured'][$k] == 'on' ? 'true' : 'false');
+                // Sanitize input
+                $caption = sanitize_text_field( $_REQUEST['galleryImage_caption'][$k] );
+                $descr = sanitize_text_field( $_REQUEST['galleryImage_descr'][$k] );
+    //            $featured = (isset($_REQUEST['galleryImage_featured']) && isset($_REQUEST['galleryImage_featured'][$k]) && $_REQUEST['galleryImage_featured'][$k] == 'on' ? 'true' : 'false');
 
-            // Check if this is the featured image
-            $thisFeatured = ($featured == $k ? 'true' : 'false');
+                // Check if this is the featured image
+                $thisFeatured = ($featured == $k ? 'true' : 'false');
 
-            // Update data for this image
-            $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET caption = '$caption', descr = '$descr', featured = $thisFeatured WHERE id = $id;";
-            $this->wpdb->query($sql);
+                // Update data for this image
+                $sql = "UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX ."images SET caption = '$caption', descr = '$descr', featured = $thisFeatured WHERE id = $id;";
+                $this->wpdb->query($sql);
             }
 
             // Check for an image deletion
@@ -363,8 +363,8 @@ class GlmDataImages extends GlmDataAbstract
 
                 // For each delete requested
                 reset($_REQUEST['galleryImage_delete']);
-                while (list($k, $v) = each($_REQUEST['galleryImage_delete'])) {
-                $id = ($k -0);
+                foreach  ( $_REQUEST['galleryImage_delete'] as $k => $v ) {
+                    $id = ($k -0);
 
                     // If a valid key and delete request is in fact set
                     if ($id > 0 && $v == 'on') {
@@ -382,7 +382,7 @@ class GlmDataImages extends GlmDataAbstract
 
                             // Also delete all copies of the image
                             reset($this->config['imageSizes']);
-                            while (list($k, $v) = each($this->config['imageSizes'])) {
+                            foreach ( $this->config['imageSizes'] as $k => $v ) {
 
                             // Check if the image actually exists - May not if we're doing development
                             if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$imgData['file_name'])) {
@@ -456,15 +456,15 @@ class GlmDataImages extends GlmDataAbstract
 
             // For each image size
             reset($sizes);
-            while (list($k, $v) = each($sizes)) {
+            foreach ( $sizes as $k => $v ) {
 
-            // Check if the source image exists
-            if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$srcName)) {
+                // Check if the source image exists
+                if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$srcName)) {
 
-                // Copy src file to dst file for this size
-                copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$srcName, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$dstName);
+                    // 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
@@ -504,4 +504,4 @@ class GlmDataImages extends GlmDataAbstract
 
 }
 
-?>
\ No newline at end of file
+?>
index a3da98a..2e5092e 100644 (file)
@@ -115,7 +115,7 @@ class GlmMemberImportFromConnections
         }
 
         // Post process list adata
-        while (list($k, $v) = each($list)) {
+        foreach ( $list as $k => $v ) {
 
             // Addresses
             $a = unserialize($v['addresses']);
@@ -252,7 +252,7 @@ class GlmMemberImportFromConnections
         if ( $start === 0 ) {
             // Store all categories and collect the new IDs
             reset( $cats );
-            while ( list( $k, $c ) = each( $cats ) ) {
+            foreach ( $cats as $k => $c ) {
                 $sql = "
                     INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories
                         ( name, descr, short_descr, parent)
@@ -268,7 +268,7 @@ class GlmMemberImportFromConnections
             }
         } else {
             reset( $cats );
-            while ( list( $k, $c ) = each( $cats ) ) {
+            foreach ( $cats as $k => $c ) {
                 $cats[$k]['new_id'] = $this->getCategoryIdByName( $c['name'] );
             }
         }
index bd43265..c8fa715 100644 (file)
@@ -94,7 +94,7 @@ class EventManagementGeoCalculations
         $distances = array();
         $over_query_limit = false;
 
-        while (list($k, $m) = each($members)) {
+        foreach ( $members as $k => $m ) {
 
             $members[$k][$distance_field] = false;
             $members[$k][$duration_field] = false;
@@ -250,4 +250,4 @@ function distCmp($a, $b) {
 
 
 
-?>
\ No newline at end of file
+?>
index ded4f3b..96b4a17 100755 (executable)
@@ -957,7 +957,7 @@ abstract class GlmDataAbstract
         }
 
         // Add list entries
-        while (list($k, $v) = each($f['list'])) {
+        foreach ( $f['list'] as $k => $v ) {
             $list[$k] = array(
                 'name'    => $v,
                 'nameEsc' => addslashes($v),
@@ -1013,7 +1013,7 @@ abstract class GlmDataAbstract
         }
 
         // Add list entries
-        while (list($k, $v) = each($f['list'])) {
+        foreach ( $f['list'] as $k => $v ) {
             $list[$k] = array(
                 'name'    => $v,
                 'nameEsc' => addslashes($v),
@@ -1110,7 +1110,7 @@ $forEdit = true;
         // Build bitmap array
         $bitmap = array();
         $bitmapNames = array();
-        while (list($k, $v) = each($f['bitmap'])) {
+        foreach ( $f['bitmap'] as $k => $v ) {
 
             // If appropriate or requested, build picklists
             if ($this->optionIncludeSelectListData || $forEdit || $alwaysList) {
@@ -1171,7 +1171,7 @@ $forEdit = true;
        // Build bitmap array
        $bitmap = array();
        $bitmapNames = array();
-       while (list($k, $v) = each($f['bitmap'])) {
+        foreach ( $f['bitmap'] as $k => $v ) {
                $bitmap[$k] = array(
                                'name'    => $v,
                                'nameEsc' => addslashes($v),
@@ -2416,7 +2416,7 @@ $forEdit = true;
         if ((isset($_REQUEST[$as."_delete"]) && $_REQUEST[$as."_delete"] == 'on') || ($new && $current_img != false)) {
 
             // Scan all the image size directories and remove this image
-            while (list($k, $v) = each($this->config['imageSizes'])) {
+            foreach ( $this->config['imageSizes'] as $k => $v ) {
                 if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$current_img)) {
                     unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$current_img);
 
@@ -2466,7 +2466,7 @@ $forEdit = true;
 
                 // 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'])) {
+                foreach ( $this->config['imageSizes'] as $k => $v ) {
 
                     // Check if size directory needs to be made
                     if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) {
@@ -2954,7 +2954,7 @@ $forEdit = true;
 
         // For each possible field
         reset($this->fields);
-        while (list($k, $v) = each($this->fields )) {
+        foreach ( $this->fields as $k => $v ) {
 
             // If this field is selected for the current operation
             if (isset($v['use']) && (strstr($v['use'], $op) || strstr($v['use'], 'a'))) {
@@ -3030,7 +3030,7 @@ $forEdit = true;
 
         // For each possible field
         reset($this->fields);
-        while (list($k, $v) = each($this->fields )) {
+        foreach ( $this->fields as $k => $v ) {
 
             // If this field is selected for the current operation
             if (isset($v['use']) && (strstr($v['use'], $op) || strstr($v['use'], 'a'))) {
@@ -3110,7 +3110,7 @@ $forEdit = true;
 
         // For each possible field
         reset($this->fields);
-        while (list($k, $v) = each($this->fields )) {
+        foreach ( $this->fields as $k => $v ) {
 
             // Assume field will be OK
             $this->inputFieldStatus = true;
@@ -3350,7 +3350,7 @@ $forEdit = true;
         $newList = array();
 
         // Process field output data for each result - use ID field as key
-        while (list($k, $v) = each($list)) {
+        foreach ( $list as $k => $v ) {
             $newList[$v['id']] = $this->processOutputData($v, 'l');
         }
 
@@ -3492,7 +3492,7 @@ $forEdit = true;
                         $newName = preg_replace('/\d{10}/', time(), $newData[$f]);
 
                         // For each image size
-                        while (list($k, $v) = each($this->config['imageSizes'])) {
+                        foreach ( $this->config['imageSizes'] as $k => $v ) {
 
                             // Check if we have that size for the original image, then copy it to the new name
                             if (file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newData[$f])) {
@@ -3641,7 +3641,7 @@ $forEdit = true;
 
             $sep = '';
             reset($r['fieldStore']);
-            while (list($k, $v) = each($r['fieldStore'])) {
+            foreach ( $r['fieldStore'] as $k => $v ) {
                 $fields .= $sep." $k";
                 $vals .= $sep." $v";
                 $sep = ",\n";
@@ -3714,7 +3714,7 @@ $forEdit = true;
 
         // Check for 'view_only' fields
         reset($this->fields);
-        while (list($k, $v) = each($this->fields )) {
+        foreach ( $this->fields as $k => $v ) {
 
             if (isset($v['view_only']) && $v['view_only']) {
 
@@ -3744,7 +3744,7 @@ $forEdit = true;
             reset($r['fieldStore']);
 
             // Build list of fields that get updated
-            while (list($k, $v) = each($r['fieldStore'])) {
+            foreach ( $r['fieldStore'] as $k => $v ) {
 
                 // Determine if the field is supposed to be updated when blank;
                 $noUpdateWhenBlank = (isset($this->fields[$k]['no_update_when_blank']) && $this->fields[$k]['no_update_when_blank']);
index c08c6c1..5dc1a63 100644 (file)
@@ -218,7 +218,7 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages
             // 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'])) {
+            foreach ( $this->config['imageSizes'] as $k => $v ) {
 
                 // Check if size directory needs to be made
                 if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) {
index d3a8f95..22b0f48 100755 (executable)
@@ -293,7 +293,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
         // If we have categories, add "selected" element default false;
         if (is_array($categories2)) {
             reset($categories2);
-            while (list($k, $v) = each($categories2)) {
+            foreach ( $categories2 as $k => $v ) {
                 $categories2[$k]['selected'] = false;
             }
         }
index 5ac5546..cb5feae 100755 (executable)
@@ -173,7 +173,7 @@ class GlmMembersAdmin_members_list extends GlmDataMembers
         // If we have categories, add "selected" element default false;
         if (is_array($categories)) {
             reset($categories);
-            while (list($k, $v) = each($categories)) {
+            foreach ( $categories as $k => $v ) {
                 $categories[$k]['selected'] = false;
             }
         }
index 0c1f8d0..b3af707 100644 (file)
@@ -172,14 +172,14 @@ class GlmMembersFront_members_detail extends GlmDataMemberInfo
                     // If we're setting all
                     if ($s == 'all') {
 
-                        while (list($key, $val) = each($GLOBALS['showOpts'])) {
+                        foreach ( $GLOBALS['showOpts'] as $key => $val ) {
                             $settings[$val] = true;
                         }
 
                         // Or we're clearing all
                     } elseif ($s == 'none') {
 
-                        while (list($key, $val) = each($GLOBALS['showOpts'])) {
+                        foreach ( $GLOBALS['showOpts'] as $key => $val ) {
                             $settings[$val] = false;
                         }
 
index 8bacf58..1226597 100755 (executable)
@@ -254,14 +254,14 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
                     // If we're setting all
                     if ($s == 'all') {
 
-                        while (list($key, $val) = each($GLOBALS['showOpts'])) {
+                        foreach ( $GLOBALS['showOpts'] as $key => $val ) {
                             $settings[$val] = true;
                         }
 
                     // Or we're clearing all
                     } elseif ($s == 'none') {
 
-                        while (list($key, $val) = each($GLOBALS['showOpts'])) {
+                        foreach ( $GLOBALS['showOpts'] as $key => $val ) {
                             $settings[$val] = false;
                         }
 
@@ -342,7 +342,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $regionsRequested = explode( ',', $actionData['request']['region-search'] );
 
             // Check for numeric ID's only
-            while ( list( $k, $v ) = each( $regionsRequested ) ) {
+            foreach ( $regionsRequested as $k => $v ) {
                 if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
                     $regions[] = ( $v - 0 );
                 }
@@ -361,7 +361,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $regionsRequested = explode( ',', $actionData['request']['county-search'] );
 
             // Check for numeric ID's only
-            while ( list( $k, $v ) = each( $regionsRequested ) ) {
+            foreach ( $regionsRequested as $k => $v ) {
                 if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
                     $counties[] = ( $v - 0 );
                 }
@@ -394,7 +394,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $citiesRequested = explode( ',', $actionData['request']['city-search'] );
 
             // Check for numeric ID's only
-            while ( list( $k, $v ) = each( $citiesRequested ) ) {
+            foreach ( $citiesRequested as $k => $v ) {
                 if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
                     $cities[] = ( $v - 0 );
                 }
@@ -487,7 +487,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $typesRequested = explode(',', $actionData['request']['type']);
 
             // Check for numeric IDs only
-            while (list($k, $v) = each($typesRequested)) {
+            foreach ( $typesRequested as $k => $v ) {
 
                 // If it's just numeric - note Explode returns an array element with value = 0 if no string.
                 if (preg_match('/^[0-9]*$/', trim($v)) && $v > 0) {
@@ -518,7 +518,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $catsRequested = explode(',', $actionData['request']['category']);
 
             // Check for numeric IDs only
-            while (list($k, $v) = each($catsRequested)) {
+            foreach ( $catsRequested as $k => $v ) {
 
                 // If it's just numeric - note Explode returns an array element with value = 0 if no string.
                 if (preg_match('/^[0-9]*$/', trim($v)) && $v > 0) {
@@ -540,7 +540,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $catsRequested = explode('|', $actionData['request']['category-name']);
 
             // Check for numeric or text selection of categories
-            while (list($k, $v) = each($catsRequested)) {
+            foreach ( $catsRequested as $k => $v ) {
 
                 $vStripped = html_entity_decode(stripslashes(trim($v)));
 
@@ -571,7 +571,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
 
                 // Add ['default'] value to all categories
                 reset($categoryData);
-                while (list($k, $v) = each($categoryData)) {
+                foreach ( $categoryData as $k => $v ) {
                     $categoryData[$k]['default'] = false;
                 }
 
@@ -589,7 +589,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
                  */
                 $parentSelected = false;
                 reset($categoryData);
-                while (list($k, $v) = each($categoryData)) {
+                foreach ( $categoryData as $k => $v ) {
 
                     // If this is a parent, then clear parent selected
                     if ($v['parent_id'] != $parentSelected) {