protected static function cb_extractStrings($match) { $label = csscrush::createTokenLabel('s'); csscrush::$storage->tokens->strings[$label] = $match[0]; return $label; }
<?php require_once 'css/CssCrush.php'; $CssFile = csscrush::file("/cauldron/css/stylesheets/style.css"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <link rel="stylesheet" type="text/css" href="<?php echo $CssFile; ?> " /> <script type="text/javascript" src="js/jquery_1.7.1_min.js"></script> </head> <body>
protected static function rewriteImportRelativeUrls($import) { $stream = $import->content; // We're comparing file system position so we'll $hostDir = csscrush_util::normalizeSystemPath($import->hostDir, true); $importDir = csscrush_util::normalizeSystemPath(dirname($import->path), true); csscrush::$storage->tmp->relativeUrlPrefix = ''; $url_prefix = ''; if ($importDir === $hostDir) { // Do nothing if files are in the same directory return $stream; } elseif (strpos($importDir, $hostDir) === false) { // Import directory is higher than the host directory // Split the directory paths into arrays so we can compare segment by segment $host_segs = preg_split('!/+!', $hostDir, null, PREG_SPLIT_NO_EMPTY); $import_segs = preg_split('!/+!', $importDir, null, PREG_SPLIT_NO_EMPTY); // Shift the segments until they are on different branches while (@($host_segs[0] == $import_segs[0])) { array_shift($host_segs); array_shift($import_segs); // csscrush::log( array( $host_segs, $import_segs ) ); } // Count the remaining $host_segs to get the offset $level_diff = count($host_segs); $url_prefix = str_repeat('../', $level_diff) . implode('/', $import_segs); } else { // Import directory is lower than host directory // easy, url_prefix is the difference $url_prefix = substr($importDir, strlen($hostDir) + 1); } if (empty($url_prefix)) { return $stream; } // Add the directory seperator ending (if needed) if ($url_prefix[strlen($url_prefix) - 1] !== '/') { $url_prefix .= '/'; } csscrush::log('relative_url_prefix: ' . $url_prefix); // Search for all relative url and data-uri references in the content // and prepend $relative_url_prefix // Make $url_prefix accessible in callback scope csscrush::$storage->tmp->relativeUrlPrefix = $url_prefix; $url_function_patt = '! ([^a-z-]) # the preceeding character (data-uri|url) # the function name \\(\\s*([^\\)]+)\\s*\\) # the url !xi'; $stream = preg_replace_callback($url_function_patt, array('self', 'cb_rewriteImportRelativeUrl'), $stream); return $stream; }
if ($variables) { parse_str($variables, $in_vars); $process_opts['vars'] = $in_vars; } $process_opts['boilerplate'] = $boilerplate ? true : false; $process_opts['debug'] = $pretty ? true : false; $process_opts['rewrite_import_urls'] = true; $import_context = $input_file ? dirname(realpath($input_file)) : null; // If there is an import context set it to the document root if ($import_context) { $old_doc_root = csscrush::$config->docRoot; csscrush::$config->docRoot = $import_context; $process_opts['import_context'] = $import_context; } // Process the stream $output = csscrush::string($input, $process_opts); // Reset the document root after processing if ($import_context) { csscrush::$config->docRoot = $old_doc_root; } ################################################################## ## Output if ($output_file) { if (!@file_put_contents($output_file, $output)) { fwrite($stdout, "Could not write to path '{$output_file}'\n"); if (strpos($output_file, '~') === 0) { fwrite($stdout, "No tilde expansion\n"); } exit(0); } } else {
public static function matchAllBrackets($str, $pair = '()', $offset = 0) { $match_obj = new stdClass(); $match_obj->string = $str; $match_obj->raw = $str; $match_obj->matches = array(); list($opener, $closer) = str_split($pair, 1); // Return early if there's no match if (false === ($first_offset = strpos($str, $opener, $offset))) { return $match_obj; } // Step through the string one character at a time storing offsets $paren_score = -1; $inside_paren = false; $match_start = 0; $offsets = array(); for ($index = $first_offset; $index < strlen($str); $index++) { $char = $str[$index]; if ($opener === $char) { if (!$inside_paren) { $paren_score = 1; $match_start = $index; } else { $paren_score++; } $inside_paren = true; } elseif ($closer === $char) { $paren_score--; } if (0 === $paren_score) { $inside_paren = false; $paren_score = -1; $offsets[] = array($match_start, $index + 1); } } // Step backwards through the matches while ($offset = array_pop($offsets)) { list($start, $finish) = $offset; $before = substr($str, 0, $start); $content = substr($str, $start, $finish - $start); $after = substr($str, $finish); $label = csscrush::createTokenLabel('p'); $str = $before . $label . $after; $match_obj->matches[$label] = $content; // Parens will be folded in later csscrush::$storage->tokens->parens[$label] = $content; } $match_obj->string = $str; return $match_obj; }