Post functions BETA.

このコミットが含まれているのは:
テクニカル諏訪子 2018-02-27 22:57:47 +09:00
コミット 41520e6cc5
1個のファイルの変更95行の追加1行の削除

ファイルの表示

@ -414,6 +414,97 @@ class BoardController extends Controller {
}
}
public function stripBR($string) {
return preg_replace('/\<br(\s*)?\/?\>/i', '', $string);
}
public function autoLink($s) {
if (strpos($s, '[link=') !== false || strpos($s, '[/link]') !== false) {
return $s;
}
else if (strpos($s, '<a href=') !== false || strpos($s, '</a>') !== false) {
return $s;
}
else if (strpos($s, '[img]') !== false || strpos($s, '[/img]') !== false) {
return $s;
}
else {
return preg_replace('!(\s|^)((https?://|www\.)+[a-z0-9_%./#?=;&-]+)!i', ' <a href="$2" target="_blank">$2</a> ',$s);
}
}
function getBBCode($text) {
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[s\](.*?)\[/s\]~s',
'~\[o\](.*?)\[/o\]~s',
'~\[centre\](.*?)\[/centre\]~s',
'~\[img width=(.*?) height=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
'~\[img height=(.*?) width=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
'~\[img width=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
'~\[img height=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
'~\[yt\](.*?)\[/yt\]~s',
'~\[link=((?:ftp|https?)://.*?)\](.*?)\[/link\]~s',
'~\[sound\](https?://.*?\.(?:mp3))\[/sound\]~s',
'~\[size=(.*?)\](.*?)\[/size\]~s',
'~\[colour=(.*?)\](.*?)\[/colour\]~s',
'~\[quote="(.*?)" id="(.*?)"](.*?)\[/quote]~s',
'~\[quote="(.*?)"](.*?)\[/quote]~s',
'~\[quote](.*?)\[/quote]~s',
'~\[code](.*?)\[/code]~s',
'~\[spoiler=(.*?)](.*?)\[/spoiler]~s',
'~\[spoiler](.*?)\[/spoiler]~s',
'~\[rtl](.*?)\[/rtl]~s',
'~\[gcn](.*?)\[/gcn]~s',
'~\[miiverse](.*?)\[/miiverse]~s',
'~\[smb](.*?)\[/smb]~s',
'~\[video](.*?)\[/video]~s',
);
$replace = array(
'<b>$1</b>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<span style="text-decoration:line-through;">$1</span>',
'<span style="text-decoration:overline;">$1</span>',
'<span align="center">$1</span>',
'<img src="$3" alt="" width="$1px" height="$2px" border="0" />',
'<img src="$3" alt="" width="$2px" height="$1px" border="0" />',
'<img src="$2" alt="" width="$1px" border="0" />',
'<img src="$2" alt="" height="$1px" border="0" />',
'<img src="$1" alt="" class="img-responsive" border="0" />',
'<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="https://www.youtube.com/embed/$1" allowfullscreen></iframe></div>',
'<a href="$1" target="_blank">$2</a>',
'<audio controls><source src="$1" type="audio/mpeg">Your browser does not support the audio tag.</audio>',
'<span style="font-size:$1px;">$2</span>',
'<span style="color:$1;">$2</span>',
'<blockquote><span class=\'quotedby\'><a href=forum.php?page=thread&tid=$threadid&pid=$2#$2><i>Posted by \'$1\'</i></a></span><hr>$3<hr></blockquote>',
'<blockquote><span class=\'quotedby\'><i>Posted by \'$1\'</i></span><hr>$2<hr></blockquote>',
'<blockquote><hr>$1<hr></blockquote>',
'<table cellspacing="0" style="width: 90%; min-width: 90%;"><tr><td class="b n3"><code class="codeblock" style="font-size: 9pt;"><xmp>$1</xmp></code></tr></table><br />',
'<div class="spoiler"><button onclick="var s=this.parentNode.getElementsByClassName(\'spoilercontents\')[0].style;s.display=(s.display==\'none\')?\'\':\'none\';">$1</button><br /><div class="spoilercontents" style="display:none;">$2</div></div>',
'<div class="spoiler"><button onclick="var s=this.parentNode.getElementsByClassName(\'spoilercontents\')[0].style;s.display=(s.display==\'none\')?\'\':\'none\';">Spoiler</button><br /><div class="spoilercontents" style="display:none;">$1</div></div>',
'<div dir="rtl">$1</div>',
'<span class="GameCube">$1</span>',
'<span class="MiiverseSymbols">$1</span>',
'<span class="MarioBros">$1</span>',
'<video width="600" controls><source src="$1" type="video/mp4">Your browser does not support MP4, or HTML5 videos.</video>',
);
return preg_replace($find, $replace, $text);
}
public function packageMessage($string) {
$string = $this->stripBR($string);
$string = $this->autoLink($string);
$string = $this->getBBCode($string);
return $string;
}
public function browseTopicPosts($tp, $id, $from, $to) {
// Load group colours.
$ucol = $this->objUser->getGroupColours();
@ -455,13 +546,16 @@ class BoardController extends Controller {
$gname = $this->objUser->getGroupName($i->user_id);
$showGroupName = $gname[0]->name;
//$mess = preg_replace('/\<br(\s*)?\/?\>/i', '', $i->message);
$mess = $this->packageMessage($i->message);
array_push($udat, [
'key' => $key,
'id' => $i->id,
'tid' => $i->top_id,
'uid' => $i->user_id,
'post_date' => date('Y/m/d, G:i:s T', $i->post_date),
'message' => $i->message,
'message' => $mess,
'delete' => $i->delete,
'delreason' => $i->delreason,
'lastedit' => date('Y/m/d, G:i:s T', $i->lastedit),