| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC. All rights reserved. | |
| 6 | | | |
| 7 | | This work is published under the GNU AGPLv3 license with some | |
| 8 | | permitted exceptions and without any warranty. For full license | |
| 9 | | and copyright information, see https://civicrm.org/licensing | |
| 10 | +--------------------------------------------------------------------+ |
| 11 | */ |
| 12 | |
| 13 | namespace Civi\Core\Themes; |
| 14 | |
| 15 | use Civi; |
| 16 | |
| 17 | /** |
| 18 | * |
| 19 | * @package CiviCRM_Hook |
| 20 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 21 | */ |
| 22 | class Resolvers { |
| 23 | |
| 24 | /** |
| 25 | * In the simple format, the CSS file is loaded from the extension's "css" subdir; |
| 26 | * if it's missing, then it searches the parents. |
| 27 | * |
| 28 | * To use an alternate subdir, override "prefix". |
| 29 | * |
| 30 | * Simple themes may use the "search_order" to assimilate content from other themes. |
| 31 | * |
| 32 | * @param \Civi\Core\Themes $themes |
| 33 | * The theming subsystem. |
| 34 | * @param string $themeKey |
| 35 | * The active/desired theme key. |
| 36 | * @param string $cssExt |
| 37 | * The extension for which we want a themed CSS file (e.g. "civicrm"). |
| 38 | * @param string $cssFile |
| 39 | * File name (e.g. "css/bootstrap.css"). |
| 40 | * @return array|string |
| 41 | * List of CSS URLs, or PASSTHRU. |
| 42 | */ |
| 43 | public static function simple($themes, $themeKey, $cssExt, $cssFile) { |
| 44 | $res = Civi::resources(); |
| 45 | $theme = $themes->get($themeKey); |
| 46 | $file = ''; |
| 47 | if (isset($theme['prefix'])) { |
| 48 | $file .= $theme['prefix']; |
| 49 | } |
| 50 | $file .= $themes->cssId($cssExt, $cssFile); |
| 51 | $file = $res->filterMinify($theme['ext'], $file); |
| 52 | |
| 53 | if ($res->getPath($theme['ext'], $file)) { |
| 54 | return array($res->getUrl($theme['ext'], $file, TRUE)); |
| 55 | } |
| 56 | else { |
| 57 | return Civi\Core\Themes::PASSTHRU; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * The base handler falls back to loading files from the main application (rather than |
| 63 | * using the theme). |
| 64 | * |
| 65 | * @param \Civi\Core\Themes $themes |
| 66 | * The theming subsystem. |
| 67 | * @param string $themeKey |
| 68 | * The active/desired theme key. |
| 69 | * @param string $cssExt |
| 70 | * The extension for which we want a themed CSS file (e.g. "civicrm"). |
| 71 | * @param string $cssFile |
| 72 | * File name (e.g. "css/bootstrap.css"). |
| 73 | * @return array|string |
| 74 | * List of CSS URLs, or PASSTHRU. |
| 75 | */ |
| 76 | public static function fallback($themes, $themeKey, $cssExt, $cssFile) { |
| 77 | $res = Civi::resources(); |
| 78 | return array($res->getUrl($cssExt, $cssFile, TRUE)); |
| 79 | } |
| 80 | |
| 81 | } |