Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Adds inline help | |
38 | * | |
39 | * @param array $params the function params | |
40 | * @param object $smarty reference to the smarty object | |
41 | * | |
42 | * @return string the help html to be inserted | |
43 | * @access public | |
44 | */ | |
45 | function smarty_function_help($params, &$smarty) { | |
46 | if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { | |
47 | return; | |
48 | } | |
49 | ||
6a488035 TO |
50 | if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) { |
51 | $params['file'] = $smarty->_tpl_vars['tplFile']; | |
52 | } | |
53 | elseif (empty($params['file'])) { | |
54 | return $help; | |
55 | } | |
56 | ||
57 | $params['file'] = str_replace(array('.tpl', '.hlp'), '', $params['file']); | |
58 | ||
59 | if (empty($params['title'])) { | |
60 | // Avod overwriting existing vars CRM-11900 | |
61 | $oldID = $smarty->get_template_vars('id'); | |
62 | $smarty->assign('id', $params['id'] . '-title'); | |
63 | $name = trim($smarty->fetch($params['file'] . '.hlp')); | |
64 | $smarty->assign('id', $oldID); | |
65 | } | |
66 | else { | |
67 | $name = trim(strip_tags($params['title'])); | |
68 | } | |
4bc223d1 CW |
69 | // Escape for html |
70 | $title = htmlspecialchars(ts('%1 Help', array(1 => $name))); | |
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 | } | |
4bc223d1 | 79 | return '<a class="helpicon" title="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>'; |
6a488035 | 80 | } |