123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <html>
- <head>
- </head>
- <body style="margin: 0px">
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
-
- //http://www.justin-cook.com/2006/03/31/php-parse-a-string-between-two-strings/
- function get_string_between($string, $start, $end){
- $string = " ".$string;
- $ini = strpos($string,$start);
- if ($ini == 0) return "";
- $ini += strlen($start);
- $len = strpos($string,$end,$ini) - $ini;
- return substr($string,$ini,$len);
- }
-
- //header('Content-type: image/svg+xml'); //does not play video
-
- $svg_file = file_get_contents(dirname(__DIR__, 1) . "/images/uploads/" . $_GET["___image___"]);
-
-
- $doc1 = new DOMDocument;
- $doc1->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') . "<br>";
- $keyValueStore[$result->nodeValue] = $result3;
- $keyValueStore2[$result->nodeValue] = $result;
- }
- }
-
- //$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') . "<br>";
-
-
- $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:
- /*
- <defs>
- <pattern id="image" x="-32" y="-32" patternUnits="userSpaceOnUse" height="64" width="64">
- <image x="0" y="0" height="64" width="64" xlink:href="http://0.gravatar.com/avatar/902a4faaa4de6f6aebd6fd7a9fbab46a?s=64"/>
- </pattern>
- </defs>
- */
-
-
- $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();
- ?>
- </body>
- </html>
|