2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Wrapper script for rendering transformations
8 use PMA\libraries\Response
;
13 define('IS_TRANSFORMATION_WRAPPER', true);
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();
23 * Ensures db and table are valid, else moves to the "parent" script
25 require_once './libraries/db_table_exists.inc.php';
29 * Sets globals from $_REQUEST
31 $request_params = array(
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;
50 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
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 . ';',
65 PMA\libraries\DatabaseInterface
::QUERY_STORE
67 $row = $GLOBALS['dbi']->fetchAssoc($result);
69 $result = $GLOBALS['dbi']->query(
70 'SELECT * FROM ' . PMA\libraries\Util
::backquote($table) . ' LIMIT 1;',
72 PMA\libraries\DatabaseInterface
::QUERY_STORE
74 $row = $GLOBALS['dbi']->fetchAssoc($result);
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();
103 if (isset($ct) && ! empty($ct)) {
106 $mime_type = (!empty($mime_map[$transform_key]['mimetype'])
107 ?
str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
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];
118 echo htmlspecialchars($row[$transform_key]);
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'];
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:
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);