2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Wrapper script for rendering transformations
8 declare(strict_types
=1);
11 use PhpMyAdmin\DatabaseInterface
;
12 use PhpMyAdmin\Relation
;
13 use PhpMyAdmin\Response
;
14 use PhpMyAdmin\Transformations
;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
20 define('IS_TRANSFORMATION_WRAPPER', true);
24 require_once ROOT_PATH
. 'libraries/common.inc.php';
26 /** @var Response $response */
27 $response = $containerBuilder->get(Response
::class);
29 /** @var DatabaseInterface $dbi */
30 $dbi = $containerBuilder->get(DatabaseInterface
::class);
32 /** @var Transformations $transformations */
33 $transformations = $containerBuilder->get('transformations');
34 /** @var Relation $relation */
35 $relation = $containerBuilder->get('relation');
36 $cfgRelation = $relation->getRelationsParam();
39 * Ensures db and table are valid, else moves to the "parent" script
41 require_once ROOT_PATH
. 'libraries/db_table_exists.inc.php';
45 * Sets globals from $_REQUEST
58 foreach ($request_params as $one_request_param) {
59 if (isset($_REQUEST[$one_request_param])) {
60 if (in_array($one_request_param, $size_params)) {
61 $GLOBALS[$one_request_param] = intval($_REQUEST[$one_request_param]);
62 if ($GLOBALS[$one_request_param] > 2000) {
63 $GLOBALS[$one_request_param] = 2000;
66 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
73 * Get the list of the fields of the current table
76 if (isset($where_clause)) {
78 if (! Core
::checkSqlQuerySignature($where_clause, isset($_GET['where_clause_sign']) ?
$_GET['where_clause_sign'] : '')) {
79 /* l10n: In case a SQL query did not pass a security check */
80 Core
::fatalError(__('There is an issue with your request.'));
83 $result = $dbi->query(
84 'SELECT * FROM ' . PhpMyAdmin\Util
::backquote($table)
85 . ' WHERE ' . $where_clause . ';',
86 PhpMyAdmin\DatabaseInterface
::CONNECT_USER
,
87 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
89 $row = $dbi->fetchAssoc($result);
91 $result = $dbi->query(
92 'SELECT * FROM ' . PhpMyAdmin\Util
::backquote($table) . ' LIMIT 1;',
93 PhpMyAdmin\DatabaseInterface
::CONNECT_USER
,
94 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
96 $row = $dbi->fetchAssoc($result);
102 } // end if (no record returned)
104 $default_ct = 'application/octet-stream';
106 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
107 $mime_map = $transformations->getMime($db, $table);
108 $mime_options = $transformations->getOptions(
109 isset($mime_map[$transform_key]['transformation_options'])
110 ?
$mime_map[$transform_key]['transformation_options'] : ''
113 foreach ($mime_options as $key => $option) {
114 if (substr($option, 0, 10) == '; charset=') {
115 $mime_options['charset'] = $option;
120 $response->getHeader()->sendHttpHeaders();
123 if (isset($ct) && ! empty($ct)) {
126 $mime_type = (! empty($mime_map[$transform_key]['mimetype'])
127 ?
str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
129 . (isset($mime_options['charset']) ?
$mime_options['charset'] : '');
132 Core
::downloadHeader($cn, $mime_type);
134 if (! isset($_REQUEST['resize'])) {
135 if (stripos($mime_type, 'html') === false) {
136 echo $row[$transform_key];
138 echo htmlspecialchars($row[$transform_key]);
141 // if image_*__inline.inc.php finds that we can resize,
142 // it sets the resize parameter to jpeg or png
144 $srcImage = imagecreatefromstring($row[$transform_key]);
145 $srcWidth = imagesx($srcImage);
146 $srcHeight = imagesy($srcImage);
148 // Check to see if the width > height or if width < height
149 // if so adjust accordingly to make sure the image
150 // stays smaller than the new width and new height
152 $ratioWidth = $srcWidth / $_REQUEST['newWidth'];
153 $ratioHeight = $srcHeight / $_REQUEST['newHeight'];
155 if ($ratioWidth < $ratioHeight) {
156 $destWidth = $srcWidth / $ratioHeight;
157 $destHeight = $_REQUEST['newHeight'];
159 $destWidth = $_REQUEST['newWidth'];
160 $destHeight = $srcHeight / $ratioWidth;
163 if ($_REQUEST['resize']) {
164 $destImage = imagecreatetruecolor($destWidth, $destHeight);
166 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
167 // $destWidth, $destHeight, $srcWidth, $srcHeight);
168 // better quality but slower:
181 if ($_REQUEST['resize'] == 'jpeg') {
182 imagejpeg($destImage, null, 75);
184 if ($_REQUEST['resize'] == 'png') {
185 imagepng($destImage);
187 imagedestroy($destImage);
189 imagedestroy($srcImage);