Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Adds inline help | |
38 | * | |
6a0b768e TO |
39 | * @param array $params |
40 | * The function params. | |
16b10e64 | 41 | * @param CRM_Core_Smarty $smarty |
6a0b768e | 42 | * Reference to the smarty object. |
6a488035 | 43 | * |
a6c01b45 | 44 | * @return string |
353ffa53 | 45 | * the help html to be inserted |
6a488035 TO |
46 | */ |
47 | function smarty_function_help($params, &$smarty) { | |
48 | if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { | |
a1a2a83d | 49 | return NULL; |
6a488035 TO |
50 | } |
51 | ||
6a488035 TO |
52 | if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) { |
53 | $params['file'] = $smarty->_tpl_vars['tplFile']; | |
54 | } | |
55 | elseif (empty($params['file'])) { | |
6eea17da | 56 | return NULL; |
6a488035 TO |
57 | } |
58 | ||
59 | $params['file'] = str_replace(array('.tpl', '.hlp'), '', $params['file']); | |
60 | ||
61 | if (empty($params['title'])) { | |
6441e8d7 | 62 | $vars = $smarty->get_template_vars(); |
6a488035 TO |
63 | $smarty->assign('id', $params['id'] . '-title'); |
64 | $name = trim($smarty->fetch($params['file'] . '.hlp')); | |
6eea17da E |
65 | $additionalTPLFile = $params['file'] . '.extra.hlp'; |
66 | if ($smarty->template_exists($additionalTPLFile)) { | |
67 | $name .= trim($smarty->fetch($additionalTPLFile)); | |
68 | } | |
6441e8d7 CW |
69 | // Ensure we didn't change any existing vars CRM-11900 |
70 | foreach ($vars as $key => $value) { | |
71 | if ($smarty->get_template_vars($key) !== $value) { | |
72 | $smarty->assign($key, $value); | |
73 | } | |
74 | } | |
6a488035 TO |
75 | } |
76 | else { | |
77 | $name = trim(strip_tags($params['title'])); | |
78 | } | |
6eea17da | 79 | |
1bf65b67 | 80 | $class = "helpicon"; |
81 | if (!empty($params['class'])) { | |
82 | $class .= " {$params['class']}"; | |
83 | } | |
84 | ||
4bc223d1 CW |
85 | // Escape for html |
86 | $title = htmlspecialchars(ts('%1 Help', array(1 => $name))); | |
87 | // Escape for html and js | |
88 | $name = htmlspecialchars(json_encode($name), ENT_QUOTES); | |
89 | ||
6a488035 | 90 | // Format params to survive being passed through json & the url |
4bc223d1 | 91 | unset($params['text'], $params['title']); |
6a488035 TO |
92 | foreach ($params as &$param) { |
93 | $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param; | |
94 | } | |
1bf65b67 | 95 | return '<a class="' . $class . '" title="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>'; |
6a488035 | 96 | } |