Dia.php 5.8 KB

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