*
*/
-require_once 'CRM/Core/Smarty/plugins/function.crmAttributes.php';
-
/**
* Generate the html for a button-style link
*
* The generated html.
*/
function smarty_block_crmButton($params, $text, &$smarty) {
- // Generate url (pass 'html' param as false to avoid double-encode by crmAttributes)
+ // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes)
$params['href'] = CRM_Utils_System::crmURL($params + array('h' => FALSE));
// Always add class 'button' - fixme probably should be crm-button
$params['class'] = 'button ' . CRM_Utils_Array::value('class', $params, '');
$icon = CRM_Utils_Array::value('icon', $params, 'pencil');
// All other params are treated as html attributes
CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe');
- $attributes = smarty_function_crmAttributes(array('a' => $params), CRM_Core_DAO::$_nullObject);
- return "<a$attributes><span><span class='icon ui-icon-$icon'></span> $text</span></a>";
+ $attributes = CRM_Utils_String::htmlAttributes($params);
+ return "<a $attributes><span><span class='icon ui-icon-$icon'></span> $text</span></a>";
}
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
- */
+*/
/**
*
* @param CRM_Core_Smarty $smarty
*
* @return string
- * @throws Exception
*/
function smarty_function_crmAttributes($params, &$smarty) {
- $output = '';
$attributes = isset($params['a']) ? $params['a'] : array();
- foreach ($attributes as $name => $vals) {
- $output .= " $name=\"" . htmlspecialchars(implode(' ', (array) $vals)) . '"';
- }
- return $output;
+ return CRM_Utils_String::htmlAttributes($attributes);
}
return str_replace('&', '&', $htmlUrl);
}
+ /**
+ * Formats a string of attributes for insertion in an html tag
+ *
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public static function htmlAttributes($attributes) {
+ $output = '';
+ foreach ($attributes as $name => $vals) {
+ $output .= " $name=\"" . htmlspecialchars(implode(' ', (array) $vals)) . '"';
+ }
+ return ltrim($output);
+ }
+
}