diff --git a/php/classes/FilesMgr.php b/php/classes/FilesMgr.php index ccd5555..6b80465 100644 --- a/php/classes/FilesMgr.php +++ b/php/classes/FilesMgr.php @@ -262,7 +262,7 @@ class FilesMgr extends AmdaObjectMgr while (!feof($handler) && !$StartTime) { $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); $elems = explode(' ', $oneLine); - if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) { + if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) { $i++; continue; } @@ -275,8 +275,8 @@ class FilesMgr extends AmdaObjectMgr if (feof($handler)) return -10; $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); - $elems = explode(" ",$oneLine); if (count($elems) < 2) return -10; // dT else Array @@ -297,8 +297,8 @@ class FilesMgr extends AmdaObjectMgr if ($handler) { $i = 0; while (!feof($handler) && !$StartTime) { - $oneLine = trim(fgets($handler)); - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine)); + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) { $i++; continue; @@ -311,8 +311,8 @@ class FilesMgr extends AmdaObjectMgr } if (feof($handle)) return array(-10); - $oneLine = trim(fgets($handler)); - $elems = explode(" ",$oneLine); + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); if (count($elems) < 2) return array (-1); // dT else Array if (!($time = strtotime($elems[0]))) @@ -324,8 +324,9 @@ class FilesMgr extends AmdaObjectMgr while (!feof($handler)) { - $oneLine = trim(fgets($handler)); - $elems = explode(" ",$oneLine); + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); + if (count($elems) < 2) continue; $StartTime = $time; if (!($time = strtotime($elems[0]))) return array(-1); @@ -358,8 +359,9 @@ class FilesMgr extends AmdaObjectMgr $i = 0; while (!$StartTime && !feof($handler)) { - $oneLine = trim(fgets($handler)); - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine)); + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); + if (!($time = strtotime($elems[0]))) { $offset = ftell($handler); @@ -372,9 +374,10 @@ class FilesMgr extends AmdaObjectMgr } $newfile = fopen(USERDATADIR."temp", "w"); - - $oneLine = trim(fgets($handler)); - $elems = explode(" " , $oneLine); + + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); + // dT if (!($time = strtotime($elems[0]))) { @@ -384,8 +387,8 @@ class FilesMgr extends AmdaObjectMgr $newtime += $dt; while (!feof($handler)) - { - $oneLine = trim(fgets($handler)); + { + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL); $newtime += $dt; } @@ -395,9 +398,9 @@ class FilesMgr extends AmdaObjectMgr { fseek($handler, $offset); while (!feof($handler)) - { - $oneLine = trim(fgets($handler)); - $elems = explode(" " ,$oneLine); + { + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); + $elems = explode(' ',$oneLine); // empty lines if (count($elems) < 2) continue; $newtime = strtotime($elems[0]); @@ -445,18 +448,18 @@ class FilesMgr extends AmdaObjectMgr $newfile = fopen(USERDATADIR."temp", "w"); while (!feof($handle)) { - if (($oneLine = fgets($handle)) !== false) + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handle))); + + if ($oneLine !== false) { - $line = $timeLength == 'auto' ? $line = trim(preg_replace('/\s+/', ' ', $oneLine)) : trim($oneLine); - - if (strlen($line) > $formatLength) + if (strlen($oneLine) > $formatLength) { try { - $date = DateTime::createFromFormat($timeFormat, trim(substr($line,0,$formatLength))); + $date = DateTime::createFromFormat($timeFormat, trim(substr($oneLine,0,$formatLength))); if (!$date) { - if (strpos($line,'#') === 0) fwrite($newfile, $line.PHP_EOL); + if (strpos($oneLine,'#') === 0) fwrite($newfile, $oneLine.PHP_EOL); } else { @@ -464,7 +467,7 @@ class FilesMgr extends AmdaObjectMgr if ($doy) { $date->modify('-1 day'); } - $suffix = preg_replace('/\s+/', ' ',substr($line, $formatLength)); + $suffix = preg_replace('/\s+/', ' ',substr($oneLine, $formatLength)); fwrite($newfile,$date->format('Y-m-d')."T".$date->format('H:i:s').$suffix.PHP_EOL); } } @@ -474,7 +477,7 @@ class FilesMgr extends AmdaObjectMgr } } else - if (strpos($line,'#') === 0) fwrite($newfile,$line.PHP_EOL); + if (strpos($oneLine,'#') === 0) fwrite($newfile,$oneLine.PHP_EOL); } } } @@ -485,7 +488,7 @@ class FilesMgr extends AmdaObjectMgr fclose($handle); unlink($this->fileName); } - return $false; + return false; } fclose($newfile); -- libgit2 0.21.2