self::$protect_tags_start . base64_decode($string) . self::$protect_tags_end; } return self::$protect_start . base64_decode($string) . self::$protect_end; } /** * Replace any protected tags to original * * @param string $string * @param array $tags */ public static function unprotectForm(&$string, $tags = []) { // Protect entire form if (empty($tags)) { self::unprotect($string); return; } self::unprotectTags($string, $tags); } /** * Replace any protected text to original * * @param string|array $string */ public static function unprotect(&$string) { if (is_array($string)) { foreach ($string as &$part) { self::unprotect($part); } return; } self::unprotectByDelimiters( $string, [self::$protect_tags_start, self::$protect_tags_end] ); self::unprotectByDelimiters( $string, [self::$protect_start, self::$protect_end] ); if (StringHelper::contains($string, [self::$protect_tags_start, self::$protect_tags_end, self::$protect_start, self::$protect_end])) { self::unprotect($string); } } /** * Replace any protected tags to original * * @param string $string * @param array $tags * @param bool $include_closing_tags */ public static function unprotectTags(&$string, $tags = [], $include_closing_tags = true) { [$tags, $protected] = self::prepareTags($tags, $include_closing_tags); $string = str_replace($protected, $tags, $string); } /** * @param string $string * @param array $delimiters */ private static function unprotectByDelimiters(&$string, $delimiters) { if ( ! StringHelper::contains($string, $delimiters)) { return; } $regex = RegEx::preparePattern(RegEx::quote($delimiters), 's', $string); $parts = preg_split($regex, $string); foreach ($parts as $i => &$part) { if ($i % 2 == 0) { continue; } $part = base64_decode($part); } $string = implode('', $parts); } /** * Replace any protected text to original * * @param string $string */ public static function unprotectHtmlSafe(&$string) { $string = str_replace( [ self::$html_safe_start, self::$html_safe_end, self::$html_safe_tags_start, self::$html_safe_tags_end, ], [ self::$protect_start, self::$protect_end, self::$protect_tags_start, self::$protect_tags_end, ], $string ); self::unprotect($string); } /** * Replace any protected tags to original * * @param string $string * @param array $unprotected * @param array $protected */ public static function unprotectInString(&$string, $unprotected = [], $protected = []) { $protected = ! empty($protected) ? $protected : self::protectArray($unprotected); $string = str_replace($protected, $unprotected, $string); } /** * Wrap string in comment tags * * @param string $name * @param string $comment * * @return string */ public static function wrapInCommentTags($name, $string) { [$start, $end] = self::getCommentTags($name); return $start . $string . $end; } /** * Wraps a javascript declaration with comment tags * * @param string $content * @param string $name * @param bool $minify */ public static function wrapScriptDeclaration($content = '', $name = '', $minify = true) { return self::wrapDeclaration($content, $name, 'scripts', $minify); } /** * Wraps a style or javascript declaration with comment tags * * @param string $content * @param string $name * @param string $type * @param bool $minify */ public static function wrapDeclaration($content = '', $name = '', $type = 'styles', $minify = true) { if (empty($name)) { return $content; } [$start, $end] = self::getInlineCommentTags($name, $type); $spacer = $minify ? ' ' : "\n"; return $start . $spacer . $content . $spacer . $end; } /** * Wraps a stylesheet declaration with comment tags * * @param string $content * @param string $name * @param bool $minify */ public static function wrapStyleDeclaration($content = '', $name = '', $minify = true) { return self::wrapDeclaration($content, $name, 'styles', $minify); } }