/** * If Flow editor is active, generates and returns CSS based on global, template, template part and module styling. Loads Google Fonts. * If Flow is not active, loads Google Fonts. * * @since 1.0.0 * * @uses TF_Shortcodes::row_styles() * @uses TF_Styling_Control::get_styling_global_settings() * @uses TF_Module_Loader::get_module() * @uses TF_Module::styles() * @uses TF_Engine_Style_Loader::get_fonts_to_load() * @uses TF_Engine_Style_Loader::build_css_rule() * * @param array $styles Styles saved. Only used if Flow editor is active. * @param bool $only_load_fonts Parses selectors and properties looking for references to fonts. If any is found, it's loaded. * @param string $format Whether to return a continuous string or an associative array. * * @return string|void Valid CSS if Flow editor is active, otherwise nothing is returned. */ public function generate_css($styles, $only_load_fonts = false, $format = 'string') { global $tf_modules, $tf_styling_control; $selectors = array(); foreach ($styles as $context => $module) { if ('row' == $module['module']) { $selector = TF_Shortcodes::row_styles(); $context_selector = '.tf_row_block_' . $context; } else { if ('global' == $module['module']) { if (!$tf_styling_control instanceof TF_Styling_Control) { global $TF; include_once $TF->framework_path() . '/classes/theme-elements/class-tf-styling-control.php'; $GLOBALS['tf_styling_control'] = new TF_Styling_Control(); } $selector = $tf_styling_control->get_styling_global_settings(); $context_selector = ''; } else { $module_instance = $tf_modules->get_module($module['module']); if (false !== $module_instance) { $selector = $module_instance->styles(); $context_selector = '.tf_module_block_' . $context; } } } if (isset($module['settings']) && count($module['settings']) > 0) { foreach ($module['settings'] as $style_key => $properties) { if (!isset($selector[$style_key]['selector'])) { continue; } if ($only_load_fonts) { $selectors[] = array('properties' => $properties); } else { $chain_with_context = isset($selector[$style_key]['chain_with_context']) && true == $selector[$style_key]['chain_with_context']; $selectors[] = array('context' => $context_selector, 'selector' => $selector[$style_key]['selector'], 'chain' => $chain_with_context, 'properties' => $properties); } } } } if ($only_load_fonts) { $this->get_fonts_to_load($selectors); } else { return $this->build_css_rule($selectors, $format); } }
public function render_selector_style($module) { ?> <?php if ('row' == $module) { $tf_styling_selectors = $this->parse_style(TF_Shortcodes::row_styles()); } else { if ('global' == $module) { $tf_styling_selectors = $this->parse_style($this->get_styling_global_settings()); // param: module slug } else { $tf_styling_selectors = $this->get_style($module); } } ?> <?php if (count($tf_styling_selectors) > 0) { ?> <ul class="tf_elements_list"> <?php foreach ($tf_styling_selectors as $key => $param) { $li_state_class = count($param['children']) > 0 ? ' tf_list_has_child' : ''; $basic_styling = isset($param['basic_styling']) ? ' data-tf-basic-styling="' . implode(',', $param['basic_styling']) . '"' : ''; ?> <li class="<?php echo esc_attr($li_state_class); ?> "> <?php $parent_attr = isset($param['selector']) && !empty($param['selector']) ? ' data-tf-style-selector="' . esc_attr($param['selector']) . '" data-tf-style-selector-key="' . $key . '"' : ''; $chain = isset($param['chain_with_context']) && $param['chain_with_context'] ? ' data-tf-chain-with-context="chain"' : ''; ?> <span class="tf_element_list_title"<?php echo $parent_attr . $chain; echo $basic_styling; ?> ><?php echo $param['label']; ?> </span> <?php if (count($param['children']) > 0) { ?> <ul> <?php foreach ($param['children'] as $child_key => $child_param) { ?> <li> <?php $parent_child_attr = isset($child_param['selector']) && !empty($child_param['selector']) ? ' data-tf-style-selector="' . esc_attr($child_param['selector']) . '" data-tf-style-selector-key="' . $child_key . '"' : ''; $basic_styling = isset($child_param['basic_styling']) ? ' data-tf-basic-styling="' . implode(',', $child_param['basic_styling']) . '"' : ''; $chain = isset($child_param['chain_with_context']) && $child_param['chain_with_context'] ? ' data-tf-chain-with-context="chain"' : ''; ?> <span class="tf_element_list_title"<?php echo $parent_child_attr . $chain; echo $basic_styling; ?> ><?php echo $child_param['label']; ?> </span> </li> <?php } ?> </ul> <?php } ?> </li> <?php } ?> </ul> <?php } // count $tf_styling_selectors ?> <?php }
/** * Fires when module form saved. * * @since 1.0.0 * @access public * @param array $post_data * @return json */ public function save_row_form($post_data) { $atts = array(); $fields = array_merge(array_keys(TF_Shortcodes::row_fields()), array('sc_id')); foreach ($fields as $key) { if (isset($post_data[$key])) { $atts[$key] = htmlentities($post_data[$key], ENT_QUOTES, 'UTF-8'); } } $atts['editable_markup'] = 'true'; global $tf_editor_ui; $shortcode_string = TF_Shortcodes::to_shortcode('tf_row', $atts); $tf_editor_ui->force_editable_shortcode($post_data['_mode']); $shortcode = do_shortcode($shortcode_string); $data = array('atts' => $atts, 'element' => $shortcode); wp_send_json_success($data); }