Merge pull request #22277 from demeritcowboy/isdir2
[civicrm-core.git] / CRM / Core / Smarty / plugins / function.crmStyle.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC
16 *
17 */
18
19 /**
20 * Add a stylesheet <LINK> to a specific part of the page
21 *
22 * @param array $params
23 * Array with keys:
24 * - ext: string, extension name. see CRM_Core_Resources::addStyleFile
25 * - file: string, relative file path. see CRM_Core_Resources::addStyleFile
26 * - url: string. see CRM_Core_Resources::addStyleURL
27 * - weight: int; default: CRM_Core_Resources::DEFAULT_WEIGHT (0)
28 * - region: string; default: CRM_Core_Resources::DEFAULT_REGION ('html-header')
29 * @param CRM_Core_Smarty $smarty
30 *
31 * @throws Exception
32 */
33 function smarty_function_crmStyle($params, &$smarty) {
34 $res = CRM_Core_Resources::singleton();
35
36 if (empty($params['weight'])) {
37 $params['weight'] = CRM_Core_Resources::DEFAULT_WEIGHT;
38 }
39 if (empty($params['region'])) {
40 $params['region'] = CRM_Core_Resources::DEFAULT_REGION;
41 }
42 if (empty($params['ext'])) {
43 $params['ext'] = 'civicrm';
44 }
45
46 if (array_key_exists('file', $params)) {
47 $res->addStyleFile($params['ext'], $params['file'], $params['weight'], $params['region']);
48 }
49 elseif (array_key_exists('url', $params)) {
50 $res->addStyleUrl($params['url'], $params['weight'], $params['region']);
51 }
52 else {
53 CRM_Core_Error::debug_var('crmStyle_params', $params);
54 throw new Exception("crmStyle requires url or ext+file");
55 }
56 }