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\Di\Container
;
13 use PhpMyAdmin\Relation
;
14 use PhpMyAdmin\Response
;
15 use PhpMyAdmin\Transformations
;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
21 define('IS_TRANSFORMATION_WRAPPER', true);
23 require_once ROOT_PATH
. 'libraries/common.inc.php';
25 $container = Container
::getDefaultContainer();
26 $container->set(Response
::class, Response
::getInstance());
28 /** @var Response $response */
29 $response = $container->get(Response
::class);
31 /** @var DatabaseInterface $dbi */
32 $dbi = $container->get(DatabaseInterface
::class);
34 $transformations = new Transformations();
35 $relation = new Relation($dbi);
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)) {
77 $result = $dbi->query(
78 'SELECT * FROM ' . PhpMyAdmin\Util
::backquote($table)
79 . ' WHERE ' . $where_clause . ';',
80 PhpMyAdmin\DatabaseInterface
::CONNECT_USER
,
81 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
83 $row = $dbi->fetchAssoc($result);
85 $result = $dbi->query(
86 'SELECT * FROM ' . PhpMyAdmin\Util
::backquote($table) . ' LIMIT 1;',
87 PhpMyAdmin\DatabaseInterface
::CONNECT_USER
,
88 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
90 $row = $dbi->fetchAssoc($result);
96 } // end if (no record returned)
98 $default_ct = 'application/octet-stream';
100 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
101 $mime_map = $transformations->getMime($db, $table);
102 $mime_options = $transformations->getOptions(
103 isset($mime_map[$transform_key]['transformation_options'])
104 ?
$mime_map[$transform_key]['transformation_options'] : ''
107 foreach ($mime_options as $key => $option) {
108 if (substr($option, 0, 10) == '; charset=') {
109 $mime_options['charset'] = $option;
114 $response->getHeader()->sendHttpHeaders();
117 if (isset($ct) && ! empty($ct)) {
120 $mime_type = (! empty($mime_map[$transform_key]['mimetype'])
121 ?
str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
123 . (isset($mime_options['charset']) ?
$mime_options['charset'] : '');
126 Core
::downloadHeader($cn, $mime_type);
128 if (! isset($_REQUEST['resize'])) {
129 if (stripos($mime_type, 'html') === false) {
130 echo $row[$transform_key];
132 echo htmlspecialchars($row[$transform_key]);
135 // if image_*__inline.inc.php finds that we can resize,
136 // it sets the resize parameter to jpeg or png
138 $srcImage = imagecreatefromstring($row[$transform_key]);
139 $srcWidth = imagesx($srcImage);
140 $srcHeight = imagesy($srcImage);
142 // Check to see if the width > height or if width < height
143 // if so adjust accordingly to make sure the image
144 // stays smaller than the new width and new height
146 $ratioWidth = $srcWidth / $_REQUEST['newWidth'];
147 $ratioHeight = $srcHeight / $_REQUEST['newHeight'];
149 if ($ratioWidth < $ratioHeight) {
150 $destWidth = $srcWidth / $ratioHeight;
151 $destHeight = $_REQUEST['newHeight'];
153 $destWidth = $_REQUEST['newWidth'];
154 $destHeight = $srcHeight / $ratioWidth;
157 if ($_REQUEST['resize']) {
158 $destImage = imagecreatetruecolor($destWidth, $destHeight);
160 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
161 // $destWidth, $destHeight, $srcWidth, $srcHeight);
162 // better quality but slower:
175 if ($_REQUEST['resize'] == 'jpeg') {
176 imagejpeg($destImage, null, 75);
178 if ($_REQUEST['resize'] == 'png') {
179 imagepng($destImage);
181 imagedestroy($destImage);
183 imagedestroy($srcImage);