From 0a05f532ec1c07f6c80f3a2275b9b7b5f73a9e6b Mon Sep 17 00:00:00 2001 From: Edward Date: Wed, 19 Feb 2014 17:58:25 +0800 Subject: [PATCH] ConvertStyle.php --- ConvertStyle.php | 71 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/ConvertStyle.php b/ConvertStyle.php index 2de9f770..b4612d42 100644 --- a/ConvertStyle.php +++ b/ConvertStyle.php @@ -93,45 +93,44 @@ class Pman_Core_ConvertStyle extends Pman $doc->formatOutput = true; $xpath = new DOMXpath($doc); -// foreach ($xpath->query('//img[@src]') as $img) { -// $href = $img->getAttribute('src'); -// if (!preg_match("/^http(.*)$/", $href, $matches)) { -// if(!empty($url)){ -// $img->setAttribute('src', $this->relPath($url, $href)); -// continue; -// } -// $this->jerr('Please use the absolutely url for image src!'); -// } -// } + foreach ($xpath->query('//img[@src]') as $img) { + $href = $img->getAttribute('src'); + if (!preg_match("/^http(.*)$/", $href, $matches)) { + if(!empty($url)){ + $img->setAttribute('src', $this->relPath($url, $href)); + continue; + } + $this->jerr('Please use the absolutely url for image src!'); + } + } -// foreach ($xpath->query('//a[@href]') as $a) { -// $href = $a->getAttribute('href'); -// if (!preg_match("/^http|mailto|#(.*)$/", $href, $matches)) { -// if(!empty($url)){ -// $a->setAttribute('href', $this->relPath($url, $href)); -// continue; -// } -// $this->jerr('Please use the absolutely url for a href!'); -// } -// } + foreach ($xpath->query('//a[@href]') as $a) { + $href = $a->getAttribute('href'); + if (!preg_match("/^http|mailto|#(.*)$/", $href, $matches)) { + if(!empty($url)){ + $a->setAttribute('href', $this->relPath($url, $href)); + continue; + } + $this->jerr('Please use the absolutely url for a href!'); + } + } -// foreach ($xpath->query('//link[@href]') as $l) { -// if($l->getAttribute('rel') == 'stylesheet'){ -// $href = $l->getAttribute('href'); -// -// -// if (empty($url) && !preg_match("/^http(.*)$/", $href, $matches)) { -// // import from file , must use absolutely url -// $this->jerr('Please use the absolutely url for link href!'); -// } -// if (!empty($url)) { -// // import from URL -// $href = $this->relPath($url, $href); -// } -// $this->styleSheets[$href] = $this->replaceImageUrl(file_get_contents($href),$href); -// } -// } + foreach ($xpath->query('//link[@href]') as $l) { + if($l->getAttribute('rel') == 'stylesheet'){ + $href = $l->getAttribute('href'); + + if (empty($url) && !preg_match("/^http(.*)$/", $href, $matches)) { + // import from file , must use absolutely url + $this->jerr('Please use the absolutely url for link href!'); + } + if (!empty($url)) { + // import from URL + $href = $this->relPath($url, $href); + } + $this->styleSheets[$href] = $this->replaceImageUrl(file_get_contents($href),$href); + } + } foreach ($xpath->query('//style') as $s){ $this->styleSheets[] = $this->replaceImageUrl($s->nodeValue, $url); -- 2.39.2