Update website

This commit is contained in:
Guilhem Lavaux 2024-11-23 20:45:29 +01:00
parent 41ce1aa076
commit ea0eb1c6e0
4222 changed files with 721797 additions and 14 deletions

View file

@ -0,0 +1,128 @@
<?php
/**
* Contains PhpMyAdmin\Plugins\Schema\Svg\RelationStatsSvg class
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Schema\Svg;
use PhpMyAdmin\Plugins\Schema\RelationStats;
use function shuffle;
use function sqrt;
/**
* Relation preferences/statistics
*
* This class fetches the table master and foreign fields positions
* and helps in generating the Table references and then connects
* master table's master field to foreign table's foreign key
* in SVG XML document.
*
* @see Svg::printElementLine
*/
class RelationStatsSvg extends RelationStats
{
/**
* @param Svg $diagram The SVG diagram
* @param string $master_table The master table name
* @param string $master_field The relation field in the master table
* @param string $foreign_table The foreign table name
* @param string $foreign_field The relation field in the foreign table
*/
public function __construct(
$diagram,
$master_table,
$master_field,
$foreign_table,
$foreign_field
) {
$this->wTick = 10;
parent::__construct($diagram, $master_table, $master_field, $foreign_table, $foreign_field);
}
/**
* draws relation links and arrows shows foreign key relations
*
* @see PMA_SVG
*
* @param bool $showColor Whether to use one color per relation or not
*/
public function relationDraw($showColor): void
{
if ($showColor) {
$listOfColors = [
'#c00',
'#bbb',
'#333',
'#cb0',
'#0b0',
'#0bf',
'#b0b',
];
shuffle($listOfColors);
$color = $listOfColors[0];
} else {
$color = '#333';
}
$this->diagram->printElementLine(
'line',
$this->xSrc,
$this->ySrc,
$this->xSrc + $this->srcDir * $this->wTick,
$this->ySrc,
'stroke:' . $color . ';stroke-width:1;'
);
$this->diagram->printElementLine(
'line',
$this->xDest + $this->destDir * $this->wTick,
$this->yDest,
$this->xDest,
$this->yDest,
'stroke:' . $color . ';stroke-width:1;'
);
$this->diagram->printElementLine(
'line',
$this->xSrc + $this->srcDir * $this->wTick,
$this->ySrc,
$this->xDest + $this->destDir * $this->wTick,
$this->yDest,
'stroke:' . $color . ';stroke-width:1;'
);
$root2 = 2 * sqrt(2);
$this->diagram->printElementLine(
'line',
$this->xSrc + $this->srcDir * $this->wTick * 0.75,
$this->ySrc,
$this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
$this->ySrc + $this->wTick / $root2,
'stroke:' . $color . ';stroke-width:2;'
);
$this->diagram->printElementLine(
'line',
$this->xSrc + $this->srcDir * $this->wTick * 0.75,
$this->ySrc,
$this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick,
$this->ySrc - $this->wTick / $root2,
'stroke:' . $color . ';stroke-width:2;'
);
$this->diagram->printElementLine(
'line',
$this->xDest + $this->destDir * $this->wTick / 2,
$this->yDest,
$this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
$this->yDest + $this->wTick / $root2,
'stroke:' . $color . ';stroke-width:2;'
);
$this->diagram->printElementLine(
'line',
$this->xDest + $this->destDir * $this->wTick / 2,
$this->yDest,
$this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick,
$this->yDest - $this->wTick / $root2,
'stroke:' . $color . ';stroke-width:2;'
);
}
}

View file

@ -0,0 +1,277 @@
<?php
/**
* Classes to create relation schema in SVG format.
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Schema\Svg;
use PhpMyAdmin\Core;
use PhpMyAdmin\ResponseRenderer;
use XMLWriter;
use function intval;
use function is_int;
use function sprintf;
use function strlen;
/**
* This Class inherits the XMLwriter class and
* helps in developing structure of SVG Schema Export
*
* @see https://www.php.net/manual/en/book.xmlwriter.php
*/
class Svg extends XMLWriter
{
/** @var string */
public $title = '';
/** @var string */
public $author = 'phpMyAdmin';
/** @var string */
public $font = 'Arial';
/** @var int */
public $fontSize = 12;
/**
* Upon instantiation This starts writing the RelationStatsSvg 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');
$this->startDtd('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
$this->endDtd();
}
/**
* Set document title
*
* @param string $value sets the title text
*/
public function setTitle($value): void
{
$this->title = $value;
}
/**
* Set document author
*
* @param string $value sets the author
*/
public function setAuthor($value): void
{
$this->author = $value;
}
/**
* Set document font
*
* @param string $value sets the font e.g Arial, Sans-serif etc
*/
public function setFont(string $value): void
{
$this->font = $value;
}
/**
* Get document font
*
* @return string returns the font name
*/
public function getFont(): string
{
return $this->font;
}
/**
* Set document font size
*
* @param int $value sets the font size in pixels
*/
public function setFontSize(int $value): void
{
$this->fontSize = $value;
}
/**
* Get document font size
*
* @return int returns the font size
*/
public function getFontSize(): int
{
return $this->fontSize;
}
/**
* Starts RelationStatsSvg Document
*
* svg document starts by first initializing svg tag
* which contains all the attributes and namespace that needed
* to define the svg document
*
* @see XMLWriter::startElement()
* @see XMLWriter::writeAttribute()
*
* @param int $width total width of the RelationStatsSvg document
* @param int $height total height of the RelationStatsSvg document
* @param int $x min-x of the view box
* @param int $y min-y of the view box
*/
public function startSvgDoc($width, $height, $x = 0, $y = 0): void
{
$this->startElement('svg');
if (! is_int($width)) {
$width = intval($width);
}
if (! is_int($height)) {
$height = intval($height);
}
if ($x != 0 || $y != 0) {
$this->writeAttribute('viewBox', sprintf('%d %d %d %d', $x, $y, $width, $height));
}
$this->writeAttribute('width', ($width - $x) . 'px');
$this->writeAttribute('height', ($height - $y) . 'px');
$this->writeAttribute('xmlns', 'http://www.w3.org/2000/svg');
$this->writeAttribute('version', '1.1');
}
/**
* Ends RelationStatsSvg Document
*
* @see XMLWriter::endElement()
* @see XMLWriter::endDocument()
*/
public function endSvgDoc(): void
{
$this->endElement();
$this->endDocument();
}
/**
* output RelationStatsSvg Document
*
* svg document prompted to the user for download
* RelationStatsSvg document saved in .svg extension and can be
* easily changeable by using any svg IDE
*
* @see XMLWriter::startElement()
* @see XMLWriter::writeAttribute()
*
* @param string $fileName file name
*/
public function showOutput($fileName): void
{
//ob_get_clean();
$output = $this->flush();
ResponseRenderer::getInstance()->disable();
Core::downloadHeader(
$fileName,
'image/svg+xml',
strlen($output)
);
print $output;
}
/**
* Draws RelationStatsSvg elements
*
* SVG has some predefined shape elements like rectangle & text
* and other elements who have x,y co-ordinates are drawn.
* specify their width and height and can give styles too.
*
* @see XMLWriter::startElement()
* @see XMLWriter::writeAttribute()
* @see XMLWriter::text()
* @see XMLWriter::endElement()
*
* @param string $name RelationStatsSvg element name
* @param int $x The x attr defines the left position of the element
* (e.g. x="0" places the element 0 pixels from the
* left of the browser window)
* @param int $y The y attribute defines the top position of the
* element (e.g. y="0" places the element 0 pixels
* from the top of the browser window)
* @param int|string $width The width attribute defines the width the element
* @param int|string $height The height attribute defines the height the element
* @param string|null $text The text attribute defines the text the element
* @param string $styles The style attribute defines the style the element
* styles can be defined like CSS styles
*/
public function printElement(
$name,
$x,
$y,
$width = '',
$height = '',
?string $text = '',
$styles = ''
): void {
$this->startElement($name);
$this->writeAttribute('width', (string) $width);
$this->writeAttribute('height', (string) $height);
$this->writeAttribute('x', (string) $x);
$this->writeAttribute('y', (string) $y);
$this->writeAttribute('style', (string) $styles);
if (isset($text)) {
$this->writeAttribute('font-family', (string) $this->font);
$this->writeAttribute('font-size', $this->fontSize . 'px');
$this->text($text);
}
$this->endElement();
}
/**
* Draws RelationStatsSvg Line element
*
* RelationStatsSvg line element is drawn for connecting the tables.
* arrows are also drawn by specify its start and ending
* co-ordinates
*
* @see XMLWriter::startElement()
* @see XMLWriter::writeAttribute()
* @see XMLWriter::endElement()
*
* @param string $name RelationStatsSvg element name i.e line
* @param int $x1 Defines the start of the line on the x-axis
* @param int $y1 Defines the start of the line on the y-axis
* @param int $x2 Defines the end of the line on the x-axis
* @param int $y2 Defines the end of the line on the y-axis
* @param string $styles The style attribute defines the style the element
* styles can be defined like CSS styles
*/
public function printElementLine($name, $x1, $y1, $x2, $y2, $styles): void
{
$this->startElement($name);
$this->writeAttribute('x1', (string) $x1);
$this->writeAttribute('y1', (string) $y1);
$this->writeAttribute('x2', (string) $x2);
$this->writeAttribute('y2', (string) $y2);
$this->writeAttribute('style', (string) $styles);
$this->endElement();
}
}

View file

@ -0,0 +1,286 @@
<?php
/**
* Contains PhpMyAdmin\Plugins\Schema\Svg\RelationStatsSvg class
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Schema\Svg;
use PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia;
use PhpMyAdmin\Plugins\Schema\Eps\TableStatsEps;
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
use PhpMyAdmin\Plugins\Schema\Pdf\TableStatsPdf;
use PhpMyAdmin\Version;
use function __;
use function in_array;
use function max;
use function min;
use function sprintf;
/**
* RelationStatsSvg Relation Schema Class
*
* Purpose of this class is to generate the SVG XML Document because
* SVG defines the graphics in XML format which is used for representing
* the database diagrams as vector image. This class actually helps
* in preparing SVG XML format.
*
* SVG XML is generated by using XMLWriter php extension and this class
* inherits ExportRelationSchema class has common functionality added
* to this class
*
* @property Svg $diagram
*/
class SvgRelationSchema extends ExportRelationSchema
{
/** @var TableStatsDia[]|TableStatsEps[]|TableStatsPdf[]|TableStatsSvg[] */
private $tables = [];
/** @var RelationStatsSvg[] Relations */
private $relations = [];
/** @var int|float */
private $xMax = 0;
/** @var int|float */
private $yMax = 0;
/** @var int|float */
private $xMin = 100000;
/** @var int|float */
private $yMin = 100000;
/** @var int */
private $tablewidth = 0;
/**
* Upon instantiation This starts writing the SVG XML document
* user will be prompted for download as .svg extension
*
* @see PMA_SVG
*
* @param string $db database name
*/
public function __construct($db)
{
parent::__construct($db, new Svg());
$this->setShowColor(isset($_REQUEST['svg_show_color']));
$this->setShowKeys(isset($_REQUEST['svg_show_keys']));
$this->setTableDimension(isset($_REQUEST['svg_show_table_dimension']));
$this->setAllTablesSameWidth(isset($_REQUEST['svg_all_tables_same_width']));
$this->diagram->setTitle(
sprintf(
__('Schema of the %s database - Page %s'),
$this->db,
$this->pageNumber
)
);
$this->diagram->setAuthor('phpMyAdmin ' . Version::VERSION);
$this->diagram->setFont('Arial');
$this->diagram->setFontSize(16);
$alltables = $this->getTablesFromRequest();
foreach ($alltables as $table) {
if (! isset($this->tables[$table])) {
$this->tables[$table] = new TableStatsSvg(
$this->diagram,
$this->db,
$table,
$this->diagram->getFont(),
$this->diagram->getFontSize(),
$this->pageNumber,
$this->tablewidth,
$this->showKeys,
$this->tableDimension,
$this->offline
);
}
if ($this->sameWide) {
$this->tables[$table]->width = &$this->tablewidth;
}
$this->setMinMax($this->tables[$table]);
}
$border = 15;
$this->diagram->startSvgDoc(
$this->xMax + $border,
$this->yMax + $border,
$this->xMin - $border,
$this->yMin - $border
);
$seen_a_relation = false;
foreach ($alltables as $one_table) {
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
if (! $exist_rel) {
continue;
}
$seen_a_relation = true;
foreach ($exist_rel as $master_field => $rel) {
/* put the foreign table on the schema only if selected
* by the user
* (do not use array_search() because we would have to
* to do a === false and this is not PHP3 compatible)
*/
if ($master_field !== 'foreign_keys_data') {
if (in_array($rel['foreign_table'], $alltables)) {
$this->addRelation(
$one_table,
$this->diagram->getFont(),
$this->diagram->getFontSize(),
$master_field,
$rel['foreign_table'],
$rel['foreign_field'],
$this->tableDimension
);
}
continue;
}
foreach ($rel as $one_key) {
if (! in_array($one_key['ref_table_name'], $alltables)) {
continue;
}
foreach ($one_key['index_list'] as $index => $one_field) {
$this->addRelation(
$one_table,
$this->diagram->getFont(),
$this->diagram->getFontSize(),
$one_field,
$one_key['ref_table_name'],
$one_key['ref_index_list'][$index],
$this->tableDimension
);
}
}
}
}
if ($seen_a_relation) {
$this->drawRelations();
}
$this->drawTables();
$this->diagram->endSvgDoc();
}
/**
* Output RelationStatsSvg Document for download
*/
public function showOutput(): void
{
$this->diagram->showOutput($this->getFileName('.svg'));
}
/**
* Sets X and Y minimum and maximum for a table cell
*
* @param TableStatsSvg $table The table
*/
private function setMinMax($table): void
{
$this->xMax = max($this->xMax, $table->x + $table->width);
$this->yMax = max($this->yMax, $table->y + $table->height);
$this->xMin = min($this->xMin, $table->x);
$this->yMin = min($this->yMin, $table->y);
}
/**
* Defines relation objects
*
* @see setMinMax,TableStatsSvg::__construct(),
* PhpMyAdmin\Plugins\Schema\Svg\RelationStatsSvg::__construct()
*
* @param string $masterTable The master table name
* @param string $font The font face
* @param int $fontSize Font size
* @param string $masterField The relation field in the master table
* @param string $foreignTable The foreign table name
* @param string $foreignField The relation field in the foreign table
* @param bool $tableDimension Whether to display table position or not
*/
private function addRelation(
$masterTable,
$font,
$fontSize,
$masterField,
$foreignTable,
$foreignField,
$tableDimension
): void {
if (! isset($this->tables[$masterTable])) {
$this->tables[$masterTable] = new TableStatsSvg(
$this->diagram,
$this->db,
$masterTable,
$font,
$fontSize,
$this->pageNumber,
$this->tablewidth,
false,
$tableDimension
);
$this->setMinMax($this->tables[$masterTable]);
}
if (! isset($this->tables[$foreignTable])) {
$this->tables[$foreignTable] = new TableStatsSvg(
$this->diagram,
$this->db,
$foreignTable,
$font,
$fontSize,
$this->pageNumber,
$this->tablewidth,
false,
$tableDimension
);
$this->setMinMax($this->tables[$foreignTable]);
}
$this->relations[] = new RelationStatsSvg(
$this->diagram,
$this->tables[$masterTable],
$masterField,
$this->tables[$foreignTable],
$foreignField
);
}
/**
* Draws relation arrows and lines
* connects master table's master field to
* foreign table's foreign field
*
* @see Relation_Stats_Svg::relationDraw()
*/
private function drawRelations(): void
{
foreach ($this->relations as $relation) {
$relation->relationDraw($this->showColor);
}
}
/**
* Draws tables
*
* @see TableStatsSvg::Table_Stats_tableDraw()
*/
private function drawTables(): void
{
foreach ($this->tables as $table) {
$table->tableDraw($this->showColor);
}
}
}

View file

@ -0,0 +1,190 @@
<?php
/**
* Contains PhpMyAdmin\Plugins\Schema\Svg\TableStatsSvg class
*/
declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Schema\Svg;
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
use PhpMyAdmin\Plugins\Schema\TableStats;
use function __;
use function count;
use function in_array;
use function max;
use function sprintf;
/**
* Table preferences/statistics
*
* This class preserves the table co-ordinates,fields
* and helps in drawing/generating the Tables in SVG XML document.
*
* @see Svg
*
* @property Svg $diagram
*/
class TableStatsSvg extends TableStats
{
/** @var int */
public $height;
/** @var int */
public $currentCell = 0;
/**
* @see Svg
* @see TableStatsSvg::setWidthTable
* @see TableStatsSvg::setHeightTable
*
* @param Svg $diagram The current SVG image document
* @param string $db The database name
* @param string $tableName The table name
* @param string $font Font face
* @param int $fontSize The font size
* @param int $pageNumber Page number
* @param int $same_wide_width The max. width among tables
* @param bool $showKeys Whether to display keys or not
* @param bool $tableDimension Whether to display table position or not
* @param bool $offline Whether the coordinates are sent
*/
public function __construct(
$diagram,
$db,
$tableName,
$font,
$fontSize,
$pageNumber,
&$same_wide_width,
$showKeys = false,
$tableDimension = false,
$offline = false
) {
parent::__construct($diagram, $db, $pageNumber, $tableName, $showKeys, $tableDimension, $offline);
// height and width
$this->setHeightTable($fontSize);
// setWidth must me after setHeight, because title
// can include table height which changes table width
$this->setWidthTable($font, $fontSize);
if ($same_wide_width >= $this->width) {
return;
}
$same_wide_width = $this->width;
}
/**
* Displays an error when the table cannot be found.
*/
protected function showMissingTableError(): void
{
ExportRelationSchema::dieSchema(
$this->pageNumber,
'SVG',
sprintf(__('The %s table doesn\'t exist!'), $this->tableName)
);
}
/**
* Sets the width of the table
*
* @see PMA_SVG
*
* @param string $font The font size
* @param int $fontSize The font size
*/
private function setWidthTable($font, $fontSize): void
{
foreach ($this->fields as $field) {
$this->width = max(
$this->width,
$this->font->getStringWidth($field, $font, $fontSize)
);
}
$this->width += $this->font->getStringWidth(' ', $font, $fontSize);
/*
* it is unknown what value must be added, because
* table title is affected by the table width value
*/
while ($this->width < $this->font->getStringWidth($this->getTitle(), $font, $fontSize)) {
$this->width += 7;
}
}
/**
* Sets the height of the table
*
* @param int $fontSize font size
*/
private function setHeightTable($fontSize): void
{
$this->heightCell = $fontSize + 4;
$this->height = (count($this->fields) + 1) * $this->heightCell;
}
/**
* draw the table
*
* @see Svg::printElement
*
* @param bool $showColor Whether to display color
*/
public function tableDraw($showColor): void
{
$this->diagram->printElement(
'rect',
$this->x,
$this->y,
$this->width,
$this->heightCell,
null,
'fill:#007;stroke:black;'
);
$this->diagram->printElement(
'text',
$this->x + 5,
$this->y + 14,
$this->width,
$this->heightCell,
$this->getTitle(),
'fill:#fff;'
);
foreach ($this->fields as $field) {
$this->currentCell += $this->heightCell;
$fillColor = 'none';
if ($showColor) {
if (in_array($field, $this->primary)) {
$fillColor = '#aea';
}
if ($field == $this->displayfield) {
$fillColor = 'none';
}
}
$this->diagram->printElement(
'rect',
$this->x,
$this->y + $this->currentCell,
$this->width,
$this->heightCell,
null,
'fill:' . $fillColor . ';stroke:black;'
);
$this->diagram->printElement(
'text',
$this->x + 5,
$this->y + 14 + $this->currentCell,
$this->width,
$this->heightCell,
$field,
'fill:black;'
);
}
}
}