本文整理汇总了PHP中DataValidator::checkUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP DataValidator::checkUrl方法的具体用法?PHP DataValidator::checkUrl怎么用?PHP DataValidator::checkUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataValidator
的用法示例。
在下文中一共展示了DataValidator::checkUrl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkMovie
/**
* Parsuje YOUTUBE
* @param array $tag wszystkie informacje o tagu
* @param array $openNode tag otwierajacy
* @param array $body zawertosc pomiedzy tagiem otwierajacym a zamykajacym
* @param array $closeNode tak zamykajacy
* @param BbCodeSettings $settings
*/
public function checkMovie($tag, &$openNode, &$body, &$closeNode, $settings)
{
require_once dirname(__FILE__) . '/../DataValidator.php';
// wyciagamy caly tekst
$bodyStr = '';
foreach ($body as &$el) {
$bodyStr .= $el['text'];
// wersja do wyswietlenia
$el['text'] = '';
}
// sprawdzamy czy ciag jest urlem
$str = DataValidator::checkUrl($bodyStr);
// skoro nie jest urlem wiec ISTNIEJE prawdopodobienstwo, ze jest to id filmu
if ($str == false) {
$idMovie = htmlspecialchars($bodyStr);
} elseif (preg_match('/watch\\?v=([a-zA-Z0-9_\\-]+)/i', $str, $matches)) {
// szukanie id filmu
$idMovie = $matches[1];
} else {
// nie ma id wiec lipa
$openNode = $settings->removeNode($openNode);
$closeNode = $settings->removeNode($closeNode);
return false;
}
// zamkniecie nie jest nam potrzebne
$closeNode['text'] = '';
// Ustawiamy content
$openNode['text'] = '<iframe title="YouTube video player" width="560" height="349"
src="http://www.youtube.com/embed/' . $idMovie . '?rel=0" frameborder="0">
</iframe>
';
//ustawiamy link dla zaufanego bbcode
reset($body);
$body[key($body)]['tagText'] = $str;
}
示例2: checkImg
/**
* Parsuje IMG
* @param array $tag
* @param array $openNode
* @param array $body
* @param array $cNode
* @param BbCodeSettings $settings
*/
public function checkImg($tag, &$openNode, &$body, &$cNode, $settings)
{
require_once dirname(__FILE__) . '/../DataValidator.php';
$src = '';
if (isset($openNode['attributes']['tag_attributes']['img'])) {
$src = DataValidator::checkUrl($openNode['attributes']['tag_attributes']['img']);
}
$bodyStr = '';
foreach ($body as $el) {
$bodyStr .= $el['text'];
}
$bodyUrl = DataValidator::checkUrl($bodyStr);
if ($bodyUrl) {
$src = $bodyUrl;
} else {
if ($bodyStr) {
$openNode['attributes']['tag_attributes']['alt'] = $bodyStr;
}
}
if ($src == false) {
$openNode = $settings->removeNode($openNode, $settings->removeInvalidTags);
$cNode = $settings->removeNode($cNode, $settings->removeInvalidTags);
return false;
}
$openNode['attributes']['tag_attributes']['src'] = $src;
unset($el);
if (isset($openNode['attributes']['tag_attributes']['img'])) {
$tagSizes = explode('x', $openNode['attributes']['tag_attributes']['img']);
if (is_array($tagSizes)) {
$tagSizes = array_map('trim', $tagSizes);
if (isset($tagSizes[0]) && is_numeric($tagSizes[0])) {
$openNode['attributes']['tag_attributes']['width'] = round($tagSizes[0]);
}
if (isset($tagSizes[1]) && is_numeric($tagSizes[1])) {
$openNode['attributes']['tag_attributes']['height'] = round($tagSizes[1]);
}
}
}
// wlaczona kontrola wielkosci zdjecia i czy zawsze mozemy taką kontrolę przeprowadzic
if ($this->imageMaxWidth > 0 || $this->imageMaxHeight > 0 || $this->imageMinHeight > 0 || $this->imageMinHeight > 0) {
if (ini_get('allow_url_fopen') && $this->checkRealImageSize) {
// ustawienie maksymalnego czasu pobierania info o zdjeciu
$oldDefaultSocketTimeout = ini_get('default_socket_timeout');
$socketTimeout = 5;
if (isset($this->socketTimeout) && $this->socketTimeout >= 0) {
$socketTimeout = $this->socketTimeout;
}
ini_set('default_socket_timeout', $socketTimeout);
$size = @getimagesize($openNode['attributes']['tag_attributes']['src']);
// z roznych przyczyn nie udalo sie pobrac zdjecia badz nie jest on plikiem graficznym
if (!$size) {
$openNode = $settings->removeNode($openNode);
$cNode = $settings->removeNode($cNode);
$openNode['text'] = '[Nieprawidłowe zdjęcie]';
return false;
}
} elseif (isset($openNode['attributes']['tag_attributes']['width']) || isset($openNode['attributes']['tag_attributes']['height'])) {
$size = array();
$size[0] = isset($openNode['attributes']['tag_attributes']['width']) ? $openNode['attributes']['tag_attributes']['width'] : false;
$size[1] = isset($openNode['attributes']['tag_attributes']['height']) ? $openNode['attributes']['tag_attributes']['height'] : false;
if ($size[0] === false && $size[1] === false) {
$size = false;
}
}
if (isset($size) && $size) {
//pomocnicze zachowanie wymiarow
$mainWidth = $size[0];
$mainHeight = $size[1];
$width = isset($openNode['attributes']['tag_attributes']['width']) ? $openNode['attributes']['tag_attributes']['width'] : $size[0];
$height = isset($openNode['attributes']['tag_attributes']['height']) ? $openNode['attributes']['tag_attributes']['height'] : $size[1];
// szerokosc
if ($this->imageMaxWidth > 0 && $width > $this->imageMaxWidth) {
$width = $this->imageMaxWidth;
$height = $this->imageMaxWidth * $height / $width;
}
// wysokosc
if ($this->imageMaxHeight > 0 && $height > $this->imageMaxHeight) {
$height = $this->imageMaxHeight;
$width = $this->imageMaxHeight * $width / $height;
}
$width = round($width);
$height = round($height);
if ($this->imageMinWidth > 0 && $this->imageMinWidth > $width) {
$width = $this->imageMinWidth;
}
if ($this->imageMinHeight > 0 && $this->imageMinHeight > $height) {
$height = $this->imageMinHeight;
}
if ($width != $mainWidth) {
$openNode['attributes']['tag_attributes']['width'] = $width;
}
if ($height != $mainHeight) {
//.........这里部分代码省略.........
示例3: _parseAttributes
/**
* Sprawdza i buduję listę parametrów taga na podstawie podanego tekstu
* @param array $tagInfo tablica ustawień taga wyciągnięta z filtra bądź z {@link $tags}
* @param string $text tekst z którego należy wyciągnąć atrybuty
* @return mixed - false w przypadku braku atrybutów, -1 w przypadku brak wymaganych atrybutów, tablica parametrów w przypadku prawidłowego odczytania parametrów
*/
private function _parseAttributes($tagInfo, $text)
{
$attr = $tagInfo['attributes'];
// ustawienia atrybutów taga
$tagAttributes = array();
// atrybuty taga
$text = substr($text, 1, -1);
preg_match_all('/\\s*([a-z0-9-_]+)=(\'.+?\'|".+?"|\\S*)\\s*/i', $text, $matches, PREG_SET_ORDER);
if (count($matches) == 0) {
// nie ma wymaganego argumentu
if (isset($tagInfo['required_attributes'])) {
return -1;
} elseif (isset($tagInfo['default_attributes'])) {
foreach ($tagInfo['default_attributes'] as $attrName) {
$attrOptions = $tagInfo['attributes'][$attrName];
$this->_parseDefaultAttribute($attrName, $attrOptions, 'no_enter', $tagAttributes);
}
return $tagAttributes;
} else {
return false;
}
}
foreach ($matches as $attribute) {
$tagAttr = strtolower($attribute[1]);
if (strlen($attribute[2]) == 0) {
continue;
}
// jezelo koncza sie na ' lub " to trzeba to usunac
$attribute[2] = trim($attribute[2], '"\'');
/*
if(in_array($attribute[2][0], array('\'', '"'))) $attribute[2]=substr($attribute[2],1);
if(in_array($attribute[2][strlen($attribute[2])-1], array('\'', '"'))) $attribute[2]=substr($attribute[2],0, -1);
*/
if (!$this->settings->trustText) {
require_once dirname(__FILE__) . '/DataValidator.php';
// sprawdzanie w liscie mozliwych atrybutow ale takze czy atrybut sie nei powtarza
if (!isset($attr[$tagAttr]) || isset($tagAttributes[$tagAttr])) {
continue;
}
$options = $attr[$tagAttr];
if (isset($options['no_changeable']) && $options['no_changeable']) {
continue;
}
switch ($options['type']) {
case 'number':
$str = @DataValidator::parseNumber($attribute[2], isset($options['dimensions']) ? $options['dimensions'] : null, isset($options['default_dimension']) ? $options['default_dimension'] : null, true);
break;
case 'url':
$str = @DataValidator::checkUrl($attribute[2]);
break;
default:
case 'string':
$str = @DataValidator::checkStringValues($attribute[2], isset($options['values']) ? $options['values'] : null, isset($options['replace']) ? $options['replace'] : null);
break;
}
if ($str == false && isset($tagInfo['default_attributes']) && in_array($tagAttr, $tagInfo['default_attributes'])) {
$this->_parseDefaultAttribute($tagAttr, $options, 'no_valid', $tagAttributes);
continue;
} elseif ($str == false) {
continue;
} else {
$str = htmlspecialchars($str);
}
} else {
$str = $attribute[2];
}
$tagAttributes[$tagAttr] = $str;
}
if (isset($tagInfo['default_attributes'])) {
foreach ($tagInfo['default_attributes'] as $dAttribute) {
if (!isset($tagAttributes[$dAttribute])) {
$this->_parseDefaultAttribute($dAttribute, $tagInfo['attributes'][$dAttribute], 'no_enter', $tagAttributes);
}
}
}
if (isset($tagInfo['required_attributes'])) {
//sprawdzanie czy wystapily wszystkie wymagane atrybuty
foreach ($tagInfo['required_attributes'] as $rAttribute) {
if (!isset($tagAttributes[$rAttribute])) {
return -1;
}
}
}
return $tagAttributes ? $tagAttributes : false;
}
示例4: parseUrl
/**
* Parsuje URL
* @param array $tag
* @param array $openNode
* @param array $body
* @param array $cNode
* @param BbCodeSettings $settings
*/
public function parseUrl($tag, &$openNode, &$body, &$cNode, $settings)
{
if (isset($openNode['attributes']['tag_attributes']['url'])) {
return false;
}
require_once dirname(__FILE__) . '/../DataValidator.php';
$str = false;
$inImg = false;
foreach ($body as &$el) {
// szukamy urla w tekscie
if ($el['type'] == BbCode::NODE_TYPE_TEXT) {
$str = DataValidator::checkUrl($el['text']);
if ($str !== false) {
if (!$inImg) {
$str = $this->shortUrl($el['text'], self::URL_LENGTH);
}
break;
}
}
// jezeli jest obrazek i posiada adres obrazka to adres jest przepisywany do [URL]
if ($el['type'] == BbCode::NODE_TYPE_OPEN && $el['tagname'] == 'img') {
if (isset($el['attributes']['tag_attributes']['img'])) {
$inImg = true;
$str = $el['attributes']['tag_attributes']['img'];
break;
}
}
if ($el['type'] == BbCode::NODE_TYPE_CLOSE && $el['tagname'] == 'img') {
$inImg = false;
}
}
if ($str === false) {
$openNode = $settings->removeNode($openNode);
$cNode = $settings->removeNode($cNode);
return false;
}
$openNode['attributes'] = array('tag_attributes' => array('url' => $str));
$openNode = BbCode::rebuildNode($tag, $openNode, $settings);
}