loadXML($svg_file); $xpath1 = new DOMXPath($doc1); $xpath1->registerNamespace('svg', 'http://www.w3.org/2000/svg'); //prüfen ob exteranlImage dann wird dieses verwendet if(strlen($svg_file) < 400){ $url = $xpath1->query("/svg:svg/svg:image/@href"); $svg_file = file_get_contents($url[0]->nodeValue); } $doc = new DOMDocument; $doc->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(); $keyValueStore2=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; //echo $result->nodeValue . " "; //get Rect foreach ($style2 as $result3) { //echo $result->nodeValue; //echo $result3->getAttribute('transform') . "
"; $keyValueStore[$result->nodeValue] = $result3; $keyValueStore2[$result->nodeValue] = $result; } } $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://") . $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']) . "/TransformProductCode.php" . "?ProductCode=" . $_GET["ProductCode"]; $json = file_get_contents($url); $asocarray = json_decode($json, true); $curstation = $_GET["Station"]; //Einzelbilder vom Universal Storage laden foreach ($keyValueStore as $key => $value) { $keyorig = $key; $key = substr($key, 1); $keyarray = str_split($key, 2); $fullfilename = ""; $textentry = ""; foreach($keyarray as $keypart){ //only if all keyparts (Pb Sy Pk Of) can be found within the asociative array (Pb -> E, Sy -> X) the file can be linked otherwise there is a problem. if($keypart == "ID"){ $fullfilename = $fullfilename . "_ID;" . substr($keyorig, strrpos($keyorig, "ID:") + 3); $textentry = substr($keyorig, strrpos($keyorig, "ID:") + 3); break; } else if(array_key_exists ($keypart, $asocarray)){ $fullfilename = $fullfilename . "_" . $keypart . ";" . $asocarray[$keypart]; } else{ continue 2; } } $fullfilename = substr($fullfilename, 1); $fullfilename = $universalStorageEinzelbilder . "Station" . $curstation . "/Station". $curstation. "_" . $fullfilename . ".jpg"; //if Real image was not found $file_headers = @get_headers($fullfilename); if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') { echo $key . " "; echo json_encode($asocarray); $onlyUsedParts=array(); foreach($asocarray as $keypart => $keyval){ if(in_array($keypart, $keyarray)){ array_push($onlyUsedParts, $keyval); } else{ array_push($onlyUsedParts, ""); } } echo implode (".", $onlyUsedParts); echo "
"; $fullfilename = $wasUrl . "server/assignments/search?pattern=". implode (".", $onlyUsedParts) ."&station=". $curstation ."&Text=" . $textentry; $json = json_decode(file_get_contents($fullfilename)); if (isset($json[0])) { $fullfilename = $json[0]; } else{ continue; } } //echo $fullfilename . "
"; $element3 = $doc->createElement('pattern'); $element3->setAttribute("id", $fullfilename); $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", $value->getAttribute('width')); $element2->setAttribute("height", $value->getAttribute('height')); $element2->setAttribute("xlink:href", $fullfilename); $element3->appendChild($element2); $parent = $doc->getElementsByTagName('defs')->item(0); $parent->appendChild($element3); $value->setAttribute("fill", "url(#". $fullfilename . ")"); //override identifier to be empty $keyValueStore2[$keyorig]->nodeValue = ""; } //$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'); //Notwendig da ab und zu mit transform exportiert wird liegt an der powerpoint version if($result3->getAttribute('transform') != null){ $transform = get_string_between($keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('transform'), "matrix(", ")"); $matrix = explode(" ", $transform); $videox =$matrix[4]; $videoy =$matrix[5]; $element->setAttribute("x", $videox); $element->setAttribute("y", $videoy); }else{ $element->setAttribute("x", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('x')); $element->setAttribute("y", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('y')); } // echo $result->nodeValue;// + result3->getAttribute('x'); // echo $result3->getAttribute('transform') . "
"; $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); //override identifier to be empty $keyValueStore2[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->nodeValue = ""; } 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.")"); //override identifier to be empty $keyValueStore2[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->nodeValue = ""; } } } echo $doc->saveXML(); ?>