Beispiel #1
0
 /**
  * Parsuje tag QUOTE
  * @param array $tag
  * @param array $openNode
  * @param array $body
  * @param array $closeNode
  * @param BbCodeSettings $settings
  */
 public function parseQuote($tag, &$openNode, &$body, &$closeNode, $settings)
 {
     $divText = '';
     if (isset($openNode['attributes'])) {
         if (isset($openNode['attributes']['tag_attributes']['quote'])) {
             $divText .= $openNode['attributes']['tag_attributes']['quote'] . ' ';
         }
         if (isset($openNode['attributes']['tag_attributes']['date'])) {
             $dateExpr = '/^[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}$/';
             if (preg_match($dateExpr, $openNode['attributes']['tag_attributes']['date'])) {
                 $divText .= '<small>(' . $openNode['attributes']['tag_attributes']['date'] . ')</small> ';
             } else {
                 unset($openNode['attributes']['tag_attributes']['date']);
                 $openNode = BbCode::rebuildNode($tag, $openNode, $settings);
             }
         }
     }
     $openNode['text'] .= '<div class="quote_title">Cytat ' . $divText . ':</div><div class="quote_area">';
     $closeNode['text'] = '</div>' . $closeNode['text'];
 }
Beispiel #2
0
<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <title>Test bbcode - tworzenie zajawki</title>
	<link href="styl.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="all">
<h1>Test skracania tekstu</h1>
<?php 
function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
require_once 'Bbcode/BbCode.php';
$bb = new BbCode();
$length = 22;
$text = '[ul]
[li]Internet Explorer,[/li]
[li]Firefox,[/li]
[li]Google Chrome 4.0,[/li]
[li]Safari 3.0.[/li]
[/ul]';
echo '<fieldset class="pre"><legend>Oryginalny tekst</legend>' . $text . '</fieldset>';
$bb->parse($text, false);
$cutText = $bb->cutText($length);
echo '<fieldset><legend>Skrócona wersja do ' . $length . ' znaków </legend>' . $cutText . '</fieldset>';
echo '<fieldset><legend>Skrócona wersja do ' . $length . ' znaków (tagi)</legend>' . $bb->cutText($length, true) . '</fieldset>';
?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
Beispiel #3
0
 /**
  * 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) {
                 $openNode['attributes']['tag_attributes']['height'] = $height;
             }
         }
         // przywrocenie domyslnego ustawienia
         if (ini_get('allow_url_fopen') && $this->checkRealImageSize) {
             ini_set('default_socket_timeout', $oldDefaultSocketTimeout);
         }
     }
     // ustawianie ostatecznie pobranych argumentow
     $imgValue = '';
     if (isset($openNode['attributes']['tag_attributes']['width'])) {
         $imgValue .= $openNode['attributes']['tag_attributes']['width'];
     }
     if (isset($openNode['attributes']['tag_attributes']['height'])) {
         $imgValue .= 'x' . $openNode['attributes']['tag_attributes']['height'];
     }
     if ($imgValue) {
         $openNode['attributes']['tag_attributes']['img'] = $imgValue;
     }
     // usuwamy zawartosc body
     foreach ($body as $key => &$el) {
         if ($el['type'] != 0) {
             $el = array('type' => 0, 'text' => '', 'tagText' => $el['text']);
         } else {
             $el = array('type' => 0, 'text' => '', 'tagText' => $el['text']);
         }
     }
     $cNode['text'] = '';
     $openNode = BbCode::rebuildNode($tag, $openNode, $settings);
     $openNode['text'] = substr($openNode['text'], 0, -1) . '/>';
     // domykamy img :)
 }
Beispiel #4
0
 /**
  * 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);
 }
Beispiel #5
0
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<title>Test bbcode</title>
		<link href="styl.css" rel="stylesheet" type="text/css"/>
	</head>
	<body>
		<div id="all">
			<h1>Test BBCODE</h1>
			<?php 
function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
include_once 'Bbcode/BbCode.php';
$bb = new BbCode();
$text = '
Pobrubienie:
	[b]Pogrubiony[/b]
Podkreślenie:
	[u]Podkreślony[/u]
Kursywa:
	[i]Kursywa[/i]
Przekreślenie:
	[s]Przekreślony[/s]
Kolorowanie:
	[color=#AF0D0D]Kolorowy tekst[/color]
	[color=blue]Kolorowy tekst 2[/color]
Linkowanie:
	[url]Link niepoprawny[/url]
	[url]http://wookieb.pl[/url]