/** * Gets style LESS code * @param array $current_style style data to override current style data * @return string style LESS code */ public function getLess($current_style = array()) { $custom_less = ''; $style = $this->get(Registry::get('runtime.layout.style_id')); if (!empty($style['less'])) { $custom_less = $style['less']; $custom_less .= "\n" . $style['custom_css']; } if (!empty($current_style)) { $custom_less .= Less::arrayToLessVars($current_style); } return $custom_less; }
public static function convertPresets401To402() { $theme_name = Registry::get('config.base_theme'); $schema_path = fn_get_theme_path('[themes]/' . $theme_name . '/styles/schema.json', 'C'); $schema = file_get_contents($schema_path); if (!empty($schema)) { $schema = json_decode($schema, true); } db_query('ALTER TABLE ?:bm_layouts CHANGE `preset_id` `preset_id` varchar(64) NOT NULL default ""'); $presets = db_get_array('SELECT * FROM ?:theme_presets'); foreach ($presets as $preset) { $preset['name'] = self::_formPresetName($preset['name']); //We should rename default preset to satori in order to prevent default preset creation. if ($preset['name'] == 'default') { $preset['name'] = 'satori'; } db_query('UPDATE ?:bm_layouts SET preset_id = ?s WHERE preset_id = ?i', $preset['name'], $preset['preset_id']); $preset_path = fn_get_theme_path('[themes]/' . $theme_name . '/styles/data/', 'C'); if (file_exists($preset_path . $preset['name'] . '.less')) { continue; } $preset_data = unserialize($preset['data']); $less = array(); foreach ($preset_data as $section => $fields) { foreach ($fields as $field_id => $value) { switch ($section) { case 'general': $less[$field_id] = empty($value) ? $schema[$section]['fields'][$field_id]['off'] : $schema[$section]['fields'][$field_id]['on']; break; case 'colors': $less[$field_id] = $value; break; case 'fonts': $less[$field_id] = $value['family']; if (!empty($value['size'])) { $field_name = $schema[$section]['fields'][$field_id]['properties']['size']['match']; $field_value = $value['size'] . $schema[$section]['fields'][$field_id]['properties']['size']['unit']; $less[$field_name] = $field_value; } if (!empty($value['style'])) { foreach ($value['style'] as $style_type => $style_value) { $field_name = $schema[$section]['fields'][$field_id]['properties']['style'][$style_type]['match']; $field_value = $schema[$section]['fields'][$field_id]['properties']['style'][$style_type]['property']; $less[$field_name] = $field_value; } } break; case 'backgrounds': $value['transparent'] = isset($value['transparent']) ? $value['transparent'] : false; $value['full_width'] = isset($value['full_width']) ? $value['full_width'] : false; foreach ($value as $bg_name => $bg_value) { switch ($bg_name) { case 'color': $field_name = $schema[$section]['fields'][$field_id]['properties']['color']['match']; $less[$field_name] = $bg_value; break; case 'gradient': $field_name = $schema[$section]['fields'][$field_id]['gradient']['match']; $less[$field_name] = $bg_value; break; case 'image_data': $less[$schema[$section]['fields'][$field_id]['properties']['pattern']] = !empty($bg_value) ? 'url("' . $bg_value . '")' : 'transparent'; break; case 'repeat': $field_name = $schema[$section]['fields'][$field_id]['properties']['repeat']; if (!empty($field_name)) { $less[$field_name] = $bg_value; } break; case 'attachment': $field_name = $schema[$section]['fields'][$field_id]['properties']['attachment']; if (!empty($field_name)) { $less[$field_name] = $bg_value; } break; case 'full_width': if (!isset($schema[$section]['fields'][$field_id]['copies'])) { break; } foreach ($schema[$section]['fields'][$field_id]['copies']['full_width'] as $copies) { if (!empty($value['full_width'])) { if (!empty($copies['inverse'])) { $less[$copies['match']] = $copies['default']; } elseif (isset($less[$copies['source']])) { $less[$copies['match']] = $less[$copies['source']]; } } else { if (empty($copies['inverse'])) { $less[$copies['match']] = $copies['default']; } } } break; case 'transparent': if (!isset($schema[$section]['fields'][$field_id]['copies'])) { break; } foreach ($schema[$section]['fields'][$field_id]['copies']['transparent'] as $copies) { if (!empty($value['transparent'])) { if (!empty($copies['inverse'])) { $less[$copies['match']] = $copies['default']; } elseif (isset($less[$copies['source']])) { $less[$copies['match']] = $less[$copies['source']]; } } else { if (empty($copies['inverse'])) { $less[$copies['match']] = $copies['default']; } } } break; case 'image_name': break; default: fn_print_r('Unprocessed background property: ' . $bg_name); } } break; default: fn_print_r('Error: Section ' . $section . ' was not processed'); } } } $less = Less::arrayToLessVars($less); file_put_contents(fn_get_theme_path('[themes]/' . $theme_name . '/styles/data/' . $preset['name'] . '.less', 'C'), $less); } db_query('DROP TABLE IF EXISTS ?:theme_presets'); return true; }