function
compress()
{
foreach
(
$this
->files
as
$file
) {
$this
->string .=
file_get_contents
(
$file
)
or
die
(
"Cannot read from uploaded file"
);
}
$input_hash
= sha1(
$this
->string);
$file
=
$this
->TEMP_FILES_DIR .
'/'
.
$input_hash
.
'.txt'
;
$fh
=
fopen
(
$file
,
'w'
)
or
die
(
"Can't create new file"
);
fwrite(
$fh
,
$this
->string);
fclose(
$fh
);
$cmd
=
"java -Xmx32m -jar "
.
escapeshellarg
(
$this
->JAR_PATH) .
' '
.
escapeshellarg
(
$file
) .
" --charset UTF-8"
;
$cmd
.=
" --type "
. (
strtolower
(
$this
->options[
'type'
]) ==
"css"
?
"css"
:
"js"
);
if
(
$this
->options[
'linebreak'
] &&
intval
(
$this
->options[
'linebreak'
]) > 0) {
$cmd
.=
' --line-break '
.
intval
(
$this
->options[
'linebreak'
]);
}
if
(
$this
->options[
'verbose'
]) {
$cmd
.=
" -v"
;
}
if
(
$this
->options[
'nomunge'
]) {
$cmd
.=
' --nomunge'
;
}
if
(
$this
->options[
'semi'
]) {
$cmd
.=
' --preserve-semi'
;
}
if
(
$this
->options[
'nooptimize'
]) {
$cmd
.=
' --disable-optimizations'
;
}
exec
(
$cmd
.
' 2>&1'
,
$raw_output
);
$flattened_output
= implode(
"\n"
,
$raw_output
);
unlink(
$file
);
return
$flattened_output
;
}