Translated using Weblate (Interlingua)
[phpmyadmin.git] / transformation_wrapper.php
blob1751842e47ac63e2fa49170826dfdfe6b1c42e1c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Wrapper script for rendering transformations
6 * @package PhpMyAdmin
7 */
9 /**
12 define('IS_TRANSFORMATION_WRAPPER', true);
14 /**
15 * Gets a core script and starts output buffering work
17 require_once './libraries/common.inc.php';
18 require_once './libraries/transformations.lib.php'; // Transformations
19 $cfgRelation = PMA_getRelationsParam();
21 /**
22 * Ensures db and table are valid, else moves to the "parent" script
24 require_once './libraries/db_table_exists.inc.php';
27 /**
28 * Sets globals from $_REQUEST
30 $request_params = array(
31 'cn',
32 'ct',
33 'sql_query',
34 'transform_key',
35 'where_clause'
37 $size_params = array(
38 'newHeight',
39 'newWidth',
41 foreach ($request_params as $one_request_param) {
42 if (isset($_REQUEST[$one_request_param])) {
43 if (in_array($one_request_param, $size_params)) {
44 $GLOBALS[$one_request_param] = intval($_REQUEST[$one_request_param]);
45 if ($GLOBALS[$one_request_param] > 2000) {
46 $GLOBALS[$one_request_param] = 2000;
48 } else {
49 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
55 /**
56 * Get the list of the fields of the current table
58 $GLOBALS['dbi']->selectDb($db);
59 if (isset($where_clause)) {
60 $result = $GLOBALS['dbi']->query(
61 'SELECT * FROM ' . PMA\libraries\Util::backquote($table)
62 . ' WHERE ' . $where_clause . ';',
63 null,
64 PMA\libraries\DatabaseInterface::QUERY_STORE
66 $row = $GLOBALS['dbi']->fetchAssoc($result);
67 } else {
68 $result = $GLOBALS['dbi']->query(
69 'SELECT * FROM ' . PMA\libraries\Util::backquote($table) . ' LIMIT 1;',
70 null,
71 PMA\libraries\DatabaseInterface::QUERY_STORE
73 $row = $GLOBALS['dbi']->fetchAssoc($result);
76 // No row returned
77 if (! $row) {
78 exit;
79 } // end if (no record returned)
81 $default_ct = 'application/octet-stream';
83 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
84 $mime_map = PMA_getMime($db, $table);
85 $mime_options = PMA_Transformation_getOptions(
86 isset($mime_map[$transform_key]['transformation_options'])
87 ? $mime_map[$transform_key]['transformation_options'] : ''
90 foreach ($mime_options as $key => $option) {
91 if (substr($option, 0, 10) == '; charset=') {
92 $mime_options['charset'] = $option;
97 // Only output the http headers
98 $response = PMA\libraries\Response::getInstance();
99 $response->getHeader()->sendHttpHeaders();
101 // [MIME]
102 if (isset($ct) && ! empty($ct)) {
103 $mime_type = $ct;
104 } else {
105 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
106 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
107 : $default_ct)
108 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
111 PMA_downloadHeader($cn, $mime_type);
113 if (! isset($_REQUEST['resize'])) {
114 if (stripos($mime_type, 'html') === false) {
115 echo $row[$transform_key];
116 } else {
117 echo htmlspecialchars($row[$transform_key]);
119 } else {
120 // if image_*__inline.inc.php finds that we can resize,
121 // it sets the resize parameter to jpeg or png
123 $srcImage = imagecreatefromstring($row[$transform_key]);
124 $srcWidth = ImageSX($srcImage);
125 $srcHeight = ImageSY($srcImage);
127 // Check to see if the width > height or if width < height
128 // if so adjust accordingly to make sure the image
129 // stays smaller than the new width and new height
131 $ratioWidth = $srcWidth/$_REQUEST['newWidth'];
132 $ratioHeight = $srcHeight/$_REQUEST['newHeight'];
134 if ($ratioWidth < $ratioHeight) {
135 $destWidth = $srcWidth/$ratioHeight;
136 $destHeight = $_REQUEST['newHeight'];
137 } else {
138 $destWidth = $_REQUEST['newWidth'];
139 $destHeight = $srcHeight/$ratioWidth;
142 if ($_REQUEST['resize']) {
143 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
146 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
147 // $destWidth, $destHeight, $srcWidth, $srcHeight);
148 // better quality but slower:
149 ImageCopyResampled(
150 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
151 $destHeight, $srcWidth, $srcHeight
154 if ($_REQUEST['resize'] == 'jpeg') {
155 ImageJPEG($destImage, null, 75);
157 if ($_REQUEST['resize'] == 'png') {
158 ImagePNG($destImage);
160 ImageDestroy($srcImage);
161 ImageDestroy($destImage);