protected function processCSSExternalReferences(&$cssFile, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $cssDir = "")
{
if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) {
return false;
}
$backPath = preg_replace('#[^/]+/#i', "../", $cssDir);
$imgs = null;
preg_match_all('#url\\s*\\([\'\\"\\s]*(.+?)[\'\\"\\s]*\\)#im', $cssFile, $imgs, PREG_SET_ORDER);
$itemCount = count($imgs);
for ($idx = 0; $idx < $itemCount; $idx++) {
$img = $imgs[$idx];
if ($externalReferences === EPub::EXTERNAL_REF_REMOVE_IMAGES || $externalReferences === EPub::EXTERNAL_REF_REPLACE_IMAGES) {
$cssFile = str_replace($img[0], "", $cssFile);
} else {
$source = $img[1];
$pathData = pathinfo($source);
$internalSrc = $pathData['basename'];
$internalPath = "";
$isSourceExternal = false;
if ($this->resolveImage($source, $internalPath, $internalSrc, $isSourceExternal, $baseDir, $cssDir)) {
$cssFile = str_replace($img[0], "url('" . $backPath . $internalPath . "')", $cssFile);
} elseif ($isSourceExternal) {
$cssFile = str_replace($img[0], "", $cssFile);
// External image is missing
}
// else do nothing, if the image is local, and missing, assume it's been generated.
}
}
return true;
}