第一步:创建新仓库
第一步:创建新仓库
- 登录 GitHub
- 点击右上角 "+" → "New repository"
- 填写信息:
- Repository name: joomla-ad-unlock
- Description: Joomla 4 Ad Unlock Module - Click ads to unlock content
- Public
- 勾选 "Add a README file"
- 选择 MIT License
- 点击 "Create repository"
第二步:准备本地文件
创建本地目录结构:
# 在你的电脑上执行mkdir joomla-ad-unlockcd joomla-ad-unlock
# 创建目录结构mkdir -p {tmpl,sql/mysql,language/en-GB,media/{css,js,images},forms,src}
# 初始化Gitgit init
git remote add origin https://github.com/bluetoothbeijing/joomla-ad-unlock.git
第三步:创建所有文件
使用我下面提供的完整代码,创建以下文件:
1. README.md
# Joomla 4 Ad Unlock Module
A professional Joomla 4 module that allows you to lock content behind advertisements. Users must click ads to unlock premium content.
## Features
- 🛡️ **Joomla 4.4+ Compatible**- 🚀 **PHP 8.3 Ready**- 🗄️ **MySQL 8.0 + utf8mb4 Optimized**- 📱 **Mobile Responsive**- 🔒 **Anti-Fraud Protection**- 📊 **Click Analytics**- ⚡ **Fast & Lightweight**
## Installation
1. Download the latest release: [mod_adunlock_v2.0.zip](https://github.com/bluetoothbeijing/joomla-ad-unlock/releases/latest)2. In Joomla admin: Extensions → Manage → Install3. Upload the ZIP file4. Enable the module: Extensions → Modules
## Configuration
### Basic Settings- **Content ID**: The article ID to unlock- **Ad ID**: Unique identifier for the ad- **Ad Code**: Paste your ad HTML/JavaScript- **Unlock Duration**: How long content stays unlocked (1-720 hours)
### Advanced Settings- **Cache**: Enable module caching- **Debug Mode**: Show debug information- **Google Analytics**: Track ad clicks
## Usage
### In Articles```html
Manual HTML
<div class="locked-content" data-content-id="123"> This content requires ad click to view.</div>
Requirements
- Joomla 4.0+
- PHP 7.4+ (PHP 8.3 recommended)
- MySQL 5.7+ (MySQL 8.0 recommended)
- Apache/Nginx with mod_rewrite
Support
- Issues: GitHub Issues
- Documentation: Wiki
License
MIT License. See LICENSE file.
Author
Developed by bluetoothbeijing
text
#### **2. LICENSE**
```text
MIT License
Copyright (c) 2024 bluetoothbeijing
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3. .gitignore
# IDE files
.idea/
.vscode/
*.swp
*.swo
# OS files
.DS_Store
Thumbs.db
# Logs
*.log
logs/
# Composer
vendor/
composer.lock
# Node
node_modules/
npm-debug.log*
# Temp files
*.tmp
*.temp
/tmp/
# Build artifacts
dist/
build/
*.zip
4. composer.json (可选)
将我之前提供的所有代码文件按照这个结构创建:
joomla-ad-unlock/ ├── README.md ├── LICENSE ├── .gitignore ├── composer.json ├── adunlock.xml ├── adunlock.php ├── helper.php ├── script.install.php ├── script.uninstall.php ├── tmpl/ │ ├── default.php │ ├── unlocked.php │ ├── alternative.php │ └── thank-you.php ├── sql/ │ └── mysql/ │ ├── install.sql │ └── uninstall.sql ├── language/ │ └── en-GB/ │ ├── en-GB.mod_adunlock.ini │ └── en-GB.mod_adunlock.sys.ini ├── media/ │ ├── css/ │ │ └── adunlock.css │ ├── js/ │ │ └── adunlock.js │ └── images/ │ ├── icon.png │ └── icon.svg ├── forms/ │ └── fields/ │ └── contentid.xml └── src/ └── Helper/ └── AdunlockHelper.php
第四步:创建自动打包脚本
build.php (创建发布包)
<?php
/**
* Build script for Ad Unlock module
*/
$version = '2.0.0';
$buildDir = __DIR__ . '/build';
$distDir = __DIR__ . '/dist';
// 创建目录
if (!is_dir($buildDir)) mkdir($buildDir, 0755, true);
if (!is_dir($distDir)) mkdir($distDir, 0755, true);
// 复制文件
$filesToCopy = [
'adunlock.xml',
'adunlock.php',
'helper.php',
'script.install.php',
'script.uninstall.php',
'tmpl/default.php',
'tmpl/unlocked.php',
'tmpl/alternative.php',
'tmpl/thank-you.php',
'sql/mysql/install.sql',
'sql/mysql/uninstall.sql',
'language/en-GB/en-GB.mod_adunlock.ini',
'language/en-GB/en-GB.mod_adunlock.sys.ini',
'media/css/adunlock.css',
'media/js/adunlock.js',
'media/images/icon.png',
'media/images/icon.svg'
];
echo "Building Ad Unlock Module v{$version}\n";
// 清空build目录
array_map('unlink', glob("{$buildDir}/*"));
foreach (glob("{$buildDir}/*", GLOB_ONLYDIR) as $dir) {
removeDirectory($dir);
}
// 复制文件
foreach ($filesToCopy as $file) {
$source = __DIR__ . '/' . $file;
$target = $buildDir . '/' . $file;
if (!file_exists($source)) {
echo "Warning: {$file} not found\n";
continue;
}
// 创建目录
$dir = dirname($target);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
copy($source, $target);
echo "Copied: {$file}\n";
}
// 创建ZIP文件
$zip = new ZipArchive();
$zipFile = "{$distDir}/mod_adunlock_v{$version}.zip";
if ($zip->open($zipFile, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($buildDir),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($buildDir) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
echo "✅ Package created: {$zipFile}\n";
// 计算文件大小
$size = filesize($zipFile);
echo "📦 File size: " . formatBytes($size) . "\n";
} else {
echo "❌ Failed to create ZIP file\n";
}
// 清理
removeDirectory($buildDir);
// Helper functions
function removeDirectory($dir) {
if (!is_dir($dir)) return;
$items = scandir($dir);
foreach ($items as $item) {
if ($item === '.' || $item === '..') continue;
$path = $dir . '/' . $item;
if (is_dir($path)) {
removeDirectory($path);
} else {
unlink($path);
}
}
rmdir($dir);
}
function formatBytes($bytes, $precision = 2) {
$units = ['B', 'KB', 'MB', 'GB'];
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
第五步:推送到GitHub
# 添加所有文件git add .
# 提交git commit -m "Initial commit: Joomla 4 Ad Unlock Module v2.0"
# 推送到GitHubgit branch -M maingit push -u origin main
第六步:创建GitHub Release
- 在GitHub仓库页面,点击 "Create a new release"
- 填写:
- Tag version: v2.0.0
- Release title: Ad Unlock Module v2.0.0
- Description: Complete Joomla 4 module for ad-based content unlocking
- 上传ZIP文件(使用build.php生成的)
- 点击 "Publish release"
🎯 你的GitHub仓库地址
你的仓库地址将是:
https://github.com/bluetoothbeijing/joomla-ad-unlock
发布后的下载链接:
text
https://github.com/bluetoothbeijing/joomla-ad-unlock/releases/download/v2.0.0/mod_adunlock_v2.0.0.zip
📦 快速开始脚本
如果你不想手动创建所有文件,我为你准备了快速创建脚本:
quick_setup.sh (Linux/Mac)
#!/bin/bash
# 快速创建Ad Unlock模块项目
echo "🎯 Setting up Joomla Ad Unlock Module Project"
# 创建项目目录
PROJECT_DIR="joomla-ad-unlock"
if [ -d "$PROJECT_DIR" ]; then
echo "⚠️ Directory $PROJECT_DIR already exists"
read -p "Delete and recreate? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$PROJECT_DIR"
else
exit 1
fi
fi
mkdir -p "$PROJECT_DIR"
cd "$PROJECT_DIR"
echo "📁 Creating directory structure..."
mkdir -p {tmpl,sql/mysql,language/en-GB,media/{css,js,images},forms/fields,src/Helper}
echo "📝 Creating files..."
# 创建README
cat > README.md << 'EOF'
# Joomla 4 Ad Unlock Module
# ... (使用上面的README内容)
EOF
# 创建主文件
cat > adunlock.xml << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="4.0" client="site">
<name>Ad Unlock</name>
<version>2.0.0</version>
<files>
<filename module="mod_adunlock">adunlock.php</filename>
<folder>tmpl</folder>
<folder>language</folder>
<folder>media</folder>
</files>
<config>
<fields name="params">
<field name="content_id" type="text" label="Content ID" />
<field name="ad_code" type="textarea" label="Ad Code" rows="5" />
</fields>
</config>
</extension>
EOF
# 创建PHP文件
cat > adunlock.php << 'EOF'
<?php
defined('_JEXEC') or die;
$content_id = (int) $params->get('content_id');
$ad_code = $params->get('ad_code');
?>
<div class="ad-unlock">
<div class="alert alert-info">
<i class="fas fa-lock"></i> Please click ad to unlock content
</div>
<div class="ad-container">
<?php echo $ad_code; ?>
</div>
</div>
EOF
# 创建模板
cat > tmpl/default.php << 'EOF'
<div class="ad-unlock-module">
<?php echo $params->get('ad_code'); ?>
<p class="text-muted small">Click ad to unlock content</p>
</div>
EOF
# 创建CSS
cat > media/css/adunlock.css << 'EOF'
.ad-unlock-module {
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background: #f8f9fa;
}
EOF
echo "✅ Project setup complete!"
echo "📦 Run: zip -r mod_adunlock.zip *"
echo "🚀 Upload to Joomla: Extensions → Manage → Install"
🔗 最终结果
完成以上步骤后,你将拥有:
- ✅ 完整的GitHub仓库
- ✅ 永久的下载链接
- ✅ 版本控制
- ✅ 问题追踪
- ✅ 社区支持