|
|
|
ช่วยแก้ปัญหา Call to a member function on a non-object |
|
|
|
|
|
|
|
ผมได้ error message คือ
Call to a member function on a non-object ครับ บนบรรทัด 615 ครับ
บรรทัดนี้อ่ะครับ
if ( $this->parseBBCode ) $text = $this->bbcode->parse($text);
นี่เป็น code ของท่านดุนยา ครับ ผมเอาไปใช้ใน localhost ในเครื่อง มันก็ยังใช้ได้ดีอยู่ครับ แต่ตอน up ขึ้น server มันจะมี error ครับ พอหาสาเหตุของ error นั้นใน google ก็ได้คำตอบมาว่า เกิดจากความแตกต่างของ php5 และ php4 ครับ ก็คือเหมือนกับว่าผมใช้ php5 แต่ server ใช้ php 4 เลยใช้ พวก public,private,protected ไม่ได้ครับ
ทางแก้ก็คือเปลี่ยนเป็น var และเอา public ออกจากหน้า fuction ต่างๆออกให้หมดครับ
อย่างเช่น
private $listStyle; เปลี่ยนเป็น var $listStyle;
และ
public function __construct() เปลี่ยนเป็น function __construct() // เอา public ออก
หลังจากเปลี่ยนแล้วก็ดูถ้าทางจะได้ผลครับ แต่มันมาติดที่ error อันที่ว่าข้างบนอ่ะครับ
ใครรู้ช่วยทีครับ
Code (PHP)
<?php
class bbcode
{
/**
* html list tyle
*
* @var array
*/
private $listStyle;
/**
* syntag of syntaxHighlighter
*
* @var array
*/
private $syntaxHighlighter;
/**
* custom BBcode
*
* @var array
*/
private $customBBCode;
/**
* html Replacement
*
* @var string
*/
private $htmlReplacement;
/**
* tag
*
* @var string
*/
private $tag;
/**
* remove message in code tag
*
* @var array
*/
private $removeMSGCodeTag = array('<br />','<br>');
/**
* substr long url
*
* @var boolean
*/
public $trimLongURLTag = false;
/**
* class constructor
*
* @return void
*/
public function __construct()
{
$this->listStyle = array('1' => '1','a' => 'a','A' => 'A', 'i' => 'i', 'I' => 'I');
$this->syntaxHighlighter = array(
'php' => 'php',
'js' => 'js',
'asp' => 'asp',
'sql' => 'sql',
'css' => 'css',
'xml' => 'xml',
'java' => 'java
');
$this->customBBCode = array(
'1' => array(
'b' => '<strong>{message}</strong>',
'i' => '<em>{message}</em>',
'u' => '<u>{message}</u>',
'left' => '<div style="text-align: left">{message}</div>',
'center'=> '<div style="text-align: center">{message}</div>',
'right' => '<div style="text-align: right">{message}</div>'
),
'2' => array(
'color' => '<span style="color: {option}">{message}</span>',
'size' => '<font size={option}>{message}</font>',
'quote' => "
<div class='quotemessage'>
<table width='90%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>
<div class='quote_title' style='padding:5px; margin:0px;'><b>ข้อความโดย :: {option}</b></div>
<div class='quotecontent' style='padding:5px; margin:0px;'>{message}</div>
</td>
</tr>
</table>
</div>"
)
);
}
/**
* array to remove message in code text
*
* @param array $removeMSGCodeTag (array('<br />','\n'))
*
* @return void
*/
public function setremoveMSGCodeTag($removeMSGCodeTag)
{
$this->removeMSGCodeTag[] = $removeMSGCodeTag;
}
public function setTrimLongURLTag($boolean)
{
if ( is_bool($boolean) ) $this->trimLongURLTag = $boolean;
}
/**
* add new tag
*
* @param string $type (1-3)
* 1 : single tag
* 2 : double tag
* 3 : tripple tag
* @param string $tag ( video )
* @param string $html
*
* @return void
*/
public function addTag($type, $tag, $html)
{
$this->customBBCode[$type][$tag] = $html;
}
/**
* parse bbcode
*
* @param string $text
*
* @return string
*/
final public function parse($text)
{
if ( count( $this->customBBCode['1'] ) > 0 )
{
foreach ( $this->customBBCode['1'] AS $tag => $html)
{
$this->htmlReplacement = $html;
$this->tag = $tag;
$text = $this->customTag( $text );
}
}
if ( count( $this->customBBCode['2'] ) > 0 )
{
foreach ( $this->customBBCode['2'] as $tag => $html)
{
$this->htmlReplacement = $html;
$this->tag = $tag;
$text = $this->customOptionTag( $text );
}
}
$text = self::emailTag($text);
$text = $this->imgTag($text);
$text = $this->urlTag($text);
$text = $this->listTag($text);
$text = $this->codeTag($text);
return $text;
}
/**
* parse img tag
*
* @param string $text
*
* @return void
*/
public static function imgTag( $text )
{
return preg_replace('#\[img](.+?)\[/img\]#is', '<img src=\'\\1\' alt="" title="" />', $text);
}
/**
* parse url tag
*
* @param string $text
*
* @return string
*/
protected function urlTag( $text )
{
$text = preg_replace_callback('#\[url\](.+?)\[/url\]#is', array( &$this, 'urlTagCallBack' ), $text);
$text = preg_replace_callback('#\[link\](.+?)\[/link\]#is', array( &$this, 'urlTagCallBack' ), $text);
$text = preg_replace_callback('#\[url=(.+?)\](.+?)\[/url\]#is', array( &$this, 'urlOptionTagCallBack' ), $text);
$text = preg_replace_callback('#\[link=(.+?)\](.+?)\[/link\]#is', array( &$this, 'urlOptionTagCallBack' ), $text);
return $text;
}
/**
* parse url tag callback
*
* @param string $match
*
* @return string
*/
protected function urlTagCallBack( $match )
{
if ( mb_strlen($match[1],'utf-8') > 50 && $this->trimLongURLTag )
{
$start = mb_substr( $match[1], 0, 40,'utf-8' );
$end = mb_substr( $match[1], -10, 10,'utf-8');
$url = $start . '...' . $end;
}
else
{
$url = $match[1];
}
return '<a href="' . $match[1] . '" alt="" title="" target="_blank">' . $url . '</a>';;
}
/**
* parse url with option tag callback
*
* @param string $match
*
* @return string
*/
protected function urlOptionTagCallBack( $match )
{
if ( mb_strlen($match[2],'utf-8') > 50 && $this->trimLongURLTag && $match[1] == $match[2] )
{
$start = mb_substr( $match[2], 0, 40,'utf-8');
$end = mb_substr( $match[2], -10, 10,'utf-8');
$show = $start . '...' . $end;
}
else
{
$show = $match[2];
}
return '<a href="' . $match[1] . '" alt="" title="" target="_blank">' . $show . '</a>';;
}
/**
* parse url tag
*
* @param string $text
*
* @return string
*/
public static function emailTag( $text )
{
$text = preg_replace('#\[email](.+?)\[/email\]#is', '<a href="mailto:\'\\1\'" alt="" title="">\\1</a>', $text);
return $text;
}
/**
* parse custom tag
*
* @param string $text
*
* @return string
*/
protected function customTag( $text )
{
while( preg_match( "#\[" . $this->tag . "\](.+?)\[/" . $this->tag . "\]#is" , $text ) )
{
$text = preg_replace_callback( "#\[" . $this->tag . "\](.+?)\[/" . $this->tag . "\]#is" , array( &$this, 'customTagCallBack' ), $text );
}
return $text;
}
/**
* parse custom tag callback
*
* @param string $match
*
* @return string
*/
protected function customTagCallBack( $match )
{
return str_replace('{message}' ,$match[1], $this->htmlReplacement);
}
/**
* parse custom option tag
*
* @param string $text
*
* @return string
*/
protected function customOptionTag( $text )
{
while( preg_match( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is" , $text ) )
{
$text = preg_replace_callback( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is" , array( &$this, 'customOptionTagCallBack' ), $text );
}
return $text;
}
/**
* parse custom option tag callback
*
* @param string $match
*
* @return string
*/
protected function customOptionTagCallBack( $match )
{
$text = str_replace('{message}' ,$match[2], $this->htmlReplacement);
return str_replace('{option}' ,$match[1], $text);
}
/**
* parse list with option tag
*
* @param string $text
*
* @return string
*/
protected function listTag( $text )
{
while ( preg_match( "#\[list\](.+?)\[/list\]#is" , $text ) )
{
$text = preg_replace_callback('#\[list\](.+?)\[/list\]#is', array( &$this, 'listTagCallBack' ), $text);
}
while ( preg_match( "#\[list=(.+?)\](.+?)\[/list\]#is" , $text ) )
{
$text = preg_replace_callback('#\[list=(.+?)\](.+?)\[/list\]#is', array( &$this, 'listOptionTagCallBack' ), $text);
}
return $text;
}
/**
* parse list with option tag callback
*
* @param string $match
*
* @return string
*/
protected function listTagCallBack( $match )
{
while ( preg_match( "#\[li\](.+?)\[/li\]#is" , $match[1] ) )
{
$match[1] = preg_replace('#\[li\](.+?)\[/li\]#is', '<li>\\1 \\2</li>', $match[1]);
}
return '<ol style="list-style: disc">' . $match[1] . '</ol>';
}
/**
* parse list with option tag callback
*
* @param string $match
*
* @return string
*/
protected function listOptionTagCallBack( $match )
{
while ( preg_match( "#\[li\](.+?)\[/li\]#is" , $match[2] ) )
{
$match[2] = preg_replace( '#\[li\](.+?)\[/li\]#is' , '<li>\\1 \\2</li>', $match[2]);
}
return '<ol type="' . $this->listStyle[$match[1]] . '">' . $match[2] . '</ol>';
}
/**
* parse code tag
*
* @param string $text
*
* @return string
*/
protected function codeTag( $text )
{
return preg_replace_callback('#\[code=(.+?)\](.*?)\[/code\]#is', array( &$this, 'codeTagCallBack' ), $text);
}
/**
* parse code tag callback
*
* @param string $match
*
* @return string
*/
protected function codeTagCallBack( $match )
{
if ( count( $this->removeMSGCodeTag ) > 0 )
{
foreach ( $this->removeMSGCodeTag AS $value )
{
$match[2] = str_replace( $value,'',$match[2] );
}
}
return '<pre class="brush: ' . $this->syntaxHighlighter[$match[1]] . '">' . $match[2] . '</pre>';
}
}
class postMessageBox
{
private $tag = array();
private $toolWidth = '400';
private $textName = 'txtBox';
private $imgURL = 'images';
private $defaultValue = '';
public function __construct( $textName )
{
$this->textName = $textName;
$this->tag = array(
'1' => array(
'b' => array('ตัวหนา', 'bold.gif'),
'i' => array('ตัวเอียง', 'em.gif'),
'u' => array('ขีดเส้นใต้', 'underline.gif'),
'left' => array('จัดข้อความชิดซ้าย', 'left.gif'),
'center'=> array('จัดข้อความชิดกลาง', 'center.gif'),
'right' => array('จัดข้อความชิดขวา', 'right.gif'),
'img' => array('รูปภาพ', 'img.gif'),
'email' => array('อีเมล์', 'email.gif')
),
'2' => array(
'color' => array('สีข้อความ', 'color.gif', 'ป้อนสี'),
'quote' => array('อ้างอิงข้อความ', 'quote.gif', 'ใส่ชื่อเจ้าของข้อความ'),
'url' => array('ลิงค์', 'url.gif','ป้อนลิงค์'),
'code' => array('โค้ด', 'code.gif','ป้อนภาษาที่เขียน เช่น php, js, asp, sql, css')
),
'3' => array(
'list' => array('ลิส์แบบลำดับ','orderlist.gif','ป้อนประเภทลิสท์ เช่น 1, a, A, i, I','li','ป้อนรายการ')
)
);
}
public function setToolWidth( $width )
{
$this->toolWidth = $width;
}
public function setDefaultValue( $message )
{
$this->defaultValue = $message;
}
public function addTag($type, $tag, $title, $image, $message = '')
{
$this->tag[$type][$tag] = array( $title, $image, $message) ;
}
private function fetchBBCode()
{
if ( count($this->tag) > 0 )
{
foreach( $this->tag AS $type => $text )
{
switch ( $type )
{
case 1:
foreach( $text AS $tag => $message )
{
$list[1][] = <<<HTML
<a onclick="addBBCode(1,'$tag', '{$this->textName}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
case 2:
foreach( $text AS $tag => $message )
{
$list[2][] = <<<HTML
<a onclick="addBBCode(2,'$tag', '{$this->textName}', '{$message[2]}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
case 3:
foreach( $text AS $tag => $message )
{
$list[3][] = <<<HTML
<a onclick="addBBCode(3,'$tag', '{$this->textName}', '{$message[2]}', '{$message[3]}', '{$message[4]}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
default:
$list[1][] = <<<HTML
<a onclick="addBBCode(1,'$tag', '{$this->textName}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
break;
}
}
return array($list[1],$list[2],$list[3]);
}
}
protected function getPostToolFormat()
{
list($list1, $list2, $list3) = $this->fetchBBCode();
if ( count($list1) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list1) . "</td>\n";
$list .= "</tr>\n";
}
if ( count($list2) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list2) . "</td>\n";
$list .= "</tr>\n";
}
if ( count($list3) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list3) . "</td>\n";
$list .= "</tr>\n";
}
return <<<HTML
<table width="{$this->toolWidth}" cellpadding="0" cellspacing="0">
{$list}
</table>
HTML;
}
final public function getPostMessageBox()
{
$list = $this->getPostToolFormat();
return <<<HTML
<table width="{$this->toolWidth}" cellpadding="5" cellspacing="2">
<tr>
<td>
<div class="textarea">
<table width="98%" cellpadding="5" cellspacing="2">
<tr>
<td>
{$list}
</td>
</tr>
</table>
<table width="98%" cellpadding="5" cellspacing="2">
<tr>
<td>
<textarea cols="80" rows="20" name="{$this->textName}" id="{$this->textName}">{$this->defaultValue}</textarea>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
HTML;
}
}
class textParse
{
private $parsenl2br = true;
private $parseBBCode = true;
private $autoParseURL = true;
private $stripHTML = true;
private $bbcode;
private $allowHtml = true;
public function __construct( $nl2br = true, $bbcode = true, $stripHTML = false, $allowHtml = false)
{
$this->bbcode = new bbcode();
if ( is_bool( $nl2br ) ) $this->parsenl2br = $nl2br;
if ( is_bool( $bbcode ) ) $this->parseBBCode = $bbcode;
if ( is_bool( $stripHTML ) ) $this->stripHTML = $stripHTML;
if ( is_bool( $allowHtml ) ) $this->allowHtml = $allowHtml;
}
final public function parseText( $text )
{
if ( $this->stripHTML ) $text = strip_tags( $text );
if ( !$this->allowHtml ) $text = htmlspecialchars( $text );
//$text = preg_replace( "/<br>|<br \/>/", "\n", $text );
# First we did hex, now we do url encoded
# <script
$text = str_replace( "%3C%73%63%72%69%70%74", "<script" , $text );
# document.cookie
$text = str_replace( "%64%6F%63%75%6D%65%6E%74%2E%63%6F%6F%6B%69%65", "document.cookie", $text );
$text = preg_replace( "#javascript\:#is" , "java script:" , $text );
$text = preg_replace( "#vbscript\:#is" , "vb script:" , $text );
$text = str_replace( "`" , "`" , $text );
$text = preg_replace( "#moz\-binding:#is" , "moz binding:" , $text );
$text = str_replace( "<script" , "<script" , $text );
$text = str_replace( "‮" , '' , $text );
$text = str_replace( "<?" , '<?' , $text );
if ( $this->autoParseURL )
{
$text = preg_replace_callback( "#(^|\s|>)((http|https|news|ftp)://\w+[^\s\[\]\<]+)#i", array( &$this, 'buildURLManualCallBack' ), $text );
}
if ( $this->parsenl2br )
$text = nl2br( $text );
else
$text = str_replace( "\n", "", $text );
if ( $this->parseBBCode ) $text = $this->bbcode->parse($text);
return $text;
}
protected function buildURLManualCallBack( $matches = array() )
{
$url = $matches[2] ? $matches[2] : $matches[1];
if ( mb_strlen($url, 'utf-8') > 50 && $this->bbcode->trimLongURLTag )
{
$start = mb_substr( $url, 0, 40, 'utf-8' );
$end = mb_substr( $url, -10, 10, 'utf-8');
$url = $start . '...' . $end;
}
return '<a href="' . ( $matches[2] ? $matches[2] : $matches[1] ) . '" target="_blank" >' . $url . '</a>';
}
}
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-08-23 22:16:29 |
By :
cjmling |
View :
1839 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี่เป็น code หลังจากที่ผมเปลี่ยนตามที่ว่าไว้ด้านบนครับ
code ยาวไปหน่อย เหอะๆ
Code (PHP)
<?php
class bbcode
{
/**
* html list tyle
*
* @var array
*/
var $listStyle;
/**
* syntag of syntaxHighlighter
*
* @var array
*/
var $syntaxHighlighter;
/**
* custom BBcode
*
* @var array
*/
var $customBBCode;
/**
* html Replacement
*
* @var string
*/
var $htmlReplacement;
/**
* tag
*
* @var string
*/
var $tag;
/**
* remove message in code tag
*
* @var array
*/
var $removeMSGCodeTag = array('<br />','<br>');
/**
* substr long url
*
* @var boolean
*/
var $trimLongURLTag = false;
/**
* class constructor
*
* @return void
*/
function __construct()
{
$this->listStyle = array('1' => '1','a' => 'a','A' => 'A', 'i' => 'i', 'I' => 'I');
$this->syntaxHighlighter = array(
'php' => 'php',
'js' => 'js',
'asp' => 'asp',
'sql' => 'sql',
'css' => 'css',
'xml' => 'xml',
'java' => 'java
');
$this->customBBCode = array(
'1' => array(
'b' => '<strong>{message}</strong>',
'i' => '<em>{message}</em>',
'u' => '<u>{message}</u>',
'left' => '<div style="text-align: left">{message}</div>',
'center'=> '<div style="text-align: center">{message}</div>',
'right' => '<div style="text-align: right">{message}</div>'
),
'2' => array(
'color' => '<span style="color: {option}">{message}</span>',
'size' => '<font size={option}>{message}</font>',
'quote' => "
<div class='quotemessage'>
<table width='90%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>
<div class='quote_title' style='padding:5px; margin:0px;'><b>Message By :: {option}</b></div>
<div class='quotecontent' style='padding:5px; margin:0px;'>{message}</div>
</td>
</tr>
</table>
</div>"
)
);
}
/**
* array to remove message in code text
*
* @param array $removeMSGCodeTag (array('<br />','\n'))
*
* @return void
*/
function setremoveMSGCodeTag($removeMSGCodeTag)
{
$this->removeMSGCodeTag[] = $removeMSGCodeTag;
}
function setTrimLongURLTag($boolean)
{
if ( is_bool($boolean) ) $this->trimLongURLTag = $boolean;
}
/**
* add new tag
*
* @param string $type (1-3)
* 1 : bbcode no option
* 2 : bbcode with option
* @param string $tag ( video )
* @param string $html
*
* @return void
*/
function addTag($type, $tag, $html)
{
$this->customBBCode[$type][$tag] = $html;
}
/**
* parse bbcode
*
* @param string $text
*
* @return string
*/
function parse($text)
{
if ( count( $this->customBBCode['1'] ) > 0 )
{
foreach ( $this->customBBCode['1'] AS $tag => $html)
{
$this->htmlReplacement = $html;
$this->tag = $tag;
$text = $this->customTag( $text );
}
}
if ( count( $this->customBBCode['2'] ) > 0 )
{
foreach ( $this->customBBCode['2'] as $tag => $html)
{
$this->htmlReplacement = $html;
$this->tag = $tag;
$text = $this->customOptionTag( $text );
}
}
$text = self::emailTag($text);
$text = $this->imgTag($text);
$text = $this->urlTag($text);
$text = $this->listTag($text);
$text = $this->codeTag($text);
return $text;
}
/**
* parse img tag
*
* @param string $text
*
* @return void
*/
function imgTag( $text )
{
return preg_replace('#\[img](.+?)\[/img\]#is', '<img src=\'\\1\' alt="" title="" />', $text);
}
/**
* parse url tag
*
* @param string $text
*
* @return string
*/
function urlTag( $text )
{
$text = preg_replace_callback('#\[url\](.+?)\[/url\]#is', array( &$this, 'urlTagCallBack' ), $text);
$text = preg_replace_callback('#\[link\](.+?)\[/link\]#is', array( &$this, 'urlTagCallBack' ), $text);
$text = preg_replace_callback('#\[url=(.+?)\](.+?)\[/url\]#is', array( &$this, 'urlOptionTagCallBack' ), $text);
$text = preg_replace_callback('#\[link=(.+?)\](.+?)\[/link\]#is', array( &$this, 'urlOptionTagCallBack' ), $text);
return $text;
}
/**
* parse url tag callback
*
* @param string $match
*
* @return string
*/
function urlTagCallBack( $match )
{
if ( mb_strlen($match[1],'utf-8') > 50 && $this->trimLongURLTag )
{
$start = mb_substr( $match[1], 0, 40,'utf-8' );
$end = mb_substr( $match[1], -10, 10,'utf-8');
$url = $start . '...' . $end;
}
else
{
$url = $match[1];
}
return '<a href="' . $match[1] . '" alt="" title="" target="_blank">' . $url . '</a>';;
}
/**
* parse url with option tag callback
*
* @param string $match
*
* @return string
*/
function urlOptionTagCallBack( $match )
{
if ( mb_strlen($match[2],'utf-8') > 50 && $this->trimLongURLTag && $match[1] == $match[2] )
{
$start = mb_substr( $match[2], 0, 40,'utf-8');
$end = mb_substr( $match[2], -10, 10,'utf-8');
$show = $start . '...' . $end;
}
else
{
$show = $match[2];
}
return '<a href="' . $match[1] . '" alt="" title="" target="_blank">' . $show . '</a>';;
}
/**
* parse url tag
*
* @param string $text
*
* @return string
*/
function emailTag( $text )
{
$text = preg_replace('#\[email](.+?)\[/email\]#is', '<a href="mailto:\'\\1\'" alt="" title="">\\1</a>', $text);
return $text;
}
/**
* parse custom tag
*
* @param string $text
*
* @return string
*/
function customTag( $text )
{
while( preg_match( "#\[" . $this->tag . "\](.+?)\[/" . $this->tag . "\]#is" , $text ) )
{
$text = preg_replace_callback( "#\[" . $this->tag . "\](.+?)\[/" . $this->tag . "\]#is" , array( &$this, 'customTagCallBack' ), $text );
}
return $text;
}
/**
* parse custom tag callback
*
* @param string $match
*
* @return string
*/
function customTagCallBack( $match )
{
return str_replace('{message}' ,$match[1], $this->htmlReplacement);
}
/**
* parse custom option tag
*
* @param string $text
*
* @return string
*/
function customOptionTag( $text )
{
while( preg_match( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is" , $text ) )
{
$text = preg_replace_callback( "#\[" . $this->tag . "=(.+?)\](.+?)\[/" . $this->tag . "\]#is" , array( &$this, 'customOptionTagCallBack' ), $text );
}
return $text;
}
/**
* parse custom option tag callback
*
* @param string $match
*
* @return string
*/
function customOptionTagCallBack( $match )
{
$text = str_replace('{message}' ,$match[2], $this->htmlReplacement);
return str_replace('{option}' ,$match[1], $text);
}
/**
* parse list with option tag
*
* @param string $text
*
* @return string
*/
function listTag( $text )
{
while ( preg_match( "#\[list\](.+?)\[/list\]#is" , $text ) )
{
$text = preg_replace_callback('#\[list\](.+?)\[/list\]#is', array( &$this, 'listTagCallBack' ), $text);
}
while ( preg_match( "#\[list=(.+?)\](.+?)\[/list\]#is" , $text ) )
{
$text = preg_replace_callback('#\[list=(.+?)\](.+?)\[/list\]#is', array( &$this, 'listOptionTagCallBack' ), $text);
}
return $text;
}
/**
* parse list with option tag callback
*
* @param string $match
*
* @return string
*/
function listTagCallBack( $match )
{
while ( preg_match( "#\[li\](.+?)\[/li\]#is" , $match[1] ) )
{
$match[1] = preg_replace('#\[li\](.+?)\[/li\]#is', '<li>\\1 \\2</li>', $match[1]);
}
return '<ol style="list-style: disc">' . $match[1] . '</ol>';
}
/**
* parse list with option tag callback
*
* @param string $match
*
* @return string
*/
function listOptionTagCallBack( $match )
{
while ( preg_match( "#\[li\](.+?)\[/li\]#is" , $match[2] ) )
{
$match[2] = preg_replace( '#\[li\](.+?)\[/li\]#is' , '<li>\\1 \\2</li>', $match[2]);
}
return '<ol type="' . $this->listStyle[$match[1]] . '">' . $match[2] . '</ol>';
}
/**
* parse code tag
*
* @param string $text
*
* @return string
*/
function codeTag( $text )
{
return preg_replace_callback('#\[code=(.+?)\](.*?)\[/code\]#is', array( &$this, 'codeTagCallBack' ), $text);
}
/**
* parse code tag callback
*
* @param string $match
*
* @return string
*/
function codeTagCallBack( $match )
{
if ( count( $this->removeMSGCodeTag ) > 0 )
{
foreach ( $this->removeMSGCodeTag AS $value )
{
$match[2] = str_replace( $value,'',$match[2] );
}
}
return '<pre class="brush: ' . $this->syntaxHighlighter[$match[1]] . '">' . $match[2] . '</pre>';
}
}
class postMessageBox
{
var $tag = array();
var $toolWidth = '400';
var $textName = 'txtBox';
var $imgURL = 'images';
var $defaultValue = '';
function __construct( $textName )
{
$this->textName = $textName;
$this->tag = array(
'1' => array(
'b' => array('ตัวหนา', 'bold.gif'),
'i' => array('ตัวเà¸à¸µà¸¢à¸‡', 'em.gif'),
'u' => array('ขีดเส้นใต้', 'underline.gif'),
'left' => array('จัดข้à¸à¸„วามชิดซ้าย', 'left.gif'),
'center'=> array('จัดข้à¸à¸„วามชิดà¸à¸¥à¸²à¸‡', 'center.gif'),
'right' => array('จัดข้à¸à¸„วามชิดขวา', 'right.gif'),
'img' => array('รูปภาพ', 'img.gif'),
'email' => array('à¸à¸µà¹€à¸¡à¸¥à¹Œ', 'email.gif')
),
'2' => array(
'color' => array('สีข้à¸à¸„วาม', 'color.gif', 'ป้à¸à¸™à¸ªà¸µ'),
'quote' => array('à¸à¹‰à¸²à¸‡à¸à¸´à¸‡à¸‚้à¸à¸„วาม', 'quote.gif', 'ใส่ชื่à¸à¹€à¸ˆà¹‰à¸²à¸‚à¸à¸‡à¸‚้à¸à¸„วาม'),
'url' => array('ลิงค์', 'url.gif','ป้à¸à¸™à¸¥à¸´à¸‡à¸„์'),
'code' => array('โค้ด', 'code.gif','ป้à¸à¸™à¸ าษาที่เขียน เช่น php, js, asp, sql, css')
),
'3' => array(
'list' => array('ลิส์à¹à¸šà¸šà¸¥à¸³à¸”ับ','orderlist.gif','ป้à¸à¸™à¸›à¸£à¸°à¹€à¸ ทลิสท์ เช่น 1, a, A, i, I','li','ป้à¸à¸™à¸£à¸²à¸¢à¸à¸²à¸£')
)
);
}
function setToolWidth( $width )
{
$this->toolWidth = $width;
}
function setDefaultValue( $message )
{
$this->defaultValue = $message;
}
function addTag($type, $tag, $title, $image, $message = '')
{
$this->tag[$type][$tag] = array( $title, $image, $message) ;
}
function fetchBBCode()
{
if ( count($this->tag) > 0 )
{
foreach( $this->tag AS $type => $text )
{
switch ( $type )
{
case 1:
foreach( $text AS $tag => $message )
{
$list[1][] = <<<HTML
<a onclick="addBBCode(1,'$tag', '{$this->textName}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
case 2:
foreach( $text AS $tag => $message )
{
$list[2][] = <<<HTML
<a onclick="addBBCode(2,'$tag', '{$this->textName}', '{$message[2]}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
case 3:
foreach( $text AS $tag => $message )
{
$list[3][] = <<<HTML
<a onclick="addBBCode(3,'$tag', '{$this->textName}', '{$message[2]}', '{$message[3]}', '{$message[4]}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
}
break;
default:
$list[1][] = <<<HTML
<a onclick="addBBCode(1,'$tag', '{$this->textName}'); return false;" href="javascript:void(0);"><img src="{$this->imgURL}/{$message[1]}" title="{$message[0]}" alt="{$message[0]}" border="0" /></a>
HTML;
break;
}
}
return array($list[1],$list[2],$list[3]);
}
}
function getPostToolFormat()
{
list($list1, $list2, $list3) = $this->fetchBBCode();
if ( count($list1) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list1) . "</td>\n";
$list .= "</tr>\n";
}
if ( count($list2) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list2) . "</td>\n";
$list .= "</tr>\n";
}
if ( count($list3) > 0 )
{
$list .= "<tr>\n";
$list .= "<td>" . implode(" ", $list3) . "</td>\n";
$list .= "</tr>\n";
}
return <<<HTML
<table width="{$this->toolWidth}" cellpadding="0" cellspacing="0">
{$list}
</table>
HTML;
}
function getPostMessageBox()
{
$list = $this->getPostToolFormat();
return <<<HTML
<table width="{$this->toolWidth}" cellpadding="5" cellspacing="2">
<tr>
<td>
<div class="textarea">
<table width="98%" cellpadding="5" cellspacing="2">
<tr>
<td>
{$list}
</td>
</tr>
</table>
<table width="98%" cellpadding="5" cellspacing="2">
<tr>
<td>
<textarea cols="80" rows="20" name="{$this->textName}" id="{$this->textName}">{$this->defaultValue}</textarea>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
HTML;
}
}
class textParse
{
var $parsenl2br = true;
var $parseBBCode = true;
var $autoParseURL = true;
var $stripHTML = true;
var $bbcode;
var $allowHtml = true;
function __construct( $nl2br = true, $bbcode = true, $stripHTML = false, $allowHtml = false)
{
$this->bbcode = new bbcode();
if ( is_bool( $nl2br ) ) $this->parsenl2br = $nl2br;
if ( is_bool( $bbcode ) ) $this->parseBBCode = $bbcode;
if ( is_bool( $stripHTML ) ) $this->stripHTML = $stripHTML;
if ( is_bool( $allowHtml ) ) $this->allowHtml = $allowHtml;
}
function parseText( $text )
{
if ( $this->stripHTML ) $text = strip_tags( $text );
if ( !$this->allowHtml ) $text = htmlspecialchars( $text );
//$text = preg_replace( "/<br>|<br \/>/", "\n", $text );
# First we did hex, now we do url encoded
# <script
$text = str_replace( "%3C%73%63%72%69%70%74", "<script" , $text );
# document.cookie
$text = str_replace( "%64%6F%63%75%6D%65%6E%74%2E%63%6F%6F%6B%69%65", "document.cookie", $text );
$text = preg_replace( "#javascript\:#is" , "java script:" , $text );
$text = preg_replace( "#vbscript\:#is" , "vb script:" , $text );
$text = str_replace( "`" , "`" , $text );
$text = preg_replace( "#moz\-binding:#is" , "moz binding:" , $text );
$text = str_replace( "<script" , "<script" , $text );
$text = str_replace( "‮" , '' , $text );
$text = str_replace( "<?" , '<?' , $text );
if ( $this->autoParseURL )
{
$text = preg_replace_callback( "#(^|\s|>)((http|https|news|ftp)://\w+[^\s\[\]\<]+)#i", array( &$this, 'buildURLManualCallBack' ), $text );
}
if ( $this->parsenl2br )
$text = nl2br( $text );
else
$text = str_replace( "\n", "", $text );
if ( $this->parseBBCode )$text = $this->bbcode->parse($text); // บรรทัดนี้ครับ
return $text;
}
function buildURLManualCallBack( $matches = array() )
{
$url = $matches[2] ? $matches[2] : $matches[1];
if ( mb_strlen($url, 'utf-8') > 50 && $this->bbcode->trimLongURLTag )
{
$start = mb_substr( $url, 0, 40, 'utf-8' );
$end = mb_substr( $url, -10, 10, 'utf-8');
$url = $start . '...' . $end;
}
return '<a href="' . ( $matches[2] ? $matches[2] : $matches[1] ) . '" target="_blank" >' . $url . '</a>';
}
}
?>
|
|
|
|
|
Date :
2009-08-23 22:20:24 |
By :
cjmling |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำ โค๊ด ยาวไปไม่มีใครตอบเยย เหอะๆ ช่วยหน่อยคร๊าบ
|
|
|
|
|
Date :
2009-08-24 13:48:21 |
By :
ลิง |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยทีครับ อยากให้แก้ได้จริงๆครับ
|
|
|
|
|
Date :
2009-08-24 23:31:36 |
By :
cjmling |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|