Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 12 mapcode_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ function decodeTriple($input)
$c1 = decodeChar($input);
$x = decodeBase31(substr($input, 1));
if ($x < 0) {
return 0;
return null;
}
if ($c1 < 24) {
return new Coord((int)($c1 / 6) * 34 + (int)($x % 34), ($c1 % 6) * 28 + (int)($x / 34));
Expand Down Expand Up @@ -781,7 +781,7 @@ function decodeGrid($input, $extensionchars, $m)

if ($postfixlength == 3) {
$d = decodeTriple($rest);
if ($d == 0) {
if (!$d) {
return new MapcodeZone();
}
$difx = $d->lon;
Expand Down Expand Up @@ -961,7 +961,7 @@ function decodeAutoHeader($input, $extensionchars, $m)
}
$value *= (961 * 31);
$triple = decodeTriple(substr($input, strlen($input) - 3));
if ($triple == 0) {
if (!$triple) {
return new MapcodeZone();
}
for (; Codex($m) == $codexm; $m++) {
Expand Down Expand Up @@ -1239,7 +1239,7 @@ function to_ascii($str)
}
$p = strrpos($result, ' ');
if ($p === false) $p = 0; else $p++;
if ($result[$p] == 'A') {
if ((strlen($result)) && ($result[$p] == 'A')) {
$result = substr($result, 0, $p) . aeu_pack(aeu_unpack(substr($result, $p)));
}
return $result;
Expand Down Expand Up @@ -1454,7 +1454,7 @@ function decode($mapcodeString, $territory = -1)
} else {
return master_decode($mapcodeString, $contextTerritoryNumber);
}
return 0;
return null;
}

function encodeSixWide($x, $y, $width, $height)
Expand Down Expand Up @@ -1783,7 +1783,7 @@ function mapcoderEngine($enc, $tn, $getshortest, $isrecursive, $state_override,
if (is_numeric($tn) && $tn >= 0 && $tn <= $uptoRun) {
$fromRun = $tn;
$uptoRun = $tn;
} else if ($GLOBALS['redivar']) {
} else if (array_key_exists('redivar', $GLOBALS)) {
$use_redivar = 1;
$HOR = 1;
$i = 0; // pointer into redivar
Expand Down
8 changes: 6 additions & 2 deletions 8 sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@

echo '<H1>Mapcode PHP version ' . mapcode_phpversion . ' example</H1>';

$input = trim($_REQUEST["s"]);
if (array_key_exists('s', $_REQUEST)) {
$input = trim($_REQUEST["s"]);
} else {
$input = NULL;
}
if ($input != NULL) {
//$input = utf8_decode(mb_convert_encoding($input,"utf-8" ));
if (strpos($input, ',') !== false) // contains a comma, so assume coordinates
Expand All @@ -60,7 +64,7 @@
echo ' (romanized as ' . $asc . ')';
}
$d = decode($input);
if ($d == 0) {
if (!$d) {
echo '<BR>is not a valid mapcode<BR>';
if (strpos($input, ' ') === false) {
echo '(did you include the territory?)<BR>';
Expand Down
21 changes: 15 additions & 6 deletions 21 unittest/unittest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function progress(id, x, total) {
include 'test_territories.php';
include 'test_encodes.php';

ini_set('max_execution_time', 300);
set_time_limit(300);
ini_set('max_execution_time', 1200);
set_time_limit(1200);

echo "Mapcode Unittest version 2.2<BR>";
echo "Mapcode PHP version " . mapcode_phpversion . "<BR>";
Expand Down Expand Up @@ -167,7 +167,7 @@ function test_encode_decode($str, $y, $x, $localsolutions, $globalsolutions)
$str = $r[$i];
// check if every solution decodes
$p = decode($str);
if ($p == 0) {
if (!$p) {
$GLOBALS['nrErrors']++;
echo '*** ERROR *** decode(' . $str . ') = no result. expected ~(' . number_format($y, 14) . ' . ' . number_format($x, 14) . ')<BR>';
} else {
Expand Down Expand Up @@ -340,7 +340,12 @@ function test_encodes()
while ($t[$n * 5] !== false) $n++;

// executed (optionally, from "start" parameter)
$i = intval($_GET["start"]) - 1;
if (array_key_exists("start", $_GET)) {
$i = intval($_GET["start"]) - 1;
} else {
$i = 0;
}

if ($i < 0) $i = 0;
$nextlevel = $i;
while ($i <= $n) {
Expand Down Expand Up @@ -419,7 +424,7 @@ function territory_code_tests()
"USA", -1, "US OTHER TEXT",
"USA", -1, " US OTHER TEXT ",
"US-CA", -1, "US-CA",
"US-CA", -1 - 1, "US-CA OTHER TEXT",
"US-CA", -1, "US-CA OTHER TEXT",
"US-CA", -1, "USA-CA",
"RU-TT", -1, "RUS-TAM",
-1, -1, "RUS-TAMX",
Expand Down Expand Up @@ -498,7 +503,11 @@ function test_corner_encodes()

echo '<HR>Edge encode/decode tests <font id="prog1">0</font>%<BR>';
{
$i = intval($_GET["edge"]);
if (array_key_exists("edge", $_GET)) {
$i = intval($_GET["edge"]);
} else {
$i = 0;
}
if ($i > 0) $GLOBALS['next_corner_to_test'] = $i;
while (test_corner_encodes()) ;
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.