phpmyadmin/libraries/classes/ThemeGenerator/Layout.php
Saksham Gupta 27b8fbe71c Add automated theme generator (#14293)
Google Summer of Code 2018 project

Signed-off-by: Saksham Gupta <shucon01@gmail.com>
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
2019-01-29 11:28:19 -03:00

114 lines
4.8 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Creates Layout.inc.php file
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
namespace PhpMyAdmin\ThemeGenerator;
/**
* Function to create Layout.inc.php in phpMyAdmin
*
* @package PhpMyAdmin
*/
class Layout
{
/**
* Creates layout.inc.php
*
* @param array $post POST form data
*
* @return string $txt layout.inc.php file data
*/
public function createLayoutFile(array $post)
{
$name = $post['theme_name'];
$file = fopen("themes/" . $name . "/layout.inc.php", "w");
$txt = "<?php\n";
/**
* configures general layout
* for detailed layout configuration please refer to the css files
*/
$txt .= 'declare(strict_types=1);';
/**
* navi frame
*/
// navi frame width
$txt .= '$GLOBALS[\'cfg\'][\'NaviWidth\'] = 240;';
// foreground (text) color for the navi frame
$txt .= '$GLOBALS[\'cfg\'][\'NaviColor\'] = \'#000\';';
// background for the navi frame
$txt .= '$GLOBALS[\'cfg\'][\'NaviBackground\'] = \'' . $post['Navigation_Panel'] . '\';';
// foreground (text) color of the pointer in navi frame
$txt .= '$GLOBALS[\'cfg\'][\'NaviPointerColor\'] = \'#000\';';
// background of the pointer in navi frame
$txt .= '$GLOBALS[\'cfg\'][\'NaviPointerBackground\'] = \'' . $post['Navigation_Hover'] . '\';';
/**
* main frame
*/
// foreground (text) color for the main frame
$txt .= '$GLOBALS[\'cfg\'][\'MainColor\'] = \'' . $post['Text_Colour'] . '\';';
// background for the main frame
$txt .= '$GLOBALS[\'cfg\'][\'MainBackground\'] = \'' . $post['Background_Colour'] . '\';';
// foreground (text) color of the pointer in browse mode
$txt .= '$GLOBALS[\'cfg\'][\'BrowsePointerColor\'] = \'#000\';';
// background of the pointer in browse mode
$txt .= '$GLOBALS[\'cfg\'][\'BrowsePointerBackground\'] = \'#cfc\';';
// foreground (text) color of the marker (visually marks row by clicking on it)
// in browse mode
$txt .= '$GLOBALS[\'cfg\'][\'BrowseMarkerColor\'] = \'#000\';';
// background of the marker (visually marks row by clicking on it) in browse mode
$txt .= '$GLOBALS[\'cfg\'][\'BrowseMarkerBackground\'] = \'#fc9\';';
//server info header
$txt .= '$GLOBALS[\'cfg\'][\'Header\'] = \'' . $post['Header'] . '\';';
/**
* fonts
*/
/**
* the font family as a valid css font family value,
* if not set the browser default will be used
* (depending on browser, DTD and system settings)
*/
$txt .= '$GLOBALS[\'cfg\'][\'FontFamily\'] = \'' . $post['font'] . '\';';
/**
* fixed width font family, used in textarea
*/
$txt .= '$GLOBALS[\'cfg\'][\'FontFamilyFixed\'] = \'monospace\';';
/**
* tables
*/
// border
$txt .= '$GLOBALS[\'cfg\'][\'Border\'] = 0;';
// table header and footer color
// Dialogue Footer color
$txt .= '$GLOBALS[\'cfg\'][\'ThBackground\'] = \'' . $post['Table_Header_and_Footer_Background'] . '\';';
// table header and footer background
//text color footer and dialogue
$txt .= '$GLOBALS[\'cfg\'][\'ThColor\'] = \'' . $post['Table_Header_and_Footer_Text_Colour'] . '\';';
// table data row background
// Dialougue result background
$txt .= '$GLOBALS[\'cfg\'][\'BgOne\'] = \'' . $post['Table_Row_Background'] . '\';';
// table data row background, alternate
$txt .= '$GLOBALS[\'cfg\'][\'BgTwo\'] = \'' . $post['Table_Row_Alternate_Background'] . '\';';
//table hover and selected
$txt .= '$GLOBALS[\'cfg\'][\'BgThree\'] = \'' . $post['Table_Row_Hover_and_Selected'] . '\';';
// Hyperlink Text
$txt .= '$GLOBALS[\'cfg\'][\'Hyperlink\'] = \'' . $post['Hyperlink_Text'] . '\';';
// Group Background
$txt .= '$GLOBALS[\'cfg\'][\'GroupBg\'] = \'' . $post['Group_Background'] . '\';';
// Check if the file is writable as this condition would only occur if files are overwritten.
if ($file) {
fwrite($file, $txt);
fclose($file);
return $txt;
} else {
trigger_error("The layout.inc.php file is not writable by the webserver process. You must change permissions for the theme generator to be able to write the generated theme.", E_USER_ERROR);
return;
}
}
}