diff --git a/views/load_twt_files.php b/views/load_twt_files.php index d183c6f..68acd17 100644 --- a/views/load_twt_files.php +++ b/views/load_twt_files.php @@ -33,16 +33,18 @@ if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { die('Not a valid URL'); } -echo "Loading URL: $url
\n
\n"; -#ob_flush(); +echo '
'; +echo ''; + +ob_flush(); const DEBUG_TIME_SECS = 300; const PRODUCTION_TIME_SECS = 5; $fileContent = getCachedFileContentsOrUpdate($url, PRODUCTION_TIME_SECS); $fileContent = mb_convert_encoding($fileContent, 'UTF-8'); - $fileLines = explode("\n", $fileContent); +// Build Following List $twtFollowingList = []; foreach ($fileLines as $currentLine) { @@ -53,55 +55,32 @@ foreach ($fileLines as $currentLine) { } } -# Load all the files -# Save a flag to know it's loading files in the background -/* -foreach ($twtFollowingList as $following) { - echo "Updating: $following[1]
\n"; - #ob_flush(); - flush(); - updateCachedFile($following[1]); -} -*/ -//echo 'Finished'; -//ob_flush(); - -//header('Location: /'); -//exit(); - -/* from: https://github.com/w3shaman/php-progress-bar */ - -echo '
'; - -echo '
'; +/* Progress bar based on: https://github.com/w3shaman/php-progress-bar */ $i = 1; +$total = count($twtFollowingList); foreach ($twtFollowingList as $following) { - $total = count($twtFollowingList); - // Calculate the percentation - $percent = intval($i/$total * 100)."%"; + $float = $i/$total; + $percent = intval($float * 100)."%"; // Javascript for updating the progress bar and information echo ''; + document.getElementById("refreshLabel").innerHTML = "Updating: '.$following[1].' ('.$i.'/'.$total.')"; + document.getElementById("refreshProgress").value = "'.$float.'"; + document.getElementById("refreshProgress").innerHTML = "'.$percent.'"; + '; - -// This is for the buffer achieve the minimum size in order to flush data + updateCachedFile($following[1]); - echo "Updating: $following[1]"." (".$i."/".$total.")
\n"; - updateCachedFile($following[1]); - -// Send output to browser immediately - flush(); + ob_flush(); // Send output to browser immediately $i++; } -echo 'Finished'; - // Tell user that the process is completed -echo ''; +echo ''; + +//header('Location: /'); +exit();