Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.61% |
10 / 217 |
|
6.25% |
2 / 32 |
CRAP | |
0.00% |
0 / 1 |
| Layout | |
4.61% |
10 / 217 |
|
6.25% |
2 / 32 |
9311.87 | |
0.00% |
0 / 1 |
| setTemplate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReleaseMsgData | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
42 | |||
| getSandboxExpiration | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| renderIcon | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
182 | |||
| getBundleLoader | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| getModuleLoader | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getAmdLoader | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| getTitle | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| isSmallNavi | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
12 | |||
| isSolarDesignEnabled | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| isQuickWinsDesignEnabled | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getContentTemplate | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getLogoUrl | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
| getDefaultLogoUrl | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
| getBranding | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getThemeUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLinkUrl | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
90 | |||
| getMessage | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
90 | |||
| getOperatedByData | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
| isUnstable | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getVerboseVersionName | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getLoginMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLoginLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPasswordLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCopyrightNotice | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| renderThemeTemplate | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getThemeTemplate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getThemeStylesheet | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| printAnalyticsCode | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
| getCurrentTheme | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getThemeService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSortedActionsByWeight | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program 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 this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2014-2024 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\helpers; |
| 24 | |
| 25 | use Jig\Utils\StringUtils; |
| 26 | use oat\tao\model\menu\Icon; |
| 27 | use oat\tao\model\OperatedByService; |
| 28 | use oat\tao\model\theme\ConfigurablePlatformTheme; |
| 29 | use oat\tao\model\theme\ConfigurableTheme; |
| 30 | use oat\tao\model\theme\Theme; |
| 31 | use oat\tao\model\theme\ThemeService; |
| 32 | use oat\tao\model\theme\ThemeServiceAbstract; |
| 33 | use oat\oatbox\service\ServiceManager; |
| 34 | use oat\tao\model\layout\AmdLoader; |
| 35 | use oat\tao\model\theme\SolarDesignCheckerInterface; |
| 36 | |
| 37 | class Layout |
| 38 | { |
| 39 | protected static string $templateClass = Template::class; |
| 40 | |
| 41 | public static function setTemplate(string $templateClass): void |
| 42 | { |
| 43 | self::$templateClass = $templateClass; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Compute the parameters for the release message |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | public static function getReleaseMsgData() |
| 52 | { |
| 53 | $params = [ |
| 54 | 'version-type' => '', |
| 55 | 'is-unstable' => self::isUnstable(), |
| 56 | 'is-sandbox' => false, |
| 57 | 'logo' => self::getLogoUrl(), |
| 58 | 'link' => self::getLinkUrl(), |
| 59 | 'msg' => self::getMessage() |
| 60 | ]; |
| 61 | |
| 62 | switch (TAO_RELEASE_STATUS) { |
| 63 | case 'alpha': |
| 64 | case 'demoA': |
| 65 | $params['version-type'] = __('Alpha version'); |
| 66 | break; |
| 67 | |
| 68 | case 'beta': |
| 69 | case 'demoB': |
| 70 | $params['version-type'] = __('Beta version'); |
| 71 | break; |
| 72 | |
| 73 | case 'demoS': |
| 74 | $params['version-type'] = __('Demo Sandbox'); |
| 75 | $params['is-sandbox'] = true; |
| 76 | $params['msg'] = self::getSandboxExpiration(); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | return $params; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | /** |
| 85 | * Compute the expiration time for the sandbox version |
| 86 | * |
| 87 | * @return string |
| 88 | */ |
| 89 | public static function getSandboxExpiration() |
| 90 | { |
| 91 | $datetime = new \DateTime(); |
| 92 | $d = new \DateTime($datetime->format('Y-m-d')); |
| 93 | $weekday = $d->format('w'); |
| 94 | $weekNumber = $d->format('W'); |
| 95 | $diff = $weekNumber % 2 ? 7 : 6 - $weekday; |
| 96 | $d->modify(sprintf('+ %d day', $diff)); |
| 97 | return \tao_helpers_Date::displayInterval($d, \tao_helpers_Date::FORMAT_INTERVAL_LONG); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * $icon defined in oat\tao\model\menu\Perspective::fromSimpleXMLElement |
| 102 | * |
| 103 | * $icon has two methods, getSource() and getId(). |
| 104 | * There are three possible ways to include icons, either as font, img or svg (not yet supported). |
| 105 | * - Font uses source to address the style sheet (TAO font as default) and id to build the class name |
| 106 | * - Img uses source only |
| 107 | * - Svg uses source to address an SVG sprite and id to point to the right icon in there |
| 108 | * |
| 109 | * @param Icon $icon |
| 110 | * @param string $defaultIcon e.g. icon-extension | icon-action |
| 111 | * @return string icon as html |
| 112 | */ |
| 113 | public static function renderIcon($icon, $defaultIcon) |
| 114 | { |
| 115 | |
| 116 | $srcExt = ''; |
| 117 | $isBase64 = false; |
| 118 | $iconClass = $defaultIcon; |
| 119 | if (!is_null($icon)) { |
| 120 | if ($icon->getSource()) { |
| 121 | $imgXts = 'png|jpg|jpe|jpeg|gif|svg'; |
| 122 | $regExp = sprintf('~((^data:image/(%s))|(\.(%s)$))~', $imgXts, $imgXts); |
| 123 | $srcExt = preg_match($regExp, $icon->getSource(), $matches) ? array_pop($matches) : []; |
| 124 | $isBase64 = 0 === strpos($icon->getSource(), 'data:image'); |
| 125 | } |
| 126 | |
| 127 | $iconClass = $icon->getId() ? $icon->getId() : $defaultIcon; |
| 128 | } |
| 129 | // clarification icon vs. glyph: same thing but due to certain CSS rules a second class is required |
| 130 | switch ($srcExt) { |
| 131 | case 'png': |
| 132 | case 'jpg': |
| 133 | case 'jpe': |
| 134 | case 'jpeg': |
| 135 | case 'gif': |
| 136 | return $isBase64 |
| 137 | ? '<img src="' . $icon->getSource() . '" alt="" class="glyph" />' |
| 138 | : '<img src="' . Template::img( |
| 139 | $icon->getSource(), |
| 140 | $icon->getExtension() |
| 141 | ) . '" alt="" class="glyph" />'; |
| 142 | break; |
| 143 | |
| 144 | case 'svg': |
| 145 | return sprintf( |
| 146 | '<svg class="svg-glyph"><use xlink:href="%s#%s"/></svg>', |
| 147 | Template::img($icon->getSource(), $icon->getExtension()), |
| 148 | $icon->getId() |
| 149 | ); |
| 150 | |
| 151 | case '': // no source means an icon font is used |
| 152 | return sprintf('<span class="%s glyph"></span>', $iconClass); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Create the AMD loader to load a bundle for the current context. |
| 158 | * |
| 159 | * @param string $bundle the bundle URL |
| 160 | * @param string $controller the controller module id |
| 161 | * @param array $params additional parameters |
| 162 | * @param string $type the type of bundle, can be: '', 'es5', 'standalone' (default: '') |
| 163 | * @return string the script tag |
| 164 | */ |
| 165 | public static function getBundleLoader( |
| 166 | string $bundle, |
| 167 | string $controller, |
| 168 | array $params = [], |
| 169 | string $type = '' |
| 170 | ): string { |
| 171 | $configUrl = get_data('client_config_url'); |
| 172 | $requireJsUrl = Template::js('lib/require.js', 'tao'); |
| 173 | $bootstrapUrl = Template::js('loader/bootstrap.js', 'tao'); |
| 174 | |
| 175 | switch (strtolower($type)) { |
| 176 | case 'es5': |
| 177 | $vendor = 'loader/vendor.es5.min.js'; |
| 178 | break; |
| 179 | |
| 180 | case 'standalone': |
| 181 | $vendor = ''; |
| 182 | break; |
| 183 | |
| 184 | default: |
| 185 | $vendor = 'loader/vendor.min.js'; |
| 186 | } |
| 187 | |
| 188 | $dependency = ''; |
| 189 | if ($vendor) { |
| 190 | $dependency = "<script src='" . Template::js($vendor, 'tao') . "'></script>\n"; |
| 191 | } |
| 192 | |
| 193 | $loader = new AmdLoader($configUrl, $requireJsUrl, $bootstrapUrl); |
| 194 | |
| 195 | return $dependency . $loader->getBundleLoader($bundle, $controller, $params); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Create the AMD loader to load modules for the current context. |
| 200 | * |
| 201 | * @param string $controller the controller module id |
| 202 | * @param array $params additional parameters |
| 203 | * @return string the script tag |
| 204 | */ |
| 205 | public static function getModuleLoader(string $controller, array $params = []): string |
| 206 | { |
| 207 | $configUrl = get_data('client_config_url'); |
| 208 | $requireJsUrl = Template::js('lib/require.js', 'tao'); |
| 209 | $bootstrapUrl = Template::js('loader/bootstrap.js', 'tao'); |
| 210 | |
| 211 | $loader = new AmdLoader($configUrl, $requireJsUrl, $bootstrapUrl); |
| 212 | |
| 213 | return $loader->getDynamicLoader($controller, $params); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Create the AMD loader for the current context. |
| 218 | * It will load login's modules for anonymous session. |
| 219 | * Loads the bundle mode in production and the dynamic mode in debug. |
| 220 | * |
| 221 | * @param string $bundle the bundle URL |
| 222 | * @param string $controller the controller module id |
| 223 | * @param array $params additional parameters |
| 224 | * @param bool $allowAnonymous allows to load the bundle in anonymous mode. |
| 225 | * @param string $type the type of bundle, can be: '', 'es5', 'standalone' (default: '') |
| 226 | * @return string the script tag |
| 227 | */ |
| 228 | public static function getAmdLoader( |
| 229 | string $bundle, |
| 230 | string $controller, |
| 231 | array $params = [], |
| 232 | bool $allowAnonymous = false, |
| 233 | string $type = '' |
| 234 | ): string { |
| 235 | if (\common_session_SessionManager::isAnonymous() && !$allowAnonymous) { |
| 236 | $controller = 'controller/login'; |
| 237 | $bundle = Template::js('loader/login.min.js', 'tao'); |
| 238 | } |
| 239 | |
| 240 | if (\tao_helpers_Mode::is('production')) { |
| 241 | return self::getBundleLoader($bundle, $controller, $params, $type); |
| 242 | } |
| 243 | |
| 244 | return self::getModuleLoader($controller, $params); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @return string |
| 249 | */ |
| 250 | public static function getTitle() |
| 251 | { |
| 252 | $title = get_data('title'); |
| 253 | return $title ? $title : PRODUCT_NAME . ' ' . TAO_VERSION; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | /** |
| 258 | * Navigation is considered small when it has no main and max. 2 item in the settings menu |
| 259 | * @return bool |
| 260 | */ |
| 261 | public static function isSmallNavi() |
| 262 | { |
| 263 | $settingsMenu = get_data('settings-menu'); |
| 264 | return empty(get_data('main-menu')) && empty($settingsMenu) || count($settingsMenu) < 3; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Tells if the Solar Design System should apply. |
| 269 | */ |
| 270 | public static function isSolarDesignEnabled(): bool |
| 271 | { |
| 272 | // if FEATURE_FLAG_SOLAR_DESIGN_ENABLED is active, the feature is always on |
| 273 | if (self::getThemeService()->isSolarDesignEnabled()) { |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | // a theme can also require the feature based on an option |
| 278 | $theme = self::getCurrentTheme(); |
| 279 | if ($theme instanceof SolarDesignCheckerInterface) { |
| 280 | return $theme->isSolarDesignEnabled(); |
| 281 | } |
| 282 | |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | public static function isQuickWinsDesignEnabled(): bool |
| 287 | { |
| 288 | // if FEATURE_FLAG_QUICK_WINS_ENABLED is active, the feature is always on |
| 289 | if (self::getThemeService()->isQuickWinsDesignEnabled()) { |
| 290 | return true; |
| 291 | } |
| 292 | return false; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Retrieve the template with the actual content |
| 297 | * |
| 298 | * @return array |
| 299 | */ |
| 300 | public static function getContentTemplate() |
| 301 | { |
| 302 | $templateData = (array)get_data('content-template'); |
| 303 | $contentExtension = get_data('content-extension'); |
| 304 | $contentTemplate['path'] = $templateData[0]; |
| 305 | $contentTemplate['ext'] = isset($templateData[1]) |
| 306 | ? $templateData[1] |
| 307 | : ($contentExtension ? $contentExtension : 'tao'); |
| 308 | return $contentTemplate; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Get the logo URL. |
| 313 | * |
| 314 | * In case of non configurable theme, logo can be changed following on platform readiness |
| 315 | * |
| 316 | * @return string The absolute URL to the logo image. |
| 317 | */ |
| 318 | public static function getLogoUrl() |
| 319 | { |
| 320 | if (self::getThemeService()->isQuickWinsDesignEnabled()) { |
| 321 | return $logoFile = Template::img('logo.svg', 'tao'); |
| 322 | } |
| 323 | $theme = self::getCurrentTheme(); |
| 324 | if ( |
| 325 | $theme instanceof ConfigurableTheme || |
| 326 | $theme instanceof ConfigurablePlatformTheme |
| 327 | ) { |
| 328 | $logoFile = $theme->getLogoUrl(); |
| 329 | if (!empty($logoFile)) { |
| 330 | return $logoFile; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return static::getDefaultLogoUrl(); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Returns the default logo url. |
| 339 | * |
| 340 | * @return string |
| 341 | */ |
| 342 | public static function getDefaultLogoUrl() |
| 343 | { |
| 344 | switch (TAO_RELEASE_STATUS) { |
| 345 | case 'alpha': |
| 346 | case 'demoA': |
| 347 | return Template::img('tao-logo-alpha.png', 'tao'); |
| 348 | break; |
| 349 | case 'beta': |
| 350 | case 'demoB': |
| 351 | return Template::img('tao-logo-beta.png', 'tao'); |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | return $logoFile = Template::img('tao-logo.png', 'tao'); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Deprecated way to insert a theming css, use custom template instead |
| 360 | * |
| 361 | * @deprecated |
| 362 | * @return string |
| 363 | */ |
| 364 | public static function getBranding() |
| 365 | { |
| 366 | return 'TAO'; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Deprecated way to insert a theming css, use custom template instead |
| 371 | * |
| 372 | * @deprecated |
| 373 | * @return string |
| 374 | */ |
| 375 | public static function getThemeUrl() |
| 376 | { |
| 377 | return ''; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Get the url link of current theme |
| 382 | * Url is used into header, to provide link to logo |
| 383 | * Url is used into footer, to provide link to footer message |
| 384 | * |
| 385 | * In case of non configurable theme, link can be changed following on platform readiness |
| 386 | * |
| 387 | * @return string |
| 388 | */ |
| 389 | public static function getLinkUrl() |
| 390 | { |
| 391 | $theme = self::getCurrentTheme(); |
| 392 | if ( |
| 393 | $theme instanceof ConfigurableTheme || |
| 394 | $theme instanceof ConfigurablePlatformTheme |
| 395 | ) { |
| 396 | $link = $theme->getLink(); |
| 397 | if (!empty($link)) { |
| 398 | return $link; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | //move this into the standard template setData() |
| 404 | switch (TAO_RELEASE_STATUS) { |
| 405 | case 'alpha': |
| 406 | case 'demoA': |
| 407 | case 'beta': |
| 408 | case 'demoB': |
| 409 | $link = 'https://forum.taocloud.org/'; |
| 410 | break; |
| 411 | default: |
| 412 | $link = 'http://taotesting.com'; |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | return $link; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Get the message of current theme |
| 421 | * Message is used into header, to provide title to logo |
| 422 | * Message is used into footer, as footer message |
| 423 | * |
| 424 | * In case of non configurable theme, message can be changed following on platform readiness |
| 425 | * |
| 426 | * @return string |
| 427 | */ |
| 428 | public static function getMessage() |
| 429 | { |
| 430 | $theme = self::getCurrentTheme(); |
| 431 | if ( |
| 432 | $theme instanceof ConfigurableTheme || |
| 433 | $theme instanceof ConfigurablePlatformTheme |
| 434 | ) { |
| 435 | $message = $theme->getMessage(); |
| 436 | if (!empty($message)) { |
| 437 | return $message; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | switch (TAO_RELEASE_STATUS) { |
| 442 | case 'alpha': |
| 443 | case 'demoA': |
| 444 | case 'beta': |
| 445 | case 'demoB': |
| 446 | $message = __('Please report bugs, ideas, comments or feedback on the TAO Forum'); |
| 447 | break; |
| 448 | default: |
| 449 | $message = ''; |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | return $message; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Get the currently registered OperatedBy data |
| 458 | * @return array |
| 459 | */ |
| 460 | public static function getOperatedByData() |
| 461 | { |
| 462 | |
| 463 | $name = ''; |
| 464 | $email = ''; |
| 465 | |
| 466 | // find data in the theme, they will be there if installed with the taoStyles extension |
| 467 | $theme = self::getCurrentTheme(); |
| 468 | if ($theme instanceof ConfigurablePlatformTheme) { |
| 469 | $operatedBy = $theme->getOperatedBy(); |
| 470 | $name = $operatedBy['name']; |
| 471 | $email = $operatedBy['email']; |
| 472 | } |
| 473 | |
| 474 | // otherwise they will be stored in config |
| 475 | if (!$name && !$email) { |
| 476 | $operatedByService = ServiceManager::getServiceManager()->get(OperatedByService::SERVICE_ID); |
| 477 | $name = $operatedByService->getName(); |
| 478 | $email = $operatedByService->getEmail(); |
| 479 | } |
| 480 | |
| 481 | $data = [ |
| 482 | 'name' => $name, |
| 483 | 'email' => empty($email) |
| 484 | ? '' |
| 485 | : StringUtils::encodeText('mailto:' . $email) |
| 486 | ]; |
| 487 | |
| 488 | return $data; |
| 489 | } |
| 490 | |
| 491 | public static function isUnstable() |
| 492 | { |
| 493 | |
| 494 | $isUnstable = true; |
| 495 | switch (TAO_RELEASE_STATUS) { |
| 496 | case 'demoS': |
| 497 | case 'stable': |
| 498 | $isUnstable = false; |
| 499 | break; |
| 500 | } |
| 501 | return $isUnstable; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Turn TAO_VERSION in a more verbose form. |
| 506 | * If TAO_VERSION diverges too much from the usual patterns TAO_VERSION will be returned unaltered. |
| 507 | * |
| 508 | * Examples (TAO_VERSION => return value): |
| 509 | * 3.2.0-sprint52 => Sprint52 rev 3.2.0 |
| 510 | * v3.2.0-sprint52 => Sprint52 rev 3.2.0 |
| 511 | * 3.2.0sprint52 => Sprint52 rev 3.2.0 |
| 512 | * 3.2.0 => 3.2.0 |
| 513 | * 3.2 => 3.2 |
| 514 | * 3.2 0 => 3.2 |
| 515 | * pattern w/o numbers => pattern w/o numbers |
| 516 | * |
| 517 | * @return string |
| 518 | */ |
| 519 | public static function getVerboseVersionName() |
| 520 | { |
| 521 | preg_match('~(?<revision>([\d\.]+))([\W_]?(?<specifics>(.*)?))~', trim(TAO_VERSION), $components); |
| 522 | if (empty($components['revision'])) { |
| 523 | return TAO_VERSION; |
| 524 | } |
| 525 | $version = ''; |
| 526 | if (!empty($components['specifics'])) { |
| 527 | $version .= ucwords($components['specifics']) . ' rev '; |
| 528 | } |
| 529 | $version .= ucwords($components['revision']); |
| 530 | return $version; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * |
| 535 | * @deprecated use custom template instead |
| 536 | * @return type |
| 537 | */ |
| 538 | public static function getLoginMessage() |
| 539 | { |
| 540 | return __("Connect to the TAO platform"); |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * |
| 545 | * @deprecated change default language if you want to change the "Login" translation |
| 546 | * @return type |
| 547 | */ |
| 548 | public static function getLoginLabel() |
| 549 | { |
| 550 | return __("Login"); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * |
| 555 | * @deprecated change default language if you want to change the "Password" translation |
| 556 | * @return type |
| 557 | */ |
| 558 | public static function getPasswordLabel() |
| 559 | { |
| 560 | return __("Password"); |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * |
| 565 | * @deprecated use custom footer.tpl template instead |
| 566 | * @return type |
| 567 | */ |
| 568 | public static function getCopyrightNotice() |
| 569 | { |
| 570 | return ''; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Render a themable template identified by its id |
| 575 | * |
| 576 | * @param string $templateId |
| 577 | * @param array $data |
| 578 | * @return string |
| 579 | */ |
| 580 | public static function renderThemeTemplate($target, $templateId, $data = []) |
| 581 | { |
| 582 | |
| 583 | //search in the registry to get the custom template to render |
| 584 | $tpl = self::getThemeTemplate($target, $templateId); |
| 585 | $theme = self::getCurrentTheme(); |
| 586 | |
| 587 | if (!is_null($tpl)) { |
| 588 | if ($theme instanceof ConfigurablePlatformTheme) { |
| 589 | // allow to use the getters from ConfigurablePlatformTheme |
| 590 | // to insert logo and such |
| 591 | $data['themeObj'] = $theme; |
| 592 | } |
| 593 | //render the template |
| 594 | $renderer = new \Renderer($tpl, $data); |
| 595 | return $renderer->render(); |
| 596 | } |
| 597 | return ''; |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Returns the absolute path of the template to be rendered considering the given context |
| 602 | * |
| 603 | * @param $target |
| 604 | * @param $templateId |
| 605 | * @return string |
| 606 | */ |
| 607 | public static function getThemeTemplate($target, $templateId) |
| 608 | { |
| 609 | return self::getCurrentTheme()->getTemplate($templateId, $target); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Returns the absolute path of the theme css that overwrites the base css |
| 614 | * |
| 615 | * @param $target |
| 616 | * @return string |
| 617 | */ |
| 618 | public static function getThemeStylesheet($target) |
| 619 | { |
| 620 | return self::getCurrentTheme()->getStylesheet($target); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Returns the necessary analytics code. |
| 625 | */ |
| 626 | public static function printAnalyticsCode(): void |
| 627 | { |
| 628 | $gaTag = $_ENV['GA_TAG'] ?? ''; |
| 629 | $environment = isset($_ENV['NODE_ENV']) && $_ENV['NODE_ENV'] === 'production' ? 'Production' : 'Internal'; |
| 630 | |
| 631 | if ($gaTag && method_exists(self::$templateClass, 'inc')) { |
| 632 | call_user_func( |
| 633 | [self::$templateClass, 'inc'], |
| 634 | 'blocks/analytics.tpl', |
| 635 | 'tao', |
| 636 | ['gaTag' => $gaTag, 'environment' => $environment] |
| 637 | ); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Get the current theme configured into tao/theming config |
| 643 | * |
| 644 | * @return Theme |
| 645 | */ |
| 646 | protected static function getCurrentTheme() |
| 647 | { |
| 648 | return self::getThemeService()->getTheme(); |
| 649 | } |
| 650 | |
| 651 | private static function getThemeService(): ThemeServiceAbstract |
| 652 | { |
| 653 | return ServiceManager::getServiceManager()->get(ThemeService::SERVICE_ID); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Get data from the request context with sorting by weight. |
| 658 | * |
| 659 | * @param string $key A key to identify the data. |
| 660 | * @return mixed The data bound to the key. If no data is bound to the provided key, null is return. |
| 661 | */ |
| 662 | |
| 663 | public static function getSortedActionsByWeight($key) |
| 664 | { |
| 665 | $data = get_data($key); |
| 666 | |
| 667 | usort($data, function ($a, $b) { |
| 668 | return $a->getWeight() < $b->getWeight(); |
| 669 | }); |
| 670 | |
| 671 | return $data; |
| 672 | } |
| 673 | } |