PHPePub\Core\EPub::processCSSExternalReferences PHP Method

processCSSExternalReferences() protected method

$externalReferences determins how the function will handle external references.
protected processCSSExternalReferences ( &$cssFile, integer $externalReferences = EPub::EXTERNAL_REF_ADD, string $baseDir = "", string $cssDir = "" ) : boolean
$externalReferences integer How to handle external references, EPub::EXTERNAL_REF_IGNORE, EPub::EXTERNAL_REF_ADD or EPub::EXTERNAL_REF_REMOVE_IMAGES? Default is EPub::EXTERNAL_REF_ADD.
$baseDir string Default is "", meaning it is pointing to the document root.
$cssDir string The of the CSS file's directory from the root of the archive.
return boolean FALSE if unsuccessful (book is finalized or $externalReferences == EXTERNAL_REF_IGNORE).
    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;
    }