107 $js = $jshrink->lock($js);
108 $jshrink->minifyDirectToOutput($js,
$options);
111 $js = ltrim(ob_get_clean());
112 $js = $jshrink->unlock($js);
117 }
catch (\Exception $e) {
119 if (isset($jshrink)) {
154 $this->options = array_merge(static::$defaultOptions,
$options);
155 $js = str_replace(
"\r\n",
"\n", $js);
156 $this->input = str_replace(
"\r",
"\n", $js);
161 $this->input .= PHP_EOL;
175 while ($this->a !==
false && !is_null($this->a) && $this->a !==
'') {
181 if (strpos(
'(-+{[@', $this->b) !==
false) {
195 if(static::isAlphaNumeric($this->b))
204 if (strpos(
'}])+-"\'', $this->a) !==
false) {
209 if (static::isAlphaNumeric($this->a)) {
217 if(!static::isAlphaNumeric($this->a))
222 if ($this->a ==
'/' && ($this->b ==
'\'' || $this->b ==
'"')) {
236 if(($this->b ==
'/' && strpos(
'(,=:[!&|?', $this->a) !==
false))
250 $this->a = $this->b =
'';
252 unset($this->options);
263 if (isset($this->c)) {
269 $char = substr($this->input, $this->index, 1);
272 if (isset($char) && $char ===
false) {
282 if($char !==
"\n" && ord($char) < 32)
311 if ($this->c ==
'/') {
314 }
elseif ($this->c ==
'*') {
330 $thirdCommentString = substr($this->input, $this->index, 1);
335 if ($thirdCommentString ==
'@') {
338 $char =
"\n" . substr($this->input, $startIndex, $endPoint);
359 $thirdCommentString = $this->
getChar();
369 if (($this->options[
'flaggedComments'] && $thirdCommentString ==
'!')
370 || ($thirdCommentString ==
'@') ) {
374 if ($startIndex > 0) {
379 if ($this->input[($startIndex - 1)] ==
"\n") {
384 $endPoint = ($this->index - 1) - $startIndex;
385 echo substr($this->input, $startIndex, $endPoint);
395 throw new \RuntimeException(
'Unclosed multiline comment at position: ' . ($this->index - 2));
415 $pos = strpos($this->input, $string, $this->index);
426 return substr($this->input, $this->index, 1);
444 if ($this->a !=
"'" && $this->a !=
'"') {
473 throw new \RuntimeException(
'Unclosed string at position: ' . $startpos );
485 if ($this->b ==
"\n") {
512 while (($this->a = $this->
getChar()) !==
false) {
516 if ($this->a ==
'\\') {
522 throw new \RuntimeException(
'Unclosed regex pattern at position: ' . $this->index);
537 return preg_match(
'/^[\w\$]$/', $char) === 1 || $char ==
'/';
549 $lock =
'"LOCK---' . crc32(time()) .
'"';
552 preg_match(
'/([+-])(\s+)([+-])/', $js, $matches);
553 if (empty($matches)) {
557 $this->locks[$lock] = $matches[2];
559 $js = preg_replace(
'/([+-])\s+([+-])/',
"$1{$lock}$2", $js);
573 if (!count($this->locks)) {
577 foreach ($this->locks as $lock => $replacement) {
578 $js = str_replace($lock, $replacement, $js);
lock($js)
Replace patterns in the given string and store the replacement.
getChar()
Returns the next string for processing based off of the current index.
saveString()
When a javascript string is detected this function crawls for the end of it and saves the whole strin...
unlock($js)
Replace "locks" with the original characters.
static isAlphaNumeric($char)
Checks to see if a character is alphanumeric.
processOneLineComments($startIndex)
Removed one line comments, with the exception of some very specific types of conditional comments...
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
processMultiLineComments($startIndex)
Skips multiline comments where appropriate, and includes them where needed.
loop()
The primary action occurs here.
static minify($js, $options=array())
Takes a string containing javascript and removes unneeded characters in order to shrink the code with...
getReal()
This function gets the next "real" character.
saveRegex()
When a regular expression is detected this function crawls for the end of it and saves the whole rege...
clean()
Resets attributes that do not need to be stored between requests so that the next request is ready to...
initialize($js, $options)
Initializes internal variables, normalizes new lines,.
minifyDirectToOutput($js, $options)
Processes a javascript string and outputs only the required characters, stripping out all unneeded ch...
getNext($string)
Pushes the index ahead to the next instance of the supplied string.