mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
Documents in Markdown: a document can be written in Markdown with Write and Preview or in the rich text editor and switched either way, pictures pasted or dropped into the Markdown are kept as files, New Document starts in the way last used, Import Markdown Files beside Upload makes a document from each .md file, a Markdown button beside PDF downloads a document as a .md file, and Markdown pasted into a document's rich text editor goes in as formatting; versions, restore, copy and the API carry the Markdown, and the API's document create and update no longer escape values twice; database 4.2.3 adds documents.document_markdown and document_versions.document_version_markdown, and league/commonmark 2.10 and league/html-to-markdown 5.2 are added to libs/vendor through composer; 26.12.3 changelog entries
This commit is contained in:
@@ -14,7 +14,7 @@ if (!empty($document_id)) {
|
||||
// 1) Load the current document (scoped to this client)
|
||||
$sql_original_document = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT document_content, document_created_at, document_created_by, document_description,
|
||||
"SELECT document_content, " . documentMarkdownSql() . ", document_created_at, document_created_by, document_description,
|
||||
document_name, document_updated_at, document_updated_by FROM documents
|
||||
WHERE document_client_id = $client_id
|
||||
AND document_id = $document_id
|
||||
@@ -53,7 +53,8 @@ if (!empty($document_id)) {
|
||||
"INSERT INTO document_versions SET
|
||||
document_version_name = '$original_document_name',
|
||||
document_version_description = '$original_document_description',
|
||||
document_version_content = '$original_document_content',
|
||||
document_version_content = '$original_document_content'
|
||||
" . documentMarkdownSet($row['document_markdown'], 'document_version_markdown') . ",
|
||||
document_version_created_by = $document_version_created_by,
|
||||
document_version_created_at = '$document_version_created_at',
|
||||
document_version_document_id = $document_id"
|
||||
@@ -75,27 +76,24 @@ if (!empty($document_id)) {
|
||||
// Assign variables from POST or fallback to DB
|
||||
require_once 'document_model.php';
|
||||
|
||||
// Process NEW HTML content: save base64 images to /uploads/documents/<document_id>/
|
||||
// In-app uses $_POST['content'] as raw; in API you likely map to $content in document_model.php
|
||||
$raw_post_content = $content;
|
||||
// What it says now - given in Markdown (document_markdown), as HTML (document_content), or
|
||||
// left as it was. Pictures sent as data become files of the document's.
|
||||
$api_markdown = $row['document_markdown'];
|
||||
if (documentMarkdownReady() && isset($_POST['document_markdown'])) {
|
||||
$api_markdown = markdownSaveImages(str_replace(["\r\n", "\r"], "\n", (string) $_POST['document_markdown']), $document_id);
|
||||
$processed_html = markdownToHtml($api_markdown);
|
||||
} elseif (isset($_POST['document_content'])) {
|
||||
$api_markdown = null;
|
||||
$processed_html = saveBase64Images((string) $_POST['document_content'], $_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/", "uploads/documents/", $document_id);
|
||||
} else {
|
||||
$processed_html = (string) $row['document_content'];
|
||||
}
|
||||
|
||||
$processed_html = saveBase64Images(
|
||||
$raw_post_content,
|
||||
$_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/",
|
||||
"uploads/documents/",
|
||||
$document_id
|
||||
);
|
||||
|
||||
// Escape for DB
|
||||
// Escaped once, for the query - the model's $name and $description already are
|
||||
$content_db = mysqli_real_escape_string($mysqli, $processed_html);
|
||||
|
||||
// Rebuild content_raw for full-text search (same technique as app)
|
||||
$content_raw = escapeSql($name . " " . str_replace("<", " <", $processed_html));
|
||||
$content_raw = mysqli_real_escape_string($mysqli, $content_raw);
|
||||
|
||||
// Escape name/description too (document_model.php may already sanitize; do DB escaping here regardless)
|
||||
$name_db = mysqli_real_escape_string($mysqli, $name);
|
||||
$description_db = mysqli_real_escape_string($mysqli, $description);
|
||||
$content_raw = escapeSql(documentContentRaw($_POST['document_name'] ?? $row['document_name'], $processed_html));
|
||||
$name_db = $name;
|
||||
$description_db = $description;
|
||||
$folder_id = intval($folder);
|
||||
|
||||
// 4) Update the document (IMPORTANT: proper WHERE + scope to client)
|
||||
@@ -108,6 +106,7 @@ if (!empty($document_id)) {
|
||||
document_content_raw = '$content_raw',
|
||||
document_folder_id = $folder_id,
|
||||
document_updated_by = 0
|
||||
" . documentMarkdownSet($api_markdown) . "
|
||||
WHERE document_id = $document_id
|
||||
AND document_client_id = $client_id
|
||||
LIMIT 1"
|
||||
|
||||
Reference in New Issue
Block a user