# Sitemap Generator Plugin for Xiuno BBS

**Version:** 1.0.2  
**Author:** Xiuno Community  
**License:** MIT

## Description

Generates static XML sitemap files for your Xiuno BBS forum to improve SEO and search engine indexing. This plugin creates **actual sitemap.xml files saved to disk**, not dynamic generation. This approach is much more efficient and can handle forums with 100,000+ threads without performance issues.

**🆕 NEW:** Automatic hourly updates! The plugin now updates sitemaps automatically every hour using Xiuno's built-in cron system. **No external cron job required!**

## Features

- ✅ **Automatic hourly updates** - Regenerates sitemaps every hour automatically
- ✅ **No cron job needed** - Uses Xiuno's internal cron system
- ✅ **Static file generation** - Creates actual XML files on disk
- ✅ **Paginated for large sites** - Handles unlimited threads (5000 per file)
- ✅ **Multiple sitemap files** - Organized by content type
- ✅ **SEO optimized** - Proper priority and update frequency
- ✅ **Standards compliant** - Follows sitemaps.org protocol
- ✅ **Performance friendly** - No server load, files served instantly
- ✅ **Simple CLI tool** - Can still run manually if needed

## Sitemap Structure

The plugin generates multiple sitemap files:

### Main Sitemap Index
**URL:** `https://yoursite.com/sitemap.xml`

This is the main entry point that links to all other sitemaps.

### Sub-Sitemaps

1. **sitemap-static.xml** - Static pages (homepage, docs, downloads)
2. **sitemap-forums.xml** - All forum categories
3. **sitemap-threads-0.xml** - First 5,000 threads
4. **sitemap-threads-1.xml** - Next 5,000 threads (if needed)
5. ... and so on

## Installation

### Method 1: Download and Extract

1. Download the plugin tar.gz file
2. Extract to your `/plugin/` directory
3. You should have: `/plugin/xn_dynamic_sitemap/`

### Method 2: Manual Installation via SSH

```bash
cd /path/to/xiuno/public_html/plugin/
# Upload or extract xn_dynamic_sitemap folder here
```

## Usage

### Automatic Updates (Default)

**The plugin updates automatically every hour!** Once installed, sitemaps will regenerate hourly using Xiuno's built-in cron system. No configuration needed.

**Configuration:**

You can customize auto-update settings in `conf.json`:

```json
"setting": {
    "threads_per_file": 5000,
    "auto_update": 1,           // 1 = enabled, 0 = disabled
    "update_interval": 3600     // Seconds between updates (3600 = 1 hour)
}
```
External Cron Job (Optional)

**Note:** With automatic hourly updates, external cron jobs are **optional**. Only use if you need a specific schedule different from hourly.

To keep sitemaps updated on a custom schedule (default, recommended)
- `7200` - Every 2 hours
- `14400` - Every 4 hours
- `86400` - Daily

To disable auto-updates, set `"auto_update": 0` in conf.json.

### Manual Generation (Optional)

You can still manually regenerate sitemaps anytime:

```bash
cd /path/to/xiuno/public_html
php plugin/xn_dynamic_sitemap/simple_generator.php
```

This will generate:
- `sitemap.xml` - Main sitemap index
- `sitemap-static.xml` - Static pages
- `sitemap-forums.xml` - Forum categories
- `sitemap-threads-0.xml` - Thread listings (paginated)

### Automate with Cron

To keep sitemaps upated, add a cron job:

```bash
# Regenerate sitemap daily at 2 AM
0 2 * * * cd /path/to/xiuno/public_html && php plugin/xn_dynamic_sitemap/simple_generator.php >> /dev/null 2>&1
```

Or regenerate weekly:

```bash
# Regenerate sitemap every Sunday at 3 AM
0 3 * * 0 cd /path/to/xiuno/public_html && php plugin/xn_dynamic_sitemap/simple_generator.php >> /dev/null 2>&1
```

### Submit to Search Engines

#### Google Search Console
1. Go to https://search.google.com/search-console
2. Select your property
3. Navigate to Sitemaps
4. Enter: `sitemap.xml`
5. Click "Submit"

#### Bing Webmaster Tools
1. Go to https://www.bing.com/webmasters
2. Select your site
3. Go to Sitemaps
4. Enter: `https://yoursite.com/sitemap.xml`
5. Click "Submit"

#### robots.txt
Add this line to your robots.txt file:
```
Sitemap: https://yoursite.com/sitemap.xml
```

## Configuration

### Settings (Admin Panel)

- **Max Threads per Sitemap**: Default 5000 (adjust based on site size)
- **Include Users**: Include user profile pages (disabled by default)
- **Cache Time**: How long to cache sitemap (3600 seconds / 1 hour)

### Manual Configuration

Edit `conf.json` in the plugin folder:

```json
{
  "setting": {
    "max_threads": 5000,
    "include_users": 0,
    "cache_time": 3600
  }
}
```

## Performance

The plugin is optimized for performance:

- **Efficient queries** - Uses indexed fields only
- **Pagination** - Splits large sitemaps for faster processing
- **Caching** - Results can be cached (optional)
- **Minimal overhead** - Only runs when sitemap is accessed

## SEO Best Practices

### Priority Levels Used

- **1.0**: Homepage
- **0.9**: Forum index, documentation hub
- **0.8**: Forums, documentation pages
- **0.7**: Downloads section
- **0.6**: Individual threads

### Update Frequency

- **Daily**: Homepage, forum index, forum categories
- **Weekly**: Download pages, threads
- **Monthly**: Documentation, static pages

## Troubleshooting

### Sitemap not accessible

1. Check that plugin is enabled in Admin Panel
2. Clear cache: `rm -rf tmp/*`
3. Check .htaccess for rewrite rules
4. Verify web server has read permissions

### Empty sitemap

1. Ensure you have forums and threads created
2. Check database connection
3. Look for PHP errors in error logs

### Search engines not indexing

1. Submit sitemap manually to search consoles
2. Verify robots.txt allows crawling
3. Check for manual penalties in search console
4. Ensure site is publicly accessible

## Compatibility

- **Xiuno BBS**: 4.0.0+
- **PHP**: 7.1+ (tested on 8.x)
- **MySQL**: 5.5+
- **Web Server**: Apache (with mod_rewrite) or Nginx

## Changelog

### Version 1.0.0 (2026-04-06)
- Initial release
- Basic sitemap generation
- Support for forums, threads, and static pages
- Pagination for large sites
- SEO optimization

## Contributing

Found a bug or have a feature request? 

- Post in [Bug Reports](https://xiuno.wiki/forum.php?fid=5)
- Suggest features in [Feature Requests](https://xiuno.wiki/forum.php?fid=6)
- Contribute code in [Development](https://xiuno.wiki/forum.php?fid=7)

## License

MIT License - Free to use, modify, and distribute

## Support

- 📖 [Documentation](https://xiuno.wiki/docs/)
- 💬 [Community Forum](https://xiuno.wiki/forum.php)
- 🐛 [Report Issues](https://xiuno.wiki/forum.php?fid=5)

## Credits

Developed by the Xiuno Community for Xiuno BBS

---

**Enjoy better SEO with Dynamic Sitemap Generator!** 🚀
