public function updateColorConfig($data)
{
$configPath = getViewPath() . 'css' . DS . 'config.css';
if (!file_exists($configPath)) {
return false;
}
$File = new File($configPath);
$config = $File->read();
$settings = array('MAIN' => 'color_main', 'SUB' => 'color_sub', 'LINK' => 'color_link', 'HOVER' => 'color_hover');
$settingExists = false;
foreach ($settings as $key => $setting) {
if (empty($data['ThemeConfig'][$setting])) {
$config = preg_replace("/\n.+?" . $key . ".+?\n/", "\n", $config);
} else {
$config = str_replace($key, '#' . $data['ThemeConfig'][$setting], $config);
$settingExists = true;
}
}
$File = new File(WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css', true, 0666);
$File->write($config);
$File->close();
if (!$settingExists) {
unlink($configPath);
}
return true;
}