From 77dfc19389f93cce2befba0a46642c5169905f6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Aug 2019 04:38:24 +0200 Subject: [PATCH] Try to compile css with lessc --- htdocs/core/class/lessc.class.php | 10 +++++-- htdocs/website/class/websitepage.class.php | 1 - htdocs/website/index.php | 33 ++++++++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/lessc.class.php b/htdocs/core/class/lessc.class.php index dcbd253c1cf..4ff2c1cc8ee 100644 --- a/htdocs/core/class/lessc.class.php +++ b/htdocs/core/class/lessc.class.php @@ -1,5 +1,4 @@ trans('Enabled'); elseif ($status == 0) return $langs->trans('Disabled'); } diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 0bbe816d8b3..004033474f7 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -476,8 +476,10 @@ if ($action == 'addcontainer') // Remove comments $tmp['content'] = removeHtmlComment($tmp['content']); - preg_match('/(.*)<\/head>/ims', $tmp['content'], $reg); - $head = $reg[1]; + $regs=array(); + + preg_match('/(.*)<\/head>/ims', $tmp['content'], $regs); + $head = $regs[1]; $objectpage->type_container = 'page'; $objectpage->pageurl = $pageurl; @@ -488,8 +490,10 @@ if ($action == 'addcontainer') } $objectpage->aliasalt = ''; - if (preg_match('/^(\d+)\-/', basename($urltograb), $reg)) $objectpage->aliasalt = $reg[1]; + if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) $objectpage->aliasalt = $regs[1]; + + $regtmp=array(); if (preg_match('/(.*)<\/title>/ims', $head, $regtmp)) { $objectpage->title = $regtmp[1]; @@ -548,7 +552,7 @@ if ($action == 'addcontainer') $errorforsubresource = 0; foreach ($regs[0] as $key => $val) { - dol_syslog("We will grab the resource found into script tag ".$regs[2][$key]); + dol_syslog("We will grab the script resource found into script tag ".$regs[2][$key]); $linkwithoutdomain = $regs[2][$key]; if (preg_match('/^\//', $regs[2][$key])) @@ -617,7 +621,7 @@ if ($action == 'addcontainer') $errorforsubresource = 0; foreach ($regs[0] as $key => $val) { - dol_syslog("We will grab the resources found into link tag ".$regs[2][$key]); + dol_syslog("We will grab the css resources found into link tag ".$regs[2][$key]); $linkwithoutdomain = $regs[2][$key]; if (preg_match('/^\//', $regs[2][$key])) @@ -662,6 +666,9 @@ if ($action == 'addcontainer') } else { + // Clean some comment + $tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']); + //dol_mkdir(dirname($filetosave)); //$fp = fopen($filetosave, "w"); @@ -675,7 +682,21 @@ if ($action == 'addcontainer') getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto); - $pagecsscontent.=$tmpgeturl['content']."\n"; + include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php'; + $lesscobj = new lessc(); + try { + $contentforlessc = ".bodywebsite {\n".$tmpgeturl['content']."\n}\n"; + //print '<pre>'.$contentforlessc.'</pre>'; + $contentforlessc = $lesscobj->compile($contentforlessc); + //var_dump($contentforlessc); exit; + + $pagecsscontent.=$contentforlessc."\n"; + //$pagecsscontent.=$tmpgeturl['content']."\n"; + } catch (exception $e) { + //echo "failed to compile lessc"; + dol_syslog("Failed to compile the CSS ".$urltograbbis." that we caught, with lessc: ".$e->getMessage(), LOG_WARNING); + $pagecsscontent.=$tmpgeturl['content']."\n"; + } $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key], '/').'\n*/ims', '', $objectpage->htmlheader); }