dimti

Untitled

Mar 11th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. class DocumentWriteViewHelper
  3. {
  4.     public static function documentWrite($string)
  5.     {
  6.         if (\Majestic\Env::Server('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest') {
  7.             return $string;
  8.         }
  9.         $string = preg_replace("#\n|\r\n#", ' ', $string);
  10.         $string = preg_replace('#  *#', ' ', $string);
  11.         if (strstr($string, '<a') && !strstr($string, '<p') && !strstr($string, '<br')) {
  12.             $string = preg_replace( '#<a([^>]+)href="([^"]+)"#u', '<a$1data-href="$2"', $string );
  13.             $string = preg_replace( '#<a([^>]+)target="([^"]+)"#u', '<a$1data-target="$2"', $string );
  14.  
  15.             if ( preg_match( '#<a[^>]+class="[^"]*"#', $string ) ) {
  16.                 $string = preg_replace( '#<a([^>]+)class="([^"]*)"#u', '<span$1class="$2 link"', $string );
  17.                 $string = preg_replace( '#<span([^>]+)class=" ([^"]+)"#u', '<span$1class="$2"', $string );
  18.             }
  19.             $string = preg_replace( '#<a #u', '<span class="link" ', $string );
  20.             $string = preg_replace( '#</a>#', '</span>', $string );
  21.         } else {
  22.             return '<script type="text/javascript">document.write(\'' . preg_replace("#\n|\r\n#", "", preg_replace("#'#", "\\'", $string)) . '\');</script>';
  23.         }
  24.         return $string;
  25.     }
  26. }
Add Comment
Please, Sign In to add comment