Toolvana: production-ready media tools platform (CodeIgniter 4)
- 134-tool registry with programmatic SEO (unique titles/H1/descriptions, JSON-LD graphs, sitemap index, canonical 301 enforcement via required filter) - DB-backed job queue (SKIP LOCKED) with drivers: Ffmpeg, Images (GD), Pdf (qpdf/gs/poppler), Youtube (thumbnails), Qr (server-side PNG) - Security: SSRF guard, MIME validation, rate limits, API-key auth, bcrypt admin login, security headers - Admin panel: dashboard, tools/categories/guides CRUD, SEO audit, analytics, job inspector with retry, system health, feature flags - Docker deployment (nginx + web/api FPM pools + scalable workers), PHPUnit suite (19 tests / 1139 assertions), PWA manifest + service worker
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# Docker deployment environment (copy values, never commit real secrets)
|
||||
CI_ENVIRONMENT = production
|
||||
|
||||
app.baseURL = 'https://your-domain.example/'
|
||||
app.forceGlobalSecureRequests = true
|
||||
app.indexPage = ''
|
||||
|
||||
database.default.hostname = db
|
||||
database.default.database = toolvana
|
||||
database.default.username = toolvana
|
||||
database.default.password = toolvana
|
||||
database.default.DBDriver = MySQLi
|
||||
|
||||
# generate once: php spark key:generate
|
||||
encryption.key =
|
||||
|
||||
session.driver = CodeIgniter\Session\Handlers\FileHandler
|
||||
session.savePath = /app/writable/session
|
||||
|
||||
site.name = 'Toolvana'
|
||||
# bcrypt hash of the admin password
|
||||
site.adminPassword =
|
||||
site.retentionHours = 2
|
||||
site.maxUploadMb = 512
|
||||
site.ytDlpEnabled = false
|
||||
|
||||
log.threshold = 4
|
||||
cache.handler = redis
|
||||
cache.redis.host = redis
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#-------------------------
|
||||
# Operating Specific Junk Files
|
||||
#-------------------------
|
||||
|
||||
# OS X
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# OS X Thumbnails
|
||||
._*
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# Linux
|
||||
*~
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
#-------------------------
|
||||
# Environment Files
|
||||
#-------------------------
|
||||
# These should never be under version control,
|
||||
# as it poses a security risk.
|
||||
.env
|
||||
.vagrant
|
||||
Vagrantfile
|
||||
|
||||
#-------------------------
|
||||
# Temporary Files
|
||||
#-------------------------
|
||||
/writable/cache/*
|
||||
!/writable/cache/index.html
|
||||
|
||||
/writable/logs/*
|
||||
!/writable/logs/index.html
|
||||
|
||||
/writable/session/*
|
||||
!/writable/session/index.html
|
||||
|
||||
/writable/uploads/*
|
||||
!/writable/uploads/index.html
|
||||
|
||||
/writable/debugbar/*
|
||||
!/writable/debugbar/index.html
|
||||
|
||||
php_errors.log
|
||||
|
||||
#-------------------------
|
||||
# User Guide Temp Files
|
||||
#-------------------------
|
||||
/user_guide_src/build/*
|
||||
/user_guide_src/cilexer/build/*
|
||||
/user_guide_src/cilexer/dist/*
|
||||
/user_guide_src/cilexer/pycilexer.egg-info/*
|
||||
|
||||
#-------------------------
|
||||
# Test Files
|
||||
#-------------------------
|
||||
/tests/coverage*
|
||||
|
||||
# Don't save phpunit under version control.
|
||||
/phpunit
|
||||
|
||||
#-------------------------
|
||||
# Composer
|
||||
#-------------------------
|
||||
vendor/
|
||||
|
||||
#-------------------------
|
||||
# IDE / Development Files
|
||||
#-------------------------
|
||||
|
||||
# Modules Testing
|
||||
_modules/*
|
||||
|
||||
# phpenv local config
|
||||
.php-version
|
||||
|
||||
# Jetbrains editors (PHPStorm, etc)
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# NetBeans
|
||||
/nbproject/
|
||||
/build/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/nbactions.xml
|
||||
/nb-configuration.xml
|
||||
/.nb-gradle/
|
||||
|
||||
# Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
.phpintel
|
||||
/api/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
/results/
|
||||
/phpunit.xml
|
||||
|
||||
# -------------------------
|
||||
# Toolvana runtime data
|
||||
# -------------------------
|
||||
.env.docker
|
||||
/writable/media/*
|
||||
/writable/incoming/*
|
||||
/writable/og/*
|
||||
!/writable/media/index.html
|
||||
!/writable/incoming/index.html
|
||||
!/writable/og/index.html
|
||||
/.phpunit.cache/
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
Copyright (c) 2019-present CodeIgniter Foundation
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,125 @@
|
||||
# Toolvana — Your free online media toolbox
|
||||
|
||||
A production-ready, SEO-first all-in-one media tools platform built on **CodeIgniter 4.7** and **PHP 8.2**: YouTube tools, video/audio/image/GIF converters, PDF utilities, QR generation, programmatic SEO at scale (134+ root-level tool pages), a durable job queue with FFmpeg workers, anonymous analytics, and a complete admin panel.
|
||||
|
||||
## Feature overview
|
||||
|
||||
| Area | What ships |
|
||||
|---|---|
|
||||
| **Tools** | 134 seeded tools across YouTube / video / audio / image / GIF / PDF / utility categories; URL-kind, upload-kind and text-kind flows |
|
||||
| **Processing** | MySQL-backed queue (`SELECT … FOR UPDATE SKIP LOCKED`), driver architecture: `Ffmpeg`, `Images` (GD), `Pdf` (qpdf/Ghostscript/poppler), `Youtube` (thumbnails via i.ytimg.com; yt-dlp optional & policy-gated), `Qr` (server-side PNG) |
|
||||
| **Security** | SSRF guard for URL fetches, extension **and** real-MIME validation, UUID storage names outside the web root, per-session/IP hourly rate limits, API-key auth with hashed lookup, admin bcrypt login, strict security headers, canonical 301 enforcement |
|
||||
| **SEO** | Unique titles/H1s/descriptions generated per format pair, JSON-LD (WebApplication, BreadcrumbList, FAQPage, HowTo, Article), auto sitemap index split at 5 000 URLs, robots.txt blocking processing endpoints, noindex on search/API/admin, hreflang scaffolding, OG images rendered by GD |
|
||||
| **Admin** (`/admin`) | Overview dashboard, tools CRUD with pre-publish SEO gate, categories, guides (Markdown), automated **SEO audit** across every page, analytics dashboard (success-rate per tool), job inspector with retry, system health (binaries/storage/worker heartbeat), feature-flag settings |
|
||||
| **API v1** | `/api/v1/tools`, `/api/v1/jobs` (+ legacy `/api/*`), Bearer-token auth, per-key hourly quotas |
|
||||
| **PWA** | Web manifest, offline-capable service worker, offline shell |
|
||||
| **Privacy** | Anonymous session-hash analytics only, automatic media expiry (`media:cleanup`), DMCA/privacy/cookies pages |
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 8.1+ (8.2 recommended) with `intl`, `mbstring`, `zip`, `pdo_mysql`, `gd`, `exif`
|
||||
- MariaDB/MySQL 10.6+
|
||||
- FFmpeg, ImageMagick (`convert`), poppler-utils (`pdftoppm`, `pdftotext`), qpdf, Ghostscript
|
||||
- Optional: `yt-dlp` (disabled by policy until enabled in Admin → Settings)
|
||||
- Composer 2
|
||||
|
||||
## Quick start (development)
|
||||
|
||||
```bash
|
||||
composer install
|
||||
cp env .env # then edit DB credentials
|
||||
php spark key:generate
|
||||
|
||||
# create schema + seed registry/content
|
||||
php spark migrate --all
|
||||
php spark db:seed InitialSeeder
|
||||
|
||||
# run
|
||||
php spark serve # http://127.0.0.1:8080 (falls back to 8081/8082 if busy)
|
||||
|
||||
# process jobs (keep one or more running)
|
||||
php spark queue:work --loop # add --sleep=2 to idle politely
|
||||
|
||||
# expire finished jobs + files (cron every 5 min in production)
|
||||
php spark media:cleanup
|
||||
```
|
||||
|
||||
Sign in to the admin panel at `/admin/login`. Set the password hash in `.env`:
|
||||
|
||||
```bash
|
||||
php -r 'echo password_hash("your-password", PASSWORD_DEFAULT), "\n";'
|
||||
# .env → site.adminPassword = '$2y$10$…'
|
||||
```
|
||||
|
||||
## Production deployment (Docker)
|
||||
|
||||
```bash
|
||||
cp .env.docker.example .env.docker # fill in secrets: encryption.key, site.adminPassword, DB password
|
||||
docker compose up -d --build
|
||||
docker compose exec web php spark migrate --all
|
||||
docker compose exec web php spark db:seed InitialSeeder
|
||||
```
|
||||
|
||||
Topology (`docker-compose.yml`):
|
||||
|
||||
```
|
||||
browser ── nginx ──► web (PHP-FPM, page rendering)
|
||||
└──► api (PHP-FPM, /api + processing endpoints isolated)
|
||||
workers × N (php spark queue:work --loop) ← scale replicas freely
|
||||
scheduler (media:cleanup every 5 minutes)
|
||||
db (MariaDB 11 + healthcheck)
|
||||
```
|
||||
|
||||
- The single `docker/Dockerfile` image contains PHP-FPM **and** the full media binary stack, so web/worker versions can never drift.
|
||||
- Media lives on named volumes (`media-storage`, `incoming-storage`); point them at shared NFS/EFS when running workers on separate hosts.
|
||||
- Put TLS termination at your edge/load balancer and set `app.forceGlobalSecureRequests = true`; nginx config includes HSTS-ready headers.
|
||||
- Recommended cron alternative to the scheduler container: `*/5 * * * * docker compose exec -T scheduler php spark media:cleanup`.
|
||||
|
||||
### Production checklist
|
||||
|
||||
- [ ] `CI_ENVIRONMENT = production`, strong `encryption.key` (`php spark key:generate`)
|
||||
- [ ] `site.adminPassword` set to a fresh bcrypt hash
|
||||
- [ ] `site.ytDlpEnabled` left `false` unless legal review is done
|
||||
- [ ] Review retention: `site.retentionHours` (default 2 h) matches your privacy policy
|
||||
- [ ] Point `/sitemap.xml` at Search Console; confirm canonical host in `.env` (`app.baseURL`)
|
||||
- [ ] Run Admin → **SEO Audit** and clear critical issues before launch
|
||||
|
||||
## Architecture notes
|
||||
|
||||
```
|
||||
app/
|
||||
├── Config/Site.php # brand, binaries map, limits, policy flags
|
||||
├── Controllers/ # Tools, Directory, Guides, Media (upload/start/download), Api/*, Admin/*
|
||||
├── Libraries/
|
||||
│ ├── Pipeline.php # enqueue guards + driver routing (by operation/format family)
|
||||
│ ├── Pipeline/{Ffmpeg,Images,Pdf,Youtube,Qr}.php
|
||||
│ ├── CatalogBuilder.php # generates the 134-tool registry with unique SEO copy
|
||||
│ ├── Seo.php # head tags, canonical, JSON-LD graphs
|
||||
│ ├── UrlGuard.php # SSRF protection for remote fetches
|
||||
│ ├── ToolSearch.php # weighted token search incl. aliases ("yt mp3")
|
||||
│ └── RelatedTools.php # internal-linking engine (format/category scoring)
|
||||
├── Commands/ # queue:work, media:cleanup
|
||||
└── Database/Migrations/ # categories, tools, guides, jobs, analytics_events, api_keys
|
||||
```
|
||||
|
||||
**Why a DB queue?** Zero extra infrastructure, transactional claims via `SKIP LOCKED`, trivial horizontal scaling of identical worker containers, and a built-in audit trail surfaced in the admin Jobs screen.
|
||||
|
||||
**Canonical URL policy:** every non-canonical variant (uppercase, trailing slash, doubled slashes) 301-redirects before routing — including unmatched routes — via a *required* filter.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
./vendor/bin/phpunit # 19 tests, ~1 100 assertions
|
||||
```
|
||||
|
||||
Suites:
|
||||
- `tests/unit/CatalogTest.php` — catalog integrity (unique slugs, complete SEO fields, format-specific titles), YouTube ID extraction, SSRF guard behaviour.
|
||||
- `tests/feature/SeoPagesTest.php` — the **SEO contract**: canonical/OG/Twitter tags, JSON-LD types present in first response, sitemaps contain only indexable URLs, robots.txt blocks processing endpoints, 301 canonicalisation, helpful 404s.
|
||||
|
||||
## Useful commands
|
||||
|
||||
```bash
|
||||
php spark queue:work [--loop] [--sleep=N] [--max-jobs=N] # process jobs
|
||||
php spark media:cleanup # expire jobs/files past retention
|
||||
php spark migrate --all && php spark db:seed InitialSeeder # rebuild registry (editorial fields preserved)
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Models\JobModel;
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
/**
|
||||
* Retention reaper — deletes expired input/output files and their rows.
|
||||
* Schedule every few minutes (cron / scheduler container):
|
||||
*
|
||||
* php spark media:cleanup
|
||||
*/
|
||||
final class MediaCleanup extends BaseCommand
|
||||
{
|
||||
protected $group = 'Toolvana';
|
||||
protected $name = 'media:cleanup';
|
||||
protected $description = 'Delete expired uploads, outputs and job rows per retention policy.';
|
||||
protected $usage = 'media:cleanup';
|
||||
|
||||
public function run(array $params): void
|
||||
{
|
||||
$jobs = model(JobModel::class);
|
||||
$deleted = 0;
|
||||
$freed = 0;
|
||||
|
||||
foreach ([...$jobs->findExpired(), ...$jobs->findOldFailed()] as $job) {
|
||||
foreach (['input_file' => Pipeline::incomingDir(), 'output_file' => Pipeline::storageDir()] as $field => $dir) {
|
||||
if (! empty($job[$field])) {
|
||||
$path = rtrim((string) $dir, '/') . '/' . basename((string) $job[$field]);
|
||||
if (is_file($path)) {
|
||||
$freed += (int) @filesize($path);
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
$jobs->delete($job['id']);
|
||||
++$deleted;
|
||||
}
|
||||
|
||||
// orphaned files with no row (worker crash leftovers)
|
||||
$cutoff = time() - max(2, config('Site')->retentionHours) * 3600 - 600;
|
||||
foreach ([Pipeline::incomingDir(), Pipeline::storageDir()] as $dir) {
|
||||
foreach (glob(rtrim($dir, '/') . '/*') ?: [] as $file) {
|
||||
if (is_file($file) && filemtime($file) < $cutoff) {
|
||||
$freed += (int) @filesize($file);
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CLI::write("Cleanup: {$deleted} job row(s) removed, " . number_format($freed / 1048576, 1) . ' MB freed.', 'yellow');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Models\JobModel;
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
/**
|
||||
* Queue worker. Run several instances for horizontal scaling:
|
||||
*
|
||||
* php spark queue:work # single pass over the queue
|
||||
* php spark queue:work --loop # long-running worker (supervisor/docker)
|
||||
* php spark queue:work --max-jobs=50
|
||||
*/
|
||||
final class QueueWork extends BaseCommand
|
||||
{
|
||||
protected $group = 'Toolvana';
|
||||
protected $name = 'queue:work';
|
||||
protected $description = 'Process queued media jobs (FFmpeg, images, PDFs).';
|
||||
protected $usage = 'queue:work [options]';
|
||||
protected $options = [
|
||||
'--loop' => 'Keep running until stopped',
|
||||
'--sleep' => 'Seconds between polls when idle (default 2)',
|
||||
'--max-jobs' => 'Exit after N successful jobs',
|
||||
'--stale' => 'Also reap jobs stuck in processing beyond max runtime',
|
||||
];
|
||||
|
||||
public function run(array $params): void
|
||||
{
|
||||
$loop = array_key_exists('loop', $params) || CLI::getOption('loop');
|
||||
$sleep = (int) ($params['sleep'] ?? 2);
|
||||
$maxJobs = isset($params['max-jobs']) ? (int) $params['max-jobs'] : 0;
|
||||
$jobs = model(JobModel::class);
|
||||
$done = 0;
|
||||
|
||||
do {
|
||||
$job = null;
|
||||
|
||||
// claim with retry: SKIP LOCKED can race under contention
|
||||
try {
|
||||
$job = $jobs->claimNext();
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'worker claim failed: {m}', ['m' => $e->getMessage()]);
|
||||
usleep(500_000);
|
||||
}
|
||||
|
||||
if ($job === null) {
|
||||
if (! $loop) {
|
||||
break;
|
||||
}
|
||||
sleep(max(1, $sleep));
|
||||
continue;
|
||||
}
|
||||
|
||||
CLI::write("Processing job {$job['id']} [{$job['operation']}]", 'green');
|
||||
self::heartbeat();
|
||||
service('pipeline')->process($job);
|
||||
++$done;
|
||||
|
||||
if ($done % 10 === 0) {
|
||||
self::reapStale($jobs); // periodic housekeeping inside long-running workers
|
||||
}
|
||||
|
||||
if ($maxJobs > 0 && $done >= $maxJobs) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
CLI::write("Worker finished after {$done} job(s).", 'yellow');
|
||||
}
|
||||
|
||||
/** Touch a cache key so the admin dashboard can see workers are alive. */
|
||||
public static function heartbeat(): void
|
||||
{
|
||||
try {
|
||||
cache()->save('tv_worker_heartbeat', gmdate('H:i:s'), 120);
|
||||
} catch (\Throwable) {
|
||||
// never let telemetry break processing
|
||||
}
|
||||
}
|
||||
|
||||
/** Fail jobs whose worker died mid-processing. */
|
||||
public static function reapStale(JobModel $jobs): void
|
||||
{
|
||||
foreach ($jobs->findStale((int) config('Site')->maxProcessingSeconds) as $stale) {
|
||||
Pipeline::failJob($stale['id'], 'Processing timed out.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The goal of this file is to allow developers a location
|
||||
* where they can overwrite core procedural functions and
|
||||
* replace them with their own. This file is loaded during
|
||||
* the bootstrap process and is called during the framework's
|
||||
* execution.
|
||||
*
|
||||
* This can be looked at as a `master helper` file that is
|
||||
* loaded early on, and may also contain additional functions
|
||||
* that you'd like to use throughout your entire application
|
||||
*
|
||||
* @see: https://codeigniter.com/user_guide/extending/common.html
|
||||
*/
|
||||
|
||||
if (! function_exists('icon')) {
|
||||
/**
|
||||
* Inline SVG icon (stroke style, 24x24 grid). Zero requests, zero JS.
|
||||
*/
|
||||
function icon(string $name, string $class = 'icon'): string
|
||||
{
|
||||
$paths = [
|
||||
'play' => '<polygon points="6 3 20 12 6 21 6 3"/>',
|
||||
'film' => '<rect x="2" y="2" width="20" height="20" rx="2.18"/><line x1="7" y1="2" x2="7" y2="22"/><line x1="17" y1="2" x2="17" y2="22"/><line x1="2" y1="12" x2="22" y2="12"/><line x1="2" y1="7" x2="7" y2="7"/><line x1="2" y1="17" x2="7" y2="17"/><line x1="17" y1="17" x2="22" y2="17"/><line x1="17" y1="7" x2="22" y2="7"/>',
|
||||
'music' => '<path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/>',
|
||||
'headphones'=> '<path d="M3 18v-6a9 9 0 0 1 18 0v6"/><path d="M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"/>',
|
||||
'image' => '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>',
|
||||
'sparkles' => '<path d="M12 3l1.9 5.8L20 11l-6.1 2.2L12 19l-1.9-5.8L4 11l6.1-2.2z"/><path d="M19 15l.9 2.6L22.5 18l-2.6.9L19 21.5 18.1 19l-2.6-.9 2.6-.9z"/>',
|
||||
'filetext' => '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/>',
|
||||
'tool' => '<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/>',
|
||||
'download' => '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/>',
|
||||
'video' => '<polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/>',
|
||||
'search' => '<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>',
|
||||
'info' => '<circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/>',
|
||||
'text' => '<line x1="4" y1="7" x2="20" y2="7"/><line x1="4" y1="12" x2="20" y2="12"/><line x1="4" y1="17" x2="12" y2="17"/>',
|
||||
'users' => '<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
|
||||
'link' => '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>',
|
||||
'code' => '<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>',
|
||||
'clock' => '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
|
||||
'qr' => '<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><line x1="14" y1="14" x2="14" y2="17"/><line x1="17" y1="14" x2="21" y2="14"/><line x1="14" y1="21" x2="14" y2="17"/><line x1="17" y1="21" x2="21" y2="21"/>',
|
||||
'shield' => '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>',
|
||||
'key' => '<path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"/>',
|
||||
'palette' => '<circle cx="12" cy="12" r="10"/><circle cx="8.5" cy="10.5" r="1"/><circle cx="15.5" cy="10.5" r="1"/><path d="M8 16c1.5 1.5 6.5 1.5 8 0"/>',
|
||||
'file' => '<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><polyline points="13 2 13 9 20 9"/>',
|
||||
'folder' => '<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>',
|
||||
'phone' => '<rect x="5" y="2" width="14" height="20" rx="2"/><line x1="12" y1="18" x2="12.01" y2="18"/>',
|
||||
'list' => '<line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/>',
|
||||
'swap' => '<polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/>',
|
||||
'layers' => '<polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/>',
|
||||
'star' => '<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>',
|
||||
'arrow' => '<line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/>',
|
||||
'menu' => '<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/>',
|
||||
];
|
||||
|
||||
$d = $paths[$name] ?? $paths['file'];
|
||||
|
||||
return '<svg class="' . htmlspecialchars($class, ENT_QUOTES) . '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' . $d . '</svg>';
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('textPlaceholder')) {
|
||||
function textPlaceholder(string $operation): string
|
||||
{
|
||||
return match ($operation) {
|
||||
'hash_text' => 'Paste any text to hash…',
|
||||
'json_format' => '{"paste":"your JSON here"}',
|
||||
'url_encode' => 'Text to encode…',
|
||||
'url_decode' => 'Text%20to%20decode…',
|
||||
'uuid_gen' => '',
|
||||
'timestamp_convert' => '1735689600 or 2025-01-01 12:00:00',
|
||||
'color_convert' => '#7c3aed',
|
||||
'yt_url_analyze' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
'yt_embed' => 'Paste a YouTube URL to build an embed code…',
|
||||
'yt_timestamp' => 'Paste a YouTube URL and set the time below…',
|
||||
default => 'Type or paste text here…',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('format_bytes')) {
|
||||
function format_bytes(int|float|null $bytes, int $precision = 1): string
|
||||
{
|
||||
$bytes = max(0, (int) $bytes);
|
||||
if ($bytes < 1024) {
|
||||
return $bytes . ' B';
|
||||
}
|
||||
foreach (['KB', 'MB', 'GB', 'TB'] as $unit) {
|
||||
$bytes /= 1024;
|
||||
if ($bytes < 1024) {
|
||||
return round((float) $bytes, $precision) . ' ' . $unit;
|
||||
}
|
||||
}
|
||||
|
||||
return round((float) $bytes, $precision) . ' PB';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class App extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Base Site URL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* URL to your CodeIgniter root. Typically, this will be your base URL,
|
||||
* WITH a trailing slash:
|
||||
*
|
||||
* E.g., http://example.com/
|
||||
*/
|
||||
public string $baseURL = 'http://127.0.0.1:8080/';
|
||||
|
||||
/**
|
||||
* Allowed Hostnames in the Site URL other than the hostname in the baseURL.
|
||||
* If you want to accept multiple Hostnames, set this.
|
||||
*
|
||||
* E.g.,
|
||||
* When your site URL ($baseURL) is 'http://example.com/', and your site
|
||||
* also accepts 'http://media.example.com/' and 'http://accounts.example.com/':
|
||||
* ['media.example.com', 'accounts.example.com']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $allowedHostnames = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Index File
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically, this will be your `index.php` file, unless you've renamed it to
|
||||
* something else. If you have configured your web server to remove this file
|
||||
* from your site URIs, set this variable to an empty string.
|
||||
*/
|
||||
public string $indexPage = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* URI PROTOCOL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This item determines which server global should be used to retrieve the
|
||||
* URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
* If your links do not seem to work, try one of the other delicious flavors:
|
||||
*
|
||||
* 'REQUEST_URI': Uses $_SERVER['REQUEST_URI']
|
||||
* 'QUERY_STRING': Uses $_SERVER['QUERY_STRING']
|
||||
* 'PATH_INFO': Uses $_SERVER['PATH_INFO']
|
||||
*
|
||||
* WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
public string $uriProtocol = 'REQUEST_URI';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible.
|
||||
|
|
||||
| By default, only these are allowed: `a-z 0-9~%.:_-`
|
||||
|
|
||||
| Set an empty string to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be used as: '/\A[<permittedURIChars>]+\z/iu'
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
public string $permittedURIChars = 'a-z 0-9~%.:_\-';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Locale roughly represents the language and location that your visitor
|
||||
* is viewing the site from. It affects the language strings and other
|
||||
* strings (like currency markers, numbers, etc), that your program
|
||||
* should run under for this request.
|
||||
*/
|
||||
public string $defaultLocale = 'en';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Negotiate Locale
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, the current Request object will automatically determine the
|
||||
* language to use based on the value of the Accept-Language header.
|
||||
*
|
||||
* If false, no automatic detection will be performed.
|
||||
*/
|
||||
public bool $negotiateLocale = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Supported Locales
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If $negotiateLocale is true, this array lists the locales supported
|
||||
* by the application in descending order of priority. If no match is
|
||||
* found, the first locale will be used.
|
||||
*
|
||||
* IncomingRequest::setLocale() also uses this list.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedLocales = ['en'];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Application Timezone
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default timezone that will be used in your application to display
|
||||
* dates with the date helper, and can be retrieved through app_timezone()
|
||||
*
|
||||
* @see https://www.php.net/manual/en/timezones.php for list of timezones
|
||||
* supported by PHP.
|
||||
*/
|
||||
public string $appTimezone = 'UTC';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default Character Set
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This determines which character set is used by default in various methods
|
||||
* that require a character set to be provided.
|
||||
*
|
||||
* @see http://php.net/htmlspecialchars for a list of supported charsets.
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Force Global Secure Requests
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, this will force every request made to this application to be
|
||||
* made via a secure connection (HTTPS). If the incoming request is not
|
||||
* secure, the user will be redirected to a secure version of the page
|
||||
* and the HTTP Strict Transport Security (HSTS) header will be set.
|
||||
*/
|
||||
public bool $forceGlobalSecureRequests = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reverse Proxy IPs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
* IP addresses from which CodeIgniter should trust headers such as
|
||||
* X-Forwarded-For or Client-IP in order to properly identify
|
||||
* the visitor's IP address.
|
||||
*
|
||||
* You need to set a proxy IP address or IP address with subnets and
|
||||
* the HTTP header for the client IP address.
|
||||
*
|
||||
* Here are some examples:
|
||||
* [
|
||||
* '10.0.1.200' => 'X-Forwarded-For',
|
||||
* '192.168.5.0/24' => 'X-Real-IP',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $proxyIPs = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Content Security Policy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Enables the Response's Content Secure Policy to restrict the sources that
|
||||
* can be used for images, scripts, CSS files, audio, video, etc. If enabled,
|
||||
* the Response object will populate default values for the policy from the
|
||||
* `ContentSecurityPolicy.php` file. Controllers can always add to those
|
||||
* restrictions at run time.
|
||||
*
|
||||
* For a better understanding of CSP, see these documents:
|
||||
*
|
||||
* @see http://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
* @see http://www.w3.org/TR/CSP/
|
||||
*/
|
||||
public bool $CSPEnabled = false;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\AutoloadConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* AUTOLOADER CONFIGURATION
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file defines the namespaces and class maps so the Autoloader
|
||||
* can find the files as needed.
|
||||
*
|
||||
* NOTE: If you use an identical key in $psr4 or $classmap, then
|
||||
* the values in this file will overwrite the framework's values.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Autoload extends AutoloadConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Namespaces
|
||||
* -------------------------------------------------------------------
|
||||
* This maps the locations of any namespaces in your application to
|
||||
* their location on the file system. These are used by the autoloader
|
||||
* to locate files the first time they have been instantiated.
|
||||
*
|
||||
* The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are
|
||||
* already mapped for you.
|
||||
*
|
||||
* You may change the name of the 'App' namespace if you wish,
|
||||
* but this should be done prior to creating any namespaced classes,
|
||||
* else you will need to modify all of those classes for this to work.
|
||||
*
|
||||
* @var array<string, list<string>|string>
|
||||
*/
|
||||
public $psr4 = [
|
||||
APP_NAMESPACE => APPPATH,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Class Map
|
||||
* -------------------------------------------------------------------
|
||||
* The class map provides a map of class names and their exact
|
||||
* location on the drive. Classes loaded in this manner will have
|
||||
* slightly faster performance because they will not have to be
|
||||
* searched for within one or more directories as they would if they
|
||||
* were being autoloaded through a namespace.
|
||||
*
|
||||
* Prototype:
|
||||
* $classmap = [
|
||||
* 'MyClass' => '/path/to/class/file.php'
|
||||
* ];
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $classmap = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Files
|
||||
* -------------------------------------------------------------------
|
||||
* The files array provides a list of paths to __non-class__ files
|
||||
* that will be autoloaded. This can be useful for bootstrap operations
|
||||
* or for loading functions.
|
||||
*
|
||||
* Prototype:
|
||||
* $files = [
|
||||
* '/path/to/my/file.php',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $files = [];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Helpers
|
||||
* -------------------------------------------------------------------
|
||||
* Prototype:
|
||||
* $helpers = [
|
||||
* 'form',
|
||||
* ];
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $helpers = [];
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. This will control whether Kint is loaded, and a few other
|
||||
| items. It can always be used within your own application too.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| Don't show ANY in production environments. Instead, let the system catch
|
||||
| it and display a generic error message.
|
||||
|
|
||||
| If you set 'display_errors' to '1', CI4's detailed error report will show.
|
||||
*/
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
// If you want to suppress more types of errors.
|
||||
// error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
|
||||
ini_set('display_errors', '0');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', false);
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The environment testing is reserved for PHPUnit testing. It has special
|
||||
* conditions built into the framework at various places to assist with that.
|
||||
* You can’t use it for your development.
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ERROR DISPLAY
|
||||
|--------------------------------------------------------------------------
|
||||
| In development, we want to show as many errors as possible to help
|
||||
| make sure they don't make it to production. And save us hours of
|
||||
| painful debugging.
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG BACKTRACES
|
||||
|--------------------------------------------------------------------------
|
||||
| If true, this constant will tell the error screens to display debug
|
||||
| backtraces along with the other error information. If you would
|
||||
| prefer to not see this, set this value to false.
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEBUG MODE
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug mode is an experimental flag that can allow changes throughout
|
||||
| the system. It's not widely used currently, and may not survive
|
||||
| release of the framework.
|
||||
*/
|
||||
defined('CI_DEBUG') || define('CI_DEBUG', true);
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class CURLRequest extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CURLRequest Share Connection Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Share connection options between requests.
|
||||
*
|
||||
* @var list<int>
|
||||
*
|
||||
* @see https://www.php.net/manual/en/curl.constants.php#constant.curl-lock-data-connect
|
||||
*/
|
||||
public array $shareConnectionOptions = [
|
||||
CURL_LOCK_DATA_CONNECT,
|
||||
CURL_LOCK_DATA_DNS,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CURLRequest Share Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether share options between requests or not.
|
||||
*
|
||||
* If true, all the options won't be reset between requests.
|
||||
* It may cause an error request with unnecessary headers.
|
||||
*/
|
||||
public bool $shareOptions = false;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Cache\CacheInterface;
|
||||
use CodeIgniter\Cache\Handlers\ApcuHandler;
|
||||
use CodeIgniter\Cache\Handlers\DummyHandler;
|
||||
use CodeIgniter\Cache\Handlers\FileHandler;
|
||||
use CodeIgniter\Cache\Handlers\MemcachedHandler;
|
||||
use CodeIgniter\Cache\Handlers\PredisHandler;
|
||||
use CodeIgniter\Cache\Handlers\RedisHandler;
|
||||
use CodeIgniter\Cache\Handlers\WincacheHandler;
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Cache extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Primary Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the preferred handler that should be used. If for some reason
|
||||
* it is not available, the $backupHandler will be used in its place.
|
||||
*/
|
||||
public string $handler = 'file';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Backup Handler
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The name of the handler that will be used in case the first one is
|
||||
* unreachable. Often, 'file' is used here since the filesystem is
|
||||
* always available, though that's not always practical for the app.
|
||||
*/
|
||||
public string $backupHandler = 'dummy';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Key Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This string is added to all cache item names to help avoid collisions
|
||||
* if you run multiple applications with the same cache engine.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Default TTL
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of seconds to save items when none is specified.
|
||||
*
|
||||
* WARNING: This is not used by framework handlers where 60 seconds is
|
||||
* hard-coded, but may be useful to projects and modules. This will replace
|
||||
* the hard-coded value in a future release.
|
||||
*/
|
||||
public int $ttl = 60;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Reserved Characters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* A string of reserved characters that will not be allowed in keys or tags.
|
||||
* Strings that violate this restriction will cause handlers to throw.
|
||||
* Default: {}()/\@:
|
||||
*
|
||||
* NOTE: The default set is required for PSR-6 compliance.
|
||||
*/
|
||||
public string $reservedCharacters = '{}()/\@:';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* File settings
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Your file storage preferences can be specified below, if you are using
|
||||
* the File driver.
|
||||
*
|
||||
* @var array{storePath?: string, mode?: int}
|
||||
*/
|
||||
public array $file = [
|
||||
'storePath' => WRITEPATH . 'cache/',
|
||||
'mode' => 0640,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Memcached settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Memcached servers can be specified below, if you are using
|
||||
* the Memcached drivers.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||
*
|
||||
* @var array{host?: string, port?: int, weight?: int, raw?: bool}
|
||||
*/
|
||||
public array $memcached = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'weight' => 1,
|
||||
'raw' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Redis settings
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Your Redis server can be specified below, if you are using
|
||||
* the Redis or Predis drivers.
|
||||
*
|
||||
* @var array{
|
||||
* host?: string,
|
||||
* password?: string|null,
|
||||
* port?: int,
|
||||
* timeout?: int,
|
||||
* async?: bool,
|
||||
* persistent?: bool,
|
||||
* database?: int
|
||||
* }
|
||||
*/
|
||||
public array $redis = [
|
||||
'host' => '127.0.0.1',
|
||||
'password' => null,
|
||||
'port' => 6379,
|
||||
'timeout' => 0,
|
||||
'async' => false, // specific to Predis and ignored by the native Redis extension
|
||||
'persistent' => false,
|
||||
'database' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Cache Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is an array of cache engine alias' and class names. Only engines
|
||||
* that are listed here are allowed to be used.
|
||||
*
|
||||
* @var array<string, class-string<CacheInterface>>
|
||||
*/
|
||||
public array $validHandlers = [
|
||||
'apcu' => ApcuHandler::class,
|
||||
'dummy' => DummyHandler::class,
|
||||
'file' => FileHandler::class,
|
||||
'memcached' => MemcachedHandler::class,
|
||||
'predis' => PredisHandler::class,
|
||||
'redis' => RedisHandler::class,
|
||||
'wincache' => WincacheHandler::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Web Page Caching: Cache Include Query String
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to take the URL query string into consideration when generating
|
||||
* output cache files. Valid options are:
|
||||
*
|
||||
* false = Disabled
|
||||
* true = Enabled, take all query parameters into account.
|
||||
* Please be aware that this may result in numerous cache
|
||||
* files generated for the same page over and over again.
|
||||
* ['q'] = Enabled, but only take into account the specified list
|
||||
* of query parameters.
|
||||
*
|
||||
* @var bool|list<string>
|
||||
*/
|
||||
public $cacheQueryString = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Web Page Caching: Cache Status Codes
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* HTTP status codes that are allowed to be cached. Only responses with
|
||||
* these status codes will be cached by the PageCache filter.
|
||||
*
|
||||
* Default: [] - Cache all status codes (backward compatible)
|
||||
*
|
||||
* Recommended: [200] - Only cache successful responses
|
||||
*
|
||||
* You can also use status codes like:
|
||||
* [200, 404, 410] - Cache successful responses and specific error codes
|
||||
* [200, 201, 202, 203, 204] - All 2xx successful responses
|
||||
*
|
||||
* WARNING: Using [] may cache temporary error pages (404, 500, etc).
|
||||
* Consider restricting to [200] for production applications to avoid
|
||||
* caching errors that should be temporary.
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $cacheStatusCodes = [];
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------
|
||||
| App Namespace
|
||||
| --------------------------------------------------------------------
|
||||
|
|
||||
| This defines the default Namespace that is used throughout
|
||||
| CodeIgniter to refer to the Application directory. Change
|
||||
| this constant to change the namespace that all application
|
||||
| classes should use.
|
||||
|
|
||||
| NOTE: changing this will require manually modifying the
|
||||
| existing namespaces of App\* namespaced-classes.
|
||||
*/
|
||||
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Composer Path
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| The path that Composer's autoload file is expected to live. By default,
|
||||
| the vendor folder is in the Root directory, but you can customize that here.
|
||||
*/
|
||||
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . 'vendor/autoload.php');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Timing Constants
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Provide simple ways to work with the myriad of PHP functions that
|
||||
| require information to be in seconds.
|
||||
*/
|
||||
defined('SECOND') || define('SECOND', 1);
|
||||
defined('MINUTE') || define('MINUTE', 60);
|
||||
defined('HOUR') || define('HOUR', 3600);
|
||||
defined('DAY') || define('DAY', 86400);
|
||||
defined('WEEK') || define('WEEK', 604800);
|
||||
defined('MONTH') || define('MONTH', 2_592_000);
|
||||
defined('YEAR') || define('YEAR', 31_536_000);
|
||||
defined('DECADE') || define('DECADE', 315_360_000);
|
||||
|
||||
/*
|
||||
| --------------------------------------------------------------------------
|
||||
| Exit Status Codes
|
||||
| --------------------------------------------------------------------------
|
||||
|
|
||||
| Used to indicate the conditions under which the script is exit()ing.
|
||||
| While there is no universal standard for error codes, there are some
|
||||
| broad conventions. Three such conventions are mentioned below, for
|
||||
| those who wish to make use of them. The CodeIgniter defaults were
|
||||
| chosen for the least overlap with these conventions, while still
|
||||
| leaving room for others to be defined in future versions and user
|
||||
| applications.
|
||||
|
|
||||
| The three main conventions used for determining exit status codes
|
||||
| are as follows:
|
||||
|
|
||||
| Standard C/C++ Library (stdlibc):
|
||||
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||
| (This link also contains other GNU-specific conventions)
|
||||
| BSD sysexits.h:
|
||||
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||
| Bash scripting:
|
||||
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
|
|
||||
*/
|
||||
defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
|
||||
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
|
||||
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
|
||||
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
|
||||
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
|
||||
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Stores the default settings for the ContentSecurityPolicy, if you
|
||||
* choose to use it. The values here will be read in and set as defaults
|
||||
* for the site. If needed, they can be overridden on a page-by-page basis.
|
||||
*
|
||||
* Suggested reference for explanations:
|
||||
*
|
||||
* @see https://www.html5rocks.com/en/tutorials/security/content-security-policy/
|
||||
*/
|
||||
class ContentSecurityPolicy extends BaseConfig
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// Broadbrush CSP management
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Default CSP report context
|
||||
*/
|
||||
public bool $reportOnly = false;
|
||||
|
||||
/**
|
||||
* Specifies a URL where a browser will send reports
|
||||
* when a content security policy is violated.
|
||||
*/
|
||||
public ?string $reportURI = null;
|
||||
|
||||
/**
|
||||
* Specifies a reporting endpoint to which violation reports ought to be sent.
|
||||
*/
|
||||
public ?string $reportTo = null;
|
||||
|
||||
/**
|
||||
* Instructs user agents to rewrite URL schemes, changing
|
||||
* HTTP to HTTPS. This directive is for websites with
|
||||
* large numbers of old URLs that need to be rewritten.
|
||||
*/
|
||||
public bool $upgradeInsecureRequests = false;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// CSP DIRECTIVES SETTINGS
|
||||
// NOTE: once you set a policy to 'none', it cannot be further restricted
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Will default to `'self'` if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $defaultSrc;
|
||||
|
||||
/**
|
||||
* Lists allowed scripts' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $scriptSrc = 'self';
|
||||
|
||||
/**
|
||||
* Specifies valid sources for JavaScript <script> elements.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $scriptSrcElem = 'self';
|
||||
|
||||
/**
|
||||
* Specifies valid sources for JavaScript inline event
|
||||
* handlers and JavaScript URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $scriptSrcAttr = 'self';
|
||||
|
||||
/**
|
||||
* Lists allowed stylesheets' URLs.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $styleSrc = 'self';
|
||||
|
||||
/**
|
||||
* Specifies valid sources for stylesheets <link> elements.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $styleSrcElem = 'self';
|
||||
|
||||
/**
|
||||
* Specifies valid sources for stylesheets inline
|
||||
* style attributes and `<style>` elements.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $styleSrcAttr = 'self';
|
||||
|
||||
/**
|
||||
* Defines the origins from which images can be loaded.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $imageSrc = 'self';
|
||||
|
||||
/**
|
||||
* Restricts the URLs that can appear in a page's `<base>` element.
|
||||
*
|
||||
* Will default to self if not overridden
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $baseURI;
|
||||
|
||||
/**
|
||||
* Lists the URLs for workers and embedded frame contents
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $childSrc = 'self';
|
||||
|
||||
/**
|
||||
* Limits the origins that you can connect to (via XHR,
|
||||
* WebSockets, and EventSource).
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $connectSrc = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the origins that can serve web fonts.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $fontSrc;
|
||||
|
||||
/**
|
||||
* Lists valid endpoints for submission from `<form>` tags.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $formAction = 'self';
|
||||
|
||||
/**
|
||||
* Specifies the sources that can embed the current page.
|
||||
* This directive applies to `<frame>`, `<iframe>`, `<embed>`,
|
||||
* and `<applet>` tags. This directive can't be used in
|
||||
* `<meta>` tags and applies only to non-HTML resources.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameAncestors;
|
||||
|
||||
/**
|
||||
* The frame-src directive restricts the URLs which may
|
||||
* be loaded into nested browsing contexts.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $frameSrc;
|
||||
|
||||
/**
|
||||
* Restricts the origins allowed to deliver video and audio.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $mediaSrc;
|
||||
|
||||
/**
|
||||
* Allows control over Flash and other plugins.
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public $objectSrc = 'self';
|
||||
|
||||
/**
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $manifestSrc;
|
||||
|
||||
/**
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $workerSrc = [];
|
||||
|
||||
/**
|
||||
* Limits the kinds of plugins a page may invoke.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $pluginTypes;
|
||||
|
||||
/**
|
||||
* List of actions allowed.
|
||||
*
|
||||
* @var list<string>|string|null
|
||||
*/
|
||||
public $sandbox;
|
||||
|
||||
/**
|
||||
* Nonce placeholder for style tags.
|
||||
*/
|
||||
public string $styleNonceTag = '{csp-style-nonce}';
|
||||
|
||||
/**
|
||||
* Nonce placeholder for script tags.
|
||||
*/
|
||||
public string $scriptNonceTag = '{csp-script-nonce}';
|
||||
|
||||
/**
|
||||
* Replace nonce tag automatically?
|
||||
*/
|
||||
public bool $autoNonce = true;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use DateTimeInterface;
|
||||
|
||||
class Cookie extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Prefix
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set a cookie name prefix if you need to avoid collisions.
|
||||
*/
|
||||
public string $prefix = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Expires Timestamp
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Default expires timestamp for cookies. Setting this to `0` will mean the
|
||||
* cookie will not have the `Expires` attribute and will behave as a session
|
||||
* cookie.
|
||||
*
|
||||
* @var DateTimeInterface|int|string
|
||||
*/
|
||||
public $expires = 0;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Typically will be a forward slash.
|
||||
*/
|
||||
public string $path = '/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Domain
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Set to `.your-domain.com` for site-wide cookies.
|
||||
*/
|
||||
public string $domain = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Secure
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be set if a secure HTTPS connection exists.
|
||||
*/
|
||||
public bool $secure = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie HTTPOnly
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie will only be accessible via HTTP(S) (no JavaScript).
|
||||
*/
|
||||
public bool $httponly = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie SameSite
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Configure cookie SameSite setting. Allowed values are:
|
||||
* - None
|
||||
* - Lax
|
||||
* - Strict
|
||||
* - ''
|
||||
*
|
||||
* Alternatively, you can use the constant names:
|
||||
* - `Cookie::SAMESITE_NONE`
|
||||
* - `Cookie::SAMESITE_LAX`
|
||||
* - `Cookie::SAMESITE_STRICT`
|
||||
*
|
||||
* Defaults to `Lax` for compatibility with modern browsers. Setting `''`
|
||||
* (empty string) means default SameSite attribute set by browsers (`Lax`)
|
||||
* will be set on cookies. If set to `None`, `$secure` must also be set.
|
||||
*
|
||||
* @var ''|'Lax'|'None'|'Strict'
|
||||
*/
|
||||
public string $samesite = 'Lax';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Cookie Raw
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This flag allows setting a "raw" cookie, i.e., its name and value are
|
||||
* not URL encoded using `rawurlencode()`.
|
||||
*
|
||||
* If this is set to `true`, cookie names should be compliant of RFC 2616's
|
||||
* list of allowed characters.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
|
||||
* @see https://tools.ietf.org/html/rfc2616#section-2.2
|
||||
*/
|
||||
public bool $raw = false;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Cross-Origin Resource Sharing (CORS) Configuration
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
*/
|
||||
class Cors extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* The default CORS configuration.
|
||||
*
|
||||
* @var array{
|
||||
* allowedOrigins: list<string>,
|
||||
* allowedOriginsPatterns: list<string>,
|
||||
* supportsCredentials: bool,
|
||||
* allowedHeaders: list<string>,
|
||||
* exposedHeaders: list<string>,
|
||||
* allowedMethods: list<string>,
|
||||
* maxAge: int,
|
||||
* }
|
||||
*/
|
||||
public array $default = [
|
||||
/**
|
||||
* Origins for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* E.g.:
|
||||
* - ['http://localhost:8080']
|
||||
* - ['https://www.example.com']
|
||||
*/
|
||||
'allowedOrigins' => [],
|
||||
|
||||
/**
|
||||
* Origin regex patterns for the `Access-Control-Allow-Origin` header.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||
*
|
||||
* NOTE: A pattern specified here is part of a regular expression. It will
|
||||
* be actually `#\A<pattern>\z#`.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['https://\w+\.example\.com']
|
||||
*/
|
||||
'allowedOriginsPatterns' => [],
|
||||
|
||||
/**
|
||||
* Weather to send the `Access-Control-Allow-Credentials` header.
|
||||
*
|
||||
* The Access-Control-Allow-Credentials response header tells browsers whether
|
||||
* the server allows cross-origin HTTP requests to include credentials.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
|
||||
*/
|
||||
'supportsCredentials' => false,
|
||||
|
||||
/**
|
||||
* Set headers to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Headers response header is used in response to
|
||||
* a preflight request which includes the Access-Control-Request-Headers to
|
||||
* indicate which HTTP headers can be used during the actual request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
|
||||
*/
|
||||
'allowedHeaders' => [],
|
||||
|
||||
/**
|
||||
* Set headers to expose.
|
||||
*
|
||||
* The Access-Control-Expose-Headers response header allows a server to
|
||||
* indicate which response headers should be made available to scripts running
|
||||
* in the browser, in response to a cross-origin request.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
||||
*/
|
||||
'exposedHeaders' => [],
|
||||
|
||||
/**
|
||||
* Set methods to allow.
|
||||
*
|
||||
* The Access-Control-Allow-Methods response header specifies one or more
|
||||
* methods allowed when accessing a resource in response to a preflight
|
||||
* request.
|
||||
*
|
||||
* E.g.:
|
||||
* - ['GET', 'POST', 'PUT', 'DELETE']
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
|
||||
*/
|
||||
'allowedMethods' => [],
|
||||
|
||||
/**
|
||||
* Set how many seconds the results of a preflight request can be cached.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
|
||||
*/
|
||||
'maxAge' => 7200,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Database\Config;
|
||||
|
||||
/**
|
||||
* Database Configuration
|
||||
*/
|
||||
class Database extends Config
|
||||
{
|
||||
/**
|
||||
* The directory that holds the Migrations and Seeds directories.
|
||||
*/
|
||||
public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Lets you choose which connection group to use if no other is specified.
|
||||
*/
|
||||
public string $defaultGroup = 'default';
|
||||
|
||||
/**
|
||||
* The default database connection.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $default = [
|
||||
'DSN' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'numberNative' => false,
|
||||
'foundRows' => false,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLite3.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'database' => 'database.db',
|
||||
// 'DBDriver' => 'SQLite3',
|
||||
// 'DBPrefix' => '',
|
||||
// 'DBDebug' => true,
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'foreignKeys' => true,
|
||||
// 'busyTimeout' => 1000,
|
||||
// 'synchronous' => null,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for Postgre.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'public',
|
||||
// 'DBDriver' => 'Postgre',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'port' => 5432,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for SQLSRV.
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => '',
|
||||
// 'hostname' => 'localhost',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'database' => 'ci4',
|
||||
// 'schema' => 'dbo',
|
||||
// 'DBDriver' => 'SQLSRV',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'utf8',
|
||||
// 'swapPre' => '',
|
||||
// 'encrypt' => false,
|
||||
// 'failover' => [],
|
||||
// 'port' => 1433,
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// /**
|
||||
// * Sample database connection for OCI8.
|
||||
// *
|
||||
// * You may need the following environment variables:
|
||||
// * NLS_LANG = 'AMERICAN_AMERICA.UTF8'
|
||||
// * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
|
||||
// *
|
||||
// * @var array<string, mixed>
|
||||
// */
|
||||
// public array $default = [
|
||||
// 'DSN' => 'localhost:1521/FREEPDB1',
|
||||
// 'username' => 'root',
|
||||
// 'password' => 'root',
|
||||
// 'DBDriver' => 'OCI8',
|
||||
// 'DBPrefix' => '',
|
||||
// 'pConnect' => false,
|
||||
// 'DBDebug' => true,
|
||||
// 'charset' => 'AL32UTF8',
|
||||
// 'swapPre' => '',
|
||||
// 'failover' => [],
|
||||
// 'dateFormat' => [
|
||||
// 'date' => 'Y-m-d',
|
||||
// 'datetime' => 'Y-m-d H:i:s',
|
||||
// 'time' => 'H:i:s',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
/**
|
||||
* This database connection is used when running PHPUnit database tests.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $tests = [
|
||||
'DSN' => '',
|
||||
'hostname' => '127.0.0.1',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => ':memory:',
|
||||
'DBDriver' => 'SQLite3',
|
||||
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
|
||||
'pConnect' => false,
|
||||
'DBDebug' => true,
|
||||
'charset' => 'utf8',
|
||||
'DBCollat' => '',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => true,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
'foreignKeys' => true,
|
||||
'busyTimeout' => 1000,
|
||||
'synchronous' => null,
|
||||
'dateFormat' => [
|
||||
'date' => 'Y-m-d',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
'time' => 'H:i:s',
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Ensure that we always set the database group to 'tests' if
|
||||
// we are currently running an automated test suite, so that
|
||||
// we don't overwrite live data on accident.
|
||||
if (ENVIRONMENT === 'testing') {
|
||||
$this->defaultGroup = 'tests';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
class DocTypes
|
||||
{
|
||||
/**
|
||||
* List of valid document types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $list = [
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether to remove the solidus (`/`) character for void HTML elements (e.g. `<input>`)
|
||||
* for HTML5 compatibility.
|
||||
*
|
||||
* Set to:
|
||||
* `true` - to be HTML5 compatible
|
||||
* `false` - to be XHTML compatible
|
||||
*/
|
||||
public bool $html5 = true;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Email extends BaseConfig
|
||||
{
|
||||
public string $fromEmail = '';
|
||||
public string $fromName = '';
|
||||
public string $recipients = '';
|
||||
|
||||
/**
|
||||
* The "user agent"
|
||||
*/
|
||||
public string $userAgent = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The mail sending protocol: mail, sendmail, smtp
|
||||
*/
|
||||
public string $protocol = 'mail';
|
||||
|
||||
/**
|
||||
* The server path to Sendmail.
|
||||
*/
|
||||
public string $mailPath = '/usr/sbin/sendmail';
|
||||
|
||||
/**
|
||||
* SMTP Server Hostname
|
||||
*/
|
||||
public string $SMTPHost = '';
|
||||
|
||||
/**
|
||||
* Which SMTP authentication method to use: login, plain
|
||||
*/
|
||||
public string $SMTPAuthMethod = 'login';
|
||||
|
||||
/**
|
||||
* SMTP Username
|
||||
*/
|
||||
public string $SMTPUser = '';
|
||||
|
||||
/**
|
||||
* SMTP Password
|
||||
*/
|
||||
public string $SMTPPass = '';
|
||||
|
||||
/**
|
||||
* SMTP Port
|
||||
*/
|
||||
public int $SMTPPort = 25;
|
||||
|
||||
/**
|
||||
* SMTP Timeout (in seconds)
|
||||
*/
|
||||
public int $SMTPTimeout = 5;
|
||||
|
||||
/**
|
||||
* Enable persistent SMTP connections
|
||||
*/
|
||||
public bool $SMTPKeepAlive = false;
|
||||
|
||||
/**
|
||||
* SMTP Encryption.
|
||||
*
|
||||
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
|
||||
* to the server. 'ssl' means implicit SSL. Connection on port
|
||||
* 465 should set this to ''.
|
||||
*/
|
||||
public string $SMTPCrypto = 'tls';
|
||||
|
||||
/**
|
||||
* Enable word-wrap
|
||||
*/
|
||||
public bool $wordWrap = true;
|
||||
|
||||
/**
|
||||
* Character count to wrap at
|
||||
*/
|
||||
public int $wrapChars = 76;
|
||||
|
||||
/**
|
||||
* Type of mail, either 'text' or 'html'
|
||||
*/
|
||||
public string $mailType = 'text';
|
||||
|
||||
/**
|
||||
* Character set (utf-8, iso-8859-1, etc.)
|
||||
*/
|
||||
public string $charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Whether to validate the email address
|
||||
*/
|
||||
public bool $validate = false;
|
||||
|
||||
/**
|
||||
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
|
||||
*/
|
||||
public int $priority = 3;
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Newline character. (Use “\r\n” to comply with RFC 822)
|
||||
*/
|
||||
public string $newline = "\r\n";
|
||||
|
||||
/**
|
||||
* Enable BCC Batch Mode.
|
||||
*/
|
||||
public bool $BCCBatchMode = false;
|
||||
|
||||
/**
|
||||
* Number of emails in each BCC batch
|
||||
*/
|
||||
public int $BCCBatchSize = 200;
|
||||
|
||||
/**
|
||||
* Enable notify message from server
|
||||
*/
|
||||
public bool $DSN = false;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Encryption configuration.
|
||||
*
|
||||
* These are the settings used for encryption, if you don't pass a parameter
|
||||
* array to the encrypter for creation/initialization.
|
||||
*/
|
||||
class Encryption extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Key Starter
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If you use the Encryption class you must set an encryption key (seed).
|
||||
* You need to ensure it is long enough for the cipher and mode you plan to use.
|
||||
* See the user guide for more info.
|
||||
*/
|
||||
public string $key = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Previous Encryption Keys
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* When rotating encryption keys, add old keys here to maintain ability
|
||||
* to decrypt data encrypted with previous keys. Encryption always uses
|
||||
* the current $key. Decryption tries current key first, then falls back
|
||||
* to previous keys if decryption fails.
|
||||
*
|
||||
* In .env file, use comma-separated string:
|
||||
* encryption.previousKeys = hex2bin:9be8c64fcea509867...,hex2bin:3f5a1d8e9c2b7a4f6...
|
||||
*
|
||||
* @var list<string>|string
|
||||
*/
|
||||
public array|string $previousKeys = '';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption Driver to Use
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* One of the supported encryption drivers.
|
||||
*
|
||||
* Available drivers:
|
||||
* - OpenSSL
|
||||
* - Sodium
|
||||
*/
|
||||
public string $driver = 'OpenSSL';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* SodiumHandler's Padding Length in Bytes
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the number of bytes that will be padded to the plaintext message
|
||||
* before it is encrypted. This value should be greater than zero.
|
||||
*
|
||||
* See the user guide for more information on padding.
|
||||
*/
|
||||
public int $blockSize = 16;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Encryption digest
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* HMAC digest to use, e.g. 'SHA512' or 'SHA256'. Default value is 'SHA512'.
|
||||
*/
|
||||
public string $digest = 'SHA512';
|
||||
|
||||
/**
|
||||
* Whether the cipher-text should be raw. If set to false, then it will be base64 encoded.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to false for CI3 Encryption compatibility.
|
||||
*/
|
||||
public bool $rawData = true;
|
||||
|
||||
/**
|
||||
* Encryption key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'encryption' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $encryptKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Authentication key info.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'authentication' for CI3 Encryption compatibility.
|
||||
*/
|
||||
public string $authKeyInfo = '';
|
||||
|
||||
/**
|
||||
* Cipher to use.
|
||||
* This setting is only used by OpenSSLHandler.
|
||||
*
|
||||
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
|
||||
* by CI3 Encryption default configuration.
|
||||
*/
|
||||
public string $cipher = 'AES-256-CTR';
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\Exceptions\FrameworkException;
|
||||
use CodeIgniter\HotReloader\HotReloader;
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Application Events
|
||||
* --------------------------------------------------------------------
|
||||
* Events allow you to tap into the execution of the program without
|
||||
* modifying or extending core files. This file provides a central
|
||||
* location to define your events, though they can always be added
|
||||
* at run-time, also, if needed.
|
||||
*
|
||||
* You create code that can execute by subscribing to events with
|
||||
* the 'on()' method. This accepts any form of callable, including
|
||||
* Closures, that will be executed when the event is triggered.
|
||||
*
|
||||
* Example:
|
||||
* Events::on('create', [$myInstance, 'myMethod']);
|
||||
*/
|
||||
|
||||
Events::on('pre_system', static function (): void {
|
||||
if (ENVIRONMENT !== 'testing') {
|
||||
$value = ini_get('zlib.output_compression');
|
||||
|
||||
if (filter_var($value, FILTER_VALIDATE_BOOLEAN) || (int) $value > 0) {
|
||||
throw FrameworkException::forEnabledZlibOutputCompression();
|
||||
}
|
||||
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
ob_start(static fn ($buffer) => $buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* Debug Toolbar Listeners.
|
||||
* --------------------------------------------------------------------
|
||||
* If you delete, they will no longer be collected.
|
||||
*/
|
||||
if (CI_DEBUG && ! is_cli()) {
|
||||
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
|
||||
service('toolbar')->respond();
|
||||
// Hot Reload route - for framework use on the hot reloader.
|
||||
if (ENVIRONMENT === 'development') {
|
||||
service('routes')->get('__hot-reload', static function (): void {
|
||||
(new HotReloader())->run();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\ExceptionHandler;
|
||||
use CodeIgniter\Debug\ExceptionHandlerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Setup how the exception handler works.
|
||||
*/
|
||||
class Exceptions extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG EXCEPTIONS?
|
||||
* --------------------------------------------------------------------------
|
||||
* If true, then exceptions will be logged
|
||||
* through Services::Log.
|
||||
*
|
||||
* Default: true
|
||||
*/
|
||||
public bool $log = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* DO NOT LOG STATUS CODES
|
||||
* --------------------------------------------------------------------------
|
||||
* Any status codes here will NOT be logged if logging is turned on.
|
||||
* By default, only 404 (Page Not Found) exceptions are ignored.
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $ignoreCodes = [404];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
* This is the path to the directory that contains the 'cli' and 'html'
|
||||
* directories that hold the views used to generate errors.
|
||||
*
|
||||
* Default: APPPATH.'Views/errors'
|
||||
*/
|
||||
public string $errorViewPath = APPPATH . 'Views/errors';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* HIDE FROM DEBUG TRACE
|
||||
* --------------------------------------------------------------------------
|
||||
* Any data that you would like to hide from the debug trace.
|
||||
* In order to specify 2 levels, use "/" to separate.
|
||||
* ex. ['server', 'setup/password', 'secret_token']
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $sensitiveDataInTrace = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
|
||||
* --------------------------------------------------------------------------
|
||||
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
|
||||
* thrown. This option also works for user deprecations.
|
||||
*/
|
||||
public bool $logDeprecations = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* LOG LEVEL THRESHOLD FOR DEPRECATIONS
|
||||
* --------------------------------------------------------------------------
|
||||
* If `$logDeprecations` is set to `true`, this sets the log level
|
||||
* to which the deprecation will be logged. This should be one of the log
|
||||
* levels recognized by PSR-3.
|
||||
*
|
||||
* The related `Config\Logger::$threshold` should be adjusted, if needed,
|
||||
* to capture logging the deprecations.
|
||||
*/
|
||||
public string $deprecationLogLevel = LogLevel::WARNING;
|
||||
|
||||
/*
|
||||
* DEFINE THE HANDLERS USED
|
||||
* --------------------------------------------------------------------------
|
||||
* Given the HTTP status code, returns exception handler that
|
||||
* should be used to deal with this error. By default, it will run CodeIgniter's
|
||||
* default handler and display the error information in the expected format
|
||||
* for CLI, HTTP, or AJAX requests, as determined by is_cli() and the expected
|
||||
* response format.
|
||||
*
|
||||
* Custom handlers can be returned if you want to handle one or more specific
|
||||
* error codes yourself like:
|
||||
*
|
||||
* if (in_array($statusCode, [400, 404, 500])) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
* if ($exception instanceOf PageNotFoundException) {
|
||||
* return new \App\Libraries\MyExceptionHandler();
|
||||
* }
|
||||
*/
|
||||
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
|
||||
{
|
||||
return new ExceptionHandler($this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Enable/disable backward compatibility breaking features.
|
||||
*/
|
||||
class Feature extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Use improved new auto routing instead of the legacy version.
|
||||
*/
|
||||
public bool $autoRoutesImproved = true;
|
||||
|
||||
/**
|
||||
* Use filter execution order in 4.4 or before.
|
||||
*/
|
||||
public bool $oldFilterOrder = false;
|
||||
|
||||
/**
|
||||
* The behavior of `limit(0)` in Query Builder.
|
||||
*
|
||||
* If true, `limit(0)` returns all records. (the behavior of 4.4.x or before in version 4.x.)
|
||||
* If false, `limit(0)` returns no records. (the behavior of 3.1.9 or later in version 3.x.)
|
||||
*/
|
||||
public bool $limitZeroAsAll = true;
|
||||
|
||||
/**
|
||||
* Use strict location negotiation.
|
||||
*
|
||||
* By default, the locale is selected based on a loose comparison of the language code (ISO 639-1)
|
||||
* Enabling strict comparison will also consider the region code (ISO 3166-1 alpha-2).
|
||||
*/
|
||||
public bool $strictLocaleNegotiation = false;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Filters as BaseFilters;
|
||||
use CodeIgniter\Filters\Cors;
|
||||
use CodeIgniter\Filters\CSRF;
|
||||
use CodeIgniter\Filters\DebugToolbar;
|
||||
use CodeIgniter\Filters\ForceHTTPS;
|
||||
use CodeIgniter\Filters\Honeypot;
|
||||
use CodeIgniter\Filters\InvalidChars;
|
||||
use CodeIgniter\Filters\PageCache;
|
||||
use CodeIgniter\Filters\PerformanceMetrics;
|
||||
use CodeIgniter\Filters\SecureHeaders;
|
||||
|
||||
class Filters extends BaseFilters
|
||||
{
|
||||
/**
|
||||
* Configures aliases for Filter classes to
|
||||
* make reading things nicer and simpler.
|
||||
*
|
||||
* @var array<string, class-string|list<class-string>>
|
||||
*
|
||||
* [filter_name => classname]
|
||||
* or [filter_name => [classname1, classname2, ...]]
|
||||
*/
|
||||
public array $aliases = [
|
||||
'csrf' => CSRF::class,
|
||||
'toolbar' => DebugToolbar::class,
|
||||
'honeypot' => Honeypot::class,
|
||||
'invalidchars' => InvalidChars::class,
|
||||
'secureheaders' => SecureHeaders::class,
|
||||
'cors' => Cors::class,
|
||||
'forcehttps' => ForceHTTPS::class,
|
||||
'pagecache' => PageCache::class,
|
||||
'performance' => PerformanceMetrics::class,
|
||||
'seocanonical' => \App\Filters\SeoCanonical::class,
|
||||
'ratelimit' => \App\Filters\RateLimit::class,
|
||||
'admin-auth' => \App\Filters\AdminAuth::class,
|
||||
'api-auth' => \App\Filters\ApiAuth::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* List of special required filters.
|
||||
*
|
||||
* The filters listed here are special. They are applied before and after
|
||||
* other kinds of filters, and always applied even if a route does not exist.
|
||||
*
|
||||
* Filters set by default provide framework functionality. If removed,
|
||||
* those functions will no longer work.
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/incoming/filters.html#provided-filters
|
||||
*
|
||||
* @var array{before: list<string>, after: list<string>}
|
||||
*/
|
||||
public array $required = [
|
||||
'before' => [
|
||||
'forcehttps', // Force Global Secure Requests
|
||||
'pagecache', // Web Page Caching
|
||||
'seocanonical', // 301 non-canonical URLs even when the route would 404
|
||||
],
|
||||
'after' => [
|
||||
'pagecache', // Web Page Caching
|
||||
'performance', // Performance Metrics
|
||||
'toolbar', // Debug Toolbar
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that are always
|
||||
* applied before and after every request.
|
||||
*
|
||||
* @var array{
|
||||
* before: array<string, array{except: list<string>|string}>|list<string>,
|
||||
* after: array<string, array{except: list<string>|string}>|list<string>
|
||||
* }
|
||||
*/
|
||||
public array $globals = [
|
||||
'before' => [],
|
||||
'after' => [
|
||||
'secureheaders',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* List of filter aliases that works on a
|
||||
* particular HTTP method (GET, POST, etc.).
|
||||
*
|
||||
* Example:
|
||||
* 'POST' => ['foo', 'bar']
|
||||
*
|
||||
* If you use this, you should disable auto-routing because auto-routing
|
||||
* permits any HTTP method to access a controller. Accessing the controller
|
||||
* with a method you don't expect could bypass the filter.
|
||||
*
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
public array $methods = [];
|
||||
|
||||
/**
|
||||
* List of filter aliases that should run on any
|
||||
* before or after URI patterns.
|
||||
*
|
||||
* Example:
|
||||
* 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
|
||||
*
|
||||
* @var array<string, array<string, list<string>>>
|
||||
*/
|
||||
public array $filters = [
|
||||
'ratelimit' => ['before' => ['api/*', 'upload', 'download/*', 'preview/*']],
|
||||
'csrf' => ['except' => ['api/*']],
|
||||
'admin-auth' => ['except' => ['admin/login', 'admin/logout']],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\ForeignCharacters as BaseForeignCharacters;
|
||||
|
||||
/**
|
||||
* @immutable
|
||||
*/
|
||||
class ForeignCharacters extends BaseForeignCharacters
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Format\JSONFormatter;
|
||||
use CodeIgniter\Format\XMLFormatter;
|
||||
|
||||
class Format extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Available Response Formats
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* When you perform content negotiation with the request, these are the
|
||||
* available formats that your application supports. This is currently
|
||||
* only used with the API\ResponseTrait. A valid Formatter must exist
|
||||
* for the specified format.
|
||||
*
|
||||
* These formats are only checked when the data passed to the respond()
|
||||
* method is an array.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $supportedResponseFormats = [
|
||||
'application/json',
|
||||
'application/xml', // machine-readable XML
|
||||
'text/xml', // human-readable XML
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Lists the class to use to format responses with of a particular type.
|
||||
* For each mime type, list the class that should be used. Formatters
|
||||
* can be retrieved through the getFormatter() method.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $formatters = [
|
||||
'application/json' => JSONFormatter::class,
|
||||
'application/xml' => XMLFormatter::class,
|
||||
'text/xml' => XMLFormatter::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Formatters Options
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Additional Options to adjust default formatters behaviour.
|
||||
* For each mime type, list the additional options that should be used.
|
||||
*
|
||||
* @var array<string, int>
|
||||
*/
|
||||
public array $formatterOptions = [
|
||||
'application/json' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
|
||||
'application/xml' => 0,
|
||||
'text/xml' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Maximum depth for JSON encoding.
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This value determines how deep the JSON encoder will traverse nested structures.
|
||||
*/
|
||||
public int $jsonEncodeDepth = 512;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Generators extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Generator Commands' Views
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This array defines the mapping of generator commands to the view files
|
||||
* they are using. If you need to customize them for your own, copy these
|
||||
* view files in your own folder and indicate the location here.
|
||||
*
|
||||
* You will notice that the views have special placeholders enclosed in
|
||||
* curly braces `{...}`. These placeholders are used internally by the
|
||||
* generator commands in processing replacements, thus you are warned
|
||||
* not to delete them or modify the names. If you will do so, you may
|
||||
* end up disrupting the scaffolding process and throw errors.
|
||||
*
|
||||
* YOU HAVE BEEN WARNED!
|
||||
*
|
||||
* @var array<string, array<string, string>|string>
|
||||
*/
|
||||
public array $views = [
|
||||
'make:cell' => [
|
||||
'class' => 'CodeIgniter\Commands\Generators\Views\cell.tpl.php',
|
||||
'view' => 'CodeIgniter\Commands\Generators\Views\cell_view.tpl.php',
|
||||
],
|
||||
'make:command' => 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
|
||||
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
|
||||
'make:controller' => 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
|
||||
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',
|
||||
'make:filter' => 'CodeIgniter\Commands\Generators\Views\filter.tpl.php',
|
||||
'make:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
'make:model' => 'CodeIgniter\Commands\Generators\Views\model.tpl.php',
|
||||
'make:seeder' => 'CodeIgniter\Commands\Generators\Views\seeder.tpl.php',
|
||||
'make:validation' => 'CodeIgniter\Commands\Generators\Views\validation.tpl.php',
|
||||
'session:migration' => 'CodeIgniter\Commands\Generators\Views\migration.tpl.php',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Honeypot extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Makes Honeypot visible or not to human
|
||||
*/
|
||||
public bool $hidden = true;
|
||||
|
||||
/**
|
||||
* Honeypot Label Content
|
||||
*/
|
||||
public string $label = 'Fill This Field';
|
||||
|
||||
/**
|
||||
* Honeypot Field Name
|
||||
*/
|
||||
public string $name = 'honeypot';
|
||||
|
||||
/**
|
||||
* Honeypot HTML Template
|
||||
*/
|
||||
public string $template = '<label>{label}</label><input type="text" name="{name}" value="">';
|
||||
|
||||
/**
|
||||
* Honeypot container
|
||||
*
|
||||
* If you enabled CSP, you can remove `style="display:none"`.
|
||||
*/
|
||||
public string $container = '<div style="display:none">{template}</div>';
|
||||
|
||||
/**
|
||||
* The id attribute for Honeypot container tag
|
||||
*
|
||||
* Used when CSP is enabled.
|
||||
*/
|
||||
public string $containerId = 'hpc';
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
class Hostnames
|
||||
{
|
||||
// List of known two-part TLDs for subdomain extraction
|
||||
public const TWO_PART_TLDS = [
|
||||
'co.uk', 'org.uk', 'gov.uk', 'ac.uk', 'sch.uk', 'ltd.uk', 'plc.uk',
|
||||
'com.au', 'net.au', 'org.au', 'edu.au', 'gov.au', 'asn.au', 'id.au',
|
||||
'co.jp', 'ac.jp', 'go.jp', 'or.jp', 'ne.jp', 'gr.jp',
|
||||
'co.nz', 'org.nz', 'govt.nz', 'ac.nz', 'net.nz', 'geek.nz', 'maori.nz', 'school.nz',
|
||||
'co.in', 'net.in', 'org.in', 'ind.in', 'ac.in', 'gov.in', 'res.in',
|
||||
'com.cn', 'net.cn', 'org.cn', 'gov.cn', 'edu.cn',
|
||||
'com.sg', 'net.sg', 'org.sg', 'gov.sg', 'edu.sg', 'per.sg',
|
||||
'co.za', 'org.za', 'gov.za', 'ac.za', 'net.za',
|
||||
'co.kr', 'or.kr', 'go.kr', 'ac.kr', 'ne.kr', 'pe.kr',
|
||||
'co.th', 'or.th', 'go.th', 'ac.th', 'net.th', 'in.th',
|
||||
'com.my', 'net.my', 'org.my', 'edu.my', 'gov.my', 'mil.my', 'name.my',
|
||||
'com.mx', 'org.mx', 'net.mx', 'edu.mx', 'gob.mx',
|
||||
'com.br', 'net.br', 'org.br', 'gov.br', 'edu.br', 'art.br', 'eng.br',
|
||||
'co.il', 'org.il', 'ac.il', 'gov.il', 'net.il', 'muni.il',
|
||||
'co.id', 'or.id', 'ac.id', 'go.id', 'net.id', 'web.id', 'my.id',
|
||||
'com.hk', 'edu.hk', 'gov.hk', 'idv.hk', 'net.hk', 'org.hk',
|
||||
'com.tw', 'net.tw', 'org.tw', 'edu.tw', 'gov.tw', 'idv.tw',
|
||||
'com.sa', 'net.sa', 'org.sa', 'gov.sa', 'edu.sa', 'sch.sa', 'med.sa',
|
||||
'co.ae', 'net.ae', 'org.ae', 'gov.ae', 'ac.ae', 'sch.ae',
|
||||
'com.tr', 'net.tr', 'org.tr', 'gov.tr', 'edu.tr', 'av.tr', 'gen.tr',
|
||||
'co.ke', 'or.ke', 'go.ke', 'ac.ke', 'sc.ke', 'me.ke', 'mobi.ke', 'info.ke',
|
||||
'com.ng', 'org.ng', 'gov.ng', 'edu.ng', 'net.ng', 'sch.ng', 'name.ng',
|
||||
'com.pk', 'net.pk', 'org.pk', 'gov.pk', 'edu.pk', 'fam.pk',
|
||||
'com.eg', 'edu.eg', 'gov.eg', 'org.eg', 'net.eg',
|
||||
'com.cy', 'net.cy', 'org.cy', 'gov.cy', 'ac.cy',
|
||||
'com.lk', 'org.lk', 'edu.lk', 'gov.lk', 'net.lk', 'int.lk',
|
||||
'com.bd', 'net.bd', 'org.bd', 'ac.bd', 'gov.bd', 'mil.bd',
|
||||
'com.ar', 'net.ar', 'org.ar', 'gov.ar', 'edu.ar', 'mil.ar',
|
||||
'gob.cl', 'com.pl', 'net.pl', 'org.pl', 'gov.pl', 'edu.pl',
|
||||
'co.ir', 'ac.ir', 'org.ir', 'id.ir', 'gov.ir', 'sch.ir', 'net.ir',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Images\Handlers\GDHandler;
|
||||
use CodeIgniter\Images\Handlers\ImageMagickHandler;
|
||||
|
||||
class Images extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Default handler used if no other handler is specified.
|
||||
*/
|
||||
public string $defaultHandler = 'gd';
|
||||
|
||||
/**
|
||||
* The path to the image library.
|
||||
* Required for ImageMagick, GraphicsMagick, or NetPBM.
|
||||
*
|
||||
* @deprecated 4.7.0 No longer used.
|
||||
*/
|
||||
public string $libraryPath = '/usr/local/bin/convert';
|
||||
|
||||
/**
|
||||
* The available handler classes.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $handlers = [
|
||||
'gd' => GDHandler::class,
|
||||
'imagick' => ImageMagickHandler::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use Kint\Parser\ConstructablePluginInterface;
|
||||
use Kint\Renderer\Rich\TabPluginInterface;
|
||||
use Kint\Renderer\Rich\ValuePluginInterface;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Kint
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* We use Kint's `RichRenderer` and `CLIRenderer`. This area contains options
|
||||
* that you can set to customize how Kint works for you.
|
||||
*
|
||||
* @see https://kint-php.github.io/kint/ for details on these settings.
|
||||
*/
|
||||
class Kint
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
|
||||
*/
|
||||
public $plugins;
|
||||
|
||||
public int $maxDepth = 6;
|
||||
public bool $displayCalledFrom = true;
|
||||
public bool $expanded = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RichRenderer Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public string $richTheme = 'aante-light.css';
|
||||
public bool $richFolder = false;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<ValuePluginInterface>>|null
|
||||
*/
|
||||
public $richObjectPlugins;
|
||||
|
||||
/**
|
||||
* @var array<string, class-string<TabPluginInterface>>|null
|
||||
*/
|
||||
public $richTabPlugins;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CLI Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public bool $cliColors = true;
|
||||
public bool $cliForceUTF8 = false;
|
||||
public bool $cliDetectWidth = true;
|
||||
public int $cliMinWidth = 40;
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Log\Handlers\FileHandler;
|
||||
use CodeIgniter\Log\Handlers\HandlerInterface;
|
||||
|
||||
class Logger extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Error Logging Threshold
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* You can enable error logging by setting a threshold over zero. The
|
||||
* threshold determines what gets logged. Any values below or equal to the
|
||||
* threshold will be logged.
|
||||
*
|
||||
* Threshold options are:
|
||||
*
|
||||
* - 0 = Disables logging, Error logging TURNED OFF
|
||||
* - 1 = Emergency Messages - System is unusable
|
||||
* - 2 = Alert Messages - Action Must Be Taken Immediately
|
||||
* - 3 = Critical Messages - Application component unavailable, unexpected exception.
|
||||
* - 4 = Runtime Errors - Don't need immediate action, but should be monitored.
|
||||
* - 5 = Warnings - Exceptional occurrences that are not errors.
|
||||
* - 6 = Notices - Normal but significant events.
|
||||
* - 7 = Info - Interesting events, like user logging in, etc.
|
||||
* - 8 = Debug - Detailed debug information.
|
||||
* - 9 = All Messages
|
||||
*
|
||||
* You can also pass an array with threshold levels to show individual error types
|
||||
*
|
||||
* array(1, 2, 3, 8) = Emergency, Alert, Critical, and Debug messages
|
||||
*
|
||||
* For a live site you'll usually enable Critical or higher (3) to be logged otherwise
|
||||
* your log files will fill up very fast.
|
||||
*
|
||||
* @var int|list<int>
|
||||
*/
|
||||
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Date Format for Logs
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Each item that is logged has an associated date. You can use PHP date
|
||||
* codes to set your own date formatting
|
||||
*/
|
||||
public string $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Log Handlers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The logging system supports multiple actions to be taken when something
|
||||
* is logged. This is done by allowing for multiple Handlers, special classes
|
||||
* designed to write the log to their chosen destinations, whether that is
|
||||
* a file on the getServer, a cloud-based service, or even taking actions such
|
||||
* as emailing the dev team.
|
||||
*
|
||||
* Each handler is defined by the class name used for that handler, and it
|
||||
* MUST implement the `CodeIgniter\Log\Handlers\HandlerInterface` interface.
|
||||
*
|
||||
* The value of each key is an array of configuration items that are sent
|
||||
* to the constructor of each handler. The only required configuration item
|
||||
* is the 'handles' element, which must be an array of integer log levels.
|
||||
* This is most easily handled by using the constants defined in the
|
||||
* `Psr\Log\LogLevel` class.
|
||||
*
|
||||
* Handlers are executed in the order defined in this array, starting with
|
||||
* the handler on top and continuing down.
|
||||
*
|
||||
* @var array<class-string<HandlerInterface>, array<string, int|list<string>|string>>
|
||||
*/
|
||||
public array $handlers = [
|
||||
/*
|
||||
* --------------------------------------------------------------------
|
||||
* File Handler
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
FileHandler::class => [
|
||||
// The log levels that this handler will handle.
|
||||
'handles' => [
|
||||
'critical',
|
||||
'alert',
|
||||
'emergency',
|
||||
'debug',
|
||||
'error',
|
||||
'info',
|
||||
'notice',
|
||||
'warning',
|
||||
],
|
||||
|
||||
/*
|
||||
* The default filename extension for log files.
|
||||
* An extension of 'php' allows for protecting the log files via basic
|
||||
* scripting, when they are to be stored under a publicly accessible directory.
|
||||
*
|
||||
* NOTE: Leaving it blank will default to 'log'.
|
||||
*/
|
||||
'fileExtension' => '',
|
||||
|
||||
/*
|
||||
* The file system permissions to be applied on newly created log files.
|
||||
*
|
||||
* IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||
* integer notation (i.e. 0700, 0644, etc.)
|
||||
*/
|
||||
'filePermissions' => 0644,
|
||||
|
||||
/*
|
||||
* Logging Directory Path
|
||||
*
|
||||
* By default, logs are written to WRITEPATH . 'logs/'
|
||||
* Specify a different destination here, if desired.
|
||||
*/
|
||||
'path' => '',
|
||||
],
|
||||
|
||||
/*
|
||||
* The ChromeLoggerHandler requires the use of the Chrome web browser
|
||||
* and the ChromeLogger extension. Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
|
||||
// /*
|
||||
// * The log levels that this handler will handle.
|
||||
// */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug',
|
||||
// 'error', 'info', 'notice', 'warning'],
|
||||
// ],
|
||||
|
||||
/*
|
||||
* The ErrorlogHandler writes the logs to PHP's native `error_log()` function.
|
||||
* Uncomment this block to use it.
|
||||
*/
|
||||
// 'CodeIgniter\Log\Handlers\ErrorlogHandler' => [
|
||||
// /* The log levels this handler can handle. */
|
||||
// 'handles' => ['critical', 'alert', 'emergency', 'debug', 'error', 'info', 'notice', 'warning'],
|
||||
//
|
||||
// /*
|
||||
// * The message type where the error should go. Can be 0 or 4, or use the
|
||||
// * class constants: `ErrorlogHandler::TYPE_OS` (0) or `ErrorlogHandler::TYPE_SAPI` (4)
|
||||
// */
|
||||
// 'messageType' => 0,
|
||||
// ],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Migrations extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable/Disable Migrations
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Migrations are enabled by default.
|
||||
*
|
||||
* You should enable migrations whenever you intend to do a schema migration
|
||||
* and disable it back when you're done.
|
||||
*/
|
||||
public bool $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Migrations Table
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the name of the table that will store the current migrations state.
|
||||
* When migrations runs it will store in a database table which migration
|
||||
* files have already been run.
|
||||
*/
|
||||
public string $table = 'migrations';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Timestamp Format
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is the format that will be used when creating new migrations
|
||||
* using the CLI command:
|
||||
* > php spark make:migration
|
||||
*
|
||||
* NOTE: if you set an unsupported format, migration runner will not find
|
||||
* your migration files.
|
||||
*
|
||||
* Supported formats:
|
||||
* - YmdHis_
|
||||
* - Y-m-d-His_
|
||||
* - Y_m_d_His_
|
||||
*/
|
||||
public string $timestampFormat = 'Y-m-d-His_';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable/Disable Migration Lock
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Locking is disabled by default.
|
||||
*
|
||||
* When enabled, it will prevent multiple migration processes
|
||||
* from running at the same time by using a lock mechanism.
|
||||
*
|
||||
* This is useful in production environments to avoid conflicts
|
||||
* or race conditions during concurrent deployments.
|
||||
*/
|
||||
public bool $lock = false;
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* This file contains an array of mime types. It is used by the
|
||||
* Upload class to help identify allowed file types.
|
||||
*
|
||||
* When more than one variation for an extension exist (like jpg, jpeg, etc)
|
||||
* the most common one should be first in the array to aid the guess*
|
||||
* methods. The same applies when more than one mime-type exists for a
|
||||
* single extension.
|
||||
*
|
||||
* When working with mime types, please make sure you have the ´fileinfo´
|
||||
* extension enabled to reliably detect the media types.
|
||||
*/
|
||||
class Mimes
|
||||
{
|
||||
/**
|
||||
* Map of extensions to mime types.
|
||||
*
|
||||
* @var array<string, list<string>|string>
|
||||
*/
|
||||
public static array $mimes = [
|
||||
'hqx' => [
|
||||
'application/mac-binhex40',
|
||||
'application/mac-binhex',
|
||||
'application/x-binhex40',
|
||||
'application/x-mac-binhex40',
|
||||
],
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'csv' => [
|
||||
'text/csv',
|
||||
'text/x-comma-separated-values',
|
||||
'text/comma-separated-values',
|
||||
'application/vnd.ms-excel',
|
||||
'application/x-csv',
|
||||
'text/x-csv',
|
||||
'application/csv',
|
||||
'application/excel',
|
||||
'application/vnd.msexcel',
|
||||
'text/plain',
|
||||
],
|
||||
'bin' => [
|
||||
'application/macbinary',
|
||||
'application/mac-binary',
|
||||
'application/octet-stream',
|
||||
'application/x-binary',
|
||||
'application/x-macbinary',
|
||||
],
|
||||
'dms' => 'application/octet-stream',
|
||||
'lha' => 'application/octet-stream',
|
||||
'lzh' => 'application/octet-stream',
|
||||
'exe' => [
|
||||
'application/octet-stream',
|
||||
'application/vnd.microsoft.portable-executable',
|
||||
'application/x-dosexec',
|
||||
'application/x-msdownload',
|
||||
],
|
||||
'class' => 'application/octet-stream',
|
||||
'psd' => [
|
||||
'application/x-photoshop',
|
||||
'image/vnd.adobe.photoshop',
|
||||
],
|
||||
'so' => 'application/octet-stream',
|
||||
'sea' => 'application/octet-stream',
|
||||
'dll' => 'application/octet-stream',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => [
|
||||
'application/pdf',
|
||||
'application/force-download',
|
||||
'application/x-download',
|
||||
],
|
||||
'ai' => [
|
||||
'application/pdf',
|
||||
'application/postscript',
|
||||
],
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'mif' => 'application/vnd.mif',
|
||||
'xls' => [
|
||||
'application/vnd.ms-excel',
|
||||
'application/msexcel',
|
||||
'application/x-msexcel',
|
||||
'application/x-ms-excel',
|
||||
'application/x-excel',
|
||||
'application/x-dos_ms_excel',
|
||||
'application/xls',
|
||||
'application/x-xls',
|
||||
'application/excel',
|
||||
'application/download',
|
||||
'application/vnd.ms-office',
|
||||
'application/msword',
|
||||
],
|
||||
'ppt' => [
|
||||
'application/vnd.ms-powerpoint',
|
||||
'application/powerpoint',
|
||||
'application/vnd.ms-office',
|
||||
'application/msword',
|
||||
],
|
||||
'pptx' => [
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
],
|
||||
'wbxml' => 'application/wbxml',
|
||||
'wmlc' => 'application/wmlc',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'php' => [
|
||||
'application/x-php',
|
||||
'application/x-httpd-php',
|
||||
'application/php',
|
||||
'text/php',
|
||||
'text/x-php',
|
||||
'application/x-httpd-php-source',
|
||||
],
|
||||
'php4' => 'application/x-httpd-php',
|
||||
'php3' => 'application/x-httpd-php',
|
||||
'phtml' => 'application/x-httpd-php',
|
||||
'phps' => 'application/x-httpd-php-source',
|
||||
'js' => [
|
||||
'application/x-javascript',
|
||||
'text/plain',
|
||||
],
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'tar' => 'application/x-tar',
|
||||
'tgz' => [
|
||||
'application/x-tar',
|
||||
'application/x-gzip-compressed',
|
||||
],
|
||||
'z' => 'application/x-compress',
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => [
|
||||
'application/x-zip',
|
||||
'application/zip',
|
||||
'application/x-zip-compressed',
|
||||
'application/s-compressed',
|
||||
'multipart/x-zip',
|
||||
],
|
||||
'rar' => [
|
||||
'application/vnd.rar',
|
||||
'application/x-rar',
|
||||
'application/rar',
|
||||
'application/x-rar-compressed',
|
||||
],
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => [
|
||||
'audio/mpeg',
|
||||
'audio/mpg',
|
||||
'audio/mpeg3',
|
||||
'audio/mp3',
|
||||
],
|
||||
'aif' => [
|
||||
'audio/x-aiff',
|
||||
'audio/aiff',
|
||||
],
|
||||
'aiff' => [
|
||||
'audio/x-aiff',
|
||||
'audio/aiff',
|
||||
],
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'rv' => 'video/vnd.rn-realvideo',
|
||||
'wav' => [
|
||||
'audio/x-wav',
|
||||
'audio/wave',
|
||||
'audio/wav',
|
||||
],
|
||||
'bmp' => [
|
||||
'image/bmp',
|
||||
'image/x-bmp',
|
||||
'image/x-bitmap',
|
||||
'image/x-xbitmap',
|
||||
'image/x-win-bitmap',
|
||||
'image/x-windows-bmp',
|
||||
'image/ms-bmp',
|
||||
'image/x-ms-bmp',
|
||||
'application/bmp',
|
||||
'application/x-bmp',
|
||||
'application/x-win-bitmap',
|
||||
],
|
||||
'gif' => 'image/gif',
|
||||
'jpg' => [
|
||||
'image/jpeg',
|
||||
'image/pjpeg',
|
||||
],
|
||||
'jpeg' => [
|
||||
'image/jpeg',
|
||||
'image/pjpeg',
|
||||
],
|
||||
'jpe' => [
|
||||
'image/jpeg',
|
||||
'image/pjpeg',
|
||||
],
|
||||
'jp2' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'j2k' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'jpf' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'jpg2' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'jpx' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'jpm' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'mj2' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'mjp2' => [
|
||||
'image/jp2',
|
||||
'video/mj2',
|
||||
'image/jpx',
|
||||
'image/jpm',
|
||||
],
|
||||
'png' => [
|
||||
'image/png',
|
||||
'image/x-png',
|
||||
],
|
||||
'webp' => 'image/webp',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff',
|
||||
'css' => [
|
||||
'text/css',
|
||||
'text/plain',
|
||||
],
|
||||
'html' => [
|
||||
'text/html',
|
||||
'text/plain',
|
||||
],
|
||||
'htm' => [
|
||||
'text/html',
|
||||
'text/plain',
|
||||
],
|
||||
'shtml' => [
|
||||
'text/html',
|
||||
'text/plain',
|
||||
],
|
||||
'txt' => 'text/plain',
|
||||
'text' => 'text/plain',
|
||||
'log' => [
|
||||
'text/plain',
|
||||
'text/x-log',
|
||||
],
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'xml' => [
|
||||
'application/xml',
|
||||
'text/xml',
|
||||
'text/plain',
|
||||
],
|
||||
'xsl' => [
|
||||
'application/xml',
|
||||
'text/xsl',
|
||||
'text/xml',
|
||||
],
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'avi' => [
|
||||
'video/x-msvideo',
|
||||
'video/msvideo',
|
||||
'video/avi',
|
||||
'application/x-troff-msvideo',
|
||||
],
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'doc' => [
|
||||
'application/msword',
|
||||
'application/vnd.ms-office',
|
||||
],
|
||||
'docx' => [
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/zip',
|
||||
'application/msword',
|
||||
'application/x-zip',
|
||||
],
|
||||
'dot' => [
|
||||
'application/msword',
|
||||
'application/vnd.ms-office',
|
||||
],
|
||||
'dotx' => [
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/zip',
|
||||
'application/msword',
|
||||
],
|
||||
'xlsx' => [
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'application/zip',
|
||||
'application/vnd.ms-excel',
|
||||
'application/msword',
|
||||
'application/x-zip',
|
||||
],
|
||||
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
|
||||
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||
'word' => [
|
||||
'application/msword',
|
||||
'application/octet-stream',
|
||||
],
|
||||
'xl' => 'application/excel',
|
||||
'eml' => 'message/rfc822',
|
||||
'json' => [
|
||||
'application/json',
|
||||
'text/json',
|
||||
],
|
||||
'pem' => [
|
||||
'application/x-x509-user-cert',
|
||||
'application/x-pem-file',
|
||||
'application/octet-stream',
|
||||
],
|
||||
'p10' => [
|
||||
'application/x-pkcs10',
|
||||
'application/pkcs10',
|
||||
],
|
||||
'p12' => 'application/x-pkcs12',
|
||||
'p7a' => 'application/x-pkcs7-signature',
|
||||
'p7c' => [
|
||||
'application/pkcs7-mime',
|
||||
'application/x-pkcs7-mime',
|
||||
],
|
||||
'p7m' => [
|
||||
'application/pkcs7-mime',
|
||||
'application/x-pkcs7-mime',
|
||||
],
|
||||
'p7r' => 'application/x-pkcs7-certreqresp',
|
||||
'p7s' => 'application/pkcs7-signature',
|
||||
'crt' => [
|
||||
'application/x-x509-ca-cert',
|
||||
'application/x-x509-user-cert',
|
||||
'application/pkix-cert',
|
||||
],
|
||||
'crl' => [
|
||||
'application/pkix-crl',
|
||||
'application/pkcs-crl',
|
||||
],
|
||||
'der' => 'application/x-x509-ca-cert',
|
||||
'kdb' => 'application/octet-stream',
|
||||
'pgp' => 'application/pgp',
|
||||
'gpg' => 'application/gpg-keys',
|
||||
'sst' => 'application/octet-stream',
|
||||
'csr' => 'application/octet-stream',
|
||||
'rsa' => 'application/x-pkcs7',
|
||||
'cer' => [
|
||||
'application/pkix-cert',
|
||||
'application/x-x509-ca-cert',
|
||||
],
|
||||
'3g2' => 'video/3gpp2',
|
||||
'3gp' => [
|
||||
'video/3gp',
|
||||
'video/3gpp',
|
||||
],
|
||||
'mp4' => 'video/mp4',
|
||||
'm4a' => 'audio/x-m4a',
|
||||
'f4v' => [
|
||||
'video/mp4',
|
||||
'video/x-f4v',
|
||||
],
|
||||
'flv' => 'video/x-flv',
|
||||
'webm' => 'video/webm',
|
||||
'aac' => 'audio/x-acc',
|
||||
'm4u' => 'application/vnd.mpegurl',
|
||||
'm3u' => 'text/plain',
|
||||
'xspf' => 'application/xspf+xml',
|
||||
'vlc' => 'application/videolan',
|
||||
'wmv' => [
|
||||
'video/x-ms-wmv',
|
||||
'video/x-ms-asf',
|
||||
],
|
||||
'au' => 'audio/x-au',
|
||||
'ac3' => 'audio/ac3',
|
||||
'flac' => 'audio/x-flac',
|
||||
'ogg' => [
|
||||
'audio/ogg',
|
||||
'video/ogg',
|
||||
'application/ogg',
|
||||
],
|
||||
'kmz' => [
|
||||
'application/vnd.google-earth.kmz',
|
||||
'application/zip',
|
||||
'application/x-zip',
|
||||
],
|
||||
'kml' => [
|
||||
'application/vnd.google-earth.kml+xml',
|
||||
'application/xml',
|
||||
'text/xml',
|
||||
],
|
||||
'ics' => 'text/calendar',
|
||||
'ical' => 'text/calendar',
|
||||
'zsh' => 'text/x-scriptzsh',
|
||||
'7zip' => [
|
||||
'application/x-compressed',
|
||||
'application/x-zip-compressed',
|
||||
'application/zip',
|
||||
'multipart/x-zip',
|
||||
],
|
||||
'cdr' => [
|
||||
'application/cdr',
|
||||
'application/coreldraw',
|
||||
'application/x-cdr',
|
||||
'application/x-coreldraw',
|
||||
'image/cdr',
|
||||
'image/x-cdr',
|
||||
'zz-application/zz-winassoc-cdr',
|
||||
],
|
||||
'wma' => [
|
||||
'audio/x-ms-wma',
|
||||
'video/x-ms-asf',
|
||||
],
|
||||
'jar' => [
|
||||
'application/java-archive',
|
||||
'application/x-java-application',
|
||||
'application/x-jar',
|
||||
'application/x-compressed',
|
||||
],
|
||||
'svg' => [
|
||||
'image/svg+xml',
|
||||
'image/svg',
|
||||
'application/xml',
|
||||
'text/xml',
|
||||
],
|
||||
'vcf' => 'text/x-vcard',
|
||||
'srt' => [
|
||||
'text/srt',
|
||||
'text/plain',
|
||||
],
|
||||
'vtt' => [
|
||||
'text/vtt',
|
||||
'text/plain',
|
||||
],
|
||||
'ico' => [
|
||||
'image/x-icon',
|
||||
'image/x-ico',
|
||||
'image/vnd.microsoft.icon',
|
||||
],
|
||||
'stl' => [
|
||||
'application/sla',
|
||||
'application/vnd.ms-pki.stl',
|
||||
'application/x-navistyle',
|
||||
'model/stl',
|
||||
'application/octet-stream',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Attempts to determine the best mime type for the given file extension.
|
||||
*
|
||||
* @return string|null The mime type found, or none if unable to determine.
|
||||
*/
|
||||
public static function guessTypeFromExtension(string $extension)
|
||||
{
|
||||
$extension = trim(strtolower($extension), '. ');
|
||||
|
||||
if (! array_key_exists($extension, static::$mimes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to determine the best file extension for a given mime type.
|
||||
*
|
||||
* @param string|null $proposedExtension - default extension (in case there is more than one with the same mime type)
|
||||
*
|
||||
* @return string|null The extension determined, or null if unable to match.
|
||||
*/
|
||||
public static function guessExtensionFromType(string $type, ?string $proposedExtension = null)
|
||||
{
|
||||
$type = trim(strtolower($type), '. ');
|
||||
|
||||
$proposedExtension = trim(strtolower($proposedExtension ?? ''));
|
||||
|
||||
if (
|
||||
$proposedExtension !== ''
|
||||
&& array_key_exists($proposedExtension, static::$mimes)
|
||||
&& in_array($type, (array) static::$mimes[$proposedExtension], true)
|
||||
) {
|
||||
// The detected mime type matches with the proposed extension.
|
||||
return $proposedExtension;
|
||||
}
|
||||
|
||||
// Reverse check the mime type list if no extension was proposed.
|
||||
// This search is order sensitive!
|
||||
foreach (static::$mimes as $ext => $types) {
|
||||
if (in_array($type, (array) $types, true)) {
|
||||
return $ext;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Modules\Modules as BaseModules;
|
||||
|
||||
/**
|
||||
* Modules Configuration.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Modules extends BaseModules
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all elements listed in
|
||||
* $aliases below. If false, no auto-discovery will happen at all,
|
||||
* giving a slight performance boost.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Enable Auto-Discovery Within Composer Packages?
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If true, then auto-discovery will happen across all namespaces loaded
|
||||
* by Composer, as well as the namespaces configured locally.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $discoverInComposer = true;
|
||||
|
||||
/**
|
||||
* The Composer package list for Auto-Discovery
|
||||
* This setting is optional.
|
||||
*
|
||||
* E.g.:
|
||||
* [
|
||||
* 'only' => [
|
||||
* // List up all packages to auto-discover
|
||||
* 'codeigniter4/shield',
|
||||
* ],
|
||||
* ]
|
||||
* or
|
||||
* [
|
||||
* 'exclude' => [
|
||||
* // List up packages to exclude.
|
||||
* 'pestphp/pest',
|
||||
* ],
|
||||
* ]
|
||||
*
|
||||
* @var array{only?: list<string>, exclude?: list<string>}
|
||||
*/
|
||||
public $composerPackages = [];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Auto-Discovery Rules
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Aliases list of all discovery classes that will be active and used during
|
||||
* the current application request.
|
||||
*
|
||||
* If it is not listed, only the base application elements will be used.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public $aliases = [
|
||||
'events',
|
||||
'filters',
|
||||
'registrars',
|
||||
'routes',
|
||||
'services',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Optimization Configuration.
|
||||
*
|
||||
* NOTE: This class does not extend BaseConfig for performance reasons.
|
||||
* So you cannot replace the property values with Environment Variables.
|
||||
*
|
||||
* WARNING: Do not use these options when running the app in the Worker Mode.
|
||||
*/
|
||||
class Optimize
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
|
||||
*/
|
||||
public bool $configCacheEnabled = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/autoloader.html#file-locator-caching
|
||||
*/
|
||||
public bool $locatorCacheEnabled = false;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Pager extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Templates
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Pagination links are rendered out using views to configure their
|
||||
* appearance. This array contains aliases and the view names to
|
||||
* use when rendering the links.
|
||||
*
|
||||
* Within each view, the Pager object will be available as $pager,
|
||||
* and the desired group as $pagerGroup;
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'default_full' => 'CodeIgniter\Pager\Views\default_full',
|
||||
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
|
||||
'default_head' => 'CodeIgniter\Pager\Views\default_head',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Items Per Page
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The default number of results shown in a single page.
|
||||
*/
|
||||
public int $perPage = 20;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* Paths
|
||||
*
|
||||
* Holds the paths that are used by the system to
|
||||
* locate the main directories, app, system, etc.
|
||||
*
|
||||
* Modifying these allows you to restructure your application,
|
||||
* share a system folder between multiple applications, and more.
|
||||
*
|
||||
* All paths are relative to the project's root folder.
|
||||
*
|
||||
* NOTE: This class is required prior to Autoloader instantiation,
|
||||
* and does not extend BaseConfig.
|
||||
*/
|
||||
class Paths
|
||||
{
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* SYSTEM FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This must contain the name of your "system" folder. Include
|
||||
* the path if the folder is not in the same directory as this file.
|
||||
*/
|
||||
public string $systemDirectory = __DIR__ . '/../../vendor/codeigniter4/framework/system';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* APPLICATION FOLDER NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* If you want this front controller to use a different "app"
|
||||
* folder than the default one you can set its name here. The folder
|
||||
* can also be renamed or relocated anywhere on your server. If
|
||||
* you do, use a full server path.
|
||||
*
|
||||
* @see http://codeigniter.com/user_guide/general/managing_apps.html
|
||||
*/
|
||||
public string $appDirectory = __DIR__ . '/..';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* WRITABLE DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "writable" directory.
|
||||
* The writable directory allows you to group all directories that
|
||||
* need write permission to a single place that can be tucked away
|
||||
* for maximum security, keeping it out of the app and/or
|
||||
* system directories.
|
||||
*/
|
||||
public string $writableDirectory = __DIR__ . '/../../writable';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* TESTS DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of your "tests" directory.
|
||||
*/
|
||||
public string $testsDirectory = __DIR__ . '/../../tests';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* VIEW DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of the directory that
|
||||
* contains the view files used by your application. By
|
||||
* default this is in `app/Views`. This value
|
||||
* is used when no value is provided to `Services::renderer()`.
|
||||
*/
|
||||
public string $viewDirectory = __DIR__ . '/../Views';
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------
|
||||
* ENVIRONMENT DIRECTORY NAME
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* This variable must contain the name of the directory where
|
||||
* the .env file is located.
|
||||
* Please consider security implications when changing this
|
||||
* value - the directory should not be publicly accessible.
|
||||
*/
|
||||
public string $envDirectory = __DIR__ . '/../../';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Publisher as BasePublisher;
|
||||
|
||||
/**
|
||||
* Publisher Configuration
|
||||
*
|
||||
* Defines basic security restrictions for the Publisher class
|
||||
* to prevent abuse by injecting malicious files into a project.
|
||||
*/
|
||||
class Publisher extends BasePublisher
|
||||
{
|
||||
/**
|
||||
* A list of allowed destinations with a (pseudo-)regex
|
||||
* of allowed files for each destination.
|
||||
* Attempts to publish to directories not in this list will
|
||||
* result in a PublisherException. Files that do no fit the
|
||||
* pattern will cause copy/merge to fail.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public $restrictions = [
|
||||
ROOTPATH => '*',
|
||||
FCPATH => '#\.(s?css|js|map|html?|xml|json|webmanifest|ttf|eot|woff2?|gif|jpe?g|tiff?|png|webp|bmp|ico|svg)$#i',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
use CodeIgniter\Router\RouteCollection;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------------------------
|
||||
* Toolvana routing map
|
||||
* ---------------------------------------------------------------------------------------------
|
||||
*
|
||||
* URL architecture (strongest SEO structure):
|
||||
*
|
||||
* / homepage
|
||||
* /{tool-slug} every tool at the root: /youtube-to-mp3, /jpg-to-png ...
|
||||
* /tools searchable tool directory (+ /tools/category/{cat})
|
||||
* /{category-slug} category landing pages: /youtube-tools, /video-tools ...
|
||||
* /blog, /blog/{guide-slug} guides cluster
|
||||
* /search crawlable search results page
|
||||
* /privacy /terms ... legal pages
|
||||
* /sitemap*.xml, /robots.txt SEO plumbing
|
||||
* /api/v1/... public API (noindex)
|
||||
* /admin/... admin panel (denied to robots)
|
||||
*/
|
||||
|
||||
/** @var RouteCollection $routes */
|
||||
|
||||
$routes->setAutoRoute(false);
|
||||
$routes->setDefaultNamespace('App\Controllers');
|
||||
$routes->setDefaultController('Home');
|
||||
$routes->setDefaultMethod('index');
|
||||
|
||||
// 404 override -> useful "Tool not found" page with popular tools.
|
||||
$routes->set404Override(static function () {
|
||||
return (new \App\Controllers\Errors())->notFound();
|
||||
});
|
||||
|
||||
// Health probes (unfiltered, no session, no analytics).
|
||||
$routes->get('/health', 'Health::index');
|
||||
$routes->get('/ready', 'Health::ready');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// SEO plumbing
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/robots.txt', 'Seo::robots');
|
||||
$routes->get('/sitemap.xml', 'Seo::sitemapIndex');
|
||||
$routes->get('/sitemap-tools-([0-9]+).xml', 'Seo::sitemapTools/$1');
|
||||
$routes->get('/sitemap-guides.xml', 'Seo::sitemapGuides');
|
||||
$routes->get('/sitemap-categories.xml', 'Seo::sitemapCategories');
|
||||
$routes->get('/sitemap-pages.xml', 'Seo::sitemapPages');
|
||||
$routes->get('/opensearch.xml', 'Seo::openSearch');
|
||||
$routes->get('/manifest.webmanifest', 'Seo::manifest');
|
||||
$routes->get('/service-worker.js', 'Seo::serviceWorker');
|
||||
$routes->get('/og/(:segment).png', 'Seo::ogImage/$1'); // cached social cards
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Public API (internal + v1). Noindex; blocked in robots.txt.
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->group('api', ['namespace' => 'App\Controllers\Api'], static function ($routes) {
|
||||
// Browser-facing endpoints used by tool pages.
|
||||
$routes->post('jobs', 'Jobs::create');
|
||||
$routes->get('jobs/(:segment)', 'Jobs::show/$1');
|
||||
$routes->delete('jobs/(:segment)', 'Jobs::delete/$1');
|
||||
$routes->post('youtube/info', 'Youtube::info');
|
||||
$routes->post('events', 'Events::track'); // analytics beacon
|
||||
$routes->get('suggest', 'SearchApi::suggest'); // search-as-you-type
|
||||
|
||||
// Versioned developer API (token auth).
|
||||
$routes->group('v1', ['filter' => 'api-auth'], static function ($routes) {
|
||||
$routes->get('tools', 'ToolsApi::index');
|
||||
$routes->get('tools/(:segment)', 'ToolsApi::show/$1');
|
||||
$routes->post('convert', 'Jobs::create');
|
||||
$routes->get('jobs/(:segment)', 'Jobs::show/$1');
|
||||
$routes->delete('jobs/(:segment)', 'Jobs::delete/$1');
|
||||
});
|
||||
});
|
||||
|
||||
// File upload endpoint for tool pages (multipart).
|
||||
$routes->post('/upload', 'Media::upload');
|
||||
$routes->post('/jobs/start', 'Media::startJob');
|
||||
// Result download endpoint — temporary, never indexed.
|
||||
$routes->get('/download/(:segment)', 'Media::download/$1');
|
||||
$routes->get('/preview/(:segment).(:segment)', 'Media::preview/$1/$2');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Static / legal pages
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/privacy', 'Pages::privacy');
|
||||
$routes->get('/terms', 'Pages::terms');
|
||||
$routes->get('/cookies', 'Pages::cookies');
|
||||
$routes->get('/dmca', 'Pages::dmca');
|
||||
$routes->get('/contact', 'Pages::contact');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Search & directory
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/search', 'Search::index');
|
||||
$routes->get('/tools', 'Directory::index');
|
||||
$routes->get('/tools/popular', 'Directory::popular');
|
||||
$routes->get('/tools/recent', 'Directory::recent');
|
||||
$routes->get('/tools/a-z', 'Directory::az');
|
||||
$routes->get('/tools/category/(:segment)', 'Directory::category/$1');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Guides cluster
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/blog', 'Guides::index');
|
||||
$routes->get('/blog/rss.xml', 'Guides::rss');
|
||||
$routes->get('/blog/(:segment)', 'Guides::show/$1');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Category landing pages: /youtube-tools, /video-tools, ...
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/([a-z0-9]+-tools)', 'Categories::show/$1');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Admin panel (session auth, CSRF protected, noindex)
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'admin-auth'], static function ($routes) {
|
||||
$routes->get('/', 'Dashboard::index');
|
||||
$routes->get('login', 'Auth::loginForm');
|
||||
$routes->post('login', 'Auth::attempt');
|
||||
$routes->get('logout', 'Auth::logout');
|
||||
|
||||
$routes->get('tools', 'ToolsAdmin::index');
|
||||
$routes->get('tools/new', 'ToolsAdmin::create');
|
||||
$routes->post('tools', 'ToolsAdmin::store');
|
||||
$routes->get('tools/(:num)/edit', 'ToolsAdmin::edit/$1');
|
||||
$routes->post('tools/(:num)', 'ToolsAdmin::update/$1');
|
||||
$routes->post('tools/(:num)/delete', 'ToolsAdmin::delete/$1');
|
||||
|
||||
$routes->get('categories', 'CategoriesAdmin::index');
|
||||
$routes->post('categories', 'CategoriesAdmin::store');
|
||||
$routes->get('categories/(:num)/edit', 'CategoriesAdmin::edit/$1');
|
||||
$routes->post('categories/(:num)', 'CategoriesAdmin::update/$1');
|
||||
|
||||
$routes->get('guides', 'GuidesAdmin::index');
|
||||
$routes->get('guides/new', 'GuidesAdmin::create');
|
||||
$routes->post('guides', 'GuidesAdmin::store');
|
||||
$routes->get('guides/(:num)/edit', 'GuidesAdmin::edit/$1');
|
||||
$routes->post('guides/(:num)', 'GuidesAdmin::update/$1');
|
||||
$routes->post('guides/(:num)/delete', 'GuidesAdmin::delete/$1');
|
||||
|
||||
$routes->get('seo', 'SeoAdmin::index');
|
||||
$routes->get('analytics', 'AnalyticsAdmin::index');
|
||||
$routes->get('jobs', 'JobsAdmin::index');
|
||||
$routes->post('jobs/(:segment)/retry', 'JobsAdmin::retry/$1');
|
||||
$routes->get('system', 'SystemAdmin::index');
|
||||
$routes->get('settings', 'SettingsAdmin::index');
|
||||
$routes->post('settings', 'SettingsAdmin::save');
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Homepage last but one...
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/', 'Home::index');
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// ...and the catch-all: every active tool slug lives at the root.
|
||||
// Registered last so concrete routes always win. Uppercase and
|
||||
// trailing-slash variants are canonicalized by the SeoFilter.
|
||||
// ---------------------------------------------------------------------
|
||||
$routes->get('/([a-z0-9-]+)', 'Tools::show/$1');
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of CodeIgniter 4 framework.
|
||||
*
|
||||
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\Routing as BaseRouting;
|
||||
|
||||
/**
|
||||
* Routing configuration
|
||||
*/
|
||||
class Routing extends BaseRouting
|
||||
{
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* An array of files that contain route definitions.
|
||||
* Route files are read in order, with the first match
|
||||
* found taking precedence.
|
||||
*
|
||||
* Default: APPPATH . 'Config/Routes.php'
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $routeFiles = [
|
||||
APPPATH . 'Config/Routes.php',
|
||||
];
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default namespace to use for Controllers when no other
|
||||
* namespace has been specified.
|
||||
*
|
||||
* Default: 'App\Controllers'
|
||||
*/
|
||||
public string $defaultNamespace = 'App\Controllers';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* The default controller to use when no other controller has been
|
||||
* specified.
|
||||
*
|
||||
* Default: 'Home'
|
||||
*/
|
||||
public string $defaultController = 'Home';
|
||||
|
||||
/**
|
||||
* For Defined Routes and Auto Routing.
|
||||
* The default method to call on the controller when no other
|
||||
* method has been set in the route.
|
||||
*
|
||||
* Default: 'index'
|
||||
*/
|
||||
public string $defaultMethod = 'index';
|
||||
|
||||
/**
|
||||
* For Auto Routing.
|
||||
* Whether to translate dashes in URIs for controller/method to underscores.
|
||||
* Primarily useful when using the auto-routing.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateURIDashes = false;
|
||||
|
||||
/**
|
||||
* Sets the class/method that should be called if routing doesn't
|
||||
* find a match. It can be the controller/method name like: Users::index
|
||||
*
|
||||
* This setting is passed to the Router class and handled there.
|
||||
*
|
||||
* If you want to use a closure, you will have to set it in the
|
||||
* routes file by calling:
|
||||
*
|
||||
* $routes->set404Override(function() {
|
||||
* // Do something here
|
||||
* });
|
||||
*
|
||||
* Example:
|
||||
* public $override404 = 'App\Errors::show404';
|
||||
*/
|
||||
public ?string $override404 = null;
|
||||
|
||||
/**
|
||||
* If TRUE, the system will attempt to match the URI against
|
||||
* Controllers by matching each segment against folders/files
|
||||
* in APPPATH/Controllers, when a match wasn't found against
|
||||
* defined routes.
|
||||
*
|
||||
* If FALSE, will stop searching and do NO automatic routing.
|
||||
*/
|
||||
public bool $autoRoute = false;
|
||||
|
||||
/**
|
||||
* If TRUE, the system will look for attributes on controller
|
||||
* class and methods that can run before and after the
|
||||
* controller/method.
|
||||
*
|
||||
* If FALSE, will ignore any attributes.
|
||||
*/
|
||||
public bool $useControllerAttributes = true;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, will enable the use of the 'prioritize' option
|
||||
* when defining routes.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $prioritize = false;
|
||||
|
||||
/**
|
||||
* For Defined Routes.
|
||||
* If TRUE, matched multiple URI segments will be passed as one parameter.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $multipleSegmentsOneParam = false;
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Map of URI segments and namespaces.
|
||||
*
|
||||
* The key is the first URI segment. The value is the controller namespace.
|
||||
* E.g.,
|
||||
* [
|
||||
* 'blog' => 'Acme\Blog\Controllers',
|
||||
* ]
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $moduleRoutes = [];
|
||||
|
||||
/**
|
||||
* For Auto Routing (Improved).
|
||||
* Whether to translate dashes in URIs for controller/method to CamelCase.
|
||||
* E.g., blog-controller -> BlogController
|
||||
*
|
||||
* If you enable this, $translateURIDashes is ignored.
|
||||
*
|
||||
* Default: false
|
||||
*/
|
||||
public bool $translateUriToCamelCase = true;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
class Security extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Protection Method
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Protection Method for Cross Site Request Forgery protection.
|
||||
*
|
||||
* @var string 'cookie' or 'session'
|
||||
*/
|
||||
public string $csrfProtection = 'cookie';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Randomization
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Randomize the CSRF Token for added security.
|
||||
*/
|
||||
public bool $tokenRandomize = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Token Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Token name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $tokenName = 'csrf_test_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Header Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Header name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $headerName = 'X-CSRF-TOKEN';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Cookie name for Cross Site Request Forgery protection.
|
||||
*/
|
||||
public string $cookieName = 'csrf_cookie_name';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Expires
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Expiration time for Cross Site Request Forgery protection cookie.
|
||||
*
|
||||
* Defaults to two hours (in seconds).
|
||||
*/
|
||||
public int $expires = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Regenerate
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Regenerate CSRF Token on every submission.
|
||||
*/
|
||||
public bool $regenerate = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* CSRF Redirect
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Redirect to previous page with error on failure.
|
||||
*
|
||||
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
|
||||
*/
|
||||
public bool $redirect = (ENVIRONMENT === 'production');
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use App\Libraries\Analytics;
|
||||
use App\Libraries\Finder;
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Libraries\RelatedTools;
|
||||
use App\Libraries\Seo;
|
||||
use App\Libraries\ToolSearch;
|
||||
use CodeIgniter\Config\BaseService;
|
||||
|
||||
/**
|
||||
* Application-specific services. Each is swappable: swap the class behind
|
||||
* the accessor and nothing else in the app changes.
|
||||
*/
|
||||
class Services extends BaseService
|
||||
{
|
||||
/**
|
||||
* Tool registry & lookup (DB-backed, request-cached).
|
||||
*/
|
||||
public static function finder(bool $getShared = true): Finder
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('finder');
|
||||
}
|
||||
|
||||
return new Finder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Related-tools recommendation engine.
|
||||
*/
|
||||
public static function relatedTools(bool $getShared = true): RelatedTools
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('relatedTools');
|
||||
}
|
||||
|
||||
return new RelatedTools();
|
||||
}
|
||||
|
||||
/**
|
||||
* SEO metadata / structured data builder.
|
||||
*/
|
||||
public static function seo(bool $getShared = true): Seo
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('seo');
|
||||
}
|
||||
|
||||
return new Seo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Media processing pipeline (queue + drivers).
|
||||
*/
|
||||
public static function pipeline(bool $getShared = true): Pipeline
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('pipeline');
|
||||
}
|
||||
|
||||
return new Pipeline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymous event analytics.
|
||||
*/
|
||||
public static function analytics(bool $getShared = true): Analytics
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('analytics');
|
||||
}
|
||||
|
||||
return new Analytics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global tool search with alias support.
|
||||
*/
|
||||
public static function toolSearch(bool $getShared = true): ToolSearch
|
||||
{
|
||||
if ($getShared) {
|
||||
return static::getSharedInstance('toolSearch');
|
||||
}
|
||||
|
||||
return new ToolSearch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Session\Handlers\BaseHandler;
|
||||
use CodeIgniter\Session\Handlers\FileHandler;
|
||||
|
||||
class Session extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Driver
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session storage driver to use:
|
||||
* - `CodeIgniter\Session\Handlers\ArrayHandler` (for testing)
|
||||
* - `CodeIgniter\Session\Handlers\FileHandler`
|
||||
* - `CodeIgniter\Session\Handlers\DatabaseHandler`
|
||||
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
|
||||
* - `CodeIgniter\Session\Handlers\RedisHandler`
|
||||
*
|
||||
* @var class-string<BaseHandler>
|
||||
*/
|
||||
public string $driver = FileHandler::class;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Cookie Name
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The session cookie name, must contain only [0-9a-z_-] characters
|
||||
*/
|
||||
public string $cookieName = 'ci_session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Expiration
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The number of SECONDS you want the session to last.
|
||||
* Setting to 0 (zero) means expire when the browser is closed.
|
||||
*/
|
||||
public int $expiration = 7200;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Save Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The location to save sessions to and is driver dependent.
|
||||
*
|
||||
* For the 'files' driver, it's a path to a writable directory.
|
||||
* WARNING: Only absolute paths are supported!
|
||||
*
|
||||
* For the 'database' driver, it's a table name.
|
||||
* Please read up the manual for the format with other session drivers.
|
||||
*
|
||||
* IMPORTANT: You are REQUIRED to set a valid save path!
|
||||
*/
|
||||
public string $savePath = WRITEPATH . 'session';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Match IP
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to match the user's IP address when reading the session data.
|
||||
*
|
||||
* WARNING: If you're using the database driver, don't forget to update
|
||||
* your session table's PRIMARY KEY when changing this setting.
|
||||
*/
|
||||
public bool $matchIP = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Time to Update
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* How many seconds between CI regenerating the session ID.
|
||||
*/
|
||||
public int $timeToUpdate = 300;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Regenerate Destroy
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Whether to destroy session data associated with the old session ID
|
||||
* when auto-regenerating the session ID. When set to FALSE, the data
|
||||
* will be later deleted by the garbage collector.
|
||||
*/
|
||||
public bool $regenerateDestroy = false;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Session Database Group
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* DB Group for the database session.
|
||||
*/
|
||||
public ?string $DBGroup = null;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Retry Interval (microseconds)
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Time (microseconds) to wait if lock cannot be acquired.
|
||||
* The default is 100,000 microseconds (= 0.1 seconds).
|
||||
*/
|
||||
public int $lockRetryInterval = 100_000;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Max Retries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Maximum number of lock acquisition attempts.
|
||||
* The default is 300 times. That is lock timeout is about 30 (0.1 * 300)
|
||||
* seconds.
|
||||
*/
|
||||
public int $lockMaxRetries = 300;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Site-wide configuration for Toolvana.
|
||||
*
|
||||
* Everything an operator is likely to tune lives here or in .env
|
||||
* (values in .env override these defaults via the standard
|
||||
* `site.*` namespace).
|
||||
*/
|
||||
class Site extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Brand / identity
|
||||
* -----------------------------------------------------------------
|
||||
*/
|
||||
public string $name = 'Toolvana';
|
||||
public string $tagline = 'Your free online media toolbox.';
|
||||
public string $description = 'Fast, simple and free tools for downloading, converting, compressing and editing media online.';
|
||||
public string $twitter = '@toolvana';
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Internationalization architecture.
|
||||
*
|
||||
* English is the primary (default, un-prefixed) locale. Additional
|
||||
* locales are only enabled once real localized content exists — the
|
||||
* routes layer already supports `{locale}` URL segments and the SEO
|
||||
* library emits hreflang/canonical tags for every enabled locale.
|
||||
* Never enable a locale whose content has not been human-reviewed.
|
||||
*/
|
||||
public string $defaultLocale = 'en';
|
||||
|
||||
/** @var array<string,string> locale => native label */
|
||||
public array $locales = [
|
||||
'en' => 'English',
|
||||
];
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Media processing limits & retention
|
||||
* -----------------------------------------------------------------
|
||||
*/
|
||||
public int $maxUploadMb = 512;
|
||||
public int $maxJobsPerHourIp = 20;
|
||||
public int $maxJobsPerHourSession = 40;
|
||||
public int $maxConcurrentSession = 2;
|
||||
public int $retentionHours = 2;
|
||||
public int $maxProcessingSeconds = 900;
|
||||
public int $queueMaxLength = 500;
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Binary locations. The pipeline refuses to enqueue jobs that need a
|
||||
* missing binary and the tool page shows an honest "temporarily
|
||||
* unavailable" state instead of failing after upload.
|
||||
*/
|
||||
public array $binaries = [
|
||||
'ffmpeg' => '/usr/bin/ffmpeg',
|
||||
'ffprobe' => '/usr/bin/ffprobe',
|
||||
'convert' => '/usr/bin/convert',
|
||||
'pdftoppm' => '/usr/bin/pdftoppm',
|
||||
'pdftotext' => '/usr/bin/pdftotext',
|
||||
'qpdf' => '/usr/bin/qpdf',
|
||||
'gs' => '/usr/bin/gs',
|
||||
'yt-dlp' => '/usr/local/bin/yt-dlp',
|
||||
];
|
||||
|
||||
/**
|
||||
* Downloading from YouTube requires yt-dlp AND explicit operator opt-in,
|
||||
* both for legal review and because platform terms evolve. When off,
|
||||
* affected tools render a clear notice and every other tool keeps
|
||||
* working. Thumbnail/metadata/embed tools never require it.
|
||||
*/
|
||||
public bool $ytDlpEnabled = false;
|
||||
|
||||
/** Extra hosts allowed for direct media URL fetches (SSRF allowlist). */
|
||||
public array $urlFetchAllowlist = [
|
||||
'i.ytimg.com', 'img.youtube.com', 'yt3.ggpht.com',
|
||||
];
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Monetization (kept modular; disabled by default)
|
||||
* -----------------------------------------------------------------
|
||||
*/
|
||||
public bool $adsEnabled = false;
|
||||
|
||||
/** @var array<string,string> placement => snippet (loaded by view) */
|
||||
public array $adSlots = [];
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------
|
||||
* Analytics beacon sampling: 100 = record every event.
|
||||
*/
|
||||
public int $analyticsSampleRate = 100;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Database;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Events;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Files;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Logs;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Routes;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Timers;
|
||||
use CodeIgniter\Debug\Toolbar\Collectors\Views;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Debug Toolbar
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The Debug Toolbar provides a way to see information about the performance
|
||||
* and state of your application during that page display. By default it will
|
||||
* NOT be displayed under production environments, and will only display if
|
||||
* `CI_DEBUG` is true, since if it's not, there's not much to display anyway.
|
||||
*/
|
||||
class Toolbar extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Collectors
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* List of toolbar collectors that will be called when Debug Toolbar
|
||||
* fires up and collects data from.
|
||||
*
|
||||
* @var list<class-string>
|
||||
*/
|
||||
public array $collectors = [
|
||||
Timers::class,
|
||||
Database::class,
|
||||
Logs::class,
|
||||
Views::class,
|
||||
// \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
|
||||
Files::class,
|
||||
Routes::class,
|
||||
Events::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Collect Var Data
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If set to false var data from the views will not be collected. Useful to
|
||||
* avoid high memory usage when there are lots of data passed to the view.
|
||||
*/
|
||||
public bool $collectVarData = true;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max History
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* `$maxHistory` sets a limit on the number of past requests that are stored,
|
||||
* helping to conserve file space used to store them. You can set it to
|
||||
* 0 (zero) to not have any history stored, or -1 for unlimited history.
|
||||
*/
|
||||
public int $maxHistory = 20;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Toolbar Views Path
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* The full path to the the views that are used by the toolbar.
|
||||
* This MUST have a trailing slash.
|
||||
*/
|
||||
public string $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/';
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Max Queries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* If the Database Collector is enabled, it will log every query that the
|
||||
* the system generates so they can be displayed on the toolbar's timeline
|
||||
* and in the query log. This can lead to memory issues in some instances
|
||||
* with hundreds of queries.
|
||||
*
|
||||
* `$maxQueries` defines the maximum amount of queries that will be stored.
|
||||
*/
|
||||
public int $maxQueries = 100;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched Directories
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of directories that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
* We restrict the values to keep performance as high as possible.
|
||||
*
|
||||
* NOTE: The ROOTPATH will be prepended to all values.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedDirectories = [
|
||||
'app',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Watched File Extensions
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Contains an array of file extensions that will be watched for changes and
|
||||
* used to determine if the hot-reload feature should reload the page or not.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $watchedExtensions = [
|
||||
'php', 'css', 'js', 'html', 'svg', 'json', 'env',
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Ignored HTTP Headers
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* CodeIgniter Debug Toolbar normally injects HTML and JavaScript into every
|
||||
* HTML response. This is correct for full page loads, but it breaks requests
|
||||
* that expect only a clean HTML fragment.
|
||||
*
|
||||
* Libraries like HTMX, Unpoly, and Hotwire (Turbo) update parts of the page or
|
||||
* manage navigation on the client side. Injecting the Debug Toolbar into their
|
||||
* responses can cause invalid HTML, duplicated scripts, or JavaScript errors
|
||||
* (such as infinite loops or "Maximum call stack size exceeded").
|
||||
*
|
||||
* Any request containing one of the following headers is treated as a
|
||||
* client-managed or partial request, and the Debug Toolbar injection is skipped.
|
||||
*
|
||||
* @var array<string, string|null>
|
||||
*/
|
||||
public array $disableOnHeaders = [
|
||||
'X-Requested-With' => 'xmlhttprequest', // AJAX requests
|
||||
'HX-Request' => 'true', // HTMX requests
|
||||
'X-Up-Version' => null, // Unpoly partial requests
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* User Agents
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* This file contains four arrays of user agent data. It is used by the
|
||||
* User Agent Class to help identify browser, platform, robot, and
|
||||
* mobile device data. The array keys are used to identify the device
|
||||
* and the array values are used to set the actual name of the item.
|
||||
*/
|
||||
class UserAgents extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* OS Platforms
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $platforms = [
|
||||
'windows nt 10.0' => 'Windows 10',
|
||||
'windows nt 6.3' => 'Windows 8.1',
|
||||
'windows nt 6.2' => 'Windows 8',
|
||||
'windows nt 6.1' => 'Windows 7',
|
||||
'windows nt 6.0' => 'Windows Vista',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows phone' => 'Windows Phone',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'android' => 'Android',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'iphone' => 'iOS',
|
||||
'ipad' => 'iOS',
|
||||
'ipod' => 'iOS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS',
|
||||
'symbian' => 'Symbian OS',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Browsers
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* The order of this array should NOT be changed. Many browsers return
|
||||
* multiple browser types so we want to identify the subtype first.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $browsers = [
|
||||
'OPR' => 'Opera',
|
||||
'Flock' => 'Flock',
|
||||
'Edge' => 'Spartan',
|
||||
'Edg' => 'Edge',
|
||||
'Chrome' => 'Chrome',
|
||||
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||
'Opera.*?Version' => 'Opera',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Trident.* rv' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse',
|
||||
'Maxthon' => 'Maxthon',
|
||||
'Ubuntu' => 'Ubuntu Web Browser',
|
||||
'Vivaldi' => 'Vivaldi',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Mobiles
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $mobiles = [
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => 'Motorola',
|
||||
'nokia' => 'Nokia',
|
||||
'palm' => 'Palm',
|
||||
'iphone' => 'Apple iPhone',
|
||||
'ipad' => 'iPad',
|
||||
'ipod' => 'Apple iPod Touch',
|
||||
'sony' => 'Sony Ericsson',
|
||||
'ericsson' => 'Sony Ericsson',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'cocoon' => 'O2 Cocoon',
|
||||
'blazer' => 'Treo',
|
||||
'lg' => 'LG',
|
||||
'amoi' => 'Amoi',
|
||||
'xda' => 'XDA',
|
||||
'mda' => 'MDA',
|
||||
'vario' => 'Vario',
|
||||
'htc' => 'HTC',
|
||||
'samsung' => 'Samsung',
|
||||
'sharp' => 'Sharp',
|
||||
'sie-' => 'Siemens',
|
||||
'alcatel' => 'Alcatel',
|
||||
'benq' => 'BenQ',
|
||||
'ipaq' => 'HP iPaq',
|
||||
'mot-' => 'Motorola',
|
||||
'playstation portable' => 'PlayStation Portable',
|
||||
'playstation 3' => 'PlayStation 3',
|
||||
'playstation vita' => 'PlayStation Vita',
|
||||
'hiptop' => 'Danger Hiptop',
|
||||
'nec-' => 'NEC',
|
||||
'panasonic' => 'Panasonic',
|
||||
'philips' => 'Philips',
|
||||
'sagem' => 'Sagem',
|
||||
'sanyo' => 'Sanyo',
|
||||
'spv' => 'SPV',
|
||||
'zte' => 'ZTE',
|
||||
'sendo' => 'Sendo',
|
||||
'nintendo dsi' => 'Nintendo DSi',
|
||||
'nintendo ds' => 'Nintendo DS',
|
||||
'nintendo 3ds' => 'Nintendo 3DS',
|
||||
'wii' => 'Nintendo Wii',
|
||||
'open web' => 'Open Web',
|
||||
'openweb' => 'OpenWeb',
|
||||
|
||||
// Operating Systems
|
||||
'android' => 'Android',
|
||||
'symbian' => 'Symbian',
|
||||
'SymbianOS' => 'SymbianOS',
|
||||
'elaine' => 'Palm',
|
||||
'series60' => 'Symbian S60',
|
||||
'windows ce' => 'Windows CE',
|
||||
|
||||
// Browsers
|
||||
'obigo' => 'Obigo',
|
||||
'netfront' => 'Netfront Browser',
|
||||
'openwave' => 'Openwave Browser',
|
||||
'mobilexplorer' => 'Mobile Explorer',
|
||||
'operamini' => 'Opera Mini',
|
||||
'opera mini' => 'Opera Mini',
|
||||
'opera mobi' => 'Opera Mobile',
|
||||
'fennec' => 'Firefox Mobile',
|
||||
|
||||
// Other
|
||||
'digital paths' => 'Digital Paths',
|
||||
'avantgo' => 'AvantGo',
|
||||
'xiino' => 'Xiino',
|
||||
'novarra' => 'Novarra Transcoder',
|
||||
'vodafone' => 'Vodafone',
|
||||
'docomo' => 'NTT DoCoMo',
|
||||
'o2' => 'O2',
|
||||
|
||||
// Fallback
|
||||
'mobile' => 'Generic Mobile',
|
||||
'wireless' => 'Generic Mobile',
|
||||
'j2me' => 'Generic Mobile',
|
||||
'midp' => 'Generic Mobile',
|
||||
'cldc' => 'Generic Mobile',
|
||||
'up.link' => 'Generic Mobile',
|
||||
'up.browser' => 'Generic Mobile',
|
||||
'smartphone' => 'Generic Mobile',
|
||||
'cellphone' => 'Generic Mobile',
|
||||
];
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------
|
||||
* Robots
|
||||
* -------------------------------------------------------------------
|
||||
*
|
||||
* There are hundred of bots but these are the most common.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $robots = [
|
||||
'googlebot' => 'Googlebot',
|
||||
'google-pagerenderer' => 'Google Page Renderer',
|
||||
'google-read-aloud' => 'Google Read Aloud',
|
||||
'google-safety' => 'Google Safety Bot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'baiduspider' => 'Baiduspider',
|
||||
'bingbot' => 'Bing',
|
||||
'bingpreview' => 'BingPreview',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'ask jeeves' => 'Ask Jeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos',
|
||||
'yandex' => 'YandexBot',
|
||||
'mediapartners-google' => 'MediaPartners Google',
|
||||
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||
'adsbot-google' => 'AdsBot Google',
|
||||
'feedfetcher-google' => 'Feedfetcher Google',
|
||||
'curious george' => 'Curious George',
|
||||
'ia_archiver' => 'Alexa Crawler',
|
||||
'MJ12bot' => 'Majestic-12',
|
||||
'Uptimebot' => 'Uptimebot',
|
||||
'duckduckbot' => 'DuckDuckBot',
|
||||
'sogou' => 'Sogou Spider',
|
||||
'exabot' => 'Exabot',
|
||||
'bot' => 'Generic Bot',
|
||||
'crawler' => 'Generic Crawler',
|
||||
'spider' => 'Generic Spider',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
use CodeIgniter\Validation\StrictRules\CreditCardRules;
|
||||
use CodeIgniter\Validation\StrictRules\FileRules;
|
||||
use CodeIgniter\Validation\StrictRules\FormatRules;
|
||||
use CodeIgniter\Validation\StrictRules\Rules;
|
||||
|
||||
class Validation extends BaseConfig
|
||||
{
|
||||
// --------------------------------------------------------------------
|
||||
// Setup
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stores the classes that contain the
|
||||
* rules that are available.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $ruleSets = [
|
||||
Rules::class,
|
||||
FormatRules::class,
|
||||
FileRules::class,
|
||||
CreditCardRules::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Specifies the views that are used to display the
|
||||
* errors.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public array $templates = [
|
||||
'list' => 'CodeIgniter\Validation\Views\list',
|
||||
'single' => 'CodeIgniter\Validation\Views\single',
|
||||
];
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Rules
|
||||
// --------------------------------------------------------------------
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use CodeIgniter\Config\View as BaseView;
|
||||
use CodeIgniter\View\ViewDecoratorInterface;
|
||||
|
||||
class View extends BaseView
|
||||
{
|
||||
/**
|
||||
* When false, the view method will clear the data between each
|
||||
* call. This keeps your data safe and ensures there is no accidental
|
||||
* leaking between calls, so you would need to explicitly pass the data
|
||||
* to each view. You might prefer to have the data stick around between
|
||||
* calls so that it is available to all views. If that is the case,
|
||||
* set $saveData to true.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $saveData = true;
|
||||
|
||||
/**
|
||||
* Parser Filters map a filter name with any PHP callable. When the
|
||||
* Parser prepares a variable for display, it will chain it
|
||||
* through the filters in the order defined, inserting any parameters.
|
||||
* To prevent potential abuse, all filters MUST be defined here
|
||||
* in order for them to be available for use within the Parser.
|
||||
*
|
||||
* Examples:
|
||||
* { title|esc(js) }
|
||||
* { created_on|date(Y-m-d)|esc(attr) }
|
||||
*
|
||||
* @var array<string, (callable(mixed): mixed)&string>
|
||||
*/
|
||||
public $filters = [];
|
||||
|
||||
/**
|
||||
* Parser Plugins provide a way to extend the functionality provided
|
||||
* by the core Parser by creating aliases that will be replaced with
|
||||
* any callable. Can be single or tag pair.
|
||||
*
|
||||
* @var array<string, (callable(mixed...): mixed)|((callable(mixed...): mixed)&string)|list<(callable(mixed...): mixed)&string>>
|
||||
*/
|
||||
public $plugins = [];
|
||||
|
||||
/**
|
||||
* View Decorators are class methods that will be run in sequence to
|
||||
* have a chance to alter the generated output just prior to caching
|
||||
* the results.
|
||||
*
|
||||
* All classes must implement CodeIgniter\View\ViewDecoratorInterface
|
||||
*
|
||||
* @var list<class-string<ViewDecoratorInterface>>
|
||||
*/
|
||||
public array $decorators = [];
|
||||
|
||||
/**
|
||||
* Subdirectory within app/Views for namespaced view overrides.
|
||||
*
|
||||
* Namespaced views will be searched in:
|
||||
*
|
||||
* app/Views/{$appOverridesFolder}/{Namespace}/{view_path}.{php|html...}
|
||||
*
|
||||
* This allows application-level overrides for package or module views
|
||||
* without modifying vendor source files.
|
||||
*
|
||||
* Examples:
|
||||
* 'overrides' -> app/Views/overrides/Example/Blog/post/card.php
|
||||
* 'vendor' -> app/Views/vendor/Example/Blog/post/card.php
|
||||
* '' -> app/Views/Example/Blog/post/card.php (direct mapping)
|
||||
*/
|
||||
public string $appOverridesFolder = 'overrides';
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
/**
|
||||
* This configuration controls how CodeIgniter behaves when running
|
||||
* in worker mode (with FrankenPHP).
|
||||
*/
|
||||
class WorkerMode
|
||||
{
|
||||
/**
|
||||
* Persistent Services
|
||||
*
|
||||
* List of service names that should persist across requests.
|
||||
* These services will NOT be reset between requests.
|
||||
*
|
||||
* Services not in this list will be reset for each request to prevent
|
||||
* state leakage.
|
||||
*
|
||||
* Recommended persistent services:
|
||||
* - `autoloader`: PSR-4 autoloading configuration
|
||||
* - `locator`: File locator
|
||||
* - `exceptions`: Exception handler
|
||||
* - `commands`: CLI commands registry
|
||||
* - `codeigniter`: Main application instance
|
||||
* - `superglobals`: Superglobals wrapper
|
||||
* - `routes`: Router configuration
|
||||
* - `cache`: Cache instance
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $persistentServices = [
|
||||
'autoloader',
|
||||
'locator',
|
||||
'exceptions',
|
||||
'commands',
|
||||
'codeigniter',
|
||||
'superglobals',
|
||||
'routes',
|
||||
'cache',
|
||||
];
|
||||
|
||||
/**
|
||||
* Reset Event Listeners
|
||||
*
|
||||
* List of event names whose listeners should be removed between requests.
|
||||
* Use this if you register event listeners inside other event callbacks
|
||||
* (rather than at the top level of Config/Events.php), which would cause
|
||||
* them to accumulate across requests in worker mode.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $resetEventListeners = [];
|
||||
|
||||
/**
|
||||
* Force Garbage Collection
|
||||
*
|
||||
* Whether to force garbage collection after each request.
|
||||
* Helps prevent memory leaks at a small performance cost.
|
||||
*/
|
||||
public bool $forceGarbageCollection = true;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\CatalogBuilder;
|
||||
use App\Models\CategoryModel;
|
||||
use App\Models\GuideModel;
|
||||
use App\Models\ToolModel;
|
||||
|
||||
/**
|
||||
* Admin base: shared layout rendering + nav context.
|
||||
* All children sit behind the admin-auth filter.
|
||||
*/
|
||||
abstract class AdminBase extends BaseController
|
||||
{
|
||||
protected function render(string $view, array $data = []): string
|
||||
{
|
||||
$data['viewContent'] = view('admin/' . $view, $data);
|
||||
|
||||
return view('layout', ['seo' => $this->seo] + $data);
|
||||
}
|
||||
|
||||
/** Shared tool-form field list. */
|
||||
protected function toolFields(): array
|
||||
{
|
||||
return [
|
||||
'slug', 'name', 'short_description', 'description', 'icon',
|
||||
'seo_title', 'seo_description', 'h1', 'intro', 'popularity', 'status',
|
||||
];
|
||||
}
|
||||
|
||||
/** Build a registry row from POST for admin-created tools. */
|
||||
protected function toolFromInput(array $post, int $categoryId): array
|
||||
{
|
||||
// reuse the builder's content generator so admin-created tools get
|
||||
// complete SEO fields even when left blank
|
||||
$generated = null;
|
||||
if (! empty($post['format_in']) && ! empty($post['format_out'])) {
|
||||
foreach (CatalogBuilder::build() as $candidate) {
|
||||
if ($candidate['slug'] === strtolower($post['format_in']) . '-to-' . strtolower($post['format_out'])) {
|
||||
$generated = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'category_id' => $categoryId,
|
||||
'kind' => $post['kind'] ?? ($generated['kind'] ?? 'upload'),
|
||||
'operation' => $post['operation'] ?? ($generated['operation'] ?? 'convert'),
|
||||
'slug' => $post['slug'] ?? ($generated['slug'] ?? ''),
|
||||
'name' => $post['name'],
|
||||
'short_description' => $post['short_description'] ?? '',
|
||||
'description' => $post['description'] ?? null,
|
||||
'input_formats' => json_encode($generated['input_formats'] ?? []),
|
||||
'output_formats' => json_encode($generated['output_formats'] ?? []),
|
||||
'primary_input_format' => $post['format_in'] ?? ($generated['primary_input_format'] ?? null),
|
||||
'primary_output_format' => $post['format_out'] ?? ($generated['primary_output_format'] ?? null),
|
||||
'icon' => $post['icon'] ?? 'file',
|
||||
'seo_title' => $post['seo_title'] ?: ($generated['seo_title'] ?? ($post['name'] . ' – Free Online Tool')),
|
||||
'seo_description' => $post['seo_description'] ?: mb_substr((string) ($post['short_description'] ?? ''), 0, 300),
|
||||
'h1' => $post['h1'] ?: $post['name'],
|
||||
'intro' => $post['intro'] ?: ($generated['intro'] ?? null),
|
||||
'how_to' => json_encode($generated['how_to'] ?? []),
|
||||
'faqs' => json_encode($generated['faqs'] ?? []),
|
||||
'related_slugs' => json_encode([]),
|
||||
'aliases' => json_encode(array_filter(array_map('trim', explode(',', (string) ($post['aliases'] ?? ''))))),
|
||||
'requires_binaries' => json_encode($generated['requires_binaries'] ?? []),
|
||||
'accepts_mimes' => json_encode($generated['accepts_mimes'] ?? []),
|
||||
'popularity' => (int) ($post['popularity'] ?? 1000),
|
||||
'status' => in_array(($post['status'] ?? ''), ['active', 'draft', 'inactive'], true) ? $post['status'] : 'active',
|
||||
];
|
||||
}
|
||||
|
||||
protected function categories(): array
|
||||
{
|
||||
return model(CategoryModel::class)->findAll();
|
||||
}
|
||||
|
||||
protected function toolsModel(): ToolModel
|
||||
{
|
||||
return model(ToolModel::class);
|
||||
}
|
||||
|
||||
protected function guidesModel(): GuideModel
|
||||
{
|
||||
return model(GuideModel::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Models\AnalyticsEventModel;
|
||||
|
||||
/** Traffic & conversion analytics dashboard (anonymous events only). */
|
||||
final class AnalyticsAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$events = model(AnalyticsEventModel::class);
|
||||
|
||||
$topTools = $events->topTools(7, 15);
|
||||
foreach ($topTools as &$row) {
|
||||
$starts = (int) ($row['starts'] ?? 0);
|
||||
$successes = (int) ($row['successes'] ?? 0);
|
||||
$failures = (int) ($row['failures'] ?? 0);
|
||||
$finished = $successes + $failures;
|
||||
$row['success_rate'] = $finished > 0 ? (int) round($successes * 100 / $finished) : null;
|
||||
unset($row);
|
||||
}
|
||||
|
||||
return $this->render('analytics_index', [
|
||||
'counts' => $events->countsSince(1),
|
||||
'week' => $events->countsSince(7),
|
||||
'topTools' => $topTools,
|
||||
'formats' => $events->topFormats(7),
|
||||
'searches' => $events->recentSearches(15),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Admin authentication: single operator password (bcrypt) from .env.
|
||||
*/
|
||||
final class Auth extends BaseController
|
||||
{
|
||||
public function loginForm(): string
|
||||
{
|
||||
return $this->render('admin/login', ['error' => session()->getFlashdata('login_error')]);
|
||||
}
|
||||
|
||||
public function attempt(): ResponseInterface
|
||||
{
|
||||
$password = (string) $this->request->getPost('password');
|
||||
$hash = (string) env('site.adminPassword', '');
|
||||
|
||||
if ($password === '' || ! password_verify($password, $hash)) {
|
||||
sleep(1); // brute-force damping
|
||||
session()->setFlashdata('login_error', 'Incorrect password.');
|
||||
service('analytics')->track('error', ['meta' => ['scope' => 'admin_login_failed']]);
|
||||
|
||||
return redirect()->to('/admin/login')->withInput();
|
||||
}
|
||||
|
||||
// rehash if algorithm cost changed
|
||||
if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
|
||||
}
|
||||
|
||||
session()->set(['tv_admin_ok' => true, 'tv_admin_at' => time()]);
|
||||
|
||||
return redirect()->to('/admin');
|
||||
}
|
||||
|
||||
public function logout(): ResponseInterface
|
||||
{
|
||||
session()->remove('tv_admin_ok');
|
||||
|
||||
return redirect()->to('/admin/login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/** Categories CRUD (compact). */
|
||||
final class CategoriesAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return $this->render('categories_index', ['categories' => $this->categories()]);
|
||||
}
|
||||
|
||||
public function store(): ResponseInterface
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
model(\App\Models\CategoryModel::class)->insert([
|
||||
'slug' => $post['slug'],
|
||||
'name' => $post['name'],
|
||||
'tagline' => $post['tagline'] ?? null,
|
||||
'icon' => $post['icon'] ?? 'tool',
|
||||
'seo_title' => $post['seo_title'] ?? null,
|
||||
'seo_description' => $post['seo_description'] ?? null,
|
||||
'sort_order' => (int) ($post['sort_order'] ?? 99),
|
||||
'is_active' => 1,
|
||||
]);
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/categories');
|
||||
}
|
||||
|
||||
public function edit(int $id): string
|
||||
{
|
||||
return $this->render('categories_form', [
|
||||
'category' => model(\App\Models\CategoryModel::class)->find($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(int $id): ResponseInterface
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
model(\App\Models\CategoryModel::class)->update($id, [
|
||||
'name' => $post['name'],
|
||||
'tagline' => $post['tagline'] ?? null,
|
||||
'icon' => $post['icon'] ?? 'tool',
|
||||
'seo_title' => $post['seo_title'] ?? null,
|
||||
'seo_description' => $post['seo_description'] ?? null,
|
||||
'sort_order' => (int) ($post['sort_order'] ?? 99),
|
||||
]);
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/categories');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Models\AnalyticsEventModel;
|
||||
use App\Models\JobModel;
|
||||
|
||||
/** Admin overview: counts, queue health, recent activity. */
|
||||
final class Dashboard extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$jobs = model(JobModel::class);
|
||||
$day = model(AnalyticsEventModel::class)->countsSince(1);
|
||||
|
||||
return $this->render('dashboard', [
|
||||
'toolCount' => service('finder')->countTools(),
|
||||
'guideCount' => $this->guidesModel()->countPublished(),
|
||||
'queued' => $jobs->countQueued(),
|
||||
'processing' => $jobs->countProcessing(),
|
||||
'failedToday' => $jobs->where('status', 'failed')->where('created_at >=', gmdate('Y-m-d H:i:s', time() - 86400))->countAllResults(),
|
||||
'viewsToday' => $day['tool_view'] ?? 0,
|
||||
'startsToday' => $day['tool_start'] ?? 0,
|
||||
'searches' => model(AnalyticsEventModel::class)->recentSearches(8),
|
||||
'recentJobs' => $jobs->orderBy('created_at', 'DESC')->limit(8)->findAll(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/** Guides CRUD with markdown body editing. */
|
||||
final class GuidesAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return $this->render('guides_index', ['guides' => $this->guidesModel()->orderBy('published_at', 'DESC')->findAll()]);
|
||||
}
|
||||
|
||||
public function create(): string
|
||||
{
|
||||
return $this->render('guides_form', ['guide' => null]);
|
||||
}
|
||||
|
||||
public function store(): ResponseInterface
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
$body = (string) ($post['body_md'] ?? '');
|
||||
|
||||
$this->guidesModel()->insert([
|
||||
'slug' => $post['slug'],
|
||||
'title' => $post['title'],
|
||||
'excerpt' => $post['excerpt'] ?? '',
|
||||
'body_md' => $body,
|
||||
'tool_slugs' => json_encode(array_filter(array_map('trim', explode(',', (string) ($post['tool_slugs'] ?? ''))))),
|
||||
'seo_title' => $post['seo_title'] ?? null,
|
||||
'seo_description' => $post['seo_description'] ?? null,
|
||||
'reading_minutes' => max(1, (int) ceil(str_word_count(strip_tags($body)) / 220)),
|
||||
'status' => $post['status'] === 'published' ? 'published' : 'draft',
|
||||
'published_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/guides');
|
||||
}
|
||||
|
||||
public function edit(int $id): string
|
||||
{
|
||||
return $this->render('guides_form', ['guide' => $this->guidesModel()->find($id)]);
|
||||
}
|
||||
|
||||
public function update(int $id): ResponseInterface
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
$body = (string) ($post['body_md'] ?? '');
|
||||
|
||||
$this->guidesModel()->update($id, [
|
||||
'title' => $post['title'],
|
||||
'excerpt' => $post['excerpt'] ?? '',
|
||||
'body_md' => $body,
|
||||
'tool_slugs' => json_encode(array_filter(array_map('trim', explode(',', (string) ($post['tool_slugs'] ?? ''))))),
|
||||
'seo_title' => $post['seo_title'] ?? null,
|
||||
'seo_description' => $post['seo_description'] ?? null,
|
||||
'reading_minutes' => max(1, (int) ceil(str_word_count(strip_tags($body)) / 220)),
|
||||
'status' => $post['status'] === 'published' ? 'published' : 'draft',
|
||||
]);
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/guides');
|
||||
}
|
||||
|
||||
public function delete(int $id): ResponseInterface
|
||||
{
|
||||
$this->guidesModel()->delete($id);
|
||||
|
||||
return redirect()->to('/admin/guides');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Models\JobModel;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/** Queue inspection + retry. */
|
||||
final class JobsAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$status = (string) ($this->request->getGet('status') ?? '');
|
||||
|
||||
$jobs = model(JobModel::class)->orderBy('created_at', 'DESC')->limit(100);
|
||||
if ($status !== '' && in_array($status, ['queued', 'processing', 'completed', 'failed', 'cancelled', 'expired'], true)) {
|
||||
$jobs->where('status', $status);
|
||||
}
|
||||
|
||||
return $this->render('jobs_index', [
|
||||
'jobs' => $jobs->findAll(),
|
||||
'filter' => $status,
|
||||
'counts' => [
|
||||
'queued' => model(JobModel::class)->countQueued(),
|
||||
'processing' => model(JobModel::class)->countProcessing(),
|
||||
'failed' => model(JobModel::class)->where('status', 'failed')->countAllResults(),
|
||||
'completed' => model(JobModel::class)->where('status', 'completed')->countAllResults(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function retry(string $id): ResponseInterface
|
||||
{
|
||||
$job = model(JobModel::class)->find($id);
|
||||
if ($job === null) {
|
||||
throw new \CodeIgniter\Exceptions\PageNotFoundException();
|
||||
}
|
||||
|
||||
Pipeline::failJob($id, 'superseded by retry');
|
||||
$clone = $job;
|
||||
$clone['status'] = 'queued';
|
||||
$clone['stage'] = 'queued';
|
||||
$clone['progress'] = 0;
|
||||
$clone['attempts'] = 0;
|
||||
$clone['error'] = null;
|
||||
$clone['output_file'] = null;
|
||||
$clone['output_size'] = 0;
|
||||
$clone['created_at'] = gmdate('Y-m-d H:i:s');
|
||||
$clone['started_at'] = null;
|
||||
$clone['completed_at'] = null;
|
||||
$clone['expires_at'] = gmdate('Y-m-d H:i:s', time() + config('Site')->retentionHours * 3600);
|
||||
unset($clone['id']);
|
||||
model(JobModel::class)->insert($clone, false);
|
||||
|
||||
return redirect()->to('/admin/jobs');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
/**
|
||||
* SEO quality dashboard: automated audit of the whole indexable surface.
|
||||
*
|
||||
* Critical checks (block publishing in ToolsAdmin too):
|
||||
* unique titles / descriptions, length ranges, H1 present, canonical
|
||||
* slug hygiene, FAQ presence for content tools, duplicate detection.
|
||||
*/
|
||||
final class SeoAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$tools = service('finder')->all();
|
||||
$guides = model(\App\Models\GuideModel::class)->published(1000);
|
||||
|
||||
$issues = [];
|
||||
$seenTitles = [];
|
||||
$seenDescs = [];
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$slug = $tool['slug'];
|
||||
$title = (string) $tool['seo_title'];
|
||||
$desc = (string) $tool['seo_description'];
|
||||
|
||||
if (trim($title) === '') {
|
||||
$issues[] = ['severity' => 'critical', 'page' => '/' . $slug, 'check' => 'Missing SEO title'];
|
||||
} elseif (mb_strlen($title) > 65) {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'Title longer than 65 chars (' . mb_strlen($title) . ')'];
|
||||
}
|
||||
if (trim($desc) === '') {
|
||||
$issues[] = ['severity' => 'critical', 'page' => '/' . $slug, 'check' => 'Missing meta description'];
|
||||
} elseif (mb_strlen($desc) < 70 || mb_strlen($desc) > 320) {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'Description outside 70–320 chars (' . mb_strlen($desc) . ')'];
|
||||
}
|
||||
if (trim((string) $tool['h1']) === '') {
|
||||
$issues[] = ['severity' => 'critical', 'page' => '/' . $slug, 'check' => 'Missing H1'];
|
||||
}
|
||||
if ($tool['faqs'] === [] && ! in_array($tool['kind'], ['text'], true)) {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'No FAQ content'];
|
||||
}
|
||||
if ($tool['related_slugs'] === [] && count(service('relatedTools')->forTool($tool, 4)) < 3) {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'Thin internal linking (<3 related tools)'];
|
||||
}
|
||||
if (! preg_match('/^[a-z0-9]+$/', (string) ($tool['primary_input_format'] ?? '')) && $tool['operation'] === 'convert') {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'Converter without primary format pair'];
|
||||
}
|
||||
|
||||
$tKey = mb_strtolower($title);
|
||||
if ($tKey !== '' && isset($seenTitles[$tKey])) {
|
||||
$issues[] = ['severity' => 'critical', 'page' => '/' . $slug, 'check' => 'Duplicate title with /' . $seenTitles[$tKey]];
|
||||
}
|
||||
$seenTitles[$tKey] = $slug;
|
||||
|
||||
$dKey = mb_substr(mb_strtolower($desc), 0, 120);
|
||||
if ($dKey !== '' && isset($seenDescs[$dKey])) {
|
||||
// near-duplicate short descriptions are common across generated converters — flag only exact dupes
|
||||
if (mb_strtolower((string) $tool['short_description']) === mb_strtolower((string) $desc)) {
|
||||
$issues[] = ['severity' => 'warning', 'page' => '/' . $slug, 'check' => 'Description identical to /' . $seenDescs[$dKey]];
|
||||
}
|
||||
}
|
||||
$seenDescs[$dKey] = $slug;
|
||||
}
|
||||
|
||||
foreach ($guides as $g) {
|
||||
if ((string) $g['excerpt'] === '' || (string) $g['body_md'] === '') {
|
||||
$issues[] = ['severity' => 'critical', 'page' => '/blog/' . $g['slug'], 'check' => 'Guide missing excerpt/body'];
|
||||
}
|
||||
}
|
||||
|
||||
usort($issues, static fn ($a, $b) => [$b['severity'], $a['page']] <=> [$a['severity'], $b['page']]);
|
||||
$criticalCount = count(array_filter($issues, static fn ($i) => $i['severity'] === 'critical'));
|
||||
|
||||
return $this->render('seo_index', [
|
||||
'issues' => $issues,
|
||||
'criticalCount' => $criticalCount,
|
||||
'toolCount' => count($tools),
|
||||
'guideCount' => count($guides),
|
||||
'sitemapUrl' => base_url('/sitemap.xml'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Models\SettingModel;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/** Runtime feature flags & retention overrides. */
|
||||
final class SettingsAdmin extends AdminBase
|
||||
{
|
||||
private const FLAGS = [
|
||||
'ytdlp_enabled' => 'Enable YouTube video/audio downloading (requires yt-dlp binary + legal review)',
|
||||
'ads_enabled' => 'Display advertising slots',
|
||||
'maintenance' => 'Maintenance mode notice on tool pages',
|
||||
];
|
||||
|
||||
public function index(): string
|
||||
{
|
||||
return $this->render('settings_index', [
|
||||
'flags' => self::FLAGS,
|
||||
'values' => model(SettingModel::class)->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): ResponseInterface
|
||||
{
|
||||
$model = model(SettingModel::class);
|
||||
$posted = (array) $this->request->getPost();
|
||||
|
||||
foreach (array_keys(self::FLAGS) as $key) {
|
||||
$model->put($key, isset($posted[$key]) ? '1' : '0');
|
||||
}
|
||||
if (! empty($posted['retention_hours'])) {
|
||||
$hours = max(1, min(72, (int) $posted['retention_hours']));
|
||||
$model->put('retention_hours', (string) $hours);
|
||||
}
|
||||
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/settings');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
/**
|
||||
* System health: binaries, storage, queue depth, worker heartbeat.
|
||||
* Workers touch the heartbeat cache key every pass (see supervisor config).
|
||||
*/
|
||||
final class SystemAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$site = config('Site');
|
||||
|
||||
$binaries = [];
|
||||
foreach ($site->binaries as $name => $path) {
|
||||
$binaries[$name] = [
|
||||
'path' => $path,
|
||||
'ok' => $path !== '' && is_executable($path),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render('system_index', [
|
||||
'phpVersion' => PHP_VERSION,
|
||||
'ciVersion' => \CodeIgniter\CodeIgniter::CI_VERSION,
|
||||
'environment' => ENVIRONMENT,
|
||||
'dbOk' => $this->checkDb(),
|
||||
'diskFreeMb' => (int) round(disk_free_space(WRITEPATH) / 1048576),
|
||||
'storageFiles' => count(glob(\App\Libraries\Pipeline::storageDir() . '/*') ?: []),
|
||||
'incoming' => count(glob(\App\Libraries\Pipeline::incomingDir() . '/*') ?: []),
|
||||
'workerBeat' => cache()->get('tv_worker_heartbeat'),
|
||||
'ytDlpEnabled' => service('pipeline')->youtubeEnabled(),
|
||||
'retentionHrs' => $site->retentionHours,
|
||||
'maxUploadMb' => $site->maxUploadMb,
|
||||
] + ['binaries' => $binaries]);
|
||||
}
|
||||
|
||||
private function checkDb(): bool
|
||||
{
|
||||
try {
|
||||
db_connect()->query('SELECT 1');
|
||||
|
||||
return true;
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/** Tools CRUD: list, create (with generated SEO content), edit, delete. */
|
||||
final class ToolsAdmin extends AdminBase
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$q = trim((string) $this->request->getGet('q'));
|
||||
|
||||
$query = $this->toolsModel()->orderBy('name', 'ASC')->limit(300);
|
||||
if ($q !== '') {
|
||||
$query->like('name', $q)->orLike('slug', $q);
|
||||
}
|
||||
|
||||
return $this->render('tools_index', [
|
||||
'tools' => $query->findAll(),
|
||||
'categories' => $this->categories(),
|
||||
'q' => $q,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): string
|
||||
{
|
||||
return $this->render('tools_form', [
|
||||
'tool' => null,
|
||||
'categories' => $this->categories(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(): ResponseInterface
|
||||
{
|
||||
return $this->save(null);
|
||||
}
|
||||
|
||||
public function edit(int $id): string
|
||||
{
|
||||
$tool = $this->toolsModel()->find($id) ?? throw new \CodeIgniter\Exceptions\PageNotFoundException();
|
||||
|
||||
return $this->render('tools_form', [
|
||||
'tool' => $tool,
|
||||
'categories' => $this->categories(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(int $id): ResponseInterface
|
||||
{
|
||||
return $this->save($id);
|
||||
}
|
||||
|
||||
private function save(?int $id): ResponseInterface
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
$catId = (int) ($post['category_id'] ?? 0);
|
||||
|
||||
try {
|
||||
$row = $this->toolFromInput((array) $post, $catId);
|
||||
} catch (\Throwable $e) {
|
||||
session()->setFlashdata('error', 'Could not build the tool: ' . $e->getMessage());
|
||||
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
// pre-publish SEO validation (critical checks only)
|
||||
$problems = [];
|
||||
if (trim((string) $row['seo_title']) === '') {
|
||||
$problems[] = 'SEO title missing';
|
||||
}
|
||||
if (mb_strlen((string) $row['seo_description']) < 50) {
|
||||
$problems[] = 'SEO description too short (<50 chars)';
|
||||
}
|
||||
if (trim((string) $row['h1']) === '') {
|
||||
$problems[] = 'H1 missing';
|
||||
}
|
||||
if ($problems !== [] && ($row['status'] ?? '') === 'active') {
|
||||
session()->setFlashdata('error', 'Blocked from publishing: ' . implode('; ', $problems));
|
||||
session()->setFlashdata('form_data', $post);
|
||||
|
||||
return redirect()->to($id ? '/admin/tools/' . $id . '/edit' : '/admin/tools/new')->withInput();
|
||||
}
|
||||
|
||||
if ($id !== null) {
|
||||
$this->toolsModel()->update($id, $row);
|
||||
session()->setFlashdata('success', 'Tool updated.');
|
||||
} else {
|
||||
$this->toolsModel()->insert($row);
|
||||
session()->setFlashdata('success', 'Tool created.');
|
||||
}
|
||||
|
||||
return redirect()->to('/admin/tools');
|
||||
}
|
||||
|
||||
public function delete(int $id): ResponseInterface
|
||||
{
|
||||
$this->toolsModel()->delete($id);
|
||||
service('cache')->clear();
|
||||
|
||||
return redirect()->to('/admin/tools');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
/**
|
||||
* Analytics beacon: POST /api/events {name, tool, format, meta}.
|
||||
* Accepts only the whitelisted event names; everything is anonymized
|
||||
* server-side before storage.
|
||||
*/
|
||||
final class Events extends Controller
|
||||
{
|
||||
public function track(): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$payload = $this->request->getJSON(true) ?: $this->request->getPost();
|
||||
$name = (string) ($payload['name'] ?? '');
|
||||
|
||||
if (! in_array($name, \App\Libraries\Analytics::EVENTS, true)) {
|
||||
return response()->setStatusCode(422)->setJSON(['ok' => false]);
|
||||
}
|
||||
|
||||
service('analytics')->track($name, [
|
||||
'tool' => mb_substr((string) ($payload['tool'] ?? ''), 0, 120),
|
||||
'format' => isset($payload['format']) ? (string) $payload['format'] : null,
|
||||
'value' => (int) ($payload['value'] ?? 0),
|
||||
'meta' => is_array($payload['meta'] ?? null) ? array_slice($payload['meta'], 0, 5) : [],
|
||||
]);
|
||||
|
||||
return response()->setJSON(['ok' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Libraries\Pipeline\Youtube as YoutubeLib;
|
||||
use App\Models\JobModel;
|
||||
|
||||
/**
|
||||
* Job lifecycle API used by tool pages and the v1 developer API.
|
||||
* POST /api/jobs — enqueue (URL-based tools)
|
||||
* GET /api/jobs/{id} — poll status/progress
|
||||
* DELETE /api/jobs/{id} — cancel queued job / delete result
|
||||
*/
|
||||
final class Jobs extends BaseController
|
||||
{
|
||||
public function create(): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$isApiV1 = uri_string() === 'api/v1/convert';
|
||||
$payload = $this->request->getJSON(true) ?: $this->request->getPost();
|
||||
|
||||
$slug = (string) ($payload['tool'] ?? '');
|
||||
$tool = service('finder')->tool($slug);
|
||||
if ($tool === null) {
|
||||
return response()->setStatusCode(400)->setJSON(['ok' => false, 'error' => 'unknown_tool', 'message' => 'Unknown tool slug.']);
|
||||
}
|
||||
|
||||
// URL-kind tools fetch their input server-side (SSRF-guarded).
|
||||
$params = array_intersect_key($payload, array_flip([
|
||||
'url', 'format', 'bitrate', 'quality', 'width', 'height',
|
||||
'start', 'end', 'x', 'y', 'crop_width', 'crop_height',
|
||||
'degrees', 'direction', 'factor', 'fps', 'gain_db', 'level',
|
||||
'preset', 'pages', '_operation',
|
||||
]));
|
||||
$params['_operation'] = $params['_operation'] ?? $tool['operation'];
|
||||
|
||||
if ($tool['kind'] === 'upload') {
|
||||
return response()->setStatusCode(400)->setJSON(['ok' => false, 'error' => 'upload_required', 'message' => 'This tool requires a file upload via POST /upload first.']);
|
||||
}
|
||||
|
||||
if ($tool['kind'] === 'url') {
|
||||
$videoId = YoutubeLib::extractId((string) ($params['url'] ?? ''));
|
||||
if ($videoId === null) {
|
||||
service('analytics')->track('error', ['tool' => $slug]);
|
||||
return response()->setStatusCode(422)->setJSON(['ok' => false, 'error' => 'invalid_url', 'message' => 'Invalid YouTube URL.']);
|
||||
}
|
||||
// canonicalize to a plain watch URL
|
||||
$params['url'] = 'https://www.youtube.com/watch?v=' . $videoId;
|
||||
}
|
||||
|
||||
try {
|
||||
$jobId = service('pipeline')->enqueue($tool, $params, $isApiV1 ? 'api' : 'web');
|
||||
} catch (\RuntimeException $e) {
|
||||
return response()->setStatusCode(429)->setJSON(['ok' => false, 'error' => 'limit_reached', 'message' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
model(\App\Models\ToolModel::class)->bumpUseCount((int) $tool['id']);
|
||||
service('analytics')->track('tool_start', ['tool' => $slug]);
|
||||
|
||||
return response()->setStatusCode(202)->setJSON([
|
||||
'ok' => true,
|
||||
'job_id' => $jobId,
|
||||
'status' => 'queued',
|
||||
'poll_url' => base_url('/api/jobs/' . $jobId),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(string $id): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$job = model(JobModel::class)->find($id);
|
||||
if ($job === null || ! $this->owns($job)) {
|
||||
return response()->setStatusCode(404)->setJSON(['ok' => false, 'error' => 'not_found']);
|
||||
}
|
||||
|
||||
$body = [
|
||||
'job_id' => $job['id'],
|
||||
'status' => $job['status'],
|
||||
'stage' => $job['stage'],
|
||||
'progress' => (int) $job['progress'],
|
||||
'created_at' => $job['created_at'],
|
||||
'expires_at' => $job['expires_at'],
|
||||
];
|
||||
if ($job['status'] === 'completed') {
|
||||
$body['download_url'] = '/download/' . $job['id'];
|
||||
$body['preview_url'] = '/preview/' . $job['id'] . '.' . pathinfo((string) $job['output_file'], PATHINFO_EXTENSION);
|
||||
$body['output_name'] = $job['output_name'];
|
||||
$body['output_size'] = (int) $job['output_size'];
|
||||
}
|
||||
if ($job['status'] === 'failed') {
|
||||
$body['message'] = self::friendlyError((string) ($job['error'] ?? 'Processing failed.'));
|
||||
}
|
||||
|
||||
return response()->setJSON(['ok' => true] + $body);
|
||||
}
|
||||
|
||||
public function delete(string $id): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$jobs = model(JobModel::class);
|
||||
$job = $jobs->find($id);
|
||||
|
||||
if ($job === null || ! $this->owns($job)) {
|
||||
return response()->setStatusCode(404)->setJSON(['ok' => false, 'error' => 'not_found']);
|
||||
}
|
||||
|
||||
foreach (['input_file', 'output_file'] as $field) {
|
||||
if (! empty($job[$field])) {
|
||||
@unlink(Pipeline::storageDir() . '/' . $job[$field]);
|
||||
@unlink(Pipeline::incomingDir() . '/' . $job[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($job['status'], ['queued'], true)) {
|
||||
$jobs->update($id, ['status' => 'cancelled', 'completed_at' => gmdate('Y-m-d H:i:s')]);
|
||||
} else {
|
||||
$jobs->delete($id);
|
||||
}
|
||||
|
||||
return response()->setJSON(['ok' => true, 'deleted' => true]);
|
||||
}
|
||||
|
||||
/** Session ownership for web callers; API-token jobs are keyed by session hash too. */
|
||||
private function owns(array $job): bool
|
||||
{
|
||||
return $job['session_id'] === service('analytics')->sessionHash();
|
||||
}
|
||||
|
||||
private static function friendlyError(string $raw): string
|
||||
{
|
||||
$known = [
|
||||
'Invalid YouTube URL.' => 'That does not look like a valid YouTube link. Paste the full URL.',
|
||||
'disabled on this server' => 'This capability is currently disabled on this server.',
|
||||
'exceeds' => 'The file is too large for this tool.',
|
||||
];
|
||||
foreach ($known as $needle => $friendly) {
|
||||
if (str_contains($raw, $needle)) {
|
||||
return $friendly;
|
||||
}
|
||||
}
|
||||
|
||||
return 'This file could not be processed. Please check the format and try again.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Libraries\ToolSearch;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
/** Typeahead suggestions for the global search box. */
|
||||
final class SearchApi extends Controller
|
||||
{
|
||||
public function suggest(): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$q = trim((string) $this->request->getGet('q'));
|
||||
if (mb_strlen($q) < 2) {
|
||||
return response()->setJSON(['ok' => true, 'results' => []]);
|
||||
}
|
||||
|
||||
$hits = (new ToolSearch())->find($q, 6);
|
||||
$out = [];
|
||||
foreach ($hits as $tool) {
|
||||
$out[] = [
|
||||
'slug' => $tool['slug'],
|
||||
'name' => $tool['name'],
|
||||
'url' => '/' . $tool['slug'],
|
||||
'icon' => $tool['icon'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($out !== []) {
|
||||
service('analytics')->track('search', ['meta' => ['term' => mb_substr($q, 0, 60), 'scope' => 'suggest']]);
|
||||
}
|
||||
|
||||
return response()->setJSON(['ok' => true, 'results' => $out]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Libraries\CatalogBuilder;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
/** Public read-only tool registry for developers: /api/v1/tools */
|
||||
final class ToolsApi extends Controller
|
||||
{
|
||||
public function index(): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$tools = service('finder')->all();
|
||||
$out = array_map(static fn (array $t): array => [
|
||||
'slug' => $t['slug'],
|
||||
'name' => $t['name'],
|
||||
'category' => service('finder')->categoryById((int) $t['category_id'])['slug'] ?? null,
|
||||
'kind' => $t['kind'],
|
||||
'operation' => $t['operation'],
|
||||
'input_formats' => $t['input_formats'],
|
||||
'output_formats' => $t['output_formats'],
|
||||
'short_description' => $t['short_description'],
|
||||
'url' => base_url('/' . $t['slug']),
|
||||
], $tools);
|
||||
|
||||
return response()->setJSON(['ok' => true, 'count' => count($out), 'tools' => $out]);
|
||||
}
|
||||
|
||||
public function show(string $slug): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$tool = service('finder')->tool($slug);
|
||||
if ($tool === null) {
|
||||
return response()->setStatusCode(404)->setJSON(['ok' => false, 'error' => 'not_found']);
|
||||
}
|
||||
|
||||
return response()->setJSON(['ok' => true, 'tool' => [
|
||||
'slug' => $tool['slug'],
|
||||
'name' => $tool['name'],
|
||||
'kind' => $tool['kind'],
|
||||
'operation' => $tool['operation'],
|
||||
'input_formats' => $tool['input_formats'],
|
||||
'output_formats' => $tool['output_formats'],
|
||||
'how_to' => $tool['how_to'],
|
||||
'faqs' => $tool['faqs'],
|
||||
'requires_binaries' => $tool['requires_binaries'],
|
||||
'accepts_mimes' => $tool['accepts_mimes'],
|
||||
'max_upload_mb' => (int) ($tool['max_upload_mb'] ?: config('Site')->maxUploadMb),
|
||||
'url' => base_url('/' . $tool['slug']),
|
||||
]]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\Pipeline\Youtube as YoutubeLib;
|
||||
|
||||
/**
|
||||
* Instant YouTube URL analysis used by the paste-a-link UX: returns
|
||||
* oEmbed metadata + thumbnail candidates before any job is queued.
|
||||
*/
|
||||
final class Youtube extends BaseController
|
||||
{
|
||||
public function info(): \CodeIgniter\HTTP\ResponseInterface
|
||||
{
|
||||
$payload = $this->request->getJSON(true) ?: $this->request->getPost();
|
||||
$url = (string) ($payload['url'] ?? '');
|
||||
|
||||
$videoId = YoutubeLib::extractId($url);
|
||||
if ($videoId === null) {
|
||||
return response()->setStatusCode(422)->setJSON([
|
||||
'ok' => false, 'error' => 'invalid_url',
|
||||
'message' => 'Invalid YouTube URL. Paste a link like https://www.youtube.com/watch?v=…',
|
||||
]);
|
||||
}
|
||||
|
||||
service('analytics')->track('tool_start', ['tool' => 'youtube-url-analyzer']);
|
||||
|
||||
return response()->setJSON([
|
||||
'ok' => true,
|
||||
'id' => $videoId,
|
||||
'watch_url' => 'https://www.youtube.com/watch?v=' . $videoId,
|
||||
'embed_url' => 'https://www.youtube-nocookie.com/embed/' . $videoId,
|
||||
'thumbnails' => [
|
||||
['label' => 'Max resolution', 'url' => "https://i.ytimg.com/vi/{$videoId}/maxresdefault.jpg"],
|
||||
['label' => 'Standard', 'url' => "https://i.ytimg.com/vi/{$videoId}/sddefault.jpg"],
|
||||
['label' => 'High quality', 'url' => "https://i.ytimg.com/vi/{$videoId}/hqdefault.jpg"],
|
||||
['label' => 'Medium', 'url' => "https://i.ytimg.com/vi/{$videoId}/mqdefault.jpg"],
|
||||
],
|
||||
'info' => YoutubeLib::fetchInfo($videoId),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Seo;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Shared controller bootstrap: anonymous session boot, SEO service.
|
||||
*/
|
||||
abstract class BaseController extends Controller
|
||||
{
|
||||
protected Seo $seo;
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
helper('text');
|
||||
// Anonymous session (cookie) used only for job ownership + rate buckets.
|
||||
// CI4 auto-starts sessions when the session service is first touched.
|
||||
|
||||
$this->seo = service('seo');
|
||||
}
|
||||
|
||||
/** Track a page-level tool view event. */
|
||||
protected function trackToolView(string $slug): void
|
||||
{
|
||||
service('analytics')->track('tool_view', ['tool' => $slug]);
|
||||
}
|
||||
|
||||
/** Render a page inside the shared layout. */
|
||||
protected function render(string $view, array $data = []): string
|
||||
{
|
||||
$data['viewContent'] = view($view, $data);
|
||||
|
||||
return view('layout', ['seo' => $this->seo] + $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Category landing pages: /youtube-tools, /video-tools, ...
|
||||
*/
|
||||
final class Categories extends BaseController
|
||||
{
|
||||
public function show(string $slug): string
|
||||
{
|
||||
$finder = service('finder');
|
||||
$category = $finder->category($slug);
|
||||
|
||||
if ($category === null) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
$tools = $finder->toolsInCategory($slug);
|
||||
$guides = model(\App\Models\GuideModel::class)->published(50);
|
||||
// guides touching this category's tools
|
||||
$catToolSlugs = array_column($tools, 'slug');
|
||||
$relatedGuides = array_values(array_filter($guides, static function (array $g) use ($catToolSlugs): bool {
|
||||
$linked = json_decode((string) ($g['tool_slugs'] ?? '[]'), true) ?: [];
|
||||
|
||||
return count(array_intersect($linked, $catToolSlugs)) > 0;
|
||||
}));
|
||||
|
||||
$this->seo->title($category['seo_title'] ?: ($category['name'] . ' – Free Online'))
|
||||
->description($category['seo_description'] ?? (string) $category['tagline'])
|
||||
->canonical('/' . $category['slug'])
|
||||
->breadcrumbs([['label' => $category['name']]])
|
||||
->webApplication($category['name'], (string) ($category['tagline'] ?? ''))
|
||||
->faqPage(is_array($category['faqs']) ? $category['faqs'] : [])
|
||||
->ogImage('/og/' . $category['slug'] . '.png');
|
||||
|
||||
$this->trackToolView($category['slug']);
|
||||
|
||||
return $this->render('category', [
|
||||
'category' => $category,
|
||||
'tools' => $tools,
|
||||
'featured' => array_slice(array_filter($tools, static fn ($t) => (int) $t['is_featured'] === 1), 0, 4),
|
||||
'guides' => array_slice($relatedGuides, 0, 3),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Tool directory: /tools with search, category filter, popular, recent
|
||||
* and A–Z views. Server-rendered links only — crawlable navigation.
|
||||
*/
|
||||
final class Directory extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$finder = service('finder');
|
||||
$q = trim((string) $this->request->getGet('q'));
|
||||
$cat = (string) ($this->request->getGet('category') ?? '');
|
||||
|
||||
$tools = $finder->all();
|
||||
if ($q !== '') {
|
||||
$tools = service('toolSearch')->find($q, 100);
|
||||
service('analytics')->track('search', ['meta' => ['term' => mb_substr($q, 0, 80), 'scope' => 'directory']]);
|
||||
}
|
||||
if ($cat !== '') {
|
||||
$tools = array_values(array_filter(
|
||||
$tools,
|
||||
static fn (array $t): bool => (service('finder')->categoryById((int) $t['category_id'])['slug'] ?? '') === $cat
|
||||
));
|
||||
}
|
||||
|
||||
$this->seo->title('All Tools – ' . config('Site')->name)
|
||||
->description('Search and browse every free online tool: video, audio, image, GIF, PDF and YouTube utilities.')
|
||||
->canonical('/tools')
|
||||
->breadcrumbs([['label' => 'Tools']]);
|
||||
|
||||
return $this->render('directory', [
|
||||
'tools' => $tools,
|
||||
'categories' => $finder->categories(),
|
||||
'query' => $q,
|
||||
'activeCat' => $cat,
|
||||
'view' => 'all-tools',
|
||||
]);
|
||||
}
|
||||
|
||||
public function popular(): string
|
||||
{
|
||||
return $this->renderList(
|
||||
'Popular Tools',
|
||||
'The most used tools across the platform right now.',
|
||||
service('finder')->popular(24),
|
||||
'/tools/popular'
|
||||
);
|
||||
}
|
||||
|
||||
public function recent(): string
|
||||
{
|
||||
return $this->renderList(
|
||||
'Recently Added Tools',
|
||||
'Fresh additions to the toolbox.',
|
||||
service('finder')->recent(24),
|
||||
'/tools/recent'
|
||||
);
|
||||
}
|
||||
|
||||
public function az(): string
|
||||
{
|
||||
return $this->renderList(
|
||||
'All Tools A–Z',
|
||||
'Every tool in alphabetical order.',
|
||||
service('finder')->all(),
|
||||
'/tools/a-z'
|
||||
);
|
||||
}
|
||||
|
||||
public function category(string $slug): string
|
||||
{
|
||||
return redirect()->to('/' . $slug, 301);
|
||||
}
|
||||
|
||||
private function renderList(string $h1, string $intro, array $tools, string $path): string
|
||||
{
|
||||
$this->seo->title($h1 . ' – ' . config('Site')->name)
|
||||
->description(mb_substr($intro, 0, 300))
|
||||
->canonical($path)
|
||||
->breadcrumbs([['label' => 'Tools', 'url' => '/tools'], ['label' => $h1]]);
|
||||
|
||||
return $this->render('directory_list', [
|
||||
'tools' => $tools,
|
||||
'h1' => $h1,
|
||||
'intro' => $intro,
|
||||
'view' => $path,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Error pages. Every one offers a route back into the toolbox.
|
||||
* Deliberately standalone (works when invoked from the router's 404
|
||||
* override without full initController).
|
||||
*/
|
||||
final class Errors extends BaseController
|
||||
{
|
||||
public function showNotFound(): string
|
||||
{
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
public function notFound(): string
|
||||
{
|
||||
service('analytics')->sessionHash(); // ensure session exists for ownership checks
|
||||
service('seo')->title('Tool not found')
|
||||
->description('The page you requested does not exist. Browse popular tools instead.')
|
||||
->noIndex();
|
||||
|
||||
// status rides the shared response; body returned as string
|
||||
service('response')->setStatusCode(404);
|
||||
|
||||
return view('errors/tool_not_found', [
|
||||
'popular' => service('finder')->popular(6),
|
||||
'categories' => service('finder')->categories(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function forbidden(): string
|
||||
{
|
||||
service('seo')->title('Access denied')->noIndex();
|
||||
service('response')->setStatusCode(403);
|
||||
|
||||
return view('errors/http', [
|
||||
'code' => 403, 'title' => 'Access denied',
|
||||
'message' => 'You do not have permission to view this page.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function serverError(): string
|
||||
{
|
||||
service('seo')->title('Something went wrong')->noIndex();
|
||||
service('response')->setStatusCode(500);
|
||||
|
||||
return view('errors/http', [
|
||||
'code' => 500, 'title' => 'Something went wrong',
|
||||
'message' => 'Our team has been notified. Please try again in a moment.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use League\CommonMark\Environment\Environment;
|
||||
use League\CommonMark\Extension\Autolink\AutolinkExtension;
|
||||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
||||
use League\CommonMark\Extension\Table\TableExtension;
|
||||
use League\CommonMark\MarkdownConverter;
|
||||
|
||||
/**
|
||||
* Guides cluster: /blog and /blog/{slug}.
|
||||
*/
|
||||
final class Guides extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$guides = model(\App\Models\GuideModel::class)->published(50);
|
||||
|
||||
$this->seo->title('Guides & Tutorials – Media How-Tos')
|
||||
->description('Practical guides for converting, compressing and editing media: video, audio, images, GIFs, PDFs and YouTube workflows.')
|
||||
->canonical('/blog')
|
||||
->breadcrumbs([['label' => 'Blog']]);
|
||||
|
||||
return $this->render('guides_index', ['guides' => $guides]);
|
||||
}
|
||||
|
||||
public function show(string $slug): string
|
||||
{
|
||||
$guide = model(\App\Models\GuideModel::class)->findBySlug($slug);
|
||||
if ($guide === null) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
model(\App\Models\GuideModel::class)->incrementViews((int) $guide['id']);
|
||||
|
||||
$linkedTools = [];
|
||||
foreach (json_decode((string) ($guide['tool_slugs'] ?? '[]'), true) ?: [] as $toolSlug) {
|
||||
if ($tool = service('finder')->tool((string) $toolSlug)) {
|
||||
$linkedTools[] = $tool;
|
||||
}
|
||||
}
|
||||
|
||||
$related = array_values(array_filter(
|
||||
model(\App\Models\GuideModel::class)->published(20),
|
||||
static fn (array $g): bool => $g['slug'] !== $guide['slug']
|
||||
));
|
||||
|
||||
$this->seo->title($guide['seo_title'] ?: $guide['title'])
|
||||
->description($guide['seo_description'] ?: mb_substr($guide['excerpt'], 0, 300))
|
||||
->canonical('/blog/' . $guide['slug'])
|
||||
->breadcrumbs([['label' => 'Blog', 'url' => '/blog'], ['label' => $guide['title']]])
|
||||
->article($guide['title'], (string) $guide['body_md'], (string) $guide['published_at'], config('Site')->name)
|
||||
->ogImage('/og/blog-' . $guide['slug'] . '.png');
|
||||
|
||||
return $this->render('guide', [
|
||||
'guide' => $guide,
|
||||
'html' => self::markdown((string) $guide['body_md']),
|
||||
'tools' => $linkedTools,
|
||||
'related'=> array_slice($related, 0, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
public function rss(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$guides = model(\App\Models\GuideModel::class)->published(30);
|
||||
$site = config('Site');
|
||||
$items = '';
|
||||
foreach ($guides as $g) {
|
||||
$items .= "\n<item><title>" . htmlspecialchars((string) $g['title'], ENT_XML1)
|
||||
. "</title><link>" . base_url('/blog/' . $g['slug']) . "</link>"
|
||||
. "<description>" . htmlspecialchars((string) $g['excerpt'], ENT_XML1) . "</description>"
|
||||
. "<pubDate>" . date(DATE_RSS, strtotime((string) $g['published_at'])) . "</pubDate>"
|
||||
. "<guid>" . base_url('/blog/' . $g['slug']) . "</guid></item>";
|
||||
}
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>'
|
||||
. htmlspecialchars($site->name . ' Guides', ENT_XML1) . '</title><link>' . base_url('/blog')
|
||||
. '</link><description>' . htmlspecialchars($site->tagline, ENT_XML1) . '</description>'
|
||||
. $items . '</channel></rss>';
|
||||
|
||||
return response()->setContentType('application/rss+xml; charset=utf-8')->setBody($xml);
|
||||
}
|
||||
|
||||
private static function markdown(string $text): string
|
||||
{
|
||||
$env = new Environment(['html_input' => 'strip', 'allow_unsafe_links' => false]);
|
||||
$env->addExtension(new CommonMarkCoreExtension());
|
||||
$env->addExtension(new AutolinkExtension());
|
||||
$env->addExtension(new TableExtension());
|
||||
|
||||
return (new MarkdownConverter($env))->convert($text)->getContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Health & readiness probes for load balancers / Docker.
|
||||
* GET /health — process alive. GET /ready — DB + queue reachable.
|
||||
*/
|
||||
final class Health extends \CodeIgniter\Controller
|
||||
{
|
||||
public function index(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
return response()->setJSON([
|
||||
'status' => 'ok',
|
||||
'time' => gmdate('c'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function ready(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$checks = [
|
||||
'database' => false,
|
||||
'storage' => is_writable(\App\Libraries\Pipeline::storageDir()) || @mkdir(\App\Libraries\Pipeline::storageDir(), 0750, true),
|
||||
'ffmpeg' => null,
|
||||
];
|
||||
|
||||
try {
|
||||
db_connect()->query('SELECT 1');
|
||||
$checks['database'] = true;
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
|
||||
$path = config('Site')->binaries['ffmpeg'];
|
||||
if ($path !== null && file_exists($path)) {
|
||||
$checks['ffmpeg'] = is_executable($path);
|
||||
}
|
||||
|
||||
$ready = $checks['database'] && $checks['storage'];
|
||||
|
||||
return response()->setStatusCode($ready ? 200 : 503)->setJSON([
|
||||
'status' => $ready ? 'ready' : 'not_ready',
|
||||
'checks' => array_filter($checks, static fn ($v) => $v !== null),
|
||||
'time' => gmdate('c'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Homepage: hero search, popular tools, category grid, content sections.
|
||||
* Fully server-rendered.
|
||||
*/
|
||||
final class Home extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$finder = service('finder');
|
||||
|
||||
$data = [
|
||||
'popular' => $finder->featured(8),
|
||||
'recently' => $finder->recent(6),
|
||||
'mostUsed' => $finder->popular(8),
|
||||
'categories' => $finder->categories(),
|
||||
'toolCount' => $finder->countTools(),
|
||||
'guides' => model(\App\Models\GuideModel::class)->published(4),
|
||||
];
|
||||
|
||||
$this->seo->title(config('Site')->name . ' – Free Online Video, YouTube & Image Tools')
|
||||
->description('Fast, simple and free tools for downloading, converting, compressing and editing media online. ' . $data['toolCount'] . ' tools, no signup required.')
|
||||
->canonical('/')
|
||||
->breadcrumbs([]);
|
||||
|
||||
return $this->render('home', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Pipeline;
|
||||
use App\Models\JobModel;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Upload + download endpoints for tool pages.
|
||||
*
|
||||
* Uploads are validated (extension, real MIME via fileinfo, size),
|
||||
* stored outside the web root with UUID names, and enqueued on the
|
||||
* processing queue. Downloads stream from temp storage and only for
|
||||
* jobs owned by the requesting session.
|
||||
*/
|
||||
final class Media extends BaseController
|
||||
{
|
||||
public function upload(): ResponseInterface
|
||||
{
|
||||
if (! $this->request->is('post')) {
|
||||
return $this->jsonError(405, 'POST required.');
|
||||
}
|
||||
|
||||
$slug = (string) $this->request->getPost('tool');
|
||||
$tool = service('finder')->tool($slug);
|
||||
if ($tool === null) {
|
||||
return $this->jsonError(400, 'Unknown tool.');
|
||||
}
|
||||
|
||||
$files = $this->request->getFiles()['files'] ?? null;
|
||||
if ($files === null) {
|
||||
$single = $this->request->getFile('file');
|
||||
$files = $single !== null ? [$single] : [];
|
||||
}
|
||||
if (! is_array($files)) {
|
||||
$files = [$files];
|
||||
}
|
||||
|
||||
$stored = [];
|
||||
foreach ($files as $file) {
|
||||
if (! ($file instanceof \CodeIgniter\HTTP\Files\UploadedFile) || ! $file->isValid()) {
|
||||
continue;
|
||||
}
|
||||
$stored[] = $this->validateAndStore($file, $tool);
|
||||
}
|
||||
if ($stored === []) {
|
||||
return $this->jsonError(400, 'No valid file was received.');
|
||||
}
|
||||
|
||||
session()->set('pending_uploads', $stored);
|
||||
service('analytics')->track('upload', ['tool' => $slug]);
|
||||
|
||||
return response()->setJSON([
|
||||
'ok' => true,
|
||||
'file' => $stored[0]['file'],
|
||||
'name' => $stored[0]['name'],
|
||||
'size' => $stored[0]['size'],
|
||||
'count' => count($stored),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Validate one upload against the tool registry and move it into temp storage. */
|
||||
private function validateAndStore(\CodeIgniter\HTTP\Files\UploadedFile $file, array $tool): array
|
||||
{
|
||||
// ---- validation: size ------------------------------------------------
|
||||
$limitMb = (int) ($tool['max_upload_mb'] ?: config('Site')->maxUploadMb);
|
||||
if ($file->getSizeByUnit('mb') > $limitMb) {
|
||||
throw new \RuntimeException("File exceeds the {$limitMb} MB limit for this tool.");
|
||||
}
|
||||
|
||||
// ---- validation: extension allowlist ---------------------------------
|
||||
$allowedExt = array_merge(
|
||||
$tool['input_formats'] ?? [],
|
||||
in_array($tool['operation'], ['merge', 'add_audio', 'add_subtitles', 'images_to_pdf', 'frames_to_gif'], true)
|
||||
? ['mp3', 'wav', 'm4a', 'aac', 'srt', 'vtt', 'png', 'jpg', 'webp', 'gif', 'mp4', 'pdf'] : []
|
||||
);
|
||||
$ext = strtolower($file->getClientExtension());
|
||||
if ($allowedExt !== [] && ! in_array($ext, $allowedExt, true)) {
|
||||
throw new \RuntimeException('This file type is not accepted. Allowed: ' . implode(', ', $allowedExt));
|
||||
}
|
||||
|
||||
// ---- validation: real MIME --------------------------------------------
|
||||
$allowedMimes = $tool['accepts_mimes'] ?? [];
|
||||
$realMime = (new \finfo(FILEINFO_MIME_TYPE))->file($file->getTempName()) ?: 'application/octet-stream';
|
||||
if ($allowedMimes !== [] && ! in_array($realMime, $allowedMimes, true)) {
|
||||
// tolerate container/mime drift (e.g. mkv detected as application/octet-stream)
|
||||
$familyOk = str_starts_with($realMime, 'video/') || str_starts_with($realMime, 'audio/') || str_starts_with($realMime, 'image/');
|
||||
if (! ($ext === 'mkv' && $familyOk)) {
|
||||
throw new \RuntimeException('The file content does not match its extension.');
|
||||
}
|
||||
}
|
||||
|
||||
// ---- persist under UUID name, outside web root -------------------------
|
||||
$uuid = $this->uuid();
|
||||
$target = Pipeline::incomingDir() . '/' . Pipeline::safeName($uuid, $ext);
|
||||
$file->move(dirname($target), basename($target));
|
||||
|
||||
return [
|
||||
'file' => basename($target),
|
||||
'name' => (string) $file->getClientName(),
|
||||
'size' => (int) $file->getSize(),
|
||||
'mime' => $realMime,
|
||||
];
|
||||
}
|
||||
|
||||
/** Create a job from an uploaded file (session-owned). */
|
||||
public function startJob(): ResponseInterface
|
||||
{
|
||||
$isJson = str_contains((string) $this->request->getHeaderLine('Content-Type'), 'application/json');
|
||||
$body = $isJson ? ($this->request->getJSON(true) ?: []) : [];
|
||||
$slug = (string) ($body['tool'] ?? $this->request->getPost('tool'));
|
||||
$tool = service('finder')->tool($slug);
|
||||
$pending = session('pending_uploads') ?? [];
|
||||
|
||||
$isTextTool = ($tool['kind'] ?? '') === 'text';
|
||||
if (! $isTextTool && ($pending === [] || ! is_file(Pipeline::incomingDir() . '/' . $pending[0]['file']))) {
|
||||
return $this->jsonError(400, 'Upload expired — please add your file again.');
|
||||
}
|
||||
|
||||
$params = array_intersect_key($body ?: $this->request->getPost(), array_flip([
|
||||
'format', 'bitrate', 'quality', 'width', 'height', 'start', 'end',
|
||||
'x', 'y', 'crop_width', 'crop_height', 'degrees', 'direction',
|
||||
'factor', 'fps', 'gain_db', 'level', 'preset', 'pages', 'delay', 'content',
|
||||
'rotate', 'flip', 'stop_at_shortest', 'dpi', '_operation',
|
||||
]));
|
||||
$params['_operation'] = $params['_operation'] ?? $tool['operation'];
|
||||
$params['_input_file'] = $isTextTool ? '' : $pending[0]['file'];
|
||||
$params['_input_name'] = $isTextTool ? '' : $pending[0]['name'];
|
||||
$params['_input_size'] = $isTextTool ? 0 : (int) $pending[0]['size'];
|
||||
$params['_input_mime'] = $isTextTool ? 'text/plain' : $pending[0]['mime'];
|
||||
// additional files (mergers, images-to-PDF, frames-to-GIF)
|
||||
if (count($pending) > 1) {
|
||||
$params['extra_files'] = array_column(array_slice($pending, 1), 'file');
|
||||
}
|
||||
|
||||
try {
|
||||
$jobId = service('pipeline')->enqueue($tool, $params, 'web');
|
||||
} catch (\RuntimeException $e) {
|
||||
return $this->jsonError(429, $e->getMessage());
|
||||
}
|
||||
session()->remove('pending_uploads');
|
||||
model(\App\Models\ToolModel::class)->bumpUseCount((int) $tool['id']);
|
||||
service('analytics')->track('tool_start', ['tool' => $slug]);
|
||||
|
||||
return response()->setJSON(['ok' => true, 'job_id' => $jobId]);
|
||||
}
|
||||
|
||||
public function download(string $id): ResponseInterface
|
||||
{
|
||||
$job = model(JobModel::class)->find($id);
|
||||
|
||||
if ($job === null
|
||||
|| $job['status'] !== 'completed'
|
||||
|| $job['output_file'] === null
|
||||
|| $job['session_id'] !== service('analytics')->sessionHash()) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
$path = Pipeline::storageDir() . '/' . $job['output_file'];
|
||||
if (! is_file($path)) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
model(JobModel::class)->builder()->where('id', $id)->set('download_count', 'download_count+1', false)->update();
|
||||
service('analytics')->track('download', ['tool' => '', 'format' => pathinfo((string) $job['output_name'], PATHINFO_EXTENSION)]);
|
||||
|
||||
// stream outside the framework to avoid buffering large media
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
header('Content-Disposition: attachment; filename="' . rawurlencode((string) $job['output_name']) . '"');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
readfile($path);
|
||||
exit;
|
||||
}
|
||||
|
||||
/** Inline preview of completed results (images/video/audio). */
|
||||
public function preview(string $id, string $ext): ResponseInterface
|
||||
{
|
||||
$job = model(JobModel::class)->find($id);
|
||||
if ($job === null
|
||||
|| $job['status'] !== 'completed'
|
||||
|| $job['output_file'] === null
|
||||
|| $job['session_id'] !== service('analytics')->sessionHash()
|
||||
|| preg_replace('/[^a-z0-9]/i', '', $ext) !== strtolower(pathinfo((string) $job['output_file'], PATHINFO_EXTENSION))) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
$path = Pipeline::storageDir() . '/' . $job['output_file'];
|
||||
if (! is_file($path)) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
return response()->download($path, null)
|
||||
->setFileName((string) $job['output_name'])
|
||||
->setContentType($this->previewMime(strtolower($ext)))
|
||||
->inline();
|
||||
}
|
||||
|
||||
private function previewMime(string $ext): string
|
||||
{
|
||||
return match ($ext) {
|
||||
'jpg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'webp' => 'image/webp', 'gif' => 'image/gif',
|
||||
'mp4' => 'video/mp4', 'webm' => 'video/webm', 'mp3' => 'audio/mpeg', 'wav' => 'audio/wav',
|
||||
'm4a' => 'audio/mp4', 'pdf' => 'application/pdf', default => 'application/octet-stream',
|
||||
};
|
||||
}
|
||||
|
||||
private function jsonError(int $code, string $message): ResponseInterface
|
||||
{
|
||||
return response()->setStatusCode($code)->setJSON(['ok' => false, 'error' => $message]);
|
||||
}
|
||||
|
||||
private function uuid(): string
|
||||
{
|
||||
$b = random_bytes(16);
|
||||
$b[6] = chr((ord($b[6]) & 0x0f) | 0x40);
|
||||
$b[8] = chr((ord($b[8]) & 0x3f) | 0x80);
|
||||
|
||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($b), 4));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Legal / compliance pages.
|
||||
*/
|
||||
final class Pages extends BaseController
|
||||
{
|
||||
public function privacy(): string
|
||||
{
|
||||
return $this->page('privacy', 'Privacy Policy', 'What we store (very little), what we never store, and how temporary files are handled.');
|
||||
}
|
||||
|
||||
public function terms(): string
|
||||
{
|
||||
return $this->page('terms', 'Terms of Service', 'Acceptable use, content rights and platform rules for using Toolvana.');
|
||||
}
|
||||
|
||||
public function cookies(): string
|
||||
{
|
||||
return $this->page('cookies', 'Cookie Policy', 'The two cookies this site sets and what they do.');
|
||||
}
|
||||
|
||||
public function dmca(): string
|
||||
{
|
||||
return $this->page('dmca', 'DMCA & Copyright', 'How to submit a takedown or counter-notice, and our repeat-infringer policy.');
|
||||
}
|
||||
|
||||
public function contact(): string
|
||||
{
|
||||
return $this->page('contact', 'Contact', 'Reach the team: support, abuse reports, DMCA and API inquiries.');
|
||||
}
|
||||
|
||||
private function page(string $view, string $title, string $description): string
|
||||
{
|
||||
$this->seo->title($title . ' – ' . config('Site')->name)
|
||||
->description($description)
|
||||
->canonical('/' . $view)
|
||||
->breadcrumbs([['label' => $title]]);
|
||||
|
||||
return $this->render('static/' . $view);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
/**
|
||||
* Crawlable search results page: /search?q=...
|
||||
*/
|
||||
final class Search extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
$q = trim((string) $this->request->getGet('q'));
|
||||
$finder = service('finder');
|
||||
|
||||
$results = [];
|
||||
if ($q !== '') {
|
||||
$results = service('toolSearch')->find($q, 20);
|
||||
service('analytics')->track('search', ['meta' => ['term' => mb_substr($q, 0, 80)]]);
|
||||
}
|
||||
|
||||
$this->seo->title($q !== '' ? "Search: {$q}" : 'Search Tools')
|
||||
->description('Search across all free media tools.')
|
||||
->canonical('/search')
|
||||
->noIndex()
|
||||
->breadcrumbs([['label' => 'Search']]);
|
||||
|
||||
return $this->render('search', [
|
||||
'query' => $q,
|
||||
'results' => $results,
|
||||
'popular' => $finder->popular(6),
|
||||
'categories'=> $finder->categories(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\Pipeline;
|
||||
|
||||
/**
|
||||
* SEO plumbing: robots.txt, sitemap index + child sitemaps (auto-split
|
||||
* by size), Open Graph social cards (GD-generated + cached), PWA
|
||||
* manifest/service worker and OpenSearch description.
|
||||
*/
|
||||
final class Seo extends \CodeIgniter\Controller
|
||||
{
|
||||
private const SITEMAP_URLS_PER_FILE = 5000;
|
||||
|
||||
public function robots(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$base = rtrim(base_url(), '/');
|
||||
$env = ENVIRONMENT === 'production' ? '' : "# development environment — full block\n";
|
||||
|
||||
$body = $env . "User-agent: *\n"
|
||||
. "Allow: /\n"
|
||||
// processing / API / admin surfaces are never indexed
|
||||
. "Disallow: /api/\n"
|
||||
. "Disallow: /upload\n"
|
||||
. "Disallow: /download/\n"
|
||||
. "Disallow: /preview/\n"
|
||||
. "Disallow: /admin\n"
|
||||
. "Disallow: /search\n"
|
||||
. "Disallow: /*?q=\n"
|
||||
. "\nSitemap: {$base}/sitemap.xml\n";
|
||||
|
||||
return response()->setContentType('text/plain; charset=utf-8')->setBody($body);
|
||||
}
|
||||
|
||||
/** Sitemap index pointing at split children. */
|
||||
public function sitemapIndex(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$base = rtrim(base_url(), '/');
|
||||
$tools = service('finder')->countTools();
|
||||
$parts = max(1, (int) ceil($tools / self::SITEMAP_URLS_PER_FILE));
|
||||
|
||||
$entries = [];
|
||||
for ($i = 1; $i <= $parts; ++$i) {
|
||||
$entries[] = ['loc' => "{$base}/sitemap-tools-{$i}.xml"];
|
||||
}
|
||||
foreach (['categories', 'guides', 'pages'] as $kind) {
|
||||
$entries[] = ['loc' => "{$base}/sitemap-{$kind}.xml"];
|
||||
}
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
. '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
|
||||
. implode('', array_map(static fn (array $e): string => '<sitemap><loc>' . htmlspecialchars($e['loc'], ENT_XML1) . '</loc></sitemap>', $entries))
|
||||
. '</sitemapindex>';
|
||||
|
||||
return response()->setContentType('application/xml; charset=utf-8')->setBody($xml);
|
||||
}
|
||||
|
||||
public function sitemapTools(int $page = 1): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$tools = service('finder')->all();
|
||||
usort($tools, static fn ($a, $b) => strcmp($a['slug'], $b['slug']));
|
||||
$chunks = array_chunk($tools, self::SITEMAP_URLS_PER_FILE) ?: [[]];
|
||||
$slice = $chunks[$page - 1] ?? [];
|
||||
|
||||
$urls = '';
|
||||
foreach ($slice as $tool) {
|
||||
$priority = (int) $tool['popularity'] > 4000 ? '1.0' : '0.7';
|
||||
$urls .= $this->urlEntry('/' . $tool['slug'], $tool['seo_title'] ?? $tool['name'], 'weekly', $priority);
|
||||
}
|
||||
|
||||
return $this->xmlResponse($urls);
|
||||
}
|
||||
|
||||
public function sitemapCategories(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$urls = '';
|
||||
foreach (service('finder')->categories() as $category) {
|
||||
$urls .= $this->urlEntry('/' . $category['slug'], $category['name'] ?? '', 'weekly', '0.9');
|
||||
}
|
||||
|
||||
return $this->xmlResponse($urls);
|
||||
}
|
||||
|
||||
public function sitemapGuides(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$urls = '';
|
||||
foreach (model(\App\Models\GuideModel::class)->published(1000) as $guide) {
|
||||
$urls .= $this->urlEntry('/blog/' . $guide['slug'], $guide['title'] ?? '', 'monthly', '0.6', $guide['updated_at'] ?? null);
|
||||
}
|
||||
|
||||
return $this->xmlResponse($urls);
|
||||
}
|
||||
|
||||
public function sitemapPages(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$urls = $this->urlEntry('/', config('Site')->name . ' – Free Online Media Tools', 'daily', '1.0')
|
||||
. $this->urlEntry('/tools', 'All Tools', 'daily', '0.8')
|
||||
. $this->urlEntry('/tools/popular', 'Popular Tools', 'daily', '0.7')
|
||||
. $this->urlEntry('/blog', 'Guides', 'daily', '0.6')
|
||||
. $this->urlEntry('/privacy', 'Privacy Policy', 'yearly', '0.2')
|
||||
. $this->urlEntry('/terms', 'Terms of Service', 'yearly', '0.2')
|
||||
. $this->urlEntry('/cookies', 'Cookie Policy', 'yearly', '0.2')
|
||||
. $this->urlEntry('/dmca', 'DMCA Policy', 'yearly', '0.2')
|
||||
. $this->urlEntry('/contact', 'Contact', 'yearly', '0.2');
|
||||
|
||||
return $this->xmlResponse($urls);
|
||||
}
|
||||
|
||||
private function urlEntry(string $path, string $title = '', string $freq = 'weekly', string $priority = '0.7', ?string $lastmod = null): string
|
||||
{
|
||||
$loc = htmlspecialchars(rtrim(base_url(), '/') . $path, ENT_XML1);
|
||||
|
||||
return "<url><loc>{$loc}</loc>"
|
||||
. ($lastmod !== null && $lastmod !== '' ? '<lastmod>' . date('Y-m-d', strtotime((string) $lastmod)) . '</lastmod>' : '')
|
||||
. "<changefreq>{$freq}</changefreq><priority>{$priority}</priority></url>";
|
||||
}
|
||||
|
||||
private function xmlResponse(string $urls): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
return response()->setContentType('application/xml; charset=utf-8')->setBody(
|
||||
'<?xml version="1.0" encoding="UTF-8"?>'
|
||||
. '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . $urls . '</urlset>'
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Social cards: deterministic brand images cached to disk.
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
public function ogImage(string $slug): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$cacheDir = WRITEPATH . 'og';
|
||||
is_dir($cacheDir) || mkdir($cacheDir, 0755, true);
|
||||
$safe = preg_replace('/[^a-z0-9-]/', '', $slug) ?: 'default';
|
||||
$file = $cacheDir . '/' . $safe . '.png';
|
||||
|
||||
if (! is_file($file)) {
|
||||
$this->renderOgCard($file, $this->cardData($safe));
|
||||
}
|
||||
|
||||
return response()->download($file, null)->setContentType('image/png');
|
||||
}
|
||||
|
||||
private function cardData(string $slug): array
|
||||
{
|
||||
if ($slug === 'default') {
|
||||
return [config('Site')->name, config('Site')->tagline, ''];
|
||||
}
|
||||
$tool = service('finder')->tool($slug);
|
||||
if ($tool !== null) {
|
||||
return [$tool['name'], (string) $tool['short_description'], strtoupper((string) ($tool['primary_output_format'] ?? ''))];
|
||||
}
|
||||
foreach (service('finder')->categories() as $c) {
|
||||
if ($c['slug'] === $slug) {
|
||||
return [$c['name'], (string) ($c['tagline'] ?? ''), count(service('finder')->toolsInCategory($slug)) . ' tools'];
|
||||
}
|
||||
}
|
||||
if (str_starts_with($slug, 'blog-')) {
|
||||
$guide = model(\App\Models\GuideModel::class)->findBySlug(substr($slug, 5));
|
||||
|
||||
return $guide !== null ? [$guide['title'], (string) $guide['excerpt'], 'GUIDE'] : [config('Site')->name, config('Site')->tagline, ''];
|
||||
}
|
||||
|
||||
return [config('Site')->name, config('Site')->tagline, ''];
|
||||
}
|
||||
|
||||
/** Draws a branded 1200x630 card with GD. */
|
||||
private function renderOgCard(string $target, array $lines): void
|
||||
{
|
||||
[$title, $subtitle, $badge] = $lines;
|
||||
$w = 1200;
|
||||
$h = 630;
|
||||
$img = imagecreatetruecolor($w, $h);
|
||||
|
||||
// background gradient (indigo -> violet)
|
||||
$top = imagecolorallocate($img, 49, 46, 129);
|
||||
$bot = imagecolorallocate($img, 109, 40, 217);
|
||||
for ($y = 0; $y < $h; ++$y) {
|
||||
$t = $y / $h;
|
||||
$color = imagecolorallocate(
|
||||
$img,
|
||||
(int) round(49 + (109 - 49) * $t),
|
||||
(int) round(46 + (40 - 46) * $t),
|
||||
(int) round(129 + (217 - 129) * $t)
|
||||
);
|
||||
imageline($img, 0, $y, $w, $y, $color);
|
||||
}
|
||||
|
||||
$white = imagecolorallocate($img, 255, 255, 255);
|
||||
$faint = imagecolorallocate($img, 224, 224, 255);
|
||||
|
||||
// badge chip
|
||||
if ($badge !== '') {
|
||||
imagefilledrectangle($img, 60, 70, 60 + min(360, 40 + strlen($badge) * 16), 120, imagecolorallocate($img, 255, 255, 255));
|
||||
imagestring($img, 5, 80, 84, substr($badge, 0, 24), imagecolorallocate($img, 76, 29, 149));
|
||||
}
|
||||
|
||||
// title wrapped
|
||||
$y = $badge !== '' ? 190 : 150;
|
||||
foreach (str_split(mb_substr($title, 0, 90), 30) as $line) {
|
||||
imagestring($img, 5, 62, $y, mb_substr($line, 0, 28), $white);
|
||||
$y += 42;
|
||||
}
|
||||
$y += 10;
|
||||
|
||||
// subtitle wrapped
|
||||
foreach (str_split(mb_substr($subtitle, 0, 160), 52) as $i => $line) {
|
||||
if ($i > 2) {
|
||||
break;
|
||||
}
|
||||
imagestring($img, 3, 64, $y, mb_substr($line, 0, 50), $faint);
|
||||
$y += 26;
|
||||
}
|
||||
|
||||
// brand footer
|
||||
imagestring($img, 4, 62, $h - 70, config('Site')->name . ' — ' . config('Site')->tagline, $white);
|
||||
|
||||
imagepng($img, $target, 6);
|
||||
imagedestroy($img);
|
||||
}
|
||||
|
||||
public function manifest(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$site = config('Site');
|
||||
$manifest = [
|
||||
'name' => $site->name,
|
||||
'short_name' => $site->name,
|
||||
'description' => $site->description,
|
||||
'start_url' => '/',
|
||||
'display' => 'standalone',
|
||||
'background_color' => '#312e81',
|
||||
'theme_color' => '#4c1d95',
|
||||
'icons' => [
|
||||
['src' => '/favicon.svg', 'sizes' => 'any', 'type' => 'image/svg+xml'],
|
||||
['src' => '/og/default.png', 'sizes' => '512x512', 'type' => 'image/png'],
|
||||
],
|
||||
];
|
||||
|
||||
return response()->setContentType('application/manifest+json')->setBody(json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
/**
|
||||
* Offline-capable shell: caches the tool directory so users can find
|
||||
* tools offline. Never pretends server-side processing works offline.
|
||||
*/
|
||||
public function serviceWorker(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$js = <<<'JS'
|
||||
const CACHE = 'toolvana-v1';
|
||||
const SHELL = ['/tools', '/offline.html'];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
if (event.request.method !== 'GET' || url.pathname.startsWith('/api') || url.pathname.startsWith('/admin')) return;
|
||||
|
||||
// static assets: cache-first
|
||||
if (url.pathname.startsWith('/assets/') || url.pathname === '/favicon.svg') {
|
||||
event.respondWith(caches.open(CACHE).then(async (cache) => {
|
||||
const hit = await cache.match(event.request);
|
||||
const fresh = fetch(event.request).then((res) => { cache.put(event.request, res.clone()); return res; }).catch(() => hit);
|
||||
return hit || fresh;
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// pages: network-first with offline fallback
|
||||
event.respondWith(fetch(event.request).catch(() =>
|
||||
caches.open(CACHE).then((cache) => cache.match(url.pathname).then((hit) => hit || cache.match('/offline.html')))
|
||||
));
|
||||
});
|
||||
JS;
|
||||
|
||||
return response()->setContentType('application/javascript')->setBody($js);
|
||||
}
|
||||
|
||||
public function openSearch(): \CodeIgniter\HTTP\Response
|
||||
{
|
||||
$site = config('Site');
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?><OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">'
|
||||
. '<ShortName>' . htmlspecialchars($site->name, ENT_XML1) . '</ShortName>'
|
||||
. '<Description>' . htmlspecialchars('Search ' . $site->name . ' tools', ENT_XML1) . '</Description>'
|
||||
. '<InputEncoding>UTF-8</InputEncoding>'
|
||||
. '<Url type="text/html" template="' . base_url('/search') . '?q={searchTerm}"/>'
|
||||
. '</OpenSearchDescription>';
|
||||
|
||||
return response()->setContentType('application/opensearchdescription+xml')->setBody($xml);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Libraries\FormatCatalog;
|
||||
use App\Libraries\Pipeline\Youtube as YoutubeLib;
|
||||
|
||||
/**
|
||||
* Renders every individual tool page (/{slug}).
|
||||
*
|
||||
* The page is 100% server-rendered HTML: H1, intro, formats, how-to and
|
||||
* FAQ are all in the first response. Interactive processing loads a
|
||||
* small per-kind JS module afterwards.
|
||||
*/
|
||||
final class Tools extends BaseController
|
||||
{
|
||||
public function show(string $slug): string
|
||||
{
|
||||
$tool = service('finder')->tool($slug);
|
||||
|
||||
if ($tool === null) {
|
||||
return (new Errors())->notFound();
|
||||
}
|
||||
|
||||
$related = service('relatedTools')->forTool($tool);
|
||||
$conversions = service('relatedTools')->conversionsAround($tool);
|
||||
$category = service('finder')->categoryById((int) $tool['category_id']);
|
||||
$guides = $this->guidesFor($tool);
|
||||
|
||||
// capability flags for honest UX
|
||||
$capabilities = [
|
||||
'yt_dlp' => service('pipeline')->youtubeEnabled(),
|
||||
'binaries' => $this->checkBinaries($tool),
|
||||
];
|
||||
|
||||
$this->seo->title($tool['seo_title'])
|
||||
->description($tool['seo_description'])
|
||||
->canonical('/' . $tool['slug'])
|
||||
->breadcrumbs([
|
||||
['label' => $category['name'] ?? 'Tools', 'url' => '/' . ($category['slug'] ?? 'tools')],
|
||||
['label' => $tool['name']],
|
||||
])
|
||||
->webApplication($tool['name'], (string) $tool['short_description'], $this->appCategory($tool))
|
||||
->faqPage(is_array($tool['faqs']) ? $tool['faqs'] : [])
|
||||
->howTo((string) $tool['name'], is_array($tool['how_to']) ? $tool['how_to'] : [])
|
||||
->ogImage('/og/' . $tool['slug'] . '.png');
|
||||
|
||||
foreach (config('Site')->locales as $locale => $_label) {
|
||||
if ($locale === config('Site')->defaultLocale) {
|
||||
continue;
|
||||
}
|
||||
$this->seo->alternate($locale, '/' . $locale . '/' . $tool['slug']);
|
||||
}
|
||||
$this->seo->alternate('x-default', '/' . $tool['slug']);
|
||||
|
||||
$this->trackToolView($tool['slug']);
|
||||
|
||||
return $this->render('tool', [
|
||||
'tool' => $tool,
|
||||
'category' => $category,
|
||||
'related' => $related,
|
||||
'conversions' => $conversions,
|
||||
'guides' => $guides,
|
||||
'capabilities' => $capabilities,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return list<array> */
|
||||
private function guidesFor(array $tool): array
|
||||
{
|
||||
$guides = model(\App\Models\GuideModel::class)->published(30);
|
||||
$hits = [];
|
||||
foreach ($guides as $guide) {
|
||||
$linked = json_decode($guide['tool_slugs'] ?? '[]', true) ?: [];
|
||||
if (in_array($tool['slug'], $linked, true)) {
|
||||
$hits[] = $guide;
|
||||
}
|
||||
}
|
||||
|
||||
return array_slice($hits, 0, 3);
|
||||
}
|
||||
|
||||
private function checkBinaries(array $tool): array
|
||||
{
|
||||
$ok = [];
|
||||
foreach (($tool['requires_binaries'] ?? []) as $bin) {
|
||||
$path = config('Site')->binaries[$bin] ?? null;
|
||||
$ok[$bin] = $path !== null && is_executable($path);
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
private function appCategory(array $tool): string
|
||||
{
|
||||
return match (FormatCatalog::family((string) ($tool['primary_output_format'] ?? ''))) {
|
||||
'video' => 'MultimediaApplication',
|
||||
'audio' => 'MultimediaApplication',
|
||||
'image' => 'DesignApplication',
|
||||
default => 'UtilitiesApplication',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
final class CreateCategories extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
||||
'slug' => ['type' => 'VARCHAR', 'constraint' => 64, 'unique' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 80],
|
||||
'icon' => ['type' => 'VARCHAR', 'constraint' => 32, 'default' => 'tools'],
|
||||
'tagline' => ['type' => 'VARCHAR', 'constraint' => 190, 'null' => true],
|
||||
'description' => ['type' => 'TEXT', 'null' => true],
|
||||
'seo_title' => ['type' => 'VARCHAR', 'constraint' => 190, 'null' => true],
|
||||
'seo_description' => ['type' => 'VARCHAR', 'constraint' => 320, 'null' => true],
|
||||
'intro' => ['type' => 'TEXT', 'null' => true],
|
||||
'faqs' => ['type' => 'JSON', 'null' => true],
|
||||
'sort_order' => ['type' => 'INT', 'unsigned' => true, 'default' => 0],
|
||||
'is_active' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->createTable('categories', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('categories', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
/**
|
||||
* The tool registry — the heart of the platform. Adding a tool is a
|
||||
* database row, never a code change: routes, pages, sitemaps, search,
|
||||
* related-links and the pipeline all read from this table.
|
||||
*/
|
||||
final class CreateTools extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
||||
'category_id' => ['type' => 'INT', 'unsigned' => true],
|
||||
// kind drives which UI/pipeline the page uses:
|
||||
// url paste a URL (YouTube family)
|
||||
// upload file in / file out
|
||||
// text instant text utility (no processing queue)
|
||||
'kind' => ['type' => 'ENUM', 'constraint' => ['url', 'upload', 'text'], 'default' => 'upload'],
|
||||
// structured operation consumed by the pipeline drivers
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
|
||||
'slug' => ['type' => 'VARCHAR', 'constraint' => 120, 'unique' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 140],
|
||||
'short_description' => ['type' => 'VARCHAR', 'constraint' => 320],
|
||||
'description' => ['type' => 'TEXT', 'null' => true],
|
||||
'input_formats' => ['type' => 'JSON', 'null' => true],
|
||||
'output_formats' => ['type' => 'JSON', 'null' => true],
|
||||
'primary_input_format' => ['type' => 'VARCHAR', 'constraint' => 16, 'null' => true],
|
||||
'primary_output_format' => ['type' => 'VARCHAR', 'constraint' => 16, 'null' => true],
|
||||
'icon' => ['type' => 'VARCHAR', 'constraint' => 32, 'default' => 'file'],
|
||||
'seo_title' => ['type' => 'VARCHAR', 'constraint' => 190],
|
||||
'seo_description' => ['type' => 'VARCHAR', 'constraint' => 320],
|
||||
'h1' => ['type' => 'VARCHAR', 'constraint' => 190],
|
||||
'intro' => ['type' => 'TEXT', 'null' => true],
|
||||
'how_to' => ['type' => 'JSON', 'null' => true],
|
||||
'faqs' => ['type' => 'JSON', 'null' => true],
|
||||
'related_slugs' => ['type' => 'JSON', 'null' => true], // curated overrides first
|
||||
'aliases' => ['type' => 'JSON', 'null' => true], // search aliases ("yt mp3")
|
||||
'requires_binaries' => ['type' => 'JSON', 'null' => true], // ["ffmpeg"], ["qpdf"] ...
|
||||
'accepts_mimes' => ['type' => 'JSON', 'null' => true], // upload validation
|
||||
'max_upload_mb' => ['type' => 'INT', 'unsigned' => true, 'default' => 0], // 0 = site default
|
||||
'popularity' => ['type' => 'INT', 'unsigned' => true, 'default' => 0],
|
||||
'use_count' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'status' => ['type' => 'ENUM', 'constraint' => ['active', 'draft', 'inactive'], 'default' => 'active'],
|
||||
'is_featured' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0],
|
||||
'sort_order' => ['type' => 'INT', 'unsigned' => true, 'default' => 0],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->addKey('category_id');
|
||||
$this->forge->addKey('status');
|
||||
$this->forge->addKey(['status', 'popularity']);
|
||||
$this->forge->addForeignKey('category_id', 'categories', 'id', 'CASCADE', 'CASCADE');
|
||||
$this->forge->createTable('tools', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('tools', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
final class CreateGuides extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
||||
'slug' => ['type' => 'VARCHAR', 'constraint' => 160, 'unique' => true],
|
||||
'title' => ['type' => 'VARCHAR', 'constraint' => 190],
|
||||
'excerpt' => ['type' => 'VARCHAR', 'constraint' => 320],
|
||||
'body_md' => ['type' => 'LONGTEXT', 'null' => true],
|
||||
// tools this guide should interlink with (auto "Related tools" block)
|
||||
'tool_slugs' => ['type' => 'JSON', 'null' => true],
|
||||
'category_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
||||
'seo_title' => ['type' => 'VARCHAR', 'constraint' => 190, 'null' => true],
|
||||
'seo_description' => ['type' => 'VARCHAR', 'constraint' => 320, 'null' => true],
|
||||
'reading_minutes' => ['type' => 'INT', 'unsigned' => true, 'default' => 4],
|
||||
'views' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'status' => ['type' => 'ENUM', 'constraint' => ['published', 'draft'], 'default' => 'draft'],
|
||||
'published_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->addKey('status');
|
||||
$this->forge->addKey('published_at');
|
||||
$this->forge->createTable('guides', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('guides', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
/**
|
||||
* Processing queue. States: queued -> processing -> completed | failed,
|
||||
* with cancelled and expired as terminal cleanup states.
|
||||
*/
|
||||
final class CreateJobs extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'CHAR', 'constraint' => 36],
|
||||
// anonymous, hashed — no raw identifiers are ever stored
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 64],
|
||||
'ip_hash' => ['type' => 'CHAR', 'constraint' => 32],
|
||||
'tool_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
||||
'operation' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'params' => ['type' => 'JSON', 'null' => true],
|
||||
'input_file' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
||||
'input_name' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
||||
'input_size' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'input_mime' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
|
||||
'output_file' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
||||
'output_name' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
||||
'output_size' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'status' => ['type' => 'ENUM', 'constraint' => ['queued', 'processing', 'completed', 'failed', 'cancelled', 'expired'], 'default' => 'queued'],
|
||||
'progress' => ['type' => 'TINYINT', 'unsigned' => true, 'default' => 0],
|
||||
'stage' => ['type' => 'VARCHAR', 'constraint' => 32, 'default' => 'queued'],
|
||||
'error' => ['type' => 'TEXT', 'null' => true],
|
||||
'priority' => ['type' => 'TINYINT', 'constraint' => 3, 'default' => 5],
|
||||
'attempts' => ['type' => 'TINYINT', 'unsigned' => true, 'default' => 0],
|
||||
'source' => ['type' => 'ENUM', 'constraint' => ['web', 'api'], 'default' => 'web'],
|
||||
'download_count'=> ['type' => 'INT', 'unsigned' => true, 'default' => 0],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'started_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'completed_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'expires_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->addKey('status');
|
||||
$this->forge->addKey('created_at');
|
||||
$this->forge->addKey('expires_at');
|
||||
$this->forge->addKey('session_id');
|
||||
$this->forge->addForeignKey('tool_id', 'tools', 'id', 'SET NULL', 'CASCADE');
|
||||
$this->forge->createTable('jobs', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('jobs', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
/**
|
||||
* Anonymous product analytics: tool_view, tool_start, tool_success,
|
||||
* tool_failure, download, upload, search, error. No cookies, no PII —
|
||||
* session/ip values are one-way hashes with no lookup table.
|
||||
*/
|
||||
final class CreateAnalyticsEvents extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 32],
|
||||
'tool_slug' => ['type' => 'VARCHAR', 'constraint' => 120, 'null' => true],
|
||||
'format' => ['type' => 'VARCHAR', 'constraint' => 16, 'null' => true],
|
||||
'value' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'session_id' => ['type' => 'VARCHAR', 'constraint' => 64, 'null' => true],
|
||||
'country' => ['type' => 'CHAR', 'constraint' => 2, 'null' => true],
|
||||
'meta' => ['type' => 'JSON', 'null' => true],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->addKey('name');
|
||||
$this->forge->addKey('created_at');
|
||||
$this->forge->addKey('tool_slug');
|
||||
$this->forge->createTable('analytics_events', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('analytics_events', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
final class CreateApiKeys extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
||||
'name' => ['type' => 'VARCHAR', 'constraint' => 100],
|
||||
// only a salted hash is stored; the plaintext token is shown once at creation
|
||||
'key_hash' => ['type' => 'VARCHAR', 'constraint' => 64],
|
||||
'key_prefix' => ['type' => 'VARCHAR', 'constraint' => 12],
|
||||
'rate_limit_per_hour' => ['type' => 'INT', 'unsigned' => true, 'default' => 120],
|
||||
'request_count' => ['type' => 'BIGINT', 'unsigned' => true, 'default' => 0],
|
||||
'is_active' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
|
||||
'last_used_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->addPrimaryKey('id');
|
||||
$this->forge->addUniqueKey('key_hash');
|
||||
$this->forge->createTable('api_keys', true);
|
||||
|
||||
$this->forge->addField([
|
||||
'key' => ['type' => 'VARCHAR', 'constraint' => 100, 'unique' => true],
|
||||
'value' => ['type' => 'TEXT'],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
$this->forge->createTable('settings', true);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->forge->dropTable('api_keys', true);
|
||||
$this->forge->dropTable('settings', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Database\Seeds;
|
||||
|
||||
use App\Libraries\CatalogBuilder;
|
||||
use App\Models\CategoryModel;
|
||||
use App\Models\GuideModel;
|
||||
use App\Models\ToolModel;
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Initial seeder: categories, the complete tool catalog and starter
|
||||
* guides. Idempotent — safe to run repeatedly (tools/categories are
|
||||
* upserted, existing curated edits to non-generated fields survive).
|
||||
*/
|
||||
final class InitialSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->seedCategories();
|
||||
$this->seedTools();
|
||||
$this->seedGuides();
|
||||
}
|
||||
|
||||
private function seedCategories(): void
|
||||
{
|
||||
$categories = [
|
||||
[
|
||||
'slug' => 'youtube-tools', 'name' => 'YouTube Tools', 'icon' => 'play', 'sort_order' => 1,
|
||||
'tagline' => 'Downloaders, converters and metadata tools for YouTube links.',
|
||||
'description' => 'Everything you need for working with YouTube content: video and audio downloaders, thumbnail grabbers, subtitle extractors, transcript tools and link utilities. Paste a URL and get results in seconds.',
|
||||
'seo_title' => 'Free YouTube Tools – Downloaders & Converters Online',
|
||||
'seo_description' => 'Free online YouTube tools: video downloader, YouTube to MP3 converter, thumbnail grabber, subtitle extractor and more. Fast, simple, no software needed.',
|
||||
'intro' => "Our YouTube toolbox handles the whole workflow around videos: saving content for offline use where permitted, extracting audio, grabbing thumbnails at full resolution, exporting captions and analyzing links. Every tool works the same way — paste a URL, press one button, get your file.\n\nTools that download video or audio streams require explicit operator opt-in because platform terms evolve; metadata, thumbnails, transcripts analysis and link utilities always work out of the box.",
|
||||
],
|
||||
[
|
||||
'slug' => 'video-tools', 'name' => 'Video Tools', 'icon' => 'film', 'sort_order' => 2,
|
||||
'tagline' => 'Convert, compress, cut and edit videos right in your browser workflow.',
|
||||
'description' => 'A complete video toolbox: format conversion between MP4, WebM, MOV, MKV and AVI, compression with quality control, trimming, merging, rotating, speed changes, GIF export and audio extraction.',
|
||||
'seo_title' => 'Online Video Tools – Convert, Compress & Edit Videos Free',
|
||||
'seo_description' => 'Convert, compress, trim and edit videos online free. MP4, WebM, MKV support, no watermark, no signup — fast processing on dedicated servers.',
|
||||
'intro' => "Video work shouldn't require a video editor. This collection covers the everyday jobs: converting containers so files play everywhere, compressing oversized recordings under email and upload limits, cutting highlights, fixing orientation and pulling audio tracks out.\n\nFiles upload once, queue on dedicated workers powered by FFmpeg, and come back as downloads. Nothing is published anywhere and temporary copies expire automatically.",
|
||||
],
|
||||
[
|
||||
'slug' => 'audio-tools', 'name' => 'Audio Tools', 'icon' => 'music', 'sort_order' => 3,
|
||||
'tagline' => 'Convert, trim, normalize and boost any audio format.',
|
||||
'description' => 'Audio conversion between MP3, WAV, M4A, AAC, FLAC and OGG plus cutting, merging, loudness normalization and volume boosting — all in the browser.',
|
||||
'seo_title' => 'Online Audio Tools – Convert & Edit Audio Files Free',
|
||||
'seo_description' => 'Free audio converter and editor tools: MP3, WAV, FLAC, M4A conversion, trimming, normalization and volume boost. No installation required.',
|
||||
'intro' => "From podcast producers to musicians sketching ideas, these tools cover the common audio chores: converting between formats with bitrate control, cutting silence or highlights, evening out loudness to broadcast standards and rescuing quiet recordings.\n\nConversions run through FFmpeg with professional codecs — libmp3lame for MP3s, native AAC, lossless FLAC — so output quality matches desktop applications.",
|
||||
],
|
||||
[
|
||||
'slug' => 'image-tools', 'name' => 'Image Tools', 'icon' => 'image', 'sort_order' => 4,
|
||||
'tagline' => 'Compress, convert and clean up images for web and print.',
|
||||
'description' => 'Image compressor, resizer and converter for JPG, PNG, WebP and AVIF; EXIF inspection and removal; favicon generation and more image utilities.',
|
||||
'seo_title' => 'Free Image Tools – Compress & Convert Images Online',
|
||||
'seo_description' => 'Compress JPG and PNG, convert WebP and AVIF, remove EXIF data and resize images online for free. Fast browser-friendly image tools.',
|
||||
'intro' => "Faster websites start with lighter images. Here you can compress photos without visible loss, convert between modern formats like WebP and AVIF, strip location-leaking EXIF data before publishing, and generate every favicon size a modern site needs.\n\nSimple operations finish entirely in your browser — no upload wait at all.",
|
||||
],
|
||||
[
|
||||
'slug' => 'gif-tools', 'name' => 'GIF Tools', 'icon' => 'sparkles', 'sort_order' => 5,
|
||||
'tagline' => 'Create, shrink and dissect animated GIFs.',
|
||||
'description' => 'Make GIFs from videos or image sequences, compress them via palette optimization, resize, retime and extract individual frames.',
|
||||
'seo_title' => 'GIF Tools – Make, Compress & Optimize Animated GIFs',
|
||||
'seo_description' => 'Create GIFs from video, compress heavy animations, resize loops and extract frames — free online GIF toolkit.',
|
||||
'intro' => "GIFs are everywhere but notoriously heavy. This set builds them properly: smart palette generation from video sources, frame-sequence assembly with custom timing, then compression passes that routinely halve file size while keeping motion smooth.\n\nNeed stills instead? The frame extractor dumps numbered PNGs ready for editing.",
|
||||
],
|
||||
[
|
||||
'slug' => 'pdf-tools', 'name' => 'PDF Tools', 'icon' => 'filetext', 'sort_order' => 6,
|
||||
'tagline' => 'Merge, split, compress and convert PDF documents.',
|
||||
'description' => 'PDF merger and splitter, compression presets, page extraction, metadata stripping, rasterization to JPG/PNG and text extraction.',
|
||||
'seo_title' => 'Free PDF Tools – Merge, Split & Compress PDFs Online',
|
||||
'seo_description' => 'Merge PDFs, compress large documents, extract pages and convert PDF to JPG or text online. Free and privacy-friendly.',
|
||||
'intro' => "Document plumbing made easy: combine scanned pages into one file, split contracts back apart, squeeze oversized PDFs under attachment limits, pull out single chapters, or turn pages into images for presentations.\n\nProcessing uses hardened open-source engines (qpdf, Ghostscript, Poppler) inside isolated workers. Documents are never shared and vanish after the retention window.",
|
||||
],
|
||||
[
|
||||
'slug' => 'utilities', 'name' => 'Developer Utilities', 'icon' => 'tool', 'sort_order' => 7,
|
||||
'tagline' => 'Fast little helpers: QR codes, hashes, UUIDs, encoders and lookups.',
|
||||
'description' => 'QR code generator, hash digests, UUID generation, JSON formatting, URL encoding, timestamp and color conversion, Base64 image tools and media lookups.',
|
||||
'seo_title' => 'Developer Utilities – QR Codes, Hashes, UUIDs & More',
|
||||
'seo_description' => 'Free developer utilities: QR generator, MD5/SHA hashes, UUID v4, JSON formatter, URL encoder, timestamp converter and Base64 image tools.',
|
||||
'intro' => "The small tools developers reach for daily. Everything here is instant: text utilities compute entirely in your browser with zero network round-trips, while generators like QR codes produce downloadable assets server-side without logging input.\n\nNo accounts, no quotas worth mentioning, no dark patterns — just tools that work.",
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$existing = model(CategoryModel::class)->where('slug', $category['slug'])->first();
|
||||
if ($existing === null) {
|
||||
model(CategoryModel::class)->insert($category);
|
||||
} else {
|
||||
model(CategoryModel::class)->update($existing['id'], $category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function seedTools(): void
|
||||
{
|
||||
$categories = [];
|
||||
foreach (model(CategoryModel::class)->findAll() as $row) {
|
||||
$categories[$row['slug']] = (int) $row['id'];
|
||||
}
|
||||
|
||||
$model = model(ToolModel::class);
|
||||
$created = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach (CatalogBuilder::build() as $definition) {
|
||||
$categoryId = $categories[$definition['category']] ?? null;
|
||||
if ($categoryId === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = [
|
||||
'category_id' => $categoryId,
|
||||
'kind' => $definition['kind'],
|
||||
'operation' => $definition['operation'],
|
||||
'slug' => $definition['slug'],
|
||||
'name' => $definition['name'],
|
||||
'short_description' => $definition['short_description'],
|
||||
'description' => $definition['description'],
|
||||
'input_formats' => json_encode($definition['input_formats']),
|
||||
'output_formats' => json_encode($definition['output_formats']),
|
||||
'primary_input_format' => $definition['primary_input_format'],
|
||||
'primary_output_format' => $definition['primary_output_format'],
|
||||
'icon' => $definition['icon'],
|
||||
'seo_title' => $definition['seo_title'],
|
||||
'seo_description' => mb_substr($definition['seo_description'], 0, 320),
|
||||
'h1' => $definition['h1'],
|
||||
'intro' => $definition['intro'],
|
||||
'how_to' => json_encode($definition['how_to']),
|
||||
'faqs' => json_encode($definition['faqs']),
|
||||
'related_slugs' => json_encode($definition['related_slugs'] ?? []),
|
||||
'aliases' => json_encode($definition['aliases'] ?? []),
|
||||
'requires_binaries' => json_encode($definition['requires_binaries']),
|
||||
'accepts_mimes' => json_encode($definition['accepts_mimes']),
|
||||
'popularity' => $definition['popularity'],
|
||||
'is_featured' => $definition['is_featured'],
|
||||
'status' => $definition['status'],
|
||||
];
|
||||
|
||||
$existing = $model->where('slug', $row['slug'])->first();
|
||||
if ($existing === null) {
|
||||
$model->insert($row);
|
||||
++$created;
|
||||
} else {
|
||||
// keep editorial overrides made in admin: only refresh structural fields
|
||||
$model->update($existing['id'], [
|
||||
'category_id' => $row['category_id'],
|
||||
'kind' => $row['kind'],
|
||||
'operation' => $row['operation'],
|
||||
'accepts_mimes' => $row['accepts_mimes'],
|
||||
'requires_binaries' => $row['requires_binaries'],
|
||||
'primary_input_format' => $row['primary_input_format'],
|
||||
'primary_output_format'=> $row['primary_output_format'],
|
||||
'input_formats' => $row['input_formats'],
|
||||
'output_formats' => $row['output_formats'],
|
||||
]);
|
||||
++$updated;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Tools seeded: {$created} created, {$updated} refreshed." . PHP_EOL;
|
||||
}
|
||||
|
||||
private function seedGuides(): void
|
||||
{
|
||||
$dir = ROOTPATH . 'content/guides';
|
||||
if (! is_dir($dir)) {
|
||||
echo "No guides directory found — skipping." . PHP_EOL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (glob(rtrim($dir, '/') . '/*.md') ?: [] as $file) {
|
||||
$raw = (string) file_get_contents($file);
|
||||
$frontMatter = self::parseFrontMatter($raw);
|
||||
if ($frontMatter === null) {
|
||||
continue;
|
||||
}
|
||||
[$meta, $body] = $frontMatter;
|
||||
|
||||
$data = [
|
||||
'slug' => $meta['slug'],
|
||||
'title' => $meta['title'],
|
||||
'excerpt' => $meta['excerpt'],
|
||||
'body_md' => $body,
|
||||
// front matter holds a JSON list as raw text — normalize to a real list
|
||||
'tool_slugs' => json_encode(self::decodeList($meta['tools'] ?? [])),
|
||||
'seo_title' => $meta['seo_title'] ?? null,
|
||||
'seo_description' => $meta['seo_description'] ?? null,
|
||||
'reading_minutes' => max(2, (int) ceil(str_word_count(strip_tags($body)) / 220)),
|
||||
'status' => 'published',
|
||||
'published_at' => date('Y-m-d H:i:s', strtotime($meta['date'] ?? 'now')),
|
||||
];
|
||||
|
||||
$existing = model(GuideModel::class)->where('slug', $data['slug'])->first();
|
||||
if ($existing === null) {
|
||||
model(GuideModel::class)->insert($data);
|
||||
} else {
|
||||
// keep editorial fields, refresh derived ones
|
||||
model(GuideModel::class)->update($existing['id'], [
|
||||
'body_md' => $data['body_md'],
|
||||
'tool_slugs' => $data['tool_slugs'],
|
||||
'excerpt' => $data['excerpt'],
|
||||
'reading_minutes' => $data['reading_minutes'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
echo "Guides seeded." . PHP_EOL;
|
||||
}
|
||||
|
||||
/** Front-matter values may be raw JSON lists or comma text. */
|
||||
private static function decodeList(mixed $value): array
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
$decoded = json_decode((string) $value, true);
|
||||
|
||||
return is_array($decoded) ? $decoded : array_filter(array_map('trim', explode(',', (string) $value)));
|
||||
}
|
||||
|
||||
/** @return array{0: array, 1: string}|null */
|
||||
private static function parseFrontMatter(string $raw): ?array
|
||||
{
|
||||
if (! str_starts_with($raw, '---')) {
|
||||
return null;
|
||||
}
|
||||
$end = strpos($raw, '---', 3);
|
||||
if ($end === false) {
|
||||
return null;
|
||||
}
|
||||
$head = substr($raw, 3, $end - 3);
|
||||
$body = ltrim(substr($raw, $end + 3));
|
||||
|
||||
$meta = [];
|
||||
foreach (explode("\n", trim($head)) as $line) {
|
||||
$parts = explode(':', $line, 2);
|
||||
if (count($parts) === 2) {
|
||||
$meta[trim($parts[0])] = trim(trim($parts[1]), "\"'");
|
||||
}
|
||||
}
|
||||
if (empty($meta['slug']) || empty($meta['title'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [$meta, $body];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Admin gate: single-operator password from .env (bcrypt), session
|
||||
* flag, CSRF-protected login. Deliberately simple — swap for SSO or a
|
||||
* users table later without touching routes (same filter alias).
|
||||
*/
|
||||
final class AdminAuth implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
// The login/logout pair is exempted in Filters::$filters config.
|
||||
$uri = uri_string();
|
||||
if ($uri === 'admin/login' || $uri === 'admin/auth/attempt') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! session()->get('tv_admin_ok')) {
|
||||
return redirect()->to('/admin/login');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Developer API authentication: `Authorization: Bearer <token>` mapped
|
||||
* to an api_keys row. Per-key hourly quota enforced here.
|
||||
*/
|
||||
final class ApiAuth implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
if (! $request instanceof \CodeIgniter\HTTP\IncomingRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$header = $request->getHeaderLine('Authorization');
|
||||
if ($header === '' || ! preg_match('/^Bearer\s+(\S+)$/i', $header, $m)) {
|
||||
return $this->deny(401, 'Missing bearer token.');
|
||||
}
|
||||
|
||||
$key = model(\App\Models\ApiKeyModel::class)->findByPlainKey($m[1]);
|
||||
if ($key === null) {
|
||||
return $this->deny(401, 'Invalid token.');
|
||||
}
|
||||
|
||||
// hourly per-key quota
|
||||
$bucket = 'rl_api_' . $key['key_prefix'] . date('YmdH');
|
||||
$used = (int) (cache()->get($bucket) ?? 0);
|
||||
if ($used >= (int) $key['rate_limit_per_hour']) {
|
||||
return response()->setStatusCode(429)
|
||||
->setJSON(['error' => 'quota_exceeded', 'message' => 'Hourly API quota exhausted.']);
|
||||
}
|
||||
cache()->save($bucket, $used + 1, 3700);
|
||||
|
||||
service('request')->api_key = $key; // available to controllers
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function deny(int $status, string $message): ResponseInterface
|
||||
{
|
||||
return response()->setStatusCode($status)
|
||||
->setJSON(['error' => 'unauthorized', 'message' => $message]);
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Cache-backed sliding-window rate limiting for processing endpoints
|
||||
* (API, upload, download). Buckets: per-IP and per-session. Legit users
|
||||
* never hit these limits; abusive automation gets a clean 429.
|
||||
*/
|
||||
final class RateLimit implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
if (! $request instanceof \CodeIgniter\HTTP\IncomingRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$site = config('Site');
|
||||
|
||||
$ipBucket = 'rl_ip_' . md5($request->getIPAddress() . '|' . date('YmdH'));
|
||||
$sessionKey = service('analytics')->sessionHash();
|
||||
$sessBucket = 'rl_ses_' . substr($sessionKey, 0, 16) . '|' . date('YmdH');
|
||||
|
||||
$cache = cache();
|
||||
|
||||
$ipCount = (int) ($cache->get($ipBucket) ?? 0);
|
||||
$seCount = (int) ($cache->get($sessBucket) ?? 0);
|
||||
|
||||
// API tokens carry their own generous quota and bypass the IP window
|
||||
$isApi = str_starts_with(uri_string(), 'api/v1') && $request->getHeaderLine('Authorization') !== '';
|
||||
|
||||
if (! $isApi && $ipCount >= $site->maxJobsPerHourIp * 3) {
|
||||
return $this->tooMany();
|
||||
}
|
||||
if ($seCount >= $site->maxJobsPerHourSession * 3) {
|
||||
return $this->tooMany();
|
||||
}
|
||||
|
||||
$cache->save($ipBucket, $ipCount + 1, 3700);
|
||||
$cache->save($sessBucket, $seCount + 1, 3700);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function tooMany(): ResponseInterface
|
||||
{
|
||||
return response()
|
||||
->setStatusCode(429)
|
||||
->setBody(view('errors/rate_limited'));
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Canonical URL enforcement for SEO: any request that differs from the
|
||||
* canonical lowercase, no-trailing-slash form is 301-redirected before
|
||||
* routing. Prevents duplicate-content across case variants and slashes.
|
||||
*/
|
||||
final class SeoCanonical implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
if (! $request instanceof \CodeIgniter\HTTP\IncomingRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only GET/HEAD matter for indexing.
|
||||
if (! in_array(strtolower($request->getMethod()), ['get', 'head'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = trim(uri_string());
|
||||
if ($path === '') {
|
||||
$path = trim($request->getUri()->getPath(), '/');
|
||||
}
|
||||
|
||||
// Skip files that legitimately end with a slash-like pattern or assets
|
||||
if ($path === '' || str_contains($path, '.')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$needsRedirect = false;
|
||||
|
||||
// trailing slash
|
||||
if (str_ends_with($path, '/')) {
|
||||
$path = rtrim($path, '/');
|
||||
$needsRedirect = true;
|
||||
}
|
||||
|
||||
// uppercase / mixed case
|
||||
if ($path !== mb_strtolower($path)) {
|
||||
$path = mb_strtolower($path);
|
||||
$needsRedirect = true;
|
||||
}
|
||||
|
||||
// multiple consecutive slashes
|
||||
if (str_contains($path, '//')) {
|
||||
$path = preg_replace('#/+#', '/', $path);
|
||||
$needsRedirect = true;
|
||||
}
|
||||
|
||||
if ($needsRedirect) {
|
||||
return redirect()->to($path !== '' ? '/' . ltrim((string) $path, '/') : '/')
|
||||
->setStatusCode(301);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// override core en language system validation or define your own en language validation message
|
||||
return [];
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Models\AnalyticsEventModel;
|
||||
|
||||
/**
|
||||
* Anonymous, privacy-first analytics. Sessions/IPs are stored only as
|
||||
* salted one-way hashes; no cookies are set for tracking and no PII is
|
||||
* ever persisted.
|
||||
*/
|
||||
final class Analytics
|
||||
{
|
||||
public const EVENTS = [
|
||||
'tool_view', 'tool_start', 'tool_success', 'tool_failure',
|
||||
'conversion_format', 'download', 'upload', 'search', 'error',
|
||||
];
|
||||
|
||||
public function sessionHash(): string
|
||||
{
|
||||
static $hash = null;
|
||||
if ($hash === null) {
|
||||
try {
|
||||
// make sure the session actually exists before reading its id
|
||||
if (session_id() === '') {
|
||||
service('session')->start();
|
||||
}
|
||||
$sid = session_id() ?: bin2hex(random_bytes(16));
|
||||
} catch (\Throwable) {
|
||||
$sid = 'no-session'; // CLI/tests: stable, never random
|
||||
}
|
||||
$salt = env('encryption.key', 'tv-fallback-salt');
|
||||
$hash = hash('sha256', $sid . '|' . $salt);
|
||||
}
|
||||
|
||||
return substr($hash, 0, 32);
|
||||
}
|
||||
|
||||
public function ipHash(): string
|
||||
{
|
||||
$salt = env('encryption.key', 'tv-fallback-salt');
|
||||
|
||||
return hash('sha256', service('request')->getIPAddress() . '|' . $salt);
|
||||
}
|
||||
|
||||
public function track(string $name, array $data = []): void
|
||||
{
|
||||
if (! in_array($name, self::EVENTS, true)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
model(AnalyticsEventModel::class)->record([
|
||||
'name' => $name,
|
||||
'tool_slug' => $data['tool'] ?? null,
|
||||
'format' => isset($data['format']) ? mb_substr((string) $data['format'], 0, 16) : null,
|
||||
'value' => (int) ($data['value'] ?? 0),
|
||||
'session_id' => $this->sessionHash(),
|
||||
'country' => $this->guessCountry(),
|
||||
'meta' => json_encode($data['meta'] ?? new \stdClass(), JSON_UNESCAPED_UNICODE),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'analytics write failed: {m}', ['m' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Country from CDN geo headers when present (Cloudflare/Fastly), else null. */
|
||||
private function guessCountry(): ?string
|
||||
{
|
||||
$cc = $_SERVER['HTTP_CF_IPCOUNTRY'] ?? $_SERVER['X-Geo-Country'] ?? null;
|
||||
|
||||
return is_string($cc) && preg_match('/^[A-Z]{2}$/', $cc) === 1 ? $cc : null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user