/**
* Generates a CSS string of all the options
*
* @return string A CSS string of all the values
* @since 1.2
*/
public function generateCSS()
{
$cssString = '';
// These are the option types which are not allowed:
$noCSSOptionTypes = array('text', 'textarea', 'editor');
// Compile as SCSS & minify
require_once trailingslashit(dirname(__FILE__)) . 'inc/scssphp/scss.inc.php';
$scss = new titanscssc();
// Get all the CSS
foreach ($this->allOptionsWithIDs as $option) {
// Only do this for the allowed types
if (in_array($option->settings['type'], $noCSSOptionTypes)) {
continue;
}
// Decide whether or not we should continue to generate CSS for this option
if (!apply_filters('tf_continue_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), true, $option)) {
continue;
}
// Custom generated CSS
$generatedCSS = apply_filters('tf_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), '', $option);
if (!empty($generatedCSS)) {
try {
$testerForValidCSS = $scss->compile($generatedCSS);
$cssString .= $generatedCSS;
} catch (Exception $e) {
}
continue;
}
// Don't render CSS for this option if it doesn't have a value
$optionValue = $this->frameworkInstance->getOption($option->settings['id']);
if ($optionValue == '' || $optionValue == false) {
continue;
}
// Add the values as SaSS variables
$generatedCSS = $this->formCSSVariables($option->settings['id'], $option->settings['type'], $optionValue);
if (!empty($generatedCSS)) {
try {
$testerForValidCSS = $scss->compile($generatedCSS);
$cssString .= $generatedCSS;
} catch (Exception $e) {
}
}
// Add the custom CSS
if (!empty($option->settings['css'])) {
// In the css parameter, we accept the term `value` as our current value,
// translate it into the SaSS variable for the current option
$generatedCSS = str_replace('value', '#{$' . $option->settings['id'] . '}', $option->settings['css']);
if (!empty($generatedCSS)) {
try {
$testerForValidCSS = $scss->compile($generatedCSS);
$cssString .= $generatedCSS;
} catch (Exception $e) {
}
}
}
}
// Add additional CSS added via TitanFramework::createCSS()
foreach ($this->additionalCSS as $css) {
$cssString .= $css . "\n";
}
// Compile as SCSS & minify
if (!empty($cssString)) {
$scss->setFormatter(self::SCSS_COMPRESSION);
try {
$testerForValidCSS = $scss->compile($cssString);
$cssString = $testerForValidCSS;
} catch (Exception $e) {
}
}
return $cssString;
}