function tag_reassemble($a) { $node = $a[1]; // getting referer document path $base = env('HTTP_REFERER'); preg_match("/^([a-z]*:\\/\\/[^\\/]*)\\/(.*?)(index.php|\$)/i", $base, $url); $host = $url[1]; $docroot = '/' . ($url[3] ? dirname($url[2]) . '/' : $url[2]); $attr = format::split_attributes(isset($a[2]) ? $a[2] : null); // checking resources $src_arr = array('src', 'href', 'action'); foreach ($src_arr as $src) { if (isset($attr[$src])) { if (substr($attr[$src], 0, 2) == '..') { $path = explode('/', $docroot); if (($del = strpos($attr[$src], '?')) !== false) { $relative = substr($attr[$src], 0, $del); } $rel = explode('/', isset($relative) ? $relative : $attr[$src]); for ($i = 0; $rel[$i] == '..'; $i++) { array_pop($path); } $attr[$src] = (count($path) ? implode('/', $path) . '/' : '') . substr($attr[$src], $i * 3); } } } switch ($node) { case 'img': if (!isset($attr['alt'])) { $attr['alt'] = htmlspecialchars(basename($attr['src'])); } if (!isset($attr['width']) || !isset($attr['height'])) { $attr['width'] = $attr['height'] = 0; } if (substr($attr['src'], 0, 7) != 'http://' || substr($attr['src'], 0, strlen($_SERVER['HTTP_HOST'])) == $_SERVER['HTTP_HOST']) { $src = urldecode($attr['src']); $local_src = TM_SOURCE_DIR . ltrim($src, '/'); if (file_exists($local_src)) { $size = @getimagesize($local_src); if (isset($size[0]) && isset($size[1])) { $attr['width'] = $size[0]; $attr['height'] = $size[1]; } } } // this line breaks the standards... but surely the user don't cares (she/he didn't provide a with nor a height attribute) if (0 == $attr['width'] + $attr['height']) { unset($attr['width'], $attr['height']); } break; } $attr = format::join_attributes($attr); return '<' . $node . ($attr ? ' ' . $attr : '') . (format::is_single_tag($node) ? ' /' : '') . '>'; }