Merge pull request #22277 from demeritcowboy/isdir2
[civicrm-core.git] / CRM / Core / Smarty / plugins / function.crmSetting.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 TTTP
16 *
17 */
18
19 /**
20 * Retrieve CiviCRM settings from the api for use in templates.
21 *
22 * @param $params
23 * @param $smarty
24 *
25 * @return int|string|null
26 */
27 function smarty_function_crmSetting($params, &$smarty) {
28
29 $errorScope = CRM_Core_TemporaryErrorScope::create(['CRM_Utils_REST', 'fatal']);
30 unset($params['method']);
31 unset($params['assign']);
32 $params['version'] = 3;
33
34 require_once 'api/api.php';
35 $result = civicrm_api('setting', 'getvalue', $params);
36 unset($errorScope);
37 // Core-688 FALSE is returned by Boolean settings, thus giving false errors.
38 if ($result === NULL) {
39 $smarty->trigger_error("Unknown error");
40 return NULL;
41 }
42
43 if (empty($params['var'])) {
44 return is_numeric($result) ? $result : json_encode($result);
45 }
46 if (!empty($params['json'])) {
47 $smarty->assign($params["var"], json_encode($result));
48 }
49 else {
50 $smarty->assign($params["var"], $result);
51 }
52 }