From 2eb63d296c9e0d035380cb04030635c529ee9513 Mon Sep 17 00:00:00 2001 From: cth-inni Date: Tue, 26 Oct 2021 12:26:11 +0800 Subject: [PATCH] Fix Hide debugger setting JS strip tags Fix text format detect Disable \@\# --- src/ChatBlock.php | 79 +++++++++++++++++++++++++++++++---------------- src/chatblock.css | 12 +++---- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/ChatBlock.php b/src/ChatBlock.php index 65de275..df281ec 100644 --- a/src/ChatBlock.php +++ b/src/ChatBlock.php @@ -51,6 +51,7 @@ function __construct($newObj=null) ]; // default setting $oriObj = [ + 'devTools' => false, 'allowForkScript' => null, 'chatHeaderSize' => 'normal', 'mainCastColor' => '#248bf5', @@ -164,7 +165,7 @@ public function showCasts(){ { $chatColor = $this->loadCastColor($cast['name']); $tempHtml .= '
'; - $tempHtml .= '
'.trim($cast['name']).'
'; + $tempHtml .= '
'.trim($cast['name']).'
'; $tempHtml .= '
'; } $tempHtml .= ''; @@ -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) { @@ -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]); @@ -552,7 +554,10 @@ public function render(){ } $tempHtml .= ''; $tempHtml .= ''; - $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='') @@ -673,15 +678,15 @@ private function render_rawdata($dialogue, $rawData) private function render_rawdata_full($dialogue, $rawData) { $ts = time(); - $tempHtml = '
'; + $tempHtml = '
'; $tempHtml .= '
'; - $tempHtml .= '显示原始对话剧本'; + $tempHtml .= 'Toggle Devtools'; if(isset($this->settings->allowForkScript)) { $tempHtml .= '
'; $tempHtml .= '
'; - $tempHtml .= '
'; - $tempHtml .= ''; + $tempHtml .= '
'; + $tempHtml .= ''; $tempHtml .= '
'; $tempHtml .= ''; } @@ -723,8 +728,7 @@ 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 = '
'; $tempHtml .= '

'.$sentence.'

'; $tempHtml .= '
'; @@ -732,17 +736,17 @@ private function render_text($dialogue) } private function render_heading($dialogue) { - $link = $this->fn_valid_link($dialogue['_line']); + $sentence = $this->fn_stripTags($dialogue['_context']); $tempHtml = '
'; $tempHtml .= '<'.strtolower($dialogue['_castname']).'>'; - $tempHtml .= $dialogue['_line']; + $tempHtml .= $sentence; $tempHtml .= ''; $tempHtml .= '
'; return $tempHtml; } private function md_render_heading($dialogue,$headingLevel) { - $sentence = ($dialogue['_context']); + $sentence = $this->fn_stripTags($dialogue['_context']); $tempHtml = '
'; $tempHtml .= ''; $tempHtml .= $sentence; @@ -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 @@ -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]}", $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]}", $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], "{$set2[2]} ", $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], "{$set2[2]} ", $newStr); + // } + // } // @,# - end $newStr = str_replace($this->linebreak,'
',$newStr); // Allow to multiples lines return trim($newStr); @@ -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 = '
'; $tempHtml .= '

'.$sentence.'

'; $tempHtml .= '
'; diff --git a/src/chatblock.css b/src/chatblock.css index 98a6b60..549a31e 100644 --- a/src/chatblock.css +++ b/src/chatblock.css @@ -383,8 +383,8 @@ .chatblock .casts-list{ display: flex; + flex-wrap: wrap; flex-direction: row; - /* flex-wrap: wrap; */ } .chatblock .casts-list .cast{ @@ -392,7 +392,7 @@ } .chatblock .casts-list .cast .square{ - /* opacity: 0.7; */ + opacity: 0.7; cursor: pointer; color: #FFF; text-shadow: 2px 2px #000; @@ -430,10 +430,6 @@ right: 10px; } -.chatblock .rawscript-chatblock-editor textarea{ - display: none; -} - .chatblock .rawscript-chatblock-container{ overflow: auto; } @@ -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; } \ No newline at end of file