aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/media_proxy.php
blob: 50dc3df54d537e13276c188ec9661510af94787e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
 * media_proxy.php - media proxy controller
 *
 * 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 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Elmar Ludwig
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */

class MediaProxyController extends StudipController
{
    /**
     * Empty before filter to avoid any unwanted output changes.
     *
     * @param string $action
     * @param array  $args
     */
    public function before_filter(&$action, &$args)
    {
    }

    /**
     * default action of this controller: proxy media data
     */
    public function index_action()
    {
        $url = Request::get('url');
        $media_proxy = new MediaProxy();
        $config = Config::GetInstance();
        $modified_since = NULL;

        if (!Seminar_Session::is_current_session_authenticated() ||
            $config->getValue('LOAD_EXTERNAL_MEDIA') != 'proxy') {
            throw new AccessDeniedException();
        }

        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            $modified_since = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
        }

        ini_set('default_socket_timeout', 5);
        $this->render_nothing();

        //stop output buffering started in Trails_Dispatcher::dispatch()
        while (ob_get_level()) {
            ob_end_clean();
        }

        try {
            $media_proxy->readURL($url, $modified_since);
        } catch (MediaProxyException $ex) {
            header($ex->getMessage());
        }
    }
}