Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Hide debugger setting
JS strip tags
Fix text format detect
Disable \@\#
  • Loading branch information
cth-inni committed Oct 26, 2021
1 parent 0d0517d commit 2eb63d2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
79 changes: 52 additions & 27 deletions src/ChatBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function __construct($newObj=null)
];
// default setting
$oriObj = [
'devTools' => false,
'allowForkScript' => null,
'chatHeaderSize' => 'normal',
'mainCastColor' => '#248bf5',
Expand Down Expand Up @@ -164,7 +165,7 @@ public function showCasts(){
{
$chatColor = $this->loadCastColor($cast['name']);
$tempHtml .= '<div class="cast btnGotoHead" data-castid="'.$cast['castId'].'">';
$tempHtml .= '<div class="square disable-select" style="border-color:'.$chatColor.';background:#38A899 url('.$this->loadChatHeaderImg($cast['name']).')center center/60px 60px no-repeat;">'.trim($cast['name']).'</div>';
$tempHtml .= '<div class="square disable-select" style="border-color:'.$chatColor.';background:#38A899 url('.$this->loadChatHeaderImg($cast['name']).')center center/60px 60px no-repeat;" role="text" aria-label="'.trim($cast['name']).'" alt="'.trim($cast['name']).'">'.trim($cast['name']).'</div>';
$tempHtml .= '</div>';
}
$tempHtml .= '</div>';
Expand Down Expand Up @@ -246,7 +247,7 @@ private function _buildCastsFeed($rawData) {
$tempCast = [];
$tempCast['name'] = $tempRolesKey;
$tempCast['castId'] = uniqid();
$tempCast['color'] = null;
$tempCast['color'] = null;
$tempCast['img'] = null;
switch($this->settings->castColorMode)
{
Expand Down Expand Up @@ -284,6 +285,7 @@ private function _buildCastsFeed($rawData) {
{ // Shift to first as main cast
$newCastdata = [];
$newCastdata['name'] = $name;
$newCastdata['castId']= uniqid();
$newCastdata['color'] = $proceedData[$castKey]['color'];
$newCastdata['img'] = $img;
unset($proceedData[$castKey]);
Expand Down Expand Up @@ -552,7 +554,10 @@ public function render(){
}
$tempHtml .= '</section>';
$tempHtml .= '</div>';
$tempHtml .= $this->render_rawdata_full(null,$this->rawData);
if($this->settings->devTools)
{
$tempHtml .= $this->render_rawdata_full(null,$this->rawData);
}
return $tempHtml;
}
private function renderDev($dialogue=null,$option='')
Expand Down Expand Up @@ -673,15 +678,15 @@ private function render_rawdata($dialogue, $rawData)
private function render_rawdata_full($dialogue, $rawData)
{
$ts = time();
$tempHtml = '<div class="readingStory-changes well margin-top-2x padding-sm rawscript-chatblock-container">';
$tempHtml = '<div id="chatblock-devtools" class="readingStory-changes well margin-top-2x padding-sm rawscript-chatblock-container">';
$tempHtml .= '<hr/>';
$tempHtml .= '<a class="btn btn-default btn-xs" data-toggle="collapse" data-target="#readingStory-changes-chatblock-'.$ts.'">显示原始对话剧本</a>';
$tempHtml .= '<a class="btn btn-default btn-xs" data-toggle="collapse" data-target="#readingStory-changes-chatblock-'.$ts.'">Toggle Devtools</a>';
if(isset($this->settings->allowForkScript))
{
$tempHtml .= '<div id="rawscript-chatblock-editor" class="rawscript-chatblock-editor">';
$tempHtml .= '<form method="POST" target="_blank" action="'.$this->settings->allowForkScript.'">';
$tempHtml .= '<button type="submit" class="btn btn-default btn-xs">玩玩本章对话剧本</button><br/>';
$tempHtml .= '<textarea name="rawscript">'.$rawData.'</textarea>';
$tempHtml .= '<button type="submit" class="btn btn-default btn-xs">Debug Scripts</button><br/>';
$tempHtml .= '<textarea class="d-none" name="rawscript">'.$rawData.'</textarea>';
$tempHtml .= '</div>';
$tempHtml .= '</form>';
}
Expand Down Expand Up @@ -723,26 +728,25 @@ private function render_reflink($dialogue)
}
private function render_text($dialogue)
{
// $sentence = $this->fn_filter($dialogue['_line']);
$sentence = ($dialogue['_line']);
$sentence = $this->fn_stripTags($dialogue['_context']);
$tempHtml = '<div class="imessage">';
$tempHtml .= '<p class="comment-full disable-select">'.$sentence.'</p>';
$tempHtml .= '</div>';
return $tempHtml;
}
private function render_heading($dialogue)
{
$link = $this->fn_valid_link($dialogue['_line']);
$sentence = $this->fn_stripTags($dialogue['_context']);
$tempHtml = '<div class="imessage text-center">';
$tempHtml .= '<'.strtolower($dialogue['_castname']).'>';
$tempHtml .= $dialogue['_line'];
$tempHtml .= $sentence;
$tempHtml .= '</'.strtolower($dialogue['_castname']).'>';
$tempHtml .= '</div>';
return $tempHtml;
}
private function md_render_heading($dialogue,$headingLevel)
{
$sentence = ($dialogue['_context']);
$sentence = $this->fn_stripTags($dialogue['_context']);
$tempHtml = '<div class="imessage text-center">';
$tempHtml .= '<h'.$headingLevel.'>';
$tempHtml .= $sentence;
Expand Down Expand Up @@ -807,6 +811,10 @@ private function render_decisions_holder($dialogue)
return $tempHtml;
}
// Misc
private function fn_stripTags($dialogue)
{
return strip_tags($dialogue); // Strip all tag
}
private function fn_filter($dialogue)
{
$newStr = strip_tags($dialogue); // Strip all tag
Expand All @@ -815,23 +823,40 @@ private function fn_filter($dialogue)
preg_match_all("~$regex~", $newStr, $matches, PREG_SET_ORDER);
foreach($matches as $set)
{
if($set[1] == '`') $tag = 'code';
elseif($set[1] == '*') $tag = 'b';
elseif($set[1] == '-') $tag = 'del';
else $tag = 'em';
$newStr = str_replace($set[0], "<$tag>{$set[2]}</$tag>", $newStr);
switch($set[1])
{
case '`': $tag = 'code'; break;
case '*': $tag = 'b'; break;
case '-': $tag = 'del'; break;
case '_': $tag = 'em'; break;
default: $tag = null; break;
}
if(!is_null($tag))
{
$newStr = str_replace($set[0], "<$tag>{$set[2]}</$tag>", $newStr);
}
}
// Bold, Italic, Code, Delete - end
// @,# - start
$regex = '([@#])((?:(?!\1).)+)\s';
preg_match_all("~$regex~", $newStr, $matches2, PREG_SET_ORDER);
foreach($matches2 as $set2)
{
if($set2[1] == '@') $tag = 'cast';
elseif($set2[1] == '#') $tag = 'topic';

$newStr = str_replace($set2[0], "<span class=\"chat-label chat-label-{$tag}\">{$set2[2]}</span>&nbsp;", $newStr);
}
// $regex = '([\@\#])((?:(?!\1).)+)\s';
// $regex = '[\#|\@][^$]';
// $regex = '(^|\s)[\#\@](\w*[a-zA-Z_]+\w*)';
// $regex = '([\#\@]\w*)';
// preg_match_all("~$regex~", $newStr, $matches2, PREG_SET_ORDER);
// foreach($matches2 as $set2)
// {
// print_r($set2);
// switch($set[1])
// {
// case '@': $tag = 'cast'; break;
// case '#': $tag = 'topic'; break;
// default: $tag = null; break;
// }
// if(!is_null($tag))
// {
// $newStr = str_replace($set2[0], "<span class=\"chat-label chat-label-{$tag}\">{$set2[2]}</span>&nbsp;", $newStr);
// }
// }
// @,# - end
$newStr = str_replace($this->linebreak,'<br/>',$newStr); // Allow to multiples lines
return trim($newStr);
Expand All @@ -848,7 +873,7 @@ private function fn_valid_link($dialogue)
// Chat Blocks
private function role_narrator($dialogue)
{
$sentence = $this->fn_filter($dialogue['_context']);
$sentence = $this->fn_stripTags($dialogue['_context']);
$tempHtml = '<div class="imessage">';
$tempHtml .= '<p class="narrator disable-select">'.$sentence.'</p>';
$tempHtml .= '</div>';
Expand Down
12 changes: 5 additions & 7 deletions src/chatblock.css
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@

.chatblock .casts-list{
display: flex;
flex-wrap: wrap;
flex-direction: row;
/* flex-wrap: wrap; */
}

.chatblock .casts-list .cast{
margin: 5px;
}

.chatblock .casts-list .cast .square{
/* opacity: 0.7; */
opacity: 0.7;
cursor: pointer;
color: #FFF;
text-shadow: 2px 2px #000;
Expand Down Expand Up @@ -430,10 +430,6 @@
right: 10px;
}

.chatblock .rawscript-chatblock-editor textarea{
display: none;
}

.chatblock .rawscript-chatblock-container{
overflow: auto;
}
Expand All @@ -442,7 +438,9 @@
min-height: 80vh;
}

.chatblock .d-none,
.chatblock .rawscript-chatblock-container,
.chatblock .rawscript-chatblock-editor button{
.chatblock .rawscript-chatblock-editor textarea,
.chatblock .rawscript-chatblock-editor button {
display: none;
}

0 comments on commit 2eb63d2

Please sign in to comment.