2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Wrapper script for rendering transformations
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
12 use PhpMyAdmin\Transformations
;
17 define('IS_TRANSFORMATION_WRAPPER', true);
20 * Gets a core script and starts output buffering work
22 require_once './libraries/common.inc.php';
24 $cfgRelation = Relation
::getRelationsParam();
27 * Ensures db and table are valid, else moves to the "parent" script
29 require_once './libraries/db_table_exists.inc.php';
33 * Sets globals from $_REQUEST
35 $request_params = array(
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;
54 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
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 . ';',
69 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
71 $row = $GLOBALS['dbi']->fetchAssoc($result);
73 $result = $GLOBALS['dbi']->query(
74 'SELECT * FROM ' . PhpMyAdmin\Util
::backquote($table) . ' LIMIT 1;',
76 PhpMyAdmin\DatabaseInterface
::QUERY_STORE
78 $row = $GLOBALS['dbi']->fetchAssoc($result);
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();
107 if (isset($ct) && ! empty($ct)) {
110 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
111 ?
str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
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];
122 echo htmlspecialchars($row[$transform_key]);
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'];
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:
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);