thumb.php 5.27 KB
Newer Older
Penny Leach's avatar
Penny Leach committed
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
Penny Leach's avatar
Penny Leach committed
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Penny Leach's avatar
Penny Leach committed
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
Penny Leach's avatar
Penny Leach committed
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Penny Leach's avatar
Penny Leach committed
18
19
 *
 * @package    mahara
20
 * @subpackage core
21
 * @author     Catalyst IT Ltd
Penny Leach's avatar
Penny Leach committed
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
Penny Leach's avatar
Penny Leach committed
24
25
26
27
28
29
 *
 */

define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');
30
require_once('file.php');
Penny Leach's avatar
Penny Leach committed
31
32
33
34

$type = param_alpha('type');

switch ($type) {
35
    case 'profileiconbyid':
36
37
    case 'profileicon':
        $id = param_integer('id');
38
        $size = get_imagesize_parameters();
39

40
41
42
        if ($type == 'profileicon') {
            // Convert ID of user to the ID of a profileicon
            $id = get_field('usr', 'profileicon', 'id', $id);
43
44
        }

45
46
        if ($id) {
            if ($path = get_dataroot_image_path('artefact/internal/profileicons', $id, $size)) {
47
48
49
50
51
52
53
54
55
56
57
58
59
                $mimetype = get_mime_type($path);
                if ($mimetype) {
                    header('Content-type: ' . $mimetype);

                    // We can't cache 'profileicon' because it might change, 
                    // but 'profileiconbyid' never changes...
                    if ($type == 'profileiconbyid') {
                        // 1 week
                        $maxage = 604800;
                        header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
                        header('Cache-Control: max-age=' . $maxage);
                        header('Pragma: public');
                    }
60
61
62
                    readfile($path);
                    exit;
                }
63
            }
64
        }
65

66
67
        // We couldn't find an image for this user. Attempt to use the 'no user 
        // photo' image for the current theme
68
69
70
71
72
73
74

        // We can cache such images
        $maxage = 604800;
        header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
        header('Cache-Control: max-age=' . $maxage);
        header('Pragma: public');

75
76
77
78
79
80
        // NOTE: the institutional admin branch allows the theme to be locked 
        // down. This means that $USER->get('theme') should be used here 
        // instead, when that branch is merged. And don't forget to change it 
        // below at the other get_config('theme') call!
        if ($path = get_dataroot_image_path('artefact/internal/profileicons/no_userphoto/' . get_config('theme'), 0, $size)) {
            header('Content-type: ' . 'image/png');
81
82
83
            readfile($path);
            exit;
        }
84
85
86
87
88
89
90
91
92

        // If we couldn't find the no user photo picture, we put it into 
        // dataroot if we can
        $nouserphotopic = theme_get_path('images/no_userphoto.png');
        if ($nouserphotopic) {
            // Move the file into the correct place.
            $directory = get_config('dataroot') . 'artefact/internal/profileicons/no_userphoto/' . get_config('theme') . '/originals/0/';
            check_dir_exists($directory);
            copy($nouserphotopic, $directory . '0');
93
94
95
96
97
98
            // Now we can try and get the image in the correct size
            if ($path = get_dataroot_image_path('artefact/internal/profileicons/no_userphoto/' . get_config('theme'), 0, $size)) {
                header('Content-type: ' . 'image/png');
                readfile($path);
                exit;
            }
99
100
101
102
103
104
105
        }


        // Emergency fallback
        header('Content-type: ' . 'image/png');
        readfile(theme_get_path('images/no_userphoto.png'));
        exit;
106
        break;
107
108
109
110
111
112
113
114
115
116

    case 'blocktype':
        $bt = param_alpha('bt'); // blocktype
        $ap = param_alpha('ap', null); // artefact plugin (optional)
        
        $basepath = 'blocktype/' . $bt;
        if (!empty($ap)) {
            $basepath = 'artefact/' . $ap . '/' . $basepath;
        }
        header('Content-type: image/png');
117
118
119
120
        $maxage = 604800;
        header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
        header('Cache-Control: max-age=' . $maxage);
        header('Pragma: public');
121
122
        $path = get_config('docroot') . $basepath . '/thumb.png';
        if (is_readable($path)) {
123
124
125
126
127
            readfile($path);
            exit;
        }
        readfile(theme_get_path('images/no_thumbnail.png'));
        break;
128
129
130
131
    case 'viewlayout':
        header('Content-type: image/png');
        $vl = param_integer('vl');
        if ($widths = get_field('view_layout', 'widths', 'id', $vl)) {
132
133
134
135
            if ($path = theme_get_path('images/vl-' . str_replace(',', '-', $widths) . '.png')) {
                readfile($path);
                exit;
            }
136
137
138
        }
        readfile(theme_get_path('images/no_thumbnail.png'));
        break;
Penny Leach's avatar
Penny Leach committed
139
140
141
}

?>