} return $result; } set_time_limit(0); header('Content-Type: text/plain'); $css_rules_array = array(); get_file_list($file_list, 'forum/styles', 'style.css'); get_file_list($file_list, 'forum/styles', 'mobile.css'); foreach ($file_list as $css_filepath) { $css_rules_array[$css_filepath] = parse_css_to_array(file_get_contents($css_filepath)); } foreach ($css_rules_array as $css_filepath => $css_rules_set) { $default_css_filepath = sprintf('forum/styles/default/%s', basename($css_filepath)); $default_css_rules = parse_css_to_array(file_get_contents($default_css_filepath)); file_put_contents($default_css_filepath, parse_array_to_css($default_css_rules)); $default_css_rules = parse_css_to_array(file_get_contents($default_css_filepath)); foreach ($default_css_rules as $selector => $default_rules_set) { if (!isset($css_rules_set[$selector])) { $css_rules_set[$selector] = $default_rules_set; } else { foreach ($default_rules_set as $rule_name => $value) { if (preg_match('/(#[0-9A-F]{3,6}|rgba?)/i', $value) > 0) { continue; } if (preg_match('/color/i', $rule_name) > 0) { continue; } $css_rules_set[$selector][$rule_name] = $value; } } }
function get_css_styles($path, $pattern, $exclude_dirs_array, $exclude_files_array) { $output = array(); $directory_iterator = new DirectoryIterator($path); foreach ($directory_iterator as $dirinfo) { /** @var DirectoryIterator $dirinfo */ if (!$dirinfo->isDir() || $dirinfo->isDot() || in_array($dirinfo->getBasename(), $exclude_dirs_array)) { continue; } $style_name = $dirinfo->getBasename(); $style_pathname = str_replace(DIRECTORY_SEPARATOR, '/', $dirinfo->getPathname()); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($style_pathname)); foreach ($iterator as $fileinfo) { /** @var SplFileInfo $fileinfo */ if ($fileinfo->isDir()) { continue; } if (in_array($fileinfo->getBasename(), $exclude_files_array)) { continue; } if (!preg_match($pattern, str_replace(DIRECTORY_SEPARATOR, '/', $fileinfo->getPathname()))) { continue; } $css_filename = ltrim(str_replace(DIRECTORY_SEPARATOR, '/', str_replace($style_pathname, '', $fileinfo->getPathname())), '/'); if (!isset($output[$style_name])) { $output[$style_name] = array(); } $css_file_contents = file_get_contents($fileinfo->getPathname()); $output[$style_name][$css_filename] = parse_css_to_array($css_file_contents); } } return $output; }