1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Component\Utils; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ChamiloApi |
8
|
|
|
* @package Chamilo\CoreBundle\Component |
9
|
|
|
*/ |
10
|
|
|
class ChamiloApi |
11
|
|
|
{ |
12
|
|
|
private static $configuration; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* ChamiloApi constructor. |
16
|
|
|
* @param $configuration |
17
|
|
|
*/ |
18
|
|
|
public function __construct(array $configuration) |
19
|
|
|
{ |
20
|
|
|
self::$configuration = $configuration; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
|
|
public static function getConfigurationArray() |
27
|
|
|
{ |
28
|
|
|
return self::$configuration; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $variable |
33
|
|
|
* @return bool|string |
34
|
|
|
*/ |
35
|
|
|
public static function getConfigurationValue($variable) |
36
|
|
|
{ |
37
|
|
|
$configuration = self::getConfigurationArray(); |
38
|
|
|
if (array_key_exists($variable, $configuration)) { |
39
|
|
|
return $configuration[$variable]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns an array of resolutions that can be used for the conversion of documents to images |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public static function getDocumentConversionSizes() |
51
|
|
|
{ |
52
|
|
|
return array( |
53
|
|
|
'540x405' => '540x405 (3/4)', |
54
|
|
|
'640x480' => '640x480 (3/4)', |
55
|
|
|
'720x540' => '720x540 (3/4)', |
56
|
|
|
'800x600' => '800x600 (3/4)', |
57
|
|
|
'1024x576' => '1024x576 (16/9)', |
58
|
|
|
'1024x768' => '1000x750 (3/4)', |
59
|
|
|
'1280x720' => '1280x720 (16/9)', |
60
|
|
|
'1280x860' => '1280x960 (3/4)', |
61
|
|
|
'1400x1050' => '1400x1050 (3/4)', |
62
|
|
|
'1600x900' => '1600x900 (16/9)', |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the platform logo path |
68
|
|
|
* @return null|string |
69
|
|
|
*/ |
70
|
|
|
public static function getWebPlatformLogoPath() |
71
|
|
|
{ |
72
|
|
|
$theme = api_get_visual_theme(); |
73
|
|
|
$accessUrlId = api_get_current_access_url_id(); |
74
|
|
|
$customLogoPath = "themes/$theme/images/header-logo-custom$accessUrlId.png"; |
75
|
|
|
|
76
|
|
|
if (file_exists(api_get_path(SYS_PUBLIC_PATH) . "css/$customLogoPath")) { |
77
|
|
|
return api_get_path(WEB_CSS_PATH) . $customLogoPath; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$originalLogoPath = "themes/$theme/images/header-logo.png"; |
81
|
|
|
|
82
|
|
|
if (file_exists(api_get_path(SYS_CSS_PATH) . $originalLogoPath)) { |
83
|
|
|
return api_get_path(WEB_CSS_PATH) . $originalLogoPath; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the platform logo. |
91
|
|
|
* Return a <img> if the logo image exists. Otherwise return a <h2> with the institution name. |
92
|
|
|
* @param array $imageAttributes Optional. |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public static function getPlatformLogo($imageAttributes = []) |
96
|
|
|
{ |
97
|
|
|
$logoPath = self::getWebPlatformLogoPath(); |
98
|
|
|
$institution = api_get_setting('Institution'); |
99
|
|
|
$institutionUrl = api_get_setting('InstitutionUrl'); |
100
|
|
|
$siteName = api_get_setting('siteName'); |
101
|
|
|
|
102
|
|
|
if ($logoPath === null) { |
103
|
|
|
$headerLogo = \Display::url($siteName, api_get_path(WEB_PATH) . 'index.php'); |
104
|
|
|
|
105
|
|
|
if (!empty($institutionUrl) && !empty($institution)) { |
106
|
|
|
$headerLogo .= ' - ' . \Display::url($institution, $institutionUrl); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$courseInfo = api_get_course_info(); |
110
|
|
|
|
111
|
|
|
if (isset($courseInfo['extLink']) && !empty($courseInfo['extLink']['name'])) { |
112
|
|
|
$headerLogo .= '<span class="extLinkSeparator"> - </span>'; |
113
|
|
|
|
114
|
|
|
if (!empty($courseInfo['extLink']['url'])) { |
115
|
|
|
$headerLogo .= \Display::url( |
116
|
|
|
$courseInfo['extLink']['name'], |
117
|
|
|
$courseInfo['extLink']['url'], |
118
|
|
|
['class' => 'extLink'] |
119
|
|
|
); |
120
|
|
|
} else if (!empty($courseInfo['extLink']['url'])) { |
121
|
|
|
$headerLogo .= $courseInfo['extLink']['url']; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return \Display::tag('h2', $headerLogo, ['class' => 'text-left']); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$image = \Display::img($logoPath, $institution, $imageAttributes); |
129
|
|
|
|
130
|
|
|
return \Display::url($image, api_get_path(WEB_PATH) . 'index.php'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Like strip_tags(), but leaves an additional space and removes only the given tags |
135
|
|
|
* @param string $string |
136
|
|
|
* @param array $tags Tags to be removed |
137
|
|
|
* @return string The original string without the given tags |
138
|
|
|
*/ |
139
|
|
View Code Duplication |
public static function stripGivenTags($string, $tags) |
140
|
|
|
{ |
141
|
|
|
foreach ($tags as $tag) { |
142
|
|
|
$string2 = preg_replace('#</' . $tag . '[^>]*>#i', ' ', $string); |
143
|
|
|
if ($string2 != $string) { |
144
|
|
|
$string = preg_replace('/<' . $tag . '[^>]*>/i', ' ', $string2); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
return $string; |
148
|
|
|
} |
149
|
|
|
/** |
150
|
|
|
* Adds or Subtract a time in hh:mm:ss to a datetime |
151
|
|
|
* @param string $time Time in hh:mm:ss format |
152
|
|
|
* @param string $datetime Datetime as accepted by the Datetime class constructor |
153
|
|
|
* @param bool $operation True for Add, False to Subtract |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public static function addOrSubTimeToDateTime($time, $datetime = 'now', $operation = true) |
157
|
|
|
{ |
158
|
|
|
$date = new \DateTime($datetime); |
159
|
|
|
|
160
|
|
|
$hours = $minutes = $seconds = 0; |
161
|
|
|
|
162
|
|
|
sscanf($time, "%d:%d:%d", $hours, $minutes, $seconds); |
163
|
|
|
|
164
|
|
|
$timeSeconds = isset($seconds) ? $hours * 3600 + $minutes * 60 + $seconds : $hours * 60 + $minutes; |
165
|
|
|
|
166
|
|
|
if ($operation) { |
167
|
|
|
$date->add(new \DateInterval('PT' . $timeSeconds . 'S')); |
168
|
|
|
} else { |
169
|
|
|
$date->sub(new \DateInterval('PT' . $timeSeconds . 'S')); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
return $date->format('Y-m-d H:i:s'); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|