A lightweight PHP-based API for scraping product and author data from RTL-Theme.com. This project provides a unified API endpoint that intelligently handles both product listings and author details.
- Features
- Architecture
- Quick Start
- API Documentation
- Authentication
- Caching System
- HTML Export
- Error Handling
- Configuration
- Development
- Deployment
- Troubleshooting
- Contributing
- License
- Unified API Endpoint - Single endpoint for both products and authors
- Smart Request Detection - Automatically detects request type based on parameters
- Product Scraping - Extract products from homepage with pagination support
- Author Profiling - Comprehensive author data including stats, followers, and descriptions
- Income Analytics - 50% commission-based revenue calculations
- Caching Layer - Multi-level caching system for optimal performance
- RESTful Design - Clean, predictable API structure
- Token Authentication - Secure Bearer token-based access control
- CORS Enabled - Cross-origin resource sharing support
- HTML Export - Generate static author profile pages
- Comprehensive Logging - Detailed debug and monitoring logs
- Security Hardened - Input validation and security headers
rtltheme-api/
βββ π api/
β βββ π― index.php # Unified API endpoint
βββ π config/
β βββ βοΈ config.php # Configuration and security settings
βββ π lib/ # Core libraries
β βββ π Auth.php
β βββ π HomepageParser.php
β βββ π° IncomeCalculator.php
β βββ π¦ ProductParser.php
β βββ π Scraper.php
β βββ π€ SellerParser.php
β βββ πΎ StorageManager.php
βββ π storage/ # Data storage
β βββ π authors/ # Cached author JSON files
β βββ π html/ # Generated HTML profiles
βββ π output/ # Log files
β βββ π log.txt
βββ π .htaccess # URL routing and security
βββ π README.md
Client Request β Authentication β Request Detection β Data Processing β Response
β β β β β
API Call Token Validation Route Detection Scraping/Logic JSON Output
- PHP 7.4 or higher
- cURL extension enabled
- Apache web server with mod_rewrite
allow_url_fopenenabled (recommended)
-
Clone the repository
git clone https://github.com/farhamaghdasi/rtltheme-api.git cd rtltheme-api -
Set directory permissions
chmod -R 755 storage/ output/ chmod 644 config/config.php
-
Configure security token
// Edit config/config.php define('ALLOWED_TOKENS', [ 'your-secret-production-token' => true, 'your-development-token' => true ]);
-
Verify installation
curl "https://your-domain.com/rtltheme/api/?author=farhamaghdasi&token=your-token"
GET /api/
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
integer | 1 |
Page number for pagination |
details |
boolean | false |
Include detailed author information |
save_html |
boolean | false |
Generate HTML profiles for authors |
force_update |
boolean | false |
Bypass cache and fetch fresh data |
| Parameter | Type | Default | Description |
|---|---|---|---|
author |
string | Required | Author username |
fields |
string | all |
Comma-separated fields: basic, stats, products, income |
cache |
boolean | true |
Use cached data when available |
| Parameter | Type | Description |
|---|---|---|
token |
string | Authentication token (required) |
curl "https://api.example.com/rtltheme/api/?page=2&details=true&token=your-secret-token"curl "https://api.example.com/rtltheme/api/?author=farhamaghdasi&fields=basic,stats,income&token=your-secret-token"{
"products": [
{
"title": "ΩΨ§ΩΨ¨ ΩΨ±Ψ―ΩΎΨ±Ψ³ ΨͺΨ¬Ψ§Ψ±Ϋ",
"url": "https://www.rtl-theme.com/theme/",
"author": {
"username": "authorname",
"name": "Author Display Name",
"url": "https://www.rtl-theme.com/author/authorname/",
"need_further_processing": false
},
"author_data": {
"basic_info": {
"name": "Author Display Name",
"slogan": "Professional WordPress Developer",
"response_time": "1 hour",
"support_quality": "A+"
},
"stats": {
"total_sales": 150,
"total_income": "15,000,000 ΨͺΩΩ
Ψ§Ω"
}
},
"price": 850000,
"stats": {
"sales": 4,
"rating": 4.8
}
}
],
"metadata": {
"endpoint": "homepage",
"timestamp": "2024-01-15 10:30:00",
"page": 2,
"products_count": 12,
"unique_authors": 8
}
}{
"seller": {
"basic_info": {
"name": "ΩΨ±ΩΨ§Ω
Ψ§ΩΨ―Ψ³Ϋ",
"slogan": "Ψ§Ψ±Ψ§Ψ¦Ω Ψ―ΩΩΨ―Ω Ψ¨ΩΨͺΨ±ΫΩ ΩΨ§ΩΨ¨ ΩΨ§",
"response_time": "1 Ψ³Ψ§ΨΉΨͺ",
"support_quality": "A+"
},
"description": "Experienced WordPress developer with 5+ years of experience...",
"image": "https://media.rtlcdn.com/author/avatar.jpg",
"stats": {
"total_products": 25,
"total_sales": 320,
"average_rating": 4.9
},
"followers": 1250
},
"products": [
{
"title": "Premium WordPress Theme",
"price": 1200000,
"sales": 45,
"income": {
"author_share": 540000,
"platform_share": 540000,
"total": 1080000
}
}
],
"income": {
"total_income": 12500000,
"total_income_formatted": "12,500,000 ΨͺΩΩ
Ψ§Ω",
"average_per_product": 500000,
"top_selling_product": "Premium Theme"
},
"metadata": {
"endpoint": "author",
"author": "farhamaghdasi",
"timestamp": "2024-01-15 10:30:00",
"cached": false,
"version": "2.0"
}
}// config/config.php
define('ALLOWED_TOKENS', [
'production-token-12345' => true,
'development-token-67890' => true
]);curl "https://api.example.com/rtltheme/api/?author=username&token=your-secret-token"curl -H "Authorization: Bearer your-secret-token" \
"https://api.example.com/rtltheme/api/?author=username"$context = stream_context_create([
'http' => [
'header' => "Authorization: Bearer your-secret-token\r\n"
]
]);
$response = file_get_contents('https://api.example.com/rtltheme/api/?author=username', false, $context);// config/config.php
define('CACHE_DURATION', 1800); // 30 minutes for product data
define('AUTHOR_CACHE_DURATION', 86400); // 24 hours for author data
define('MAX_PRODUCTS', 100); // Maximum products per author# Force fresh data fetch
curl "https://api.example.com/rtltheme/api/?author=username&force_update=true&token=your-token"# Use cached data when available
curl "https://api.example.com/rtltheme/api/?author=username&cache=true&token=your-token"- Product Data:
storage/cache/homepage_page_{X}.json - Author Data:
storage/authors/{username}.json - HTML Profiles:
storage/html/authors/{username}.html
# Generate HTML profile for authors
curl "https://api.example.com/rtltheme/api/?author=username&save_html=true&token=your-token"- Responsive design
- Author statistics and profile
- Product portfolio
- Income analytics
- Social media links
https://api.example.com/rtltheme/storage/html/authors/username.html
| Code | Description | Resolution |
|---|---|---|
200 |
Success | Request completed successfully |
400 |
Bad Request | Check required parameters |
401 |
Unauthorized | Verify authentication token |
404 |
Not Found | Author or page not found |
500 |
Server Error | Check server logs |
{
"error": "Parameter 'author' is required",
"code": 400,
"timestamp": "2024-01-15 10:30:00"
}Check log files for detailed debugging information:
tail -f output/log.txtSample log entry:
[2024-01-15 10:30:00] EXECUTED: api/index.php | URI: /rtltheme/api/?author=farhamaghdasi
[2024-01-15 10:30:01] AUTHOR FOUND: {"username":"farhamaghdasi","name":"ΩΨ±ΩΨ§Ω
Ψ§ΩΨ―Ψ³Ϋ"}
[2024-01-15 10:30:02] PRODUCTS PARSED: 15 products found
config/config.php
<?php
// Security Tokens
define('ALLOWED_TOKENS', [
'your-production-token' => true
]);
// Cache Settings
define('CACHE_DURATION', 1800); // 30 minutes
define('AUTHOR_CACHE_DURATION', 86400); // 24 hours
define('MAX_PRODUCTS', 100);
// API Behavior
define('ENABLE_HTML_EXPORT', true);
define('DEBUG_MODE', false);
define('MAX_REQUESTS_PER_MINUTE', 60);
// Storage Paths
define('STORAGE_PATH', __DIR__ . '/../storage/');
define('CACHE_PATH', STORAGE_PATH . 'cache/');
define('AUTHORS_PATH', STORAGE_PATH . 'authors/');
define('HTML_PATH', STORAGE_PATH . 'html/');
?>For different environments, create separate config files:
config/config.production.phpconfig/config.development.phpconfig/config.local.php
-
Clone and configure
git clone https://github.com/farhamaghdasi/rtltheme-api.git cd rtltheme-api cp config/config.php config/config.local.php -
Development token setup
// config/config.local.php define('ALLOWED_TOKENS', [ 'dev-token-local' => true ]); define('DEBUG_MODE', true);
-
Testing endpoints
# Test homepage products curl "http://localhost/rtltheme/api/?page=1&token=dev-token-local" # Test author endpoint curl "http://localhost/rtltheme/api/?author=farhamaghdasi&token=dev-token-local"
Scraper: Handles HTTP requests and response parsingHomepageParser: Extracts product data from homepageSellerParser: Processes author profile informationProductParser: Manages author product listingsIncomeCalculator: Handles revenue calculationsStorageManager: Manages caching and file operationsAuth: Handles token authentication
- Extend existing parsers for new data points
- Add new configuration options
- Update response structures
- Document new parameters
- Update security tokens in
config/config.php - Set proper file permissions
- Configure web server rewrite rules
- Enable PHP error logging
- Set up monitoring and alerts
- Configure backup for storage directory
<VirtualHost *:80>
ServerName api.example.com
DocumentRoot /var/www/rtltheme-api
<Directory /var/www/rtltheme-api>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
# Security headers
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"
</Directory>
# Logging
ErrorLog ${APACHE_LOG_DIR}/rtltheme-api_error.log
CustomLog ${APACHE_LOG_DIR}/rtltheme-api_access.log combined
</VirtualHost>server {
listen 80;
server_name api.example.com;
root /var/www/rtltheme-api;
index index.php;
location / {
try_files $uri $uri/ /api/index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Security
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
}- Verify token in
config/config.php - Check Authorization header format
- Ensure token is URL-safe
- Confirm author username exists
- Check pagination limits
- Verify .htaccess routing
- Check PHP error logs
- Verify file permissions
- Confirm cURL extension enabled
- Enable caching
- Reduce request frequency
- Check network connectivity to RTL-Theme
Enable detailed logging by setting:
define('DEBUG_MODE', true);- Monitor
output/log.txtfor errors - Check storage directory disk space
- Monitor API response times
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PSR-12 coding standards
- Add PHPDoc comments for new methods
- Update documentation for new features
- Include tests when possible
When reporting bugs, include:
- API request and response
- Error logs
- PHP version and environment details
- Steps to reproduce
This project is licensed under the MIT License - see the LICENSE file for details.
- Data sourced from RTL-Theme.com
- Icons provided by Shields.io
- Farham Aghdasi
- GitHub: @farhamaghdasi
- Email: [email protected]
β Star this repo if you find it helpful!
Last updated: January 2024