Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoid PHP, HTML mix. Improve doc comments

  • Loading branch information...
commit 7b12b12aeec1872a90c1f8b938643605efd4d1d7 1 parent 61831e2
@madhuracj madhuracj authored
Showing with 179 additions and 132 deletions.
  1. +179 −132 gis_data_editor.php
View
311 gis_data_editor.php
@@ -1,5 +1,24 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Editor for Geometry data types.
+ *
+ * @package PhpMyAdmin
+ */
+
+/**
+ * Escapes special characters if the variable is set.
+ * Returns an empty string otherwise.
+ *
+ * @param string $variable variable to be escaped
+ *
+ * @return escaped variable
+ */
+function escape($variable)
+{
+ return isset($variable) ? htmlspecialchars($variable) : '';
+}
+
require_once 'libraries/common.inc.php';
require_once 'libraries/gis/pma_gis_factory.php';
require_once 'libraries/gis_visualization.lib.php';
@@ -82,16 +101,19 @@
}
ob_start();
-?>
- <form id="gis_data_editor_form" action="gis_data_editor.php" method="post">
- <input type="hidden" id="pmaThemeImage" value="<?php echo($GLOBALS['pmaThemeImage']); ?>" />
- <div id="gis_data_editor">
- <h3>
-<?php
+
+echo '<form id="gis_data_editor_form" action="gis_data_editor.php" method="post">';
+echo '<input type="hidden" id="pmaThemeImage"'
+ . ' value="' . $GLOBALS['pmaThemeImage'] . '" />';
+echo '<div id="gis_data_editor">';
+
+echo '<h3>';
printf(
- __('Value for the column "%s"'), htmlspecialchars($_REQUEST['field'])
+ __('Value for the column "%s"'),
+ htmlspecialchars($_REQUEST['field'])
);
echo '</h3>';
+
echo '<input type="hidden" name="field" value="'
. htmlspecialchars($_REQUEST['field']) . '" />';
// The input field to which the final result should be added
@@ -101,40 +123,32 @@
. htmlspecialchars($_REQUEST['input_name']) . '" />';
}
echo PMA_generate_common_hidden_inputs();
-?>
- <!-- Visualization section -->
- <div id="placeholder" style="width:450px;height:300px;
-<?php
-if ($srid != 0) {
- echo 'display:none;';
-}
-echo '">' . $visualization;
-?> </div>
- <div id="openlayersmap" style="width:450px;height:300px;
-<?php
-if ($srid == 0) {
- echo 'display:none;';
-}
-?> ">
- </div>
- <div class="choice" style="float:right;clear:right;">
- <input type="checkbox" id="choice" value="useBaseLayer"
-<?php
-if ($srid != 0) {
- echo ' checked="checked"';
-}
-?> />
- <label for="choice"><?php echo __("Use OpenStreetMaps as Base Layer"); ?></label>
- </div>
- <script language="javascript" type="text/javascript">
- <?php echo($open_layers); ?>
- </script>
- <!-- End of visualization section -->
-
- <!-- Header section - Inclueds GIS type selector and input field for SRID -->
- <div id="gis_data_header">
- <select name="gis_data[gis_type]" class="gis_type">
-<?php
+
+echo '<!-- Visualization section -->';
+echo '<div id="placeholder" style="width:450px;height:300px;'
+ . ($srid != 0 ? 'display:none;' : '') . '">';
+echo $visualization;
+echo '</div>';
+
+echo '<div id="openlayersmap" style="width:450px;height:300px;'
+ . ($srid == 0 ? 'display:none;' : '') . '">';
+echo '</div>';
+
+echo '<div class="choice" style="float:right;clear:right;">';
+echo '<input type="checkbox" id="choice" value="useBaseLayer"'
+ . ($srid != 0 ? ' checked="checked"' : '') . '/>';
+echo '<label for="choice">' . __("Use OpenStreetMaps as Base Layer") . '</label>';
+echo '</div>';
+
+echo '<script language="javascript" type="text/javascript">';
+echo $open_layers;
+echo '</script>';
+echo '<!-- End of visualization section -->';
+
+
+echo '<!-- Header section - Inclueds GIS type selector and input field for SRID -->';
+echo '<div id="gis_data_header">';
+echo '<select name="gis_data[gis_type]" class="gis_type">';
foreach ($gis_types as $gis_type) {
echo '<option value="' . $gis_type . '"';
if ($geom_type == $gis_type) {
@@ -142,16 +156,16 @@
}
echo '>' . $gis_type . '</option>';
}
-?>
- </select>
- <label for="srid"><?php echo __("SRID"); ?>:&nbsp;</label>
- <input name="gis_data[srid]" type="text" value="<?php echo($srid); ?>" />
- </div>
- <!-- End of header section -->
-
- <!-- Data section -->
- <div id="gis_data">
-<?php
+echo '</select>';
+echo '&nbsp;&nbsp;&nbsp;&nbsp;';
+echo '<label for="srid">' . __("SRID") . ':</label>';
+echo '<input name="gis_data[srid]" type="text" value="' . $srid . '" />';
+echo '</div>';
+echo '<!-- End of header section -->';
+
+echo '<!-- Data section -->';
+echo '<div id="gis_data">';
+
$geom_count = 1;
if ($geom_type == 'GEOMETRYCOLLECTION') {
$geom_count = (isset($gis_data[$geom_type]['geom_count']))
@@ -160,36 +174,43 @@
$geom_count++;
}
echo '<input type="hidden" name="gis_data[GEOMETRYCOLLECTION][geom_count]"'
- . ' value="' . $geom_count . '">';
+ . ' value="' . $geom_count . '" />';
}
+
for ($a = 0; $a < $geom_count; $a++) {
+
if ($geom_type == 'GEOMETRYCOLLECTION') {
- echo('<br/><br/>'); echo __("Geometry"); echo($a + 1 . ':<br/>');
+ echo '<br/><br/>';
+ echo __("Geometry") . ' ' . ($a + 1) . ': ';
+ echo '<br/>';
if (isset($gis_data[$a]['gis_type'])) {
$type = $gis_data[$a]['gis_type'];
} else {
$type = $gis_types[0];
}
- echo('<select name="gis_data[' . $a . '][gis_type]" class="gis_type">');
+ echo '<select name="gis_data[' . $a . '][gis_type]" class="gis_type">';
foreach (array_slice($gis_types, 0, 6) as $gis_type) {
- echo('<option value="' . $gis_type . '"');
+ echo '<option value="' . $gis_type . '"';
if ($type == $gis_type) {
- echo(' selected="selected"');
+ echo ' selected="selected"';
}
- echo('>' . $gis_type . '</option>');
+ echo '>' . $gis_type . '</option>';
}
- echo('</select>');
+ echo '</select>';
} else {
$type = $geom_type;
}
if ($type == 'POINT') {
- echo('<br/>'); echo __("Point"); echo(' :');
-?> <label for="x"><?php echo __("X"); ?></label>
- <input name="gis_data[<?php echo($a); ?>][POINT][x]" type="text" value="<?php echo(isset($gis_data[$a]['POINT']['x']) ? htmlspecialchars($gis_data[$a]['POINT']['x']) : ''); ?>" />
- <label for="y"><?php echo __("Y"); ?></label>
- <input name="gis_data[<?php echo($a); ?>][POINT][y]" type="text" value="<?php echo(isset($gis_data[$a]['POINT']['y']) ? htmlspecialchars($gis_data[$a]['POINT']['y']) : ''); ?>" />
-<?php
+ echo '<br/>';
+ echo __("Point") . ': ';
+ echo '<label for="x">' . __("X") . '</label>';
+ echo '<input name="gis_data[' . $a . '][POINT][x]" type="text"'
+ . ' value="' . escape($gis_data[$a]['POINT']['x']) . '" />';
+ echo '<label for="y">' . __("Y") . '</label>';
+ echo '<input name="gis_data[' . $a . '][POINT][y]" type="text"'
+ . ' value="' . escape($gis_data[$a]['POINT']['y']) . '" />';
+
} elseif ($type == 'MULTIPOINT' || $type == 'LINESTRING') {
$no_of_points = isset($gis_data[$a][$type]['no_of_points'])
? $gis_data[$a][$type]['no_of_points'] : 1;
@@ -203,22 +224,26 @@
if (isset($gis_data[$a][$type]['add_point'])) {
$no_of_points++;
}
- echo('<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][no_of_points]" value="' . $no_of_points . '">');
+ echo '<input type="hidden" value="' . $no_of_points . '"'
+ . ' name="gis_data[' . $a . '][' . $type . '][no_of_points]" />';
for ($i = 0; $i < $no_of_points; $i++) {
echo '<br/>';
printf(__('Point %d'), $i + 1);
- echo ':';
-?> <label for="x"><?php echo __("X"); ?></label>
- <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][x]" value="<?php echo(isset($gis_data[$a][$type][$i]['x']) ? htmlspecialchars($gis_data[$a][$type][$i]['x']) : ''); ?>" />
- <label for="y"><?php echo __("Y"); ?></label>
- <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][y]" value="<?php echo(isset($gis_data[$a][$type][$i]['y']) ? htmlspecialchars($gis_data[$a][$type][$i]['y']) : ''); ?>" />
-<?php
+ echo ': ';
+ echo '<label for="x">' . __("X") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][x]"'
+ . ' value="' . escape($gis_data[$a][$type][$i]['x']) . '" />';
+ echo '<label for="y">' . __("Y") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][y]"'
+ . ' value="' . escape($gis_data[$a][$type][$i]['y']). '" />';
}
-?>
- <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_point]" class="add addPoint" value="<?php echo __("Add a point"); ?>">
-<?php
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][add_point]"'
+ . ' class="add addPoint" value="' . __("Add a point") . '" />';
+
} elseif ($type == 'MULTILINESTRING' || $type == 'POLYGON') {
$no_of_lines = isset($gis_data[$a][$type]['no_of_lines'])
? $gis_data[$a][$type]['no_of_lines'] : 1;
@@ -228,18 +253,18 @@
if (isset($gis_data[$a][$type]['add_line'])) {
$no_of_lines++;
}
- echo '<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][no_of_lines]" value="' . $no_of_lines . '">';
+ echo '<input type="hidden" value="' . $no_of_lines . '"'
+ . ' name="gis_data[' . $a . '][' . $type . '][no_of_lines]" />';
for ($i = 0; $i < $no_of_lines; $i++) {
echo '<br/>';
if ($type == 'MULTILINESTRING') {
- echo __("Linestring"); echo ($i + 1) . ':';
+ echo __("Linestring") . ' ' . ($i + 1) . ':';
} else {
if ($i == 0) {
echo __("Outer Ring") . ':';
} else {
- echo __("Inner Ring"); echo $i . ':';
+ echo __("Inner Ring") . ' ' . $i . ':';
}
}
@@ -254,26 +279,34 @@
if (isset($gis_data[$a][$type][$i]['add_point'])) {
$no_of_points++;
}
- echo '<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][' . $i . '][no_of_points]" value="' . $no_of_points . '">';
+ echo '<input type="hidden" value="' . $no_of_points . '"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][no_of_points]" />';
for ($j = 0; $j < $no_of_points; $j++) {
echo('<br/>');
printf(__('Point %d'), $j + 1);
- echo ':';
-?> <label for="x"><?php echo __("X"); ?></label>
- <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][x]" value="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['x']) : ''); ?>" />
- <label for="y"><?php echo __("Y"); ?></label>
- <input type="text" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][<?php echo($j); ?>][y]" value="<?php echo(isset($gis_data[$a][$type][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$i][$j]['y']) : ''); ?>" />
-<?php
+ echo ': ';
+ echo '<label for="x">' . __("X") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][' . $j . '][x]"'
+ . ' value="' . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
+ echo '<label for="y">' . __("Y") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][' . $j . '][y]"'
+ . ' value="' . escape($gis_data[$a][$type][$i][$j]['x']) . '" />';
}
-?> <input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][<?php echo($i); ?>][add_point]" class="add addPoint" value="<?php echo __("Add a point"); ?>">
-<?php
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $i . '][add_point]"'
+ . ' class="add addPoint" value="' . __("Add a point") . '" />';
}
$caption = ($type == 'MULTILINESTRING')
- ? __('Add a linestring') : __('Add an inner ring');
-?> <br/><input type="submit" name="gis_data[<?php echo($a); ?>][<?php echo($type); ?>][add_line]" class="add addLine" value="<?php echo($caption); ?>">
-<?php
+ ? __('Add a linestring')
+ : __('Add an inner ring');
+ echo '<br/>';
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][add_line]"'
+ . ' class="add addLine" value="' . $caption . '" />';
+
} elseif ($type == 'MULTIPOLYGON') {
$no_of_polygons = isset($gis_data[$a][$type]['no_of_polygons'])
? $gis_data[$a][$type]['no_of_polygons'] : 1;
@@ -283,11 +316,13 @@
if (isset($gis_data[$a][$type]['add_polygon'])) {
$no_of_polygons++;
}
- echo('<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][no_of_polygons]" value="' . $no_of_polygons . '">');
+ echo '<input type="hidden"'
+ . ' name="gis_data[' . $a . '][' . $type . '][no_of_polygons]"'
+ . ' value="' . $no_of_polygons . '" />';
for ($k = 0; $k < $no_of_polygons; $k++) {
- echo('<br/>'); echo __("Polygon"); echo($k + 1 . ':');
+ echo '<br/>';
+ echo __("Polygon") . ' ' . ($k + 1) . ':';
$no_of_lines = isset($gis_data[$a][$type][$k]['no_of_lines'])
? $gis_data[$a][$type][$k]['no_of_lines'] : 1;
if ($no_of_lines < 1) {
@@ -296,15 +331,16 @@
if (isset($gis_data[$a][$type][$k]['add_line'])) {
$no_of_lines++;
}
- echo('<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][' . $k . '][no_of_lines]" value="' . $no_of_lines . '">');
+ echo '<input type="hidden"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][no_of_lines]"'
+ . ' value="' . $no_of_lines . '" />';
for ($i = 0; $i < $no_of_lines; $i++) {
- echo('<br/><br/>');
+ echo '<br/><br/>';
if ($i == 0) {
echo __("Outer Ring") . ':';
} else {
- echo __("Inner Ring"); echo($i . ':');
+ echo __("Inner Ring") . ' ' . $i . ':';
}
$no_of_points = isset($gis_data[$a][$type][$k][$i]['no_of_points'])
@@ -315,54 +351,65 @@
if (isset($gis_data[$a][$type][$k][$i]['add_point'])) {
$no_of_points++;
}
- echo('<input type="hidden" name="gis_data[' . $a . '][' . $type
- . '][' . $k . '][' . $i . '][no_of_points]" value="'
- . $no_of_points . '">');
+ echo '<input type="hidden"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][no_of_points]"'
+ . ' value="' . $no_of_points . '" />';
for ($j = 0; $j < $no_of_points; $j++) {
- echo('<br/>');
+ echo '<br/>';
printf(__('Point %d'), $j + 1);
- echo ':';
-?> <label for="x"><?php echo __("X"); ?></label>
- <input type="text" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][x]"); ?>" value="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['x']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['x']) : ''); ?>" />
- <label for="y"><?php echo __("Y"); ?></label>
- <input type="text" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][" . $j . "][y]"); ?>" value="<?php echo(isset($gis_data[$a][$type][$k][$i][$j]['y']) ? htmlspecialchars($gis_data[$a][$type][$k][$i][$j]['y']) : ''); ?>" />
-<?php
+ echo ': ';
+ echo '<label for="x">' . __("X") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][' . $j . '][x]"'
+ . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['x']). '" />';
+ echo '<label for="y">' . __("Y") . '</label>';
+ echo '<input type="text"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][' . $j . '][y]"'
+ . ' value="' . escape($gis_data[$a][$type][$k][$i][$j]['y']) . '" />';
}
-?> <input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][" . $i . "][add_point]"); ?>" class="add addPoint" value="<?php echo __("Add a point"); ?>">
-<?php
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][' . $i . '][add_point]"'
+ . ' class="add addPoint" value="' . __("Add a point") . '" />';
}
-?> <br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][" . $k . "][add_line]"); ?>" class="add addLine" value="<?php echo __('Add an inner ring') ?>"><br/>
-<?php
+ echo '<br/>';
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][' . $k . '][add_line]"'
+ . ' class="add addLine" value="' . __('Add an inner ring'). '" />';
+ echo '<br/>';
}
-?> <br/><input type="submit" name="<?php echo("gis_data[" . $a . "][" . $type . "][add_polygon]"); ?>" class="add addPolygon" value="<?php echo __('Add a polygon') ?>">
-<?php
+ echo '<br/>';
+ echo '<input type="submit"'
+ . ' name="gis_data[' . $a . '][' . $type . '][add_polygon]"'
+ . ' class="add addPolygon" value="' . __('Add a polygon') . '" />';
}
}
if ($geom_type == 'GEOMETRYCOLLECTION') {
-?> <br/><br/><input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]" class="add addGeom" value="<?php echo __("Add geometry"); ?>" />
-<?php
+ echo '<br/><br/>';
+ echo '<input type="submit" name="gis_data[GEOMETRYCOLLECTION][add_geom]"'
+ . 'class="add addGeom" value="' . __("Add geometry") . '" />';
}
-?> </div>
- <!-- End of data section -->
+echo '</div>';
+echo '<!-- End of data section -->';
+
+echo '<br/>';
+echo '<input type="submit" name="gis_data[save]" value="' . __('Go') . '" />';
- <br/><input type="submit" name="gis_data[save]" value="<?php echo __('Go') ?>">
- <div id="gis_data_output">
- <h3><?php echo __('Output'); ?></h3>
- <p><?php
+echo '<div id="gis_data_output">';
+echo '<h3>' . __('Output') . '</h3>';
+echo '<p>';
echo __(
'Choose "GeomFromText" from the "Function" column and paste the'
. ' string below into the "Value" field'
-);
-?></p>
- <textarea id="gis_data_textarea" cols="95" rows="5">
-<?php
+);
+echo '</p>';
+echo '<textarea id="gis_data_textarea" cols="95" rows="5">';
echo $result;
-?> </textarea>
- </div>
- </div>
- </form>
-<?php
+echo '</textarea>';
+echo '</div>';
+
+echo '</div>';
+echo '</form>';
PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
ob_end_clean();
Please sign in to comment.
Something went wrong with that request. Please try again.