Files
wevads-platform/scripts/hamid-generate.php
2026-02-26 04:53:11 +01:00

60 lines
2.6 KiB
PHP
Executable File

<?php
error_reporting(0); ini_set("display_errors",0);
header('Content-Type: application/json');
error_reporting(0);
$outputDir = '/opt/wevads/public/hamid-files/';
if (!is_dir($outputDir)) mkdir($outputDir, 0755, true);
try {
$input = json_decode(file_get_contents('php://input'), true);
$type = strtolower($input['type'] ?? 'pdf');
$title = $input['title'] ?? 'Document';
$content = $input['content'] ?? '';
$timestamp = date('Ymd_His');
$safeName = preg_replace('/[^a-zA-Z0-9_-]/', '_', mb_substr($title, 0, 40));
$filename = $timestamp . '_' . $safeName;
$htmlContent = $content;
$htmlContent = preg_replace('/^### (.+)$/m', '<h3>$1</h3>', $htmlContent);
$htmlContent = preg_replace('/^## (.+)$/m', '<h2>$1</h2>', $htmlContent);
$htmlContent = preg_replace('/^# (.+)$/m', '<h1>$1</h1>', $htmlContent);
$htmlContent = preg_replace('/\*\*(.+?)\*\*/', '<strong>$1</strong>', $htmlContent);
$htmlContent = preg_replace('/\*(.+?)\*/', '<em>$1</em>', $htmlContent);
$htmlContent = preg_replace('/`(.+?)`/', '<code>$1</code>', $htmlContent);
$htmlContent = nl2br($htmlContent);
switch ($type) {
case 'pdf':
$filename .= '.pdf';
$filepath = $outputDir . $filename;
$html = '<!DOCTYPE html><html data-theme="dark"><head><meta charset="UTF-8">
<style>
body{font-family:DejaVu Sans,Arial,sans-serif;font-size:11pt;line-height:1.7;color:#333;margin:40px}
.header{text-align:center;border-bottom:3px solid #d4a574;padding-bottom:20px;margin-bottom:30px}
.header h1{color:#5d4e37;font-size:24pt;margin:0}
.header .date{color:#999;font-size:10pt}
h1{color:#5d4e37;font-size:18pt;border-bottom:2px solid #d4a574;padding-bottom:8px;margin-top:25px}
h2{color:#7a6b5a;font-size:14pt;margin-top:20px;border-left:4px solid #d4a574;padding-left:12px}
h3{color:#8a7b6a;font-size:12pt}
p{margin:12px 0;text-align:justify}
ul,ol{margin:15px 0 15px 30px}
li{margin:8px 0}
code{background:#f5ebe0;padding:2px 8px;border-radius:4px;font-family:monospace}
pre{background:#2d2a26;color:#f5ebe0;padding:15px;border-radius:8px;white-space:pre-wrap}
table{border-collapse:collapse;width:100%;margin:20px 0}
th{background:#d4a574;color:white;padding:12px}
td{border:1px solid #ddd;padding:10px}
.footer{text-align:center;font-size:9pt;color:#999;margin-top:40px;padding-top:20px;border-top:1px solid #eee}
</style>
</head><body>
<div class="header"><h1>' . htmlspecialchars($title) . '</h1><div class="date">Genere par WEVAL MIND - ' . date('d/m/Y H:i') . '</div></div>
<div class="content">' . $htmlContent . '</div>
<div class="footer">WEVAL MIND - Assistant IA Expert WEVAL</div>
</body></html>