[offtopic]
Wie is dat meisje links onder(a)
[/offtopic]
Ziet er nice uit, alleen de 2e screen vind ik minder, zit ook niet egt een layout aan zeg maar..
[offtopic]
Wie is dat meisje links onder(a)
[/offtopic]
Ziet er nice uit, alleen de 2e screen vind ik minder, zit ook niet egt een layout aan zeg maar..
het komt hier vandaan:
http://www.sitemasters.be/scripts/1/17/1…ased_UBB_parser
Ik ga even kijken of ik in de clean wat kan veranderen.
EDIT
Ik heb het nu weggehaald, en het werkt nu al wat beter, maar als ik bijvoorbeeld bij mijn [ code] block wat heb staan en vervolgens wat enters, worden die enters alsnog weggehaad, geldt ook voor de eerste regel tekst na het code block;)
Beste leden van criminalspoint, op dit moment ben ik druk bezig aan één nieuwe website. Maar daarvoor heb ik een stack based ubb script voor nodig. Nu ik er eindelijk een heb gevonden die werkt, zit ik met één groter probleem.
Wanneer je 2 enters typt zet hij er maar één neer, terwijl er 2 nodig zijn. Wanneer ik er dan echter nl2br overheen gooi, wordt het script zo ongeveer per enter 2 enters neergezet. Ook niet echt de bedoeling.
Nu hoop ik dat iemand me hiermee kan helpen. Voor live voorbeeld PM me.
<?php
/*
* Auteur: Grayen Myrith
*/
class ubb
{
private $aPieces = array();
private $aTree = array();
private $bParse = true;
private $bParagraphise = true;
private $aAlias = array
(
'*' => 'li',
'list' => 'ul',
'ulist' => 'ul',
'olist' => 'ol',
'url' => 'a',
'quote' => 'blockquote',
'google' => 'search'
);
/*
allowed: alle tags die in de gedefineerde tag mogen staan.
child: de verplichte childs die een tag moet hebben.
parent: de verplichte parent die en tag moet hebben.
inline: is het inline element? of niet?
solid: is het een block element waarbij eerst alle tags moeten worden gesloten? Voorbeelden hiervan: table, ul, ol dat moet je uiteraard niet aan tags als td gaan geven, want dan krijg je bijvoorbeeld het volgende: <table><tr></tr></table><td>tekst</td> (en dat willen we natuurljik niet :P)
single: de tag heeft geen bij behorende sluitende tag.
master: door deze item toe te voegen negeert de tag alle regels (Pas op! bij deze tags kun je niet meer gebruik maken van $this->parse('tag') functionaliteit)
*/
public $aFilters = array
(
'basic' => array
(
'b' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
'i' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
'u' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
's' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
'sub' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
'sup' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
)
),
'extended' => array
(
'code' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'h2' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'h3' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'h4' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'h5' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'h6' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false
),
'blockquote' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false,
'master' => true
),
'hr' => array
(
'allowed' => 'all',
'solid' => true,
'inline' => false,
'single' => true
)
),
'links' => array
(
'a' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
),
'search' => array
(
'allowed' => 'all',
'solid' => false,
'inline' => true
)
),
'images' => array
(
'img' => array
(
'allowed' => 'none',
'solid' => true,
'inline' => false,
'single' => true
)
),
'tables' => array
(
'table' => array
(
'allowed' => 'all',
'child' => array('tr'),
'solid' => true,
'inline' => false
),
'tr' => array
(
'allowed' => 'all',
'parent' => array('table'),
'child' => array('td', 'th'),
'solid' => false,
'inline' => false
),
'th' => array
(
'allowed' => 'all',
'parent' => array('tr'),
'solid' => false,
'inline' => false
),
'td' => array
(
'allowed' => 'all',
'parent' => array('tr'),
'solid' => false,
'inline' => false
)
),
'lists' => array
(
'ol' => array
(
'allowed' => 'all',
'child' => array('li'),
'solid' => true,
'inline' => false
),
'ul' => array
(
'allowed' => 'all',
'child' => array('li'),
'solid' => true,
'inline' => false
),
'li' => array
(
'allowed' => 'all',
'parent' => array('ul', 'ol'),
'solid' => false,
'inline' => false
)
)
);
private $aFilter = array('basic', 'extended', 'links', 'images', 'lists', 'tables');
private $aTags = array();
public $sText = '';
public $aText = array();
public function __construct($sText)
{
$this->sText = trim($sText);
foreach($this->aFilters as $sName => $aTags)
{
if(in_array($sName, $this->aFilter) === true)
{
$this->aTags = array_merge($this->aTags, $aTags);
}
}
}
private function cleanWhiteSpace()
{
$this->sText = preg_replace(array("/\\n{3,}/", "/\\n *\\n/"), "\\n\\n", str_replace(array("\\r\\n", "\\n\\r"), "\\n", $this->sText));
}
private function realEmpty($sString)
{
return !(empty($sString) === false && substr_count($sString, "\\n") != strlen($sString));
}
private function getPieces()
{
# De tekst die in delen moet worden gehakt.
$sText = $this->sText;
# De counter voor de key waarden voor elk stukje.
$i = 0;
# De tekst dat zich nog voor de tag bevindt.
$sOther = '';
while(strlen($sText) > 0)
{
$iOpen = strpos($sText, '[');
$iClose = strpos($sText, ']');
# Er is geen tag gevonden, het is dus tekst.
if($iClose === false || $iOpen === false)
{
$this->aPieces['t'.$i] = $sText;
$i++;
return true;
}
else
{
# Is het echt wel een tag, zoals [tag] en niet zomaar twee haakjes als ][.
while($iOpen > $iClose)
{
$iClose = strpos($sText, ']', $iClose + 1);
# Het was geen echte tag, dus het is tekst.
if($iClose === false)
{
$this->aPieces['t'.$i] = $sText;
$i++;
return true;
}
}
# Zit er niet nog een [ voor de tag.
$iTemp = strpos($sText, '[', $iOpen + 1);
while($iOpen < $iTemp && $iTemp < $iClose)
{
$iOpen = $iTemp;
$iTemp = strpos($sText, '[', $iOpen + 1);
}
# Er is een tag gevonden.
if($iOpen < $iClose)
{
$sTag = substr($sText, $iOpen, $iClose - $iOpen + 1);
# Heeft de tag wel een waarde en is het niet gewoon [].
$sTagValue = substr($sTag, 1, -1);
if(empty($sTagValue) === true)
{
$iOpen = $iClose + 1;
}
# De tekst voor de tag ophalen.
$sTemp = substr($sText, 0, $iOpen);
if(empty($sTemp) === false)
{
$sOther .= $sTemp;
}
# Is de tag niet leeg?
if(empty($sTagValue) === false)
{
# Stond er nog tekst voor de tag?
if(empty($sOther) === false)
{
$this->aPieces['t'.$i] = $sOther;
$i++;
$sOther = '';
}
# Stop de tag in de array.
$this->aPieces[($sTag{1} == '/' ? 'c' : 'o').$i] = $sTag;
$i++;
}
# Hakt het al geparsde deel van de tekst af.
$sText = substr($sText, $iClose + 1);
}
}
}
}
private function createTree()
{
foreach($this->aPieces as $sKey => $sPiece)
{
switch($sKey{0})
{
case 't':
$this->append($this->createText($sPiece));
break;
case 'o':
$this->append($this->createOpenTag($sPiece));
break;
case 'c':
$this->append($this->createCloseTag($sPiece));
break;
}
}
}
private function append($aData)
{
$this->aTree[] = $aData;
}
private function createOpenTag($sTag)
{
# Zet alle gegevens over de tag in een array.
$aNode = array();
$aNode['type'] = 'open';
$aNode['text'] = $sTag;
# De tag zonder haakjes.
$sTag = substr($sTag, 1, -1);
if(strpos($sTag, ' ') == true || strpos($sTag, '=') == true)
{
$aNode['tag'] = strtok($sTag, " =");
}
else
{
$aNode['tag'] = $sTag;
}
$aNode['attributes'] = array();
$iSpace = strpos($aNode['text'], ' ');
$iIsSign = strpos($aNode['text'], '=');
if($iSpace !== false || $iIsSign !== false)
{
while(preg_match('#([a-zA-Z0-9]+?)=\\'(.*?)\\'(\\s|$)#si', $sTag, $aMatches) == true || preg_match('#([a-zA-Z0-9]+?)=(.*?)(\\s|$)#si', $sTag, $aMatches) == true)
{
$sValue = trim($aMatches[2]);
if(empty($sValue) === false)
{
$aNode['attributes'][isset($this->aAlias[trim($aMatches[1])]) === true ? $this->aAlias[trim($aMatches[1])] : trim($aMatches[1])] = str_replace(array('"', "'"), '', $sValue);
}
$sTag = str_replace($aMatches[0], '', $sTag);
}
}
# Vervangt de waarde naar de alias.
if(isset($this->aAlias[$aNode['tag']]) === true)
{
$aNode['tag'] = $this->aAlias[$aNode['tag']];
if($iSpace === false && $iIsSign === false)
{
$aNode['text'] = '['.$aNode['tag'].']';
}
else
{
if($iSpace > $iIsSign || $iIsSign !== false && $iSpace === false)
{
$aNode['text'] = '['.$aNode['tag'].substr($aNode['text'], $iIsSign).']';
}
else if($iIsSign > $iSpace || $iSpace === false && $iIsSign !== false)
{
$aNode['text'] = '['.$aNode['tag'].substr($aNode['text'], $iSpace).']';
}
}
}
return $aNode;
}
private function createCloseTag($sTag)
{
$aNode = array();
$aNode['type'] = 'close';
$aNode['text'] = $sTag;
$aNode['tag'] = substr($sTag, 2, -1);
# Kijken of er een alias voor bestaat.
$aNode['tag'] = isset($this->aAlias[$aNode['tag']]) === true ? $this->aAlias[$aNode['tag']] : $aNode['tag'];
return $aNode;
}
private function createText($sText)
{
$aNode = array();
$aNode['type'] = 'text';
$aNode['text'] = $sText;
return $aNode;
}
private function validateTree()
{
# Is er een child toegevoegd (en is dus nog niet gesloten)?
$sOpened = '';
# Welk block element geopend is als laatst geopend?
$bSolidOpened = false;
$aNewTree = array();
$aOpenTags = array();
$aNode = array_shift($this->aTree);
while(empty($aNode) === false)
{
$aPrevNode = end($aNewTree);
switch($aNode['type'])
{
case 'text':
# Heeft de parent tag nog een bepaalde child nodig?
if($this->realEmpty($aNode['text']) === false && empty($aOpenTags) === false && ($vChild = $this->childNeeded(end($aOpenTags), 'text')) !== false && is_bool($vChild) === false)
{
array_unshift($this->aTree, $this->createCloseTag('[/'.$vChild['tag'].']'));
array_unshift($this->aTree, $aNode);
array_unshift($this->aTree, $vChild);
}
else
{
# Als het vorige fragment ook tekst is, voeg deze dan samen.
if($aPrevNode['type'] === 'text')
{
$aNode['text'] = $aPrevNode['text'].$aNode['text'];
array_pop($aNewTree);
}
# Als er een paragraaf in de tekst zit, sluit dan eerst alle open tags.
if(empty($aOpenTags) === false && isset($this->aTags[end($aOpenTags)]) === true && strpos($aNode['text'], "\\n\\n") !== false)
{
# Verwijder spaties links en recht van de tekst indien de tekst in een element staat.
$aNode['text'] = trim($aNode['text']);
if($this->aTags[end($aOpenTags)]['inline'] === true)
{
$aParagraphs = explode("\\n\\n", $aNode['text']);
$aNode['text'] = array_shift($aParagraphs);
$aNewTree[] = $aNode;
while(end($aOpenTags) && (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true))
{
$aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
array_pop($aOpenTags);
}
$aNode['text'] = "\\n\\n".implode("\\n\\n", $aParagraphs);
$aNewTree[] = $aNode;
}
else
{
$aNode['text'] = $aNode['text'];
$aNewTree[] = $aNode;
}
}
else
{
$aNewTree[] = $aNode;
}
}
break;
case 'open':
$bSkip = false;
if(isset($this->aTags[$aNode['tag']]) === false)
{
$aNode['type'] = 'text';
if($aNode['type'] == 'text')
{
$aNode['text'] = $aPrevNode['text'].$aNode['text'];
array_pop($aNewTree);
}
$aNewTree[] = $aNode;
}
else
{
# Is de tag wel toegestaan binnen zijn parent?
if(empty($aOpenTags) === true || $this->isAllowed(end($aOpenTags), $aNode['tag']) === true)
{
# Voorkomt dat een inline element om een block element komt te staan.
if(isset($this->aTags[end($aOpenTags)]) === true && $this->aTags[end($aOpenTags)]['inline'] === true && $this->aTags[$aNode['tag']]['inline'] === false)
{
array_pop($aNewTree);
array_pop($aOpenTags);
continue;
}
# Zorgt ervoor dat alle tags worden gesloten bij een nieuw block element.
if(isset($this->aTags[$aNode['tag']]['solid']) === true && $this->aTags[$aNode['tag']]['solid'] === true)
{
$bSolidOpened = true;
while(end($aOpenTags) && (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true) && isset($this->aTags[end($aOpenTags)]['master']) === false)
{
$aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
array_pop($aOpenTags);
}
}
$vParent = $this->parentNeeded(end($aOpenTags), $aNode['tag']);
$vChild = $this->childNeeded(end($aOpenTags), $aNode['tag']);
# Omdat we het gebruik van parent willen verkomen moeten we kijken of de vorige node niet al de juiste parent heeft aangemaakt.
if(is_bool($vParent) === false)
{
if($aNode['tag'] == end($aOpenTags))
{
$aNewTree[] = $this->createCloseTag('[/'.$aNode['tag'].']');
array_pop($aOpenTags);
}
else
{
array_unshift($this->aTree, $aNode);
array_unshift($this->aTree, $vParent);
$bSkip = true;
}
}
# Is een child noodzakelijk?
if(is_bool($vChild) === false)
{
array_unshift($this->aTree, $aNode);
array_unshift($this->aTree, $vChild);
$bSkip = true;
}
if($bSkip === false)
{
# Voeg de tag toe aan de nieuwe tree.
$aNewTree[] = $aNode;
$aOpenTags[] = $aNode['tag'];
}
}
}
break;
case 'close':
# Als er niks tussen de tags staat, haal ze dan weg.
if($aPrevNode['type'] == 'open' && $aPrevNode['tag'] == $aNode['tag'])
{
array_pop($aNewTree);
array_pop($aOpenTags);
}
else
{
# Is de sluitende tag wel gelijk aan de geopende?
if(empty($aOpenTags) === false && ($aNode['tag'] == end($aOpenTags)))
{
if(in_array($aNode['tag'], $aOpenTags) === true)
{
$aNewTree[] = $aNode;
array_pop($aOpenTags);
}
}
else if(isset($this->aTags[$aNode['tag']]) === false)
{
$aNode['type'] = 'text';
if($aNode['type'] == 'text')
{
$aNode['text'] = $aPrevNode['text'].$aNode['text'];
array_pop($aNewTree);
}
$aNewTree[] = $aNode;
}
}
break;
}
$aNode = array_shift($this->aTree);
}
# Sluit alle nog open tags.
while(end($aOpenTags) && (isset($this->aTags[end($aOpenTags)]['single']) === false || $this->aTags[end($aOpenTags)]['single'] !== true))
{
$aNewTree[] = $this->createCloseTag('[/'.end($aOpenTags).']');
array_pop($aOpenTags);
}
# Update de oude tree.
$this->aTree = $aNewTree;
}
private function childNeeded($sParent, $sChild)
{
# Er zijn geen verplichte childs.
if(isset($this->aTags[$sParent]['child']) === false)
{
return false;
}
# De nieuwe child is al in orde.
if(in_array($sChild, $this->aTags[$sParent]['child']) === true)
{
return false;
}
# Een child is nodig, dus moet er een worden toegevoegd.
return $this->createOpenTag('['.$this->aTags[$sParent]['child'][0].']');
}
private function parentNeeded($sParent, $sChild)
{
# Er zijn geen verplichte parents.
if(isset($this->aTags[$sChild]['parent']) === false)
{
return false;
}
# De parent is al in orde.
if(in_array($sParent, $this->aTags[$sChild]['parent']) === true)
{
return false;
}
# Een andere parent is nodig, dus moet er een worden toegevoegd.
return $this->createOpenTag('['.$this->aTags[$sChild]['parent'][0].']');
}
private function isAllowed($sParent, $sChild)
{
# Alle tags zijn toegestaan.
if($this->aTags[$sParent]['allowed'] == 'all')
{
return true;
}
# Geen enkele tag is binnen deze tag toegestaan.
if($this->aTags[$sParent]['allowed'] == 'none')
{
return false;
}
# Leest de argumenten uit.
$aArguments = explode('^', $this->aTags[$sChild]['allowed']);
$aTags = explode(',', $aArguments[1]);
# Kijkt of de child aan de eisen voldoet.
if($aArguments[0] == 'none' && in_array($sChild, $aTags) === true)
{
return true;
}
if($aArguments[0] == 'all' && in_array($sChild, $aTags) === true)
{
return false;
}
return false;
}
# Zodat de parser weet of hij zich in het eerste level bevindt of niet.
private $iLevel = 0;
# Zorgt ervoor dat de parse functie ook werkt binnen ubb methodes die je zelf aan heb gemaakt.
private $bChangeSolid = false;
private function parse($sStopTag = '')
{
# Als er niks is om te parsen.
if(empty($this->aTree) === true)
{
return '';
}
# De tag van het block type dat open is.
$aOpen = array();
# De hoeveelheid tags er van het type block en hetzelfde zijn die open zijn.
$iOpen = 0;
# Wat het vorige type was.
$bSolid = false;
# Het type van het huidige element.
$bNodeInline = false;
# De counter voor de keys van de text array.
$i = 0;
$iLevel = $this->iLevel;
$this->iLevel++;
$sText = '';
while($aNode = array_shift($this->aTree))
{
if($this->bParagraphise === true && $iLevel == 0)
{
# Is het een tag?
if(isset($aNode['tag']) === true && isset($this->aTags[$aNode['tag']]) === true)
{
# Is geen tag open van het type block?
if(empty($aOpen) === true)
{
$bNodeInline = $this->aTags[$aNode['tag']]['solid'];
}
}
else if($aNode['type'] == 'text' && empty($aOpen) === true && empty($aNode['text']) === false)
{
$bNodeInline = false;
}
# Stopt de tekst als een item in de tekst array.
if($bSolid !== $bNodeInline && $this->realEmpty($sText) === false)
{
$this->aText[($bSolid === false ? 'i' : 'b').$i] = trim($sText);
$sText = '';
$i++;
}
# Update het vorige type naar het huidige.
$bSolid = $bNodeInline;
}
if(isset($aNode['tag']) === true && isset($this->aTags[$aNode['tag']]) === true)
{
if($aNode['tag'] == $sStopTag)
{
$this->bChangeSolid = true;
return $sText;
}
else
{
if(method_exists($this, $aNode['tag']) === true)
{
if($this->bParse === true)
{
$sText .= $this->$aNode['tag']($aNode);
}
else
{
$sText .= $aNode['text'];
}
}
}
}
else
{
$sText .= $aNode['text'];
}
# Zet de tekst in array formaat als dit aan staat.
if($this->bParagraphise === true && $iLevel == 0)
{
# Is het een tag?
if(isset($aNode['tag']) === true && isset($this->aTags[$aNode['tag']]) === true)
{
if(isset($this->aTags[$aNode['tag']]['master']) === true)
{
$this->aText['b'.$i] = trim($sText);
$sText = '';
$i++;
$aOpen = array();
$iOpen = 0;
}
else
{
# Er is een tag geopend van het type block.
if($aNode['type'] == 'open' && $this->aTags[$aNode['tag']]['solid'] === true)
{
if(empty($aOpen) === true)
{
$aOpen = $aNode;
}
# Is het dezelfde tag als de geen die al open is?
if($aNode['tag'] == $aOpen['tag'])
{
$iOpen++;
}
}
# Er is een tag gesloten van het type block.
if(($aNode['type'] == 'close' && $this->aTags[$aNode['tag']]['solid'] === true && empty($aOpen) === false && $aNode['tag'] == $aOpen['tag']) || $this->bChangeSolid === true)
{
$this->bChangeSolid = false;
$iOpen--;
if($iOpen == 0 && $this->realEmpty($sText) === false)
{
$this->aText[($bSolid === false ? 'i' : 'b').$i] = trim($sText);
$sText = '';
$i++;
$aOpen = array();
}
}
}
}
}
}
# Als paragrafen aanmaken aanstaat, maak dan paragrafen om de teksten.
if($this->bParagraphise === true && $iLevel == 0)
{
# Het overgebleven geparsde tekst toevoegen aan de tekst array.
if($this->realEmpty($sText) === false)
{
$this->aText[($bSolid === false ? 'i' : 'b').$i] = $sText;
}
# Zorg ervoor dat er paragrafen komen.
$this->sText = '';
foreach($this->aText as $sKey => $sText)
{
if($sKey{0} == 'i')
{
$this->sText .= $this->paragraphise($sText);
}
else
{
$this->sText .= $sText;
}
}
}
else
{
$this->sText = $sText;
}
}
private function paragraphise($sText)
{
$aParagraphs = explode("\\n\\n", $sText);
$sText = '';
foreach($aParagraphs as $sParagraph)
{
$sText .= '<p>'.str_replace("\\n", '<br />', trim($sParagraph)).'</p>';
}
return $sText;
}
private function basic($aNode, $sTag)
{
if($aNode['type'] == 'open')
{
return '<'.$sTag.'>';
}
else
{
return '</'.$sTag.'>';
}
}
private function b($aNode)
{
return $this->basic($aNode, 'strong');
}
private function i($aNode)
{
return $this->basic($aNode, 'em');
}
private function u($aNode)
{
return $this->basic($aNode, 'ins');
}
private function s($aNode)
{
return $this->basic($aNode, 'del');
}
private function sub($aNode)
{
return $this->basic($aNode, 'sub');
}
private function sup($aNode)
{
return $this->basic($aNode, 'sup');
}
private function a($aNode)
{
if($aNode['type'] == 'open')
{
if(isset($aNode['attributes'][$aNode['tag']]) === true)
{
$sHref = $aNode['attributes'][$aNode['tag']];
if(strpos($sHref, 'http://') === false)
{
$sHref = 'http://'.$sHref;
}
}
else
{
$sHref = '#';
}
return '<a href="'.$sHref.'">';
}
else
{
return '</a>';
}
}
private function search($aNode)
{
$sSearch = $this->parse('search');
return 'Google zoekopdracht: <a href="http://www.google.nl/search?q='.$sSearch.'">'.$sSearch.'</a>';
}
private function h2($aNode)
{
return $this->basic($aNode, 'h2');
}
private function h3($aNode)
{
return $this->basic($aNode, 'h3');
}
private function h4($aNode)
{
return $this->basic($aNode, 'h4');
}
private function h5($aNode)
{
return $this->basic($aNode, 'h5');
}
private function h6($aNode)
{
return $this->basic($aNode, 'h6');
}
private function ol($aNode)
{
return $this->basic($aNode, 'ol');
}
private function ul($aNode)
{
return $this->basic($aNode, 'ul');
}
private function li($aNode)
{
return $this->basic($aNode, 'li');
}
private function table($aNode)
{
return $this->basic($aNode, 'table');
}
private function tr($aNode)
{
return $this->basic($aNode, 'tr');
}
private function th($aNode)
{
return $this->basic($aNode, 'th');
}
private function td($aNode)
{
return $this->basic($aNode, 'td');
}
private function img($aNode)
{
$this->bParse = false;
$sIMG = $this->parse('img');
$this->bParse = true;
return '<img src="'.stripslashes($sIMG).'" alt="Kon niet weergegeven worden" />';
}
private function hr($aNode)
{
if($aNode['type'] == 'open')
{
return '<hr />';
}
}
private function blockquote($aNode)
{
return $this->basic($aNode, 'blockquote');
}
private function code($aNode)
{
$this->bParse = false;
$sCode = $this->parse('code');
$this->bParse = true;
$sCode = str_replace("<br>", "", $sCode);
$sCode = str_replace("<br />", "", $sCode);
$sCode = str_replace("&gt;", ">", $sCode);
$sCode = str_replace("&lt;", "<", $sCode);
$sCode = str_replace("&quot;", "\\"", $sCode);
$sCode = str_replace("&amp;", "&", $sCode);
$sCode = str_replace('$', '\\$', $sCode);
$sCode = str_replace('\\n', '\\\\\\\\n', $sCode);
$sCode = str_replace('\\r', '\\\\\\\\r', $sCode);
$sCode = str_replace('\\t', '\\\\\\\\t', $sCode);
$sCode = str_replace(':)', ':)', $sCode);
$lines = explode(PHP_EOL, trim($sCode));
$i=1;
$code = '<div class="Code">
<div class="Code_Titel">PHP code</div>
<div class="Left">';
foreach ($lines as $line)
{
$code .= $i.'<br />';
$i++;
}
$code .= '</div>
<div class="Right">
'.highlight_string(stripslashes(trim($sCode)), true).'
</div>
</div>';
return $code;
}
static public function execute($sText)
{
$oParser = new ubb($sText);
$oParser->cleanWhiteSpace();
$oParser->getPieces();
$oParser->createTree();
$oParser->validateTree();
$oParser->parse();
echo $oParser->sText;
return noXSS($oParser->sText);
}
}
function noXSS($sString)
{
return stripslashes(preg_replace('#(href|src)=(\\'|\\")(.+?)(\\'|\\")( |>)#ise', "'\\\\1=\\\\2'.removeJavascript('\\\\3').'\\\\4\\\\5'", $sString));
}
function removeJavascript($sString)
{
$sReturn = '#';
$sCheck = str_replace(array("\\n", ' '), '', stripslashes(strip_tags(html_entity_decode(trim(strtolower($sString))))));
$bEvil = false;
$aEvil = array('javascript:', 'onfocus=', 'onblur=', 'onclick=', 'ondblclick=', 'onmousedown=', 'onmouseup=', 'onmouseover=', 'onmousemove=', 'onmouseout=', 'onkeypress=', 'onkeydown=', 'onkeyup=');
foreach($aEvil as $sEvil)
{
if(strpos($sCheck, $sEvil) !== false)
{
$bEvil = true;
break;
}
}
if($bEvil === false)
{
$sReturn = $sString;
}
return $sReturn;
}
?>
Meer tonen
er zit nergens een ob start;) en higlight string zorgt voor die mooie kleurtjes:P
Verder weet ik niet egt wat het nog meer doet..
nou, ik heb dus een ubb-parser, en nu ben ik bezig met een code blok, dus dat je je scripts kan posten enzo..
Mar nu delete hij steeds alle enkele quotes.. Wat dus niet moet..
Beste,
Op dit moment ben ik druk bezig om een ubb parser aan te passen,
Nu zit ik met een volgende probleem:
Ik wil dat alles veilig is, maar dat wel alles perfect wordt weergegeven.
ik heb nu: $hoi = 'hoi'; en dan gaan de '' weg om de hoi, en dat kan natuurlijk niet..
Hopelijk kan iemand me helpen.
Kunt u misschien elk stukje nader toelichten, want dit is een rommeltje en weet dus eigenlijk niet wat welk ding doet:P
Groeten,
Luc
Ik lees serieus nu pas jou mededeling hoor, dus zal jou wel even een feedback geven, verder goed initiatief.
Met vriendelijke groet,
Luc
3 keer om voorbeelden vragen is beetje erg,
Heb je verstand van classes?
ik roep het nu aan met parse($forum['bericht']);
Maar dit heeft nog geen enkel effect want er komen nergens enters of wat dan ook..
Heel jammer en vreemd.
Is het misschien zo dat ik bestanden mis?
Als iemand een betere ubb parser heeft die werkt zoals deze mag die dat ook geven.
@ darsstar, het probleem is dat ik deze class vaker moet gebruiken, dus het is niet altijd $forum bericht, hoe koppel ik dan iets aan een var?
Ja die wordt hierin geinclude:
<?php
/**
* Bbcode testbestand
*
* @link http://en.wikipedia.org/wiki/BBCode
* @author Richard van Velzen
* @package Bbcode
*/
$startTime = microtime(true);
require 'allinone.php';
/**
* Verwerking voor de code tag
*
* @param string $tagName
* @param string $content
* @param array $arguments
* @return string
*/
function codeTag($tagName, $content, array $arguments) {
return '<pre><code>' . preg_replace('{(?=[\\r\\n])\\r?+\\n?+}', '</code><code>', htmlspecialchars($content)) . '</code></pre>';
}
/**
* url-tag specifieke rule
*
* @author Richard van Velzen
*/
class UrlTagRule extends TagRule {
/**
* Check of we binnen een andere url-tag zitten
*
* @param PointNode $node
* @return boolean
*/
public function isPermissableIn(PointNode $node) {
$initialValid = parent::isPermissableIn($node);
if($initialValid) {
// verdorie, nu moeten we de tree aflopen of we mogen
while(!$node->getRule() instanceof UrlTagRule) {
$node = $node->getParent();
if(!$node instanceof TagNode) {
return true;
}
}
}
return false;
}
}
/**
* Verwerking voor de url tag
*
* @param string $tagName
* @param string $content
* @param array $arguments
* @return string
*/
function linkTag($tagName, $content, array $arguments) {
$argName = $tagName == 'url' ? 'url' : 'href';
$link = &$arguments[$argName];
$match = array();
if(!isset($link) || !preg_match('{^(?:((?:https?|ftp)://)|\\w+\\.)[\\w.]+[;#&/~=\\w+()?.,:%-]*$}i', $link, $match)) {
return $content;
}
if(empty($match[1])) {
$link = 'http://' . $link;
}
return '<a href="' . $link . '">' . $content . '</a>';
}
/**
* Verwerking voor een image tag
*
* @param unknown_type $tagName
* @param unknown_type $content
* @param unknown_type $arguments
* @return unknown
*/
function imageTag($tagName, $content, array $arguments) {
$match = array();
if(!preg_match('{^(?:((?:https?|ftp)://)|\\w+\\.)[\\w.]+[;#&/~=\\w+()?.,:%-]*$}i', $content, $match)) {
return htmlspecialchars($content);
}
$url = $content;
if(empty($match[1])) {
$url = 'http://' . $url;
}
$alt = isset($arguments['alt']) ? htmlspecialchars($arguments['alt']) : '';
return '<img src="' . htmlspecialchars($url) . '" alt="' . $alt . '" />';
}
$text = file_get_contents('input.txt');
$parser = new Parser();
$parser->setLexer(new SplitLexer())
->addRule(new TagRule('b', 'inline', array('block', 'inline', 'listitem'), new TagTemplate('<strong>{$_content/nl2br}</strong>')))
->addRule(new UrlTagRule('url', 'inline', array('block', 'inline', 'listitem'), 'linkTag'))
->addRule(new UrlTagRule('a', 'inline', array('block', 'inline', 'listitem'), 'linkTag'))
->addRule(new TagRule('i', 'inline', array('block', 'inline', 'listitem'), new TagTemplate('<em>{$_content/nl2br}</em>')))
->addRule(new TagRule('u', 'inline', array('block', 'inline', 'listitem'), new TagTemplate('<span class="underline">{$_content/nl2br}</span>')))
->addRule(new TagRule('list', 'list', array('block', 'listitem'), new TagTemplate('<ul>{$_content/trim}</ul>'), TagRule::TRIM_BOTH))
->addRule(new TagRule('sup', 'inline', array('block', 'inline', 'listitem'), new TagTemplate('<sub>{$_content/nl2br}</sup>')))
->addRule(new TagRule('sub', 'inline', array('block', 'inline', 'listitem'), new TagTemplate('<sub>{$_content/nl2br}</sub>')))
->addRule(new TagRule('*', 'listitem', array('list'), new TagTemplate('<li>{$_content/trim/nl2br}</li>'), TagRule::TRIM_BOTH, TagRule::PARSE))
->addRule(new TagRule('quote', 'block', array('block'), new TagTemplate('<div class="quote">{$_content/trim/nl2br}</div>'), TagRule::TRIM_BOTH))
// letterlijke tags met callback
->addRule(new TagRule('img', 'image', array('block', 'inline', 'listitem'), 'imageTag', Tagrule::TRIM_NONE, TagRule::LITERAL))
->addRule(new TagRule('code', 'code', array('block'), 'codeTag', TagRule::TRIM_BOTH, TagRule::LITERAL));
$output = $parser->parse($text);
?>
Meer tonen
ik roep het aan via $parser->parse($forum['bericht']);
allinone is niets aan verandert en is dus zoals op de website.
Nou
ik heb het script erin zitten, en gedaan zoals het dus in je linkje staat dus de basistest geintergreerd in mijn systeem, en de library de naam allinone.php gegeven zoals bij hun.
Maar als ik nu echo $parser->parse($forum['bericht']);
doe dan parsed hij de tekst alsnog niet..
Ben ik dan nog wat vergeten?
Dat is mijn vraag.
[offtopic]
Ik vind cp slecht sinds ik gewoon op een topic reageerde waar een vraag in stond, en het ging over de eigenaar. Toen kreeg ik ban omdat ik zei dat het idd de eigenaar was.
[/offtopic]
ik heb dat linkje ook ingebouwd.. Maar nu wordt de parser nogsteeds niet uitgevoerd..
Hij werkt nu ongeeer, maar hoe maak ik nu een code block:$?
Dat heb ik al geprobeerd, maar blijft dezelfde error geven, ik heb zelf geen verstand van het aanroepen van classes. Dus denk dat ik daar iets fout doe.
Beste leden,
Ik gebruik de volgende ubb parser:
http://www.liefcoden.nl/ubb/proof-of-c…e/allinone.html
Maar als ik deze erin bouw en aanroep via :
$parser->Parser($forum['bericht']);
Notice: Undefined variable: parser in /home/onenat/sub/com/forum/onderwerp.php on line 50
Fatal error: Call to a member function Parser() on a non-object in .../ on line 50
Dan werkt deze niet meer. Wie weet wat ik fout doe?
inmiddels is het al gelukt via een andere weg, wat misschien niet zo handig was. Maar wel efficiënter, gewoon een extra tabel aangemaakt waar de data wordt opgeslagen.
:slotje:
beste leden,
ik ben bezig met een poll script te maken, nu worden alle ip's opgeslagen in de database die al gestemd hebben. Nu moet het alleen nog gecontroleerd worden of de ip of user id in die tabel voorkomt.
ze worden als volgd opgeslagen.
ik ben speler 5 en ga stemmen, mijn stem is uitgebracht:
word alsvolgt opgeslagen in de database: 5,111.111.1.11
nu moet hij gaan zoeken of 5, of mijn ip voorkomt. Hoe doe ik dat?
ik heb al met strstr geprobeerd, en preg match maar het wou me niet baten.