Translated using Weblate (Japanese)
[phpmyadmin.git] / transformation_wrapper.php
bloba1c8416aab3304beded31091d9f503bbb84d31e0
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)) {
67 if (! Core::checkSqlQuerySignature($where_clause, isset($_GET['where_clause_sign']) ? $_GET['where_clause_sign'] : '')) {
68 /* l10n: In case a SQL query did not pass a security check */
69 Core::fatalError(__('There is an issue with your request.'));
70 exit;
72 $result = $GLOBALS['dbi']->query(
73 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table)
74 . ' WHERE ' . $where_clause . ';',
75 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
76 PhpMyAdmin\DatabaseInterface::QUERY_STORE
78 $row = $GLOBALS['dbi']->fetchAssoc($result);
79 } else {
80 $result = $GLOBALS['dbi']->query(
81 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table) . ' LIMIT 1;',
82 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
83 PhpMyAdmin\DatabaseInterface::QUERY_STORE
85 $row = $GLOBALS['dbi']->fetchAssoc($result);
88 // No row returned
89 if (! $row) {
90 exit;
91 } // end if (no record returned)
93 $default_ct = 'application/octet-stream';
95 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
96 $mime_map = Transformations::getMIME($db, $table);
97 $mime_options = Transformations::getOptions(
98 isset($mime_map[$transform_key]['transformation_options'])
99 ? $mime_map[$transform_key]['transformation_options'] : ''
102 foreach ($mime_options as $key => $option) {
103 if (substr($option, 0, 10) == '; charset=') {
104 $mime_options['charset'] = $option;
109 // Only output the http headers
110 $response = Response::getInstance();
111 $response->getHeader()->sendHttpHeaders();
113 // [MIME]
114 if (isset($ct) && ! empty($ct)) {
115 $mime_type = $ct;
116 } else {
117 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
118 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
119 : $default_ct)
120 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
123 Core::downloadHeader($cn, $mime_type);
125 if (! isset($_REQUEST['resize'])) {
126 if (stripos($mime_type, 'html') === false) {
127 echo $row[$transform_key];
128 } else {
129 echo htmlspecialchars($row[$transform_key]);
131 } else {
132 // if image_*__inline.inc.php finds that we can resize,
133 // it sets the resize parameter to jpeg or png
135 $srcImage = imagecreatefromstring($row[$transform_key]);
136 $srcWidth = ImageSX($srcImage);
137 $srcHeight = ImageSY($srcImage);
139 // Check to see if the width > height or if width < height
140 // if so adjust accordingly to make sure the image
141 // stays smaller than the new width and new height
143 $ratioWidth = $srcWidth/$_REQUEST['newWidth'];
144 $ratioHeight = $srcHeight/$_REQUEST['newHeight'];
146 if ($ratioWidth < $ratioHeight) {
147 $destWidth = $srcWidth/$ratioHeight;
148 $destHeight = $_REQUEST['newHeight'];
149 } else {
150 $destWidth = $_REQUEST['newWidth'];
151 $destHeight = $srcHeight/$ratioWidth;
154 if ($_REQUEST['resize']) {
155 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
158 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
159 // $destWidth, $destHeight, $srcWidth, $srcHeight);
160 // better quality but slower:
161 ImageCopyResampled(
162 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
163 $destHeight, $srcWidth, $srcHeight
166 if ($_REQUEST['resize'] == 'jpeg') {
167 ImageJPEG($destImage, null, 75);
169 if ($_REQUEST['resize'] == 'png') {
170 ImagePNG($destImage);
172 ImageDestroy($srcImage);
173 ImageDestroy($destImage);