Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DocumentWriteViewHelper
- {
- public static function documentWrite($string)
- {
- if (\Majestic\Env::Server('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest') {
- return $string;
- }
- $string = preg_replace("#\n|\r\n#", ' ', $string);
- $string = preg_replace('# *#', ' ', $string);
- if (strstr($string, '<a') && !strstr($string, '<p') && !strstr($string, '<br')) {
- $string = preg_replace( '#<a([^>]+)href="([^"]+)"#u', '<a$1data-href="$2"', $string );
- $string = preg_replace( '#<a([^>]+)target="([^"]+)"#u', '<a$1data-target="$2"', $string );
- if ( preg_match( '#<a[^>]+class="[^"]*"#', $string ) ) {
- $string = preg_replace( '#<a([^>]+)class="([^"]*)"#u', '<span$1class="$2 link"', $string );
- $string = preg_replace( '#<span([^>]+)class=" ([^"]+)"#u', '<span$1class="$2"', $string );
- }
- $string = preg_replace( '#<a #u', '<span class="link" ', $string );
- $string = preg_replace( '#</a>#', '</span>', $string );
- } else {
- return '<script type="text/javascript">document.write(\'' . preg_replace("#\n|\r\n#", "", preg_replace("#'#", "\\'", $string)) . '\');</script>';
- }
- return $string;
- }
- }
Add Comment
Please, Sign In to add comment