Created
October 23, 2012 16:09
-
-
Save AgelxNash/3939722 to your computer and use it in GitHub Desktop.
StaticUrl plugin for MODX Revo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/**************************************/ | |
/** StaticUrl plugin for MODX Revo | |
* | |
* @version 1.2 | |
* @author Borisov Evgeniy aka Agel Nash (agel-nash@xaker.ru) | |
* @date 23.10.2012 | |
* | |
* @category plugin | |
* @internal @event OnWebPagePrerender | |
* @internal @properties &StaticNewUrl=CDN URL;integer;1 | |
* @internal @modx_category HTML-code | |
* | |
* | |
* | |
* INSTALL | |
* 3) Создать параметр к плагину с именем StaticNewUrl | |
* - Значение параметра: URL домена с которого будет грузиться статика | |
* - Тип ввода: текст | |
*/ | |
/*************************************/ | |
if($modx->event->name=='OnWebPagePrerender'){ | |
$html = &$modx->resource->_output; | |
$replaceD=array(); | |
preg_match_all('#src=(?:"|\')(.*?)>#',$html,$matches); | |
foreach($matches[1] as $item){ | |
if(substr($item,0,1)!='/'){ | |
continue; | |
} | |
if(substr($item,0,2)!='//'){ | |
$replaceD[md5($item)]=$item; | |
} | |
} | |
preg_match_all('#<link.*?href=(?:"|\')(.*?)>#',$html,$matches); | |
foreach($matches[1] as $item){ | |
if(substr($item,0,1)!='/'){ | |
continue; | |
} | |
if(substr($item,0,2)!='//' && substr($item,0,12)!='/favicon.ico'){ | |
$replaceD[md5($item)]=$item; | |
} | |
} | |
array_unique($replaceD); | |
foreach($replaceD as $item){ | |
$html=str_replace($item,$StaticNewUrl.substr($item,1),$html); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment