import os import glob import re base_dir = os.path.dirname(os.path.abspath(__file__)) def create_php_scripts(): # process_form.php process_php = """ $value) { // Skip hidden fields used for configuration if (in_array($key, ['_next', '_subject', '_captcha'])) continue; $clean_key = str_replace('_', ' ', ucfirst($key)); $message .= "{$clean_key}: " . htmlspecialchars($value) . "\\n"; } // Set headers $reply_to = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_SANITIZE_EMAIL) : 'noreply@hafizpublications.com'; $headers = "From: website@hafizpublications.com\\r\\n"; $headers .= "Reply-To: {$reply_to}\\r\\n"; // Send email if (mail($to, $subject, $message, $headers)) { $next = isset($_POST['_next']) ? $_POST['_next'] : 'thanks.html'; header("Location: " . $next); exit(); } else { echo "Error sending email. Please make sure PHP mail() is enabled on your server."; } } else { echo "Invalid request."; } ?>""" with open(os.path.join(base_dir, 'process_form.php'), 'w', encoding='utf-8') as f: f.write(process_php) # subscribe.php subscribe_php = """""" with open(os.path.join(base_dir, 'subscribe.php'), 'w', encoding='utf-8') as f: f.write(subscribe_php) def create_thanks_page(): thanks_html = """ Thank You | Hafiz Publications

Thank You!

Your submission has been received successfully. We will get back to you within 24 hours.

Return to Homepage
""" with open(os.path.join(base_dir, 'thanks.html'), 'w', encoding='utf-8') as f: f.write(thanks_html) def update_html_forms(): html_files = glob.glob(os.path.join(base_dir, "*.html")) + glob.glob(os.path.join(base_dir, "blog", "*.html")) count = 0 for f_path in html_files: with open(f_path, 'r', encoding='utf-8') as f: content = f.read() is_blog = "blog" in os.path.relpath(f_path, base_dir).split(os.sep) prefix = "../" if is_blog else "" # 1. Update contact.html form action if 'contactForm' in content: content = content.replace('action="https://formsubmit.co/hafizpublications@gmail.com"', f'action="{prefix}process_form.php"') content = content.replace('value="https://hafizpublications.com/contact.html"', f'value="{prefix}thanks.html"') # 2. Update Newsletter form action in footers content = content.replace('action="https://formsubmit.co/hafizpublications@gmail.com"', f'action="{prefix}subscribe.php"') with open(f_path, 'w', encoding='utf-8') as f: f.write(content) count += 1 print(f"Updated actions in {count} HTML files.") def update_popup_js(): popup_path = os.path.join(base_dir, 'js', 'popup.js') if not os.path.exists(popup_path): return with open(popup_path, 'r', encoding='utf-8') as f: content = f.read() content = content.replace('action="https://formsubmit.co/hafizpublications@gmail.com"', 'action="process_form.php"') content = content.replace('value="https://hafizpublications.com/"', 'value="thanks.html"') with open(popup_path, 'w', encoding='utf-8') as f: f.write(content) print("Updated popup.js") if __name__ == "__main__": create_php_scripts() create_thanks_page() update_html_forms() update_popup_js()