| @@ -1,15 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Import Users plugin file. | |
| 4 | - * | |
| 5 | - * Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com | |
| 6 | - */ | |
| 2 | +/****************************************************************************************** | |
| 3 | + * Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License | |
| 4 | + * Unauthorized copying of this file, via any medium is strictly prohibited | |
| 5 | + * Proprietary and confidential | |
| 6 | + * You can contact Smackcoders at email address info@smackcoders.com. | |
| 7 | + *******************************************************************************************/ | |
| 7 | 8 | |
| 8 | 9 | namespace Smackcoders\SMUSERS; |
| 9 | 10 | |
| 10 | 11 | if ( ! defined( 'ABSPATH' ) ) |
| 11 | - exit; // Exit if accessed directly | |
| 12 | +exit; // Exit if accessed directly | |
| 12 | 13 | |
| 13 | 14 | class ImportHelpers { |
| 14 | 15 | private static $helpers_instance = null; |
| 15 | 16 | |
| @@ -132,8 +133,9 @@ | ||
| 132 | 133 | foreach($map as $key => $value){ |
| 133 | 134 | $csv_value= trim($map[$key]); |
| 134 | 135 | |
| 135 | 136 | if(!empty($csv_value)){ |
| 137 | + //if(preg_match_all('/{(\w+)}/', $csv_value, $matches)){ | |
| 136 | 138 | $pattern = "/({([a-z A-Z 0-9 | , _ -]+)(.*?)(}))/"; |
| 137 | 139 | if(preg_match_all($pattern, $csv_value, $matches, PREG_PATTERN_ORDER)){ |
| 138 | 140 | $csv_element = $csv_value; |
| 139 | 141 | |
| @@ -147,20 +149,21 @@ | ||
| 147 | 149 | } |
| 148 | 150 | } |
| 149 | 151 | |
| 150 | 152 | $math = 'MATH('; |
| 151 | - if (strpos($csv_element, $math) !== false) { | |
| 152 | - $equation = str_replace('MATH(', '', $csv_element); | |
| 153 | - $equation = str_replace(')', '', $equation); | |
| 154 | - $csv_element = $this->evalmath($equation); | |
| 155 | - } | |
| 153 | + if (strpos($csv_element, $math) !== false) { | |
| 154 | + $equation = str_replace('MATH(', '', $csv_element); | |
| 155 | + $equation = str_replace(')', '', $equation); | |
| 156 | + $csv_element = $this->evalmath($equation); | |
| 157 | + } | |
| 156 | 158 | |
| 157 | - $wp_element= trim($key); | |
| 158 | - if(!empty($csv_element) && !empty($wp_element)){ | |
| 159 | - $post_values[$wp_element] = $csv_element; | |
| 160 | - } | |
| 159 | + $wp_element= trim($key); | |
| 160 | + if(!empty($csv_element) && !empty($wp_element)){ | |
| 161 | + $post_values[$wp_element] = $csv_element; | |
| 162 | + } | |
| 163 | + //} | |
| 161 | 164 | } |
| 162 | - | |
| 165 | + | |
| 163 | 166 | elseif(!in_array($csv_value , $header_array)){ |
| 164 | 167 | $wp_element= trim($key); |
| 165 | 168 | $post_values[$wp_element] = $csv_value; |
| 166 | 169 | } |
| @@ -183,14 +186,15 @@ | ||
| 183 | 186 | public function evalmath($equation) { |
| 184 | 187 | |
| 185 | 188 | $result = 0; |
| 186 | 189 | |
| 187 | - //input | |
| 190 | + // sanitize input | |
| 188 | 191 | $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); |
| 189 | 192 | |
| 190 | 193 | // convert percentages to decimal |
| 191 | 194 | $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); |
| 192 | 195 | $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); |
| 196 | + //$equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); | |
| 193 | 197 | |
| 194 | 198 | if ( $equation != "" ) |
| 195 | 199 | { |
| 196 | 200 | $result = @eval("return " . $equation . ";" ); |
| @@ -213,17 +217,17 @@ | ||
| 213 | 217 | global $wpdb; |
| 214 | 218 | $importlog_table_name = $wpdb->prefix ."import_log_detail"; |
| 215 | 219 | |
| 216 | 220 | $wpdb->insert($importlog_table_name, array( |
| 217 | - 'hash_key' => $hash_key, | |
| 218 | - 'message' => "{$message}", | |
| 219 | - 'status' => "{$status}", | |
| 220 | - 'verify' => "{$verify}", | |
| 221 | - 'post_id' => $post_id, | |
| 221 | + 'hash_key' => $hash_key, | |
| 222 | + 'message' => "{$message}", | |
| 223 | + 'status' => "{$status}", | |
| 224 | + 'verify' => "{$verify}", | |
| 225 | + 'post_id' => $post_id, | |
| 222 | 226 | |
| 223 | - ), | |
| 224 | - array('%s', '%s', '%s', '%s', '%d') | |
| 225 | - ); | |
| 227 | + ), | |
| 228 | + array('%s', '%s', '%s', '%s', '%d') | |
| 229 | + ); | |
| 226 | 230 | } |
| 227 | 231 | |
| 228 | 232 | public function update_error_log($message , $hash_key , $post_id){ |
| 229 | 233 | global $wpdb; |
| @@ -229,42 +233,42 @@ | ||
| 229 | 233 | global $wpdb; |
| 230 | 234 | $importlog_table_name = $wpdb->prefix ."import_log_detail"; |
| 231 | 235 | |
| 232 | 236 | $wpdb->insert($importlog_table_name, array( |
| 233 | - 'hash_key' => $hash_key, | |
| 234 | - 'message' => "{$message}", | |
| 235 | - 'post_id' => $post_id | |
| 237 | + 'hash_key' => $hash_key, | |
| 238 | + 'message' => "{$message}", | |
| 239 | + 'post_id' => $post_id | |
| 236 | 240 | |
| 237 | - ), | |
| 238 | - array('%s', '%s', '%d') | |
| 239 | - ); | |
| 241 | + ), | |
| 242 | + array('%s', '%s', '%d') | |
| 243 | + ); | |
| 240 | 244 | } |
| 241 | 245 | |
| 242 | 246 | public function update_category_log($category , $post_id){ |
| 243 | 247 | global $wpdb; |
| 244 | 248 | $wpdb->update($wpdb->prefix.'import_log_detail', array( |
| 245 | - 'categories' => "{$category}" | |
| 246 | - ), | |
| 247 | - array('post_id' => $post_id) | |
| 248 | - ); | |
| 249 | + 'categories' => "{$category}" | |
| 250 | + ), | |
| 251 | + array('post_id' => $post_id) | |
| 252 | + ); | |
| 249 | 253 | } |
| 250 | 254 | |
| 251 | 255 | public function update_tag_log($tag , $post_id){ |
| 252 | 256 | global $wpdb; |
| 253 | 257 | $wpdb->update($wpdb->prefix.'import_log_detail', array( |
| 254 | - 'tags' => "{$tag}" | |
| 255 | - ), | |
| 256 | - array('post_id' => $post_id) | |
| 257 | - ); | |
| 258 | + 'tags' => "{$tag}" | |
| 259 | + ), | |
| 260 | + array('post_id' => $post_id) | |
| 261 | + ); | |
| 258 | 262 | } |
| 259 | 263 | public function update_status_log($status , $verify , $post_id){ |
| 260 | 264 | global $wpdb; |
| 261 | 265 | $wpdb->update($wpdb->prefix.'import_log_detail', array( |
| 262 | - 'status' => "{$status}", | |
| 263 | - 'verify' => "{$verify}" | |
| 264 | - ), | |
| 265 | - array('post_id' => $post_id) | |
| 266 | - ); | |
| 266 | + 'status' => "{$status}", | |
| 267 | + 'verify' => "{$verify}" | |
| 268 | + ), | |
| 269 | + array('post_id' => $post_id) | |
| 270 | + ); | |
| 267 | 271 | } |
| 268 | 272 | |
| 269 | 273 | public function formatSizeUnits($bytes) |
| 270 | 274 | { |