~ubuntu-branches/ubuntu/saucy/phpmyadmin/saucy-proposed

« back to all changes in this revision

Viewing changes to transformation_wrapper.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-05-16 20:53:50 UTC
  • mfrom: (1.2.40) (55.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130516205350-sam3ls8m02vn3967
Tags: 4:4.0.1-1
* New upstream release.
* Update to debhelper 9, policy 3.9.4. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
3
/**
4
4
 *
5
 
 * @package phpMyAdmin
 
5
 * @package PhpMyAdmin
6
6
 */
7
7
 
8
8
/**
24
24
 
25
25
 
26
26
/**
 
27
 * Sets globals from $_REQUEST
 
28
 */
 
29
$request_params = array(
 
30
    'cn',
 
31
    'ct',
 
32
    'newHeight',
 
33
    'newWidth',
 
34
    'resize',
 
35
    'sql_query',
 
36
    'transform_key',
 
37
    'where_clause'
 
38
);
 
39
foreach ($request_params as $one_request_param) {
 
40
    if (isset($_REQUEST[$one_request_param])) {
 
41
        $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
 
42
    }
 
43
}
 
44
 
 
45
 
 
46
/**
27
47
 * Get the list of the fields of the current table
28
48
 */
29
49
PMA_DBI_select_db($db);
30
 
$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
31
50
if (isset($where_clause)) {
32
 
    $result      = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE);
33
 
    $row         = PMA_DBI_fetch_assoc($result);
 
51
    $result = PMA_DBI_query(
 
52
        'SELECT * FROM ' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';',
 
53
        null,
 
54
        PMA_DBI_QUERY_STORE
 
55
    );
 
56
    $row = PMA_DBI_fetch_assoc($result);
34
57
} else {
35
 
    $result      = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
36
 
    $row         = PMA_DBI_fetch_assoc($result);
 
58
    $result = PMA_DBI_query(
 
59
        'SELECT * FROM ' . PMA_Util::backquote($table) . ' LIMIT 1;',
 
60
        null,
 
61
        PMA_DBI_QUERY_STORE
 
62
    );
 
63
    $row = PMA_DBI_fetch_assoc($result);
37
64
}
38
65
 
39
66
// No row returned
40
 
if (!$row) {
 
67
if (! $row) {
41
68
    exit;
42
69
} // end if (no record returned)
43
70
 
45
72
 
46
73
if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
47
74
    $mime_map = PMA_getMime($db, $table);
48
 
    $mime_options = PMA_transformation_getOptions((isset($mime_map[$transform_key]['transformation_options']) ? $mime_map[$transform_key]['transformation_options'] : ''));
 
75
    $mime_options = PMA_transformation_getOptions(
 
76
        isset($mime_map[$transform_key]['transformation_options'])
 
77
        ? $mime_map[$transform_key]['transformation_options'] : ''
 
78
    );
49
79
 
50
80
    foreach ($mime_options AS $key => $option) {
51
81
        if (substr($option, 0, 10) == '; charset=') {
54
84
    }
55
85
}
56
86
 
57
 
// For re-usability, moved http-headers and stylesheets
58
 
// to a seperate file. It can now be included by libraries/header.inc.php,
59
 
// querywindow.php.
 
87
// Only output the http headers
 
88
$response = PMA_Response::getInstance();
 
89
$response->getHeader()->sendHttpHeaders();
60
90
 
61
 
require_once './libraries/header_http.inc.php';
62
91
// [MIME]
63
 
if (isset($ct) && !empty($ct)) {
64
 
    $content_type = 'Content-Type: ' . $ct;
 
92
if (isset($ct) && ! empty($ct)) {
 
93
    $mime_type = $ct;
65
94
} else {
66
 
    $content_type = 'Content-Type: ' . (isset($mime_map[$transform_key]['mimetype']) ? str_replace('_', '/', $mime_map[$transform_key]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
67
 
}
68
 
header($content_type);
69
 
 
70
 
if (isset($cn) && !empty($cn)) {
71
 
    header('Content-Disposition: attachment; filename=' . PMA_sanitize_filename($cn));
72
 
}
73
 
 
74
 
if (!isset($resize)) {
 
95
    $mime_type = (isset($mime_map[$transform_key]['mimetype'])
 
96
        ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
 
97
        : $default_ct)
 
98
    . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
 
99
}
 
100
 
 
101
PMA_downloadHeader($cn, $mime_type);
 
102
 
 
103
if (! isset($resize)) {
75
104
    echo $row[$transform_key];
76
105
} else {
77
106
    // if image_*__inline.inc.php finds that we can resize,
88
117
    $ratioWidth = $srcWidth/$newWidth;
89
118
    $ratioHeight = $srcHeight/$newHeight;
90
119
 
91
 
    if ($ratioWidth < $ratioHeight){
 
120
    if ($ratioWidth < $ratioHeight) {
92
121
        $destWidth = $srcWidth/$ratioHeight;
93
122
        $destHeight = $newHeight;
94
123
    } else {
100
129
        $destImage = ImageCreateTrueColor($destWidth, $destHeight);
101
130
    }
102
131
 
103
 
//    ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
104
 
// better quality but slower:
105
 
    ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
 
132
    // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
 
133
    // $destWidth, $destHeight, $srcWidth, $srcHeight);
 
134
    // better quality but slower:
 
135
    ImageCopyResampled(
 
136
        $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
 
137
        $destHeight, $srcWidth, $srcHeight
 
138
    );
106
139
 
107
140
    if ($resize == 'jpeg') {
108
 
        ImageJPEG($destImage, '', 75);
 
141
        ImageJPEG($destImage, null, 75);
109
142
    }
110
143
    if ($resize == 'png') {
111
144
        ImagePNG($destImage);