loadXML($svg_file); $xpath = new DOMXPath($doc); $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg'); $root = $xpath->query("/*"); $root[0]->setAttribute("viewBox", "0 0 1280 720"); $widthq = $xpath->query("/*/@width"); $heightq = $xpath->query("/*/@height"); $root = $xpath->query("/*"); $root[0]->setAttribute("viewBox", "0 0 ". $widthq[0]->nodeValue . " " . $heightq[0]->nodeValue); $widthq[0]->nodeValue = "100%"; $heightq[0]->nodeValue = "100%"; //Get all Text Nodes $style = $xpath->query('//svg:text'); $keyValueStore=array(); //Get all rect nodes before text nodes and store them in key value store to access them for manipulation foreach ($style as $result) { $style2 = $xpath->query('./preceding-sibling::*[1]', $result); //echo $style2[0]->nodeName; foreach ($style2 as $result3) { //echo $result3->nodeName; $keyValueStore[$result->nodeValue] = $result3; } } //$keyValueStore["*imga"]->setAttribute("fill", "#FFFFFF"); //replace text from URL GET within image foreach($_GET as $key => $value){ if($key != "___image___"){ $alltext = $xpath->query('//svg:text'); foreach ($alltext as $text) { if($key == $text->nodeValue){ $text->nodeValue = $value; } } } } //load image Replacements $replacements = new DOMDocument(); $newstr = substr( $_GET["___image___"], 0, strpos( $_GET["___image___"], '/', strpos( $_GET["___image___"], '/')+1)); $urlreplacement = dirname('https://' . $_SERVER['HTTP_HOST']. $_SERVER['PHP_SELF'], 2) . "/server/" . $newstr . "/replacement"; $replacements->loadXML(file_get_contents($urlreplacement)); $elements = $replacements->getElementsByTagName('item'); foreach($elements as $node){ if(array_key_exists($node->getElementsByTagName("abbreviation")[0]->nodeValue, $keyValueStore)){ $extension = pathinfo($node->getElementsByTagName("url")[0]->nodeValue, PATHINFO_EXTENSION); if($extension == "mp4"){ $element = $doc->createElement('foreignObject'); $element->setAttribute("x", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('x')); $element->setAttribute("y", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('y')); $element->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width')); $element->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height')); $element1 = $doc->createElement('video'); $element1->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width')); $element1->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height')); $element1->setAttribute("controls", ""); $element2 = $doc->createElement('source'); $element2->setAttribute("type", "video/mp4"); $element2->setAttribute("src", $node->getElementsByTagName("url")[0]->nodeValue); $element1->appendChild($element2); $element->appendChild($element1); $parent = $doc->getElementsByTagName('svg')->item(0); $parent->appendChild($element); } else{ //create image element (currently we use background image) /* $element = $doc->createElement('image'); $element->setAttribute("x", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('x')); $element->setAttribute("y", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('y')); $element->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width')); $element->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height')); $element->setAttribute("xlink:href", $node->getElementsByTagName("url")[0]->nodeValue); $doc->appendChild($element); $parent = $doc->getElementsByTagName('svg')->item(0); $parent->appendChild($element); */ //create pattern for rect-filling looks like this: /* */ $element3 = $doc->createElement('pattern'); $element3->setAttribute("id", $node->getElementsByTagName("abbreviation")[0]->nodeValue); $element3->setAttribute("x", "0"); $element3->setAttribute("y", "0"); $element3->setAttribute("width", "1"); $element3->setAttribute("height", "1"); $element2 = $doc->createElement('image'); $element2->setAttribute("x", "0"); $element2->setAttribute("y", "0"); $element2->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width')); $element2->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height')); $element2->setAttribute("xlink:href", $node->getElementsByTagName("url")[0]->nodeValue); $element3->appendChild($element2); $parent = $doc->getElementsByTagName('defs')->item(0); $parent->appendChild($element3); $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->setAttribute("fill", "url(#".$node->getElementsByTagName("abbreviation")[0]->nodeValue.")"); } } } echo $doc->saveXML(); ?>