function archive_path_for_sheet(&$sheet) { $root = $GLOBALS['cfg']['import_archive_root']; $user_root = _archive_explode_id($sheet['user_id']); $ymd = gmdate('Ymd', $sheet['created']); $map = formats_valid_import_map(); $ext = $map[$sheet['mime_type']]; $fname = "{$sheet['id']}.{$ext}"; $parts = array($root, $user_root, $ymd, $fname); return implode("/", $parts); }
function formats_valid_import_list($sep = ', ') { $map = formats_valid_import_map('key by extension'); $things_with_geo = array('json', 'rss'); $list = array(); foreach (array_keys($map) as $format) { $prefix = ''; if (in_array($format, $things_with_geo)) { $prefix = 'Geo'; } $list[] = $prefix . strtoupper($format); } sort($list); return implode($sep, $list); }
if (count($pre_process['errors'])) { $_errors = array(); foreach ($pre_process['errors'] as $e) { $_errors[$e['record']] = $e; } $pre_process['errors'] = $_errors; } $GLOBALS['smarty']->assign_by_ref("pre_process", $pre_process); } } # # Everything looks good, so let's try to talk to the database. # Note the part where we're also re-assign $step (below). # if ($ok) { $GLOBALS['smarty']->assign('step', 'import'); $more = array('return_dots' => 0, 'dots_index_on' => $dots_index_on, 'label' => $label, 'mark_all_private' => $private, 'mime_type' => $mime_type, 'fingerprint' => $fingerprint, 'simplified' => $simplified); $import = import_process_data($GLOBALS['cfg']['user'], $data, $more); $GLOBALS['smarty']->assign_by_ref("import", $import); } } else { # nuthin' } } } $import_formats = formats_valid_import_map('key by extension'); $GLOBALS['smarty']->assign_by_ref("import_formats", $import_formats); $import_formats_pretty = formats_pretty_import_names_map(); $GLOBALS['smarty']->assign_by_ref("import_formats_pretty", $import_formats_pretty); $smarty->display("page_upload3.txt"); exit;
function import_process_file(&$file) { # Is this something that we are going to try parsing with # ogre (assuming it's been enabled). If it has then it will # return GeoJSON and we'll just carry on pretending that's # what the file is. $use_ogre = 0; if ($GLOBALS['cfg']['enable_feature_ogre']) { $ogre_map = formats_valid_ogre_import_map(); if (isset($ogre_map[$file['type']])) { $use_ogre = 1; } } if ($use_ogre) { $new_path = "{$file['path']}.{$file['extension']}"; rename($file['path'], $new_path); $file['path'] = $new_path; loadlib("geo_ogre"); $rsp = geo_ogre_convert_file($file['path']); if (!$rsp['ok']) { $rsp['details'] = $rsp['error']; $rsp['error'] = 'ogre_fail'; return $rsp; } $fh = fopen($file['path'], 'w'); fwrite($fh, json_encode($rsp['data'])); fclose($fh); $map = formats_valid_import_map("key by extension"); $old_path = $file['path']; $new_path = str_replace(".{$file['extension']}", ".json", $file['path']); rename($old_path, $new_path); $file = array('path' => $new_path, 'name' => basename($new_path), 'size' => filesize($new_path), 'extension' => 'json', 'type' => $map['json']); } # # Basic setup stuff # $rsp = array('ok' => 0); $more = array(); if ($max = $GLOBALS['cfg']['import_max_records']) { $more['max_records'] = $max; } # # CAN HAZ FILE? # $fh = fopen($file['path'], 'r'); if (!$fh) { return array('ok' => 0, 'error' => 'failed to open file'); } # # Store the $file hash we're passing around. It may be the case # that some import related libraries do not have functions for # working with filehandles (DOMDocument for example...wtf?) # $more['file'] = $file; # # Okay, now figure what we need to load and call. We # do this by asking the import map for an extension # corresponding to the file's mime-type (note: at some # point we may need to make this a bit more fine-grained # but today we don't) and then load lib_EXTENSION and # call that library's 'parse_fh' function. # $map = formats_valid_import_map(); $type = $map[$file['type']]; $func = "{$type}_parse_fh"; # # HEY LOOK! THIS PART IS IMPORTANT!! It is left to the # format specific libraries to sanitize both field names # and values (using lib_sanitize). This is *not* a # question of validating the data (checking lat/lon # ranges etc.) but just making sure that the user isn't # passing in pure crap. Take a look at the parse_fh function # in lib_csv for an example of how/what to do. # loadlib($type); $rsp = call_user_func_array($func, array($fh, $more)); # sudo put me in a function? (20110610/straup) # made it a function (20110707 | seanc) if ($rsp['ok']) { $rsp = import_preprocess_address_fields($rsp); /* loadlib("dots_address"); $needs_geocoding = 0; # note the pass-by-ref on $row foreach ($rsp['data'] as &$row){ if (($row['latitude']) && ($row['longitude'])){ $row['_has_latlon'] = 1; continue; } $row['_has_latlon'] = 0; $row['_address'] = dots_address_parse_for_geocoding($row); $needs_geocoding += 1; } $rsp['needs_geocoding'] = $needs_geocoding; */ } # TO DO: check $GLOBALS['cfg'] to see whether we should # store a permanent copy of $file['tmp_name'] somewhere # on disk. It would be nice to store it with the sheet # ID the data has been associated which we don't have # yet so maybe this isn't the best place to do the storing... # (2010107/straup) return $rsp; }