Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
15 | * @copyright CiviCRM LLC | |
16 | * $Id$ | |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * Add a stylesheet <LINK> to a specific part of the page | |
22 | * | |
16b10e64 CW |
23 | * @param array $params |
24 | * Array with keys: | |
25 | * - ext: string, extension name. see CRM_Core_Resources::addStyleFile | |
26 | * - file: string, relative file path. see CRM_Core_Resources::addStyleFile | |
27 | * - url: string. see CRM_Core_Resources::addStyleURL | |
28 | * - weight: int; default: CRM_Core_Resources::DEFAULT_WEIGHT (0) | |
29 | * - region: string; default: CRM_Core_Resources::DEFAULT_REGION ('html-header') | |
30 | * @param CRM_Core_Smarty $smarty | |
77b97be7 EM |
31 | * |
32 | * @throws Exception | |
6a488035 TO |
33 | */ |
34 | function smarty_function_crmStyle($params, &$smarty) { | |
35 | $res = CRM_Core_Resources::singleton(); | |
36 | ||
37 | if (empty($params['weight'])) { | |
38 | $params['weight'] = CRM_Core_Resources::DEFAULT_WEIGHT; | |
39 | } | |
40 | if (empty($params['region'])) { | |
41 | $params['region'] = CRM_Core_Resources::DEFAULT_REGION; | |
42 | } | |
10bf3572 CW |
43 | if (empty($params['ext'])) { |
44 | $params['ext'] = 'civicrm'; | |
45 | } | |
6a488035 TO |
46 | |
47 | if (array_key_exists('file', $params)) { | |
48 | $res->addStyleFile($params['ext'], $params['file'], $params['weight'], $params['region']); | |
0db6c3e1 TO |
49 | } |
50 | elseif (array_key_exists('url', $params)) { | |
6a488035 | 51 | $res->addStyleUrl($params['url'], $params['weight'], $params['region']); |
0db6c3e1 TO |
52 | } |
53 | else { | |
6a488035 TO |
54 | CRM_Core_Error::debug_var('crmStyle_params', $params); |
55 | throw new Exception("crmStyle requires url or ext+file"); | |
56 | } | |
57 | } |