From 65061046bd8aab184b07d00a6e8681bdee300d8a Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:32:55 -0400 Subject: [PATCH 01/18] __construct --- parsecsv.lib.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 158ee26..08d7e01 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -351,23 +351,23 @@ class parseCSV { * @param [string] conditions Basic SQL-like conditions for row matching */ public function __construct ($input = null, $offset = null, $limit = null, $conditions = null, $keep_file_data = null) { - if ( $offset !== null ) { + if (!is_null($offset)) { $this->offset = $offset; } - if ( $limit !== null ) { + if (!is_null($limit)) { $this->limit = $limit; } - if ( !is_null($conditions) ) { + if (!is_null($conditions)) { $this->conditions = $conditions; } - if ( !is_null($keep_file_data) ) { + if (!is_null($keep_file_data)) { $this->keep_file_data = $keep_file_data; } - if ( !empty($input) ) { + if (!empty($input)) { $this->parse($input); } } From 936b6f4a50be616cea74f5f267d0fd6f245facc5 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:34:08 -0400 Subject: [PATCH 02/18] parse --- parsecsv.lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 08d7e01..9ec6017 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -391,24 +391,24 @@ class parseCSV { * @return [bool] */ public function parse ($input = null, $offset = null, $limit = null, $conditions = null) { - if ( $input === null ) { + if (is_null($input)) { $input = $this->file; } - if ( !empty($input) ) { - if ( $offset !== null ) { + if (!empty($input)) { + if (!is_null($offset)) { $this->offset = $offset; } - if ($limit !== null ) { + if (!is_null($limit)) { $this->limit = $limit; } - if ( !is_null($conditions) ) { + if (!is_null($conditions)) { $this->conditions = $conditions; } - if ( is_readable($input) ) { + if (is_readable($input)) { $this->data = $this->parse_file($input); } else { @@ -416,7 +416,7 @@ class parseCSV { $this->data = $this->parse_string(); } - if ( $this->data === false ) { + if ($this->data === false) { return false; } } From 17e060ea33efcc19625d46cd92ff181004bf4127 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:35:40 -0400 Subject: [PATCH 03/18] save --- parsecsv.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 9ec6017..000bcb4 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -437,7 +437,7 @@ class parseCSV { * @return [bool] */ public function save ($file = null, $data = array(), $append = false, $fields = array()) { - if ( empty($file) ) { + if (empty($file)) { $file = &$this->file; } From 31417caafdf71b7ed01c15761161419bad6a80d1 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:36:32 -0400 Subject: [PATCH 04/18] output --- parsecsv.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 000bcb4..54c5295 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -460,17 +460,17 @@ class parseCSV { * @return [string] */ public function output ($filename = null, $data = array(), $fields = array(), $delimiter = null) { - if ( empty($filename) ) { + if (empty($filename)) { $filename = $this->output_filename; } - if ( $delimiter === null ) { + if ($delimiter === null) { $delimiter = $this->output_delimiter; } $data = $this->unparse($data, $fields, null, null, $delimiter); - if ( $filename !== null ) { + if (!is_null($filename)) { header('Content-type: application/csv'); header('Content-Length: '.strlen($data)); header('Cache-Control: no-cache, must-revalidate'); From 8e19ecf94fd8937c6f133974f2e52e7f729e2a2d Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:37:02 -0400 Subject: [PATCH 05/18] encoding --- parsecsv.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 54c5295..416bb61 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -494,11 +494,11 @@ class parseCSV { */ public function encoding ($input = null, $output = null) { $this->convert_encoding = true; - if ( $input !== null ) { + if (!is_null($input)) { $this->input_encoding = $input; } - if ( $output !== null ) { + if (!is_null($output)) { $this->output_encoding = $output; } } From 604872faaddaed8c107981e2220f34a1d97abf38 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:39:21 -0400 Subject: [PATCH 06/18] auto --- parsecsv.lib.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 416bb61..1075eaf 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -518,24 +518,24 @@ class parseCSV { * @return [string] */ public function auto ($file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null) { - if ( $file === null ) { + if (is_null($file)) { $file = $this->file; } - if ( empty($search_depth) ) { + if (empty($search_depth)) { $search_depth = $this->auto_depth; } - if ( $enclosure === null ) { + if (is_null($enclosure)) { $enclosure = $this->enclosure; } - if ( $preferred === null ) { + if (is_null($preferred)) { $preferred = $this->auto_preferred; } - if ( empty($this->file_data) ) { - if ( $this->_check_data($file) ) { + if (empty($this->file_data)) { + if ($this->_check_data($file)) { $data = &$this->file_data; } else { @@ -553,24 +553,24 @@ class parseCSV { $to_end = true; // walk specific depth finding posssible delimiter characters - for ( $i=0; $i < $strlen; $i++ ) { + for ($i=0; $i < $strlen; $i++) { $ch = $data{$i}; - $nch = ( isset($data{$i+1}) ) ? $data{$i+1} : false ; - $pch = ( isset($data{$i-1}) ) ? $data{$i-1} : false ; + $nch = (isset($data{$i+1})) ? $data{$i+1} : false ; + $pch = (isset($data{$i-1})) ? $data{$i-1} : false ; // open and closing quotes - if ( $ch == $enclosure ) { - if ( !$enclosed || $nch != $enclosure ) { - $enclosed = ( $enclosed ) ? false : true ; + if ($ch == $enclosure) { + if (!$enclosed || $nch != $enclosure) { + $enclosed = ($enclosed) ? false : true ; } - elseif ( $enclosed ) { + elseif ($enclosed) { $i++; } // end of row } - elseif ( ($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed ) { - if ( $n >= $search_depth ) { + elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) { + if ($n >= $search_depth) { $strlen = 0; $to_end = false; } @@ -581,8 +581,8 @@ class parseCSV { // count character } elseif (!$enclosed) { - if ( !preg_match('/['.preg_quote($this->auto_non_chars, '/').']/i', $ch) ) { - if ( !isset($chars[$ch][$n]) ) { + if (!preg_match('/['.preg_quote($this->auto_non_chars, '/').']/i', $ch)) { + if (!isset($chars[$ch][$n])) { $chars[$ch][$n] = 1; } else { @@ -593,10 +593,10 @@ class parseCSV { } // filtering - $depth = ( $to_end ) ? $n-1 : $n ; + $depth = ($to_end) ? $n-1 : $n; $filtered = array(); - foreach( $chars as $char => $value ) { - if ( $match = $this->_check_count($char, $value, $depth, $preferred) ) { + foreach ($chars as $char => $value) { + if ($match = $this->_check_count($char, $value, $depth, $preferred)) { $filtered[$match] = $char; } } @@ -606,7 +606,7 @@ class parseCSV { $this->delimiter = reset($filtered); // parse data - if ( $parse ) { + if ($parse) { $this->data = $this->parse_string(); } From 710f22eeb90cf04b63230db56947c6bf84feee1e Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:40:00 -0400 Subject: [PATCH 07/18] parse_file --- parsecsv.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 1075eaf..899c25f 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -629,15 +629,15 @@ class parseCSV { * @return [array|bool] */ public function parse_file ($file = null) { - if ( $file === null ) { + if (is_null($file)) { $file = $this->file; } - if ( empty($this->file_data) ) { + if (empty($this->file_data)) { $this->load_data($file); } - return ( !empty($this->file_data) ) ? $this->parse_string() : false ; + return (!empty($this->file_data)) ? $this->parse_string() : false; } /** From 4d07760933f2ed25df7f6025c96c4fc04090c5ff Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:44:14 -0400 Subject: [PATCH 08/18] parse_string --- parsecsv.lib.php | 68 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 899c25f..a3234c9 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -649,8 +649,8 @@ class parseCSV { * @return 2D array with CSV data, or false on failure */ public function parse_string ($data = null) { - if ( empty($data) ) { - if ( $this->_check_data() ) { + if (empty($data)) { + if ($this->_check_data()) { $data = &$this->file_data; } else { @@ -664,7 +664,7 @@ class parseCSV { $row = array(); $row_count = 0; $current = ''; - $head = ( !empty($this->fields) ) ? $this->fields : array() ; + $head = (!empty($this->fields)) ? $this->fields : array(); $col = 0; $enclosed = false; $was_enclosed = false; @@ -678,23 +678,23 @@ class parseCSV { } // walk through each character - for ( $i=0; $i < $strlen; $i++ ) { - $ch = ( isset($data{$i}) ) ? $data{$i} : false ; - $nch = ( isset($data{$i+1}) ) ? $data{$i+1} : false ; - $pch = ( isset($data{$i-1}) ) ? $data{$i-1} : false ; + for ($i=0; $i < $strlen; $i++) { + $ch = (isset($data{$i})) ? $data{$i} : false; + $nch = (isset($data{$i+1})) ? $data{$i+1} : false; + $pch = (isset($data{$i-1})) ? $data{$i-1} : false; // open/close quotes, and inline quotes - if ( $ch == $this->enclosure ) { - if ( !$enclosed ) { - if ( ltrim($current,$white_spaces) == '' ) { - $enclosed = true; + if ($ch == $this->enclosure) { + if (!$enclosed) { + if (ltrim($current,$white_spaces) == '') { + $enclosed = true; $was_enclosed = true; } else { $this->error = 2; $error_row = count($rows) + 1; $error_col = $col + 1; - if ( !isset($this->error_info[$error_row.'-'.$error_col]) ) { + if (!isset($this->error_info[$error_row.'-'.$error_col])) { $this->error_info[$error_row.'-'.$error_col] = array( 'type' => 2, 'info' => 'Syntax error found on row '.$error_row.'. Non-enclosed fields can not contain double-quotes.', @@ -711,20 +711,20 @@ class parseCSV { $current .= $ch; $i++; } - elseif ( $nch != $this->delimiter && $nch != "\r" && $nch != "\n" ) { - for ( $x=($i+1); isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++ ) {} - if ( $data{$x} == $this->delimiter ) { + elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") { + for ($x=($i+1); isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++) {} + if ($data{$x} == $this->delimiter) { $enclosed = false; $i = $x; } else { - if ( $this->error < 1 ) { + if ($this->error < 1) { $this->error = 1; } $error_row = count($rows) + 1; $error_col = $col + 1; - if ( !isset($this->error_info[$error_row.'-'.$error_col]) ) { + if (!isset($this->error_info[$error_row.'-'.$error_col])) { $this->error_info[$error_row.'-'.$error_col] = array( 'type' => 1, 'info' => @@ -748,24 +748,24 @@ class parseCSV { // end of field/row/csv } elseif ( ($ch == $this->delimiter || $ch == "\n" || $ch == "\r" || $ch === false) && !$enclosed ) { - $key = ( !empty($head[$col]) ) ? $head[$col] : $col ; - $row[$key] = ( $was_enclosed ) ? $current : trim($current) ; + $key = (!empty($head[$col])) ? $head[$col] : $col; + $row[$key] = ($was_enclosed) ? $current : trim($current); $current = ''; $was_enclosed = false; $col++; // end of row - if ( $ch == "\n" || $ch == "\r" || $ch === false ) { - if ( $this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions) ) { - if ( $this->heading && empty($head) ) { + if ($ch == "\n" || $ch == "\r" || $ch === false) { + if ($this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions)) { + if ($this->heading && empty($head)) { $head = $row; } - elseif ( empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading)) ) { - if ( !empty($this->sort_by) && !empty($row[$this->sort_by]) ) { - if ( isset($rows[$row[$this->sort_by]]) ) { + elseif (empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading))) { + if (!empty($this->sort_by) && !empty($row[$this->sort_by])) { + if (isset($rows[$row[$this->sort_by]])) { $rows[$row[$this->sort_by].'_0'] = &$rows[$row[$this->sort_by]]; unset($rows[$row[$this->sort_by]]); - for ( $sn=1; isset($rows[$row[$this->sort_by].'_'.$sn]); $sn++ ) {} + for ($sn=1; isset($rows[$row[$this->sort_by].'_'.$sn]); $sn++) {} $rows[$row[$this->sort_by].'_'.$sn] = $row; } else $rows[$row[$this->sort_by]] = $row; @@ -780,11 +780,11 @@ class parseCSV { $col = 0; $row_count++; - if ( $this->sort_by === null && $this->limit !== null && count($rows) == $this->limit ) { + if ($this->sort_by === null && $this->limit !== null && count($rows) == $this->limit) { $i = $strlen; } - if ( $ch == "\r" && $nch == "\n" ) { + if ($ch == "\r" && $nch == "\n") { $i++; } } @@ -797,23 +797,23 @@ class parseCSV { } $this->titles = $head; - if ( !empty($this->sort_by) ) { + if (!empty($this->sort_by)) { $sort_type = SORT_REGULAR; - if ( $this->sort_type == 'numeric' ) { + if ($this->sort_type == 'numeric') { $sort_type = SORT_NUMERIC; } - elseif ( $this->sort_type == 'string' ) { + elseif ($this->sort_type == 'string') { $sort_type = SORT_STRING; } - ( $this->sort_reverse ) ? krsort($rows, $sort_type) : ksort($rows, $sort_type) ; + ($this->sort_reverse) ? krsort($rows, $sort_type) : ksort($rows, $sort_type); - if ( $this->offset !== null || $this->limit !== null ) { + if ($this->offset !== null || $this->limit !== null) { $rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset) , $this->limit, true); } } - if ( !$this->keep_file_data ) { + if (!$this->keep_file_data) { $this->file_data = null; } From 8af4d1e513f77545871d229cf496664e58d120f3 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:45:28 -0400 Subject: [PATCH 09/18] unparse --- parsecsv.lib.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index a3234c9..362caac 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -833,25 +833,25 @@ class parseCSV { * * @return CSV data (text string) */ - public function unparse ( $data = array(), $fields = array(), $append = false , $is_php = false, $delimiter = null) { - if ( !is_array($data) || empty($data) ) { + public function unparse ($data = array(), $fields = array(), $append = false , $is_php = false, $delimiter = null) { + if (!is_array($data) || empty($data)) { $data = &$this->data; } - if ( !is_array($fields) || empty($fields) ) { + if (!is_array($fields) || empty($fields)) { $fields = &$this->titles; } - if ( $delimiter === null ) { + if ($delimiter === null) { $delimiter = $this->delimiter; } - $string = ( $is_php ) ? "".$this->linefeed : '' ; + $string = ($is_php) ? "".$this->linefeed : ''; $entry = array(); // create heading - if ( $this->heading && !$append && !empty($fields) ) { - foreach( $fields as $key => $value ) { + if ($this->heading && !$append && !empty($fields)) { + foreach ($fields as $key => $value) { $entry[] = $this->_enclose_value($value, $delimiter); } @@ -860,8 +860,8 @@ class parseCSV { } // create data - foreach( $data as $key => $row ) { - foreach( $row as $field => $value ) { + foreach ($data as $key => $row) { + foreach ($row as $field => $value) { $entry[] = $this->_enclose_value($value, $delimiter); } From 33825514d93c2f476ef137618afe68f209937306 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:46:29 -0400 Subject: [PATCH 10/18] load_data --- parsecsv.lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 362caac..da8bea1 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -884,30 +884,30 @@ class parseCSV { $data = null; $file = null; - if ( $input === null ) { + if (is_null($input)) { $file = $this->file; } - elseif ( file_exists($input) ) { + elseif (file_exists($input)) { $file = $input; } else { $data = $input; } - if ( !empty($data) || $data = $this->_rfile($file) ) { - if ( $this->file != $file ) { + if (!empty($data) || $data = $this->_rfile($file)) { + if ($this->file != $file) { $this->file = $file; } - if ( preg_match('/\.php$/i', $file) && preg_match('/<\?.*?\?>(.*)/ims', $data, $strip) ) { + if (preg_match('/\.php$/i', $file) && preg_match('/<\?.*?\?>(.*)/ims', $data, $strip)) { $data = ltrim($strip[1]); } - if ( $this->convert_encoding ) { + if ($this->convert_encoding) { $data = iconv($this->input_encoding, $this->output_encoding, $data); } - if ( substr($data, -1) != "\n" ) { + if (substr($data, -1) != "\n") { $data .= "\n"; } From ce19deec4ed8e52cfc814ee4ed2ccdd0847bd97b Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:48:11 -0400 Subject: [PATCH 11/18] _validate_row_conditions --- parsecsv.lib.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index da8bea1..eff9e6d 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -933,27 +933,27 @@ class parseCSV { * @return true of false */ protected function _validate_row_conditions ($row = array(), $conditions = null) { - if ( !empty($row) ) { - if ( !empty($conditions) ) { - $conditions = (strpos($conditions, ' OR ') !== false) ? explode(' OR ', $conditions) : array($conditions) ; + if (!empty($row)) { + if (!empty($conditions)) { + $conditions = (strpos($conditions, ' OR ') !== false) ? explode(' OR ', $conditions) : array($conditions); $or = ''; - foreach( $conditions as $key => $value ) { - if ( strpos($value, ' AND ') !== false ) { + foreach ($conditions as $key => $value) { + if (strpos($value, ' AND ') !== false) { $value = explode(' AND ', $value); $and = ''; - foreach( $value as $k => $v ) { + foreach ($value as $k => $v) { $and .= $this->_validate_row_condition($row, $v); } - $or .= (strpos($and, '0') !== false) ? '0' : '1' ; + $or .= (strpos($and, '0') !== false) ? '0' : '1'; } else { $or .= $this->_validate_row_condition($row, $value); } } - return (strpos($or, '1') !== false) ? true : false ; + return (strpos($or, '1') !== false) ? true : false; } return true; From 494087ab1d7d309ebdb7bf25040aff300b7123b0 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:49:49 -0400 Subject: [PATCH 12/18] _validate_row_condition --- parsecsv.lib.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index eff9e6d..ec79f3e 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -985,19 +985,19 @@ class parseCSV { $operators_regex = array(); - foreach( $operators as $value ) { + foreach ($operators as $value) { $operators_regex[] = preg_quote($value, '/'); } $operators_regex = implode('|', $operators_regex); - if ( preg_match('/^(.+) ('.$operators_regex.') (.+)$/i', trim($condition), $capture) ) { + if (preg_match('/^(.+) ('.$operators_regex.') (.+)$/i', trim($condition), $capture)) { $field = $capture[1]; $op = $capture[2]; $value = $capture[3]; - if ( preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture) ) { - if ( $capture[1] == $capture[3] ) { + if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) { + if ($capture[1] == $capture[3]) { $value = $capture[2]; $value = str_replace("\\n", "\n", $value); $value = str_replace("\\r", "\r", $value); @@ -1006,29 +1006,29 @@ class parseCSV { } } - if ( array_key_exists($field, $row) ) { - if ( ($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value ) { + if (array_key_exists($field, $row)) { + if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) { return '1'; } - elseif ( ($op == '!=' || $op == 'is not') && $row[$field] != $value ) { + elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) { return '1'; } - elseif ( ($op == '<' || $op == 'is less than' ) && $row[$field] < $value ) { + elseif (($op == '<' || $op == 'is less than' ) && $row[$field] < $value) { return '1'; } - elseif ( ($op == '>' || $op == 'is greater than') && $row[$field] > $value ) { + elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) { return '1'; } - elseif ( ($op == '<=' || $op == 'is less than or equals' ) && $row[$field] <= $value ) { + elseif (($op == '<=' || $op == 'is less than or equals' ) && $row[$field] <= $value) { return '1'; } - elseif ( ($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value ) { + elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) { return '1'; } - elseif ( $op == 'contains' && preg_match('/'.preg_quote($value, '/').'/i', $row[$field]) ) { + elseif ($op == 'contains' && preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) { return '1'; } - elseif ( $op == 'does not contain' && !preg_match('/'.preg_quote($value, '/').'/i', $row[$field]) ) { + elseif ($op == 'does not contain' && !preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) { return '1'; } else { From 6f4d150e6f04e23d9547dd4e0b6f30deb9719be3 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:50:08 -0400 Subject: [PATCH 13/18] _validate_offset --- parsecsv.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index ec79f3e..6010b16 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1049,7 +1049,7 @@ class parseCSV { * @return true of false */ protected function _validate_offset ($current_row) { - if ( $this->sort_by === null && $this->offset !== null && $current_row < $this->offset ) { + if ($this->sort_by === null && $this->offset !== null && $current_row < $this->offset) { return false; } From 0422d5d9fe6d24c3ea284ec3718f98b90703b74d Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:50:48 -0400 Subject: [PATCH 14/18] _enclose_value --- parsecsv.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 6010b16..2478858 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1066,13 +1066,13 @@ class parseCSV { * @return Processed value */ protected function _enclose_value ($value = null, $delimiter = null) { - if ( $delimiter === null ) { + if (is_null($delimiter)) { $delimiter = $this->delimiter; } - if ( $value !== null && $value != '' ) { + if ($value !== null && $value != '') { $delimiter_quoted = preg_quote($delimiter, '/'); $enclosure_quoted = preg_quote($this->enclosure, '/'); - if ( preg_match("/".$delimiter_quoted."|".$enclosure_quoted."|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ') || $this->enclose_all ) { + if (preg_match("/".$delimiter_quoted."|".$enclosure_quoted."|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ') || $this->enclose_all) { $value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value); $value = $this->enclosure.$value.$this->enclosure; } From 4366201dc00b9ff439227e53cb3b41426137cfd3 Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:51:26 -0400 Subject: [PATCH 15/18] _check_data --- parsecsv.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 2478858..ccdfb71 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1090,8 +1090,8 @@ class parseCSV { * @return true or false */ protected function _check_data ($file = null) { - if ( empty($this->file_data) ) { - if ( $file === null ) $file = $this->file; + if (empty($this->file_data)) { + if (is_null($file)) $file = $this->file; return $this->load_data($file); } From 0c4a804db1c144c1bf03bc1ac13079bf1e7e3cff Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:52:23 -0400 Subject: [PATCH 16/18] _check_count --- parsecsv.lib.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index ccdfb71..8729062 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1112,19 +1112,19 @@ class parseCSV { * @return special string used for delimiter selection, or false */ protected function _check_count ($char, $array, $depth, $preferred) { - if ( $depth == count($array) ) { + if ($depth == count($array)) { $first = null; $equal = null; $almost = false; - foreach( $array as $key => $value ) { - if ( $first == null ) { + foreach ($array as $key => $value) { + if ($first == null) { $first = $value; } - elseif ( $value == $first && $equal !== false) { + elseif ($value == $first && $equal !== false) { $equal = true; } - elseif ( $value == $first+1 && $equal !== false ) { - $equal = true; + elseif ($value == $first+1 && $equal !== false) { + $equal = true; $almost = true; } else { @@ -1132,10 +1132,10 @@ class parseCSV { } } - if ( $equal ) { - $match = ( $almost ) ? 2 : 1 ; + if ($equal) { + $match = ($almost) ? 2 : 1; $pref = strpos($preferred, $char); - $pref = ( $pref !== false ) ? str_pad($pref, 3, '0', STR_PAD_LEFT) : '999' ; + $pref = ($pref !== false) ? str_pad($pref, 3, '0', STR_PAD_LEFT) : '999'; return $pref.$match.'.'.(99999 - str_pad($first, 5, '0', STR_PAD_LEFT)); } From 01e71adf36ae701687be81c8edff14194f66c16c Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:52:43 -0400 Subject: [PATCH 17/18] _rfile --- parsecsv.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 8729062..fb36e9f 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1154,8 +1154,8 @@ class parseCSV { * @return Data from file, or false on failure */ protected function _rfile ($file = null) { - if ( is_readable($file) ) { - if ( !($fh = fopen($file, 'r')) ) { + if (is_readable($file)) { + if (!($fh = fopen($file, 'r'))) { return false; } From 2f3732e35074503c806ec3060fa56721757602cd Mon Sep 17 00:00:00 2001 From: William Knauss Date: Thu, 5 Jun 2014 20:53:19 -0400 Subject: [PATCH 18/18] _wfile --- parsecsv.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsecsv.lib.php b/parsecsv.lib.php index fb36e9f..5dafcd5 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -1179,11 +1179,11 @@ class parseCSV { * @return true or false */ protected function _wfile ($file, $string = '', $mode = 'wb', $lock = 2) { - if ( $fp = fopen($file, $mode) ) { + if ($fp = fopen($file, $mode)) { flock($fp, $lock); $re = fwrite($fp, $string); $re2 = fclose($fp); - if ( $re != false && $re2 != false ) { + if ($re != false && $re2 != false) { return true; } }