Skip to content

Commit 5d83255

Browse files
committed
Don't show invalid Gis download options
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
1 parent e70f983 commit 5d83255

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

libraries/classes/Controllers/Table/GisVisualizationController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
use PhpMyAdmin\Template;
1717
use PhpMyAdmin\Url;
1818
use PhpMyAdmin\Util;
19+
use TCPDF;
1920

2021
use function __;
2122
use function array_merge;
23+
use function class_exists;
24+
use function extension_loaded;
2225
use function is_array;
2326

2427
/**
@@ -115,6 +118,8 @@ public function __invoke(): void
115118

116119
$this->visualization = GisVisualization::get($sqlQuery, $visualizationSettings, $rows, $pos);
117120

121+
$downloadOptions = $this->getDownloadOptions();
122+
118123
if (isset($_GET['saveToFile'])) {
119124
$this->saveToFile($visualizationSettings['spatialColumn'], $_GET['fileFormat']);
120125

@@ -172,11 +177,29 @@ public function __invoke(): void
172177
'start_and_number_of_rows_fieldset' => $startAndNumberOfRowsFieldset,
173178
'visualization' => $this->visualization->toImage('svg'),
174179
'draw_ol' => $this->visualization->asOl(),
180+
'download_options' => $downloadOptions,
175181
]);
176182

177183
$this->response->addHTML($html);
178184
}
179185

186+
/** @return list<'svg'|'png'|'pdf'> */
187+
private function getDownloadOptions(): array
188+
{
189+
$downloadOptions = [];
190+
if (class_exists(TCPDF::class)) {
191+
$downloadOptions[] = 'pdf';
192+
}
193+
194+
if (extension_loaded('gd')) {
195+
$downloadOptions[] = 'png';
196+
}
197+
198+
$downloadOptions[] = 'svg';
199+
200+
return $downloadOptions;
201+
}
202+
180203
/**
181204
* @param string $filename File name
182205
* @param string $format Save format

templates/table/gis_visualization/gis_visualization.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
{{ get_icon('b_saveimage', 'Save'|trans) }}
4141
</button>
4242
<ul class="dropdown-menu" aria-labelledby="saveImageButton">
43-
<li><a class="dropdown-item disableAjax" href="{{ download_url|raw }}&fileFormat=png">PNG</a></li>
44-
<li><a class="dropdown-item disableAjax" href="{{ download_url|raw }}&fileFormat=pdf">PDF</a></li>
45-
<li><a class="dropdown-item disableAjax" href="{{ download_url|raw }}&fileFormat=svg">SVG</a></li>
43+
{% for fileType in download_options %}
44+
<li><a class="dropdown-item disableAjax" download href="{{ download_url|raw }}&amp;fileFormat={{ fileType }}">{{ fileType|upper }}</a></li>
45+
{% endfor %}
4646
</ul>
4747
</div>
4848
</div>

0 commit comments

Comments
 (0)