mpdf = $mpdf; $this->tablecascadeCSS = array(); $this->listcascadeCSS = array(); $this->CSS=array(); $this->cascadeCSS = array(); $this->tbCSSlvl = 0; $this->listCSSlvl = 0; } function ReadDefaultCSS($CSSstr) { $CSS = array(); $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr); $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr); $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr); if ($CSSstr ) { preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles); for($i=0; $i < count($styles[1]) ; $i++) { $stylestr= trim($styles[2][$i]); $stylearr = explode(';',$stylestr); foreach($stylearr AS $sta) { if (trim($sta)) { // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')" list($property,$value) = explode(':',$sta,2); $property = trim($property); $value = preg_replace('/\s*!important/i','',$value); $value = trim($value); if ($property && ($value || $value==='0')) { $classproperties[strtoupper($property)] = $value; } } } $classproperties = $this->fixCSS($classproperties); $tagstr = strtoupper(trim($styles[1][$i])); $tagarr = explode(',',$tagstr); foreach($tagarr AS $tg) { $tags = preg_split('/\s+/',trim($tg)); $level = count($tags); if ($level == 1) { // e.g. p or .class or #id or p.class or p#id $t = trim($tags[0]); if ($t) { $tag = ''; if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; } if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); } else if ($tag) { $CSS[$tag] = $classproperties; } } } } $properties = array(); $values = array(); $classproperties = array(); } } // end of if return $CSS; } function ReadCSS($html) { preg_match_all('/]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m); for($i=0; $impdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } preg_match_all('/]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m); for($i=0; $impdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } // mPDF 5.5.02 // Remove Comment tags inside CSS as ', $html); preg_match_all('/(.*?)<\/style>/si',$html,$m); if (count($m[1])) { for($i=0;$i)/s',' ',$m[1][$i]); $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).''; $html = str_replace('>'.$m[1][$i].'', $sub, $html); } } $html = preg_replace('//i','',$html); $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html); $match = 0; // no match for instance $regexp = ''; // This helps debugging: showing what is the REAL string being processed $CSSext = array(); //CSS inside external files $regexp = '/]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = $cxt[1]; } $regexp = '/]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import stylesheets //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si'; $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import without the url() //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si'; $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } $ind = 0; $CSSstr = ''; if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array(); while($match){ $path = $CSSext[$ind]; $this->mpdf->GetFullPath($path); $CSSextblock = $this->mpdf->_get_file($path); if ($CSSextblock) { // look for embedded @import stylesheets in other stylesheets // and fix url paths (including background-images) relative to stylesheet //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si'; $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/'; if ($xem) { foreach($cxtem[1] AS $cxtembedded) { // path is relative to original stlyesheet!! $this->mpdf->GetFullPath($cxtembedded, $cssBasePath ); $match++; $CSSext[] = $cxtembedded; } } $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si'; $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); if ($xem) { for ($i=0;$impdf->GetFullPath($embedded, $cssBasePath ); $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock); } } } $CSSstr .= ' '.$CSSextblock; } $match--; $ind++; } //end of match $match = 0; // reset value, if needed // CSS as