Beispiel #1
0
 public static function minify($css, $options = array())
 {
     $options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
     set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_CSSTIDY_DIR);
     require_once 'class.csstidy.php';
     $csstidy = new csstidy();
     foreach ($options as $option => $value) {
         $csstidy->set_cfg($option, $value);
     }
     $csstidy->load_template($options['template']);
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     if (isset($options['currentDir']) || isset($options['prependRelativePath'])) {
         require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
         $browsercache_id = isset($options['browserCacheId']) ? $options['browserCacheId'] : 0;
         $browsercache_extensions = isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array();
         if (isset($options['currentDir'])) {
             $document_root = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
             $symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
             return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $document_root, $symlinks, $browsercache_id, $browsercache_extensions);
         } else {
             return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath'], $browsercache_id, $browsercache_extensions);
         }
     }
     return $css;
 }
 public static function minifyCss($path)
 {
     require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
     $css = new \csstidy();
     $css->set_cfg('allow_html_in_templates', false);
     $css->set_cfg('compress_colors', true);
     $css->set_cfg('compress_font-weight', true);
     $css->set_cfg('remove_last_', true);
     $css->set_cfg('remove_bslash', true);
     $css->set_cfg('template', 'highest');
     $css->set_cfg('preserve_css', true);
     $css->set_cfg('silent', true);
     $css->parse(file_get_contents($path));
     return $css->print->plain();
 }
function firmasite_sanitize_customcss($css)
{
    // Sadly we cant include csstidy. WordPress Theme Directory's automatic code checking system is not accepting it.
    // You have 2 option for including css checker: install jetpack and activate custom css or copy csstidy's folder to theme's functions folder from jetpack's plugin
    firmasite_safecss_class();
    if (class_exists('safecss') || class_exists('firmasite_safecss')) {
        $csstidy = new csstidy();
        if (class_exists('firmasite_safecss')) {
            $csstidy->optimise = new firmasite_safecss($csstidy);
        } else {
            $csstidy->optimise = new safecss($csstidy);
        }
        $csstidy->set_cfg('remove_bslash', false);
        $csstidy->set_cfg('compress_colors', false);
        $csstidy->set_cfg('compress_font-weight', false);
        $csstidy->set_cfg('optimise_shorthands', 0);
        $csstidy->set_cfg('remove_last_;', false);
        $csstidy->set_cfg('case_properties', false);
        $csstidy->set_cfg('discard_invalid_properties', true);
        $csstidy->set_cfg('css_level', 'CSS3.0');
        $csstidy->set_cfg('preserve_css', true);
        $csstidy->set_cfg('template', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl');
        $css = stripslashes($css);
        // Some people put weird stuff in their CSS, KSES tends to be greedy
        $css = str_replace('<=', '&lt;=', $css);
        // Why KSES instead of strip_tags?  Who knows?
        $css = wp_kses_split($prev = $css, array(), array());
        $css = str_replace('&gt;', '>', $css);
        // kses replaces lone '>' with &gt;
        // Why both KSES and strip_tags?  Because we just added some '>'.
        $css = strip_tags($css);
        $csstidy->parse($css);
        $safe_css = $csstidy->print->plain();
    } else {
        $safe_css = $css;
    }
    return $safe_css;
}
Beispiel #4
0
 public static function minify($css, $options = array())
 {
     $options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
     set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_DIR . '/CSSTidy');
     require_once 'class.csstidy.php';
     $csstidy = new csstidy();
     foreach ($options as $option => $value) {
         $csstidy->set_cfg($option, $value);
     }
     $csstidy->load_template($options['template']);
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     $css = Minify_CSS_UriRewriter::rewrite($css, $options);
     return $css;
 }
Beispiel #5
0
 /**
  * Field Render Function.
  * Takes the vars and validates them
  *
  * @since ReduxFramework 3.0.0
  */
 function validate()
 {
     require_once dirname(__FILE__) . '/csstidy/class.csstidy.php';
     $csstidy = new csstidy();
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', false);
     $csstidy->set_cfg('compress_font-weight', false);
     $csstidy->set_cfg('optimise_shorthands', 0);
     $csstidy->set_cfg('remove_last_;', false);
     $csstidy->set_cfg('case_properties', false);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $csstidy->set_cfg('preserve_css', true);
     $csstidy->set_cfg('template', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl');
     $css = $orig = $this->value;
     $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $prev = $css);
     if ($css != $prev) {
         $this->warning = true;
     }
     // Some people put weird stuff in their CSS, KSES tends to be greedy
     $css = str_replace('<=', '&lt;=', $css);
     // Why KSES instead of strip_tags?  Who knows?
     $css = wp_kses_split($prev = $css, array(), array());
     $css = str_replace('&gt;', '>', $css);
     // kses replaces lone '>' with &gt;
     // Why both KSES and strip_tags?  Because we just added some '>'.
     $css = strip_tags($css);
     if ($css != $prev) {
         $this->warning = true;
     }
     $csstidy->parse($css);
     $this->value = $csstidy->print->plain();
     if (isset($this->warning) && $this->warning) {
         $this->warning = __('Unsafe strings were found in your CSS and have been filtered out.', 'redux-framework');
     }
 }
 /**
  * Implements SimpleExpectation::test().
  * @param $filename Filename of test file to test.
  */
 function test($filename = false)
 {
     if ($filename) {
         $this->load($filename);
     }
     $css = new csstidy();
     $css->set_cfg($this->settings);
     $css->parse($this->css);
     if ($this->fullexpect) {
         $this->actual = var_export($css->css, true);
     } elseif (isset($css->css[41])) {
         $this->actual = var_export($css->css[41], true);
     } else {
         $this->actual = 'Key 41 does not exist';
     }
     return $this->expect === $this->actual;
 }
 public static function sanitize_css($css)
 {
     if (!class_exists('csstidy')) {
         require_once 'class.csstidy.php';
     }
     $csstidy = new csstidy();
     $csstidy->set_cfg('remove_bslash', FALSE);
     $csstidy->set_cfg('compress_colors', FALSE);
     $csstidy->set_cfg('compress_font-weight', FALSE);
     $csstidy->set_cfg('discard_invalid_properties', TRUE);
     $csstidy->set_cfg('merge_selectors', FALSE);
     $csstidy->set_cfg('remove_last_;', FALSE);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $csstovalidateindiv = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css);
     $csstovalidateindiv = wp_kses_split($csstovalidateindiv, array(), array());
     $csstidy->parse($csstovalidateindiv);
     $cssvalidated = $csstidy->print->plain();
     return $cssvalidated;
 }
Beispiel #8
0
 function pixopoint_validate_css($css)
 {
     // SafeCSS / CSSTidy stuff
     require_once 'csstidy.php';
     // CSS sanitising gizmo
     $csstidy = new csstidy();
     $csstidy->optimise = new safecss($csstidy);
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', false);
     $csstidy->set_cfg('compress_font-weight', false);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('merge_selectors', false);
     $csstidy->set_cfg('preserve_css', true);
     // Outputs code comments
     // $csstidy->set_cfg( 'lowercase_s', false );
     // $csstidy->set_cfg( 'optimise_shorthands', 1 );
     // $csstidy->set_cfg( 'remove_last_;', false );
     // $csstidy->set_cfg( 'case_properties', 1 );
     // $csstidy->set_cfg( 'sort_properties', false );
     // $csstidy->set_cfg( 'sort_selectors', false );
     // Santisation stuff copied from SafeCSS by Automattic
     $css = stripslashes($css);
     $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $prev = $css);
     $css = str_replace('<=', '&lt;=', $css);
     // Some people put weird stuff in their CSS, KSES tends to be greedy
     $css = wp_kses_split($prev = $css, array(), array());
     // Why KSES instead of strip_tags?  Who knows?
     $css = str_replace('&gt;', '>', $css);
     // kses replaces lone '>' with &gt;
     $css = strip_tags($css);
     // Why both KSES and strip_tags?  Because we just added some '>'.
     // Parse with CSS tidy
     $csstidy->parse($css);
     // Parse with CSS Tidy
     $css = $csstidy->print->plain();
     // Grab CSS output
     // Make CSS look pretty
     $css = pixopoint_pretty_css($css);
     return $css;
 }
Beispiel #9
0
 public function update_settings()
 {
     global $register_plus_redux;
     $options = array();
     $redux_usermeta = array();
     $_POST = stripslashes_deep((array) $_POST);
     if (isset($_POST['custom_logo_url']) && !isset($_POST['remove_logo'])) {
         $options['custom_logo_url'] = esc_url_raw((string) $_POST['custom_logo_url']);
     }
     $options['verify_user_email'] = isset($_POST['verify_user_email']) ? '1' : '0';
     $options['message_verify_user_email'] = isset($_POST['message_verify_user_email']) ? wp_kses_post((string) $_POST['message_verify_user_email']) : '';
     $options['verify_user_admin'] = isset($_POST['verify_user_admin']) ? '1' : '0';
     $options['message_verify_user_admin'] = isset($_POST['message_verify_user_admin']) ? wp_kses_post((string) $_POST['message_verify_user_admin']) : '';
     $options['delete_unverified_users_after'] = isset($_POST['delete_unverified_users_after']) ? absint((string) $_POST['delete_unverified_users_after']) : '0';
     $options['registration_redirect_url'] = isset($_POST['registration_redirect_url']) ? esc_url_raw((string) $_POST['registration_redirect_url']) : '';
     $options['verification_redirect_url'] = isset($_POST['verification_redirect_url']) ? esc_url_raw((string) $_POST['verification_redirect_url']) : '';
     $options['autologin_user'] = isset($_POST['autologin_user']) ? '1' : '0';
     $options['username_is_email'] = isset($_POST['username_is_email']) ? '1' : '0';
     $options['double_check_email'] = isset($_POST['double_check_email']) ? '1' : '0';
     if (isset($_POST['show_fields']) && is_array($_POST['show_fields'])) {
         $options['show_fields'] = (array) $_POST['show_fields'];
     }
     if (isset($_POST['required_fields']) && is_array($_POST['required_fields'])) {
         $options['required_fields'] = (array) $_POST['required_fields'];
     }
     $options['user_set_password'] = isset($_POST['user_set_password']) ? '1' : '0';
     $options['min_password_length'] = isset($_POST['min_password_length']) ? absint($_POST['min_password_length']) : 0;
     $options['disable_password_confirmation'] = isset($_POST['disable_password_confirmation']) ? '1' : '0';
     $options['show_password_meter'] = isset($_POST['show_password_meter']) ? '1' : '0';
     $options['message_empty_password'] = isset($_POST['message_empty_password']) ? wp_kses_data((string) $_POST['message_empty_password']) : '';
     $options['message_short_password'] = isset($_POST['message_short_password']) ? wp_kses_data((string) $_POST['message_short_password']) : '';
     $options['message_bad_password'] = isset($_POST['message_bad_password']) ? wp_kses_data((string) $_POST['message_bad_password']) : '';
     $options['message_good_password'] = isset($_POST['message_good_password']) ? wp_kses_data((string) $_POST['message_good_password']) : '';
     $options['message_strong_password'] = isset($_POST['message_strong_password']) ? wp_kses_data((string) $_POST['message_strong_password']) : '';
     $options['message_mismatch_password'] = isset($_POST['message_mismatch_password']) ? wp_kses_data((string) $_POST['message_mismatch_password']) : '';
     $options['enable_invitation_code'] = isset($_POST['enable_invitation_code']) ? '1' : '0';
     if (isset($_POST['invitation_code_bank']) && is_array($_POST['invitation_code_bank'])) {
         $invitation_code_bank = (array) $_POST['invitation_code_bank'];
     }
     $options['require_invitation_code'] = isset($_POST['require_invitation_code']) ? '1' : '0';
     $options['invitation_code_case_sensitive'] = isset($_POST['invitation_code_case_sensitive']) ? '1' : '0';
     $options['invitation_code_unique'] = isset($_POST['invitation_code_unique']) ? '1' : '0';
     $options['enable_invitation_tracking_widget'] = isset($_POST['enable_invitation_tracking_widget']) ? '1' : '0';
     $options['show_disclaimer'] = isset($_POST['show_disclaimer']) ? '1' : '0';
     $options['message_disclaimer_title'] = isset($_POST['message_disclaimer_title']) ? sanitize_text_field((string) $_POST['message_disclaimer_title']) : '';
     $options['message_disclaimer'] = isset($_POST['message_disclaimer']) ? wp_kses_post((string) $_POST['message_disclaimer']) : '';
     $options['require_disclaimer_agree'] = isset($_POST['require_disclaimer_agree']) ? '1' : '0';
     $options['message_disclaimer_agree'] = isset($_POST['message_disclaimer_agree']) ? sanitize_text_field((string) $_POST['message_disclaimer_agree']) : '';
     $options['show_license'] = isset($_POST['show_license']) ? '1' : '0';
     $options['message_license_title'] = isset($_POST['message_license_title']) ? sanitize_text_field((string) $_POST['message_license_title']) : '';
     $options['message_license'] = isset($_POST['message_license']) ? wp_kses_post((string) $_POST['message_license']) : '';
     $options['require_license_agree'] = isset($_POST['require_license_agree']) ? '1' : '0';
     $options['message_license_agree'] = isset($_POST['message_license_agree']) ? sanitize_text_field((string) $_POST['message_license_agree']) : '';
     $options['show_privacy_policy'] = isset($_POST['show_privacy_policy']) ? '1' : '0';
     $options['message_privacy_policy_title'] = isset($_POST['message_privacy_policy_title']) ? sanitize_text_field((string) $_POST['message_privacy_policy_title']) : '';
     $options['message_privacy_policy'] = isset($_POST['message_privacy_policy']) ? wp_kses_post((string) $_POST['message_privacy_policy']) : '';
     $options['require_privacy_policy_agree'] = isset($_POST['require_privacy_policy_agree']) ? '1' : '0';
     $options['message_privacy_policy_agree'] = isset($_POST['message_privacy_policy_agree']) ? sanitize_text_field((string) $_POST['message_privacy_policy_agree']) : '';
     $options['default_css'] = isset($_POST['default_css']) ? '1' : '0';
     $options['required_fields_style'] = '';
     if (isset($_POST['required_fields_style'])) {
         // Stolen from Jetpack 2.0.4 custom-css.php Jetpack_Custom_CSS::filter_attr()
         require_once 'csstidy/class.csstidy.php';
         $csstidy = new csstidy();
         $csstidy->set_cfg('remove_bslash', FALSE);
         $csstidy->set_cfg('compress_colors', FALSE);
         $csstidy->set_cfg('compress_font-weight', FALSE);
         $csstidy->set_cfg('discard_invalid_properties', TRUE);
         $csstidy->set_cfg('merge_selectors', FALSE);
         $csstidy->set_cfg('remove_last_;', FALSE);
         $csstidy->set_cfg('css_level', 'CSS3.0');
         $required_fields_style = 'div {' . (string) $_POST['required_fields_style'] . '}';
         $required_fields_style = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $required_fields_style);
         $required_fields_style = wp_kses_split($required_fields_style, array(), array());
         $csstidy->parse($required_fields_style);
         $required_fields_style = $csstidy->print->plain();
         $required_fields_style = str_replace(array("\n", "\r", "\t"), '', $required_fields_style);
         preg_match("/^div\\s*{(.*)}\\s*\$/", $required_fields_style, $matches);
         if (!empty($matches[1])) {
             $options['required_fields_style'] = $matches[1];
         }
     }
     $options['required_fields_asterisk'] = isset($_POST['required_fields_asterisk']) ? '1' : '0';
     $options['starting_tabindex'] = isset($_POST['starting_tabindex']) ? absint($_POST['starting_tabindex']) : 0;
     /*
     if ( isset( $_POST['datepicker_firstdayofweek'] ) ) $options['datepicker_firstdayofweek'] = absint( $_POST['datepicker_firstdayofweek'] );
     if ( isset( $_POST['datepicker_dateformat'] ) ) $options['datepicker_dateformat'] = sanitize_text_field( (string) $_POST['datepicker_dateformat'] );
     if ( isset( $_POST['datepicker_startdate'] ) ) $options['datepicker_startdate'] = sanitize_text_field( (string) $_POST['datepicker_startdate'] );
     if ( isset( $_POST['datepicker_calyear'] ) ) $options['datepicker_calyear'] = sanitize_text_field( (string) $_POST['datepicker_calyear'] );
     if ( isset( $_POST['datepicker_calmonth'] ) ) $options['datepicker_calmonth'] = sanitize_text_field( (string) $_POST['datepicker_calmonth'] );
     */
     $options['disable_user_message_registered'] = isset($_POST['disable_user_message_registered']) ? '1' : '0';
     $options['disable_user_message_created'] = isset($_POST['disable_user_message_created']) ? '1' : '0';
     $options['custom_user_message'] = isset($_POST['custom_user_message']) ? '1' : '0';
     $options['user_message_from_email'] = isset($_POST['user_message_from_email']) ? sanitize_text_field((string) $_POST['user_message_from_email']) : '';
     $options['user_message_from_name'] = isset($_POST['user_message_from_name']) ? sanitize_text_field((string) $_POST['user_message_from_name']) : '';
     $options['user_message_subject'] = isset($_POST['user_message_subject']) ? sanitize_text_field((string) $_POST['user_message_subject']) : '';
     $options['user_message_body'] = isset($_POST['user_message_body']) ? wp_kses_post((string) $_POST['user_message_body']) : '';
     $options['send_user_message_in_html'] = isset($_POST['send_user_message_in_html']) ? '1' : '0';
     $options['user_message_newline_as_br'] = isset($_POST['user_message_newline_as_br']) ? '1' : '0';
     $options['custom_verification_message'] = isset($_POST['custom_verification_message']) ? '1' : '0';
     $options['verification_message_from_email'] = isset($_POST['verification_message_from_email']) ? sanitize_text_field((string) $_POST['verification_message_from_email']) : '';
     $options['verification_message_from_name'] = isset($_POST['verification_message_from_name']) ? sanitize_text_field((string) $_POST['verification_message_from_name']) : '';
     $options['verification_message_subject'] = isset($_POST['verification_message_subject']) ? sanitize_text_field((string) $_POST['verification_message_subject']) : '';
     $options['verification_message_body'] = isset($_POST['verification_message_body']) ? wp_kses_post((string) $_POST['verification_message_body']) : '';
     $options['send_verification_message_in_html'] = isset($_POST['send_verification_message_in_html']) ? '1' : '0';
     $options['verification_message_newline_as_br'] = isset($_POST['verification_message_newline_as_br']) ? '1' : '0';
     $options['disable_admin_message_registered'] = isset($_POST['disable_admin_message_registered']) ? '1' : '0';
     $options['disable_admin_message_created'] = isset($_POST['disable_admin_message_created']) ? '1' : '0';
     $options['admin_message_when_verified'] = isset($_POST['admin_message_when_verified']) ? '1' : '0';
     $options['custom_admin_message'] = isset($_POST['custom_admin_message']) ? '1' : '0';
     $options['admin_message_from_email'] = isset($_POST['admin_message_from_email']) ? sanitize_text_field((string) $_POST['admin_message_from_email']) : '';
     $options['admin_message_from_name'] = isset($_POST['admin_message_from_name']) ? sanitize_text_field((string) $_POST['admin_message_from_name']) : '';
     $options['admin_message_subject'] = isset($_POST['admin_message_subject']) ? sanitize_text_field((string) $_POST['admin_message_subject']) : '';
     $options['admin_message_body'] = isset($_POST['admin_message_body']) ? wp_kses_post((string) $_POST['admin_message_body']) : '';
     $options['send_admin_message_in_html'] = isset($_POST['send_admin_message_in_html']) ? '1' : '0';
     $options['admin_message_newline_as_br'] = isset($_POST['admin_message_newline_as_br']) ? '1' : '0';
     $options['custom_registration_page_css'] = '';
     if (isset($_POST['custom_registration_page_css'])) {
         // Stolen from Jetpack 2.0.4 custom-css.php Jetpack_Custom_CSS::init()
         require_once 'csstidy/class.csstidy.php';
         $csstidy = new csstidy();
         $csstidy->set_cfg('remove_bslash', FALSE);
         $csstidy->set_cfg('compress_colors', FALSE);
         $csstidy->set_cfg('compress_font-weight', FALSE);
         $csstidy->set_cfg('optimise_shorthands', 0);
         $csstidy->set_cfg('remove_last_;', FALSE);
         $csstidy->set_cfg('case_properties', FALSE);
         $csstidy->set_cfg('discard_invalid_properties', TRUE);
         $csstidy->set_cfg('css_level', 'CSS3.0');
         $csstidy->set_cfg('preserve_css', TRUE);
         $csstidy->set_cfg('template', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl');
         $custom_registration_page_css = (string) $_POST['custom_registration_page_css'];
         $custom_registration_page_css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $custom_registration_page_css);
         $custom_registration_page_css = str_replace('<=', '&lt;=', $custom_registration_page_css);
         $custom_registration_page_css = wp_kses_split($custom_registration_page_css, array(), array());
         $custom_registration_page_css = str_replace('&gt;', '>', $custom_registration_page_css);
         $custom_registration_page_css = strip_tags($custom_registration_page_css);
         $csstidy->parse($custom_registration_page_css);
         $options['custom_registration_page_css'] = $csstidy->print->plain();
     }
     $options['custom_login_page_css'] = '';
     if (isset($_POST['custom_login_page_css'])) {
         // Stolen from Jetpack 2.0.4 custom-css.php Jetpack_Custom_CSS::init()
         require_once 'csstidy/class.csstidy.php';
         $csstidy = new csstidy();
         $csstidy->set_cfg('remove_bslash', FALSE);
         $csstidy->set_cfg('compress_colors', FALSE);
         $csstidy->set_cfg('compress_font-weight', FALSE);
         $csstidy->set_cfg('optimise_shorthands', 0);
         $csstidy->set_cfg('remove_last_;', FALSE);
         $csstidy->set_cfg('case_properties', FALSE);
         $csstidy->set_cfg('discard_invalid_properties', TRUE);
         $csstidy->set_cfg('css_level', 'CSS3.0');
         $csstidy->set_cfg('preserve_css', TRUE);
         $csstidy->set_cfg('template', dirname(__FILE__) . '/csstidy/wordpress-standard.tpl');
         $custom_login_page_css = (string) $_POST['custom_login_page_css'];
         $custom_login_page_css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $custom_login_page_css);
         $custom_login_page_css = str_replace('<=', '&lt;=', $custom_login_page_css);
         $custom_login_page_css = wp_kses_split($custom_login_page_css, array(), array());
         $custom_login_page_css = str_replace('&gt;', '>', $custom_login_page_css);
         $custom_login_page_css = strip_tags($custom_login_page_css);
         $csstidy->parse($custom_login_page_css);
         $options['custom_login_page_css'] = $csstidy->print->plain();
     }
     if (isset($_POST['label'])) {
         foreach ((array) $_POST['label'] as $index => $v) {
             $meta_field = array();
             if (!empty($_POST['label'][$index])) {
                 $meta_field['label'] = isset($_POST['label'][$index]) ? sanitize_text_field((string) $_POST['label'][$index]) : '';
                 $meta_field['meta_key'] = isset($_POST['meta_key'][$index]) ? sanitize_text_field((string) $_POST['meta_key'][$index]) : '';
                 $meta_field['display'] = isset($_POST['display'][$index]) ? sanitize_text_field((string) $_POST['display'][$index]) : '';
                 $meta_field['options'] = '';
                 if (isset($_POST['options'][$index])) {
                     if (in_array($meta_field['display'], array('checkbox', 'radio', 'select'))) {
                         /*.array[]string.*/
                         $field_options = explode(',', (string) $_POST['options'][$index]);
                         foreach ($field_options as &$field_option) {
                             $field_option = sanitize_text_field($field_option);
                         }
                         $meta_field['options'] = implode(',', $field_options);
                     } else {
                         $meta_field['options'] = sanitize_text_field((string) $_POST['options'][$index]);
                     }
                 }
                 $meta_field['escape_url'] = '0';
                 $meta_field['show_on_profile'] = isset($_POST['show_on_profile'][$index]) ? '1' : '0';
                 $meta_field['show_on_registration'] = isset($_POST['show_on_registration'][$index]) ? '1' : '0';
                 $meta_field['require_on_registration'] = isset($_POST['require_on_registration'][$index]) ? '1' : '0';
                 $meta_field['show_datepicker'] = isset($_POST['show_datepicker'][$index]) ? '1' : '0';
                 $meta_field['terms_content'] = isset($_POST['terms_content'][$index]) ? wp_kses_post((string) $_POST['terms_content'][$index]) : '';
                 $meta_field['terms_agreement_text'] = isset($_POST['terms_agreement_text'][$index]) ? wp_kses_post((string) $_POST['terms_agreement_text'][$index]) : '';
                 $meta_field['date_revised'] = isset($_POST['date_revised'][$index]) ? strtotime((string) $_POST['date_revised'][$index]) : time();
                 if (empty($meta_field['meta_key'])) {
                     $meta_field['meta_key'] = 'rpr_' . Register_Plus_Redux::sanitize_text($meta_field['label']);
                 }
             }
             $redux_usermeta[] = $meta_field;
         }
     }
     if (isset($_POST['newMetaFields'])) {
         foreach ((array) $_POST['newMetaFields'] as $label) {
             $meta_field = array();
             $meta_field['label'] = sanitize_text_field($label);
             $meta_field['meta_key'] = 'rpr_' . Register_Plus_Redux::sanitize_text($meta_field['label']);
             $meta_field['display'] = '';
             $meta_field['options'] = '';
             $meta_field['escape_url'] = '0';
             $meta_field['show_on_profile'] = '0';
             $meta_field['show_on_registration'] = '0';
             $meta_field['require_on_registration'] = '0';
             $meta_field['show_datepicker'] = '0';
             $meta_field['terms_content'] = '';
             $meta_field['terms_agreement_text'] = '';
             $meta_field['date_revised'] = time();
             $redux_usermeta[] = $meta_field;
         }
     }
     $register_plus_redux->rpr_update_options($options);
     if (!empty($invitation_code_bank)) {
         update_option('register_plus_redux_invitation_code_bank-rv1', $invitation_code_bank);
     }
     if (!empty($redux_usermeta)) {
         update_option('register_plus_redux_usermeta-rv2', $redux_usermeta);
     }
 }
Beispiel #10
0
 function __process($type, $assets)
 {
     $path = $this->__getPath($type);
     $folder = new Folder($this->paths['wwwRoot'] . $this->cachePaths[$type], true);
     //check if the cached file exists
     $scripts = Set::extract('/script', $assets);
     $fileName = $folder->find($this->__generateFileName($scripts) . '_([0-9]{10}).' . $type);
     if ($fileName) {
         //take the first file...really should only be one.
         $fileName = $fileName[0];
     }
     //make sure all the pieces that went into the packed script
     //are OLDER then the packed version
     if ($this->checkTs && $fileName) {
         $packed_ts = filemtime($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
         $latest_ts = 0;
         foreach ($assets as $asset) {
             $assetFile = $this->__findFile($asset, $type);
             if (!$assetFile) {
                 continue;
             }
             $latest_ts = max($latest_ts, filemtime($assetFile));
         }
         //an original file is newer.  need to rebuild
         if ($latest_ts > $packed_ts) {
             unlink($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
             $fileName = null;
         }
     }
     //file doesn't exist.  create it.
     if (!$fileName) {
         $ts = time();
         switch ($type) {
             case 'js':
                 if (PHP5) {
                     App::import('Vendor', 'Asset.jsmin/jsmin');
                 }
                 break;
             case 'css':
                 App::import('Vendor', 'Asset.csstidy', array('file' => 'class.csstidy.php'));
                 $tidy = new csstidy();
                 $tidy->set_cfg('preserve_css', false);
                 $tidy->set_cfg('ie_fix_friendly', true);
                 $tidy->set_cfg('optimise_shorthands', 0);
                 //Maintain the order of ie hacks (properties)
                 $tidy->set_cfg('discard_invalid_properties', false);
                 $tidy->load_template($this->cssCompression);
                 break;
         }
         //merge the script
         $scriptBuffer = '';
         foreach ($assets as $asset) {
             $buffer = $this->__getFileContents($asset, $type);
             $origSize = strlen($buffer);
             switch ($type) {
                 case 'js':
                     //jsmin only works with PHP5
                     if (PHP5) {
                         $buffer = trim(JSMin::minify($buffer));
                     }
                     break;
                 case 'css':
                     $buffer = preg_replace('/url\\(([\\"\'])?([^\\"\']+)\\1\\)/', 'url($1' . FULL_BASE_URL . $asset['url'] . '$2$1)', $buffer);
                     $tidy->parse($buffer);
                     $buffer = $tidy->print->plain();
                     break;
             }
             $delta = 0;
             if ($origSize > 0) {
                 $delta = strlen($buffer) / $origSize * 100;
             }
             $scriptBuffer .= sprintf("/* %s.%s (%d%%) */\n", $asset['script'], $type, $delta);
             $scriptBuffer .= $buffer . "\n\n";
         }
         //write the file
         $fileName = $this->__generateFileName($scripts) . '_' . $ts . '.' . $type;
         $file = new File($this->paths['wwwRoot'] . $this->cachePaths[$type] . DS . $fileName);
         $file->write(trim($scriptBuffer));
     }
     if ($type == 'css') {
         //$html->css doesn't check if the file already has
         //the .css extension and adds it automatically, so we need to remove it.
         $fileName = str_replace('.css', '', $fileName);
     }
     return $fileName;
 }
 function &loadStyles($theme = 'default', &$xml_reponse)
 {
     if ($xml_reponse == null) {
         $xml_reponse =& new pfcResponse();
     }
     $c =& pfcGlobalConfig::Instance();
     // do not overload the theme parameter as long as
     // the ajax request do not give the correct one
     //    $c->theme = $theme;
     $u =& pfcUserConfig::Instance();
     $js = '';
     //file_get_contents(dirname(__FILE__).'/client/createstylerule.js');
     $js .= 'var c = $H();';
     $path = $c->getFilePathFromTheme('style.css.php');
     require_once dirname(__FILE__) . '/../lib/ctype/ctype.php';
     // to keep compatibility for php without ctype support
     require_once dirname(__FILE__) . '/../lib/csstidy-1.2/class.csstidy.php';
     $css = new csstidy();
     $css->set_cfg('preserve_css', false);
     $css_code = '';
     $t = new pfcTemplate();
     $t->assignObject($u, "u");
     $t->assignObject($c, "c");
     if (!$c->isDefaultFile('style.css.php')) {
         $t->setTemplate($c->theme_default_path . '/default/style.css.php');
         $css_code .= $t->getOutput();
     }
     $t->setTemplate($c->getFilePathFromTheme('style.css.php'));
     $css_code .= $t->getOutput();
     $css->parse($css_code);
     foreach ($css->css as $k => $v) {
         foreach ($v as $k2 => $v2) {
             $rules = '';
             foreach ($v2 as $k3 => $v3) {
                 $rules .= $k3 . ':' . $v3 . ';';
             }
             $js .= "c['" . $k2 . "']='" . str_replace("\n", "", $rules) . "';\n";
         }
     }
     $js .= "var pfccss = new pfcCSS(); var k = c.keys(); c.each(function (a) { pfccss.applyRule(a[0],a[1]); });";
     $xml_reponse->script($js);
     return $xml_reponse;
 }
  * Compress a css file.
  *
  * @param {string} path The path of the file to compress
  * @param {string} advanced Either advanced or standard_compression
  */
 case 'compressCSS':
     if (isset($_GET['path']) && isset($_POST['advanced'])) {
         $path = getWorkspacePath($_GET['path']);
         $css_code = file_get_contents($path);
         $css = new csstidy();
         $css->parse($css_code);
         if ($_POST['compression'] != "standard_compression") {
             $css->load_template($_POST['compression']);
         }
         if ($_POST['advanced']) {
             $css->set_cfg('compress_colors', $_POST['color']);
             $css->set_cfg('compress_font-weight', $_POST['fontw']);
             $css->set_cfg('remove_last_;', $_POST['bslash']);
             $css->set_cfg('remove_bslash', $_POST['last']);
         }
         $code = $css->print->plain();
         $nFile = substr($path, 0, strrpos($path, ".css"));
         $nFile = $nFile . ".min.css";
         file_put_contents($nFile, $code);
         echo '{"status":"success","message":"CSS tidied!"}';
     } else {
         echo '{"status":"error","message":"Missing Parameter!"}';
     }
     break;
 case 'compressJS':
     if (isset($_GET['path']) && isset($_POST['code'])) {
	/**
	 * Yii-ified version of CSS.php of the Minify packages with fixed options
	 *
	 * @param <type> $css
	 */
	private function minifyCss($css)
	{
		Yii::import('application.extensions.csstidy.*');
		require_once('class.csstidy.php');

		$cssTidy = new csstidy();
		$cssTidy->load_template($this->cssTidyTemplate);

		foreach($this->cssTidyConfig as $k => $v)
			$cssTidy->set_cfg($k, $v);

		$cssTidy->parse($css);
		return $cssTidy->print->plain();
	}
function custom_css_minify($css)
{
    if (!$css) {
        return '';
    }
    safecss_class();
    $csstidy = new csstidy();
    $csstidy->optimise = new safecss($csstidy);
    $csstidy->set_cfg('remove_bslash', false);
    $csstidy->set_cfg('compress_colors', true);
    $csstidy->set_cfg('compress_font-weight', true);
    $csstidy->set_cfg('remove_last_;', true);
    $csstidy->set_cfg('case_properties', true);
    $csstidy->set_cfg('discard_invalid_properties', true);
    $csstidy->set_cfg('css_level', 'CSS3.0');
    $csstidy->set_cfg('template', 'highest');
    $csstidy->parse($css);
    return $csstidy->print->plain();
}
 /**
  * sanitize user entered css
  * as seen here: http://wordpress.stackexchange.com/questions/53970/sanitize-user-entered-css
  *
  * @param type $css
  */
 function sanitize_css($css)
 {
     if (!class_exists('csstidy')) {
         include_once 'csstidy/class.csstidy.php';
     }
     $csstidy = new csstidy();
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', false);
     $csstidy->set_cfg('compress_font-weight', false);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('merge_selectors', false);
     $csstidy->set_cfg('remove_last_;', false);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css);
     $css = wp_kses_split($css, array(), array());
     $csstidy->parse($css);
     return $csstidy->print->plain();
 }
Beispiel #16
0
 static function filter_attr($css, $element = 'div')
 {
     safecss_class();
     $css = $element . ' {' . $css . '}';
     $csstidy = new csstidy();
     $csstidy->optimise = new safecss($csstidy);
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', false);
     $csstidy->set_cfg('compress_font-weight', false);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('merge_selectors', false);
     $csstidy->set_cfg('remove_last_;', false);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $css = preg_replace('/\\\\([0-9a-fA-F]{4})/', '\\\\\\\\$1', $css);
     $css = wp_kses_split($css, array(), array());
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     $css = str_replace(array("\n", "\r", "\t"), '', $css);
     preg_match("/^{$element}\\s*{(.*)}\\s*\$/", $css, $matches);
     if (empty($matches[1])) {
         return '';
     }
     return $matches[1];
 }
Beispiel #17
0
<?php
	include('class.csstidy.php');
	
	$css_file = dirname(__FILE__). "/tmp_csstidy_code.css";
	
	$f = fopen($css_file, "r");
	$css_code = fread($f, filesize($css_file));
	fclose($f);



	$css = new csstidy();
	$css->load_template("highest_compression");
	
	$css->set_cfg('remove_last_;',TRUE);

	$css->parse($css_code);

	print $css->print->plain();

?>
Beispiel #18
0
/**
 * Minifier un contenu CSS
 * 
 * Si $options est vide on utilise la methode regexp simple
 *
 * Si $options est une chaine non vide elle definit un media à appliquer
 * à la css. Si la css ne contient aucun @media ni @import, on encapsule tout
 * dans "@media $option {...}" et on utilise regexp sinon on utilise csstidy
 * pour ne pas faire d'erreur, mais c'est 12 fois plus lent
 *
 * Si $options sous forme de array() on passe par csstidy pour parser le code
 * et produire un contenu plus compact et prefixé eventuellement par un @media
 * options disponibles :
 * - string media : media qui seront utilisés pour encapsuler par @media
 *   les selecteurs sans media
 * - string template : format de sortie parmi 'low','default','high','highest'
 * 
 * @param string $contenu
 *     Contenu CSS
 * @param mixed $options
 *     Options de minification
 * @return string
 *     Contenu CSS minifié
 */
function minifier_css($contenu, $options = '')
{
    if (is_string($options) and $options) {
        if ($options == "all") {
            // facile : media all => ne rien preciser
            $options = "";
        } elseif (strpos($contenu, "@media") == false and strpos($contenu, "@import") == false and strpos($contenu, "@font-face") == false) {
            $contenu = "@media {$options} {\n{$contenu}\n}\n";
            $options = "";
        } else {
            $options = array('media' => $options);
        }
    }
    if (!is_array($options)) {
        // nettoyer la css de tout ce qui sert pas
        // pas de commentaires
        $contenu = preg_replace(",/\\*.*\\*/,Ums", "", $contenu);
        $contenu = preg_replace(",\\s//[^\n]*\n,Ums", "", $contenu);
        // espaces autour des retour lignes
        $contenu = str_replace("\r\n", "\n", $contenu);
        $contenu = preg_replace(",\\s+\n,ms", "\n", $contenu);
        $contenu = preg_replace(",\n\\s+,ms", "\n", $contenu);
        // pas d'espaces consecutifs
        $contenu = preg_replace(",\\s(?=\\s),Ums", "", $contenu);
        // pas d'espaces avant et apres { ; ,
        $contenu = preg_replace("/\\s?({|;|,)\\s?/ms", "\$1", $contenu);
        // supprimer les espaces devant : sauf si suivi d'une lettre (:after, :first...)
        $contenu = preg_replace("/\\s:([^a-z])/ims", ":\$1", $contenu);
        // supprimer les espaces apres :
        $contenu = preg_replace("/:\\s/ms", ":", $contenu);
        // pas d'espaces devant }
        $contenu = preg_replace("/\\s}/ms", "}", $contenu);
        // ni de point virgule sur la derniere declaration
        $contenu = preg_replace("/;}/ms", "}", $contenu);
        // pas d'espace avant !important
        $contenu = preg_replace("/\\s!\\s?important/ms", "!important", $contenu);
        // passser les codes couleurs en 3 car si possible
        // uniquement si non precedees d'un [="'] ce qui indique qu'on est dans un filter(xx=#?...)
        $contenu = preg_replace(";([:\\s,(])#([0-9a-f])(\\2)([0-9a-f])(\\4)([0-9a-f])(\\6)(?=[^\\w\\-]);i", "\$1#\$2\$4\$6", $contenu);
        // remplacer font-weight:bold par font-weight:700
        $contenu = preg_replace("/font-weight:bold(?!er)/ims", "font-weight:700", $contenu);
        // remplacer font-weight:normal par font-weight:400
        $contenu = preg_replace("/font-weight:normal/ims", "font-weight:400", $contenu);
        // si elle est 0, enlever la partie entière des unites decimales
        $contenu = preg_replace("/\\b0+\\.(\\d+em)/ims", ".\$1", $contenu);
        // supprimer les declarations vides
        $contenu = preg_replace(",(^|})([^{}]*){},Ums", "\$1", $contenu);
        // zero est zero, quelle que soit l'unite
        $contenu = preg_replace("/([^0-9.]0)(em|px|pt|%)/ms", "\$1", $contenu);
        // renommer les couleurs par leurs versions courtes quand c'est possible
        $colors = array('source' => array('black', 'fuchsia', 'white', 'yellow', '#800000', '#ffa500', '#808000', '#800080', '#008000', '#000080', '#008080', '#c0c0c0', '#808080', '#f00'), 'replace' => array('#000', '#F0F', '#FFF', '#FF0', 'maroon', 'orange', 'olive', 'purple', 'green', 'navy', 'teal', 'silver', 'gray', 'red'));
        foreach ($colors['source'] as $k => $v) {
            $colors['source'][$k] = ";([:\\s,(])" . $v . "(?=[^\\w\\-]);ms";
            $colors['replace'][$k] = "\$1" . $colors['replace'][$k];
        }
        $contenu = preg_replace($colors['source'], $colors['replace'], $contenu);
        // raccourcir les padding qui le peuvent (sur 3 ou 2 valeurs)
        $contenu = preg_replace(",padding:([^\\s;}]+)\\s([^\\s;}]+)\\s([^\\s;}]+)\\s(\\2),ims", "padding:\$1 \$2 \$3", $contenu);
        $contenu = preg_replace(",padding:([^\\s;}]+)\\s([^\\s;}]+)\\s(\\1)([;}!]),ims", "padding:\$1 \$2\$4", $contenu);
        // raccourcir les margin qui le peuvent (sur 3 ou 2 valeurs)
        $contenu = preg_replace(",margin:([^\\s;}]+)\\s([^\\s;}]+)\\s([^\\s;}]+)\\s(\\2),ims", "margin:\$1 \$2 \$3", $contenu);
        $contenu = preg_replace(",margin:([^\\s;}]+)\\s([^\\s;}]+)\\s(\\1)([;}!]),ims", "margin:\$1 \$2\$4", $contenu);
        $contenu = trim($contenu);
        return $contenu;
    } else {
        // compression avancee en utilisant csstidy
        // beaucoup plus lent, mais necessaire pour placer des @media la ou il faut
        // si il y a deja des @media ou des @import
        // modele de sortie plus ou moins compact
        $template = 'high';
        if (isset($options['template']) and in_array($options['template'], array('low', 'default', 'high', 'highest'))) {
            $template = $options['template'];
        }
        // @media eventuel pour prefixe toutes les css
        // et regrouper plusieurs css entre elles
        $media = "";
        if (isset($options['media'])) {
            $media = "@media " . $options['media'] . " ";
        }
        include_spip("lib/csstidy/class.csstidy");
        $css = new csstidy();
        // essayer d'optimiser les font, margin, padding avec des ecritures raccourcies
        $css->set_cfg('optimise_shorthands', 2);
        $css->set_cfg('template', $template);
        $css->parse($contenu);
        return $css->print->plain($media);
    }
}
 /**
  * Minimize CSS output using CSS Tidy.
  * 
  * @see styles_css_output filter
  * @author JetPack by Automattic
  */
 public function minify($css)
 {
     // Allow minification to be disabled with add_filter( 'styles_minify_css', '__return_false' );
     if (!apply_filters('styles_minify_css', true)) {
         return $css;
     }
     if (!class_exists('csstidy')) {
         include dirname(__FILE__) . '/csstidy/class.csstidy.php';
     }
     $csstidy = new csstidy();
     $csstidy->optimize = new csstidy_optimise($csstidy);
     $csstidy->set_cfg('remove_bslash', false);
     $csstidy->set_cfg('compress_colors', true);
     $csstidy->set_cfg('compress_font-weight', true);
     $csstidy->set_cfg('remove_last_;', true);
     $csstidy->set_cfg('case_properties', true);
     $csstidy->set_cfg('discard_invalid_properties', true);
     $csstidy->set_cfg('css_level', 'CSS3.0');
     $csstidy->set_cfg('template', 'highest');
     $csstidy->parse($css);
     $css = $csstidy->print->plain();
     return $css;
 }
Beispiel #20
0
 /**
  * Compress the JavaScripts or CSS files
  * 
  * @param string $type Can be js or css
  * @param string $prefix
  * @return Core_View_Helper_Compressor The compressor instance
  */
 public function compressor($type = 'js', $prefix = 'head')
 {
     $type = strtolower($type);
     $this->_type = $type;
     /**
      * Check whether the compression is enable or not
      */
     $config = Pandamp_Config::getConfig();
     $compressCss = isset($config->cache->compress->css) ? (string) $config->cache->compress->css : 'false';
     $compressJs = isset($config->cache->compress->js) ? (string) $config->cache->compress->js : 'false';
     if ($type == 'css' && $compressCss == 'false') {
         $return = $this->view->headLink()->toString() . $this->view->headStyle()->toString();
         return $return;
     } elseif ($type == 'js' && $compressJs == 'false') {
         $return = $this->view->headScript()->toString();
         $this->_resetHeadScript();
         return $return;
     }
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $cacheFile = md5(implode('_', array($prefix, $module, $controller, $action))) . '.' . $type;
     /**
      * Build cache dir and URL to show cache data
      */
     $cacheDir = TEMP_DIR . DS . 'cache' . DS . $type;
     $htaccess = $cacheDir . DS . '.htaccess';
     if (!file_exists($cacheDir)) {
         mkdir($cacheDir);
     }
     /**
      * Create .htaccess file that allows browser to access
      */
     if (!file_exists($htaccess)) {
         if ($fp = fopen($htaccess, 'wb')) {
             fwrite($fp, 'Allow from all');
             fclose($fp);
         }
     }
     $staticUrl = $config->web->static_server;
     $cachePath = $cacheDir . DS . $cacheFile;
     $this->_cacheUrl = $staticUrl . '/temp/cache/' . $type . '/' . $cacheFile;
     $files = array();
     $urls = array();
     $cssStyles = array();
     $jsScripts = array();
     switch ($type) {
         case 'css':
             $iterator = $this->view->headLink()->getIterator();
             foreach ($iterator as $item) {
                 if ($item->type == 'text/css') {
                     $urls[] = $item->href;
                 }
             }
             $styleIterator = $this->view->headStyle()->getIterator();
             foreach ($styleIterator as $item) {
                 $cssStyles[] = $item->content;
             }
             break;
         case 'js':
             $iterator = $this->view->headScript()->getIterator();
             foreach ($iterator as $item) {
                 if ($item->source == null) {
                     $urls[] = $item->attributes['src'];
                 } else {
                     $jsScripts[] = $item->source;
                 }
             }
             $this->_resetHeadScript();
             break;
     }
     if (count($urls) == 0) {
         return '';
     }
     $start = strlen($staticUrl);
     foreach ($urls as $url) {
         if (substr($url, 0, $start) == $staticUrl) {
             $url = substr($url, $start);
             $url = ltrim($url, '/');
             $url = str_replace('/', DS, $url);
             $url = ROOT_DIR . DS . $url;
         }
         $files[] = $url;
     }
     /**
      * Compare the timestamp of the cached file with
      * timestamp of all included file
      */
     $maxTimeStamp = 0;
     foreach ($files as $index => $f) {
         if (file_exists($f)) {
             $maxTimeStamp = max($maxTimeStamp, filemtime($f));
         }
     }
     if (file_exists($cachePath) && $maxTimeStamp > filemtime($cachePath)) {
         unlink($cachePath);
     }
     if (!file_exists($cachePath)) {
         $content = '';
         switch ($type) {
             case 'css':
                 foreach ($files as $index => $f) {
                     $path = pathinfo($f);
                     $url = $urls[$index];
                     $url = substr($url, 0, -strlen($path['basename']));
                     $url = rtrim($url, '/');
                     $str = file_get_contents($f);
                     /**
                      * Replace value of background and background-image properties
                      * with the full URL.
                      * We have to handle some expressions:
                      * - background: #Color_Code url(images/...)
                      * - background-image: url(images/...)
                      * - background: url('images/...')
                      * - jQueryUI theme (/js/jquery.ui/themes/base/ui.theme.css)
                      */
                     $str = preg_replace("/background([-image]*):(\\s*)([#0-9a-zA-Z]*)([\\/\\*\\{a-zA-Z\\}\\*\\/]*)(\\s*)url\\(([']*)images\\/([\\w-.]+)([']*)\\)/", 'background$1: $3 url(' . $url . '/images/$7)', $str);
                     $content .= "\n\n" . trim($str);
                 }
                 foreach ($cssStyles as $style) {
                     $content .= "\n\n" . trim($style);
                 }
                 /**
                  * Use CSSTidy to compress CSS content
                  */
                 require_once 'csstidy/class.csstidy.php';
                 $csstidy = new csstidy();
                 $csstidy->set_cfg('remove_last_;', true);
                 $csstidy->load_template(self::$_CSS_COMPRESS);
                 $csstidy->parse($content);
                 $content = $csstidy->print->plain();
                 break;
             case 'js':
                 require_once 'jsmin/jsmin.php';
                 foreach ($files as $index => $f) {
                     if (file_exists($f)) {
                         $str = file_get_contents($f);
                     } else {
                         $str = file_get_contents($urls[$index]);
                     }
                     $content .= "\n\n" . trim(JSMin::minify($str));
                 }
                 foreach ($jsScripts as $script) {
                     $content .= "\n\n" . trim(JSMin::minify($script));
                 }
                 break;
         }
         if ($fp = fopen($cachePath, 'wb')) {
             fwrite($fp, $content);
             fclose($fp);
         }
     }
     return $this;
 }
 protected function csstidy($filescontent = '')
 {
     $css = new csstidy();
     $css->set_cfg('sort_selectors', false);
     $css->set_cfg('sort_properties', false);
     $css->set_cfg('merge_selectors', 0);
     $css->set_cfg('optimise_shorthands', 1);
     $css->set_cfg('compress_colors', true);
     $css->set_cfg('compress_font-weight', true);
     $css->set_cfg('lowercase_s', false);
     $css->set_cfg('case_properties', 1);
     $css->set_cfg('remove_bslash', false);
     $css->set_cfg('remove_last_;', true);
     $css->set_cfg('discard_invalid_properties', false);
     $css->load_template('high_compression');
     $result = $css->parse($filescontent);
     $filescontent = $css->print->plain();
     return $filescontent;
 }
Beispiel #22
0
        }
        $html .= '>' . $label . '</option>';
    }
    if (!$html) {
        $html .= '<option value="0">---</option>';
    }
    return $html;
}
$css = new csstidy();
$is_custom = isset($_REQUEST['custom']) && !empty($_REQUEST['custom']) && isset($_REQUEST['template']) && $_REQUEST['template'] === '4';
if ($is_custom) {
    setcookie('custom_template', $_REQUEST['custom'], time() + 360000);
}
rmdirr('temp');
if (isset($_REQUEST['case_properties'])) {
    $css->set_cfg('case_properties', $_REQUEST['case_properties']);
}
if (isset($_REQUEST['lowercase'])) {
    $css->set_cfg('lowercase_s', true);
}
if (!isset($_REQUEST['compress_c']) && isset($_REQUEST['post'])) {
    $css->set_cfg('compress_colors', false);
}
if (!isset($_REQUEST['compress_fw']) && isset($_REQUEST['post'])) {
    $css->set_cfg('compress_font-weight', false);
}
if (isset($_REQUEST['merge_selectors'])) {
    $css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']);
}
if (isset($_REQUEST['optimise_shorthands'])) {
    $css->set_cfg('optimise_shorthands', $_REQUEST['optimise_shorthands']);
Beispiel #23
0
 /**
  * Создает css-компрессор и инициализирует его конфигурацию
  *
  * @return bool
  */
 protected function InitCssCompressor()
 {
     /**
      * Получаем параметры из конфигурации
      */
     $aParams = Config::Get('compress.css');
     $this->oCssCompressor = $aParams['use'] ? new csstidy() : null;
     /**
      * Если компрессор не создан, завершаем работу инициализатора
      */
     if (!$this->oCssCompressor) {
         return false;
     }
     /**
      * Устанавливаем параметры
      */
     $this->oCssCompressor->set_cfg('case_properties', $aParams['case_properties']);
     $this->oCssCompressor->set_cfg('merge_selectors', $aParams['merge_selectors']);
     $this->oCssCompressor->set_cfg('optimise_shorthands', $aParams['optimise_shorthands']);
     $this->oCssCompressor->set_cfg('remove_last_;', $aParams['remove_last_;']);
     $this->oCssCompressor->set_cfg('css_level', $aParams['css_level']);
     $this->oCssCompressor->load_template($aParams['template']);
     return true;
 }
Beispiel #24
0
 private function get_css_html($cachefile)
 {
     if (Configure::read('debug') > 0) {
         $ret = "";
         foreach ($this->libs['css'] as $lib) {
             $ret .= $this->Html->css($lib);
         }
         return $ret;
     }
     if (file_exists($this->cachePath['css'] . '/' . $cachefile)) {
         return $this->Html->css($cachefile);
     }
     // Get the content
     $file_content = '';
     foreach ($this->libs['css'] as $lib) {
         $file_content .= "\n\n" . file_get_contents($this->basePath['css'] . '/' . $lib);
     }
     // Get inline code if exist
     if (!empty($this->inline_code['css'])) {
         foreach ($this->inline_code['css'] as $inlineCss) {
             $file_content .= "\n\n" . $inlineCss;
         }
     }
     // If compression is enable, compress it !
     if ($this->__options['css']['enableCompression']) {
         App::import('Vendor', 'csstidy', array('file' => 'class.csstidy.php'));
         $tidy = new csstidy();
         $tidy->load_template($this->__options['css']['compression']);
         $tidy->set_cfg('sort_selectors', FALSE);
         $tidy->set_cfg('sort_properties', FALSE);
         $tidy->parse($file_content);
         $file_content = $tidy->print->plain();
     }
     if ($fp = fopen($this->cachePath['css'] . '/' . $cachefile, 'wb')) {
         fwrite($fp, $file_content);
         fclose($fp);
     }
     return $this->Html->css($cachefile);
 }
 /**
  * Implements SimpleExpectation::test().
  * @param $filename Filename of test file to test.
  */
 function test($filename = false)
 {
     if ($filename) {
         $this->load($filename);
     }
     $css = new csstidy();
     $css->set_cfg($this->settings);
     $css->parse($this->css);
     if ($this->print) {
         $this->actual = $css->print->plain($this->default_media);
     } else {
         $this->actual = $css->css;
     }
     return $this->expect === $this->actual;
 }
Beispiel #26
0
if (!file_exists($cache_dir)) {
    $status = @mkdir($cache_dir, 0755);
}
$cssdata = file_get_contents($css_file);
$cssmd5 = md5($cssdata);
$cache_file = $cache_dir . "/" . base64_encode($_SERVER['SERVER_NAME'] . "/" . $css_file);
$data = array();
if (file_exists($cache_file)) {
    $data = unserialize(file_get_contents($cache_file));
}
if (!isset($data['md5']) || $cssmd5 != $data['md5']) {
    require_once 'external/csstidy/class.csstidy.php';
    $css = new csstidy();
    $css->load_template('high_compression');
    $result = $css->parse($cssdata);
    $css->set_cfg('optimise_shorthands', 1);
    $css->set_cfg('merge_selectors', 2);
    $css->set_cfg('compress_colors', true);
    $css->set_cfg('compress_font-weight', true);
    $css->set_cfg('remove_bslash', true);
    $output = $css->print->plain();
    $fp = @fopen($cache_file, 'w');
    $data['md5'] = $cssmd5;
    $data['css'] = $output;
    @fwrite($fp, serialize($data));
    @fclose($fp);
}
if (!isset($data['css'])) {
    $data['css'] = $cssdata;
}
print $data['css'];
<?php

require 'css_results.php';
require '../class.csstidy.php';
ini_set('display_errors', 'On');
$css = new csstidy();
$css->set_cfg('preserve_css', false);
$css_code = file_get_contents('fisubsilver.css');
$css->parse($css_code);
if ($css->css === $xhtml_result) {
    echo '<div style="color:green">XHTML OK!</div>';
} else {
    echo '<div style="color:red">XHTML failed!</div>';
}
flush();
$css_code = file_get_contents('base.css');
$css->parse($css_code);
if ($css->css === $ala_result) {
    echo '<div style="color:green">ALA OK!</div>';
} else {
    echo '<div style="color:red">ALA failed!</div>';
}
flush();
$css->set_cfg('remove_last_;', true);
if ($css->print->formatted() === $ala_html) {
    echo '<div style="color:green">ALA HTML OK!</div>';
} else {
    echo '<div style="color:red">ALA HTML failed!</div>';
}
flush();
$css->set_cfg('optimise_shorthands', false);
Beispiel #28
0
 /**
  * @access public
  * @param $source
  * @return string
  */
 public function post_format($source, $scaffold)
 {
     $css = new csstidy();
     $css->set_cfg('case_properties', false);
     $css->set_cfg('lowercase_s', true);
     $css->set_cfg('compress_colors', false);
     $css->set_cfg('compress_font-weight', false);
     $css->set_cfg('merge_selectors', true);
     $css->set_cfg('optimise_shorthands', true);
     $css->set_cfg('remove_bslash', false);
     $css->set_cfg('preserve_css', true);
     $css->set_cfg('sort_selectors', true);
     $css->set_cfg('sort_properties', true);
     $css->set_cfg('remove_last_;', true);
     $css->set_cfg('discard_invalid_properties', true);
     $css->set_cfg('css_level', '2.1');
     $css->set_cfg('timestamp', false);
     $css->load_template('highest_compression');
     $result = $css->parse($source->contents);
     $output = $css->print->plain();
     $source->contents = $output;
 }
Beispiel #29
0
<?php

$file = "cssparse.css";
$content = file_get_contents($file);
require 'class.csstidy.php';
$instance = new csstidy();
$instance->set_cfg("lowercase_s", true);
$instance->set_cfg("remove_last_", true);
$instance->set_cfg("sort_properties", true);
$instance->set_cfg("sort_selectors", true);
$instance->set_cfg("discard_invalid_properties", true);
$instance->set_cfg("preserve_css", true);
$instance->set_cfg("timestamp", true);
$result = $instance->parse($content);
echo $result;
Beispiel #30
0
 switch ($optimize['css']) {
     case 'csstidy':
         /*
          * CSStidy would be great, but watch it with the 'optimise_shorthands'
          * setting: that bugger implicitly ASSUMES CSS3 ABILITY: the generated
          *     font:
          * and
          *     background:
          * 'shorthands' are NOT accepted by FF3.6.x at least.
          *
          * Hence never dial that setting higher than '1' unless you fix csstidy.
          */
         /*MARKER*/
         require_once BASE_PATH . '/lib/includes/csstidy/class.csstidy.php';
         $css = new csstidy();
         $css->set_cfg('remove_last_;', true);
         $css->set_cfg('preserve_css', false);
         $css->set_cfg('lowercase_s', false);
         // MUST be 'false' or scrollbar in admin screen==MochaUI desktop is GONE :-(
         /*
          * 1 common shorthands optimization
          * 2 + font property optimization
          * 3 + background property optimization
          */
         $css->set_cfg('optimise_shorthands', 1);
         /* rewrite all properties with low case, better for later gzip */
         $css->set_cfg('case_properties', false);
         /* sort properties in alpabetic order, better for later gzip */
         $css->set_cfg('sort_properties', true);
         /*
          * 1, 3, 5, etc -- enable sorting selectors inside @media: a{}b{}c{}