diff --git a/src/MprIcons.php b/src/MprIcons.php index 0804a14..f8771ef 100644 --- a/src/MprIcons.php +++ b/src/MprIcons.php @@ -404,15 +404,31 @@ class MprIcons if (!file_exists($cssFile)) { continue; } - // Read first 50KB — font-face is always near the top + // Minified theme.css can be 200KB+; font-face may be at ~85KB + // Read in 100KB chunks, scan up to 200KB $handle = fopen($cssFile, 'r'); if ($handle) { - $chunk = fread($handle, 51200); + $hasMaterial = false; + $hasFA = false; + $bytesRead = 0; + while (!feof($handle) && $bytesRead < 204800) { + $chunk = fread($handle, 102400); + $bytesRead += strlen($chunk); + if (!$hasMaterial && stripos($chunk, 'Material Icons') !== false) { + $hasMaterial = true; + } + if (!$hasFA && stripos($chunk, 'FontAwesome') !== false) { + $hasFA = true; + } + if ($hasMaterial || $hasFA) { + break; + } + } fclose($handle); - if (stripos($chunk, 'Material Icons') !== false) { + if ($hasMaterial) { return self::MATERIAL; } - if (stripos($chunk, 'FontAwesome') !== false) { + if ($hasFA) { return self::FA; } } @@ -481,9 +497,18 @@ class MprIcons } $handle = fopen($cssFile, 'r'); if ($handle) { - $chunk = fread($handle, 51200); + $found = false; + $bytesRead = 0; + while (!feof($handle) && $bytesRead < 204800) { + $chunk = fread($handle, 102400); + $bytesRead += strlen($chunk); + if (stripos($chunk, $needle) !== false) { + $found = true; + break; + } + } fclose($handle); - if (stripos($chunk, $needle) !== false) { + if ($found) { return true; } }