本文整理汇总了PHP中CM_Util::htmlspecialchars方法的典型用法代码示例。如果您正苦于以下问题:PHP CM_Util::htmlspecialchars方法的具体用法?PHP CM_Util::htmlspecialchars怎么用?PHP CM_Util::htmlspecialchars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CM_Util
的用法示例。
在下文中一共展示了CM_Util::htmlspecialchars方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderTag
/**
* @param string $elementName
* @param string|null $content
* @param array|null $attributes
* @param array|null $dataAttributes
* @return string
* @throws CM_Exception_Invalid
*/
public function renderTag($elementName, $content = null, array $attributes = null, array $dataAttributes = null)
{
$elementName = (string) $elementName;
if ('' === $elementName) {
throw new CM_Exception_Invalid('Empty element name');
}
$content = (string) $content;
if (null === $attributes) {
$attributes = [];
}
if (null === $dataAttributes) {
$dataAttributes = [];
}
// http://www.w3.org/TR/html-markup/syntax.html#void-element
$namesVoid = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
$html = '<' . $elementName;
foreach ($dataAttributes as $dataKey => $dataValue) {
$attributes['data-' . $dataKey] = $dataValue;
}
foreach ($attributes as $attributeName => $attributeValue) {
if (isset($attributeValue)) {
$html .= ' ' . CM_Util::htmlspecialchars($attributeName) . '="' . CM_Util::htmlspecialchars($attributeValue) . '"';
}
}
if (in_array($elementName, $namesVoid)) {
$html .= '>';
} else {
$html .= '>' . $content . '</' . $elementName . '>';
}
return $html;
}
示例2: smarty_function_tag
function smarty_function_tag(array $params, Smarty_Internal_Template $template)
{
if (!isset($params['el'])) {
trigger_error('Param `el` missing.');
}
$name = $params['el'];
unset($params['el']);
$content = '';
if (isset($params['content'])) {
$content = (string) $params['content'];
unset($params['content']);
}
$attributes = $params;
// http://www.w3.org/TR/html-markup/syntax.html#void-element
$namesVoid = array('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr');
$html = '<' . $name;
foreach ($attributes as $attributeName => $attributeValue) {
if (isset($attributeValue)) {
$html .= ' ' . $attributeName . '="' . CM_Util::htmlspecialchars($attributeValue) . '"';
}
}
if (in_array($name, $namesVoid)) {
$html .= '>';
} else {
$html .= '>' . $content . '</' . $name . '>';
}
return $html;
}
示例3: getHtml
public function getHtml($zoneName, $zoneData, array $variables)
{
$zoneId = CM_Util::htmlspecialchars($zoneData['zoneId']);
$variables = $this->_variableKeysToUnderscore($variables);
$variables['key'] = $zoneData['accessKey'];
$html = '<div id="epom-' . $zoneId . '" class="epom-ad" data-zone-name="' . $zoneName . '" data-variables="' . CM_Util::htmlspecialchars(json_encode($variables, JSON_FORCE_OBJECT)) . '"></div>';
return $html;
}
示例4: getHtml
public function getHtml($zoneName, $zoneData, array $variables)
{
$src = (string) $zoneData['src'];
$width = (string) $zoneData['width'];
$height = (string) $zoneData['height'];
$params = ['src' => $src, 'width' => $width, 'height' => $height, 'class' => 'advertisement-hasContent', 'data-variables' => json_encode($variables, JSON_FORCE_OBJECT), 'frameborder' => 0, 'scrolling' => 'no'];
$params = Functional\map($params, function ($value, $key) {
return $key . '="' . CM_Util::htmlspecialchars($value) . '"';
});
return '<iframe ' . join(' ', $params) . '></iframe>';
}
示例5: smarty_function_locationFlag
function smarty_function_locationFlag(array $params, Smarty_Internal_Template $template)
{
/** @var CM_Frontend_Render $render */
$render = $template->smarty->getTemplateVars('render');
/** @var CM_Model_Location $location */
$location = $params['location'];
$html = '';
if ($abbreviation = $location->getAbbreviation(CM_Model_Location::LEVEL_COUNTRY)) {
$flagUrl = $render->getUrlResource('layout', 'img/flags/' . strtolower($abbreviation) . '.png');
$name = $location->getName(CM_Model_Location::LEVEL_COUNTRY);
$html .= '<img class="flag" src="' . $flagUrl . '" title="' . CM_Util::htmlspecialchars($name) . '" />';
}
return $html;
}
示例6: smarty_function_img
function smarty_function_img(array $params, Smarty_Internal_Template $template)
{
/** @var CM_Frontend_Render $render */
$render = $template->smarty->getTemplateVars('render');
$path = $params['path'];
$params = array_merge(['width' => null, 'height' => null, 'title' => null, 'class' => null, 'site' => null], $params);
if (preg_match('#(^/|://)#', $path)) {
$url = $path;
} elseif (!empty($params['static'])) {
$url = $render->getUrlStatic('/img/' . $path, $params['site']);
} else {
$url = $render->getUrlResource('layout', 'img/' . $path, null, $params['site']);
}
$html = '<img src="' . $url . '"';
if (isset($params['background-image'])) {
$backgroundImage = (string) $params['background-image'];
if (preg_match('#(^/|://|^data:)#', $backgroundImage)) {
$backgroundImageUrl = $backgroundImage;
} elseif (!empty($params['static'])) {
$backgroundImageUrl = $render->getUrlStatic('/img/' . $backgroundImage, $params['site']);
} else {
$backgroundImageUrl = $render->getUrlResource('layout', 'img/' . $backgroundImage, null, $params['site']);
}
$html .= ' style="background-image: url(' . CM_Util::htmlspecialchars($backgroundImageUrl) . ')"';
$params['class'] = (string) $params['class'];
if ('' !== $params['class']) {
$params['class'] .= ' ';
}
$params['class'] .= 'background-cover';
}
if ($params['class']) {
$html .= ' class="' . $params['class'] . '"';
}
if ($params['title']) {
$html .= ' title="' . $params['title'] . '" alt="' . $params['title'] . '"';
}
if ($params['width']) {
$html .= ' width="' . $params['width'] . '"';
}
if ($params['height']) {
$html .= ' height="' . $params['height'] . '"';
}
$html .= ' />';
return $html;
}
示例7: smarty_function_gravatar
function smarty_function_gravatar(array $params)
{
$url = smarty_function_gravatarUrl($params);
$html = '<img src="' . CM_Util::htmlspecialchars($url) . '"';
if (!empty($params['class'])) {
$html .= ' class="' . CM_Util::htmlspecialchars($params['class']) . '"';
}
if (!empty($params['title'])) {
$html .= ' title="' . CM_Util::htmlspecialchars($params['title']) . '" alt="' . CM_Util::htmlspecialchars($params['title']) . '"';
}
if (!empty($params['width'])) {
$html .= ' width="' . CM_Util::htmlspecialchars($params['width']) . '"';
}
if (!empty($params['height'])) {
$html .= ' height="' . CM_Util::htmlspecialchars($params['height']) . '"';
}
$html .= ' />';
return $html;
}
示例8: smarty_function_checkbox
function smarty_function_checkbox(array $params, Smarty_Internal_Template $template)
{
$isSwitch = isset($params['isSwitch']) ? (bool) $params['isSwitch'] : false;
$checked = isset($params['checked']) ? (bool) $params['checked'] : false;
$id = isset($params['id']) ? (string) $params['id'] : null;
$label = (string) $params['label'];
$name = isset($params['name']) ? (string) $params['name'] : null;
$tabindex = isset($params['tabindex']) ? (int) $params['tabindex'] : null;
$value = isset($params['value']) ? (string) $params['value'] : null;
$classList = [];
if (isset($params['class'])) {
$classList[] = (string) $params['class'];
}
if ($isSwitch) {
$classList[] = 'checkbox-switch';
}
$data = [];
if (isset($params['data'])) {
$data = (array) $params['data'];
unset($params['data']);
}
if (null === $id) {
$id = uniqid();
}
$attributeList = ['el' => 'input', 'type' => 'checkbox', 'id' => $id, 'class' => !empty($classList) ? implode(' ', $classList) : null, 'checked' => $checked ? 'checked' : null, 'name' => $name, 'tabindex' => $tabindex, 'value' => $value];
if (!empty($data)) {
foreach ($data as $name => $value) {
$attributeList['data-' . $name] = CM_Util::htmlspecialchars($value);
}
}
$html = smarty_function_tag($attributeList, $template);
$htmlLabelContent = '';
if ($isSwitch) {
$htmlLabelContent .= smarty_function_tag(['el' => 'span', 'class' => 'handle'], $template);
}
$htmlLabelContent .= smarty_function_tag(['el' => 'span', 'content' => $label, 'class' => 'label'], $template);
$html .= smarty_function_tag(['el' => 'label', 'content' => $htmlLabelContent, 'for' => $id], $template);
return $html;
}
示例9: smarty_function_button
function smarty_function_button(array $params, Smarty_Internal_Template $template)
{
/** @var CM_Frontend_Render $render */
$render = $template->smarty->getTemplateVars('render');
$viewResponse = $render->getGlobalResponse()->getClosestViewResponse('CM_Form_Abstract');
if (null === $viewResponse) {
throw new CM_Exception_Invalid('Cannot find parent `CM_Form_Abstract` view response. {button} can be only rendered within form view.');
}
/** @var CM_Form_Abstract $form */
$form = $viewResponse->getView();
if (empty($params['action'])) {
trigger_error('Param `action` missing.');
}
$action = $form->getAction($params['action']);
$title = isset($params['title']) ? (string) $params['title'] : null;
$theme = isset($params['theme']) ? (string) $params['theme'] : 'default';
$isHtmlLabel = isset($params['isHtmlLabel']) ? (bool) $params['isHtmlLabel'] : false;
$class = 'button ' . 'button-' . $theme;
if (isset($params['class'])) {
$class .= ' ' . trim($params['class']);
}
$data = array();
if (isset($params['data'])) {
$data = $params['data'];
unset($params['data']);
}
if (isset($params['event'])) {
$data['event'] = (string) $params['event'];
unset($params['event']);
}
$icon = null;
$iconConfirm = null;
if (isset($params['icon'])) {
$icon = $params['icon'];
if (isset($params['iconConfirm'])) {
$iconConfirm = $params['iconConfirm'];
}
}
$label = '';
if (isset($params['label'])) {
$label = $isHtmlLabel ? $params['label'] : CM_Util::htmlspecialchars($params['label']);
}
if ($label) {
$class .= ' hasLabel';
}
if ($icon) {
$class .= ' hasIcon';
}
if ($title) {
$class .= ' showTooltip';
}
$id = $viewResponse->getAutoId() . '-' . $action->getName() . '-button';
$html = '';
$html .= '<button class="' . $class . '" id="' . $id . '" type="submit" value="' . $label . '" data-click-spinner="true"';
if ($title) {
$html .= ' title="' . $title . '"';
}
if (!empty($data)) {
foreach ($data as $name => $value) {
$html .= ' data-' . $name . '="' . CM_Util::htmlspecialchars($value) . '"';
}
}
$html .= '>';
if ($icon) {
if ($iconConfirm) {
$html .= '<span class="icon icon-' . $icon . ' confirmClick-state-inactive"></span>' . '<span class="icon icon-' . $iconConfirm . ' confirmClick-state-active"></span>';
} else {
$html .= '<span class="icon icon-' . $icon . '"></span>';
}
}
if ($label) {
$html .= '<span class="label">' . $label . '</span>';
}
$html .= '</button>';
return $html;
}
示例10: smarty_function_link
function smarty_function_link(array $params, Smarty_Internal_Template $template)
{
$label = '';
if (isset($params['label'])) {
$label = $params['label'];
}
unset($params['label']);
$class = 'link';
if (isset($params['class'])) {
$class .= ' ' . $params['class'];
}
unset($params['class']);
$title = null;
if (isset($params['title'])) {
$title = $params['title'];
}
unset($params['title']);
$icon = null;
if (isset($params['icon'])) {
$icon = $params['icon'];
}
unset($params['icon']);
$iconPosition = 'left';
if (isset($params['iconPosition']) && $params['iconPosition'] === 'right') {
$iconPosition = 'right';
}
unset($params['iconPosition']);
$data = array();
if (isset($params['data'])) {
$data = (array) $params['data'];
}
unset($params['data']);
$onclick = null;
if (isset($params['onclick'])) {
$onclick = $params['onclick'];
}
unset($params['onclick']);
$href = 'javascript:;';
if (isset($params['href'])) {
$href = (string) $params['href'];
}
unset($params['href']);
$target = null;
if (isset($params['target'])) {
$target = (string) $params['target'];
}
unset($params['target']);
if (isset($params['page'])) {
$href = smarty_function_linkUrl($params, $template);
}
if (empty($label) && empty($icon) && empty($title) && 0 !== strpos($href, 'javascript:')) {
$label = $href;
}
$iconMarkup = null;
if (null !== $icon) {
$iconMarkup = '<span class="icon icon-' . $icon . '"></span>';
}
$html = '';
if (null !== $iconMarkup && 'left' === $iconPosition) {
$html .= $iconMarkup;
$class .= ' hasIcon';
}
if (!empty($label)) {
$html .= '<span class="label">' . CM_Util::htmlspecialchars($label) . '</span>';
$class .= ' hasLabel';
}
if (null !== $iconMarkup && 'right' === $iconPosition) {
$html .= $iconMarkup;
$class .= ' hasIconRight';
}
$attributeList = ['el' => 'a', 'content' => $html, 'href' => $href, 'class' => $class, 'title' => $title, 'onclick' => $onclick, 'target' => $target];
foreach ($data as $name => $value) {
$attributeList['data-' . $name] = $value;
}
return smarty_function_tag($attributeList, $template);
}
示例11: smarty_function_select
function smarty_function_select(array $params, Smarty_Internal_Template $template)
{
/** @var CM_Frontend_Render $render */
$render = $template->smarty->getTemplateVars('render');
$htmlAttributes = array('id', 'name', 'class');
$optionList = array();
if (isset($params['optionList'])) {
$optionList = $params['optionList'];
}
$selectedValue = null;
if (isset($params['selectedValue']) && isset($optionList[$params['selectedValue']])) {
$selectedValue = $params['selectedValue'];
}
$translate = !empty($params['translate']);
$translatePrefix = '';
if (isset($params['translatePrefix'])) {
$translatePrefix = (string) $params['translatePrefix'];
}
$placeholder = null;
if (isset($params['placeholder']) && is_string($params['placeholder'])) {
$placeholder = $params['placeholder'];
} elseif (!empty($params['placeholder'])) {
$placeholder = ' -' . $render->getTranslation('Select') . '- ';
}
$labelPrefix = null;
if (isset($params['labelPrefix'])) {
$labelPrefix = (string) $params['labelPrefix'];
}
foreach ($optionList as $itemValue => $itemLabel) {
if ($translate) {
$optionList[$itemValue] = $render->getTranslation($translatePrefix . $itemLabel, array());
} else {
$optionList[$itemValue] = CM_Util::htmlspecialchars($itemLabel);
}
}
if (null !== $placeholder) {
$optionList = array(null => $placeholder) + $optionList;
}
$html = '';
$html .= '<select';
foreach ($htmlAttributes as $name) {
if (isset($params[$name])) {
$html .= ' ' . $name . '="' . CM_Util::htmlspecialchars($params[$name]) . '"';
}
}
$html .= '>';
$selectedLabel = '';
if (null === $selectedValue && count($optionList) > 0) {
$optionListValues = array_keys($optionList);
$selectedValue = reset($optionListValues);
}
if (null !== $selectedValue) {
$selectedValue = (string) $selectedValue;
}
foreach ($optionList as $itemValue => $itemLabel) {
if (null !== $itemValue) {
$itemValue = (string) $itemValue;
}
$html .= '<option value="' . CM_Util::htmlspecialchars($itemValue) . '"';
if ($itemValue === $selectedValue) {
$html .= ' selected';
$selectedLabel = $itemLabel;
}
$html .= '>' . $itemLabel . '</option>';
}
$html .= '</select>';
$html .= '<div class="fancySelect-select nowrap">';
if ($labelPrefix) {
$html .= '<span class="labelPrefix">' . CM_Util::htmlspecialchars($labelPrefix) . '</span>';
}
$html .= '<span class="label">' . $selectedLabel . '</span><span class="icon icon-select"></span>';
$html .= '</div>';
return '<div class="fancySelect">' . $html . '</div>';
}
示例12: smarty_function_button_link
function smarty_function_button_link(array $params, Smarty_Internal_Template $template)
{
$isHtmlLabel = isset($params['isHtmlLabel']) ? (bool) $params['isHtmlLabel'] : false;
$label = '';
if (isset($params['label'])) {
$label = $isHtmlLabel ? $params['label'] : CM_Util::htmlspecialchars($params['label']);
unset($params['label']);
}
$attrs = '';
$icon = null;
$iconConfirm = null;
if (isset($params['icon'])) {
$icon = $params['icon'];
if (isset($params['iconConfirm'])) {
$iconConfirm = $params['iconConfirm'];
}
}
unset($params['icon']);
unset($params['iconConfirm']);
$iconPosition = 'left';
if (!empty($params['iconPosition']) && $params['iconPosition'] == 'right') {
$iconPosition = 'right';
}
unset($params['iconPosition']);
$title = null;
if (isset($params['title'])) {
$title = (string) $params['title'];
$attrs .= ' title="' . CM_Util::htmlspecialchars($title) . '"';
}
unset($params['title']);
if (isset($params['id'])) {
$attrs .= ' id="' . $params['id'] . '"';
}
unset($params['id']);
$theme = isset($params['theme']) ? (string) $params['theme'] : 'default';
$class = 'button ' . 'button-' . $theme . ' clickFeedback' . ' ';
if (isset($params['class'])) {
$class .= $params['class'];
}
unset($params['theme']);
unset($params['class']);
if ($label) {
$class .= ' hasLabel';
}
$iconMarkup = '';
if ($icon) {
if ($iconConfirm) {
$iconMarkup = '<span class="icon icon-' . $icon . ' confirmClick-state-inactive"></span>' . '<span class="icon icon-' . $iconConfirm . ' confirmClick-state-active"></span>';
} else {
$iconMarkup = '<span class="icon icon-' . $icon . '"></span>';
}
if ($iconPosition == 'right') {
$class .= ' hasIconRight';
} else {
$class .= ' hasIcon';
}
}
$onclick = false;
if (isset($params['onclick'])) {
$onclick = $params['onclick'];
unset($params['onclick']);
}
if (isset($params['page'])) {
$onclick .= ' cm.router.route(\'' . smarty_function_linkUrl($params, $template) . '\');';
}
if ($onclick) {
$attrs .= ' onclick="' . CM_Util::htmlspecialchars($onclick) . '"';
}
if (isset($params['data'])) {
foreach ($params['data'] as $name => $value) {
$attrs .= ' data-' . $name . '="' . CM_Util::htmlspecialchars($value) . '"';
}
}
$html = '';
$html .= '<button class="' . $class . '" type="button" value="' . $label . '" ' . $attrs . '>';
if ($icon && $iconPosition == 'left') {
$html .= $iconMarkup;
}
if ($label) {
$html .= '<span class="label">' . $label . '</span>';
}
if ($icon && $iconPosition == 'right') {
$html .= $iconMarkup;
}
$html .= '</button>';
return $html;
}
示例13: _getTrackingImageTag
/**
* @param CM_Mail_Mailable $mail
* @return string
*/
protected function _getTrackingImageTag(CM_Mail_Mailable $mail)
{
return '<img src="' . CM_Util::htmlspecialchars($this->getRender()->getUrlEmailTracking($mail)) . '" width="1" height="1" />';
}