Advertisement
eqeqwan21

ods_svg.php

Jun 20th, 2025
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.99 KB | None | 0 0
  1. <?php
  2.  
  3. class ods_svg {
  4.     private $anime1 = '<animate attributeName="visibility" from="visible" to="hidden" dur="1s" repeatCount="indefinite" />';
  5.     private $anime2 = '<animate attributeName="visibility" from="visible" to="hidden" dur="2s" repeatCount="indefinite" />';
  6.    private $animeall = '<animate attributeName="visibility" from="visible" to="hidden" dur="0.5s" repeatCount="indefinite" />';
  7.    private $animeous = '<animate attributeName="visibility" values="visible;hidden;visible;hidden;visible;hidden;visible;visible;visible;visible;visible" dur="0.8s" repeatCount="indefinite" />';
  8.  
  9.     public function run()
  10.     {
  11.         $script = substr(stristr(strtok($_SERVER['REQUEST_URI'],'?'), 'images/'),7);
  12.         $script = str_replace(['/','\\',':','.'],'_',$script);
  13.  
  14.         $method = strtolower($_SERVER['REQUEST_METHOD'].'_'.$script);
  15.  
  16.         if( method_exists($this, $method) ) {
  17.             $this->$method();
  18.         }
  19.         else {
  20.             header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
  21.             echo('Not Found');
  22.         }
  23.     }
  24.  
  25.     private function get_galbox_svg() {
  26.  
  27.         $header = !isset($_GET['noxml']);
  28.  
  29.         $box = new ods_box($_GET['cnf']);
  30.         if($header)
  31.             header ('Content-Type: image/svg+xml');
  32.  
  33.  
  34.         header_remove("Pragma");
  35.         header_remove("Expires");
  36.  
  37.         header("Cache-Control: max-age=86400");
  38.  
  39.         echo $box->run($header);
  40.     }
  41.  
  42.  
  43. private function get_lamp_svg() {
  44. $anm='';
  45. $anm2='';
  46. $foncolor = "rgb(0,176,80)";
  47. $incolor="white";
  48.  
  49. if(isset($_GET['auto']))
  50.     $foncolor = "rgb(0,176,80)";
  51. if(isset($_GET['manual']))
  52.     $foncolor = "rgb(0,112,192)";
  53. if(isset($_GET['unmanaged']))
  54.     $foncolor = "rgb(166,166,166)";
  55.  
  56. $outcolor = $foncolor;
  57. if(isset($_GET['nopower']))
  58.     $outcolor = "rgb(255,0,0)";
  59. if(isset($_GET['on']))
  60.     $incolor="white";
  61. if(isset($_GET['off']))
  62.     $incolor="black";
  63. $circlecolor=$incolor;
  64. if(isset($_GET['trouble']))
  65.     $circlecolor="red";
  66. $opa=1;
  67. if(isset($_GET['nocon']))
  68.     $opa="0.5";
  69.  
  70. if (isset($_GET['shape'])) {
  71.     $foncolor="black";
  72.     $outcolor="black";
  73.     $circklecolor="white";
  74.     $incolor="white";
  75. }
  76.  
  77. if(isset($_GET['timeallert']))
  78.     $anm=$this->anime1;
  79. if(isset($_GET['controlallert']))
  80.     $anm=$this->anime2;
  81. if(isset($_GET['timeallert']) && isset($_GET['controlallert']))
  82.    $anm=$this->animeall;
  83.  
  84. if(isset($_GET['open']))
  85.     $anm=$this->animeall;
  86.  
  87. if(isset($_GET['ous']))
  88.     $anm2=$this->animeous;
  89.  
  90. $data = <<<EOT
  91. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  92. <svg
  93.    xmlns:dc="http://purl.org/dc/elements/1.1/"
  94.    xmlns:cc="http://creativecommons.org/ns#"
  95.    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  96.    xmlns:svg="http://www.w3.org/2000/svg"
  97.    xmlns="http://www.w3.org/2000/svg"
  98.    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  99.    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  100.    version="1.1"
  101.    id="Capa_1"
  102.    x="0px"
  103.    y="0px"
  104.    width="333.668"
  105.    height="491.582"
  106.    viewBox="0 0 333.668 491.582"
  107.    xml:space="preserve"
  108.    sodipodi:docname="location.svg"
  109.    inkscape:version="0.92.1 r15371"><metadata
  110.      id="metadata4620"><rdf:RDF><cc:Work
  111.          rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
  112.            rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
  113.      id="defs4618" /><sodipodi:namedview
  114.      pagecolor="#ffffff"
  115.      bordercolor="#666666"
  116.      borderopacity="1"
  117.      objecttolerance="10"
  118.      gridtolerance="10"
  119.      guidetolerance="10"
  120.      inkscape:pageopacity="0"
  121.      inkscape:pageshadow="2"
  122.      inkscape:window-width="1920"
  123.      inkscape:window-height="1017"
  124.      id="namedview4616"
  125.      showgrid="false"
  126.      inkscape:zoom="1.5480632"
  127.      inkscape:cx="166.834"
  128.      inkscape:cy="245.791"
  129.      inkscape:window-x="1272"
  130.      inkscape:window-y="-8"
  131.      inkscape:window-maximized="1"
  132.      inkscape:current-layer="Capa_1" />
  133.      <g>
  134.     $anm
  135.     $anm2
  136.      <path style="fill:$outcolor;fill-opacity:$opa;"
  137.      d="M 166.834,0 C 74.842,0 0,74.841 0,166.833 0,203.8 21.764,260.02 68.493,343.759 c 31.887,57.138 63.627,105.4 64.966,107.433 l 22.941,34.773 c 2.313,3.507 6.232,5.617 10.434,5.617 4.202,0 8.121,-2.11 10.434,-5.617 l 22.94,-34.771 c 1.326,-2.01 32.835,-49.855 64.967,-107.435 46.729,-83.735 68.493,-139.955 68.493,-176.926 C 333.668,74.841 258.826,0 166.834,0 Z m 76.511,331.576 C 211.66,388.351 180.649,435.445 179.342,437.424 L 166.834,456.383 154.33,437.429 C 153.016,435.434 121.767,387.918 90.323,331.576 46.978,253.9 25,198.472 25,166.833 25,88.626 88.626,25 166.834,25 c 78.208,0 141.834,63.626 141.834,141.833 0,31.643 -21.978,87.069 -65.323,164.743 z"
  138.      id="out"
  139.      inkscape:connector-curvature="0" /><path
  140.      d="m 166.51102,70.061158 c -52.60786,0 -95.40686,42.800032 -95.40686,95.406862 0,52.60682 42.799,95.40685 95.40686,95.40685 52.60786,0 95.40685,-42.80003 95.40685,-95.40685 0,-52.60683 -42.79899,-95.406862 -95.40685,-95.406862 z m 0,165.028072 c -38.38966,0 -69.62123,-31.23156 -69.62123,-69.62121 0,-38.38966 31.23157,-69.621225 69.62123,-69.621225 38.39069,0 69.62121,31.231565 69.62121,69.621225 0,38.38965 -31.23052,69.62121 -69.62121,69.62121 z"
  141.      id="path4579"
  142.      inkscape:connector-curvature="0"
  143.      style="stroke-width:1.0314256; fill:$circlecolor;fill-opacity:$opa" /><g
  144.      id="g4585"
  145.      transform="translate(-78.957)" /><g
  146.      id="g4587"
  147.      transform="translate(-78.957)" /><g
  148.      id="g4589"
  149.      transform="translate(-78.957)" /><g
  150.      id="g4591"
  151.      transform="translate(-78.957)" /><g
  152.      id="g4593"
  153.      transform="translate(-78.957)" /><g
  154.      id="g4595"
  155.      transform="translate(-78.957)" /><g
  156.      id="g4597"
  157.      transform="translate(-78.957)" /><g
  158.      id="g4599"
  159.      transform="translate(-78.957)" /><g
  160.      id="g4601"
  161.      transform="translate(-78.957)" /><g
  162.      id="g4603"
  163.      transform="translate(-78.957)" /><g
  164.      id="g4605"
  165.      transform="translate(-78.957)" /><g
  166.      id="g4607"
  167.      transform="translate(-78.957)" /><g
  168.      id="g4609"
  169.      transform="translate(-78.957)" /><g
  170.      id="g4611"
  171.      transform="translate(-78.957)" /><g
  172.      id="g4613"
  173.      transform="translate(-78.957)" /><path
  174.      style="opacity:1;fill:$incolor;fill-opacity:$opa;fill-rule:evenodd;stroke:none;stroke-width:1.39170384;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
  175.      d="m 139.55478,232.35515 c -16.58989,-6.60707 -28.58213,-18.03317 -37.03437,-35.28599 -6.38482,-13.03281 -7.31297,-17.131 -7.19708,-31.77843 0.10703,-13.52786 1.31773,-19.29209 6.19162,-29.47857 20.24225,-42.306575 76.0645,-53.865996 110.39606,-22.86032 16.49621,14.89816 23.55823,30.9106 23.55823,53.41604 0,15.0389 -0.98737,19.91288 -6.1896,30.55391 -6.8541,14.01987 -18.68856,25.94228 -33.23311,33.48003 -13.78082,7.14194 -41.09228,8.08629 -56.49175,1.95333 z"
  176.      id="in"
  177.      inkscape:connector-curvature="0" /><path
  178.      style="opacity:1;fill:$foncolor;fill-opacity:$opa;fill-rule:evenodd;stroke:none;stroke-width:1.32080853;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
  179.      d="M 155.30991,441.46651 C 87.7426,335.06388 48.24689,260.59788 30.49318,206.13462 17.902965,167.51149 22.33961,127.83742 43.19548,92.545955 47.13571,85.878452 57.60351,73.120056 66.45725,64.193964 79.6908,50.852276 86.10715,46.269966 102.51958,38.439622 c 25.34418,-12.091664 38.10009,-15.050718 64.51217,-14.965211 39.60128,0.128207 71.08382,13.371175 99.77161,41.968433 33.76712,33.66056 48.87939,78.982346 40.21435,120.602906 -9.96466,47.86278 -55.10745,138.24455 -118.4759,237.20424 -10.9865,17.15712 -20.90722,31.50438 -22.04607,31.8828 -1.13885,0.37843 -6.17246,-5.77141 -11.18583,-13.66628 z m 37.97331,-186.45037 c 7.0625,-2.19116 16.94549,-6.38177 21.96218,-9.31247 11.50031,-6.71836 29.4853,-25.54903 35.35406,-37.01644 C 277.86863,155.40391 249.9923,90.544348 192.68445,73.937085 172.78736,68.171099 145.53005,70.166632 127.17736,78.732914 64.14447,108.15411 51.97082,190.13931 103.86658,235.72282 c 5.57279,4.89497 12.99612,10.39475 16.49629,12.22174 21.51321,11.22941 50.46835,14.03738 72.92035,7.07158 z"
  180.      id="fon"
  181.      inkscape:connector-curvature="0" />
  182.      </g>
  183.      <circle cx="50" cy="50" r="5" fill="green" />
  184.         <circle cx="70" cy="50" r="5" fill="green" />
  185. </svg>
  186. EOT;
  187.  
  188.  
  189.         $this->output($data);
  190. }
  191.  
  192. private function get_box_svg() {
  193. $anm='';
  194. $anm2='';
  195. $foncolor = "rgb(0,176,80)";
  196. $incolor="white";
  197.     $depth   = 33;
  198.     $bodyX   = 42.333332;
  199.     $bodyW   = 74.083336;
  200.     $bodyH   = 89.958336;
  201.  
  202.     $canvasW = $bodyW + $depth*2 + 5;
  203.     $canvasH = 100.79864;
  204.  
  205.     if(isset($_GET['auto']))
  206.     $foncolor = "rgb(0,176,80)";
  207. if(isset($_GET['manual']))
  208.     $foncolor = "rgb(0,112,192)";
  209. if(isset($_GET['unmanaged']))
  210.     $foncolor = "rgb(166,166,166)";
  211.  
  212. $outcolor = $foncolor;
  213. if(isset($_GET['nopower']))
  214.     $outcolor = "rgb(255,0,0)";
  215. if(isset($_GET['on']))
  216.     $incolor="white";
  217. if(isset($_GET['off']))
  218.     $incolor="black";
  219. $circlecolor=$foncolor;
  220. if(isset($_GET['trouble']))
  221.     $circlecolor="red";
  222. $opa=1;
  223. if(isset($_GET['nocon']))
  224.     $opa="0.5";
  225.  
  226.  
  227. if(isset($_GET['timeallert']))
  228.     $anm=$this->anime1;
  229. if(isset($_GET['controlallert']))
  230.     $anm=$this->anime2;
  231. if(isset($_GET['timeallert']) && isset($_GET['controlallert']))
  232.     $anm=$this->animeall;
  233.  
  234. if(isset($_GET['open']))
  235.     $anm=$this->animeall;
  236.  
  237. if(isset($_GET['ous']))
  238.     $anm2=$this->animeous;
  239.  
  240.  
  241. if (isset($_GET['shape'])) {
  242.     $foncolor="black";
  243.     $outcolor="black";
  244.     $circlecolor="black";
  245.     $incolor="white";
  246. }
  247.     $circlesCount = isset($_GET['multiple']) && $_GET['multiple'] == 'true' ? 2 : 1;
  248.     $state = isset($_GET['state']) ? intval($_GET['state']) : 0;
  249.     if ($state > 15) {
  250.         $state = 15;
  251.     }
  252.  
  253.     $k1_on = ($state & 0x8) != 0;
  254.     $k2_on = ($state & 0x4) != 0;
  255.  
  256.     $eyeOn  = $incolor;
  257.     $eyeOff = 'black';
  258.  
  259.     $centerX = 78.845825;
  260.     $circle1 = '<circle
  261.       style="fill:'.($k1_on?$eyeOn:$eyeOff). ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  262.       id="dyra"
  263.       cx="' . $centerX . '"
  264.       cy="136.13333"
  265.       r="18.520834" />';
  266.  
  267.     $circle2 = '';
  268.     if ($circlesCount === 2) {
  269.         $spacing = 30;
  270.         $circle1 = '<circle
  271.       style="fill:' . ($k1_on?$eyeOn:$eyeOff) . ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  272.       id="dyra"
  273.       cx="' . ($centerX - $spacing / 2) . '"
  274.       cy="136.13333"
  275.       r="14" />';
  276.  
  277.         $circle2 = '<circle
  278.       style="fill:' . ($k2_on?$eyeOn:$eyeOff) . ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  279.       id="dyra2"
  280.       cx="' . ($centerX + $spacing / 2) . '"
  281.       cy="136.13333"
  282.       r="14" />';
  283.     }
  284.  
  285.     $doorSvg = '';
  286.     if (isset($_GET['open']) && $_GET['open']=='1') {
  287.  
  288.         $bodyY = 106.5;
  289.         $slant = 15;
  290.         $doorClr = '#002b5c';
  291.         $bodyR = $bodyX + $bodyW;
  292.         $leftX  = $bodyX  - $depth;
  293.         $rightX = $bodyR + $depth;
  294.  
  295.         $DL_p1 = $bodyX  .','.$bodyY;
  296.         $DL_p2 = $bodyX  .','.($bodyY + $bodyH - $slant);
  297.         $DL_p3 = $leftX  .','.($bodyY + $bodyH );
  298.         $DL_p4 = $leftX  .','.($bodyY + $slant);
  299.  
  300.         $DR_p1 = $bodyR .','.$bodyY;
  301.         $DR_p2 = $bodyR .','.($bodyY + $bodyH - $slant);
  302.         $DR_p3 = $rightX.','.($bodyY + $bodyH );
  303.         $DR_p4 = $rightX.','.($bodyY + $slant);
  304.  
  305.         $doorSvg = '
  306. <polygon id="doorLeft"  points="'.$DL_p1.' '.$DL_p2.' '.$DL_p3.' '.$DL_p4.'" style="fill:'.$doorClr.';fill-opacity:'.$opa.';stroke:none"/>
  307. <polygon id="doorRight" points="'.$DR_p1.' '.$DR_p2.' '.$DR_p3.' '.$DR_p4.'" style="fill:'.$doorClr.';fill-opacity:'.$opa.';stroke:none"/>';
  308.     }
  309.  
  310. $data = <<<EOT
  311. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  312.  
  313. <svg
  314.    xmlns:dc="http://purl.org/dc/elements/1.1/"
  315.    xmlns:cc="http://creativecommons.org/ns#"
  316.    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  317.    xmlns:svg="http://www.w3.org/2000/svg"
  318.    xmlns="http://www.w3.org/2000/svg"
  319.    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  320.    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  321.    width ="{$canvasW}mm"
  322.       height="{$canvasH}mm"
  323.       viewBox="-{$depth} 0 {$canvasW} {$canvasH}"
  324.    version="1.1"
  325.    id="svg8"
  326.    inkscape:version="0.92.1 r15371"
  327.    sodipodi:docname="box.svg">
  328.   <defs
  329.      id="defs2" />
  330.   <sodipodi:namedview
  331.      id="base"
  332.      pagecolor="#ffffff"
  333.      bordercolor="#666666"
  334.      borderopacity="1.0"
  335.      inkscape:pageopacity="0.0"
  336.      inkscape:pageshadow="2"
  337.      inkscape:zoom="0.5"
  338.      inkscape:cx="257.32181"
  339.      inkscape:cy="180.5"
  340.      inkscape:document-units="mm"
  341.      inkscape:current-layer="layer1"
  342.      showgrid="false"
  343.      inkscape:window-width="1920"
  344.      inkscape:window-height="1017"
  345.      inkscape:window-x="1272"
  346.      inkscape:window-y="-8"
  347.      inkscape:window-maximized="1">
  348.     <inkscape:grid
  349.        type="xygrid"
  350.        id="grid4493"
  351.        originx="-36.916937"
  352.        originy="-100.40938" />
  353.   </sodipodi:namedview>
  354.   <metadata
  355.      id="metadata5">
  356.     <rdf:RDF>
  357.       <cc:Work
  358.          rdf:about="">
  359.         <dc:format>image/svg+xml</dc:format>
  360.         <dc:type
  361.            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
  362.         <dc:title></dc:title>
  363.       </cc:Work>
  364.     </rdf:RDF>
  365.   </metadata>
  366.   <g   
  367.      inkscape:label="Layer 1"
  368.      inkscape:groupmode="layer"
  369.      id="layer1"
  370.      transform="translate(-36.916938,-95.791984)">
  371.     $anm
  372.     $anm2
  373.     <rect
  374.        style="fill:$foncolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.24052194"
  375.        id="rectbox"
  376.        width="74.083336"
  377.        height="89.958336"
  378.        x="42.333332"
  379.        y="106.5" />
  380.     <rect
  381.        style="fill:$outcolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.24945155"
  382.        id="rectup"
  383.        width="84.666664"
  384.        height="10.583333"
  385.        x="37.041664"
  386.        y="95.91671"
  387.        inkscape:label="#rrectup" />
  388.     <rect
  389.        style="fill:$circlecolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.26458332"
  390.        id="rectdown"
  391.        width="74.083336"
  392.        height="26.458332"
  393.        x="42.333328"
  394.        y="170" />
  395.     $circle1
  396.     $circle2
  397.     $doorSvg
  398.   </g>
  399. </svg>
  400. EOT;
  401.  
  402.         $this->output($data);
  403. }
  404.  
  405.  
  406.     private function putsvg($data, $addxml=false) {
  407.     $header = "<svg>";
  408. $header = <<<EOT
  409. <svg
  410.    xmlns:dc="http://purl.org/dc/elements/1.1/"
  411.    xmlns:cc="http://creativecommons.org/ns#"
  412.    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  413.    xmlns:svg="http://www.w3.org/2000/svg"
  414.    xmlns="http://www.w3.org/2000/svg"
  415.  
  416.    viewBox="0 0 1000 600"
  417.    version="1.1"
  418.    id="svg8"
  419.    >
  420.  
  421. EOT;
  422.     $tail = '</svg>';
  423.     if($addxml) {
  424.         $header = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n\n$header";
  425.     }
  426.     return $header."\n".$data."\n".$tail;
  427.     }
  428.  
  429.     private function get_test_svg() {
  430.         //$data = $this->draw_fuze_group();
  431.         $data = $this->draw_box();
  432.         $this->output( $this->putsvg($data, true) );
  433.     }
  434.  
  435.     private function output($data)  {
  436.         header_remove("Pragma");
  437.         header_remove("Expires");
  438.  
  439.         //header("Cache-Control: max-age=86400");
  440.         header('Content-type: image/svg+xml');
  441.         header('Content-Length: '.strlen($data));
  442.         echo $data;
  443.     }
  444.  
  445.     private function err_out()  {
  446.         header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
  447.         echo $this->num . ' Not Found ';
  448.     }
  449. }
  450.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement