本文整理汇总了PHP中Sanitizer::cleanUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitizer::cleanUrl方法的具体用法?PHP Sanitizer::cleanUrl怎么用?PHP Sanitizer::cleanUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitizer
的用法示例。
在下文中一共展示了Sanitizer::cleanUrl方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHtml
/**
* Builds the HTML code for this component
*
* @return String the HTML code
*/
public function getHtml()
{
$element = $this->getDomElement();
if ($element === null) {
return '';
}
$msgKey = $element->getAttribute('message');
$menuFactory = new MenuFactory();
if (empty($msgKey)) {
$text = $element->textContent;
$menu = $menuFactory->getMenuFromMessageText($text);
} else {
$menu = $menuFactory->getMenuFromMessage($msgKey);
}
$menu->setMenuItemFormatter(function ($href, $text, $depth, $subitems) {
$href = \Sanitizer::cleanUrl($href);
$text = htmlspecialchars($text);
if ($depth === 1 && !empty($subitems)) {
return "<li class=\"dropdown\"><a class=\"dropdown-toggle\" href=\"#\" data-toggle=\"dropdown\">{$text}<b class=\"caret\"></b></a>{$subitems}</li>";
} else {
return "<li><a href=\"{$href}\">{$text}</a>{$subitems}</li>";
}
});
$menu->setItemListFormatter(function ($rawItemsHtml, $depth) {
if ($depth === 0) {
return $rawItemsHtml;
} elseif ($depth === 1) {
return "<ul class=\"dropdown-menu\">{$rawItemsHtml}</ul>";
} else {
return "<ul>{$rawItemsHtml}</ul>";
}
});
return $menu->getHtml();
}
示例2: foreach
}
?>
</tr>
<?php
foreach ($content as $item) {
?>
<tr class="insights-list-item">
<td class="insights-list-item-page insights-list-cell insights-list-first-column">
<a class="insights-list-item-title <?php
echo Sanitizer::encodeAttribute($item['link']['classes']);
?>
" title="<?php
echo Sanitizer::encodeAttribute($item['link']['title']);
?>
" href="<?php
echo Sanitizer::cleanUrl($item['link']['url']);
?>
"><?php
echo Sanitizer::escapeHtmlAllowEntities($item['link']['text']);
?>
</a>
<?php
if (isset($item['metadata'])) {
?>
<p class="insights-list-item-metadata">
<?php
if (isset($item['metadata']['lastRevision'])) {
?>
<?php
echo wfMessage('insights-last-edit')->rawParams(Xml::element('a', ['href' => $item['metadata']['lastRevision']['userpage']], $item['metadata']['lastRevision']['username']), date('F j, Y', $item['metadata']['lastRevision']['timestamp']))->escaped();
?>
示例3: replaceExternalLinks
/**
* Replace external links (REL)
*
* Note: this is all very hackish and the order of execution matters a lot.
* Make sure to run tests/parserTests.php if you change this code.
*
* @private
*
* @param $text string
*
* @throws MWException
* @return string
*/
function replaceExternalLinks($text)
{
wfProfileIn(__METHOD__);
$bits = preg_split($this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
if ($bits === false) {
wfProfileOut(__METHOD__);
throw new MWException("PCRE needs to be compiled with --enable-unicode-properties in order for MediaWiki to function");
}
$s = array_shift($bits);
$i = 0;
while ($i < count($bits)) {
$url = $bits[$i++];
$i++;
// protocol
$text = $bits[$i++];
$trail = $bits[$i++];
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
$m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$text = substr($url, $m2[0][1]) . ' ' . $text;
$url = substr($url, 0, $m2[0][1]);
}
# If the link text is an image URL, replace it with an <img> tag
# This happened by accident in the original parser, but some people used it extensively
$img = $this->maybeMakeExternalImage($text);
if ($img !== false) {
$text = $img;
}
$dtrail = '';
# Set linktype for CSS - if URL==text, link is essentially free
$linktype = $text === $url ? 'free' : 'text';
# No link text, e.g. [http://domain.tld/some.link]
if ($text == '') {
# Autonumber
$langObj = $this->getTargetLanguage();
$text = '[' . $langObj->formatNum(++$this->mAutonumber) . ']';
$linktype = 'autonumber';
} else {
# Have link text, e.g. [http://domain.tld/some.link text]s
# Check for trail
list($dtrail, $trail) = Linker::splitTrail($trail);
}
$text = $this->getConverterLanguage()->markNoConversion($text);
$url = Sanitizer::cleanUrl($url);
# Use the encoded URL
# This means that users can paste URLs directly into the text
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
$s .= Linker::makeExternalLink($url, $text, false, $linktype, $this->getExternalLinkAttribs($url)) . $dtrail . $trail;
# Register link in the output object.
# Replace unnecessary URL escape codes with the referenced character
# This prevents spammers from hiding links from the filters
$pasteurized = self::replaceUnusualEscapes($url);
$this->mOutput->addExternalLink($pasteurized);
}
wfProfileOut(__METHOD__);
return $s;
}
示例4: replaceFreeExternalLinks
/**
* Replace anything that looks like a URL with a link
* @private
*/
function replaceFreeExternalLinks($text)
{
global $wgContLang;
$fname = 'Parser::replaceFreeExternalLinks';
wfProfileIn($fname);
$bits = preg_split('/(\\b(?:' . wfUrlProtocols() . '))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$s = array_shift($bits);
$i = 0;
$sk = $this->mOptions->getSkin();
while ($i < count($bits)) {
$protocol = $bits[$i++];
$remainder = $bits[$i++];
$m = array();
if (preg_match('/^(' . self::EXT_LINK_URL_CLASS . '+)(.*)$/s', $remainder, $m)) {
# Found some characters after the protocol that look promising
$url = $protocol . $m[1];
$trail = $m[2];
# special case: handle urls as url args:
# http://www.example.com/foo?=http://www.example.com/bar
if (strlen($trail) == 0 && isset($bits[$i]) && preg_match('/^' . wfUrlProtocols() . '$/S', $bits[$i]) && preg_match('/^(' . self::EXT_LINK_URL_CLASS . '+)(.*)$/s', $bits[$i + 1], $m)) {
# add protocol, arg
$url .= $bits[$i] . $m[1];
# protocol, url as arg to previous link
$i += 2;
$trail = $m[2];
}
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
$m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$trail = substr($url, $m2[0][1]) . $trail;
$url = substr($url, 0, $m2[0][1]);
}
# Move trailing punctuation to $trail
$sep = ',;\\.:!?';
# If there is no left bracket, then consider right brackets fair game too
if (strpos($url, '(') === false) {
$sep .= ')';
}
$numSepChars = strspn(strrev($url), $sep);
if ($numSepChars) {
$trail = substr($url, -$numSepChars) . $trail;
$url = substr($url, 0, -$numSepChars);
}
$url = Sanitizer::cleanUrl($url);
# Is this an external image?
$text = $this->maybeMakeExternalImage($url);
if ($text === false) {
# Not an image, make a link
$text = $sk->makeExternalLink($url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace());
# Register it in the output object...
# Replace unnecessary URL escape codes with their equivalent characters
$pasteurized = Parser::replaceUnusualEscapes($url);
$this->mOutput->addExternalLink($pasteurized);
}
$s .= $text . $trail;
} else {
$s .= $protocol . $remainder;
}
}
wfProfileOut($fname);
return $s;
}
示例5: replaceExternalLinks
/**
* Replace external links (REL)
*
* Note: this is all very hackish and the order of execution matters a lot.
* Make sure to run maintenance/parserTests.php if you change this code.
*
* @private
*
* @param $text string
*
* @return string
*/
function replaceExternalLinks($text)
{
wfProfileIn(__METHOD__);
$bits = preg_split($this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$s = array_shift($bits);
$i = 0;
while ($i < count($bits)) {
$url = $bits[$i++];
$protocol = $bits[$i++];
$text = $bits[$i++];
$trail = $bits[$i++];
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
$m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$text = substr($url, $m2[0][1]) . ' ' . $text;
$url = substr($url, 0, $m2[0][1]);
}
# If the link text is an image URL, replace it with an <img> tag
# This happened by accident in the original parser, but some people used it extensively
$img = $this->maybeMakeExternalImage($text);
if ($img !== false) {
$text = $img;
}
$dtrail = '';
# Set linktype for CSS - if URL==text, link is essentially free
$linktype = $text === $url ? 'free' : 'text';
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński
global $wgRTEParserEnabled;
if (!empty($wgRTEParserEnabled)) {
$RTE_wikitextIdx = RTEMarker::getDataIdx(RTEMarker::EXTERNAL_WIKITEXT, $trail);
$wasblank = $text == '';
}
# RTE - end
# No link text, e.g. [http://domain.tld/some.link]
if ($text == '') {
# Autonumber
$langObj = $this->getTargetLanguage();
$text = '[' . $langObj->formatNum(++$this->mAutonumber) . ']';
$linktype = 'autonumber';
} else {
# Have link text, e.g. [http://domain.tld/some.link text]s
# Check for trail
list($dtrail, $trail) = Linker::splitTrail($trail);
}
$text = $this->getConverterLanguage()->markNoConversion($text);
$url = Sanitizer::cleanUrl($url);
# Use the encoded URL
# This means that users can paste URLs directly into the text
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński
if (!empty($wgRTEParserEnabled)) {
$text = RTEMarker::generate(RTEMarker::EXTERNAL_DATA, RTEData::put('data', array('type' => 'external', 'wikitextIdx' => $RTE_wikitextIdx, 'text' => $text, 'link' => $url, 'linktype' => $linktype, 'wasblank' => $wasblank))) . $text;
}
# RTE - end
$s .= Linker::makeExternalLink($url, $text, false, $linktype, $this->getExternalLinkAttribs($url)) . $dtrail . $trail;
# Register link in the output object.
# Replace unnecessary URL escape codes with the referenced character
# This prevents spammers from hiding links from the filters
$pasteurized = self::replaceUnusualEscapes($url);
$this->mOutput->addExternalLink($pasteurized);
}
wfProfileOut(__METHOD__);
return $s;
}
示例6: replaceExternalLinks
/**
* Replace external links (REL)
*
* Note: this is all very hackish and the order of execution matters a lot.
* Make sure to run maintenance/parserTests.php if you change this code.
*
* @private
*/
function replaceExternalLinks($text)
{
global $wgContLang;
wfProfileIn(__METHOD__);
$sk = $this->mOptions->getSkin();
$bits = preg_split($this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$s = array_shift($bits);
$i = 0;
while ($i < count($bits)) {
$url = $bits[$i++];
$protocol = $bits[$i++];
$text = $bits[$i++];
$trail = $bits[$i++];
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
$m2 = array();
if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
$text = substr($url, $m2[0][1]) . ' ' . $text;
$url = substr($url, 0, $m2[0][1]);
}
# If the link text is an image URL, replace it with an <img> tag
# This happened by accident in the original parser, but some people used it extensively
$img = $this->maybeMakeExternalImage($text);
if ($img !== false) {
$text = $img;
}
$dtrail = '';
# Set linktype for CSS - if URL==text, link is essentially free
$linktype = $text === $url ? 'free' : 'text';
# No link text, e.g. [http://domain.tld/some.link]
if ($text == '') {
# Autonumber if allowed. See bug #5918
if (strpos(wfUrlProtocols(), substr($protocol, 0, strpos($protocol, ':'))) !== false) {
$langObj = $this->getFunctionLang();
$text = '[' . $langObj->formatNum(++$this->mAutonumber) . ']';
$linktype = 'autonumber';
} else {
# Otherwise just use the URL
$text = htmlspecialchars($url);
$linktype = 'free';
}
} else {
# Have link text, e.g. [http://domain.tld/some.link text]s
# Check for trail
list($dtrail, $trail) = Linker::splitTrail($trail);
}
$text = $wgContLang->markNoConversion($text);
$url = Sanitizer::cleanUrl($url);
if ($this->mOptions->mExternalLinkTarget) {
$attribs = array('target' => $this->mOptions->mExternalLinkTarget);
} else {
$attribs = array();
}
# Use the encoded URL
# This means that users can paste URLs directly into the text
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
$s .= $sk->makeExternalLink($url, $text, false, $linktype, $this->getExternalLinkAttribs()) . $dtrail . $trail;
# Register link in the output object.
# Replace unnecessary URL escape codes with the referenced character
# This prevents spammers from hiding links from the filters
$pasteurized = self::replaceUnusualEscapes($url);
$this->mOutput->addExternalLink($pasteurized);
}
wfProfileOut(__METHOD__);
return $s;
}
示例7: foreach
</th>
</tr>
<?php
foreach ($flagTypes as $flagTypeId => $flag) {
?>
<?php
$title = Title::newFromText($flag['flag_view'], NS_TEMPLATE);
?>
<tr class="flags-special-list-item">
<td class="flags-special-list-item-name"><?php
echo $flag['flag_name'];
?>
</td>
<td class="flags-special-list-item-template">
<a class="flags-special-list-item-template-link" href="<?php
echo Sanitizer::cleanUrl($title->getFullURL());
?>
" target="_blank">
<?php
echo $flag['flag_view'];
?>
</a>
</td>
<td class="flags-special-list-item-params">
<?php
$paramsNames = json_decode($flag['flag_params_names'], true);
if (is_array($paramsNames)) {
?>
<?php
foreach ($paramsNames as $name => $description) {
?>