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