Completed
Push — v2.2-stable ( 20d974...7dc50b )
by Jesus
02:31
created

bigbluebutton   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A action_url() 0 11 3
A sanitized_url() 0 10 3
A sanitized_secret() 0 3 1
A root() 0 8 2
1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * The mod_bigbluebuttonbn locallib/bigbluebutton.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010-2017 Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
23
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 */
25
26
namespace mod_bigbluebuttonbn\locallib;
27
28
defined('MOODLE_INTERNAL') || die();
29
30
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php');
31
32
/**
33
 * Wrapper for executing http requests on a BigBlueButton server.
34
 *
35
 * @copyright 2010-2017 Blindside Networks Inc
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
37
 */
38
class bigbluebutton {
39
40
    /**
41
     * Returns the right URL for the action specified.
42
     *
43
     * @param string $action
44
     * @param array  $data
45
     * @param array  $metadata
46
     * @return string
47
     */
48
    public static function action_url($action = '', $data = array(), $metadata = array()) {
49
        $baseurl = self::sanitized_url() . $action . '?';
50
        $params = '';
51
        foreach ($data as $key => $value) {
52
            $params .= '&' . $key . '=' . urlencode($value);
53
        }
54
        foreach ($metadata as $key => $value) {
55
            $params .= '&' . 'meta_' . $key.'=' . urlencode($value);
56
        }
57
        return $baseurl . $params . '&checksum=' . sha1($action . $params . self::sanitized_secret());
58
    }
59
60
    /**
61
     * Makes sure the url used doesn't is in the format required.
62
     *
63
     * @return string
64
     */
65
    public static function sanitized_url() {
66
        $serverurl = trim(\mod_bigbluebuttonbn\locallib\config::get('server_url'));
67
        if (substr($serverurl, -1) == '/') {
68
            $serverurl = rtrim($serverurl, '/');
69
        }
70
        if (substr($serverurl, -4) == '/api') {
71
            $serverurl = rtrim($serverurl, '/api');
72
        }
73
        return $serverurl . '/api/';
74
    }
75
76
    /**
77
     * Makes sure the shared_secret used doesn't have trailing white characters.
78
     *
79
     * @return string
80
     */
81
    public static function sanitized_secret() {
82
        return trim(\mod_bigbluebuttonbn\locallib\config::get('shared_secret'));
83
    }
84
85
    /**
86
     * Returns the BigBlueButton server root URL.
87
     *
88
     * @return string
89
     */
90
    public static function root() {
91
        $pserverurl = parse_url(trim(\mod_bigbluebuttonbn\locallib\config::get('server_url')));
92
        $pserverurlport = "";
93
        if (isset($pserverurl['port'])) {
94
            $pserverurlport = ":" . $pserverurl['port'];
95
        }
96
        return $pserverurl['scheme'] . "://" . $pserverurl['host'] . $pserverurlport . "/";
97
    }
98
}
99