-
Notifications
You must be signed in to change notification settings - Fork 2
/
ClockIP.php
executable file
·86 lines (76 loc) · 3.18 KB
/
ClockIP.php
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
80
81
82
83
84
85
86
<?php
/**
* ClockIP.class.php
*
* 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 Jan-Hendrik Willms <[email protected]>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @version 1.5
*/
if ($GLOBALS['SOFTWARE_VERSION'] >= '2.2') {
@include_once 'lib/classes/UpdateInformation.class.php';
}
class ClockIP extends StudipPlugin implements SystemPlugin
{
const FORMAT = 'l, d.m.Y H:i:s';
const MEDIUM_FORMAT = '(max-width:480px)d.m.Y H:i:s';
const SMALL_FORMAT = '(max-width:320px)H:i:s';
function __construct()
{
parent::__construct();
// Stud.IP 2.2: Periodically adjust clock
if (class_exists('UpdateInformation') && mt_rand(0, 10) == 0 && UpdateInformation::isCollecting()) {
UpdateInformation::setInformation('CLOCK.adjust', floor(microtime(true) * 1000));
return;
}
$additional_classes = '';
// Local changes:
// Uni Oldenburg
if (strpos($GLOBALS['STUDIP_INSTALLATION_ID'], 'uni-ol') !== false) {
if (!PageLayout::isHeaderEnabled()) {
return;
}
$additional_classes .= ' uni-oldenburg';
};
// Uni Augsburg - only display on details page
// TODO still working? INSTALLATION_ID?
if (strpos($GLOBALS['ABSOLUTE_URI_STUDIP'], 'augsburg') !== false) {
if (basename($_SERVER['SCRIPT_FILENAME']) !== 'details.php') {
return;
}
$additional_classes .= ' uni-augsburg';
};
// Generate time output, special case "l" for localized output
$format = self::FORMAT;
if (strpos($format, 'l') !== false) {
# ugly but since the plugin provides no translation itself, it should do the trick
$days = array_map('_', words('Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag'));
$format = str_replace('l', '\\'.implode('\\', str_split($days[date('w')])), $format);
}
$timestamp = date($format);
// Add clock to page
$html = sprintf('<div class="clockip%s" data-format="%s" data-mediumformat="%s" data-smallformat="%s" data-timestamp="%u">%s</div>',
$additional_classes,
self::FORMAT,
self::MEDIUM_FORMAT,
self::SMALL_FORMAT,
floor(microtime(true) * 1000),
$timestamp
);
PageLayout::addBodyElements($html);
// Add version to STUDIP javascript object
$js = sprintf('STUDIP = STUDIP || {}; STUDIP.VERSION = "%s";', $GLOBALS['SOFTWARE_VERSION']);
PageLayout::addHeadElement('script', array('type' => 'text/javascript'), $js);
// Add css and js to page
PageLayout::addScript($this->getPluginURL() . '/clock.js');
if ($GLOBALS['SOFTWARE_VERSION'] > '2.3') {
$this->addStylesheet('clock.less');
} else {
PageLayout::addStylesheet($this->getPluginURL() . '/clock.css');
}
}
}