From f286156c8e41f57d2dcccc4bb08cc2ca4ccdec8d Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 07:58:17 +0530 Subject: [PATCH 1/7] No need to assign to any variable, we only need to ignore the next 4 bytes --- libraries/import/shp.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index c3439a58f3..f992623c86 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -162,8 +162,7 @@ if (isset($plugin_list)) { function _loadHeaders() { $this->recordNumber = loadData("N", readFromBuffer(4)); - //We read the length of the record - $tmp = loadData("N", readFromBuffer(4)); + readFromBuffer(4); $this->shapeType = loadData("V", readFromBuffer(4)); } From 8bcbf0f688790738bd0ebf7becf3f88a578eeadd Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:01:34 +0530 Subject: [PATCH 2/7] Add missing tags --- libraries/import/shp.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index f992623c86..965c2bc2f6 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -64,6 +64,9 @@ if (isset($plugin_list)) { * 2) To use PMA_importGetNextChunk() functionality to read data, rather than * reading directly from a file. Using readFromBuffer() in place of fread(). * This makes it possible to use compressions. + * + * @package PhpMyAdmin-Import + * @subpackage ESRI_Shape */ class PMA_ShapeFile extends ShapeFile { @@ -126,6 +129,9 @@ if (isset($plugin_list)) { * 2) To use PMA_importGetNextChunk() functionality to read data, rather than * reading directly from a file. Using readFromBuffer() in place of fread(). * This makes it possible to use compressions. + * + * @package PhpMyAdmin-Import + * @subpackage ESRI_Shape */ class PMA_ShapeRecord extends ShapeRecord { From 8e78aaad08fadbd5a0a611608209e578da3a56e7 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:26:21 +0530 Subject: [PATCH 3/7] Add documentation comments --- libraries/import/shp.php | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index 965c2bc2f6..cfbba3fb63 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -70,11 +70,25 @@ if (isset($plugin_list)) { */ class PMA_ShapeFile extends ShapeFile { + /** + * Returns whether the 'dbase' is loaded + * + * @return whether the 'dbase' is loaded + */ function _isDbaseLoaded() { return extension_loaded('dbase'); } + /** + * Loads ESRI shape data from the imported file + * + * @param string $FileName not used, it's here only to match the method + * signature of the method being overidden + * + * @return void + * @see ShapeFile::loadFromFile() + */ function loadFromFile($FileName) { $this->_loadHeaders(); @@ -84,6 +98,12 @@ if (isset($plugin_list)) { } } + /** + * Loads metadata from the ESRI shape file header + * + * @return void + * @see ShapeFile::_loadHeaders() + */ function _loadHeaders() { readFromBuffer(24); @@ -103,6 +123,12 @@ if (isset($plugin_list)) { } } + /** + * Loads geometry data from the ESRI shape file + * + * @return void + * @see ShapeFile::_loadRecords() + */ function _loadRecords() { global $eof; @@ -135,6 +161,15 @@ if (isset($plugin_list)) { */ class PMA_ShapeRecord extends ShapeRecord { + /** + * Loads a geometry data record from the file + * + * @param object &$SHPFile .shp file + * @param object &$DBFFile .dbf file + * + * @return void + * @see ShapeRecord::loadFromFile() + */ function loadFromFile(&$SHPFile, &$DBFFile) { $this->DBFFile = $DBFFile; @@ -165,6 +200,12 @@ if (isset($plugin_list)) { } } + /** + * Loads metadata from the ESRI shape record header + * + * @return void + * @see ShapeRecord::_loadHeaders() + */ function _loadHeaders() { $this->recordNumber = loadData("N", readFromBuffer(4)); @@ -172,6 +213,12 @@ if (isset($plugin_list)) { $this->shapeType = loadData("V", readFromBuffer(4)); } + /** + * Loads data from a point reocrd + * + * @return void + * @see ShapeRecord::_loadPoint() + */ function _loadPoint() { $data = array(); @@ -182,6 +229,12 @@ if (isset($plugin_list)) { return $data; } + /** + * Loads data from a multipoint record + * + * @return void + * @see ShapeRecord::_loadMultiPointRecord() + */ function _loadMultiPointRecord() { $this->SHPData = array(); @@ -197,6 +250,12 @@ if (isset($plugin_list)) { } } + /** + * Loads data from a polyline record + * + * @return void + * @see ShapeRecord::_loadPolyLineRecord() + */ function _loadPolyLineRecord() { $this->SHPData = array(); From 0ae196277abc08455cd01f68db20c0dff4e7a0f9 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:30:15 +0530 Subject: [PATCH 4/7] Wrap some long lines --- libraries/import/shp.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index cfbba3fb63..0a2210eb52 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -31,7 +31,9 @@ if (isset($plugin_list)) { // Append the bfShapeFiles directory to the include path variable - set_include_path(get_include_path() . PATH_SEPARATOR . getcwd() . '/libraries/bfShapeFiles/'); + set_include_path( + get_include_path() . PATH_SEPARATOR . getcwd() . '/libraries/bfShapeFiles/' + ); include_once './libraries/bfShapeFiles/ShapeFile.lib.php'; $GLOBALS['finished'] = false; @@ -283,7 +285,8 @@ if (isset($plugin_list)) { while (! in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) ) { - $this->SHPData["parts"][$partIndex]["points"][] = $this->_loadPoint(); + $this->SHPData["parts"][$partIndex]["points"][] + = $this->_loadPoint(); $readPoints++; } } @@ -293,7 +296,9 @@ if (isset($plugin_list)) { $shp = new PMA_ShapeFile(1); // If the zip archive has more than one file, // get the correct content to the buffer from .shp file. - if ($compression == 'application/zip' && PMA_getNoOfFilesInZip($import_file) > 1) { + if ($compression == 'application/zip' + && PMA_getNoOfFilesInZip($import_file) > 1 + ) { $zip_content = PMA_getZipContents($import_file, '/^.*\.shp$/i'); $GLOBALS['import_text'] = $zip_content['data']; } @@ -307,7 +312,9 @@ if (isset($plugin_list)) { && ! empty($cfg['TempDir']) && is_writable($cfg['TempDir']) ) { - $dbf_file_name = PMA_findFileFromZipArchive('/^.*\.dbf$/i', $import_file); + $dbf_file_name = PMA_findFileFromZipArchive( + '/^.*\.dbf$/i', $import_file + ); // If the corresponding .dbf file is in the zip archive if ($dbf_file_name) { // Extract the .dbf file and point to it. @@ -320,8 +327,11 @@ if (isset($plugin_list)) { $dbf_file_path = realpath($cfg['TempDir']) . (PMA_IS_WINDOWS ? '\\' : '/') . $dbf_file_name; $temp_dbf_file = true; - // Replace the .dbf with .*, as required by the bsShapeFiles library. - $file_name = substr($dbf_file_path, 0, strlen($dbf_file_path) - 4) . '.*'; + // Replace the .dbf with .*, as required + // by the bsShapeFiles library. + $file_name = substr( + $dbf_file_path, 0, strlen($dbf_file_path) - 4 + ) . '.*'; $shp->FileName = $file_name; } } @@ -418,7 +428,8 @@ if (isset($plugin_list)) { if ($gis_obj == null) { $tempRow[] = null; } else { - $tempRow[] = "GeomFromText('" . $gis_obj->getShape($record->SHPData) . "')"; + $tempRow[] = "GeomFromText('" + . $gis_obj->getShape($record->SHPData) . "')"; } if (isset($shp->DBFHeader)) { From 3603ac703fe36ce5e9ac0d95c855ac6828f723ae Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:40:48 +0530 Subject: [PATCH 5/7] Make a message translatable --- libraries/import/shp.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index 0a2210eb52..dfa0dda0a6 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -194,7 +194,12 @@ if (isset($plugin_list)) { $this->_loadMultiPointRecord(); break; default: - $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); + $this->setError( + sprintf( + __("Geometry type '%s' is not supported by MySQL."), + $this->shapeType + ) + ); break; } if (extension_loaded('dbase') && isset($this->DBFFile)) { From e53858ba724910623e85c02f4ad9138c1c592d4d Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:43:37 +0530 Subject: [PATCH 6/7] Typo --- libraries/import/shp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index dfa0dda0a6..18f009f658 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -221,7 +221,7 @@ if (isset($plugin_list)) { } /** - * Loads data from a point reocrd + * Loads data from a point record * * @return void * @see ShapeRecord::_loadPoint() From 22194ad787c93888724919205547178e774da8c2 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 6 May 2012 08:44:34 +0530 Subject: [PATCH 7/7] Better doc comment --- libraries/import/shp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/import/shp.php b/libraries/import/shp.php index 18f009f658..3b8703712f 100644 --- a/libraries/import/shp.php +++ b/libraries/import/shp.php @@ -73,9 +73,9 @@ if (isset($plugin_list)) { class PMA_ShapeFile extends ShapeFile { /** - * Returns whether the 'dbase' is loaded + * Returns whether the 'dbase' extension is loaded * - * @return whether the 'dbase' is loaded + * @return whether the 'dbase' extension is loaded */ function _isDbaseLoaded() {