<?php
class Text
{
private $smilies = array();
private $balises = array();
public $content;
public function __construct($content)
{
$this->smilies[] = array('file' => '1.png', 'shortcut' => ':-D');
$this->smilies[] = array('file' => '2.gif', 'shortcut' => 'Oo');
$this->smilies[] = array('file' => '3.gif', 'shortcut' => '^^');
$this->smilies[] = array('file' => '4.png', 'shortcut' => '(siffle)');
$this->smilies[] = array('file' => '5.png', 'shortcut' => '8D');
$this->smilies[] = array('file' => '6.gif', 'shortcut' => 'wink');
$this->smilies[] = array('file' => '7.png', 'shortcut' => ':-p');
$this->smilies[] = array('file' => '8.png', 'shortcut' => ';-)');
$this->smilies[] = array('file' => '9.png', 'shortcut' => '(magicien)');
$this->smilies[] = array('file' => '10.gif', 'shortcut' => '(rolleyes)');
$this->smilies[] = array('file' => '11.gif', 'shortcut' => '(love)');
$this->smilies[] = array('file' => '12.gif', 'shortcut' => '(siflotte)');
$this->smilies[] = array('file' => '13.gif', 'shortcut' => ':-(');
$this->smilies[] = array('file' => '14.gif', 'shortcut' => '-.-');
$this->smilies[] = array('file' => '15.gif', 'shortcut' => '-,-');
$this->smilies[] = array('file' => '16.png', 'shortcut' => ':-O');
$this->balises[] = array('balise' => 'citation', 'open' => '<div style="border:1px solid #ccc;margin:10px 0 10px 0;"><blockquote class="citation"><p>', 'close' => '</p></blockquote></div>');
$this->balises[] = array('balise' => 'information', 'open' => '<div class="information">', 'close' => '</div>');
$this->balises[] = array('balise' => 'question', 'open' => '<div class="question">', 'close' => '</div>');
$this->balises[] = array('balise' => 'code');
$this->content = $content;
}
public function getSmilies()
{
return $this->smilies;
}
public function getBalises()
{
return $this->balises;
}
public function getTags()
{
$return = '';
foreach($this->smilies as $key => $value)
{
$return .= '<a href="#" onclick="insertion(\''. $value['shortcut'] .'\', \'\')"><img src="'. smilies . $value['file'] .'" alt="'. $value['shortcut'] .'" /></a> ';
}
$return .= '<br />';
foreach($this->balises as $key => $value)
{
$return .= '<a href="#" onclick="insertion(\'['. $value['balise'] .']\', \'[/'. $value['balise'].']\')">'. $value['balise'] .'</a> | ';
}
return substr($return, 0, -3);
}
private function replaceSmilies($text)
{
$in = array();
$out = array();
foreach($this->smilies as $key => $value)
{
$in[] = $value['shortcut'];
$out[] = '<img src="'. smilies . $value['file'] .'" alt="'. $value['shortcut'] .'" />';
}
return str_replace($in, $out, $text);
}
private function replaceBalises($text)
{
$in = array();
$out = array();
foreach($this->balises as $key => $value)
{
if($value['balise'] != 'code')
{
$in[] = '['. $value['balise'] .']';
$out[] = $value['open'];
$in[] = '[/'. $value['balise'] .']';
$out[] = $value['close'];
}
}
return str_replace($in, $out, $text);
}
private function replaceAll($text)
{
$return = array();
$openCode = explode('[code]', $text);
$return[] = $this->replaceBalises($this->replaceSmilies($openCode[0]));
foreach($openCode as $key => $value)
{
if($key != 0)
{
$closeCode = explode('[/code]', $value);
$return[] = '
<p style="margin:30px 0px -15px 20px;font-variant:small-caps;">Code Source :</p>
<div class="code">'.
highlight_string('<?php
'. str_replace('<br />', '', $closeCode[0]) .'
?>', true) .'</div>
';
$return[] = $this->replaceBalises($this->replaceSmilies($closeCode[1]));
}
}
$text = implode('', $return);
return $text;
}
public function execute()
{
if(strstr(substr($this->content, 0, 10), '[noformat]') === false)
{
$this->content = $this->replaceAll($this->content);
}
else $this->content = str_replace('[noformat]', '', $this->content);
}
}
?>