* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE */ namespace Joomla\Component\MokoBackup\Administrator\Field; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Form\FormField; use Joomla\CMS\Language\Text; class DatabaseTablesField extends FormField { protected $type = 'DatabaseTables'; protected function getInput(): string { $db = Factory::getDbo(); $tables = $db->getTableList(); $prefix = $db->getPrefix(); // Parse current exclusions (newline-separated, with optional :data-only suffix) $excludeData = []; $excludeStructure = []; if (!empty($this->value)) { $lines = array_filter(array_map('trim', explode("\n", str_replace("\r", '', $this->value)))); foreach ($lines as $line) { // Normalize table name to real prefix for comparison if (str_ends_with($line, ':data-only')) { $tableName = str_replace('#__', $prefix, substr($line, 0, -10)); $excludeData[$tableName] = true; } elseif (str_ends_with($line, ':structure-only')) { $tableName = str_replace('#__', $prefix, substr($line, 0, -15)); $excludeStructure[$tableName] = true; } else { // No suffix = exclude both (backward compatible) $tableName = str_replace('#__', $prefix, $line); $excludeData[$tableName] = true; $excludeStructure[$tableName] = true; } } } $id = htmlspecialchars($this->id, ENT_QUOTES, 'UTF-8'); $name = htmlspecialchars($this->name, ENT_QUOTES, 'UTF-8'); $html = '
'; $html .= ''; $html .= '
' . Text::_('COM_MOKOBACKUP_FIELD_EXCLUDE_TABLES_HELP') . '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($tables as $table) { $dataChecked = isset($excludeData[$table]) ? ' checked' : ''; $structureChecked = isset($excludeStructure[$table]) ? ' checked' : ''; // Convert to #__ notation for storage $storeValue = $table; if (str_starts_with($table, $prefix)) { $storeValue = '#__' . substr($table, \strlen($prefix)); } $safeValue = htmlspecialchars($storeValue, ENT_QUOTES, 'UTF-8'); $safeTable = htmlspecialchars($table, ENT_QUOTES, 'UTF-8'); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . Text::_('COM_MOKOBACKUP_FIELD_EXCLUDE_DATA') . '' . Text::_('COM_MOKOBACKUP_FIELD_EXCLUDE_STRUCTURE') . '' . Text::_('COM_MOKOBACKUP_FIELD_TABLE_NAME') . '
' . $safeTable . '
'; // Script to sync checkboxes to hidden field $html .= << SCRIPT; return $html; } }