Fix #14184 - HTTPS/HTTP cookie separation issue (aka Failed to set session cookie...
[phpmyadmin.git] / transformation_wrapper.php
bloba1d653b08f81e3384d0d40b97c2ff3ee008cf2b3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Wrapper script for rendering transformations
6 * @package PhpMyAdmin
7 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\Relation;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Transformations;
14 /**
17 define('IS_TRANSFORMATION_WRAPPER', true);
19 /**
20 * Gets a core script and starts output buffering work
22 require_once './libraries/common.inc.php';
24 $relation = new Relation();
25 $cfgRelation = $relation->getRelationsParam();
27 /**
28 * Ensures db and table are valid, else moves to the "parent" script
30 require_once './libraries/db_table_exists.inc.php';
33 /**
34 * Sets globals from $_REQUEST
36 $request_params = array(
37 'cn',
38 'ct',
39 'sql_query',
40 'transform_key',
41 'where_clause'
43 $size_params = array(
44 'newHeight',
45 'newWidth',
47 foreach ($request_params as $one_request_param) {
48 if (isset($_REQUEST[$one_request_param])) {
49 if (in_array($one_request_param, $size_params)) {
50 $GLOBALS[$one_request_param] = intval($_REQUEST[$one_request_param]);
51 if ($GLOBALS[$one_request_param] > 2000) {
52 $GLOBALS[$one_request_param] = 2000;
54 } else {
55 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
61 /**
62 * Get the list of the fields of the current table
64 $GLOBALS['dbi']->selectDb($db);
65 if (isset($where_clause)) {
66 $result = $GLOBALS['dbi']->query(
67 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table)
68 . ' WHERE ' . $where_clause . ';',
69 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
70 PhpMyAdmin\DatabaseInterface::QUERY_STORE
72 $row = $GLOBALS['dbi']->fetchAssoc($result);
73 } else {
74 $result = $GLOBALS['dbi']->query(
75 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table) . ' LIMIT 1;',
76 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
77 PhpMyAdmin\DatabaseInterface::QUERY_STORE
79 $row = $GLOBALS['dbi']->fetchAssoc($result);
82 // No row returned
83 if (! $row) {
84 exit;
85 } // end if (no record returned)
87 $default_ct = 'application/octet-stream';
89 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
90 $mime_map = Transformations::getMIME($db, $table);
91 $mime_options = Transformations::getOptions(
92 isset($mime_map[$transform_key]['transformation_options'])
93 ? $mime_map[$transform_key]['transformation_options'] : ''
96 foreach ($mime_options as $key => $option) {
97 if (substr($option, 0, 10) == '; charset=') {
98 $mime_options['charset'] = $option;
103 // Only output the http headers
104 $response = Response::getInstance();
105 $response->getHeader()->sendHttpHeaders();
107 // [MIME]
108 if (isset($ct) && ! empty($ct)) {
109 $mime_type = $ct;
110 } else {
111 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
112 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
113 : $default_ct)
114 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
117 Core::downloadHeader($cn, $mime_type);
119 if (! isset($_REQUEST['resize'])) {
120 if (stripos($mime_type, 'html') === false) {
121 echo $row[$transform_key];
122 } else {
123 echo htmlspecialchars($row[$transform_key]);
125 } else {
126 // if image_*__inline.inc.php finds that we can resize,
127 // it sets the resize parameter to jpeg or png
129 $srcImage = imagecreatefromstring($row[$transform_key]);
130 $srcWidth = ImageSX($srcImage);
131 $srcHeight = ImageSY($srcImage);
133 // Check to see if the width > height or if width < height
134 // if so adjust accordingly to make sure the image
135 // stays smaller than the new width and new height
137 $ratioWidth = $srcWidth/$_REQUEST['newWidth'];
138 $ratioHeight = $srcHeight/$_REQUEST['newHeight'];
140 if ($ratioWidth < $ratioHeight) {
141 $destWidth = $srcWidth/$ratioHeight;
142 $destHeight = $_REQUEST['newHeight'];
143 } else {
144 $destWidth = $_REQUEST['newWidth'];
145 $destHeight = $srcHeight/$ratioWidth;
148 if ($_REQUEST['resize']) {
149 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
152 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
153 // $destWidth, $destHeight, $srcWidth, $srcHeight);
154 // better quality but slower:
155 ImageCopyResampled(
156 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
157 $destHeight, $srcWidth, $srcHeight
160 if ($_REQUEST['resize'] == 'jpeg') {
161 ImageJPEG($destImage, null, 75);
163 if ($_REQUEST['resize'] == 'png') {
164 ImagePNG($destImage);
166 ImageDestroy($srcImage);
167 ImageDestroy($destImage);