/** * Transform an LTR stylesheet to RTL * @param string $css stylesheet to transform * @param $swapLtrRtlInURL Boolean: If true, swap 'ltr' and 'rtl' in URLs * @param $swapLeftRightInURL Boolean: If true, swap 'left' and 'right' in URLs * @return string Transformed stylesheet */ public static function transform($css, $swapLtrRtlInURL = false, $swapLeftRightInURL = false) { // We wrap tokens in ` , not ~ like the original implementation does. // This was done because ` is not a legal character in CSS and can only // occur in URLs, where we escape it to %60 before inserting our tokens. $css = str_replace('`', '%60', $css); self::buildPatterns(); // Tokenize single line rules with /* @noflip */ $noFlipSingle = new CSSJanus_Tokenizer(self::$patterns['noflip_single'], '`NOFLIP_SINGLE`'); $css = $noFlipSingle->tokenize($css); // Tokenize class rules with /* @noflip */ $noFlipClass = new CSSJanus_Tokenizer(self::$patterns['noflip_class'], '`NOFLIP_CLASS`'); $css = $noFlipClass->tokenize($css); // Tokenize comments $comments = new CSSJanus_Tokenizer(self::$patterns['comment'], '`C`'); $css = $comments->tokenize($css); // LTR->RTL fixes start here $css = self::fixDirection($css); if ($swapLtrRtlInURL) { $css = self::fixLtrRtlInURL($css); } if ($swapLeftRightInURL) { $css = self::fixLeftRightInURL($css); } $css = self::fixLeftAndRight($css); $css = self::fixCursorProperties($css); $css = self::fixFourPartNotation($css); $css = self::fixBorderRadius($css); $css = self::fixBackgroundPosition($css); $css = self::fixShadows($css); // Detokenize stuff we tokenized before $css = $comments->detokenize($css); $css = $noFlipClass->detokenize($css); $css = $noFlipSingle->detokenize($css); return $css; }
/** * Transform an LTR stylesheet to RTL * @param $css String: stylesheet to transform * @param $swapLtrRtlInURL Boolean: If true, swap 'ltr' and 'rtl' in URLs * @param $swapLeftRightInURL Boolean: If true, swap 'left' and 'right' in URLs * @return Transformed stylesheet */ public static function transform($css, $swapLtrRtlInURL = false, $swapLeftRightInURL = false) { self::buildPatterns(); // We wrap tokens in ` , not ~ like the original implementation does. // This was done because ` is not a legal character in CSS and can only // occur in URLs, where we escape it to %60 before inserting our tokens. $css = str_replace(self::$patterns['token_delimiter'], '%60', $css); // Tokenize single line rules with /* @noflip */ $noFlipSingle = new CSSJanus_Tokenizer(self::$patterns['noflip_single_re'], '`NOFLIP_SINGLE`'); $css = $noFlipSingle->tokenize($css); // Tokenize class rules with /* @noflip */ $noFlipClass = new CSSJanus_Tokenizer(self::$patterns['noflip_class_re'], '`NOFLIP_CLASS`'); $css = $noFlipClass->tokenize($css); // Tokenize comments $comments = new CSSJanus_Tokenizer(self::$patterns['comment_re'], '`C`'); $css = $comments->tokenize($css); # Tokenize gradients since we don't want to mirror the values inside //$comments = new CSSJanus_Tokenizer( self::$patterns['comment_re']GradientMatcher(), '`GRADIENT`' ); //$css = $comments->tokenize( $css ); // LTR->RTL fixes start here $css = self::FixBodyDirectionLtrAndRtl($css); if ($swapLtrRtlInURL) { $css = self::fixLtrRtlInURL($css); } if ($swapLeftRightInURL) { $css = self::fixLeftRightInURL($css); } $css = self::fixLeftAndRight($css); $css = self::fixCursorProperties($css); $css = self::fixBorderRadius($css); # Since FourPartNotation conflicts with BorderRadius, we tokenize border-radius properties here. $border_radius_tokenizer = new CSSJanus_Tokenizer(self::$patterns['border_radius_tokenizer_re'], '`BORDER_RADIUS`'); $css = $border_radius_tokenizer->tokenize($css); $css = self::fixFourPartNotation($css); $css = $border_radius_tokenizer->detokenize($css); $css = self::fixBackgroundPosition($css); // Detokenize stuff we tokenized before $css = $comments->detokenize($css); $css = $noFlipClass->detokenize($css); $css = $noFlipSingle->detokenize($css); return $css; }