Merge pull request #1 from civicrm/master
[civicrm-core.git] / Civi / Core / Themes / Resolvers.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.7 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2016 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 namespace Civi\Core\Themes;
30
31 use Civi;
32
33 /**
34 *
35 * @package CiviCRM_Hook
36 * @copyright CiviCRM LLC (c) 2004-2016
37 */
38 class Resolvers {
39
40 /**
41 * In the simple format, the CSS file is loaded from the extension's "css" subdir;
42 * if it's missing, then it searches the parents.
43 *
44 * To use an alternate subdir, override "prefix".
45 *
46 * Simple themes may use the "search_order" to assimilate content from other themes.
47 *
48 * @param \Civi\Core\Themes $themes
49 * The theming subsystem.
50 * @param string $themeKey
51 * The active/desired theme key.
52 * @param string $cssExt
53 * The extension for which we want a themed CSS file (e.g. "civicrm").
54 * @param string $cssFile
55 * File name (e.g. "css/bootstrap.css").
56 * @return array|string
57 * List of CSS URLs, or PASSTHRU.
58 */
59 public static function simple($themes, $themeKey, $cssExt, $cssFile) {
60 $res = Civi::resources();
61 $theme = $themes->get($themeKey);
62 $file = '';
63 if (isset($theme['prefix'])) {
64 $file .= $theme['prefix'];
65 }
66 $file .= $themes->cssId($cssExt, $cssFile);
67 $file = $res->filterMinify($theme['ext'], $file);
68
69 if ($res->getPath($theme['ext'], $file)) {
70 return array($res->getUrl($theme['ext'], $file, TRUE));
71 }
72 else {
73 return Civi\Core\Themes::PASSTHRU;
74 }
75 }
76
77 /**
78 * The base handler falls back to loading files from the main application (rather than
79 * using the theme).
80 *
81 * @param \Civi\Core\Themes $themes
82 * The theming subsystem.
83 * @param string $themeKey
84 * The active/desired theme key.
85 * @param string $cssExt
86 * The extension for which we want a themed CSS file (e.g. "civicrm").
87 * @param string $cssFile
88 * File name (e.g. "css/bootstrap.css").
89 * @return array|string
90 * List of CSS URLs, or PASSTHRU.
91 */
92 public static function fallback($themes, $themeKey, $cssExt, $cssFile) {
93 $res = Civi::resources();
94 return array($res->getUrl($cssExt, $cssFile, TRUE));
95 }
96
97 }