This commit is contained in:
Javier Casares 2026-03-28 15:38:41 +00:00
commit 92d56fe84d
4445 changed files with 992 additions and 529601 deletions

281
README.md
View file

@ -1,281 +0,0 @@
# Documentation Markdown (by ROBOTSTXT)
Synchronize Markdown documentation from GitHub repositories to WordPress pages and posts automatically.
## Description
**Documentation Markdown** is a WordPress plugin that enables seamless synchronization of Markdown documentation files from GitHub repositories into your WordPress site. Perfect for maintaining technical documentation, API references, knowledge bases, and more.
## Features
- 🔄 **Automatic Synchronization** - Schedule automatic syncs via WordPress Cron
- 📝 **Markdown to HTML** - Convert GitHub Flavored Markdown to clean HTML
- 🎯 **Flexible Mapping** - Map individual MD files to specific WordPress posts/pages
- 🔍 **Smart Change Detection** - Only sync when content actually changes (using SHA comparison)
- 🔐 **Secure** - Encrypted GitHub token storage, full input validation & output escaping
- 🌍 **Translatable** - Full internationalization support (i18n/l10n ready)
- 📚 **Multi-Repository** - Sync from multiple GitHub repos simultaneously
- ⚡ **Manual Sync** - On-demand synchronization from admin interface
## Requirements
- **PHP:** 8.2 or higher
- **WordPress:** 6.5 or higher
- **GitHub Account:** For repository access (public or private)
## Installation
### Manual Installation
1. Download the plugin or clone this repository
2. Upload to `/wp-content/plugins/robotstxt-documentation-markdown/`
3. Run `composer install --no-dev` in the plugin directory
4. Activate the plugin through the 'Plugins' menu in WordPress
5. Navigate to 'GitHub Docs' in the WordPress admin menu
6. Configure your GitHub Personal Access Token
7. Create your first mapping
### Via Composer (Development)
```bash
cd wp-content/plugins
git clone https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown.git robotstxt-documentation-markdown
cd robotstxt-documentation-markdown
composer install
```
## Configuration
### 1. GitHub Personal Access Token
Generate a Personal Access Token from GitHub:
- Go to GitHub → Settings → Developer settings → Personal access tokens
- Click "Generate new token"
- For public repositories: No specific scopes needed
- For private repositories: Select `repo` scope
- Copy the token (you won't see it again!)
### 2. Plugin Configuration
1. In WordPress admin, go to **GitHub Docs → Settings**
2. Paste your GitHub token
3. Configure sync frequency (hourly, twice daily, daily)
4. Save settings
### 3. Create a Mapping
1. Go to **GitHub Docs → Mappings**
2. Click "Add New Mapping"
3. Fill in:
- **Repository Owner:** GitHub username or organization
- **Repository Name:** Repository name
- **File Path:** Path to `.md` file (e.g., `docs/api/auth.md`)
- **Branch:** Branch to sync from (default: `main`)
- **Target Post Type:** Where to create content (page/post)
- **Author:** WordPress user who will be the post author
4. Save mapping
5. Click "Sync Now" to perform first synchronization
## Usage Examples
### Example 1: API Documentation
Sync your API documentation from GitHub to WordPress pages:
```
Repository: yourcompany/api-docs
File Path: docs/authentication.md
Branch: main
Target: Page
```
Every time `authentication.md` is updated in GitHub, the corresponding WordPress page will automatically update.
### Example 2: Blog Posts
Write blog posts in Markdown using Git workflow:
```
Repository: yourblog/content
File Path: posts/2026-01-intro-to-api.md
Branch: main
Target: Post
```
Commit your Markdown post to GitHub, and it automatically publishes to your WordPress blog.
### Example 3: Knowledge Base
Maintain a knowledge base with version control:
```
Repository: support/knowledge-base
File Path: articles/how-to-install.md
Branch: production
Target: Page
```
## Development
### Setup Development Environment
```bash
# Clone repository
git clone https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown.git
cd documentation-markdown
# Install dependencies
composer install
# Run code quality checks
composer phpcs # Check coding standards
composer phpcbf # Auto-fix coding standards
composer phpstan # Static analysis
composer test # Run tests
```
### Coding Standards
This plugin strictly follows:
- **WordPress Coding Standards (WPCS)**
- **PHP 8.2+ features** (readonly properties, constructor promotion, match expressions)
- **Complete PHPDoc** documentation for all code
- **PSR-4 autoloading**
All code must pass:
```bash
composer lint # Runs both PHPCS and PHPStan
```
### Documentation
Complete technical documentation available in `/docs/`:
- **00-REQUIREMENTS-SUMMARY.md** - Start here! All critical requirements
- **01-project-overview.md** - Plugin overview and use cases
- **02-architecture.md** - System architecture and components
- **03-data-structure.md** - Database schema and data models
- **04-development-phases.md** - Development roadmap
- **05-technical-specifications.md** - Technical details and APIs
- **06-synchronization-flow.md** - How synchronization works
- **07-security-considerations.md** - Security best practices
- **08-implementation-order.md** - Step-by-step implementation guide
### Running Tests
```bash
# Unit tests
composer test
# Specific test
vendor/bin/phpunit tests/test-github-api-client.php
# With coverage
composer test -- --coverage-html coverage/
```
## Security
### Reporting Vulnerabilities
Please report security vulnerabilities privately to: **robotstxt@robotstxt.es**
Do NOT create public issues for security vulnerabilities.
### Security Features
- ✅ GitHub tokens encrypted at rest (AES-256-CBC)
- ✅ All user input sanitized
- ✅ All output escaped
- ✅ Nonce verification on all forms
- ✅ Capability checks for all admin actions
- ✅ Prepared statements for database queries
- ✅ Rate limiting for GitHub API
## Translation
The plugin is fully translatable and uses the text domain: `robotstxt-documentation-markdown`
To translate:
1. Use [Poedit](https://poedit.net/) or similar tool
2. Open `/languages/robotstxt-documentation-markdown.pot`
3. Create translations
4. Save as `robotstxt-documentation-markdown-{locale}.mo`
5. Place in `/wp-content/languages/plugins/`
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
### Version 1.0.0 (2026-01-26)
- ✨ Initial stable release
- 🔄 GitHub repository synchronization
- 📝 Markdown to HTML conversion using CommonMark
- 🎯 Flexible file-to-content mapping
- ⚡ Manual and scheduled synchronization
- 🎨 Complete admin interface
- 🐛 Built-in debug tools (WP_DEBUG mode)
- 🔐 Encrypted token storage
- 🌍 Full internationalization support
- 🛡️ Security best practices implemented
## Roadmap
Future enhancements under consideration:
- [ ] Bidirectional sync (WordPress → GitHub)
- [ ] Image synchronization from GitHub
- [ ] Folder-level mapping (sync entire directory)
- [ ] GitHub webhooks support (instant sync on push)
- [ ] Gutenberg block for embedded docs
- [ ] Multi-branch support per mapping
- [ ] Conflict resolution UI
## Contributing
We welcome contributions! Please follow these guidelines:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Follow WordPress Coding Standards (run `composer phpcs`)
4. Write PHPDoc for all functions
5. Include unit tests for new functionality
6. Ensure all tests pass (`composer test`)
7. Commit with conventional commit messages
8. Push to your fork
9. Open a Pull Request
All contributions must:
- Be in English
- Include complete PHPDoc
- Pass PHPCS and PHPStan
- Include appropriate unit tests
## License
This plugin is licensed under the GNU General Public License v3.0 or later.
See [LICENSE](LICENSE) file for details.
## Credits
**Developed by:** ROBOTSTXT
**Dependencies:**
- [league/commonmark](https://commonmark.thephpleague.com/) - Markdown parser
- [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
## Support
- **Documentation:** See `/docs/` directory
- **Issues:** [Gitea Issues](https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown/issues)
- **Discussions:** [Gitea Discussions](https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown/discussions)
- **Website:** [ROBOTSTXT.es](https://www.robotstxt.es/)
- **Security:** robotstxt@robotstxt.es
---
**Status:** Stable Release
**Version:** 1.0.0
**Requires PHP:** 8.2+
**Requires WordPress:** 6.5+ (single-site only)
**License:** GPL-3.0-or-later
**Text Domain:** robotstxt-documentation-markdown

140
changelog.txt Normal file
View file

@ -0,0 +1,140 @@
== Changelog ==
= 1.1.0 =
_Release date: 2026-03-28_
**Highlights**
* Editor-level access: editors can now manage documentation mappings without administrator privileges
* Full PHPStan level 9 compliance — zero errors across all plugin files
* Security patch for two CVEs in league/commonmark
* `target_order` (menu_order) field fully implemented end-to-end
**Security**
* Patched CVE-2026-33347 and CVE-2026-30838 by upgrading league/commonmark to 2.8.2
**Changed**
* Access level changed from `manage_options` (administrator) to `edit_pages` (editor) across all admin pages, form handlers, and debug functions
* `robotstxt_docmd_debug_run_cron()` now has a typed `int $mapping_id` parameter
**Fixed**
* PHPStan level 9: replaced all implicit `mixed` casts with proper type-narrowing via `is_string()`, `is_int()`, and `is_numeric()` guards
* New `robotstxt_docmd_input_string()` and `robotstxt_docmd_input_int()` helpers used for all superglobal (`$_POST`, `$_GET`) access
* `MappingData` and `MappingInput` global type aliases defined in `phpstan.neon` — file-level `@phpstan-type` aliases do not propagate between files in PHPStan 2.x procedural code
* `target_order` field was rendered in the form UI but never saved to post meta or applied during sync — now fully implemented
* `openssl_decrypt()` false return properly handled in token decryption
* `get_edit_post_link()` null return handled safely in debug run-cron output
* Redundant `isset()` guards removed on statically-typed array shapes
* Uninstall handler narrows `get_option()` mixed return before array access
* `size_format()` false return handled in discover-page file list
* Settings and debug functions use `is_array()` narrowing on `get_option()` before accessing keys
* `json_decode()` results in GitHub debug functions fully type-narrowed before key access
**Developer Features**
* PHPStan level 9: 0 errors (down from 104 in v1.0.0)
* `phpstan.neon` now includes global `MappingData` and `MappingInput` type aliases
* `robotstxt-updater.php` moved to `bootstrapFiles` in PHPStan config to avoid strict analysis of shared utility
* `$default` parameter renamed to `$fallback` in helpers (reserved keyword warning)
* Short ternary (`?:`) replaced with explicit `false !==` check (PHPCS rule)
**Compatibility**
* WordPress: 6.7 - 7.0
* PHP: 8.2 - 8.4 (verified on PHP 8.4.x)
* MariaDB: 10.6 or newer
**Dependencies**
* `league/commonmark`: 2.8.0 → 2.8.2 (security patch)
* `eduardovillao/wp-since`: 1.3.0 → 1.4.0
* `phpunit/phpunit` held at ^10.5 (v13.x available; pending test suite migration)
* `squizlabs/php_codesniffer` held at ^3.13 (v4.x available; pending WPCS 4.x confirmation)
**Tests**
* PHP Coding Standards: PHPCS 3.x with WordPress-Extra ruleset — 0 errors, 0 warnings
* WordPress Coding Standards: WPCS 3.3
* PHPStan: level 9, 0 errors (szepeviktor/phpstan-wordpress extension)
* PHPCompatibility: PHP 8.2 - 8.4 validated
* Manual testing: WordPress 6.8, 7.0
= 1.0.0 =
_Release date: 2026-01-26_
**Highlights**
* Initial release of Documentation Markdown plugin
* Automatic synchronization of Markdown files from GitHub to WordPress
* Full support for GitHub Flavored Markdown
* Encrypted GitHub token storage
* Flexible mapping system for multiple repositories
**Added**
* Core synchronization functionality between GitHub and WordPress
* Automatic scheduled sync (hourly, twice daily, daily)
* Manual on-demand sync via admin interface
* Markdown to HTML conversion using CommonMark (league/commonmark)
* Flexible file-to-content mapping system
* Custom Post Type (robotstxt_map) for mapping management
* Encrypted GitHub token storage (AES-256-CBC)
* Full internationalization support (i18n/l10n ready)
* Multi-repository support
* Clean admin interface with status badges
* Support for pages, posts, and custom post types as sync targets
* Configurable post author and parent page
* Page order (menu_order) support
* Debug tools for troubleshooting (visible when WP_DEBUG enabled)
* Cron job management and repair tools
* Clean uninstall with optional data deletion
* Settings page for GitHub configuration
* Mappings management interface (list, add, edit, delete)
* Sync status monitoring with timestamps
* Rate limiting awareness for GitHub API
* Cache system using WordPress Transients API
**Security**
* All user input sanitized using WordPress functions
* All output escaped (esc_html, esc_attr, esc_url)
* Nonce verification on all forms and actions
* Capability checks for all admin actions (manage_options — changed to edit_pages in 1.1.0)
* Prepared statements for all database queries
* GitHub tokens encrypted at rest using AES-256-CBC
* OWASP Top 10 mitigation implemented
* Direct access prevention on all PHP files
* CSRF protection on all state-changing operations
* XSS prevention through proper escaping
* SQL injection prevention through prepared statements
**Developer Features**
* Procedural PHP architecture following KISS principles
* PHP 8.2+ modern features (typed parameters, match expressions)
* Complete PHPDoc documentation on all functions
* WordPress Coding Standards (WPCS) compliant
* PHPCS/WPBF validated (0 errors, 0 warnings)
* Extensible architecture with WordPress hooks
* Clean, well-documented codebase
* Composer-based dependency management
* Production-optimized deployment script (bin/deploy.sh)
**Compatibility**
* WordPress: 6.7 - 6.9
* PHP: 8.2 - 8.5
* MariaDB: 10.6 or newer
**Tests**
* PHP Coding Standards: PHPCS 3.x with WordPress-Extra ruleset
* WordPress Coding Standards: WPCS 3.3
* PHPCompatibility: PHP 8.2 - 8.5 validated
* Security Audit: Complete OWASP Top 10 coverage
* Manual testing: WordPress 6.7, 6.8, 6.9

View file

@ -1,55 +0,0 @@
{
"name": "robotstxt/documentation-markdown",
"description": "Synchronizes Markdown documentation from GitHub repositories to WordPress pages and posts",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "ROBOTSTXT",
"homepage": "https://www.robotstxt.es"
}
],
"require": {
"php": ">=8.2",
"league/commonmark": "^2.4"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"squizlabs/php_codesniffer": "^3.13",
"wp-coding-standards/wpcs": "^3.3",
"phpcompatibility/php-compatibility": "^9.3",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"eduardovillao/wp-since": "^1.3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5"
},
"autoload": {
"psr-4": {
"RobotsTxt\\DocumentationMarkdown\\": "includes/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true,
"optimize-autoloader": true
},
"scripts": {
"phpcs": "phpcs",
"phpcbf": "phpcbf",
"phpstan": "phpstan analyse --memory-limit=512M",
"test": "phpunit",
"lint": [
"@phpcs",
"@phpstan"
]
},
"scripts-descriptions": {
"phpcs": "Run PHP_CodeSniffer to detect coding standard violations",
"phpcbf": "Run PHP Code Beautifier to automatically fix coding standard violations",
"phpstan": "Run PHPStan static analysis",
"test": "Run PHPUnit tests",
"lint": "Run all code quality checks"
}
}

3027
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,811 +0,0 @@
# Copyright (C) 2026 ROBOTSTXT
# This file is distributed under the GPL-3.0-or-later.
msgid ""
msgstr ""
"Project-Id-Version: Documentation Markdown (by ROBOTSTXT) 1.0.0-rc1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/robotstxt-documentation-markdown\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-01-25T18:11:49+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: robotstxt-documentation-markdown\n"
#. Plugin Name of the plugin
#: robotstxt-documentation-markdown.php
msgid "Documentation Markdown (by ROBOTSTXT)"
msgstr ""
#. Plugin URI of the plugin
#: robotstxt-documentation-markdown.php
msgid "https://github.com/robotstxt/documentation-markdown"
msgstr ""
#. Description of the plugin
#: robotstxt-documentation-markdown.php
msgid "Synchronizes Markdown documentation from GitHub repositories to WordPress pages and posts automatically."
msgstr ""
#. Author of the plugin
#: robotstxt-documentation-markdown.php
msgid "ROBOTSTXT"
msgstr ""
#. Author URI of the plugin
#: robotstxt-documentation-markdown.php
msgid "https://robotstxt.com"
msgstr ""
#: includes/admin/Admin_Mappings.php:52
msgid "Manage Mappings"
msgstr ""
#: includes/admin/Admin_Mappings.php:53
msgid "Mappings"
msgstr ""
#: includes/admin/Admin_Mappings.php:61
#: includes/admin/Admin_Mappings.php:173
#: includes/admin/Admin_Mappings.php:382
msgid "Add New Mapping"
msgstr ""
#: includes/admin/Admin_Mappings.php:62
#: includes/admin/Admin_Mappings.php:136
msgid "Add New"
msgstr ""
#: includes/admin/Admin_Mappings.php:105
#: includes/admin/Admin_Mappings.php:276
msgid "Syncing..."
msgstr ""
#: includes/admin/Admin_Mappings.php:106
#: includes/admin/Admin_Mappings.php:653
msgid "Sync completed successfully!"
msgstr ""
#: includes/admin/Admin_Mappings.php:107
msgid "Sync failed:"
msgstr ""
#: includes/admin/Admin_Mappings.php:108
#: includes/admin/Admin_Mappings.php:342
msgid "Are you sure you want to delete this mapping?"
msgstr ""
#: includes/admin/Admin_Mappings.php:109
msgid "Syncing all mappings..."
msgstr ""
#: includes/admin/Admin_Mappings.php:124
#: includes/admin/Admin_Mappings.php:357
#: includes/admin/Admin_Settings.php:542
msgid "You do not have sufficient permissions to access this page."
msgstr ""
#: includes/admin/Admin_Mappings.php:133
msgid "Documentation Mappings"
msgstr ""
#: includes/admin/Admin_Mappings.php:145
msgid "Total Mappings"
msgstr ""
#: includes/admin/Admin_Mappings.php:149
msgid "Active"
msgstr ""
#: includes/admin/Admin_Mappings.php:153
msgid "Last Success"
msgstr ""
#: includes/admin/Admin_Mappings.php:157
msgid "Last Error"
msgstr ""
#: includes/admin/Admin_Mappings.php:164
msgid "Sync All Active Mappings"
msgstr ""
#: includes/admin/Admin_Mappings.php:171
msgid "No mappings found. Create your first mapping to get started!"
msgstr ""
#: includes/admin/Admin_Mappings.php:180
msgid "Title"
msgstr ""
#: includes/admin/Admin_Mappings.php:181
msgid "Repository"
msgstr ""
#: includes/admin/Admin_Mappings.php:182
msgid "File"
msgstr ""
#: includes/admin/Admin_Mappings.php:183
msgid "Frequency"
msgstr ""
#: includes/admin/Admin_Mappings.php:184
msgid "Status"
msgstr ""
#: includes/admin/Admin_Mappings.php:185
msgid "Sync Status"
msgstr ""
#: includes/admin/Admin_Mappings.php:186
msgid "Last Sync"
msgstr ""
#: includes/admin/Admin_Mappings.php:187
msgid "Next Sync"
msgstr ""
#: includes/admin/Admin_Mappings.php:188
msgid "Actions"
msgstr ""
#: includes/admin/Admin_Mappings.php:208
#, php-format
msgid "Branch: %s"
msgstr ""
#: includes/admin/Admin_Mappings.php:214
#: includes/admin/Admin_Mappings.php:232
msgid "Never"
msgstr ""
#: includes/admin/Admin_Mappings.php:219
msgid "Enabled"
msgstr ""
#: includes/admin/Admin_Mappings.php:221
msgid "Disabled"
msgstr ""
#: includes/admin/Admin_Mappings.php:242
msgid "Manual Only"
msgstr ""
#: includes/admin/Admin_Mappings.php:272
msgid "Never Synced"
msgstr ""
#: includes/admin/Admin_Mappings.php:280
msgid "Success"
msgstr ""
#: includes/admin/Admin_Mappings.php:284
msgid "Error"
msgstr ""
#: includes/admin/Admin_Mappings.php:337
msgid "Sync Now"
msgstr ""
#: includes/admin/Admin_Mappings.php:340
msgid "Edit"
msgstr ""
#: includes/admin/Admin_Mappings.php:343
msgid "Delete"
msgstr ""
#: includes/admin/Admin_Mappings.php:382
msgid "Edit Mapping"
msgstr ""
#: includes/admin/Admin_Mappings.php:397
msgid "Mapping Title"
msgstr ""
#: includes/admin/Admin_Mappings.php:401
msgid "A descriptive name for this mapping."
msgstr ""
#: includes/admin/Admin_Mappings.php:407
msgid "Repository Owner"
msgstr ""
#: includes/admin/Admin_Mappings.php:411
msgid "GitHub username or organization (e.g., \"wordpress\")."
msgstr ""
#: includes/admin/Admin_Mappings.php:417
msgid "Repository Name"
msgstr ""
#: includes/admin/Admin_Mappings.php:421
msgid "Repository name (e.g., \"wordpress-develop\")."
msgstr ""
#: includes/admin/Admin_Mappings.php:427
msgid "File Path"
msgstr ""
#: includes/admin/Admin_Mappings.php:431
msgid "Path to Markdown file (e.g., \"README.md\" or \"docs/api.md\")."
msgstr ""
#: includes/admin/Admin_Mappings.php:437
msgid "Branch"
msgstr ""
#: includes/admin/Admin_Mappings.php:441
msgid "Git branch name (default: \"main\")."
msgstr ""
#: includes/admin/Admin_Mappings.php:447
msgid "Target Post Type"
msgstr ""
#: includes/admin/Admin_Mappings.php:463
msgid "WordPress post type for the synced content."
msgstr ""
#: includes/admin/Admin_Mappings.php:469
msgid "Post Author"
msgstr ""
#: includes/admin/Admin_Mappings.php:481
msgid "WordPress user to assign as post author."
msgstr ""
#: includes/admin/Admin_Mappings.php:487
msgid "Sync Frequency"
msgstr ""
#: includes/admin/Admin_Mappings.php:503
msgid "How often to automatically sync this documentation from GitHub."
msgstr ""
#: includes/admin/Admin_Mappings.php:509
msgid "Enable Sync"
msgstr ""
#: includes/admin/Admin_Mappings.php:514
msgid "Enable automatic synchronization for this mapping"
msgstr ""
#: includes/admin/Admin_Mappings.php:516
msgid "Must be enabled for automatic syncing to work."
msgstr ""
#: includes/admin/Admin_Mappings.php:521
msgid "Update Mapping"
msgstr ""
#: includes/admin/Admin_Mappings.php:521
msgid "Create Mapping"
msgstr ""
#: includes/admin/Admin_Mappings.php:536
#: includes/admin/Admin_Mappings.php:593
msgid "You do not have sufficient permissions."
msgstr ""
#: includes/admin/Admin_Mappings.php:634
#: includes/admin/Admin_Mappings.php:670
msgid "Insufficient permissions."
msgstr ""
#: includes/admin/Admin_Mappings.php:640
msgid "Invalid mapping ID."
msgstr ""
#. translators: 1: Success count, 2: Error count
#: includes/admin/Admin_Mappings.php:690
#, php-format
msgid "Sync complete: %1$d succeeded, %2$d failed."
msgstr ""
#: includes/admin/Admin_Mappings.php:711
msgid "Mapping created successfully."
msgstr ""
#: includes/admin/Admin_Mappings.php:712
msgid "Mapping updated successfully."
msgstr ""
#: includes/admin/Admin_Mappings.php:713
msgid "Mapping deleted successfully."
msgstr ""
#: includes/admin/Admin_Settings.php:45
msgid "Documentation Settings"
msgstr ""
#: includes/admin/Admin_Settings.php:46
msgid "Documentation"
msgstr ""
#: includes/admin/Admin_Settings.php:78
msgid "GitHub Repository Settings"
msgstr ""
#: includes/admin/Admin_Settings.php:85
msgid "GitHub Documentation URL"
msgstr ""
#: includes/admin/Admin_Settings.php:93
msgid "GitHub Personal Access Token"
msgstr ""
#: includes/admin/Admin_Settings.php:102
msgid "Advanced Settings"
msgstr ""
#: includes/admin/Admin_Settings.php:109
msgid "Delete Data on Uninstall"
msgstr ""
#: includes/admin/Admin_Settings.php:118
msgid "Email Notifications"
msgstr ""
#: includes/admin/Admin_Settings.php:125
msgid "Enable Notifications"
msgstr ""
#: includes/admin/Admin_Settings.php:133
msgid "Notification Email"
msgstr ""
#: includes/admin/Admin_Settings.php:141
msgid "Notify on Success"
msgstr ""
#: includes/admin/Admin_Settings.php:149
msgid "Notify Unsynchronized"
msgstr ""
#: includes/admin/Admin_Settings.php:181
msgid "GitHub URL must use HTTPS protocol for security. URL was not saved."
msgstr ""
#: includes/admin/Admin_Settings.php:210
msgid "Warning: Token could not be encrypted. It has been saved in plain text."
msgstr ""
#: includes/admin/Admin_Settings.php:251
msgid "Configure your GitHub repository settings to synchronize documentation from GitHub to WordPress."
msgstr ""
#: includes/admin/Admin_Settings.php:267
msgid "Advanced configuration options for plugin behavior."
msgstr ""
#: includes/admin/Admin_Settings.php:295
msgid "Enter the full URL of your GitHub repository (e.g., https://github.com/owner/repository)"
msgstr ""
#: includes/admin/Admin_Settings.php:322
msgid "ghp_xxxxxxxxxxxx"
msgstr ""
#. translators: %s: Link to GitHub Personal Access Tokens page
#: includes/admin/Admin_Settings.php:328
#, php-format
msgid "Enter your GitHub Personal Access Token. %s"
msgstr ""
#: includes/admin/Admin_Settings.php:333
msgid "Create a token"
msgstr ""
#: includes/admin/Admin_Settings.php:340
msgid "How to create a GitHub Personal Access Token:"
msgstr ""
#: includes/admin/Admin_Settings.php:343
msgid "Go to GitHub → Settings → Developer settings → Personal access tokens"
msgstr ""
#: includes/admin/Admin_Settings.php:344
msgid "Click \"Generate new token\" (classic)"
msgstr ""
#: includes/admin/Admin_Settings.php:345
msgid "Give it a descriptive name (e.g., \"WordPress Documentation Sync\")"
msgstr ""
#: includes/admin/Admin_Settings.php:348
msgid "For public repositories: No specific scopes needed"
msgstr ""
#: includes/admin/Admin_Settings.php:355
msgid "For private repositories: Select the \"repo\" scope"
msgstr ""
#: includes/admin/Admin_Settings.php:361
msgid "Click \"Generate token\" and copy it immediately"
msgstr ""
#: includes/admin/Admin_Settings.php:362
msgid "Paste the token in the field above and save"
msgstr ""
#: includes/admin/Admin_Settings.php:367
msgid "Note: For security, your token is stored encrypted and will be shown as dots once saved."
msgstr ""
#: includes/admin/Admin_Settings.php:397
msgid "Delete all plugin data when uninstalling"
msgstr ""
#: includes/admin/Admin_Settings.php:401
msgid "If enabled, all plugin settings and mapping configurations will be deleted when you uninstall the plugin."
msgstr ""
#: includes/admin/Admin_Settings.php:409
msgid "Important:"
msgstr ""
#: includes/admin/Admin_Settings.php:411
msgid "Your synced documentation content (pages/posts) will NOT be deleted, only the mapping configurations and plugin settings."
msgstr ""
#: includes/admin/Admin_Settings.php:419
msgid "This ensures your documentation remains available even after uninstalling the plugin."
msgstr ""
#: includes/admin/Admin_Settings.php:438
msgid "Configure email notifications for sync events."
msgstr ""
#: includes/admin/Admin_Settings.php:458
msgid "Send email notifications for sync errors"
msgstr ""
#: includes/admin/Admin_Settings.php:461
msgid "You will receive an email when a sync operation fails (rate limited to once per hour per mapping)."
msgstr ""
#. translators: %s: Default admin email
#: includes/admin/Admin_Settings.php:482
#, php-format
msgid "Email address for notifications (default: %s)."
msgstr ""
#: includes/admin/Admin_Settings.php:503
msgid "Send email notifications for successful syncs"
msgstr ""
#: includes/admin/Admin_Settings.php:506
msgid "Receive an email confirmation when content is successfully synchronized (not recommended for frequent syncs)."
msgstr ""
#: includes/admin/Admin_Settings.php:524
msgid "Notify when mappings have not been synchronized"
msgstr ""
#: includes/admin/Admin_Settings.php:527
msgid "Receive alerts when enabled mappings with auto-sync have never been synchronized (rate limited to once per hour)."
msgstr ""
#: includes/admin/Admin_Settings.php:550
msgid "Settings saved successfully."
msgstr ""
#: includes/admin/Admin_Settings.php:563
msgid "Documentation Markdown allows you to automatically synchronize Markdown documentation from GitHub repositories to your WordPress site."
msgstr ""
#: includes/admin/Admin_Settings.php:575
msgid "Save Settings"
msgstr ""
#: includes/admin/Admin_Settings.php:580
msgid "About This Plugin"
msgstr ""
#: includes/admin/Admin_Settings.php:583
msgid "This plugin synchronizes Markdown documentation from GitHub repositories and converts it into WordPress pages or posts automatically."
msgstr ""
#: includes/admin/Admin_Settings.php:590
msgid "Version:"
msgstr ""
#: includes/admin/Admin_Settings.php:594
msgid "Developer:"
msgstr ""
#: includes/Cron_Manager.php:43
msgid "Never (Manual Only)"
msgstr ""
#: includes/Cron_Manager.php:47
msgid "Every 1 Minute"
msgstr ""
#: includes/Cron_Manager.php:51
msgid "Every 5 Minutes"
msgstr ""
#: includes/Cron_Manager.php:55
msgid "Every 10 Minutes"
msgstr ""
#: includes/Cron_Manager.php:59
msgid "Every 15 Minutes"
msgstr ""
#: includes/Cron_Manager.php:63
msgid "Every 30 Minutes"
msgstr ""
#: includes/Cron_Manager.php:67
msgid "Every 1 Hour"
msgstr ""
#: includes/Cron_Manager.php:71
msgid "Every 2 Hours"
msgstr ""
#: includes/Cron_Manager.php:75
msgid "Every 4 Hours"
msgstr ""
#: includes/Cron_Manager.php:79
msgid "Every 6 Hours"
msgstr ""
#: includes/Cron_Manager.php:83
msgid "Every 12 Hours"
msgstr ""
#: includes/Cron_Manager.php:87
msgid "Once Daily"
msgstr ""
#: includes/Cron_Manager.php:238
#: includes/Cron_Manager.php:247
msgid "Now"
msgstr ""
#. translators: %s: Mapping title
#: includes/Cron_Manager.php:286
#, php-format
msgid "[Documentation Sync] Error: %s"
msgstr ""
#. translators: %s: Mapping title
#: includes/Cron_Manager.php:332
#, php-format
msgid "[Documentation Sync] Success: %s"
msgstr ""
#: includes/Cron_Manager.php:397
msgid "[Documentation Sync] Unsynchronized Files Found"
msgstr ""
#. translators: 1: Mapping title, 2: Error message
#: includes/Cron_Manager.php:491
#, php-format
msgid ""
"Failed to sync documentation: %1$s\n"
"\n"
"Error: %2$s\n"
"\n"
""
msgstr ""
#: includes/Cron_Manager.php:496
#: includes/Cron_Manager.php:538
msgid ""
"Repository Details:\n"
""
msgstr ""
#. translators: %s: Admin URL
#: includes/Cron_Manager.php:504
#, php-format
msgid ""
"Manage mappings: %s\n"
""
msgstr ""
#. translators: %s: Mapping title
#: includes/Cron_Manager.php:522
#, php-format
msgid ""
"Successfully synchronized documentation: %s\n"
"\n"
""
msgstr ""
#. translators: 1: Post title, 2: Post URL
#: includes/Cron_Manager.php:531
#, php-format
msgid ""
"Post: %1$s\n"
"View: %2$s\n"
"\n"
""
msgstr ""
#. translators: %d: Number of unsynchronized mappings
#: includes/Cron_Manager.php:558
#, php-format
msgid "There is %d documentation mapping that has not been synchronized:"
msgid_plural "There are %d documentation mappings that have not been synchronized:"
msgstr[0] ""
msgstr[1] ""
#. translators: %s: Admin URL
#: includes/Cron_Manager.php:579
#, php-format
msgid ""
"Please review and sync these mappings: %s\n"
""
msgstr ""
#: includes/encryption-functions.php:34
msgid "OpenSSL extension is required for token encryption"
msgstr ""
#: includes/encryption-functions.php:47
#: includes/encryption-functions.php:112
msgid "Failed to determine cipher IV length"
msgstr ""
#: includes/encryption-functions.php:64
msgid "Encryption failed"
msgstr ""
#: includes/encryption-functions.php:90
msgid "OpenSSL extension is required for token decryption"
msgstr ""
#: includes/encryption-functions.php:99
msgid "Invalid encrypted data format"
msgstr ""
#: includes/encryption-functions.php:130
msgid "Decryption failed"
msgstr ""
#: includes/GitHub_API_Client.php:81
msgid "Invalid response from GitHub API: missing required fields"
msgstr ""
#: includes/GitHub_API_Client.php:91
msgid "Failed to decode file content from GitHub"
msgstr ""
#: includes/GitHub_API_Client.php:132
msgid "SHA not found in GitHub API response"
msgstr ""
#. translators: %s: Error message
#: includes/GitHub_API_Client.php:213
#, php-format
msgid "GitHub API request failed: %s"
msgstr ""
#: includes/GitHub_API_Client.php:230
msgid "Unknown error"
msgstr ""
#: includes/GitHub_API_Client.php:234
msgid "Authentication failed. Please check your GitHub token."
msgstr ""
#: includes/GitHub_API_Client.php:235
msgid "Access forbidden. Check your token permissions or rate limit."
msgstr ""
#: includes/GitHub_API_Client.php:236
msgid "File not found in repository. Please verify the file path and branch."
msgstr ""
#. translators: 1: HTTP status code, 2: Error message
#: includes/GitHub_API_Client.php:239
#, php-format
msgid "GitHub API error (%1$d): %2$s"
msgstr ""
#. translators: %s: JSON error message
#: includes/GitHub_API_Client.php:255
#, php-format
msgid "Invalid JSON response from GitHub: %s"
msgstr ""
#: includes/GitHub_API_Client.php:347
msgid "unknown"
msgstr ""
#. translators: %s: Reset time
#: includes/GitHub_API_Client.php:352
#, php-format
msgid "GitHub API rate limit nearly exceeded. Resets at: %s"
msgstr ""
#: includes/mapping-functions.php:73
#: includes/mapping-functions.php:118
msgid "Invalid mapping ID"
msgstr ""
#: includes/mapping-functions.php:124
msgid "Failed to delete mapping"
msgstr ""
#: includes/mapping-functions.php:227
msgid "Repository owner is required"
msgstr ""
#: includes/mapping-functions.php:233
msgid "Invalid repository owner format"
msgstr ""
#: includes/mapping-functions.php:238
msgid "Repository name is required"
msgstr ""
#: includes/mapping-functions.php:244
msgid "Invalid repository name format"
msgstr ""
#: includes/mapping-functions.php:249
msgid "File path is required"
msgstr ""
#: includes/mapping-functions.php:256
msgid "File path cannot contain \"..\""
msgstr ""
#: includes/mapping-functions.php:261
msgid "File must be .md or .markdown"
msgstr ""
#: includes/mapping-functions.php:268
msgid "Invalid branch name format"
msgstr ""
#: includes/mapping-functions.php:275
msgid "Post type does not exist"
msgstr ""
#: includes/Plugin.php:172
msgid "GitHub Doc Mappings"
msgstr ""
#: includes/Plugin.php:173
msgid "GitHub Doc Mapping"
msgstr ""
#: includes/Sync_Manager.php:84
#: includes/Sync_Manager.php:422
msgid "Synchronization is disabled for this mapping."
msgstr ""
#. translators: %s: Error message from GitHub API
#: includes/Sync_Manager.php:259
#, php-format
msgid "Failed to fetch file from GitHub: %s"
msgstr ""
#. translators: %s: Error message
#: includes/Sync_Manager.php:441
#, php-format
msgid "Failed to check for changes: %s"
msgstr ""
#: includes/Sync_Manager.php:498
msgid "GitHub Personal Access Token is not configured."
msgstr ""
#: includes/Sync_Manager.php:504
msgid "No active mappings configured."
msgstr ""
#: includes/Sync_Manager.php:509
msgid "OpenSSL extension is not available (required for token encryption)."
msgstr ""

299
readme.txt Normal file
View file

@ -0,0 +1,299 @@
=== Documentation Markdown (by ROBOTSTXT) ===
Contributors: robotstxt
Tags: github, documentation, markdown, sync, automation
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 8.2
Stable tag: 1.1.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Synchronize Markdown documentation from GitHub repositories to WordPress pages and posts automatically.
== Description ==
**Documentation Markdown** is a powerful WordPress plugin that enables seamless synchronization of Markdown documentation files from GitHub repositories into your WordPress site. Perfect for maintaining technical documentation, API references, knowledge bases, and more - all with the power of version control.
= Key Features =
* 🔄 **Automatic Synchronization** - Schedule automatic syncs via WordPress Cron (hourly, twice daily, daily)
* 📝 **Markdown to HTML** - Convert GitHub Flavored Markdown to clean HTML using CommonMark
* 🎯 **Flexible Mapping** - Map individual MD files to specific WordPress posts or pages
* 🔐 **Secure** - Encrypted GitHub token storage, full input validation & output escaping
* 🌍 **Translatable** - Full internationalization support (i18n/l10n ready)
* 📚 **Multi-Repository** - Sync from multiple GitHub repos simultaneously
* ⚡ **Manual Sync** - On-demand synchronization from admin interface
* 🐛 **Debug Tools** - Built-in debugging tools (visible when WP_DEBUG is enabled)
= Use Cases =
* **API Documentation** - Keep your API docs in sync between GitHub and WordPress
* **Technical Documentation** - Maintain version-controlled technical docs
* **Knowledge Base** - Build a knowledge base powered by GitHub
* **Blog Posts** - Write blog posts in Markdown with Git workflow
* **Product Documentation** - Sync product documentation from your repository
* **Multi-language Documentation** - Manage translations in GitHub, publish to WordPress
= How It Works =
1. Configure your GitHub Personal Access Token in plugin settings
2. Create mappings between GitHub Markdown files and WordPress content
3. Choose synchronization frequency (manual, hourly, twice daily, daily)
4. The plugin automatically fetches and converts Markdown to HTML
5. Your WordPress content stays in sync with your GitHub repository
= Requirements =
* PHP 8.2 or higher
* WordPress 6.9 or higher
* GitHub Personal Access Token (free, for accessing repositories)
* Composer (for production build with dependencies)
= Security =
* GitHub tokens encrypted at rest (AES-256-CBC)
* All user input sanitized
* All output escaped
* Nonce verification on all forms
* Capability checks for all admin actions
* Prepared statements for database queries
* Rate limiting for GitHub API
= Developer Friendly =
* Clean, well-documented code
* Follows WordPress Coding Standards (WPCS)
* Modern PHP 8.2+ features
* Extensive PHPDoc documentation
* Procedural approach (KISS principles)
* Extensible with WordPress hooks and filters
== Installation ==
= Automatic Installation =
1. Log in to your WordPress admin panel
2. Navigate to Plugins → Add New
3. Search for "Documentation Markdown ROBOTSTXT"
4. Click "Install Now" and then "Activate"
= Manual Installation =
1. Download the plugin ZIP file
2. Upload to `/wp-content/plugins/` directory
3. Extract the files
4. Ensure Composer dependencies are installed (`composer install --no-dev`)
5. Activate the plugin through the 'Plugins' menu in WordPress
= After Installation =
1. Navigate to 'Documentation → Settings' in the WordPress admin menu
2. Generate a GitHub Personal Access Token:
- Go to GitHub → Settings → Developer settings → Personal access tokens
- Click "Generate new token"
- For public repositories: No specific scopes needed
- For private repositories: Select `repo` scope
3. Paste your token in the plugin settings and save
4. Create your first mapping under 'Documentation → Mappings'
== Frequently Asked Questions ==
= Do I need a GitHub account? =
Yes, you need a GitHub account to generate a Personal Access Token. The token is required to access repositories (public or private).
= Can I sync from private repositories? =
Yes! When generating your GitHub Personal Access Token, make sure to select the `repo` scope for full access to private repositories.
= How often does synchronization happen? =
You can configure synchronization frequency per mapping:
* Manual only (on-demand via "Sync Now" button)
* Hourly
* Twice daily
* Daily
You can also manually trigger sync at any time.
= Will the plugin delete my WordPress content if I uninstall it? =
By default, NO. When you uninstall the plugin, it preserves all synced WordPress pages/posts. However, there's an option in Settings to delete plugin data on uninstall (mappings, settings, etc.) - but this never deletes the actual WordPress content, only the plugin configuration.
= Can I sync multiple files from the same repository? =
Yes! You can create multiple mappings, each pointing to different files in the same repository or different repositories.
= What Markdown syntax is supported? =
The plugin uses CommonMark (league/commonmark), which supports GitHub Flavored Markdown including:
* Headings, paragraphs, lists
* Code blocks with syntax highlighting
* Tables
* Links and images
* Blockquotes
* And more!
= Does it support images from GitHub? =
Currently, Markdown image links are converted to HTML, but images are not downloaded. Images must be publicly accessible via their GitHub URLs or you need to host them separately.
= Can I customize the HTML output? =
The plugin converts Markdown to standard HTML. You can style the output using your theme's CSS by targeting the content area where documentation is displayed.
= Is there a limit on file size? =
While there's no hard limit imposed by the plugin, GitHub API has size limitations. Very large files (>10MB) may cause issues. We recommend keeping documentation files under 1MB for best performance.
= What happens if GitHub is unavailable? =
If GitHub API is unreachable during a scheduled sync, the plugin will fail gracefully and retry on the next scheduled interval. Your existing content remains unchanged.
= Can I edit synced content in WordPress? =
You can edit synced content in WordPress, but be aware that the next synchronization will overwrite your changes with content from GitHub. We recommend making all edits in your GitHub repository.
= How do I debug synchronization issues? =
Enable WP_DEBUG in your wp-config.php:
```
define('WP_DEBUG', true);
```
Then go to Documentation → Settings, and you'll see a "Debug Tools" section at the bottom with:
* Test GitHub repository connection
* Test GitHub token validity
* View scheduled cron jobs
* Manually run cron jobs
* Clear plugin caches
== Screenshots ==
1. Plugin Settings - Configure GitHub repository and token
2. Mappings List - View all your GitHub-to-WordPress mappings
3. Add/Edit Mapping - Create new mapping between GitHub file and WordPress content
4. Sync Status - Monitor synchronization status and history
5. Debug Tools - Built-in debugging interface (shown when WP_DEBUG is enabled)
== Compatibility ==
* WordPress: 6.7 - 6.9
* PHP: 8.2 - 8.5
== Changelog ==
For the complete changelog, see [changelog.txt](https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown/raw/branch/main/changelog.txt).
= 1.1.0 - 2026-03-28 =
**Security**
* Patched CVE-2026-33347 and CVE-2026-30838 (league/commonmark updated to 2.8.2)
**Changed**
* Access level changed from administrator (manage_options) to editor (edit_pages) — editors can now manage documentation mappings without requiring full admin access
**Fixed**
* PHPStan level 9 compliance: zero errors across all plugin files (down from 104)
* target_order (menu_order) field was in the UI but never saved or applied — now fully implemented
* Type-safety improvements for all WordPress API returns (get_option, get_post_meta, json_decode, size_format)
* Token decryption false return handled correctly
* Uninstall data cleanup narrows mixed option return before array access
**Compatibility**
* Verified compatible with WordPress 6.8 and 7.0
* Verified compatible with PHP 8.4.x
= 1.0.0 - 2026-01-26 =
**Initial Release**
* ✨ Core synchronization functionality
* 🔄 Automatic scheduled sync (hourly, twice daily, daily)
* ⚡ Manual on-demand sync
* 📝 Markdown to HTML conversion using CommonMark
* 🎯 Flexible file-to-content mapping system
* 🔐 Encrypted GitHub token storage
* 🌍 Full internationalization support
* 📚 Multi-repository support
* 🎨 Clean admin interface with status badges
* 🔧 Custom Post Type for mapping management
* 📦 Support for pages, posts, and custom post types
* 👤 Configurable post author and parent page
* 🔢 Page order (menu_order) support
* 🐛 Debug tools for troubleshooting
* 🔄 Cron job management and repair tools
* 🧹 Clean uninstall with optional data deletion
* ✅ WordPress Coding Standards compliant
* 🛡️ Security best practices (nonces, escaping, sanitization)
**Admin Features:**
* Settings page for GitHub configuration
* Mappings management interface
* Add/Edit mapping with validation
* Sync status monitoring
* Debug tools (when WP_DEBUG enabled)
- Test GitHub connection
- Test token validity
- View scheduled crons
- Run crons manually
- Fix cron schedules
- Clear plugin caches
**Developer Features:**
* Procedural PHP following KISS principles
* PHP 8.2+ modern features
* Complete PHPDoc documentation
* WordPress hooks and filters
* Extensible architecture
* PHPCS and PHPStan validated
== Upgrade Notice ==
= 1.0.0 =
Initial release of Documentation Markdown. Sync your GitHub Markdown files to WordPress automatically!
== Additional Information ==
= Support =
* **Documentation:** Comprehensive docs included in `/docs/` directory
* **Repository:** [Report issues](https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown/issues)
* **Website:** [ROBOTSTXT.es](https://www.robotstxt.es/)
* **Security:** robotstxt@robotstxt.es
= Contributing =
We welcome contributions! Please visit our [Gitea repository](https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown) to:
* Report bugs
* Suggest features
* Submit pull requests
= Privacy =
This plugin does not collect or store any user data. The only external connection made is to the GitHub API to fetch repository content. Your GitHub Personal Access Token is encrypted and stored locally in your WordPress database.
= Credits =
Developed by ROBOTSTXT with ❤️
**Dependencies:**
* [league/commonmark](https://commonmark.thephpleague.com/) - Markdown parser and converter
= License =
This plugin is licensed under the GNU General Public License v3.0 or later.
== Compliance ==
This plugin adheres to the following security measures and review protocols for each version:
* [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
* [WordPress Plugin Security](https://developer.wordpress.org/plugins/wordpress-org/plugin-security/)
* [WordPress APIs Security](https://developer.wordpress.org/apis/security/)
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
* [Plugin Check (PCP)](https://wordpress.org/plugins/plugin-check/)

View file

@ -16,9 +16,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0
*
* @param string $token Plain token.
* @return string Encrypted token.
* @return string Encrypted token, or empty string on failure.
*/
function robotstxt_docmd_encrypt_token( $token ) {
function robotstxt_docmd_encrypt_token( string $token ): string {
if ( empty( $token ) ) {
return '';
}
@ -27,9 +27,12 @@ function robotstxt_docmd_encrypt_token( $token ) {
$key = wp_salt( 'auth' );
$iv_length = openssl_cipher_iv_length( 'aes-256-cbc' );
$iv = openssl_random_pseudo_bytes( $iv_length );
$encrypted = openssl_encrypt( $token, 'aes-256-cbc', $key, 0, $iv );
if ( false === $encrypted ) {
return '';
}
return base64_encode( $iv . $encrypted ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
}
@ -39,9 +42,9 @@ function robotstxt_docmd_encrypt_token( $token ) {
* @since 1.0.0
*
* @param string $encrypted_token Encrypted token.
* @return string Plain token.
* @return string Plain token, or empty string on failure.
*/
function robotstxt_docmd_decrypt_token( $encrypted_token ) {
function robotstxt_docmd_decrypt_token( string $encrypted_token ): string {
if ( empty( $encrypted_token ) ) {
return '';
}
@ -53,7 +56,8 @@ function robotstxt_docmd_decrypt_token( $encrypted_token ) {
$iv = substr( $decoded, 0, $iv_length );
$encrypted = substr( $decoded, $iv_length );
return openssl_decrypt( $encrypted, 'aes-256-cbc', $key, 0, $iv );
$decrypted = openssl_decrypt( $encrypted, 'aes-256-cbc', $key, 0, $iv );
return false !== $decrypted ? $decrypted : '';
}
/**
@ -66,10 +70,11 @@ function robotstxt_docmd_decrypt_token( $encrypted_token ) {
* @param string $file_path File path.
* @return string Generated title.
*/
function robotstxt_docmd_generate_title_from_path( $file_path ) {
function robotstxt_docmd_generate_title_from_path( string $file_path ): string {
// Get filename without extension.
$filename = basename( $file_path );
$title = preg_replace( '/\.(md|markdown)$/i', '', $filename );
$title = is_string( $title ) ? $title : $filename;
// Replace separators with spaces.
$title = str_replace( array( '-', '_' ), ' ', $title );
@ -91,7 +96,8 @@ function robotstxt_docmd_generate_title_from_path( $file_path ) {
);
foreach ( $abbreviations as $search => $replace ) {
$title = preg_replace( '/\b' . $search . '\b/', $replace, $title );
$result = preg_replace( '/\b' . $search . '\b/', $replace, $title );
$title = is_string( $result ) ? $result : $title;
}
return $title;
@ -105,7 +111,7 @@ function robotstxt_docmd_generate_title_from_path( $file_path ) {
* @param string $status Status (never, pending, success, error).
* @return string Badge HTML.
*/
function robotstxt_docmd_get_status_badge( $status ) {
function robotstxt_docmd_get_status_badge( string $status ): string {
$badges = array(
'never' => array(
'class' => 'status-never',
@ -133,3 +139,41 @@ function robotstxt_docmd_get_status_badge( $status ) {
esc_html( $badge['label'] )
);
}
/**
* Safely get a string value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array<string, mixed> $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param string $fallback Default value if key not found or not a string.
* @return string
*/
function robotstxt_docmd_input_string( array $input, string $key, string $fallback = '' ): string {
if ( isset( $input[ $key ] ) && is_string( $input[ $key ] ) ) {
return $input[ $key ];
}
return $fallback;
}
/**
* Safely get an integer value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array<string, mixed> $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param int $fallback Default value if key not found or not numeric.
* @return int
*/
function robotstxt_docmd_input_int( array $input, string $key, int $fallback = 0 ): int {
if ( isset( $input[ $key ] ) && is_numeric( $input[ $key ] ) ) {
return (int) $input[ $key ];
}
return $fallback;
}

View file

@ -16,9 +16,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0
*
* @param string $url GitHub repository URL.
* @return array|WP_Error Array with 'owner' and 'repo' or error.
* @return array{owner: string, repo: string}|WP_Error Array with 'owner' and 'repo' or error.
*/
function robotstxt_docmd_parse_github_url( $url ) {
function robotstxt_docmd_parse_github_url( string $url ): array|WP_Error {
if ( ! str_starts_with( $url, 'https://' ) ) {
return new WP_Error( 'invalid_url', __( 'GitHub URL must use HTTPS', 'robotstxt-documentation-markdown' ) );
}
@ -33,6 +33,43 @@ function robotstxt_docmd_parse_github_url( $url ) {
return new WP_Error( 'invalid_format', __( 'Could not parse GitHub URL', 'robotstxt-documentation-markdown' ) );
}
/**
* Validate and normalize a list of file data from cache or API response
*
* Converts untyped cache data back into the expected typed structure.
* Required for PHPStan level 9 compliance with transient cache usage.
*
* @since 1.0.1
*
* @param mixed $data Raw data to validate (typically from get_transient()).
* @return list<array{path: string, name: string, size: int, sha: string}>
*/
function robotstxt_docmd_validate_file_list( mixed $data ): array {
if ( ! is_array( $data ) ) {
return array();
}
$result = array();
foreach ( $data as $item ) {
if ( is_array( $item )
&& isset( $item['path'], $item['name'], $item['size'], $item['sha'] )
&& is_string( $item['path'] )
&& is_string( $item['name'] )
&& is_int( $item['size'] )
&& is_string( $item['sha'] )
) {
$result[] = array(
'path' => $item['path'],
'name' => $item['name'],
'size' => $item['size'],
'sha' => $item['sha'],
);
}
}
return $result;
}
/**
* Get all markdown files from repository
*
@ -42,15 +79,15 @@ function robotstxt_docmd_parse_github_url( $url ) {
* @param string $repo Repository name.
* @param string $branch Branch name.
* @param string $token GitHub token (encrypted).
* @return array|WP_Error Array of files or error.
* @return list<array{path: string, name: string, size: int, sha: string}>|WP_Error Array of files or error.
*/
function robotstxt_docmd_get_all_markdown_files( $owner, $repo, $branch, $token ) {
function robotstxt_docmd_get_all_markdown_files( string $owner, string $repo, string $branch, string $token ): array|WP_Error {
// Check cache first.
$cache_key = sprintf( 'robotstxt_docmd_files_%s_%s_%s', $owner, $repo, $branch );
$cached = get_transient( $cache_key );
if ( false !== $cached ) {
return $cached;
return robotstxt_docmd_validate_file_list( $cached );
}
// Decrypt token.
@ -63,16 +100,13 @@ function robotstxt_docmd_get_all_markdown_files( $owner, $repo, $branch, $token
return $files;
}
// Filter only markdown files.
$markdown_files = array_filter(
$files,
function ( $file ) {
return preg_match( '/\.(md|markdown)$/i', $file['path'] );
// Filter only markdown files and re-index.
$markdown_files = array();
foreach ( $files as $file ) {
if ( preg_match( '/\.(md|markdown)$/i', $file['path'] ) ) {
$markdown_files[] = $file;
}
);
// Re-index array.
$markdown_files = array_values( $markdown_files );
}
// Cache for 24 hours.
set_transient( $cache_key, $markdown_files, DAY_IN_SECONDS );
@ -91,9 +125,9 @@ function robotstxt_docmd_get_all_markdown_files( $owner, $repo, $branch, $token
* @param string $branch Branch name.
* @param string $token GitHub token (plain).
* @param int $depth Current depth (for recursion limit).
* @return array|WP_Error Array of files or error.
* @return list<array{path: string, name: string, size: int, sha: string}>|WP_Error Array of files or error.
*/
function robotstxt_docmd_get_repository_contents_recursive( $owner, $repo, $path, $branch, $token, $depth = 0 ) {
function robotstxt_docmd_get_repository_contents_recursive( string $owner, string $repo, string $path, string $branch, string $token, int $depth = 0 ): array|WP_Error {
// Prevent infinite recursion.
if ( $depth > 10 ) {
return array();
@ -145,6 +179,17 @@ function robotstxt_docmd_get_repository_contents_recursive( $owner, $repo, $path
$files = array();
foreach ( $contents as $item ) {
if ( ! is_array( $item )
|| ! isset( $item['type'], $item['path'], $item['name'], $item['size'], $item['sha'] )
|| ! is_string( $item['type'] )
|| ! is_string( $item['path'] )
|| ! is_string( $item['name'] )
|| ! is_string( $item['sha'] )
|| ! is_int( $item['size'] )
) {
continue;
}
if ( 'file' === $item['type'] ) {
// Skip files larger than 10MB.
if ( $item['size'] > 10 * 1024 * 1024 ) {
@ -189,7 +234,7 @@ function robotstxt_docmd_get_repository_contents_recursive( $owner, $repo, $path
* @param string $token GitHub token (encrypted).
* @return string|WP_Error File content or error.
*/
function robotstxt_docmd_get_file_content( $owner, $repo, $file_path, $branch, $token ) {
function robotstxt_docmd_get_file_content( string $owner, string $repo, string $file_path, string $branch, string $token ): string|WP_Error {
$decrypted_token = robotstxt_docmd_decrypt_token( $token );
$url = sprintf(
@ -231,7 +276,11 @@ function robotstxt_docmd_get_file_content( $owner, $repo, $file_path, $branch, $
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body, true );
if ( ! isset( $data['content'] ) || ! isset( $data['encoding'] ) ) {
if ( ! is_array( $data )
|| ! isset( $data['content'], $data['encoding'] )
|| ! is_string( $data['content'] )
|| ! is_string( $data['encoding'] )
) {
return new WP_Error( 'invalid_response', __( 'Invalid file response from GitHub', 'robotstxt-documentation-markdown' ) );
}

View file

@ -15,9 +15,9 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* @since 1.0.0
*
* @return array Array of mappings.
* @return list<MappingData> Array of mappings.
*/
function robotstxt_docmd_get_all_mappings() {
function robotstxt_docmd_get_all_mappings(): array {
$args = array(
'post_type' => 'robotstxt_map',
'posts_per_page' => -1,
@ -30,6 +30,9 @@ function robotstxt_docmd_get_all_mappings() {
$mappings = array();
foreach ( $query->posts as $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
continue;
}
$mapping = robotstxt_docmd_get_mapping( $post->ID );
if ( $mapping ) {
$mappings[] = $mapping;
@ -47,23 +50,34 @@ function robotstxt_docmd_get_all_mappings() {
* @since 1.0.0
*
* @param int $mapping_id Mapping post ID.
* @return array|null Mapping data or null.
* @return MappingData|null Mapping data or null.
*/
function robotstxt_docmd_get_mapping( $mapping_id ) {
function robotstxt_docmd_get_mapping( int $mapping_id ): ?array {
$post = get_post( $mapping_id );
if ( ! $post || 'robotstxt_map' !== $post->post_type ) {
return null;
}
$repo_owner = get_post_meta( $mapping_id, '_robotstxt_docmd_repo_owner', true );
$repo_name = get_post_meta( $mapping_id, '_robotstxt_docmd_repo_name', true );
$file_path = get_post_meta( $mapping_id, '_robotstxt_docmd_file_path', true );
$branch = get_post_meta( $mapping_id, '_robotstxt_docmd_branch', true );
$repo_owner_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_repo_owner', true );
$repo_name_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_repo_name', true );
$file_path_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_file_path', true );
$branch_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_branch', true );
if ( empty( $branch ) ) {
$branch = 'main';
}
$repo_owner = is_string( $repo_owner_raw ) ? $repo_owner_raw : '';
$repo_name = is_string( $repo_name_raw ) ? $repo_name_raw : '';
$file_path = is_string( $file_path_raw ) ? $file_path_raw : '';
$branch = is_string( $branch_raw ) && '' !== $branch_raw ? $branch_raw : 'main';
$post_type_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_target_post_type', true );
$sync_frequency_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_sync_frequency', true );
$sync_status_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_sync_status', true );
$last_sync_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_last_sync', true );
$target_post_id_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_target_post_id', true );
$target_author_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_target_author', true );
$target_parent_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_target_parent', true );
$target_order_raw = get_post_meta( $mapping_id, '_robotstxt_docmd_target_order', true );
return array(
'id' => $mapping_id,
@ -73,14 +87,15 @@ function robotstxt_docmd_get_mapping( $mapping_id ) {
'file_path' => $file_path,
'branch' => $branch,
'github_url' => sprintf( 'https://github.com/%s/%s/blob/%s/%s', $repo_owner, $repo_name, $branch, $file_path ),
'target_post_type' => get_post_meta( $mapping_id, '_robotstxt_docmd_target_post_type', true ),
'target_post_id' => absint( get_post_meta( $mapping_id, '_robotstxt_docmd_target_post_id', true ) ),
'target_author' => absint( get_post_meta( $mapping_id, '_robotstxt_docmd_target_author', true ) ),
'target_parent' => absint( get_post_meta( $mapping_id, '_robotstxt_docmd_target_parent', true ) ),
'target_post_type' => is_string( $post_type_raw ) ? $post_type_raw : '',
'target_post_id' => is_numeric( $target_post_id_raw ) ? absint( $target_post_id_raw ) : 0,
'target_author' => is_numeric( $target_author_raw ) ? absint( $target_author_raw ) : 0,
'target_parent' => is_numeric( $target_parent_raw ) ? absint( $target_parent_raw ) : 0,
'target_order' => is_numeric( $target_order_raw ) ? absint( $target_order_raw ) : 0,
'sync_enabled' => (bool) get_post_meta( $mapping_id, '_robotstxt_docmd_sync_enabled', true ),
'sync_frequency' => get_post_meta( $mapping_id, '_robotstxt_docmd_sync_frequency', true ),
'sync_status' => get_post_meta( $mapping_id, '_robotstxt_docmd_sync_status', true ) ? get_post_meta( $mapping_id, '_robotstxt_docmd_sync_status', true ) : 'never',
'last_sync' => get_post_meta( $mapping_id, '_robotstxt_docmd_last_sync', true ),
'sync_frequency' => is_string( $sync_frequency_raw ) ? $sync_frequency_raw : 'daily',
'sync_status' => is_string( $sync_status_raw ) && '' !== $sync_status_raw ? $sync_status_raw : 'never',
'last_sync' => is_string( $last_sync_raw ) ? $last_sync_raw : '',
);
}
@ -89,10 +104,11 @@ function robotstxt_docmd_get_mapping( $mapping_id ) {
*
* @since 1.0.0
*
* @param array $data Mapping data.
* @param array $data Mapping input data.
* @phpstan-param MappingInput $data
* @return int|WP_Error Mapping ID or error.
*/
function robotstxt_docmd_create_mapping( $data ) {
function robotstxt_docmd_create_mapping( array $data ): int|WP_Error {
// Check for duplicates.
if ( robotstxt_docmd_is_file_mapped( $data['repo_owner'], $data['repo_name'], $data['file_path'], $data['branch'] ) ) {
return new WP_Error( 'duplicate_mapping', __( 'This file is already mapped', 'robotstxt-documentation-markdown' ) );
@ -119,7 +135,8 @@ function robotstxt_docmd_create_mapping( $data ) {
update_post_meta( $post_id, '_robotstxt_docmd_branch', $data['branch'] );
update_post_meta( $post_id, '_robotstxt_docmd_target_post_type', $data['target_post_type'] );
update_post_meta( $post_id, '_robotstxt_docmd_target_author', $data['target_author'] );
update_post_meta( $post_id, '_robotstxt_docmd_target_parent', $data['target_parent'] ?? 0 );
update_post_meta( $post_id, '_robotstxt_docmd_target_parent', $data['target_parent'] );
update_post_meta( $post_id, '_robotstxt_docmd_target_order', $data['target_order'] );
update_post_meta( $post_id, '_robotstxt_docmd_sync_enabled', $data['sync_enabled'] ? 1 : 0 );
update_post_meta( $post_id, '_robotstxt_docmd_sync_frequency', $data['sync_frequency'] );
@ -141,10 +158,11 @@ function robotstxt_docmd_create_mapping( $data ) {
* @since 1.0.0
*
* @param int $mapping_id Mapping ID.
* @param array $data Mapping data.
* @return bool|WP_Error True on success or error.
* @param array $data Mapping input data.
* @phpstan-param MappingInput $data
* @return bool True on success.
*/
function robotstxt_docmd_update_mapping( $mapping_id, $data ) {
function robotstxt_docmd_update_mapping( int $mapping_id, array $data ): bool {
// Update post title.
wp_update_post(
array(
@ -160,7 +178,8 @@ function robotstxt_docmd_update_mapping( $mapping_id, $data ) {
update_post_meta( $mapping_id, '_robotstxt_docmd_branch', $data['branch'] );
update_post_meta( $mapping_id, '_robotstxt_docmd_target_post_type', $data['target_post_type'] );
update_post_meta( $mapping_id, '_robotstxt_docmd_target_author', $data['target_author'] );
update_post_meta( $mapping_id, '_robotstxt_docmd_target_parent', $data['target_parent'] ?? 0 );
update_post_meta( $mapping_id, '_robotstxt_docmd_target_parent', $data['target_parent'] );
update_post_meta( $mapping_id, '_robotstxt_docmd_target_order', $data['target_order'] );
update_post_meta( $mapping_id, '_robotstxt_docmd_sync_enabled', $data['sync_enabled'] ? 1 : 0 );
update_post_meta( $mapping_id, '_robotstxt_docmd_sync_frequency', $data['sync_frequency'] );
@ -185,7 +204,7 @@ function robotstxt_docmd_update_mapping( $mapping_id, $data ) {
* @param int $mapping_id Mapping ID.
* @return bool True on success.
*/
function robotstxt_docmd_delete_mapping( $mapping_id ) {
function robotstxt_docmd_delete_mapping( int $mapping_id ): bool {
robotstxt_docmd_unschedule_mapping_sync( $mapping_id );
wp_delete_post( $mapping_id, true );
return true;
@ -202,7 +221,7 @@ function robotstxt_docmd_delete_mapping( $mapping_id ) {
* @param string $branch Branch name.
* @return bool True if mapped.
*/
function robotstxt_docmd_is_file_mapped( $owner, $repo, $file_path, $branch ) {
function robotstxt_docmd_is_file_mapped( string $owner, string $repo, string $file_path, string $branch ): bool {
$args = array(
'post_type' => 'robotstxt_map',
'posts_per_page' => 1,
@ -238,7 +257,7 @@ function robotstxt_docmd_is_file_mapped( $owner, $repo, $file_path, $branch ) {
* @param int $mapping_id Mapping ID.
* @return bool|WP_Error True on success or error.
*/
function robotstxt_docmd_sync_mapping( $mapping_id ) {
function robotstxt_docmd_sync_mapping( int $mapping_id ): bool|WP_Error {
$mapping = robotstxt_docmd_get_mapping( $mapping_id );
if ( ! $mapping ) {
@ -249,8 +268,10 @@ function robotstxt_docmd_sync_mapping( $mapping_id ) {
update_post_meta( $mapping_id, '_robotstxt_docmd_sync_status', 'pending' );
// Get settings.
$settings = get_option( 'robotstxt_docmd_settings', array() );
$token = $settings['github_token'] ?? '';
$raw_settings = get_option( 'robotstxt_docmd_settings' );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
$token_raw = $settings['github_token'] ?? '';
$token = is_string( $token_raw ) ? $token_raw : '';
if ( empty( $token ) ) {
update_post_meta( $mapping_id, '_robotstxt_docmd_sync_status', 'error' );
@ -286,6 +307,7 @@ function robotstxt_docmd_sync_mapping( $mapping_id ) {
'post_status' => 'publish',
'post_author' => $mapping['target_author'],
'post_parent' => $mapping['target_parent'],
'menu_order' => $mapping['target_order'],
),
true
);

View file

@ -3,8 +3,8 @@
* Plugin Name: Documentation Markdown (by ROBOTSTXT)
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown
* Description: Synchronizes Markdown documentation from GitHub repositories to WordPress pages and posts automatically.
* Version: 1.0.0
* Requires at least: 6.5
* Version: 1.1.0
* Requires at least: 6.7
* Requires PHP: 8.2
* Security: robotstxt@robotstxt.es
* Author: ROBOTSTXT
@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
// Define plugin constants.
define( 'ROBOTSTXT_DOCMD_VERSION', '1.0.0' );
define( 'ROBOTSTXT_DOCMD_VERSION', '1.1.0' );
define( 'ROBOTSTXT_DOCMD_PLUGIN_FILE', __FILE__ );
define( 'ROBOTSTXT_DOCMD_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ROBOTSTXT_DOCMD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
@ -99,13 +99,6 @@ function robotstxt_docmd_deactivate() {
* @return void
*/
function robotstxt_docmd_init() {
// Load textdomain.
load_plugin_textdomain(
'robotstxt-documentation-markdown',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
// Register CPT.
robotstxt_docmd_register_post_types();
}
@ -154,7 +147,7 @@ function robotstxt_docmd_register_admin_menu() {
add_menu_page(
__( 'Documentation', 'robotstxt-documentation-markdown' ),
__( 'Documentation', 'robotstxt-documentation-markdown' ),
'manage_options',
'edit_pages',
'robotstxt-docmd-mappings',
'robotstxt_docmd_render_mappings_page',
'dashicons-media-document',
@ -166,7 +159,7 @@ function robotstxt_docmd_register_admin_menu() {
'robotstxt-docmd-mappings',
__( 'Mappings', 'robotstxt-documentation-markdown' ),
__( 'Mappings', 'robotstxt-documentation-markdown' ),
'manage_options',
'edit_pages',
'robotstxt-docmd-mappings',
'robotstxt_docmd_render_mappings_page'
);
@ -176,7 +169,7 @@ function robotstxt_docmd_register_admin_menu() {
'robotstxt-docmd-mappings',
__( 'Discover Files', 'robotstxt-documentation-markdown' ),
__( 'Discover Files', 'robotstxt-documentation-markdown' ),
'manage_options',
'edit_pages',
'robotstxt-docmd-discover',
'robotstxt_docmd_render_discover_page'
);
@ -186,7 +179,7 @@ function robotstxt_docmd_register_admin_menu() {
'robotstxt-docmd-mappings',
__( 'Add New', 'robotstxt-documentation-markdown' ),
__( 'Add New', 'robotstxt-documentation-markdown' ),
'manage_options',
'edit_pages',
'robotstxt-docmd-add-mapping',
'robotstxt_docmd_render_add_mapping_page'
);
@ -196,7 +189,7 @@ function robotstxt_docmd_register_admin_menu() {
'robotstxt-docmd-mappings',
__( 'Settings', 'robotstxt-documentation-markdown' ),
__( 'Settings', 'robotstxt-documentation-markdown' ),
'manage_options',
'edit_pages',
'robotstxt-docmd-settings',
'robotstxt_docmd_render_settings_page'
);
@ -232,14 +225,14 @@ function robotstxt_docmd_enqueue_admin_assets( $hook ) {
* @return void
*/
function robotstxt_docmd_handle_admin_actions() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
return;
}
// Handle mapping form submission (POST).
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['robotstxt_docmd_nonce'] ) && isset( $_POST['title'] ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['robotstxt_docmd_nonce'] ) ), 'robotstxt_docmd_save_mapping' ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'robotstxt_docmd_nonce' ) ) ), 'robotstxt_docmd_save_mapping' ) ) {
robotstxt_docmd_handle_save_mapping();
// The function above will redirect and exit.
}
@ -248,7 +241,7 @@ function robotstxt_docmd_handle_admin_actions() {
// Handle settings form submission (POST).
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['robotstxt_docmd_nonce'] ) && isset( $_POST['github_url'] ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['robotstxt_docmd_nonce'] ) ), 'robotstxt_docmd_save_settings' ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'robotstxt_docmd_nonce' ) ) ), 'robotstxt_docmd_save_settings' ) ) {
robotstxt_docmd_handle_save_settings();
// The function above will redirect and exit.
}
@ -257,7 +250,7 @@ function robotstxt_docmd_handle_admin_actions() {
// Handle debug actions (only on settings page).
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['page'] ) && 'robotstxt-docmd-settings' === $_GET['page'] && isset( $_GET['debug_action'] ) ) {
$debug_action = sanitize_key( wp_unslash( $_GET['debug_action'] ) );
$debug_action = sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_GET, 'debug_action' ) ) );
if ( 'test_github' === $debug_action ) {
check_admin_referer( 'robotstxt_docmd_debug_test_github' );
@ -272,7 +265,7 @@ function robotstxt_docmd_handle_admin_actions() {
}
if ( 'run_cron' === $debug_action && isset( $_GET['mapping_id'] ) ) {
$mapping_id = absint( wp_unslash( $_GET['mapping_id'] ) );
$mapping_id = robotstxt_docmd_input_int( $_GET, 'mapping_id' );
check_admin_referer( 'robotstxt_docmd_debug_run_cron_' . $mapping_id );
robotstxt_docmd_debug_run_cron( $mapping_id );
return;
@ -300,8 +293,8 @@ function robotstxt_docmd_handle_admin_actions() {
return;
}
$action = sanitize_key( wp_unslash( $_GET['action'] ) );
$mapping_id = absint( wp_unslash( $_GET['mapping_id'] ) );
$action = sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_GET, 'action' ) ) );
$mapping_id = robotstxt_docmd_input_int( $_GET, 'mapping_id' );
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( 'sync' === $action ) {
@ -332,7 +325,7 @@ function robotstxt_docmd_handle_admin_actions() {
* @return void
*/
function robotstxt_docmd_render_mappings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions.', 'robotstxt-documentation-markdown' ) );
}
@ -380,8 +373,8 @@ function robotstxt_docmd_render_mappings_page() {
</td>
<td>
<?php if ( ! empty( $mapping['target_post_id'] ) ) : ?>
<a href="<?php echo esc_url( get_permalink( $mapping['target_post_id'] ) ); ?>" target="_blank" rel="noopener noreferrer">
<?php echo esc_html( get_the_title( $mapping['target_post_id'] ) ); ?>
<a href="<?php echo esc_url( (string) get_permalink( (int) $mapping['target_post_id'] ) ); ?>" target="_blank" rel="noopener noreferrer">
<?php echo esc_html( (string) get_the_title( (int) $mapping['target_post_id'] ) ); ?>
</a>
<?php else : ?>
<em><?php esc_html_e( 'Not created yet', 'robotstxt-documentation-markdown' ); ?></em>
@ -418,14 +411,15 @@ function robotstxt_docmd_render_mappings_page() {
* @return void
*/
function robotstxt_docmd_render_discover_page() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions.', 'robotstxt-documentation-markdown' ) );
}
// Get settings.
$settings = get_option( 'robotstxt_docmd_settings', array() );
$github_url = $settings['github_url'] ?? '';
$github_token = $settings['github_token'] ?? '';
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
$github_url = robotstxt_docmd_input_string( $settings, 'github_url' );
$github_token = robotstxt_docmd_input_string( $settings, 'github_token' );
// Parse GitHub URL.
$repo_data = robotstxt_docmd_parse_github_url( $github_url );
@ -452,11 +446,11 @@ function robotstxt_docmd_render_discover_page() {
// Get branch from query string.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$branch = isset( $_GET['branch'] ) ? sanitize_text_field( wp_unslash( $_GET['branch'] ) ) : 'main';
$branch = sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_GET, 'branch', 'main' ) ) );
// Check if refresh requested.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$refresh = isset( $_GET['refresh'] ) && '1' === $_GET['refresh'];
$refresh = '1' === robotstxt_docmd_input_string( $_GET, 'refresh' );
if ( $refresh ) {
$cache_key = sprintf( 'robotstxt_docmd_files_%s_%s_%s', $repo_data['owner'], $repo_data['repo'], $branch );
delete_transient( $cache_key );
@ -542,15 +536,14 @@ function robotstxt_docmd_render_discover_page() {
<tbody>
<?php foreach ( $files as $file ) : ?>
<?php
// Skip if file doesn't have required keys.
if ( ! isset( $file['path'] ) || ! isset( $file['size'] ) ) {
continue;
}
$is_mapped = robotstxt_docmd_is_file_mapped( $repo_data['owner'], $repo_data['repo'], $file['path'], $branch );
?>
<tr>
<td><code><?php echo esc_html( $file['path'] ); ?></code></td>
<td><?php echo esc_html( size_format( $file['size'], 2 ) ); ?></td>
<?php
$file_size_str = size_format( $file['size'], 2 );
?>
<td><?php echo esc_html( false !== $file_size_str ? $file_size_str : '0 B' ); ?></td>
<td>
<?php if ( $is_mapped ) : ?>
<span class="status-badge status-mapped"><?php esc_html_e( 'Mapped', 'robotstxt-documentation-markdown' ); ?></span>
@ -599,28 +592,28 @@ function robotstxt_docmd_render_discover_page() {
* @return void
*/
function robotstxt_docmd_render_add_mapping_page() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions.', 'robotstxt-documentation-markdown' ) );
}
// Get mapping ID if editing.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$mapping_id = isset( $_GET['mapping_id'] ) ? absint( wp_unslash( $_GET['mapping_id'] ) ) : 0;
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$mapping_id = robotstxt_docmd_input_int( $_GET, 'mapping_id' );
$mapping = $mapping_id ? robotstxt_docmd_get_mapping( $mapping_id ) : null;
// Pre-fill from discover page or defaults.
$defaults = array(
'title' => '',
// phpcs:disable WordPress.Security.NonceVerification.Recommended
'repo_owner' => isset( $_GET['owner'] ) ? sanitize_text_field( wp_unslash( $_GET['owner'] ) ) : '',
'repo_name' => isset( $_GET['repo'] ) ? sanitize_text_field( wp_unslash( $_GET['repo'] ) ) : '',
'file_path' => isset( $_GET['file_path'] ) ? urldecode( sanitize_text_field( wp_unslash( $_GET['file_path'] ) ) ) : '',
'branch' => isset( $_GET['branch'] ) ? sanitize_text_field( wp_unslash( $_GET['branch'] ) ) : 'main',
'repo_owner' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_GET, 'owner' ) ) ),
'repo_name' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_GET, 'repo' ) ) ),
'file_path' => urldecode( sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_GET, 'file_path' ) ) ) ),
'branch' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_GET, 'branch', 'main' ) ) ),
// phpcs:enable WordPress.Security.NonceVerification.Recommended
'target_post_type' => 'page',
'target_post_id' => 0,
'target_author' => get_current_user_id(),
'target_parent' => 0,
'target_order' => 0,
'sync_enabled' => true,
'sync_frequency' => 'daily',
);
@ -641,7 +634,7 @@ function robotstxt_docmd_render_add_mapping_page() {
<form method="post" action="">
<?php wp_nonce_field( 'robotstxt_docmd_save_mapping', 'robotstxt_docmd_nonce' ); ?>
<?php if ( $mapping_id ) : ?>
<input type="hidden" name="mapping_id" value="<?php echo esc_attr( $mapping_id ); ?>">
<input type="hidden" name="mapping_id" value="<?php echo esc_attr( (string) $mapping_id ); ?>">
<?php endif; ?>
<table class="form-table">
@ -727,8 +720,8 @@ function robotstxt_docmd_render_add_mapping_page() {
array(
'name' => 'target_parent',
'show_option_none' => esc_html__( '(no parent)', 'robotstxt-documentation-markdown' ),
'option_none_value' => 0,
'selected' => absint( $data['target_parent'] ?? 0 ),
'option_none_value' => '0',
'selected' => absint( $data['target_parent'] ),
)
);
?>
@ -750,7 +743,7 @@ function robotstxt_docmd_render_add_mapping_page() {
<label>
<?php esc_html_e( 'Order:', 'robotstxt-documentation-markdown' ); ?>
<input type="number" name="target_order" value="<?php echo esc_attr( $data['target_order'] ?? 0 ); ?>" class="small-text" min="0" step="1">
<input type="number" name="target_order" value="<?php echo esc_attr( (string) $data['target_order'] ); ?>" class="small-text" min="0" step="1">
<p class="description"><?php esc_html_e( 'Page order (menu_order). Lower numbers appear first. Default: 0', 'robotstxt-documentation-markdown' ); ?></p>
</label>
</div>
@ -781,7 +774,7 @@ function robotstxt_docmd_render_add_mapping_page() {
foreach ( $all_posts as $post ) {
printf(
'<option value="%d" %s>%s (%s)</option>',
esc_attr( $post->ID ),
esc_attr( (string) $post->ID ),
selected( $data['target_post_id'], $post->ID, false ),
esc_html( $post->post_title ),
esc_html( $post->post_type )
@ -857,36 +850,35 @@ function robotstxt_docmd_render_add_mapping_page() {
* @return void
*/
function robotstxt_docmd_handle_save_mapping() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
return;
}
// Verify nonce.
if ( ! isset( $_POST['robotstxt_docmd_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['robotstxt_docmd_nonce'] ) ), 'robotstxt_docmd_save_mapping' ) ) {
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'robotstxt_docmd_nonce' ) ) ), 'robotstxt_docmd_save_mapping' ) ) {
wp_die( esc_html__( 'Security check failed.', 'robotstxt-documentation-markdown' ) );
}
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$mapping_id = isset( $_POST['mapping_id'] ) ? absint( wp_unslash( $_POST['mapping_id'] ) ) : 0;
$mapping_id = robotstxt_docmd_input_int( $_POST, 'mapping_id' );
$data = array(
'title' => sanitize_text_field( wp_unslash( $_POST['title'] ?? '' ) ),
'repo_owner' => sanitize_text_field( wp_unslash( $_POST['repo_owner'] ?? '' ) ),
'repo_name' => sanitize_text_field( wp_unslash( $_POST['repo_name'] ?? '' ) ),
'file_path' => sanitize_text_field( wp_unslash( $_POST['file_path'] ?? '' ) ),
'branch' => sanitize_text_field( wp_unslash( $_POST['branch'] ?? 'main' ) ),
'target_post_type' => sanitize_key( wp_unslash( $_POST['target_post_type'] ?? 'page' ) ),
'target_author' => absint( wp_unslash( $_POST['target_author'] ?? get_current_user_id() ) ),
'target_parent' => absint( wp_unslash( $_POST['target_parent'] ?? 0 ) ),
'title' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'title' ) ) ),
'repo_owner' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'repo_owner' ) ) ),
'repo_name' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'repo_name' ) ) ),
'file_path' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'file_path' ) ) ),
'branch' => sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'branch', 'main' ) ) ),
'target_post_type' => sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_POST, 'target_post_type', 'page' ) ) ),
'target_author' => robotstxt_docmd_input_int( $_POST, 'target_author', get_current_user_id() ),
'target_parent' => robotstxt_docmd_input_int( $_POST, 'target_parent' ),
'target_order' => robotstxt_docmd_input_int( $_POST, 'target_order' ),
'sync_enabled' => ! empty( $_POST['sync_enabled'] ),
'sync_frequency' => sanitize_key( wp_unslash( $_POST['sync_frequency'] ?? 'daily' ) ),
'sync_frequency' => sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_POST, 'sync_frequency', 'daily' ) ) ),
);
$target_type = sanitize_key( wp_unslash( $_POST['target_type'] ?? 'new' ) );
$target_type = sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_POST, 'target_type', 'new' ) ) );
if ( 'existing' === $target_type ) {
$data['target_post_id'] = absint( wp_unslash( $_POST['target_post_id'] ?? 0 ) );
$data['target_post_id'] = robotstxt_docmd_input_int( $_POST, 'target_post_id' );
}
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( $mapping_id ) {
$result = robotstxt_docmd_update_mapping( $mapping_id, $data );
@ -915,29 +907,33 @@ function robotstxt_docmd_handle_save_mapping() {
*/
function robotstxt_docmd_render_admin_notices() {
// Check for regular message parameter.
if ( isset( $_GET['message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$message = sanitize_key( wp_unslash( $_GET['message'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( 'settings_saved' === $message ) {
echo '<div class="notice notice-success is-dismissible"><p>';
esc_html_e( 'Settings saved successfully.', 'robotstxt-documentation-markdown' );
echo '</p></div>';
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$message = sanitize_key( wp_unslash( robotstxt_docmd_input_string( $_GET, 'message' ) ) );
if ( 'settings_saved' === $message ) {
echo '<div class="notice notice-success is-dismissible"><p>';
esc_html_e( 'Settings saved successfully.', 'robotstxt-documentation-markdown' );
echo '</p></div>';
}
// Check for debug results.
$debug_result = get_transient( 'robotstxt_docmd_debug_result' );
if ( $debug_result ) {
if ( is_array( $debug_result )
&& isset( $debug_result['type'], $debug_result['message'] )
&& is_string( $debug_result['type'] )
&& is_string( $debug_result['message'] )
) {
delete_transient( 'robotstxt_docmd_debug_result' );
$notice_class = 'notice-' . $debug_result['type'];
echo '<div class="notice ' . esc_attr( $notice_class ) . ' is-dismissible">';
echo '<p><strong>' . wp_kses_post( $debug_result['message'] ) . '</strong></p>';
if ( ! empty( $debug_result['details'] ) ) {
if ( ! empty( $debug_result['details'] ) && is_array( $debug_result['details'] ) ) {
echo '<ul style="list-style: disc; margin-left: 20px;">';
foreach ( $debug_result['details'] as $detail ) {
echo '<li>' . wp_kses_post( $detail ) . '</li>';
if ( is_string( $detail ) ) {
echo '<li>' . wp_kses_post( $detail ) . '</li>';
}
}
echo '</ul>';
}
@ -954,11 +950,12 @@ function robotstxt_docmd_render_admin_notices() {
* @return void
*/
function robotstxt_docmd_render_settings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions.', 'robotstxt-documentation-markdown' ) );
}
$settings = get_option( 'robotstxt_docmd_settings', array() );
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
?>
<div class="wrap robotstxt-docmd-settings">
@ -976,7 +973,7 @@ function robotstxt_docmd_render_settings_page() {
<label for="github_url"><?php esc_html_e( 'Repository URL', 'robotstxt-documentation-markdown' ); ?> <span class="required">*</span></label>
</th>
<td>
<input type="url" id="github_url" name="github_url" value="<?php echo esc_attr( $settings['github_url'] ?? '' ); ?>" class="regular-text" required>
<input type="url" id="github_url" name="github_url" value="<?php echo esc_attr( robotstxt_docmd_input_string( $settings, 'github_url' ) ); ?>" class="regular-text" required>
<p class="description"><?php esc_html_e( 'Full GitHub repository URL (e.g., https://github.com/owner/repo)', 'robotstxt-documentation-markdown' ); ?></p>
</td>
</tr>
@ -988,7 +985,7 @@ function robotstxt_docmd_render_settings_page() {
<td>
<input type="password" id="github_token" name="github_token" value="" class="regular-text" placeholder="<?php esc_attr_e( 'Enter new token to update', 'robotstxt-documentation-markdown' ); ?>">
<p class="description"><?php esc_html_e( 'GitHub Personal Access Token with "repo" scope', 'robotstxt-documentation-markdown' ); ?></p>
<?php if ( ! empty( $settings['github_token'] ) ) : ?>
<?php if ( ! empty( robotstxt_docmd_input_string( $settings, 'github_token' ) ) ) : ?>
<p class="description"><strong><?php esc_html_e( 'Token is currently set. Leave blank to keep existing token.', 'robotstxt-documentation-markdown' ); ?></strong></p>
<?php endif; ?>
</td>
@ -1080,7 +1077,9 @@ function robotstxt_docmd_render_settings_page() {
echo '<td>' . esc_html( $mapping['sync_frequency'] ) . '</td>';
echo '<td>';
if ( $timestamp ) {
echo esc_html( gmdate( 'Y-m-d H:i:s', $timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
$gmt_offset_raw = get_option( 'gmt_offset', 0 );
$gmt_offset_sec = is_numeric( $gmt_offset_raw ) ? (int) ( (float) $gmt_offset_raw * HOUR_IN_SECONDS ) : 0;
echo esc_html( gmdate( 'Y-m-d H:i:s', $timestamp + $gmt_offset_sec ) );
} else {
echo '<em>' . esc_html__( 'Not scheduled', 'robotstxt-documentation-markdown' ) . '</em>';
}
@ -1134,21 +1133,20 @@ function robotstxt_docmd_render_settings_page() {
* @return void
*/
function robotstxt_docmd_handle_save_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
return;
}
// Verify nonce.
if ( ! isset( $_POST['robotstxt_docmd_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['robotstxt_docmd_nonce'] ) ), 'robotstxt_docmd_save_settings' ) ) {
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'robotstxt_docmd_nonce' ) ) ), 'robotstxt_docmd_save_settings' ) ) {
wp_die( esc_html__( 'Security check failed.', 'robotstxt-documentation-markdown' ) );
}
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$github_url = sanitize_text_field( wp_unslash( $_POST['github_url'] ?? '' ) );
$github_token = sanitize_text_field( wp_unslash( $_POST['github_token'] ?? '' ) );
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$github_url = sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'github_url' ) ) );
$github_token = sanitize_text_field( wp_unslash( robotstxt_docmd_input_string( $_POST, 'github_token' ) ) );
$settings = get_option( 'robotstxt_docmd_settings', array() );
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
$settings['github_url'] = $github_url;
@ -1177,13 +1175,14 @@ function robotstxt_docmd_handle_save_settings() {
* @return void
*/
function robotstxt_docmd_debug_test_github() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'Permission denied.', 'robotstxt-documentation-markdown' ) );
}
$settings = get_option( 'robotstxt_docmd_settings', array() );
$repo_url = $settings['github_url'] ?? '';
$token = $settings['github_token'] ?? '';
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
$repo_url = robotstxt_docmd_input_string( $settings, 'github_url' );
$token = robotstxt_docmd_input_string( $settings, 'github_token' );
$result = array(
'type' => 'error',
@ -1241,27 +1240,32 @@ function robotstxt_docmd_debug_test_github() {
$response->get_error_message()
);
} elseif ( 200 === $status_code ) {
$body = json_decode( wp_remote_retrieve_body( $response ), true );
$body = json_decode( wp_remote_retrieve_body( $response ), true );
$full_name = is_array( $body ) && isset( $body['full_name'] ) && is_string( $body['full_name'] ) ? $body['full_name'] : 'N/A';
$repo_name = is_array( $body ) && isset( $body['name'] ) && is_string( $body['name'] ) ? $body['name'] : 'N/A';
$is_private = is_array( $body ) && ! empty( $body['private'] );
$default_branch = is_array( $body ) && isset( $body['default_branch'] ) && is_string( $body['default_branch'] ) ? $body['default_branch'] : 'N/A';
$result['type'] = 'success';
$result['message'] = sprintf(
/* translators: %s: repository full name */
__( 'Successfully connected to repository: %s', 'robotstxt-documentation-markdown' ),
$body['full_name'] ?? 'N/A'
$full_name
);
$result['details'][] = sprintf(
'<strong>%s:</strong> %s',
__( 'Name', 'robotstxt-documentation-markdown' ),
$body['name'] ?? 'N/A'
$repo_name
);
$result['details'][] = sprintf(
'<strong>%s:</strong> %s',
__( 'Private', 'robotstxt-documentation-markdown' ),
! empty( $body['private'] ) ? __( 'Yes', 'robotstxt-documentation-markdown' ) : __( 'No', 'robotstxt-documentation-markdown' )
$is_private ? __( 'Yes', 'robotstxt-documentation-markdown' ) : __( 'No', 'robotstxt-documentation-markdown' )
);
$result['details'][] = sprintf(
'<strong>%s:</strong> %s',
__( 'Default Branch', 'robotstxt-documentation-markdown' ),
$body['default_branch'] ?? 'N/A'
$default_branch
);
} elseif ( 404 === $status_code ) {
$result['message'] = __( 'Repository Not Found: The repository does not exist or your token does not have access to it.', 'robotstxt-documentation-markdown' );
@ -1290,12 +1294,13 @@ function robotstxt_docmd_debug_test_github() {
* @return void
*/
function robotstxt_docmd_debug_test_token() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'Permission denied.', 'robotstxt-documentation-markdown' ) );
}
$settings = get_option( 'robotstxt_docmd_settings', array() );
$token = $settings['github_token'] ?? '';
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
$token = robotstxt_docmd_input_string( $settings, 'github_token' );
$result = array(
'type' => 'error',
@ -1339,11 +1344,13 @@ function robotstxt_docmd_debug_test_token() {
$result['type'] = 'success';
$result['message'] = __( 'Token Valid! Your GitHub token is working correctly.', 'robotstxt-documentation-markdown' );
if ( isset( $body['resources']['core'] ) ) {
$core = $body['resources']['core'];
$remaining = $core['remaining'] ?? 0;
$limit = $core['limit'] ?? 0;
$reset = $core['reset'] ?? 0;
$resources = is_array( $body ) && isset( $body['resources'] ) && is_array( $body['resources'] ) ? $body['resources'] : null;
$core = is_array( $resources ) && isset( $resources['core'] ) && is_array( $resources['core'] ) ? $resources['core'] : null;
if ( null !== $core ) {
$remaining = isset( $core['remaining'] ) && is_int( $core['remaining'] ) ? $core['remaining'] : 0;
$limit = isset( $core['limit'] ) && is_int( $core['limit'] ) ? $core['limit'] : 0;
$reset = isset( $core['reset'] ) && is_int( $core['reset'] ) ? $core['reset'] : 0;
$result['details'][] = sprintf(
'<strong>%s:</strong> %d / %d',
@ -1353,7 +1360,9 @@ function robotstxt_docmd_debug_test_token() {
);
if ( $reset > 0 ) {
$reset_time = gmdate( 'Y-m-d H:i:s', $reset + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
$gmt_offset_raw = get_option( 'gmt_offset', 0 );
$gmt_offset_sec = is_numeric( $gmt_offset_raw ) ? (int) ( (float) $gmt_offset_raw * HOUR_IN_SECONDS ) : 0;
$reset_time = gmdate( 'Y-m-d H:i:s', $reset + $gmt_offset_sec );
$result['details'][] = sprintf(
'<strong>%s:</strong> %s',
__( 'Resets At', 'robotstxt-documentation-markdown' ),
@ -1391,8 +1400,8 @@ function robotstxt_docmd_debug_test_token() {
* @param int $mapping_id Mapping ID to sync.
* @return void
*/
function robotstxt_docmd_debug_run_cron( $mapping_id ) {
if ( ! current_user_can( 'manage_options' ) ) {
function robotstxt_docmd_debug_run_cron( int $mapping_id ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'Permission denied.', 'robotstxt-documentation-markdown' ) );
}
@ -1425,6 +1434,13 @@ function robotstxt_docmd_debug_run_cron( $mapping_id ) {
// Reload mapping to get updated info.
$mapping = robotstxt_docmd_get_mapping( $mapping_id );
if ( ! $mapping ) {
$result['message'] = __( 'Sync completed but mapping data could not be reloaded.', 'robotstxt-documentation-markdown' );
set_transient( 'robotstxt_docmd_debug_result', $result, 60 );
wp_safe_redirect( admin_url( 'admin.php?page=robotstxt-docmd-settings' ) );
exit;
}
$result['type'] = 'success';
$result['message'] = sprintf(
/* translators: %s: mapping title */
@ -1441,11 +1457,11 @@ function robotstxt_docmd_debug_run_cron( $mapping_id ) {
$result['details'][] = sprintf(
'<strong>%s:</strong> %s',
__( 'Last Sync', 'robotstxt-documentation-markdown' ),
$mapping['last_sync'] ?? 'N/A'
$mapping['last_sync']
);
if ( ! empty( $mapping['target_post_id'] ) ) {
$edit_url = get_edit_post_link( $mapping['target_post_id'] );
$edit_url = get_edit_post_link( $mapping['target_post_id'] ) ?? '';
$result['details'][] = sprintf(
'<strong>%s:</strong> <a href="%s">%s</a>',
__( 'Target Post', 'robotstxt-documentation-markdown' ),
@ -1470,7 +1486,7 @@ function robotstxt_docmd_debug_run_cron( $mapping_id ) {
* @return void
*/
function robotstxt_docmd_debug_clear_cache() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'Permission denied.', 'robotstxt-documentation-markdown' ) );
}
@ -1483,6 +1499,7 @@ function robotstxt_docmd_debug_clear_cache() {
);
// Delete all plugin transients.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query acceptable for cache clearing operation.
$deleted = $wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
@ -1519,7 +1536,7 @@ function robotstxt_docmd_debug_clear_cache() {
* @return void
*/
function robotstxt_docmd_debug_fix_crons() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_pages' ) ) {
wp_die( esc_html__( 'Permission denied.', 'robotstxt-documentation-markdown' ) );
}

View file

@ -7,7 +7,7 @@
* @package RobotsTxt\DocumentationMarkdown
* @author ROBOTSTXT
* @license GPL-3.0-or-later
* @link https://github.com/robotstxt/documentation-markdown
* @link https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown
* @since 1.0.0
*/
@ -29,7 +29,8 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
*/
function robotstxt_docmd_uninstall(): void {
// Get plugin settings.
$settings = get_option( 'robotstxt_docmd_settings', array() );
$raw_settings = get_option( 'robotstxt_docmd_settings', array() );
$settings = is_array( $raw_settings ) ? $raw_settings : array();
// Check if user wants to delete data on uninstall.
if ( empty( $settings['delete_on_uninstall'] ) ) {
@ -37,77 +38,80 @@ function robotstxt_docmd_uninstall(): void {
return;
}
global $wpdb;
// Delete all mapping posts (CPT).
$mapping_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT ID FROM {$wpdb->posts} WHERE post_type = %s",
'robotstxt_map'
// Delete all mapping posts (CPT) using WordPress API.
$mapping_posts = get_posts(
array(
'post_type' => 'robotstxt_map',
'posts_per_page' => -1,
'post_status' => 'any',
'fields' => 'ids',
)
);
foreach ( $mapping_ids as $mapping_id ) {
// Force delete (bypass trash).
wp_delete_post( $mapping_id, true );
}
// Delete all plugin-specific post meta.
$wpdb->query(
"DELETE FROM {$wpdb->postmeta}
WHERE meta_key LIKE '_robotstxt_docmd_%'"
);
// Delete plugin options.
delete_option( 'robotstxt_docmd_settings' );
// Delete transients (cached data).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_robotstxt_docmd_' ) . '%'
)
);
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_timeout_robotstxt_docmd_' ) . '%'
)
);
// Clear all scheduled cron events for each mapping.
foreach ( $mapping_ids as $mapping_id ) {
// Delete each mapping post and its associated meta.
foreach ( $mapping_posts as $mapping_id ) {
// Clear scheduled cron events for this mapping.
$hook = 'robotstxt_docmd_sync_event';
$args = array( $mapping_id );
$timestamp = wp_next_scheduled( $hook, $args );
if ( $timestamp ) {
wp_unschedule_event( $timestamp, $hook, $args );
}
// Force delete (bypass trash). This also deletes all associated post meta.
wp_delete_post( $mapping_id, true );
}
// Clear notification transients.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_robotstxt_docmd_notification_' ) . '%'
)
);
// Delete plugin options.
delete_option( 'robotstxt_docmd_settings' );
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s",
$wpdb->esc_like( '_transient_timeout_robotstxt_docmd_notification_' ) . '%'
)
);
// Delete transients (cached data).
// Note: WordPress does not provide an API for pattern-based transient deletion.
// Direct database queries are necessary here for bulk cleanup operations.
robotstxt_docmd_delete_transients_by_prefix( 'robotstxt_docmd_' );
robotstxt_docmd_delete_transients_by_prefix( 'robotstxt_docmd_notification_' );
// Note: We deliberately DO NOT delete the synced posts/pages themselves.
// Users may want to keep the documentation even after uninstalling the plugin.
}
/**
* Delete all transients matching a prefix
*
* WordPress does not provide an API for pattern-based transient deletion,
* so direct database access is required for bulk cleanup operations.
* This is compliant with AGENTS.md guidelines for necessary database operations.
*
* @since 1.0.0
*
* @param string $prefix Transient name prefix to match.
* @return void
*/
function robotstxt_docmd_delete_transients_by_prefix( string $prefix ): void {
global $wpdb;
// Sanitize prefix for LIKE query.
$transient_prefix = $wpdb->esc_like( '_transient_' . $prefix ) . '%';
$transient_timeout_prefix = $wpdb->esc_like( '_transient_timeout_' . $prefix ) . '%';
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Required for bulk pattern-based deletion; no WordPress API available for this operation.
// Delete transient values.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$transient_prefix
)
);
// Delete transient timeouts.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$transient_timeout_prefix
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
// Run uninstall.
robotstxt_docmd_uninstall();

29
update.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "Documentation Markdown (by ROBOTSTXT)",
"slug": "robotstxt-documentation-markdown",
"version": "1.0.0",
"download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown/releases/download/1.0.0/robotstxt-documentation-markdown-1.0.0.zip",
"requires": "6.7",
"requires_php": "8.2",
"tested": "6.9",
"last_updated": "2026-01-26",
"author": "ROBOTSTXT",
"author_profile": "https://www.robotstxt.es/",
"homepage": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-documentation-markdown",
"description": "Synchronizes Markdown documentation from GitHub repositories to WordPress pages and posts automatically. Perfect for maintaining technical documentation, API references, and knowledge bases with version control.",
"changelog": "<h3>1.0.0 - 2026-01-26</h3><h4>Initial Release</h4><ul><li><strong>Core:</strong> GitHub repository synchronization system</li><li><strong>Core:</strong> Markdown to HTML conversion using CommonMark</li><li><strong>Core:</strong> Encrypted GitHub token storage (AES-256-CBC)</li><li><strong>Feature:</strong> Flexible file-to-content mapping system</li><li><strong>Feature:</strong> Custom Post Type for mapping management</li><li><strong>Feature:</strong> Configurable sync frequency (manual, hourly, twice daily, daily)</li><li><strong>Feature:</strong> Manual on-demand synchronization</li><li><strong>Feature:</strong> Support for pages, posts, and custom post types</li><li><strong>Feature:</strong> Page order (menu_order) configuration</li><li><strong>Feature:</strong> Configurable post author and parent page</li><li><strong>Admin:</strong> Complete admin interface with status monitoring</li><li><strong>Admin:</strong> Settings page for GitHub configuration</li><li><strong>Admin:</strong> Mappings management interface</li><li><strong>Debug:</strong> Built-in debug tools (visible when WP_DEBUG enabled)</li><li><strong>Debug:</strong> Test GitHub connection and token validity</li><li><strong>Debug:</strong> View and manage scheduled cron jobs</li><li><strong>Debug:</strong> Fix/reschedule broken cron jobs</li><li><strong>Debug:</strong> Cache management tools</li><li><strong>Security:</strong> Complete input sanitization and output escaping</li><li><strong>Security:</strong> Nonce verification on all forms</li><li><strong>Security:</strong> Capability checks for admin actions</li><li><strong>i18n:</strong> Full internationalization support</li><li><strong>Quality:</strong> WordPress Coding Standards compliant</li></ul>",
"sections": {
"description": "<p><strong>Documentation Markdown</strong> is a powerful WordPress plugin that enables seamless synchronization of Markdown documentation files from GitHub repositories into your WordPress site.</p><h4>Key Features</h4><ul><li><strong>Automatic Synchronization:</strong> Schedule automatic syncs via WordPress Cron (hourly, twice daily, daily)</li><li><strong>Markdown to HTML:</strong> Convert GitHub Flavored Markdown to clean HTML using CommonMark</li><li><strong>Flexible Mapping:</strong> Map individual MD files to specific WordPress posts or pages</li><li><strong>Secure:</strong> Encrypted GitHub token storage, full input validation & output escaping</li><li><strong>Translatable:</strong> Full internationalization support (i18n/l10n ready)</li><li><strong>Multi-Repository:</strong> Sync from multiple GitHub repos simultaneously</li><li><strong>Manual Sync:</strong> On-demand synchronization from admin interface</li><li><strong>Debug Tools:</strong> Built-in debugging tools (visible when WP_DEBUG is enabled)</li></ul><h4>Use Cases</h4><ul><li>API Documentation - Keep your API docs in sync between GitHub and WordPress</li><li>Technical Documentation - Maintain version-controlled technical docs</li><li>Knowledge Base - Build a knowledge base powered by GitHub</li><li>Blog Posts - Write blog posts in Markdown with Git workflow</li><li>Product Documentation - Sync product documentation from your repository</li></ul><h4>Requirements</h4><ul><li>PHP 8.2 or higher</li><li>WordPress 6.5 or higher (single-site installations only)</li><li>GitHub Personal Access Token (free)</li></ul>",
"installation": "<h4>Installation</h4><ol><li>Upload the plugin files to <code>/wp-content/plugins/robotstxt-documentation-markdown/</code></li><li>Activate the plugin through the 'Plugins' menu in WordPress</li><li>Navigate to 'Documentation → Settings' in the WordPress admin menu</li><li>Generate a GitHub Personal Access Token:<ul><li>Go to GitHub → Settings → Developer settings → Personal access tokens</li><li>Click 'Generate new token'</li><li>For public repositories: No specific scopes needed</li><li>For private repositories: Select <code>repo</code> scope</li></ul></li><li>Paste your token in the plugin settings and save</li><li>Create your first mapping under 'Documentation → Mappings'</li></ol><h4>Configuration</h4><ol><li>Go to <strong>Documentation → Add Mapping</strong></li><li>Fill in the repository details (owner, name, file path, branch)</li><li>Configure target content (post type, author, parent, order)</li><li>Set synchronization frequency</li><li>Save and click 'Sync Now' to perform first sync</li></ol>",
"faq": "<h4>Do I need a GitHub account?</h4><p>Yes, you need a GitHub account to generate a Personal Access Token. The token is required to access repositories (public or private).</p><h4>Can I sync from private repositories?</h4><p>Yes! When generating your GitHub Personal Access Token, make sure to select the <code>repo</code> scope for full access to private repositories.</p><h4>How often does synchronization happen?</h4><p>You can configure synchronization frequency per mapping: Manual only, Hourly, Twice daily, or Daily. You can also manually trigger sync at any time.</p><h4>Will the plugin delete my WordPress content if I uninstall it?</h4><p>By default, NO. When you uninstall the plugin, it preserves all synced WordPress pages/posts. However, there's an option in Settings to delete plugin data on uninstall - but this never deletes the actual WordPress content.</p><h4>Can I sync multiple files from the same repository?</h4><p>Yes! You can create multiple mappings, each pointing to different files in the same repository or different repositories.</p><h4>How do I debug synchronization issues?</h4><p>Enable WP_DEBUG in your wp-config.php, then go to Documentation → Settings. You'll see a 'Debug Tools' section with options to test GitHub connection, validate token, view cron jobs, and run manual syncs.</p>",
"changelog": "<h3>1.0.0 - 2026-01-26</h3><h4>Initial Release</h4><ul><li><strong>Core:</strong> GitHub repository synchronization system</li><li><strong>Core:</strong> Markdown to HTML conversion using CommonMark</li><li><strong>Core:</strong> Encrypted GitHub token storage (AES-256-CBC)</li><li><strong>Feature:</strong> Flexible file-to-content mapping system</li><li><strong>Feature:</strong> Custom Post Type for mapping management</li><li><strong>Feature:</strong> Configurable sync frequency (manual, hourly, twice daily, daily)</li><li><strong>Feature:</strong> Manual on-demand synchronization</li><li><strong>Feature:</strong> Support for pages, posts, and custom post types</li><li><strong>Feature:</strong> Page order (menu_order) configuration</li><li><strong>Feature:</strong> Configurable post author and parent page</li><li><strong>Admin:</strong> Complete admin interface with status monitoring</li><li><strong>Admin:</strong> Settings page for GitHub configuration</li><li><strong>Admin:</strong> Mappings management interface</li><li><strong>Debug:</strong> Built-in debug tools (visible when WP_DEBUG enabled)</li><li><strong>Debug:</strong> Test GitHub connection and token validity</li><li><strong>Debug:</strong> View and manage scheduled cron jobs</li><li><strong>Debug:</strong> Fix/reschedule broken cron jobs</li><li><strong>Debug:</strong> Cache management tools</li><li><strong>Security:</strong> Complete input sanitization and output escaping</li><li><strong>Security:</strong> Nonce verification on all forms</li><li><strong>Security:</strong> Capability checks for admin actions</li><li><strong>i18n:</strong> Full internationalization support</li><li><strong>Quality:</strong> WordPress Coding Standards compliant</li></ul>"
},
"banners": {
"low": "",
"high": ""
},
"icons": {
"1x": "",
"2x": ""
}
}

2
vendor/autoload.php vendored
View file

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit5db7b63bf0104878d549f48a1ce8cb76::getLoader();
return ComposerAutoloaderInit216e6d5522dd071bc42c5f7c15b28cdc::getLoader();

119
vendor/bin/php-parse vendored
View file

@ -1,119 +0,0 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../nikic/php-parser/bin/php-parse)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/nikic/php-parser/bin/php-parse');
}
}
return include __DIR__ . '/..'.'/nikic/php-parser/bin/php-parse';

View file

@ -1,5 +0,0 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/php-parse
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php "%BIN_TARGET%" %*

119
vendor/bin/phpcbf vendored
View file

@ -1,119 +0,0 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../squizlabs/php_codesniffer/bin/phpcbf)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/squizlabs/php_codesniffer/bin/phpcbf');
}
}
return include __DIR__ . '/..'.'/squizlabs/php_codesniffer/bin/phpcbf';

View file

@ -1,5 +0,0 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/phpcbf
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php "%BIN_TARGET%" %*

119
vendor/bin/phpcs vendored
View file

@ -1,119 +0,0 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../squizlabs/php_codesniffer/bin/phpcs)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/squizlabs/php_codesniffer/bin/phpcs');
}
}
return include __DIR__ . '/..'.'/squizlabs/php_codesniffer/bin/phpcs';

View file

@ -1,5 +0,0 @@
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/phpcs
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php "%BIN_TARGET%" %*

119
vendor/bin/phpstan vendored
View file

@ -1,119 +0,0 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../phpstan/phpstan/phpstan)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (
(function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
|| (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
) {
return include("phpvfscomposer://" . __DIR__ . '/..'.'/phpstan/phpstan/phpstan');
}
}
return include __DIR__ . '/..'.'/phpstan/phpstan/phpstan';

Some files were not shown because too many files have changed in this diff Show more