/** * Renders and caches the CSS for a builder layout. * * @since 1.0 * @return void */ public static function render_css() { // Delete the old file. FLBuilderModel::delete_asset_cache('css'); // Get info on the new file. $nodes = FLBuilderModel::get_categorized_nodes(); $global_settings = FLBuilderModel::get_global_settings(); $asset_info = FLBuilderModel::get_asset_info(); $post_id = FLBuilderModel::get_post_id(); $post = get_post($post_id); $compiled = array(); // Global css $css = file_get_contents(FL_BUILDER_DIR . '/css/fl-builder-layout.css'); // Global RTL css if (is_rtl()) { $css .= file_get_contents(FL_BUILDER_DIR . '/css/fl-builder-layout-rtl.css'); } // Responsive css if ($global_settings->responsive_enabled) { $css .= '@media (max-width: ' . $global_settings->medium_breakpoint . 'px) { '; $css .= file_get_contents(FL_BUILDER_DIR . '/css/fl-builder-layout-medium.css'); $css .= ' }'; $css .= '@media (max-width: ' . $global_settings->responsive_breakpoint . 'px) { '; $css .= file_get_contents(FL_BUILDER_DIR . '/css/fl-builder-layout-responsive.css'); if (!isset($global_settings->auto_spacing) || $global_settings->auto_spacing) { $css .= file_get_contents(FL_BUILDER_DIR . '/css/fl-builder-layout-auto-spacing.css'); } $css .= ' }'; } // Global row margins $css .= '.fl-row-content-wrap { margin: ' . $global_settings->row_margins . 'px; }'; // Global row padding $css .= '.fl-row-content-wrap { padding: ' . $global_settings->row_padding . 'px; }'; // Global row width $css .= '.fl-row-fixed-width { max-width: ' . $global_settings->row_width . 'px; }'; // Global module margins $css .= '.fl-module-content { margin: ' . $global_settings->module_margins . 'px; }'; // Loop through rows foreach ($nodes['rows'] as $row) { // Instance row css ob_start(); include FL_BUILDER_DIR . 'includes/row-css.php'; $css .= ob_get_clean(); // Instance row margins $css .= self::render_row_margins($row); // Instance row padding $css .= self::render_row_padding($row); } // Loop through the columns. foreach ($nodes['columns'] as $col) { // Instance column css ob_start(); include FL_BUILDER_DIR . 'includes/column-css.php'; $css .= ob_get_clean(); // Instance column margins $css .= self::render_column_margins($col); // Instance column padding $css .= self::render_column_padding($col); // Get the modules in this column. $modules = FLBuilderModel::get_modules($col); } // Loop through the modules. foreach ($nodes['modules'] as $module) { // Global module css $file = $module->dir . 'css/frontend.css'; $file_responsive = $module->dir . 'css/frontend.responsive.css'; // Only include global module css that hasn't been included yet. if (!in_array($module->settings->type, $compiled)) { // Add to the compiled array so we don't include it again. $compiled[] = $module->settings->type; // Get the standard module css. if (file_exists($file)) { $css .= file_get_contents($file); } // Get the responsive module css. if ($global_settings->responsive_enabled && file_exists($file_responsive)) { $css .= '@media (max-width: ' . $global_settings->responsive_breakpoint . 'px) { '; $css .= file_get_contents($file_responsive); $css .= ' }'; } } // Instance module css $file = $module->dir . 'includes/frontend.css.php'; $settings = $module->settings; $id = $module->node; if (file_exists($file)) { ob_start(); include $file; $css .= ob_get_clean(); } // Instance module margins $css .= self::render_module_margins($module); if (!isset($global_settings->auto_spacing) || $global_settings->auto_spacing) { $css .= self::render_responsive_module_margins($module); } } // Default page heading if ($post && !$global_settings->show_default_heading && ($post->post_type == 'page' || $post->post_type == 'fl-builder-template')) { $css .= $global_settings->default_heading_selector . ' { display:none; }'; } // Save the css if (!empty($css)) { $css = apply_filters('fl_builder_render_css', $css, $nodes, $global_settings); $css = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $css); $css = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $css); file_put_contents($asset_info['css'], $css); } }
/** * Renders the markup for all modules in a column. * * @since 1.0 * @param string $parent_id A column node ID. * @return void */ public static function render_modules($parent_id) { $modules = FLBuilderModel::get_modules($parent_id); foreach ($modules as $module) { $settings = $module->settings; include FL_BUILDER_DIR . 'includes/module.php'; } }