Advertisement
eqeqwan21

ods_svg.php

Jun 18th, 2025
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.71 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.  
  249.     $centerX = 78.845825;
  250.     $circle1 = '<circle
  251.       style="fill:' . $incolor . ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  252.       id="dyra"
  253.       cx="' . $centerX . '"
  254.       cy="136.13333"
  255.       r="18.520834" />';
  256.  
  257.     $circle2 = '';
  258.     if ($circlesCount === 2) {
  259.         $spacing = 30;
  260.         $circle1 = '<circle
  261.       style="fill:' . $incolor . ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  262.       id="dyra"
  263.       cx="' . ($centerX - $spacing / 2) . '"
  264.       cy="136.13333"
  265.       r="14" />';
  266.  
  267.         $circle2 = '<circle
  268.       style="fill:' . $incolor . ';fill-opacity:' . $opa . ';stroke:none;stroke-width:0.26458332"
  269.       id="dyra2"
  270.       cx="' . ($centerX + $spacing / 2) . '"
  271.       cy="136.13333"
  272.       r="14" />';
  273.     }
  274.  
  275.     $doorSvg = '';
  276.     if (isset($_GET['open']) && $_GET['open']=='1') {
  277.  
  278.         $bodyY = 106.5;
  279.         $slant = 15;
  280.         $doorClr = '#002b5c';
  281.         $bodyR = $bodyX + $bodyW;
  282.         $leftX  = $bodyX  - $depth;
  283.         $rightX = $bodyR + $depth;
  284.  
  285.         $DL_p1 = $bodyX  .','.$bodyY;
  286.         $DL_p2 = $bodyX  .','.($bodyY + $bodyH - $slant);
  287.         $DL_p3 = $leftX  .','.($bodyY + $bodyH );
  288.         $DL_p4 = $leftX  .','.($bodyY + $slant);
  289.  
  290.         $DR_p1 = $bodyR .','.$bodyY;
  291.         $DR_p2 = $bodyR .','.($bodyY + $bodyH - $slant);
  292.         $DR_p3 = $rightX.','.($bodyY + $bodyH );
  293.         $DR_p4 = $rightX.','.($bodyY + $slant);
  294.  
  295.         $doorSvg = '
  296. <polygon id="doorLeft"  points="'.$DL_p1.' '.$DL_p2.' '.$DL_p3.' '.$DL_p4.'" style="fill:'.$doorClr.';fill-opacity:'.$opa.';stroke:none"/>
  297. <polygon id="doorRight" points="'.$DR_p1.' '.$DR_p2.' '.$DR_p3.' '.$DR_p4.'" style="fill:'.$doorClr.';fill-opacity:'.$opa.';stroke:none"/>';
  298.     }
  299.  
  300. $data = <<<EOT
  301. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  302.  
  303. <svg
  304.    xmlns:dc="http://purl.org/dc/elements/1.1/"
  305.    xmlns:cc="http://creativecommons.org/ns#"
  306.    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  307.    xmlns:svg="http://www.w3.org/2000/svg"
  308.    xmlns="http://www.w3.org/2000/svg"
  309.    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  310.    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  311.    width ="{$canvasW}mm"
  312.       height="{$canvasH}mm"
  313.       viewBox="-{$depth} 0 {$canvasW} {$canvasH}"
  314.    version="1.1"
  315.    id="svg8"
  316.    inkscape:version="0.92.1 r15371"
  317.    sodipodi:docname="box.svg">
  318.   <defs
  319.      id="defs2" />
  320.   <sodipodi:namedview
  321.      id="base"
  322.      pagecolor="#ffffff"
  323.      bordercolor="#666666"
  324.      borderopacity="1.0"
  325.      inkscape:pageopacity="0.0"
  326.      inkscape:pageshadow="2"
  327.      inkscape:zoom="0.5"
  328.      inkscape:cx="257.32181"
  329.      inkscape:cy="180.5"
  330.      inkscape:document-units="mm"
  331.      inkscape:current-layer="layer1"
  332.      showgrid="false"
  333.      inkscape:window-width="1920"
  334.      inkscape:window-height="1017"
  335.      inkscape:window-x="1272"
  336.      inkscape:window-y="-8"
  337.      inkscape:window-maximized="1">
  338.     <inkscape:grid
  339.        type="xygrid"
  340.        id="grid4493"
  341.        originx="-36.916937"
  342.        originy="-100.40938" />
  343.   </sodipodi:namedview>
  344.   <metadata
  345.      id="metadata5">
  346.     <rdf:RDF>
  347.       <cc:Work
  348.          rdf:about="">
  349.         <dc:format>image/svg+xml</dc:format>
  350.         <dc:type
  351.            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
  352.         <dc:title></dc:title>
  353.       </cc:Work>
  354.     </rdf:RDF>
  355.   </metadata>
  356.   <g   
  357.      inkscape:label="Layer 1"
  358.      inkscape:groupmode="layer"
  359.      id="layer1"
  360.      transform="translate(-36.916938,-95.791984)">
  361.     $anm
  362.     $anm2
  363.     <rect
  364.        style="fill:$foncolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.24052194"
  365.        id="rectbox"
  366.        width="74.083336"
  367.        height="89.958336"
  368.        x="42.333332"
  369.        y="106.5" />
  370.     <rect
  371.        style="fill:$outcolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.24945155"
  372.        id="rectup"
  373.        width="84.666664"
  374.        height="10.583333"
  375.        x="37.041664"
  376.        y="95.91671"
  377.        inkscape:label="#rrectup" />
  378.     <rect
  379.        style="fill:$circlecolor;fill-opacity:$opa;stroke:#ffffff;stroke-width:0.26458332"
  380.        id="rectdown"
  381.        width="74.083336"
  382.        height="26.458332"
  383.        x="42.333328"
  384.        y="170" />
  385.     $circle1
  386.     $circle2
  387.     $doorSvg
  388.   </g>
  389. </svg>
  390. EOT;
  391.  
  392.         $this->output($data);
  393. }
  394.  
  395.  
  396.     private function putsvg($data, $addxml=false) {
  397.     $header = "<svg>";
  398. $header = <<<EOT
  399. <svg
  400.    xmlns:dc="http://purl.org/dc/elements/1.1/"
  401.    xmlns:cc="http://creativecommons.org/ns#"
  402.    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  403.    xmlns:svg="http://www.w3.org/2000/svg"
  404.    xmlns="http://www.w3.org/2000/svg"
  405.  
  406.    viewBox="0 0 1000 600"
  407.    version="1.1"
  408.    id="svg8"
  409.    >
  410.  
  411. EOT;
  412.     $tail = '</svg>';
  413.     if($addxml) {
  414.         $header = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n\n$header";
  415.     }
  416.     return $header."\n".$data."\n".$tail;
  417.     }
  418.  
  419.     private function get_test_svg() {
  420.         //$data = $this->draw_fuze_group();
  421.         $data = $this->draw_box();
  422.         $this->output( $this->putsvg($data, true) );
  423.     }
  424.  
  425.     private function output($data)  {
  426.         header_remove("Pragma");
  427.         header_remove("Expires");
  428.  
  429.         //header("Cache-Control: max-age=86400");
  430.         header('Content-type: image/svg+xml');
  431.         header('Content-Length: '.strlen($data));
  432.         echo $data;
  433.     }
  434.  
  435.     private function err_out()  {
  436.         header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
  437.         echo $this->num . ' Not Found ';
  438.     }
  439. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement