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