3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
23 * @param array $params
24 * The function params.
25 * @param CRM_Core_Smarty $smarty
26 * Reference to the smarty object.
29 * the help html to be inserted
31 function smarty_function_help($params, &$smarty) {
32 if (!isset($params['id']) ||
!isset($smarty->_tpl_vars
['config'])) {
36 if (empty($params['file']) && isset($smarty->_tpl_vars
['tplFile'])) {
37 $params['file'] = $smarty->_tpl_vars
['tplFile'];
39 elseif (empty($params['file'])) {
43 $params['file'] = str_replace(['.tpl', '.hlp'], '', $params['file']);
45 if (empty($params['title'])) {
46 $vars = $smarty->get_template_vars();
47 $smarty->assign('id', $params['id'] . '-title');
48 $name = trim($smarty->fetch($params['file'] . '.hlp'));
49 $additionalTPLFile = $params['file'] . '.extra.hlp';
50 if ($smarty->template_exists($additionalTPLFile)) {
51 $name .= trim($smarty->fetch($additionalTPLFile));
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);
61 $name = trim(strip_tags($params['title']));
65 if (!empty($params['class'])) {
66 $class .= " {$params['class']}";
70 $title = htmlspecialchars(ts('%1 Help', [1 => $name]));
71 // Escape for html and js
72 $name = htmlspecialchars(json_encode($name), ENT_QUOTES
);
74 // Format params to survive being passed through json & the url
75 unset($params['text'], $params['title']);
76 foreach ($params as &$param) {
77 $param = is_bool($param) ||
is_numeric($param) ?
(int) $param : (string) $param;
79 return '<a class="' . $class . '" title="' . $title . '" aria-label="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>';