Clean code

This commit is contained in:
Laurent Destailleur
2019-08-29 13:17:14 +02:00
parent 77dfc19389
commit 01962cbc67
3 changed files with 35 additions and 12 deletions

View File

@@ -2452,6 +2452,13 @@ class lessc_parser {
}
}
/**
* Parse a string
*
* @param string $buffer String to parse
* @throws exception
* @return NULL|stdclass
*/
public function parse($buffer) {
$this->count = 0;
$this->line = 1;
@@ -2473,11 +2480,15 @@ class lessc_parser {
while (false !== $this->parseChunk());
if ($this->count != strlen($this->buffer))
$this->throwError();
{
$this->throwError('parse error count '.$this->count.' != len buffer '.strlen($this->buffer));
}
// TODO report where the block was opened
if ( !property_exists($this->env, 'parent') || !is_null($this->env->parent) )
if (!property_exists($this->env, 'parent') || !is_null($this->env->parent))
{
throw new exception('parse error: unclosed block');
}
return $this->env;
}

View File

@@ -5663,23 +5663,28 @@ function dol_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_e
* Example, if string contains euro symbol that has ascii code 128
*
* @param string $s String to check
* @return int 0 if bad iso, 1 if good iso
* @param string $clean Clean if it is not an ISO. Warning, if file is utf8, you will get a bad formated file.
* @return int|string 0 if bad iso, 1 if good iso, Or the clean string if $clean is 1
*/
function dol_string_is_good_iso($s)
function dol_string_is_good_iso($s, $clean = 0)
{
$len=dol_strlen($s);
$out= '';
$ok=1;
for($scursor=0;$scursor<$len;$scursor++)
for($scursor = 0; $scursor < $len; $scursor++)
{
$ordchar=ord($s[$scursor]);
//print $scursor.'-'.$ordchar.'<br>';
if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok=0; break; }
if ($ordchar > 126 && $ordchar < 160) { $ok=0; break; }
elseif ($ordchar > 126 && $ordchar < 160) { $ok=0; break; }
elseif ($clean) {
$out.= $s[$scursor];
}
}
if ($clean) return $out;
return $ok;
}
/**
* Return nb of lines of a clear text
*

View File

@@ -667,6 +667,13 @@ if ($action == 'addcontainer')
else
{
// Clean some comment
//$tmpgeturl['content'] = dol_string_is_good_iso($tmpgeturl['content'], 1);
//$tmpgeturl['content'] = utf8_encode(utf8_decode($tmpgeturl['content']));
//$tmpgeturl['content'] = mb_convert_encoding($tmpgeturl['content'], 'UTF-8', 'UTF-8');
//$tmpgeturl['content'] = remove_bs($tmpgeturl['content']);
//$tmpgeturl['content'] = str_replace('$screen-md-max', 'auto', $tmpgeturl['content']);
//var_dump($tmpgeturl['content']);exit;
$tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']);
//dol_mkdir(dirname($filetosave));
@@ -694,7 +701,7 @@ if ($action == 'addcontainer')
//$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);
dol_syslog("Failed to compile the CSS from URL ".$urltograbbis." with lessc: ".$e->getMessage(), LOG_WARNING);
$pagecsscontent.=$tmpgeturl['content']."\n";
}