register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader'); // ADD THIS NEW HOOK: Intercepts custom AJAX signals globally $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call'); } public function handle_metaheader(Doku_Event $event, $param) { $plugin_url = DOKU_BASE . 'lib/plugins/pgpblock/'; $event->data['script'][] = array( 'type' => 'text/javascript', '_data' => 'window.PGPBLOCK_SECTOK = ' . json_encode(getSecurityToken()) . ';', '_inline' => true ); $event->data['script'][] = array( 'type' => 'text/javascript', 'src' => $plugin_url . 'utils.js', 'defer' => 'defer', '_inline' => false ); $event->data['script'][] = array( 'type' => 'text/javascript', 'src' => $plugin_url . 'view.js', 'defer' => 'defer', '_inline' => false ); $event->data['script'][] = array( 'type' => 'text/javascript', 'src' => $plugin_url . 'editor.js', 'defer' => 'defer', '_inline' => false ); } // New function that processes the text rendering completely bypasses remote.php public function handle_ajax_call(Doku_Event $event, $param) { if ($event->data !== 'plugin_pgpblock_parsePlaintext') return; // Stop DokuWiki from throwing an "unknown call" error $event->preventDefault(); $event->stopPropagation(); // Security check: the caller must have read access to the page and a valid session token $id = cleanID(isset($_POST['id']) ? (string) $_POST['id'] : ''); if ($id === '' || auth_quickaclcheck($id) < AUTH_READ) { http_response_code(403); echo "Access Denied"; return; } global $INPUT; if (trim((string) $INPUT->server->str('REMOTE_USER')) !== '') { $sectok = isset($_POST['sectok']) ? (string) $_POST['sectok'] : ''; if ($sectok === '' || !hash_equals(getSecurityToken(), $sectok)) { http_response_code(403); echo "Access Denied"; return; } } // Pull incoming raw text array safely from the jQuery POST request $args = $_POST['args'] ?? []; $text = $args[0] ?? ''; if (!is_string($text)) $text = ''; // Run through full Dokuwiki parser pipeline into XHTML format $info = array(); $html_output = p_render('xhtml', p_get_instructions($text), $info); // Print the data out cleanly to the AJAX response channel echo $html_output; } }