Really Simple CSV Importer (WordPress-Plugin) - Polylang, Custom Post Type and Custom Taxonomy support and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1000 B

<?php
/**
* A helper class for get data from CSV files.
*
* @package Really Simple CSV Importer
*/
class RS_CSV_Helper {
public function parse_columns(&$obj, $array) {
if (!is_array($array) || count($array) == 0)
return false;
$bom = pack("CCC", 0xef, 0xbb, 0xbf);
if (0 == strncmp($array[0], $bom, 3)) {
$array[0] = substr($array[0], 3);
}
$keys = array_keys($array);
$values = array_values($array);
$obj->column_indexes = array_combine($values, $keys);
$obj->column_keys = array_combine($keys, $values);
}
public function get_data($obj, &$array, $key) {
if (!isset($obj->column_indexes) || !is_array($array) || count($array) == 0)
return false;
if (isset($obj->column_indexes[$key])) {
$index = $obj->column_indexes[$key];
if (isset($array[$index]) && !empty($array[$index])) {
$value = $array[$index];
unset($array[$index]);
return $value;
} elseif (isset($array[$index])) {
unset($array[$index]);
}
}
return false;
}
}