Lexer->addSpecialPattern('(?s:.*?)', $mode, 'plugin_pgpblock'); $this->Lexer->addSpecialPattern('(?s:.*?)', $mode, 'plugin_pgpblock'); $this->Lexer->addSpecialPattern('(?s:.*?)', $mode, 'plugin_pgpblock'); // Cannibalized Entry: Detect base64 payload subsets natively $this->Lexer->addSpecialPattern('(?s:.*?)', $mode, 'plugin_pgpblock'); } public function handle($match, $state, $pos, Doku_Handler $handler) { // Handle Base64 Tag parsing if (preg_match('/^(.*)<\/base64>$/is', $match, $matches)) { $clean_base64 = preg_replace('/\s+/', '', $matches[1]); return array('type' => 'base64', 'payload' => $clean_base64); } // Handle standard PGP Block parsing if (preg_match('/^<(pgp|gpg|pgpfile)(.*?)>(.*)<\/\1>$/is', $match, $matches)) { $tag = strtolower($matches[1]); $attr_str = $matches[2]; $text = trim($matches[3]); } else { return false; } $filename = ''; if (preg_match('/filename=["\']([^"\']+)["\']/i', $attr_str, $fn_match)) { $filename = $fn_match[1]; } return array('type' => 'pgp', 'text' => $text, 'tag' => $tag, 'filename' => $filename); } public function render($format, Doku_Renderer $renderer, $data) { if($format != 'xhtml' || $data === false) return false; // RENDER PIPELINE 1: The Cannibalized Base64 Rendering Logic if ($data['type'] === 'base64') { $base64_string = $data['payload']; if (empty($base64_string)) return true; $binary_data = base64_decode($base64_string, true); if ($binary_data === false) { $renderer->doc .= '
[Invalid Base64 Data Asset]
'; return true; } $mime_type = 'image/png'; if (class_exists('finfo')) { $finfo = new finfo(FILEINFO_MIME_TYPE); $mime_type = $finfo->buffer($binary_data); } if (strpos($mime_type, 'image/') === 0) { $renderer->doc .= '
'; $renderer->doc .= ' Embedded Image'; $renderer->doc .= '
'; } else { $renderer->doc .= '
[Unsupported MIME Type: ' . hsc($mime_type) . ']
'; } return true; } // RENDER PIPELINE 2: Standard PGP UI Interfaces $text = $data['text']; $tag = $data['tag']; $filename = $data['filename']; $is_encrypted = (strpos(trim($text), '-----BEGIN PGP MESSAGE-----') === 0) || (strpos($text, '-----BEGIN PGP MESSAGE-----') !== false); $encoded_text = hsc($text); if ($is_encrypted) { $is_file = ($tag === 'pgpfile'); $type_class = $is_file ? 'pgp-type-file' : 'pgp-type-text'; $title = $is_file ? '📦 Encrypted File' : '📄 Encrypted Text'; if ($is_file && $filename) $title .= ': ' . hsc($filename); $renderer->doc .= '
'; $renderer->doc .= '
'; $renderer->doc .= ' ' . $title . ''; $renderer->doc .= '
'; $renderer->doc .= ' '; $renderer->doc .= ' '; $renderer->doc .= '
'; $renderer->doc .= '
'; $renderer->doc .= '
'; $renderer->doc .= '
' . $encoded_text . '
'; $renderer->doc .= ' '; $renderer->doc .= '
'; $renderer->doc .= '
'; } else { $renderer->doc .= '
' . $encoded_text . '
'; } return true; } }