Skip to content

Instantly share code, notes, and snippets.

@Cipa
Created November 2, 2011 14:36
Show Gist options
  • Save Cipa/1333793 to your computer and use it in GitHub Desktop.
Save Cipa/1333793 to your computer and use it in GitHub Desktop.
Full urls custom modfier for PHx
<?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