Created
November 2, 2011 14:36
-
-
Save Cipa/1333793 to your computer and use it in GitHub Desktop.
Full urls custom modfier for PHx
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 | |
$replace = array(); | |
$replaceWith = array(); | |
//match links | |
preg_match_all('(href="(.*?)")',$output,$matches); | |
foreach($matches[1] as $key=>$m){ | |
$hasHttp = strpos($m, 'http'); | |
$hasMailto = strpos($m, 'mailto'); | |
if($hasHttp === false && $hasMailto === false ){ | |
$new = $modx->config['site_url'] . $m; | |
if(!in_array($new, $replaceWith)){//avoid duplicates | |
array_push($replace, $m); | |
array_push($replaceWith, $new); | |
} | |
} | |
} | |
//match src | |
preg_match_all('(src="(.*?)")',$output,$matches); | |
foreach($matches[1] as $key=>$m){ | |
$hasHttp = strpos($m, 'http'); | |
if($hasHttp === false){ | |
$new = $modx->config['site_url'] . $m; | |
if(!in_array($new, $replaceWith)){//avoid duplicates | |
array_push($replace, $m); | |
array_push($replaceWith, $new); | |
} | |
} | |
} | |
$output = str_replace($replace, $replaceWith, $output); | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment