From 95555b12b36fd805854680aaa5fbdae1e3f316aa Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 18 Jan 2019 10:46:09 -0500 Subject: [PATCH] Replacement of each() deprecated function calls. Replacing each each() line with proper foreach. --- classes/data/dataCategories.php | 6 +-- classes/data/dataFiles.php | 20 +++++----- classes/data/dataImages.php | 44 +++++++++++----------- classes/glmMemberImportFromConnections.php | 6 +-- lib/GeoCalculations.php | 4 +- lib/GlmDataAbstract/DataAbstract.php | 28 +++++++------- models/admin/ajax/imageUpload.php | 2 +- models/admin/member/memberInfo.php | 2 +- models/admin/members/list.php | 2 +- models/front/members/detail.php | 4 +- models/front/members/list.php | 20 +++++----- 11 files changed, 69 insertions(+), 69 deletions(-) diff --git a/classes/data/dataCategories.php b/classes/data/dataCategories.php index 66d18bf3..7fb5074b 100644 --- a/classes/data/dataCategories.php +++ b/classes/data/dataCategories.php @@ -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']; } } diff --git a/classes/data/dataFiles.php b/classes/data/dataFiles.php index 5a90407a..0d18e04f 100644 --- a/classes/data/dataFiles.php +++ b/classes/data/dataFiles.php @@ -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') { diff --git a/classes/data/dataImages.php b/classes/data/dataImages.php index 8b03f6d9..58eb01f7 100644 --- a/classes/data/dataImages.php +++ b/classes/data/dataImages.php @@ -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 +?> diff --git a/classes/glmMemberImportFromConnections.php b/classes/glmMemberImportFromConnections.php index a3da98ac..2e5092e0 100644 --- a/classes/glmMemberImportFromConnections.php +++ b/classes/glmMemberImportFromConnections.php @@ -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'] ); } } diff --git a/lib/GeoCalculations.php b/lib/GeoCalculations.php index bd432651..c8fa7156 100644 --- a/lib/GeoCalculations.php +++ b/lib/GeoCalculations.php @@ -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 +?> diff --git a/lib/GlmDataAbstract/DataAbstract.php b/lib/GlmDataAbstract/DataAbstract.php index ded4f3b8..96b4a174 100755 --- a/lib/GlmDataAbstract/DataAbstract.php +++ b/lib/GlmDataAbstract/DataAbstract.php @@ -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']); diff --git a/models/admin/ajax/imageUpload.php b/models/admin/ajax/imageUpload.php index c08c6c11..5dc1a63f 100644 --- a/models/admin/ajax/imageUpload.php +++ b/models/admin/ajax/imageUpload.php @@ -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)) { diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index d3a8f95b..22b0f48d 100755 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -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; } } diff --git a/models/admin/members/list.php b/models/admin/members/list.php index 5ac55461..cb5feaed 100755 --- a/models/admin/members/list.php +++ b/models/admin/members/list.php @@ -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; } } diff --git a/models/front/members/detail.php b/models/front/members/detail.php index 0c1f8d0b..b3af707b 100644 --- a/models/front/members/detail.php +++ b/models/front/members/detail.php @@ -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; } diff --git a/models/front/members/list.php b/models/front/members/list.php index 8bacf580..1226597e 100755 --- a/models/front/members/list.php +++ b/models/front/members/list.php @@ -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) { -- 2.17.1