Hauptnavigation
~~mein~~ MeinRechner ~~D8~~ cinGG Ideen Tools w3schools personen Drupal Linux DB JavaScript css php msc ect html responsive api symfony frameworks quickstart Komponenten HowTo Grafik MediaWiki Software HKF Leitlinien Buecher WW
<?php /** * detects if stylizer styles are used on that page, * if so, adds needed ls files and settings * * @param array $variables - (ByRef) variables got in hook_preprocess_page */ function adv_theme_styles_add_styles(&$variables) { $styles = _adv_theme_styles_required_styles($variables['css']); if (!empty($styles)) { _adv_theme_styles_add_js($variables, $styles); } } function adv_theme_styles_load_all($reset = FALSE) { ctools_include('export'); return ctools_export_crud_load_all('stylizer', $reset); } /** * * @param type $variables_css * @return array */ function _adv_theme_styles_required_styles($variables_css) { $required_styles = array(); // find all cached css files in ctools/css $path_part = file_create_path('ctools/css/'); $files = array(); foreach ($variables_css as $media) { foreach ($media as $module) { foreach ($module as $path => $val) { if (strpos($path, $path_part) !== FALSE) { $files[] = $path; } } } } if (!empty($files)) { // find styles from stylizer files, with thei css selectors ctools_include('cleanstring'); $styles_all = adv_theme_styles_load_all(); $styles = array(); foreach ($styles_all as $style) { // class selector $styles[$style->name] = '.' . ctools_cleanstring($style->settings['style_base']) . '-' . ctools_cleanstring($style->name); } foreach ($files as $file) { $content = file_get_contents($file); foreach ($styles as $key => $selector) { if (strpos($content, $selector) !== FALSE) { $required_styles[$key] = $selector; break; } } } } return $required_styles; } /** * Adds /js/adv_theme.styles.js and needed js settings * * @param array $variables - (ByRef) variables got in hook_preprocess_page * @param array $styles - stylizer styles used on that page */ function _adv_theme_styles_add_js(&$variables, $styles) { // is style posted ? $style_posted = isset($_POST['adv_theme_stylizer_name']) ? $_POST['adv_theme_stylizer_name'] : false; // create js settings $styles_all = adv_theme_styles_load_all(); $js_setting = array(); foreach ($styles as $key => $selector) { $settings_palette = $styles_all[$key]->settings['palette']; if (!isset($settings_palette)) { continue; } $sel_more = array( 'background' => '', 'header-background' => ' h2', ); $link_key = array( 'background' => 'link-color', 'header-background' => 'header-link-color', ); foreach (array('background', 'header-background') as $region) { // 1. add background settings and selector if (is_array($settings_palette[$region . '-edit'])) { $region_settings = $settings_palette[$region . '-edit']; if ($key === $style_posted) { // posted style: there are new values ! $region_settings = $_POST['palette'][$region . '-edit']; } $js_setting[$key][$region] = $region_settings; $js_setting[$key][$region]['selector'] = $selector . $sel_more[$region]; } // 2. add links $region_links = !empty($settings_palette[$link_key[$region]]) ? $settings_palette[$link_key[$region]] : false; if ($key === $style_posted) { // posted style: there are new values ! $region_links = !empty($_POST['palette'][$link_key[$region]]) ? $_POST['palette'][$link_key[$region]] : false; } // add links and selector if ($region_links) { $js_setting[$key][$region]['links'] = $region_links; $js_setting[$key][$region]['selector'] = $selector . $sel_more[$region]; } } } if (!empty($js_setting)) { // add js file drupal_add_js(drupal_get_path('module', 'adv_theme') . '/js/adv_theme.styles.js'); // add styles settings, needed theming $js_setting = array( 'AdvTheme' => array( 'styles' => $js_setting, 'theming' => _adv_theme_styles_theming_js(), ), ); drupal_add_js($js_setting, 'setting'); $variables['scripts'] = drupal_get_js(); } } /** * Get additional js settings from theming, needed by AdvTheme * * @return array */ function _adv_theme_styles_theming_js() { init_theme(); $corners = theme_get_setting('mix_and_match_corners'); $border_radius = false; if (preg_match('/round-corners-(\d+)/', $corners, $matches)) { $border_radius = $matches[1]; } return array( 'body_bg' => theme_get_setting('mix_and_match_body_bg'), 'radius' => $border_radius, ); }