Advertisement
krot

bitrix delete js

Dec 8th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2. AddEventHandler("main", "OnEndBufferContent", "deleteJs");
  3. function deleteJs(&$content) {
  4.    global $USER, $APPLICATION;
  5.    if((is_object($USER) && $USER->IsAuthorized()) || strpos($APPLICATION->GetCurDir(), "/bitrix/")!==false) return;
  6.    if($APPLICATION->GetProperty("save_kernel") == "Y") return;
  7.    
  8.  
  9. if ($APPLICATION->GetCurPage(true) == SITE_DIR."index.php"){
  10. //css
  11. if(preg_match_all('#<link.+?href=".+?kernel_main\/kernel_main\.css\?\d+"[^>]+>|<link.+?href=".+?tml\/page_[^>]+>#i',$content,$hSc)){
  12. if(!empty($hSc[0])){
  13. $scriptH=implode('',$hSc[0]);//все скрипты
  14. $content=preg_replace('#\s*(<link.+?href=".+?kernel_main\/kernel_main\.css\?\d+"[^>]+>|<link.+?href=".+?tml\/page_[^>]+>)\s*#i','',$content);
  15. $content=strtr($content,array('</body>'=>$scriptH.'</body>'));
  16. }
  17. }
  18.  
  19. if(preg_match_all('#<script(?:.|\n|\r)+?<\/script>#i',$content,$hSc)){
  20. if(!empty($hSc[0])){
  21. $scriptH=implode('',$hSc[0]);//все скрипты
  22. $content=preg_replace('#\s*<script(?:.|\n|\r)+?<\/script>\s*#i','',$content);
  23.  $content = preg_replace("/<!--(.*?)-->/s", "", $content);
  24.   $content = preg_replace("/[\x0d\x0a]+/", " ", $content);
  25.   $content = preg_replace("/>\s{4,}</", "> <", $content);
  26.  $content = preg_replace('/(["\'])\s+\/>/', '\1/>', $content);
  27. $content=strtr($content,array('</body>'=>$scriptH.'</body>'));
  28. }
  29. }
  30.  
  31.  
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement