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:
@@ -10,27 +10,31 @@ require_once 'document_model.php';
|
||||
// Default
|
||||
$insert_id = false;
|
||||
|
||||
if (!empty($name) && !(empty($content))) {
|
||||
// What it says - in Markdown (document_markdown), or as HTML (document_content)
|
||||
$api_markdown = documentMarkdownReady() && isset($_POST['document_markdown']) ? str_replace(["\r\n", "\r"], "\n", (string) $_POST['document_markdown']) : null;
|
||||
$api_content = $api_markdown === null ? (string) ($_POST['document_content'] ?? '') : '';
|
||||
|
||||
if (!empty($name) && ($api_markdown !== null ? trim($api_markdown) !== '' : $api_content !== '')) {
|
||||
|
||||
// Create document
|
||||
$insert_sql = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '', document_content_raw = '$content_raw', document_folder_id = $folder, document_created_by = 0, document_client_id = $client_id");
|
||||
$insert_sql = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '', document_content_raw = '', document_folder_id = $folder, document_created_by = 0, document_client_id = $client_id");
|
||||
|
||||
// Check insert & get insert ID
|
||||
if ($insert_sql) {
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
|
||||
$processed_content = mysqli_escape_string(
|
||||
$mysqli,
|
||||
saveBase64Images(
|
||||
$content,
|
||||
$_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/",
|
||||
"uploads/documents/",
|
||||
$insert_id
|
||||
)
|
||||
);
|
||||
// Pasted images become files of the document's - for Markdown, the HTML is made from it
|
||||
if ($api_markdown !== null) {
|
||||
$api_markdown = markdownSaveImages($api_markdown, $insert_id);
|
||||
$processed_html = markdownToHtml($api_markdown);
|
||||
} else {
|
||||
$processed_html = saveBase64Images($api_content, $_SERVER['DOCUMENT_ROOT'] . "/uploads/documents/", "uploads/documents/", $insert_id);
|
||||
}
|
||||
|
||||
// Document update content
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_content = '$processed_content' WHERE document_id = $insert_id");
|
||||
mysqli_query($mysqli, "UPDATE documents SET document_content = '" . mysqli_real_escape_string($mysqli, $processed_html) . "',
|
||||
document_content_raw = '" . escapeSql(documentContentRaw($_POST['document_name'] ?? '', $processed_html)) . "'" . documentMarkdownSet($api_markdown) . "
|
||||
WHERE document_id = $insert_id");
|
||||
|
||||
// Logging
|
||||
logAudit("Document", "Create", "$name via API ($api_key_name)", $client_id, $insert_id);
|
||||
|
||||
Reference in New Issue
Block a user