Журнал изменений
System Architecture Modernization
1. Auto-Discovery System (admin.php)
✓ Replaced manual links.admin.php with auto-discovery ✓ Scans admin/modules/ directory dynamically ✓ New routing: ?name={module}&op={action} ✓ Loads only requested module (vs loading ALL modules) ✓ Added getAdminModuleMeta() for module metadata
2. Function Name Simplification (All 16 Modules)
✓ Removed redundant module prefixes from all functions ✓ Pattern: adminsShow() → admins(), adminsAdd() → add() ✓ Main function named after module: admins(), blocks(), etc. ✓ Switch statements use default: case for main function ✓ Navi functions keep full name: adminsNavi(), blocksNavi()
3. File Changes
✓ configure.php → config.php (renamed) ✓ admin/links/links.admin.php (deleted - no longer needed!)
Modules Refactored (16 total):
- admins: admins(), add(), save(), info()
- blocks: blocks(), new(), add(), edit(), file(), fix()
- categories: categories(), add(), edit(), save(), fix()
- changelog: changelog(), conf(), confsave(), info()
- comments: comments(), edit(), editsave(), conf()
- config: config(), save(), info()
- database: database(), dump(), info()
- editor: editor(), header(), rewrite(), htaccess(), robots()
- favorites: favorites(), conf(), confsave()
- fields: fields(), saveconf(), info()
- groups: groups(), add(), save(), points()
- lang: lang(), file(), save(), conf(), confsave()
- messages: messages(), add(), save(), delete()
- modules: modules(), edit(), info()
- newsletter: newsletter(), add(), save()
- privat: privat(), conf(), confsave()
Benefits:
✅ Cleaner code - no redundant prefixes ✅ Faster - loads only needed module ✅ Auto-discovery - new modules appear automatically ✅ RESTful URLs - consistent name/op pattern ✅ Maintainable - single source of truth in getAdminModuleMeta() ✅ No manual menu file to maintain
Converted all 13 remaining admin modules to RESTful URL structure: Core modules:
- changelog.php: name=changelog&op={show|conf|saveconf|info}
- comments.php: name=comments&op={show|edit|editsave|conf|save}
- config.php: name=config&op={show|save|info}
- database.php: name=database&op={show|dump|del|info}
- editor.php: name=editor&op={function|header|rewrite|htaccess|robots}
Content modules:
- messages.php: name=messages&op={show|add|save|status|delete}
- newsletter.php: name=newsletter&op={show|add|save|delete}
System modules:
- favorites.php: name=favorites&op={show|conf|confsave}
- fields.php: name=fields&op={show|saveconf}
- groups.php: name=groups&op={show|add|save|del|points}
- lang.php: name=lang&op={main|file|save|conf|confsave}
- modules.php: name=modules&op={show|status|edit|editsave|add}
- privat.php: name=privat&op={show|conf|confsave}
All modules now follow consistent pattern: ✓ URL: ?name={module}&op={action} ✓ Simplified switch cases (show vs moduleShow) ✓ Updated navigation, forms, and redirects ✓ Consistent with admins, blocks, categories
Converted 3 admin modules + menu to RESTful URL structure:
- admin/links/links.admin.php: Updated all menu links
- admin/modules/admins.php: name=admins&op={action}
- admin/modules/blocks.php: name=blocks&op={action}
- admin/modules/categories.php: name=categories&op={action}
New URL pattern: ?name={module}&op={action}
- Separates resource (module) from action (operation)
- Simplified switch cases: 'show', 'add', 'save' vs 'moduleShow', 'moduleAdd'
- Updated all forms, redirects, and navigation
Complete language system refactoring across the entire SLAED CMS: Language File Standardization:
Renamed all language files from lang-{language}.php to {iso}.php
- lang-english.php → en.php
- lang-german.php → de.php
- lang-french.php → fr.php
- lang-polish.php → pl.php
- lang-russian.php → ru.php
- lang-ukrainian.php → uk.php
- Applied to admin/language/ and language/ directories
- Converted all language files to single quotes (performance optimization)
- Proper escaping of apostrophes in translations
Configuration Updates:
- Migrated from config_lang.php to config/lang.php
- Updated all language loading references across core files
- Modified language selection blocks and user preferences
Core System Changes:
- Updated core/core.php language loading mechanism
- Modified admin/admin.php for new language structure
- Updated all admin modules to use new language constants
- Refactored block-languages.php for ISO code support
- Updated user preference handling in core/user.php
Module Updates:
- account, contact, forum, voting, whois modules adapted
- All modules now use standardized language system
- Improved language switching functionality
Benefits:
- ISO 639-1 compliant naming convention
- Better internationalization standard compliance
- Cleaner, more maintainable codebase
- Performance improvements through single quotes
Major changes:
- PDO-only architecture (removed mysqli support)
- All SQL queries converted to prepared statements with named placeholders
- Single quotes throughout for performance optimization
- Language files standardized (lang-english.php → en.php)
- PHP 8.1 version check enforced
- sprintf format specifiers fixed (%1$s not %1\$s)
Dead code elimination:
- Removed buildSelect() function (unused)
- Removed 6 unused dropdown variable assignments
Code cleanup:
- Extracted checkWritableConfig() helper to reduce duplication
- Improved maintainability and DRY compliance
Security improvements:
- PDO parameter binding prevents SQL injection
- Automatic type handling and escaping
Applied modern file validation pattern to language files, replacing legacy end_chmod() permission checks with checkConfigFile() helper. Changes in admin/modules/lang.php:
- Replace end_chmod() with checkConfigFile() for language file validation
- Remove redundant opendir() error handling (relying on checkConfigFile)
- Consistent with config file modernization approach
Updated .
- Renamed section 2.10 to "System File Validation and Config Modernization"
- Added language file example demonstrating checkConfigFile() usage
- Clarified that pattern applies to all editable system files, not just configs
This change extends the modern permission validation pattern established for config files to language files and any other writable system files, improving code consistency and maintainability.
Improve the language path helper function to return a complete path instead of an array of path segments, making the code more intuitive.
Changes
Function Signature:
BEFORE:
function lang_get_path(string $mod, string $typ): array {
$mod_dir = $mod ? 'modules/'.$mod.'/' : '';
$lng_wh = $typ ? $typ.'/' : '';
return [$mod_dir, $lng_wh];
}
AFTER:
function getLangPath(string $mod = '', string $typ = ''): string {
$base = BASE_DIR;
$module = $mod ? '/modules/'.$mod : '';
$type = $typ ? '/'.$typ : '';
return $base.$module.$type.'/language';
}
Usage Simplification:
BEFORE (complex):
[$mod_dir, $lng_wh] = lang_get_path($mod, $typ);
$lang_path = BASE_DIR.'/'.$mod_dir.$lng_wh.'language';
$lng_src = BASE_DIR.'/'.$mod_dir.$lng_wh.'language/lang-'.$lng_cn[$j].'.php';
AFTER (clean):
$lang_path = getLangPath($mod, $typ);
$lng_src = $lang_path.'/lang-'.$lng_cn[$j].'.php';
Benefits
✅ Single source of truth for language directory paths ✅ No array destructuring needed ✅ Follows verbNoun naming convention (getLangPath) ✅ Default parameters allow optional mod/typ ✅ Returns complete path - more intuitive API ✅ Reduced code duplication (3 places simplified) ✅ Easier to understand and maintain
Files Modified
admin/modules/lang.php:
- Renamed:
lang_get_path()→getLangPath() - Updated: 3 call sites (lang_file, lang_save)
- Removed: Array destructuring
[$mod_dir, $lng_wh] - Simplified: Path construction logic
- Renamed:
Testing
- Syntax check: ✅ No errors
Path construction works for:
- System languages:
getLangPath()→BASE_DIR/language - Admin languages:
getLangPath('', 'admin')→BASE_DIR/admin/language - Module languages:
getLangPath('news')→BASE_DIR/modules/news/language - Module admin:
getLangPath('news', 'admin')→BASE_DIR/modules/news/admin/language
- System languages:
Complete the lang.php module refactoring by renaming the config file and ensuring all admin language files use LF line endings.
Config File Migration
Renamed:
config/config_lang.php→config/lang.php
Rationale:
- Follows new naming convention (remove
config_prefix) - Consistent with other refactored config files (users.php, fields.php)
- Used by
require_once CONFIG_DIR.'/lang.php'in admin/modules/lang.php
Config variable: $confla (unchanged)
Config structure: Same (key, lang, count, per_page)
Language Files Line Ending Normalization
Updated to LF (6 files):
- admin/language/lang-english.php
- admin/language/lang-french.php
- admin/language/lang-german.php
- admin/language/lang-polish.php
- admin/language/lang-russian.php
- admin/language/lang-ukrainian.php
Changes:
- CRLF → LF line endings
- All files now comply with .editorconfig (end_of_line = lf)
- Consistent with PSR-12 and SLAED coding standards
Impact
✅ Config loading works with new path: CONFIG_DIR.'/lang.php' ✅ All admin language files use Unix line endings ✅ Consistent with rest of codebase after LF normalization ✅ No functional changes - only file formatting
Related Commits
- 3ccf1d5: Normalize line endings to LF (initial CRLF→LF conversion)
- 2a84c79: Refactor lang.php module (config path update)
Modernize language management admin module to PHP 8.4+ standards and document new refactoring patterns discovered during migration.
admin/modules/lang.php Changes
Navigation Function Modernization:
- Replace
navi_gen()withgetAdminTabs() - Simplify function signature: remove unused
$optand$legacyparameters lang_navi(int $opt, int $tab, int $subtab, int $legacy)→lang_navi(int $tab, int $subtab)- Update all 5 function calls throughout the module
Config Include Modernization:
- Replace
include('config/config_lang.php')withrequire_once CONFIG_DIR.'/lang.php' - Use
checkConfigFile('lang.php')instead ofend_chmod()for permission checking - Update config file reference:
config_lang.php→lang.phpinsetConfigFile()
Error Handling Improvements:
- Remove
@error suppression fromopendir()call - Add explicit
falsecheck:if ($dir === false) { ... } - Proper error handling with early return
Code Style Improvements:
Compact one-liners for simple if statements (following 120 char limit):
if ($file !== '.' && $file !== '...' && is_file(...)) $mod[] = $file;if (is_dir(...)) $eadmin = '<a...';while (($file = readdir($dir)) !== false) if (preg_match(...)) $lng_cn[] = ...;for ($j = 0; $j < $cj; $j++) $cont .= '<input...';
- Improved readability while maintaining consistency
Language File Generation Fix:
- Remove
\r\n(CRLF) → usePHP_EOL(LF) for line endings - Remove closing
?>tag from generated language files - Replace double quotes with single quotes:
"define(...)"→'define(...)' - Generated files now fully comply with PSR-12 and SLAED standards
Minor Cleanups:
- Remove unnecessary comment "// Redirect back to same page"
- Consistent spacing and formatting
.
Added three new refactoring patterns based on lang.php migration:
Section 2.8: Remove Error Suppression Operator (@)
- Never use
@operator - handle errors properly - Examples:
@opendir()→ explicitopendir()+if ($dir === false) - Rule: Remove @ and check return values explicitly
Section 2.9: Compact Code Style (One-liners)
- For simple conditions, use compact syntax (max 120 chars)
Examples:
if (condition) $var = value;(instead of multi-line)foreach ($arr as $item) if (check) $result[] = $item;
- Rule: Single-statement conditions can be one-liners
Section 2.10: Config File Modernization
- Use
require_once CONFIG_DIR.'/filename.php'instead ofinclude() - Use
checkConfigFile('filename.php')instead ofend_chmod() - Remove
config_prefix:config_lang.php→lang.php - Consistent config handling across modules
Updated Checklist (Section 14):
Added new items to migration checklist:
- Remove all
@error suppression operators - Use compact one-liners for simple if/for/while (max 120 chars)
- Update config includes to use CONFIG_DIR constant
- Use checkConfigFile() instead of end_chmod()
- Rename config files: remove config_ prefix where applicable
Benefits
✅ Cleaner navigation function signature (2 params instead of 4) ✅ Proper error handling without suppression ✅ Modern config file organization ✅ Generated language files comply with LF line endings ✅ More compact, readable code style ✅ Documented patterns for future refactoring
Testing
- Syntax check: ✅ No errors (
php -l admin/modules/lang.php) - Config file loading: Uses new CONFIG_DIR constant
- Language file generation: Now creates LF files without closing tag
- All 5 lang_navi() calls updated and working
Convert all project files from CRLF (Windows) to LF (Unix) line endings for better cross-platform compatibility and adherence to PHP standards.
Line Endings Normalization
Changed:
- Converted 470+ PHP files from CRLF to LF
- Converted all JS, CSS, HTML, JSON, MD, XML files to LF
- Converted configuration files (.htaccess, .editorconfig, .gitignore) to LF
- Created .gitattributes to enforce LF line endings in repository
Rationale:
- PHP standard (PSR-12) recommends LF line endings
- Production servers run Linux (native LF)
- Reduces Git diff noise and merge conflicts
- Consistent across all platforms (Windows/Linux/Mac)
- Smaller file sizes (LF = 1 byte vs CRLF = 2 bytes)
Documentation Updates
.
- Merged migration-patterns.md into refactoring-rules.md
- Added real-world migration examples (Section 10)
- Added quote style consistency rules (Section 2.3)
- Added array syntax modernization (Section 2.4)
- Expanded input validation with getVar() examples (Section 2.6)
- Added complete migration checklist (Section 14)
- Added performance considerations (Section 15)
- Document now 1030+ lines comprehensive
.
- Created detailed migration progress article for website
- User-friendly explanation of 6.2 → 6.3 changes
- Security improvements documentation
- Performance benefits explanation
- FAQ section for end users
- 400+ lines ready for publication
.gitignore:
- Added .
- Added nul file (Windows artifact)
- Prevents IDE-specific files from entering repository
.gitattributes (NEW):
- Enforces LF line endings for all text files
- Declares binary file types explicitly
- Ensures consistent behavior across platforms
- Auto-normalizes files on checkout/commit
Technical Details
Files affected: 470+ PHP files, 100+ other text files Line ending change: CRLF → LF throughout entire codebase Impact: All modified files show as changed due to line ending normalization Tool used: dos2unix for safe conversion Compatibility: No functional changes, only line ending formatting
Benefits
✅ PHP 8.4 standard compliance (PSR-12) ✅ Linux production server compatibility ✅ Reduced Git conflicts in team environment ✅ Smaller file sizes ✅ Consistent IDE behavior across platforms ✅ Better integration with CI/CD pipelines