summaryrefslogtreecommitdiff
path: root/plugins/owncloud/owncloud.php
blob: f43177a9d7111270410445d95cefcf1dabd04e1a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

/**
 * OwnCloud Plugin
 *
 * @author Aleksander 'A.L.E.C' Machniak <machniak@kolabsys.com>
 * @licence GNU AGPL
 *
 * Configuration (see config.inc.php.dist)
 * 
 */

class owncloud extends rcube_plugin
{
    // all task excluding 'login' and 'logout'
    public $task = '?(?!login|logout).*';
    // we've got no ajax handlers
    public $noajax = true;
    // skip frames
    public $noframe = true;

    function init()
    {
        $rcmail = rcube::get_instance();

        // requires kolab_auth plugin
        if (empty($_SESSION['kolab_uid'])) {
            return;
        }

        $this->add_texts('localization/', false);

        // register task
        $this->register_task('owncloud');

        // register actions
        $this->register_action('index', array($this, 'action'));
        $this->register_action('redirect', array($this, 'redirect'));

        // add taskbar button
        $this->add_button(array(
            'command'    => 'owncloud',
            'class'      => 'button-owncloud',
            'classsel'   => 'button-owncloud button-selected',
            'innerclass' => 'button-inner',
            'label'      => 'owncloud.owncloud',
            ), 'taskbar');

        // add style for taskbar button (must be here) and Help UI
        $this->include_stylesheet($this->local_skin_path()."/owncloud.css");
    }

    function action()
    {
        $rcmail = rcube::get_instance();

        $rcmail->output->add_handlers(array('owncloudframe' => array($this, 'frame')));
        $rcmail->output->set_pagetitle($this->gettext('owncloud'));
        $rcmail->output->send('owncloud.owncloud');
    }

    function frame()
    {
        $rcmail = rcube::get_instance();

        $this->load_config();

        $src  = $rcmail->config->get('owncloud_url');
        $user = $_SESSION['kolab_uid']; // requires kolab_auth plugin
        $pass = $rcmail->decrypt($_SESSION['password']);

        $src = preg_replace('/^(https?:\/\/)/',
            '\\1' . urlencode($user) . ':' . urlencode($pass) . '@', $src);

        return '<iframe id="owncloudframe" width="100%" height="100%" frameborder="0"'
            .' src="' . $src. '"></iframe>';
    }

}