ajustes de tradução e documentação

This commit is contained in:
Renan Bernordi 2025-01-29 21:02:39 -03:00
parent c41ca87e4e
commit 3875b19817
4 changed files with 42 additions and 96 deletions

View file

@ -1,43 +1,44 @@
# Arquivo de exemplo para configuração de variáveis de ambiente # Sample file for environment variable configuration
# Copie este arquivo para .env e ajuste os valores conforme necessário # Copy this file to .env and adjust the values as needed
# Nome do site exibido no cabeçalho e meta tags # Site name displayed in the header and meta tags
SITE_NAME=Marreta SITE_NAME=Marreta
# Descrição do site usada em meta tags e SEO # Site description used in meta tags and SEO
SITE_DESCRIPTION="Chapéu de paywall é marreta!" SITE_DESCRIPTION="Chapéu de paywall é marreta!"
# Idioma do site (opções disponíveis: pt-br, en, es, de-de) # Site language (available options: pt-br, en, es, de-de, ru-ru)
# pt-br = Português do Brasil # pt-br = Brazilian Portuguese
# en = English # en = English
# es = Español # es = Spanish
# de-de = German # de-de = German
LANGUAGE=pt-br # ru-ru = Russian
LANGUAGE=pt-br
# URL base do site (sem barra no final) # Base URL of the site (without a trailing slash)
# Use https://localhost para desenvolvimento local # Use https://localhost for local development
SITE_URL=https://localhost SITE_URL=https://localhost
# Lista de servidores DNS para resolução de domínios # List of DNS servers for domain resolution
# Recomendado: AdGuard DNS (94.140.14.14, 94.140.15.15) # Recommended: AdGuard DNS (94.140.14.14, 94.140.15.15)
DNS_SERVERS='94.140.14.14,94.140.15.15' DNS_SERVERS='94.140.14.14,94.140.15.15'
# Modo sem cache (true/false) # Disable cache mode (true/false)
# Quando ativo, desativa o cache do sistema # When enabled, system caching is turned off
DISABLE_CACHE=false DISABLE_CACHE=false
# Configurações de Cache S3 # S3 Cache Settings
S3_CACHE_ENABLED=false S3_CACHE_ENABLED=false
S3_ACCESS_KEY= S3_ACCESS_KEY=
S3_SECRET_KEY= S3_SECRET_KEY=
S3_BUCKET= S3_BUCKET=
S3_REGION=us-east-1 S3_REGION=us-east-1
S3_FOLDER=cache/ S3_FOLDER=cache/
S3_ACL=private S3_ACL=private
S3_ENDPOINT= S3_ENDPOINT=
# Configurações do Selenium # Selenium Configuration
SELENIUM_HOST=localhost:4444 SELENIUM_HOST=localhost:4444
# Configurações de Debug # Debug Settings
DEBUG=true DEBUG=false

View file

@ -7,39 +7,24 @@ require_once __DIR__ . '/../vendor/autoload.php';
use FastRoute; use FastRoute;
/** /**
* Classe Router - Gerenciador de rotas da aplicação
* Router Class - Application route manager * Router Class - Application route manager
* * Manages all application routes, processes HTTP requests, and directs to appropriate handlers
* Esta classe implementa o sistema de roteamento usando FastRoute para:
* - Gerenciar todas as rotas da aplicação
* - Processar requisições HTTP
* - Direcionar para os manipuladores apropriados
*
* This class implements the routing system using FastRoute to:
* - Manage all application routes
* - Process HTTP requests
* - Direct to appropriate handlers
*/ */
class Router class Router
{ {
/** /**
* Instância do dispatcher do FastRoute * @var FastRoute\Dispatcher FastRoute dispatcher instance
* FastRoute dispatcher instance
*/ */
private $dispatcher; private $dispatcher;
/** /**
* Construtor - Inicializa as rotas da aplicação
* Constructor - Initializes application routes * Constructor - Initializes application routes
*/ */
public function __construct() public function __construct()
{ {
$this->dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) { $this->dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
// Rota principal - página inicial
// Main route - home page // Main route - home page
$r->addRoute(['GET','POST'], '/', function() { $r->addRoute(['GET','POST'], '/', function() {
// Inicialização das variáveis para a view principal
// Initialize variables for the main view
require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../inc/Cache.php'; require_once __DIR__ . '/../inc/Cache.php';
require_once __DIR__ . '/../inc/Language.php'; require_once __DIR__ . '/../inc/Language.php';
@ -71,7 +56,6 @@ class Router
} }
} }
// Inicializa o cache para contagem
// Initialize cache for counting // Initialize cache for counting
$cache = new \Cache(); $cache = new \Cache();
$cache_folder = $cache->getCacheFileCount(); $cache_folder = $cache->getCacheFileCount();
@ -79,21 +63,18 @@ class Router
require __DIR__ . '/views/home.php'; require __DIR__ . '/views/home.php';
}); });
// Rota da API - usa URLProcessor em modo API
// API route - uses URLProcessor in API mode // API route - uses URLProcessor in API mode
$r->addRoute('GET', '/api/{url:.+}', function($vars) { $r->addRoute('GET', '/api/{url:.+}', function($vars) {
$processor = new URLProcessor($this->sanitizeUrl($vars['url']), true); $processor = new URLProcessor($this->sanitizeUrl($vars['url']), true);
$processor->process(); $processor->process();
}); });
// Rota da API sem parâmetros - redireciona para raiz
// API route without parameters - redirects to root // API route without parameters - redirects to root
$r->addRoute('GET', '/api[/]', function() { $r->addRoute('GET', '/api[/]', function() {
header('Location: /'); header('Location: /');
exit; exit;
}); });
// Rota de processamento - usa URLProcessor em modo web
// Processing route - uses URLProcessor in web mode // Processing route - uses URLProcessor in web mode
$r->addRoute('GET', '/p/{url:.+}', function($vars) { $r->addRoute('GET', '/p/{url:.+}', function($vars) {
$processor = new URLProcessor($this->sanitizeUrl($vars['url']), false); $processor = new URLProcessor($this->sanitizeUrl($vars['url']), false);
@ -103,11 +84,9 @@ class Router
// Processing route with query parameter or without parameters // Processing route with query parameter or without parameters
$r->addRoute('GET', '/p[/]', function() { $r->addRoute('GET', '/p[/]', function() {
if (isset($_GET['url']) || isset($_GET['text'])) { if (isset($_GET['url']) || isset($_GET['text'])) {
// Sanitize input parameters
$url = isset($_GET['url']) ? $this->sanitizeUrl($_GET['url']) : ''; $url = isset($_GET['url']) ? $this->sanitizeUrl($_GET['url']) : '';
$text = isset($_GET['text']) ? $this->sanitizeUrl($_GET['text']) : ''; $text = isset($_GET['text']) ? $this->sanitizeUrl($_GET['text']) : '';
// Check which parameter is a valid URL
if (filter_var($url, FILTER_VALIDATE_URL)) { if (filter_var($url, FILTER_VALIDATE_URL)) {
header('Location: /p/' . $url); header('Location: /p/' . $url);
exit; exit;
@ -123,7 +102,6 @@ class Router
exit; exit;
}); });
// Rota do manifesto PWA - inclui manifest.php existente
// PWA manifest route - includes existing manifest.php // PWA manifest route - includes existing manifest.php
$r->addRoute('GET', '/manifest.json', function() { $r->addRoute('GET', '/manifest.json', function() {
require __DIR__ . '/views/manifest.php'; require __DIR__ . '/views/manifest.php';
@ -131,17 +109,8 @@ class Router
}); });
} }
/**
* Sanitizes URLs to prevent XSS and injection attacks
* Sanitiza URLs para prevenir ataques XSS e injeções
*
* @param string $url The URL to sanitize
* @return string The sanitized URL
*/
/** /**
* Sanitizes and normalizes URLs * Sanitizes and normalizes URLs
* Sanitiza e normaliza URLs
*
* @param string $url The URL to sanitize and normalize * @param string $url The URL to sanitize and normalize
* @return string|false The cleaned URL or false if invalid * @return string|false The cleaned URL or false if invalid
*/ */
@ -181,11 +150,9 @@ class Router
/** /**
* Sets security headers for all responses * Sets security headers for all responses
* Define cabeçalhos de segurança para todas as respostas
*/ */
private function setSecurityHeaders() private function setSecurityHeaders()
{ {
// Set security headers
header("X-Content-Type-Options: nosniff"); header("X-Content-Type-Options: nosniff");
header("X-Frame-Options: DENY"); header("X-Frame-Options: DENY");
header("X-XSS-Protection: 1; mode=block"); header("X-XSS-Protection: 1; mode=block");
@ -201,7 +168,6 @@ class Router
$httpMethod = $_SERVER['REQUEST_METHOD']; $httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
// Remove a query string mas mantém para processamento
// Strip query string but keep for processing // Strip query string but keep for processing
$queryString = ''; $queryString = '';
if (false !== $pos = strpos($uri, '?')) { if (false !== $pos = strpos($uri, '?')) {
@ -235,4 +201,4 @@ class Router
break; break;
} }
} }
} }

View file

@ -4,13 +4,7 @@ namespace App;
/** /**
* URL Processor * URL Processor
* Processador de URLs * Combines functionality for URL processing, handling both web and API responses
*
* This class combines the functionality of the previous p.php and api.php files
* to provide a unified interface for URL processing, handling both web and API responses.
*
* Esta classe combina as funcionalidades dos arquivos p.php e api.php anteriores
* para fornecer uma interface unificada para processamento de URLs, tratando respostas web e API.
*/ */
class URLProcessor class URLProcessor
{ {
@ -20,8 +14,6 @@ class URLProcessor
/** /**
* Constructor - initializes the processor with URL and mode * Constructor - initializes the processor with URL and mode
* Construtor - inicializa o processador com URL e modo
*
* @param string $url The URL to process * @param string $url The URL to process
* @param bool $isApi Whether to return API response * @param bool $isApi Whether to return API response
*/ */
@ -36,10 +28,7 @@ class URLProcessor
$this->analyzer = new \URLAnalyzer(); $this->analyzer = new \URLAnalyzer();
if ($isApi) { if ($isApi) {
// Initialize language system for API responses
\Language::init(LANGUAGE); \Language::init(LANGUAGE);
// Set API headers
header('Content-Type: application/json'); header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET'); header('Access-Control-Allow-Methods: GET');
@ -48,7 +37,6 @@ class URLProcessor
/** /**
* Sends a JSON response for API requests * Sends a JSON response for API requests
* Envia uma resposta JSON para requisições API
*/ */
private function sendApiResponse(array $data, int $statusCode = 200): void private function sendApiResponse(array $data, int $statusCode = 200): void
{ {
@ -67,7 +55,6 @@ class URLProcessor
/** /**
* Handles web redirects * Handles web redirects
* Trata redirecionamentos web
*/ */
private function redirect(string $path, string $message = ''): void private function redirect(string $path, string $message = ''): void
{ {
@ -78,7 +65,6 @@ class URLProcessor
/** /**
* Process the URL and return appropriate response * Process the URL and return appropriate response
* Processa a URL e retorna resposta apropriada
*/ */
public function process(): void public function process(): void
{ {
@ -106,7 +92,6 @@ class URLProcessor
$additionalInfo = $e->getAdditionalInfo(); $additionalInfo = $e->getAdditionalInfo();
if ($this->isApi) { if ($this->isApi) {
// Add error headers for API responses
header('X-Error-Type: ' . $errorType); header('X-Error-Type: ' . $errorType);
if ($additionalInfo) { if ($additionalInfo) {
header('X-Error-Info: ' . $additionalInfo); header('X-Error-Info: ' . $additionalInfo);
@ -120,7 +105,6 @@ class URLProcessor
] ]
], $e->getCode()); ], $e->getCode());
} else { } else {
// Handle blocked domain with redirect URL for web responses
if ($errorType === \URLAnalyzer::ERROR_BLOCKED_DOMAIN && $additionalInfo) { if ($errorType === \URLAnalyzer::ERROR_BLOCKED_DOMAIN && $additionalInfo) {
$this->redirect(trim($additionalInfo), $errorType); $this->redirect(trim($additionalInfo), $errorType);
} }
@ -139,4 +123,4 @@ class URLProcessor
} }
} }
} }
} }

View file

@ -1,12 +1,7 @@
<?php <?php
/** /**
* PWA Web Manifest Generator * PWA Web Manifest Generator
* * Generates the Web App Manifest (manifest.json) for Progressive Web App (PWA) functionality
* This file generates the Web App Manifest (manifest.json) for Progressive Web App (PWA) functionality.
* It defines the application's behavior when installed on a device and its appearance.
*
* Este arquivo gera o Manifesto Web (manifest.json) para funcionalidade de Progressive Web App (PWA).
* Ele define o comportamento da aplicação quando instalada em um dispositivo e sua aparência.
*/ */
require_once __DIR__ . '/../../config.php'; require_once __DIR__ . '/../../config.php';
@ -55,4 +50,4 @@ $manifest = [
'dir' => 'ltr' 'dir' => 'ltr'
]; ];
echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); echo json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);