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 | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * Adds inline help | |
22 | * | |
6a0b768e TO |
23 | * @param array $params |
24 | * The function params. | |
16b10e64 | 25 | * @param CRM_Core_Smarty $smarty |
6a0b768e | 26 | * Reference to the smarty object. |
6a488035 | 27 | * |
a6c01b45 | 28 | * @return string |
353ffa53 | 29 | * the help html to be inserted |
6a488035 TO |
30 | */ |
31 | function smarty_function_help($params, &$smarty) { | |
32 | if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { | |
a1a2a83d | 33 | return NULL; |
6a488035 TO |
34 | } |
35 | ||
6a488035 TO |
36 | if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) { |
37 | $params['file'] = $smarty->_tpl_vars['tplFile']; | |
38 | } | |
39 | elseif (empty($params['file'])) { | |
6eea17da | 40 | return NULL; |
6a488035 TO |
41 | } |
42 | ||
be2fb01f | 43 | $params['file'] = str_replace(['.tpl', '.hlp'], '', $params['file']); |
6a488035 TO |
44 | |
45 | if (empty($params['title'])) { | |
6441e8d7 | 46 | $vars = $smarty->get_template_vars(); |
6a488035 TO |
47 | $smarty->assign('id', $params['id'] . '-title'); |
48 | $name = trim($smarty->fetch($params['file'] . '.hlp')); | |
6eea17da E |
49 | $additionalTPLFile = $params['file'] . '.extra.hlp'; |
50 | if ($smarty->template_exists($additionalTPLFile)) { | |
51 | $name .= trim($smarty->fetch($additionalTPLFile)); | |
52 | } | |
6441e8d7 CW |
53 | // Ensure we didn't change any existing vars CRM-11900 |
54 | foreach ($vars as $key => $value) { | |
55 | if ($smarty->get_template_vars($key) !== $value) { | |
56 | $smarty->assign($key, $value); | |
57 | } | |
58 | } | |
6a488035 TO |
59 | } |
60 | else { | |
61 | $name = trim(strip_tags($params['title'])); | |
62 | } | |
6eea17da | 63 | |
1bf65b67 | 64 | $class = "helpicon"; |
65 | if (!empty($params['class'])) { | |
66 | $class .= " {$params['class']}"; | |
67 | } | |
68 | ||
4bc223d1 | 69 | // Escape for html |
be2fb01f | 70 | $title = htmlspecialchars(ts('%1 Help', [1 => $name])); |
4bc223d1 CW |
71 | // Escape for html and js |
72 | $name = htmlspecialchars(json_encode($name), ENT_QUOTES); | |
73 | ||
6a488035 | 74 | // Format params to survive being passed through json & the url |
4bc223d1 | 75 | unset($params['text'], $params['title']); |
6a488035 TO |
76 | foreach ($params as &$param) { |
77 | $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param; | |
78 | } | |
c7915cc9 | 79 | return '<a class="' . $class . '" title="' . $title . '" aria-label="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>'; |
6a488035 | 80 | } |