Translated using Weblate (Indonesian)
[phpmyadmin.git] / transformation_wrapper.php
blobcbf4772c40f023b420cdacbc1b12290b99af49b7
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 $cfgRelation = Relation::getRelationsParam();
26 /**
27 * Ensures db and table are valid, else moves to the "parent" script
29 require_once './libraries/db_table_exists.inc.php';
32 /**
33 * Sets globals from $_REQUEST
35 $request_params = array(
36 'cn',
37 'ct',
38 'sql_query',
39 'transform_key',
40 'where_clause'
42 $size_params = array(
43 'newHeight',
44 'newWidth',
46 foreach ($request_params as $one_request_param) {
47 if (isset($_REQUEST[$one_request_param])) {
48 if (in_array($one_request_param, $size_params)) {
49 $GLOBALS[$one_request_param] = intval($_REQUEST[$one_request_param]);
50 if ($GLOBALS[$one_request_param] > 2000) {
51 $GLOBALS[$one_request_param] = 2000;
53 } else {
54 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
60 /**
61 * Get the list of the fields of the current table
63 $GLOBALS['dbi']->selectDb($db);
64 if (isset($where_clause)) {
65 $result = $GLOBALS['dbi']->query(
66 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table)
67 . ' WHERE ' . $where_clause . ';',
68 null,
69 PhpMyAdmin\DatabaseInterface::QUERY_STORE
71 $row = $GLOBALS['dbi']->fetchAssoc($result);
72 } else {
73 $result = $GLOBALS['dbi']->query(
74 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table) . ' LIMIT 1;',
75 null,
76 PhpMyAdmin\DatabaseInterface::QUERY_STORE
78 $row = $GLOBALS['dbi']->fetchAssoc($result);
81 // No row returned
82 if (! $row) {
83 exit;
84 } // end if (no record returned)
86 $default_ct = 'application/octet-stream';
88 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
89 $mime_map = Transformations::getMIME($db, $table);
90 $mime_options = Transformations::getOptions(
91 isset($mime_map[$transform_key]['transformation_options'])
92 ? $mime_map[$transform_key]['transformation_options'] : ''
95 foreach ($mime_options as $key => $option) {
96 if (substr($option, 0, 10) == '; charset=') {
97 $mime_options['charset'] = $option;
102 // Only output the http headers
103 $response = Response::getInstance();
104 $response->getHeader()->sendHttpHeaders();
106 // [MIME]
107 if (isset($ct) && ! empty($ct)) {
108 $mime_type = $ct;
109 } else {
110 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
111 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
112 : $default_ct)
113 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
116 Core::downloadHeader($cn, $mime_type);
118 if (! isset($_REQUEST['resize'])) {
119 if (stripos($mime_type, 'html') === false) {
120 echo $row[$transform_key];
121 } else {
122 echo htmlspecialchars($row[$transform_key]);
124 } else {
125 // if image_*__inline.inc.php finds that we can resize,
126 // it sets the resize parameter to jpeg or png
128 $srcImage = imagecreatefromstring($row[$transform_key]);
129 $srcWidth = ImageSX($srcImage);
130 $srcHeight = ImageSY($srcImage);
132 // Check to see if the width > height or if width < height
133 // if so adjust accordingly to make sure the image
134 // stays smaller than the new width and new height
136 $ratioWidth = $srcWidth/$_REQUEST['newWidth'];
137 $ratioHeight = $srcHeight/$_REQUEST['newHeight'];
139 if ($ratioWidth < $ratioHeight) {
140 $destWidth = $srcWidth/$ratioHeight;
141 $destHeight = $_REQUEST['newHeight'];
142 } else {
143 $destWidth = $_REQUEST['newWidth'];
144 $destHeight = $srcHeight/$ratioWidth;
147 if ($_REQUEST['resize']) {
148 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
151 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
152 // $destWidth, $destHeight, $srcWidth, $srcHeight);
153 // better quality but slower:
154 ImageCopyResampled(
155 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
156 $destHeight, $srcWidth, $srcHeight
159 if ($_REQUEST['resize'] == 'jpeg') {
160 ImageJPEG($destImage, null, 75);
162 if ($_REQUEST['resize'] == 'png') {
163 ImagePNG($destImage);
165 ImageDestroy($srcImage);
166 ImageDestroy($destImage);