# BLOG_ADMIN_CONTEXT.md
# VerifyDocs — Blog CMS & Admin Panel
# Append this section to PROJECT_CONTEXT.md (str_replace the pending section)

## 16. Blog CMS — Architecture

### New Directory Layout (inside verifydocs-blog/)
```
verifydocs-blog/
├── public/                  ← Apache DocumentRoot
│   ├── .htaccess            ← All routes → index.php; static served directly
│   ├── index.php            ← Public router
│   ├── css/blog.css         ← All public blog styles
│   ├── js/blog.js           ← Scroll reveal, TOC, lead form AJAX
│   ├── admin/
│   │   ├── css/admin.css    ← Admin panel stylesheet (copy of admin/css/)
│   │   └── js/
│   │       ├── admin.js     ← Toast, modal, adminApi() helper
│   │       └── editor.js    ← Rich text editor, SEO preview, slug, save
│   └── uploads/blog/        ← Featured image uploads (writable)
├── includes/
│   ├── config.php           ← DB constants, db(), h(), slugify(), helpers
│   ├── header.php           ← Public <head> + site-header
│   └── footer.php           ← Public footer + JS include
├── pages/
│   ├── blog-list.php        ← Public listing (paginated, filtered)
│   ├── blog-single.php      ← Single post (TOC, lead form, author, related)
│   ├── lead-handler.php     ← POST /lead → INSERT blog_leads
│   └── 404.php
├── admin/
│   ├── index.php            ← Admin router + auth gate
│   ├── includes/
│   │   ├── layout-head.php  ← Admin <head> + sidebar
│   │   └── layout-foot.php  ← Admin toast/modal + JS
│   ├── css/admin.css        ← Source admin stylesheet
│   ├── js/
│   │   ├── admin.js
│   │   └── editor.js
│   └── pages/
│       ├── login.php
│       ├── dashboard.php
│       ├── blog-list.php
│       ├── blog-editor.php  ← Create + Edit (4 tabs)
│       ├── pricing.php
│       ├── leads.php
│       ├── settings.php
│       └── api/
│           ├── blogs-save.php
│           ├── blogs-delete.php
│           ├── blogs-status.php
│           ├── pricing-save.php
│           └── upload-image.php
└── database/
    └── schema.sql           ← Full DB schema + sample data
```

## 17. URL Routes (Public)

| URL | Handler |
|-----|---------|
| `/` or `/blog` | blog-list.php (all posts) |
| `/blog/page/2` | blog-list.php paginated |
| `/blog/category/{slug}` | blog-list.php filtered by category |
| `/blog/tag/{slug}` | blog-list.php filtered by tag |
| `/blog/{post-slug}` | blog-single.php |
| `/lead` POST | lead-handler.php |
| `/admin` | admin/index.php → dashboard |
| `/admin/login` | admin login page |
| `/admin/blogs` | admin blog list |
| `/admin/blogs/create` | blog editor (new) |
| `/admin/blogs/edit/{id}` | blog editor (edit) |
| `/admin/pricing` | pricing manager |
| `/admin/leads` | leads table |
| `/admin/settings` | password change |
| `/admin/api/*` | JSON endpoints |

## 18. Database Tables

| Table | Purpose |
|-------|---------|
| `admins` | Admin users (bcrypt password) |
| `categories` | Blog categories with color |
| `tags` | Blog tags |
| `posts` | Blog posts (full SEO fields, author fields) |
| `post_tags` | Pivot: post ↔ tag |
| `api_pricing` | 16 API pricing rows (editable from admin) |
| `blog_leads` | Lead capture from blog forms |

## 19. Admin Credentials (Default)
- Email: `admin@verifydocs.in`
- Password: `Admin@123`
- **Change immediately in production** via Settings → Change Password
- Hash stored with `password_hash($pass, PASSWORD_DEFAULT)`

## 20. Key Functions (config.php)
- `db()` — singleton PDO connection
- `h($s)` — htmlspecialchars wrapper
- `slugify($text)` — URL-safe slug
- `reading_time($content)` — word count / 200
- `time_ago($datetime)` — human-readable diff
- `redirect($url)` — header Location + exit
- `cat_color($cat)` — returns hex color for category name
- `admin_logged_in()` — checks `$_SESSION['admin_id']`
- `require_auth()` — redirects to login if not authed
- `current_admin()` — returns admin row from DB (cached)

## 21. Setup Instructions (cPanel)

1. **Create DB**: `verifydocs_blog` (utf8mb4_unicode_ci)
2. **Import schema**: `database/schema.sql` via phpMyAdmin
3. **Upload files**: contents of `verifydocs-blog/` to your hosting root
4. **Set DocumentRoot**: point to `public/` subfolder (or use subdomain)
5. **Edit `includes/config.php`**: set `DB_HOST`, `DB_USER`, `DB_PASS`, `SITE_URL`
6. **Writable**: `chmod 755 public/uploads/blog/`
7. **Enable mod_rewrite** (standard on cPanel)
8. **Test**: visit `/admin/login` → `admin@verifydocs.in` / `Admin@123`

## 22. What's DONE ✅

- [x] Database schema — all 7 tables with sample data
- [x] Public router (clean URLs, no .php)
- [x] Public blog listing — hero, filter bar, card grid, pagination
- [x] Single blog post — hero, TOC, article, share, author, related
- [x] Lead capture form — AJAX POST → blog_leads table
- [x] Admin login — bcrypt, session, toggle password visibility
- [x] Admin dashboard — stats, recent posts, top posts, recent leads
- [x] Admin blog list — search, filter, pagination, quick publish/delete
- [x] Admin blog editor — 4 tabs: Content / SEO / Settings / Schema
  - Rich text editor (contentEditable + execCommand toolbar)
  - HTML source mode toggle
  - Auto-slug from title
  - Live Google Search Preview
  - SEO score ring (0–100)
  - Char counters for meta title/desc
  - OG + Twitter card fields
  - Tag multi-select with visual state
  - Featured image upload (drag-drop, 2MB, AJAX)
  - Author info fields
  - Auto-save every 60s
  - JSON-LD schema editor with auto-generate + validate
- [x] Admin API pricing manager — editable table, enable/disable toggles
- [x] Admin leads table — with CSV export
- [x] Admin settings — change password
- [x] Admin AJAX API endpoints (blogs-save, delete, status, pricing-save, upload-image)

## 23. What's LEFT / Future Work 🔲

- [ ] **Category management page** (`/admin/categories`) — add/edit/delete categories + colors
- [ ] **Tag management page** (`/admin/tags`) — add/edit/delete tags
- [ ] **Duplicate post** — clone a post as draft
- [ ] **Scheduled publishing** — cron job to auto-publish scheduled posts
- [ ] **Blog search** — public-facing search box (FULLTEXT index already in schema)
- [ ] **RSS feed** — `/blog/feed.xml`
- [ ] **Sitemap** — `/sitemap.xml` for all published posts
- [ ] **Image resize** — auto-resize uploaded images to 1200×630 (needs GD/Imagick)
- [ ] **Dark mode** for admin (CSS variable swap)
- [ ] **Draft autosave to localStorage** — survive browser crash
- [ ] **Post duplication** API endpoint
- [ ] **Admin user management** — add/edit/delete admins (super role only)
- [ ] **Blog analytics** — simple view counter chart on dashboard
- [ ] **Comment system** — optional Disqus or native
- [ ] **Email notification** on new lead

## 24. CSS Asset Serving Note

Admin CSS/JS files are in two places:
- Source: `admin/css/admin.css`, `admin/js/*.js`
- Served from: `public/admin/css/admin.css`, `public/admin/js/*.js`

**After editing source files, copy to public/admin/**: 
```bash
cp admin/css/admin.css public/admin/css/admin.css
cp admin/js/admin.js   public/admin/js/admin.js
cp admin/js/editor.js  public/admin/js/editor.js
```

Or symlink on Linux: `ln -s ../../admin/css/admin.css public/admin/css/admin.css`
