geturlx(): Extended geturl

This is a modified and extended version of the original function geturl() who allows to “grab” external webcontent and to include it in the CMSimple content page. The content from the other website would be “embedded”.

Interesting if you would like to use other scripts in CMSimple without rewriting it as a plugin.

Attention: It is illegal to grab content from other websites and show them embedded in yours!

Example on how to use it in content (including an external gallery):

#CMSimple $output.=geturlx("","?gallery=Demo/Templates/MinimumBlue");#


To put in CMS.PHP (functions.php) or better include as an external file:

function geturlx($base,$default)
    Luc Saffre 2004-03-17...30:
    - replace relative links in content by absolute links
    note: considered as relative link is anything between the '"' of a
    href="" or src="" tag that does not contain a ":"
    character. If it contains a ":", then it is not modified.
    if geturlx fails there is not output at all. If you want to know
    why it failed, remove the "@" in front of fopen so that PHP will
    display a warning. Or uncomment the last two lines.
  if(substr($base,-1,1) != '/') $base .= '/';
  $urlx = $_GET['urlx'];
  if(strlen($urlx) == 0)
    $u = $base . $default;
    $u = $base . $urlx;
  $u = rawurldecode($u);
  $u = preg_replace("/\&/is","&",$u);
  // echo 'Original content from <a href="'.$u.'">here</a>';
      $t.=fread($fh, 1024);
    $t = preg_replace("/.*<body[^>]*>(.*)<\/body>.*/is","\\1",$t);
    $t = preg_replace("/src=\"([^\":]*)\"/is","src=\"$base\\1\"",$t);
    $t = preg_replace("/\('([^':]*)'/is",
    $t = preg_replace_callback("/href=\"([^\":]*)\"/is",
    return $t;
//      } else {
//        echo "could not open $u";
function geturlx_replace($matches) {
    callback function for preg_replace_callback used in geturlx
    $matches[0] is the complete match
    $matches[1] the match for the first subpattern enclosed in '(...)'
    and so on
  $uri = $_SERVER['REQUEST_URI'];
  $pos = strpos($uri,'urlx=');
  $newurl = '';
  if ($pos) {
    $self = substr($uri,0,$pos-1);
    if(strpos($urlx,'&')==false) {
      $rpos = strrpos($urlx,'/');
      if ($rpos)
        $newurl = substr($urlx,0,$rpos+1);
  } else $self = $uri;
  $newurl .= $matches[1];
  if (strpos($self,"?") === false)
    $self .= "?urlx=";
    $self .= "&urlx=";
  $self .= rawurlencode($newurl);
  return 'href="' . $self . '"';

This code is discontinued as it and should be replaced by the gxgeturl plugin!

back to addons


addons/geturlx.txt · Last modified: 2018/04/05 14:48 (external edit)
Webdesign: NMuD = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0