-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalLinkPluginUtils.php
More file actions
74 lines (68 loc) · 2.32 KB
/
ExternalLinkPluginUtils.php
File metadata and controls
74 lines (68 loc) · 2.32 KB
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
<?php
/**
* ExternalLinkPluginUtils.php - Utility functions needed by the ExternalLink plugin.
*
* Even though these functions are included with the ExternalLink plugin they
* are not specific to it and might be useful in other projects as well.
*
* 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 Robert Costa <rcosta@uos.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
/**
* Encapsulates various utility functions under the Utils class namespace.
*/
class ExternalLinkPluginUtils {
/**
* Get the current URL as called by the web client.
* taken from http://stackoverflow.com/a/2820771
*
* @return string The current URL.
*/
public static function getUrl() {
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
/**
* Get the file name of the currently executed PHP script.
*
* @return string Filename of currently executed PHP script.
*/
public static function getBasename() {
return basename($_SERVER['PHP_SELF']);
}
/**
* Get the base URL including the directory path, excluding file name,
* query string, etc.
*
* return string Base URL of client request.
*/
public static function getBaseUrl() {
$url = Utils::getUrl();
$pos = strpos($url, Utils::getBasename());
// remove current script name, query, etc.
// only keep host URL and directory part of path
return substr($url, 0, $pos);
}
/**
* Return id of currently selected seminar.
* Return false, if no seminar is selected.
*
* @return mixed seminar_id or false
*/
public static function getSeminarId() {
if (!Request::option('cid')) {
if ($GLOBALS['SessionSeminar']) {
URLHelper::bindLinkParam('cid', $GLOBALS['SessionSeminar']);
return $GLOBALS['SessionSeminar'];
}
return false;
}
return Request::option('cid');
}
}