imageReplacement.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <html>
  2. <head>
  3. </head>
  4. <body style="margin: 0px">
  5. <?php
  6. ini_set('display_errors', 1);
  7. ini_set('display_startup_errors', 1);
  8. error_reporting(E_ALL);
  9. //http://www.justin-cook.com/2006/03/31/php-parse-a-string-between-two-strings/
  10. function get_string_between($string, $start, $end){
  11. $string = " ".$string;
  12. $ini = strpos($string,$start);
  13. if ($ini == 0) return "";
  14. $ini += strlen($start);
  15. $len = strpos($string,$end,$ini) - $ini;
  16. return substr($string,$ini,$len);
  17. }
  18. //header('Content-type: image/svg+xml'); //does not play video
  19. $svg_file = file_get_contents(dirname(__DIR__, 1) . "/images/uploads/" . $_GET["___image___"]);
  20. $doc1 = new DOMDocument;
  21. $doc1->loadXML($svg_file);
  22. $xpath1 = new DOMXPath($doc1);
  23. $xpath1->registerNamespace('svg', 'http://www.w3.org/2000/svg');
  24. //prüfen ob exteranlImage dann wird dieses verwendet
  25. if(strlen($svg_file) < 400){
  26. $url = $xpath1->query("/svg:svg/svg:image/@href");
  27. $svg_file = file_get_contents($url[0]->nodeValue);
  28. }
  29. $doc = new DOMDocument;
  30. $doc->loadXML($svg_file);
  31. $xpath = new DOMXPath($doc);
  32. $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
  33. $root = $xpath->query("/*");
  34. $root[0]->setAttribute("viewBox", "0 0 1280 720");
  35. $widthq = $xpath->query("/*/@width");
  36. $heightq = $xpath->query("/*/@height");
  37. $root = $xpath->query("/*");
  38. $root[0]->setAttribute("viewBox", "0 0 ". $widthq[0]->nodeValue . " " . $heightq[0]->nodeValue);
  39. $widthq[0]->nodeValue = "100%";
  40. $heightq[0]->nodeValue = "100%";
  41. //Get all Text Nodes
  42. $style = $xpath->query('//svg:text');
  43. $keyValueStore=array();
  44. $keyValueStore2=array();
  45. //Get all rect nodes before text nodes and store them in key value store to access them for manipulation
  46. foreach ($style as $result) {
  47. $style2 = $xpath->query('./preceding-sibling::*[1]', $result);
  48. //echo $style2[0]->nodeName;
  49. //echo $result->nodeValue . " ";
  50. //get Rect
  51. foreach ($style2 as $result3) {
  52. //echo $result->nodeValue;
  53. //echo $result3->getAttribute('transform') . "<br>";
  54. $keyValueStore[$result->nodeValue] = $result3;
  55. $keyValueStore2[$result->nodeValue] = $result;
  56. }
  57. }
  58. $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://") . $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']) . "/TransformProductCode.php" . "?ProductCode=" . $_GET["ProductCode"];
  59. $json = file_get_contents($url);
  60. $asocarray = json_decode($json, true);
  61. $curstation = $_GET["Station"];
  62. //Einzelbilder vom Universal Storage laden
  63. foreach ($keyValueStore as $key => $value) {
  64. $keyorig = $key;
  65. $key = substr($key, 1);
  66. $keyarray = str_split($key, 2);
  67. $fullfilename = "";
  68. foreach($keyarray as $keypart){
  69. //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.
  70. if($keypart == "ID"){
  71. $fullfilename = $fullfilename . "_ID;" . substr($keyorig, strrpos($keyorig, "ID:") + 3);
  72. break;
  73. }
  74. else if(array_key_exists ($keypart, $asocarray)){
  75. $fullfilename = $fullfilename . "_" . $keypart . ";" . $asocarray[$keypart];
  76. }
  77. else{
  78. //echo "Continue";
  79. continue 2;
  80. }
  81. }
  82. $fullfilename = substr($fullfilename, 1);
  83. $fullfilename = "https://centurio.work/customers/evva/universal-storage/storage/JohannesEinzelbilder/" . $curstation . "_" . $fullfilename . ".jpg";
  84. //echo $fullfilename . "<br>";
  85. $element3 = $doc->createElement('pattern');
  86. $element3->setAttribute("id", $fullfilename);
  87. $element3->setAttribute("x", "0");
  88. $element3->setAttribute("y", "0");
  89. $element3->setAttribute("width", "1");
  90. $element3->setAttribute("height", "1");
  91. $element2 = $doc->createElement('image');
  92. $element2->setAttribute("x", "0");
  93. $element2->setAttribute("y", "0");
  94. $element2->setAttribute("width", $value->getAttribute('width'));
  95. $element2->setAttribute("height", $value->getAttribute('height'));
  96. $element2->setAttribute("xlink:href", $fullfilename);
  97. $element3->appendChild($element2);
  98. $parent = $doc->getElementsByTagName('defs')->item(0);
  99. $parent->appendChild($element3);
  100. $value->setAttribute("fill", "url(#". $fullfilename . ")");
  101. //override identifier to be empty
  102. $keyValueStore2[$keyorig]->nodeValue = "";
  103. }
  104. //$keyValueStore["*imga"]->setAttribute("fill", "#FFFFFF");
  105. //replace text from URL GET within image
  106. foreach($_GET as $key => $value){
  107. if($key != "___image___"){
  108. $alltext = $xpath->query('//svg:text');
  109. foreach ($alltext as $text) {
  110. if($key == $text->nodeValue){
  111. $text->nodeValue = $value;
  112. }
  113. }
  114. }
  115. }
  116. //load image Replacements
  117. $replacements = new DOMDocument();
  118. $newstr = substr( $_GET["___image___"], 0, strpos( $_GET["___image___"], '/', strpos( $_GET["___image___"], '/')+1));
  119. $urlreplacement = dirname('https://' . $_SERVER['HTTP_HOST']. $_SERVER['PHP_SELF'], 2) . "/server/" . $newstr . "/replacement";
  120. $replacements->loadXML(file_get_contents($urlreplacement));
  121. $elements = $replacements->getElementsByTagName('item');
  122. foreach($elements as $node){
  123. if(array_key_exists($node->getElementsByTagName("abbreviation")[0]->nodeValue, $keyValueStore)){
  124. $extension = pathinfo($node->getElementsByTagName("url")[0]->nodeValue, PATHINFO_EXTENSION);
  125. if($extension == "mp4"){
  126. $element = $doc->createElement('foreignObject');
  127. //Notwendig da ab und zu mit transform exportiert wird liegt an der powerpoint version
  128. if($result3->getAttribute('transform') != null){
  129. $transform = get_string_between($keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('transform'), "matrix(", ")");
  130. $matrix = explode(" ", $transform);
  131. $videox =$matrix[4];
  132. $videoy =$matrix[5];
  133. $element->setAttribute("x", $videox);
  134. $element->setAttribute("y", $videoy);
  135. }else{
  136. $element->setAttribute("x", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('x'));
  137. $element->setAttribute("y", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('y'));
  138. }
  139. // echo $result->nodeValue;// + result3->getAttribute('x');
  140. // echo $result3->getAttribute('transform') . "<br>";
  141. $element->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width'));
  142. $element->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height'));
  143. $element1 = $doc->createElement('video');
  144. $element1->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width'));
  145. $element1->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height'));
  146. $element1->setAttribute("controls", "");
  147. $element2 = $doc->createElement('source');
  148. $element2->setAttribute("type", "video/mp4");
  149. $element2->setAttribute("src", $node->getElementsByTagName("url")[0]->nodeValue);
  150. $element1->appendChild($element2);
  151. $element->appendChild($element1);
  152. $parent = $doc->getElementsByTagName('svg')->item(0);
  153. $parent->appendChild($element);
  154. //override identifier to be empty
  155. $keyValueStore2[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->nodeValue = "";
  156. }
  157. else{
  158. //create image element (currently we use background image)
  159. /*
  160. $element = $doc->createElement('image');
  161. $element->setAttribute("x", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('x'));
  162. $element->setAttribute("y", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('y'));
  163. $element->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width'));
  164. $element->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height'));
  165. $element->setAttribute("xlink:href", $node->getElementsByTagName("url")[0]->nodeValue);
  166. $doc->appendChild($element);
  167. $parent = $doc->getElementsByTagName('svg')->item(0);
  168. $parent->appendChild($element);
  169. */
  170. //create pattern for rect-filling looks like this:
  171. /*
  172. <defs>
  173. <pattern id="image" x="-32" y="-32" patternUnits="userSpaceOnUse" height="64" width="64">
  174. <image x="0" y="0" height="64" width="64" xlink:href="http://0.gravatar.com/avatar/902a4faaa4de6f6aebd6fd7a9fbab46a?s=64"/>
  175. </pattern>
  176. </defs>
  177. */
  178. $element3 = $doc->createElement('pattern');
  179. $element3->setAttribute("id", $node->getElementsByTagName("abbreviation")[0]->nodeValue);
  180. $element3->setAttribute("x", "0");
  181. $element3->setAttribute("y", "0");
  182. $element3->setAttribute("width", "1");
  183. $element3->setAttribute("height", "1");
  184. $element2 = $doc->createElement('image');
  185. $element2->setAttribute("x", "0");
  186. $element2->setAttribute("y", "0");
  187. $element2->setAttribute("width", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('width'));
  188. $element2->setAttribute("height", $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->getAttribute('height'));
  189. $element2->setAttribute("xlink:href", $node->getElementsByTagName("url")[0]->nodeValue);
  190. $element3->appendChild($element2);
  191. $parent = $doc->getElementsByTagName('defs')->item(0);
  192. $parent->appendChild($element3);
  193. $keyValueStore[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->setAttribute("fill", "url(#".$node->getElementsByTagName("abbreviation")[0]->nodeValue.")");
  194. //override identifier to be empty
  195. $keyValueStore2[$node->getElementsByTagName("abbreviation")[0]->nodeValue]->nodeValue = "";
  196. }
  197. }
  198. }
  199. echo $doc->saveXML();
  200. ?>
  201. </body>
  202. </html>