# SmartDoc to Post Importer

A professional WordPress plugin for importing Microsoft Word documents with 100% formatting preservation.

## Features

- **Complete Formatting Preservation**: Maintains all text formatting including bold, italic, underline, and colors
- **Structure Support**: Preserves headings (H1-H6), paragraphs, and document hierarchy
- **Advanced Lists**: Converts both bulleted and numbered lists with proper nesting
- **Link Preservation**: Maintains all hyperlinks with proper URLs
- **Image Import**: Automatically uploads and embeds images from Word documents
- **Table Support**: Preserves complex table layouts and formatting
- **SEO Optimization**: Automatically extracts meta titles and descriptions
- **Multiple Post Types**: Import as posts, pages, or custom post types
- **Security First**: All uploads are validated and sanitized

## Requirements

- WordPress 5.0 or higher
- PHP 7.4 or higher
- ZipArchive PHP extension
- DOMDocument PHP extension
- File uploads enabled
- Maximum upload size: 10MB minimum

## Installation

1. Upload the plugin files to `/wp-content/plugins/smartdoc-to-post-importer/`
2. Activate the plugin through the WordPress admin
3. Navigate to 'SmartDoc to Post Importer' in your admin menu
4. Upload your Word document and follow the import wizard

## Supported Formats

- Microsoft Word 2007+ (.docx)
- Microsoft Word 97-2003 (.doc)
- Maximum file size: 10MB

## File Structure

```
smartdoc-to-post-importer/
├── smartdoc-to-post-importer.php  # Main plugin file
├── readme.txt                     # WordPress.org readme
├── README.md                      # This file
├── includes/                      # Core functionality
│   ├── class-admin.php           # Admin interface
│   ├── class-word-parser.php     # Word document parser
│   ├── class-importer.php        # WordPress importer
│   └── functions.php             # Utility functions
├── assets/                        # Frontend assets
│   ├── css/
│   │   └── admin.css             # Admin styles
│   └── js/
│       └── admin.js              # Admin JavaScript
└── languages/                     # Translation files
    └── smartdoc-to-post-importer.pot     # Translation template
```

## Usage

1. **Upload Document**: Select a .docx or .doc file from your computer
2. **Preview Content**: Review the parsed content with preserved formatting
3. **Configure Import**: Set post title, type, category, and SEO meta data
4. **Import**: Click import to create your WordPress post/page

## Technical Details

### Word Document Parsing

The plugin uses advanced XML parsing to process Word documents:

- Extracts content from `word/document.xml`
- Processes relationships from `word/_rels/document.xml.rels`
- Parses styles from `word/styles.xml`
- Handles numbering from `word/numbering.xml`

### Security Features

- File type validation
- File size limits
- Content sanitization
- XSS prevention
- SQL injection protection
- Nonce verification
- Capability checks
- Temporary file cleanup

### Performance Optimizations

- Efficient XML parsing
- Memory-conscious image processing
- Optimized database queries
- Temporary file management
- Error handling and recovery

## SEO Plugin Compatibility

The plugin automatically integrates with popular SEO plugins:

- **Yoast SEO**: Sets `_yoast_wpseo_title` and `_yoast_wpseo_metadesc`
- **RankMath**: Sets `rank_math_title` and `rank_math_description`
- **All in One SEO**: Sets `_aioseo_title` and `_aioseo_description`

## Hooks and Filters

### Actions

```php
// Before document parsing
do_action('smartdocpost_before_parse_document', $file_path);

// After successful import
do_action('smartdocpost_after_import', $post_id, $parsed_content);

// Before content sanitization
do_action('smartdocpost_before_sanitize_content', $content);
```

### Filters

```php
// Modify allowed HTML tags
$allowed_html = apply_filters('smartdocpost_allowed_html_tags', $allowed_html);

// Modify post data before import
$post_data = apply_filters('smartdocpost_import_post_data', $post_data, $parsed_content);

// Modify parsed content
$content = apply_filters('smartdocpost_parsed_content', $content, $document);
```

## Development

### Setting up Development Environment

1. Clone the repository
2. Install WordPress in a local environment
3. Symlink or copy the plugin to `wp-content/plugins/`
4. Activate the plugin
5. Enable WordPress debugging:

```php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
```

### Code Standards

- Follow WordPress Coding Standards
- Use proper sanitization and validation
- Include comprehensive documentation
- Write unit tests for critical functions
- Use semantic versioning

### Testing

Test with various Word document types:

- Simple text documents
- Documents with images
- Documents with tables
- Documents with complex formatting
- Documents with lists and nested content
- Large documents (approaching 10MB limit)

## Troubleshooting

### Common Issues

**File Upload Fails**
- Check PHP `upload_max_filesize` setting
- Verify `post_max_size` is larger than file size
- Ensure `file_uploads` is enabled

**Images Not Importing**
- Verify WordPress media upload permissions
- Check available disk space
- Ensure GD or ImageMagick is installed

**Formatting Lost**
- Verify the document is in .docx format
- Check for unsupported Word features
- Review WordPress content filters

**Memory Errors**
- Increase PHP `memory_limit`
- Process smaller documents
- Check for plugin conflicts

### Debug Mode

Enable debug logging by adding to `wp-config.php`:

```php
define('SMARTDOCPOST_DEBUG', true);
```

Logs will be written to `/wp-content/debug.log`

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

### Coding Guidelines

- Follow WordPress PHP Coding Standards
- Use meaningful variable and function names
- Add inline documentation
- Sanitize all inputs
- Escape all outputs
- Use WordPress APIs when available

## License

This plugin is licensed under the GPL v2 or later.

```
SmartDoc to Post Importer
Copyright (C) 2024

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
```

## Support

For support, please:

1. Check the [FAQ section](https://wordpress.org/plugins/smartdoc-to-post-importer/faq/)
2. Search existing [support topics](https://wordpress.org/support/plugin/smartdoc-to-post-importer/)
3. Create a new support topic if needed

## Changelog

See [readme.txt](readme.txt) for detailed changelog.

## Credits

Developed with ❤️ for the WordPress community.

Special thanks to:
- WordPress core team for excellent APIs
- Beta testers and early adopters
- Contributors and translators