1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * Compression functions.
- *
- * @package Pen
- */
- if ( ! function_exists( 'pen_compress_css' ) ) {
- /**
- * Removes empty lines and white space from CSS.
- *
- * @param string $input The input CSS.
- *
- * @since Pen 1.0.0
- * @return string
- */
- function pen_compress_css( $input ) {
- // Removes blank lines.
- $output = preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n", trim( $input ) );
- // Removes comments.
- $output = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $output );
- // Removes indentation.
- $trimmed = array();
- $output = explode( "\n", $output );
- foreach ( $output as $output ) {
- $trimmed[] = trim( $output );
- }
- $output = implode( $trimmed );
- $search = array( '{ ', ' }', '; ', ', ', ' {', '} ', ': ', ' ,', ' ;', ';}' );
- $replace = array( '{', '}', ';', ',', '{', '}', ':', ',', ';', '}' );
- $output = str_replace( $search, $replace, $output );
- return $output;
- }
- }
- if ( ! function_exists( 'pen_compress_html' ) ) {
- /**
- * Compresses HTML code.
- *
- * @param string $input The input.
- *
- * @since Pen 1.0.0
- * @return string
- */
- function pen_compress_html( $input ) {
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- return $input;
- }
- $search = array( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' );
- $replace = array( '>', '<', '\\1' );
- $output = preg_replace( $search, $replace, $input );
- $output = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $output );
- $output = trim( $output );
- return $output;
- }
- }
|