/** * Compare the theme tables with the local database and check whether there are custom layout sections * * @param array $arrFiles * @param array $arrDbFields * * @return string */ protected function compareThemeFiles($arrFiles, $arrDbFields) { $return = ' <div id="tl_buttons"> <a href="' . ampersand(str_replace('&key=importTheme', '', \Environment::get('request'))) . '" class="header_back" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_theme_import" class="tl_form" method="post"> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="tl_theme_import"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="confirm" value="1">'; $count = 0; // Check the theme data foreach ($arrFiles as $strFile) { $return .= ' <div class="tl_' . ($count++ < 1 ? 't' : '') . 'box theme_import"> <h3>' . basename($strFile) . '</h3> <h4>' . $GLOBALS['TL_LANG']['tl_theme']['tables_fields'] . '</h4>'; // Find the XML file $objArchive = new \ZipReader($strFile); // Continue if there is no XML file if ($objArchive->getFile('theme.xml') === false) { $return .= "\n " . '<p class="tl_red" style="margin:0">' . sprintf($GLOBALS['TL_LANG']['tl_theme']['missing_xml'], basename($strFile)) . "</p>\n</div>"; continue; } // Open the XML file $xml = new \DOMDocument(); $xml->preserveWhiteSpace = false; $xml->loadXML($objArchive->unzip()); $tables = $xml->getElementsByTagName('table'); $blnHasError = false; // Loop through the tables for ($i = 0; $i < $tables->length; $i++) { $rows = $tables->item($i)->childNodes; $table = $tables->item($i)->getAttribute('name'); // Skip invalid tables if ($table != 'tl_theme' && $table != 'tl_style_sheet' && $table != 'tl_style' && $table != 'tl_module' && $table != 'tl_layout' && $table != 'tl_image_size' && $table != 'tl_image_size_item') { continue; } $arrFieldNames = array(); // Loop through the rows for ($j = 0; $j < $rows->length; $j++) { $fields = $rows->item($j)->childNodes; // Loop through the fields for ($k = 0; $k < $fields->length; $k++) { $arrFieldNames[$fields->item($k)->getAttribute('name')] = true; } } $arrFieldNames = array_keys($arrFieldNames); // Loop through the fields foreach ($arrFieldNames as $name) { // Print a warning if a field is missing if (!in_array($name, $arrDbFields[$table])) { $blnHasError = true; $return .= "\n " . '<p class="tl_red" style="margin:0">' . sprintf($GLOBALS['TL_LANG']['tl_theme']['missing_field'], $table . '.' . $name) . '</p>'; } } } // Confirmation if (!$blnHasError) { $return .= "\n " . '<p class="tl_green" style="margin:0">' . $GLOBALS['TL_LANG']['tl_theme']['tables_ok'] . '</p>'; } // Check the custom templates $return .= ' <h4>' . $GLOBALS['TL_LANG']['tl_theme']['custom_templates'] . '</h4>'; $objArchive->reset(); $blnTplExists = false; // Loop through the archive while ($objArchive->next()) { if (strncmp($objArchive->file_name, 'templates/', 10) !== 0) { continue; } if (file_exists(TL_ROOT . '/' . $objArchive->file_name)) { $blnTplExists = true; $return .= "\n " . '<p class="tl_red" style="margin:0">' . sprintf($GLOBALS['TL_LANG']['tl_theme']['template_exists'], $objArchive->file_name) . '</p>'; } } // Confirmation if (!$blnTplExists) { $return .= "\n " . '<p class="tl_green" style="margin:0">' . $GLOBALS['TL_LANG']['tl_theme']['templates_ok'] . '</p>'; } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['compareThemeFiles']) && is_array($GLOBALS['TL_HOOKS']['compareThemeFiles'])) { foreach ($GLOBALS['TL_HOOKS']['compareThemeFiles'] as $callback) { $return .= \System::importStatic($callback[0])->{$callback[1]}($xml, $objArchive); } } $return .= ' </div>'; } // Return the form return $return . ' </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</button> </div> </div> </form>'; }