Dia.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Classes to create relation schema in Dia format.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Plugins\Schema\Dia;
  10. use PhpMyAdmin\Core;
  11. use PhpMyAdmin\Response;
  12. use XMLWriter;
  13. /**
  14. * This Class inherits the XMLwriter class and
  15. * helps in developing structure of DIA Schema Export
  16. *
  17. * @package PhpMyAdmin
  18. * @access public
  19. * @see https://www.php.net/manual/en/book.xmlwriter.php
  20. */
  21. class Dia extends XMLWriter
  22. {
  23. /**
  24. * The "Dia" constructor
  25. *
  26. * Upon instantiation This starts writing the Dia XML document
  27. *
  28. * @see XMLWriter::openMemory(),XMLWriter::setIndent(),XMLWriter::startDocument()
  29. */
  30. public function __construct()
  31. {
  32. $this->openMemory();
  33. /*
  34. * Set indenting using three spaces,
  35. * so output is formatted
  36. */
  37. $this->setIndent(true);
  38. $this->setIndentString(' ');
  39. /*
  40. * Create the XML document
  41. */
  42. $this->startDocument('1.0', 'UTF-8');
  43. }
  44. /**
  45. * Starts Dia Document
  46. *
  47. * dia document starts by first initializing dia:diagram tag
  48. * then dia:diagramdata contains all the attributes that needed
  49. * to define the document, then finally a Layer starts which
  50. * holds all the objects.
  51. *
  52. * @param string $paper the size of the paper/document
  53. * @param float $topMargin top margin of the paper/document in cm
  54. * @param float $bottomMargin bottom margin of the paper/document in cm
  55. * @param float $leftMargin left margin of the paper/document in cm
  56. * @param float $rightMargin right margin of the paper/document in cm
  57. * @param string $orientation orientation of the document, portrait or landscape
  58. *
  59. * @return void
  60. *
  61. * @access public
  62. * @see XMLWriter::startElement(),XMLWriter::writeAttribute(),
  63. * XMLWriter::writeRaw()
  64. */
  65. public function startDiaDoc(
  66. $paper,
  67. $topMargin,
  68. $bottomMargin,
  69. $leftMargin,
  70. $rightMargin,
  71. $orientation
  72. ) {
  73. if ($orientation == 'P') {
  74. $isPortrait = 'true';
  75. } else {
  76. $isPortrait = 'false';
  77. }
  78. $this->startElement('dia:diagram');
  79. $this->writeAttribute('xmlns:dia', 'http://www.lysator.liu.se/~alla/dia/');
  80. $this->startElement('dia:diagramdata');
  81. $this->writeRaw(
  82. '<dia:attribute name="background">
  83. <dia:color val="#ffffff"/>
  84. </dia:attribute>
  85. <dia:attribute name="pagebreak">
  86. <dia:color val="#000099"/>
  87. </dia:attribute>
  88. <dia:attribute name="paper">
  89. <dia:composite type="paper">
  90. <dia:attribute name="name">
  91. <dia:string>#' . $paper . '#</dia:string>
  92. </dia:attribute>
  93. <dia:attribute name="tmargin">
  94. <dia:real val="' . $topMargin . '"/>
  95. </dia:attribute>
  96. <dia:attribute name="bmargin">
  97. <dia:real val="' . $bottomMargin . '"/>
  98. </dia:attribute>
  99. <dia:attribute name="lmargin">
  100. <dia:real val="' . $leftMargin . '"/>
  101. </dia:attribute>
  102. <dia:attribute name="rmargin">
  103. <dia:real val="' . $rightMargin . '"/>
  104. </dia:attribute>
  105. <dia:attribute name="is_portrait">
  106. <dia:boolean val="' . $isPortrait . '"/>
  107. </dia:attribute>
  108. <dia:attribute name="scaling">
  109. <dia:real val="1"/>
  110. </dia:attribute>
  111. <dia:attribute name="fitto">
  112. <dia:boolean val="false"/>
  113. </dia:attribute>
  114. </dia:composite>
  115. </dia:attribute>
  116. <dia:attribute name="grid">
  117. <dia:composite type="grid">
  118. <dia:attribute name="width_x">
  119. <dia:real val="1"/>
  120. </dia:attribute>
  121. <dia:attribute name="width_y">
  122. <dia:real val="1"/>
  123. </dia:attribute>
  124. <dia:attribute name="visible_x">
  125. <dia:int val="1"/>
  126. </dia:attribute>
  127. <dia:attribute name="visible_y">
  128. <dia:int val="1"/>
  129. </dia:attribute>
  130. <dia:composite type="color"/>
  131. </dia:composite>
  132. </dia:attribute>
  133. <dia:attribute name="color">
  134. <dia:color val="#d8e5e5"/>
  135. </dia:attribute>
  136. <dia:attribute name="guides">
  137. <dia:composite type="guides">
  138. <dia:attribute name="hguides"/>
  139. <dia:attribute name="vguides"/>
  140. </dia:composite>
  141. </dia:attribute>'
  142. );
  143. $this->endElement();
  144. $this->startElement('dia:layer');
  145. $this->writeAttribute('name', 'Background');
  146. $this->writeAttribute('visible', 'true');
  147. $this->writeAttribute('active', 'true');
  148. }
  149. /**
  150. * Ends Dia Document
  151. *
  152. * @return void
  153. * @access public
  154. * @see XMLWriter::endElement(),XMLWriter::endDocument()
  155. */
  156. public function endDiaDoc()
  157. {
  158. $this->endElement();
  159. $this->endDocument();
  160. }
  161. /**
  162. * Output Dia Document for download
  163. *
  164. * @param string $fileName name of the dia document
  165. *
  166. * @return void
  167. * @access public
  168. * @see XMLWriter::flush()
  169. */
  170. public function showOutput($fileName)
  171. {
  172. if (ob_get_clean()) {
  173. ob_end_clean();
  174. }
  175. $output = $this->flush();
  176. Response::getInstance()->disable();
  177. Core::downloadHeader(
  178. $fileName,
  179. 'application/x-dia-diagram',
  180. strlen($output)
  181. );
  182. print $output;
  183. }
  184. }