# Damalion Blog AI — WordPress Plugin

Automated blog post generation for [Damalion](https://www.damalion.com). Generates AI-powered satellite articles about Luxembourg holding structures (SOPARFI, SPF) applied to private equity sectors, with full SEO, featured images, internal linking, WPML multi-language support, and Google spam policy compliance.

## Features

- **AI Content Generation** — Uses OpenAI (GPT-4o-mini / GPT-4o) to produce 900–1,300 word professional legal/tax articles
- **Featured Image Generation** — DALL-E 3 images (950×762px) with full WP Media metadata (alt, title, caption, description)
- **Content Validation** — Regex-based validator enforces CTA placement, banned words, internal links, word count, and JSON schema
- **Internal Linking** — Automatic pillar link near top + 3 satellite links in "Related technical notes" section (no orphan pages)
- **Sitemap Parsing** — Fetches `sitemap.xml` to build a link registry for satellite URL selection
- **WPML-Aware** — Generates posts in up to 5 languages and links translations
- **Scheduling** — Configurable posting days (Mon/Wed/Sat default) and times (Luxembourg timezone)
- **Google Compliance** — Rotated themes, varied intros, banned buzzwords, practical case studies, human writing style
- **Logging** — Full audit trail with date, theme, title, post ID, validation results, and retry counts
- **Retry Logic** — Up to 3 retries with targeted fixes (link reselection, content regeneration)

## Installation

1. Upload the `damalion-blog-ai` folder to `/wp-content/plugins/`
2. Activate the plugin via WordPress admin → Plugins
3. Go to **Damalion Blog AI** in the admin menu
4. Enter your OpenAI API key
5. Configure subjects, languages, posting schedule
6. Click **Refresh Sitemap** to populate the link registry
7. Click **Generate 1 Post** to test, or **Run Daily Batch** for a full run

## Shortcode

Display generated blog posts on any page:

```
[damalion_blog limit="10"]
[damalion_blog subject="soparfi" limit="5"]
[damalion_blog language="fr" limit="8"]
```

## Configuration

### Subjects
- **SOPARFI** — Luxembourg Holding Company
- **SPF** — Family Holding Company
- **Family Holding Company**
- **Private Wealth Management**

### Themes (17 sectors)
Artificial Intelligence, Data Centers, Cybersecurity, Healthcare Technology, Fintech, Power & Energy, Semiconductors, Pharma & Biotech, Private Credit, Real Estate, Professional Services, Renewable Energy, Senior Living, Petcare, Insurance, Rare Minerals, Software/SaaS

### Posting Schedule
Default: Monday, Wednesday, Saturday at 09:10, 11:20, 13:30, 15:40, 17:50 (Europe/Luxembourg)

## Requirements

- WordPress 5.6+
- PHP 7.4+
- OpenAI API key (for GPT-4o-mini and DALL-E 3)
- WPML (optional, for multi-language support)

## File Structure

```
damalion-blog-ai/
├── damalion-blog-ai.php        # Main plugin file
├── includes/
│   ├── class-admin.php          # Settings page + dashboard
│   ├── class-ajax.php           # AJAX handlers
│   ├── class-frontend.php       # Frontend display + SEO
│   ├── class-image-generator.php # DALL-E image generation
│   ├── class-logger.php         # Database logging
│   ├── class-openai.php         # OpenAI API integration
│   ├── class-post-creator.php   # Post creation pipeline
│   ├── class-scheduler.php      # WP-Cron scheduling
│   ├── class-sitemap.php        # Sitemap parser + link registry
│   └── class-validator.php      # Content validation (regex)
├── assets/
│   ├── css/admin.css
│   ├── css/frontend.css
│   └── js/admin.js
└── README.md
```

## Validation Rules

Every generated post is validated before publishing:

1. Valid JSON parse
2. All required fields present
3. Banned words check (recoupment, paradigm, ecosystem, synergies, leveraging, optimization, framework)
4. CTA appears exactly once and is the last HTML block
5. Pillar link within first 1,200 characters
6. "Related technical notes" section with exactly 3 satellite links
7. Word count: 900–1,300 (excluding CTA)
