insertLineBreaks got " . $text;
$brString = "<br>";
$curPosition = 0;
$textPieces = explode($brString, $text);
$textPiecesLength = count($textPieces);
for ($i = 0; $i < $textPiecesLength; $i++) {
$curString = $textPieces[$i];
print "
text piece $i is $curString";
$lastInsertedBr = 0;
print "
curString length is " . strlen($curString);
while ((strlen($curString) - $lastInsertedBr) > $textSplitSize) {
print "
looking for spaces...";
// Start looking for spaces starting at $lastInsertedPos.
$maxInsertedPosition = $lastInsertedBr + $textSplitSize;
$lastSpacePos = $lastInsertedBr;
$oldLastSpacePos = $lastInsertedBr;
print "
begin: lastSpacePos is $lastSpacePos";
while (($lastSpacePos <= $maxInsertedPosition) && !($lastSpacePos === false)) {
$oldLastSpacePos = $lastSpacePos;
$lastSpacePos = strpos($curString, ' ', $lastSpacePos + 1);
print "
now lastSpacePos is $lastSpacePos";
}
if ($oldLastSpacePos == $lastInsertedBr) {
// This is a really long string that we can do nothing about,
// so lie.
print "
giving up";
// Just insert something at the next space.
if ($lastSpacePos === false) {
// There are no more spaces, so do nothing.
$oldLastSpacePos = -1;
} else {
$oldLastSpacePos = $lastSpacePos;
}
}
if ($oldLastSpacePos == -1) {
// Lie to make sure we don't do anything.
$lastInsertedBr = strlen($curString);
} else {
// Use $oldLastSpacePos
$curString = substr($curString, 0, $oldLastSpacePos) . $brString . substr($curString, $oldLastSpacePos+1);
print "
curString is now $curString";
$lastInsertedBr = $oldLastSpacePos + strlen($brString);
print "
lastInsertedBr is now $lastInsertedBr";
}
}
$textPieces[$i] = $curString;
}
print "
insertLineBreaks is returning " . implode($brString, $textPieces);
return implode($brString, $textPieces);
}
print "running script...";
#print "post[addmarker] is: " . $_POST["addmarker"];
print "post[lat] is: " . $_POST["lat"];
//if (isset($_POST["addmarker"])) {
if (isset($_POST["lat"]) && ($_POST["lat"] != "NaN" && $_POST["lng"] != "NaN")) {
// Lock the datakatrina.xml file.
print "inside loop";
$lockFileName = "datakatrinalock";
$fileName = "datakatrina.xml";
$logFileName = "commentlogkatrina";
while (file_exists($lockFileName)) {
usleep(250000);
}
print "got lock";
$lockHandle = fopen($lockFileName, "w");
fwrite($lockHandle, "locked");
fclose($lockHandle);
$fileContents = file($fileName);
$numLines = count($fileContents);
$foundLatLng = false;
if (isset($_POST["append"]) && $_POST["append"] == "1") {
for ($i = 0; ($i < $numLines) && ($foundLatLng == false); $i++) {
$findExistingMarkerRE = "";
$fileContents[$i] = preg_replace($appendCaptionRE, "caption=\"\\1" . unescapeDescription("
" . $_POST["desc"]) . unescapeDescription("
Added: " . date('m/d H:i')) . "\"", $fileContents[$i]);
$foundLatLng = true;
system("echo \"(append)\" >> $logFileName");
}
}
}
if ($foundLatLng == false) {
$fileContents[$numLines] = $fileContents[$numLines-1];
$fileContents[$numLines-1] = "Added: " . date('m/d H:i')) . "\" />\n";
}
system("echo \"At " . date('m/d H:i') . ": " . escapeshellarg($_POST["desc"]) . "\" >> $logFileName");
$fileToWrite = fopen($fileName, "w");
foreach ($fileContents as $line_num => $line) {
fwrite($fileToWrite, $line);
}
fclose($fileToWrite);
unlink($lockFileName);
}
?>