/** * Shortcode render. * * @since 1.0.0 * @access public * @return json */ public function shortcode_render() { // Check ajax referer check_ajax_referer($this->action_nonce, $this->field_nonce); $type = isset($_POST['type']) ? $_POST['type'] : ''; $method = isset($_POST['method']) ? $_POST['method'] : 'add'; $mode = isset($_POST['mode']) ? $_POST['mode'] : 'frontend'; $data = array(); switch ($method) { case 'duplicate': global $TF_Layout; if ('module' == $type) { global $tf_modules, $tf_styles; $module_instance = $tf_modules->get_module($_POST['module']); $atts = isset($_POST['shortcode_params']) ? $_POST['shortcode_params'] : ''; $content = isset($_POST['shortcode_content']) ? wp_kses_stripslashes($_POST['shortcode_content']) : ''; $template_id = (int) $_POST['template_id']; $data_styling = isset($_POST['data_styling']) ? json_decode(stripslashes($_POST['data_styling']), true) : array(); $styles = array(); $atts['sc_id'] = TF_Model::generate_block_id(); // generate new sc_id if (is_array($data_styling) && count($data_styling) > 0) { $data_styling['ID'] = $atts['sc_id']; $styles[$atts['sc_id']] = array('module' => $data_styling['module']); if (isset($data_styling['settings']) && count($data_styling['settings']) > 0) { foreach ($data_styling['settings'] as $fields) { $setting_key = ''; foreach ($fields as $key => $val) { if ('SettingKey' == $key) { $setting_key = $val; } else { $styles[$atts['sc_id']]['settings'][$setting_key][$key] = stripslashes_deep($val); } } } } } $render_style = ''; if (count($styles) > 0) { $render_style = '<style type="text/css" id="tf-template-temp-' . $atts['sc_id'] . '-css">' . $tf_styles->generate_css($styles) . '</style>'; } if (isset($atts['editable_markup'])) { unset($atts['editable_markup']); } if (get_magic_quotes_gpc()) { $atts = stripslashes_deep($atts); } $shortcode_string = $module_instance->to_shortcode($atts, $content); global $post; $post = get_post($template_id); setup_postdata($post); $shortcode = $TF_Layout->render($shortcode_string); $data = array('module' => sanitize_text_field($_POST['module']), 'content' => tf_escape_atts($content), 'atts' => $atts, 'caption' => $module_instance->name, 'element' => $shortcode, 'styles' => $render_style, 'model' => $data_styling); } else { if ('row' == $type) { global $tf_editor_ui; $row_data = isset($_POST['row_data']) ? stripslashes_deep($_POST['row_data']) : array(); tf_recursive_unset($row_data, 'sc_id'); tf_recursive_unset($row_data, 'editable_markup'); $shortcode = TF_Model::array_to_shortcode(array($row_data)); $tf_editor_ui->force_editable_shortcode($mode); $data = $TF_Layout->render($shortcode); } } break; } wp_send_json_success($data); }
/** * Escape shortcode attributes to be used in html5 data attribute. * * @since 1.0.0 * @param string $value */ function tf_escape_atts($value) { if (is_array($value)) { $value = array_map('tf_escape_atts', $value); } elseif (is_object($value)) { $vars = get_object_vars($value); foreach ($vars as $key => $data) { $value->{$key} = tf_escape_atts($data); } } elseif (is_string($value)) { $value = html_entity_decode($value); } return $value; }
/** * Shortcode row * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public static function row($atts, $content = null) { global $pagenow; // Use wp_parse_args instead of shortcode_atts because we use custom filter. $atts = apply_filters('tf_shortcode_atts', wp_parse_args($atts, array('class' => '', 'gutter' => 'tf_gutter_default', 'grid' => '1-col', 'overlay_color' => '', 'row_anchor' => '', 'row_height' => 'tf_row_height_default', 'row_width' => 'tf_row_width_default', 'editable_markup' => 'false'))); $before = ''; $after = ''; /* additional html attributes to add to the row wrapper */ $html_atts = ''; $classes = array_merge(array('tf_row', $atts['gutter'], $atts['row_height'], $atts['row_width'], 'tf_row_block_' . $atts['sc_id']), explode(' ', $atts['class'])); if (!is_admin()) { $classes[] = 'grid_' . $atts['grid']; } $row_attrs = apply_filters('tf_row_attrs', array('class' => $classes), $atts); $row_attrs['class'] = implode(' ', apply_filters('tf_row_classes', $row_attrs['class'])); foreach ($row_attrs as $key => $value) { $html_atts .= sprintf(" %s='%s'", $key, esc_attr($value)); // using single quotes in case we need to store json objects in attributes } if (isset($atts['editable_markup']) && 'true' == $atts['editable_markup']) { $style_link = sprintf('<div class="tf_styling_menu tf_row_top_item"><a href="#" title="%s" class="tf_styling_row tf-tooltips"><span class="ti-brush"></span></a></div>', __('Styling', 'themify-flow')); if ('backend' == TF_Model::get_current_builder_mode()) { $style_link = ''; } $before = sprintf(' <div class="tf_row_top tf_interface"> <div class="tf_row_top_toolbar"> <div class="tf_row_menu"> <div class="menu_icon"></div> <ul class="tf_dropdown"> <li><a href="#" class="tf_option_row"><span class="ti-pencil"></span> %s</a></li> <li><a href="#" class="tf_duplicate_row"><span class="ti-layers"></span> %s</a></li> <li><a href="#" class="tf_delete_row"><span class="ti-close"></span> %s</a></li> </ul> </div> %s %s </div> <div class="toggle_row"></div> </div> <div class="tf_row_wrapper"><div class="tf_row_inner">', __('Options', 'themify-flow'), __('Duplicate', 'themify-flow'), __('Delete', 'themify-flow'), tf_grid_lists('row', $atts['gutter']), $style_link); $before .= '<div class="tf_row_content">'; $after = '</div></div></div>'; $print_atts = $atts; unset($print_atts['editable_markup']); $output = sprintf('<div data-tf-shortcode="%s" data-tf-atts="%s"%s>', 'tf_row', esc_attr(json_encode(tf_escape_atts($print_atts))), $html_atts); } else { $before = '<div class="tf_row_wrapper"><div class="tf_row_inner">'; $after = '</div><!-- /tf_row_inner --></div><!-- /tf_row_wrapper -->'; $output = sprintf('<div %s>', $html_atts); } $output .= apply_filters('tf_row_before', $before, $atts); $output .= do_shortcode($content); $output .= apply_filters('tf_row_after', $after, $atts); $output .= '</div><!-- /tf_row -->'; return apply_filters('tf_shortcode_row', $output, $atts); }
/** * Filter shortcode to added editable markup for module edit. * * @since 1.0.0 * @access public * @param string $output * @param string $module_slug * @param array $atts * @return string */ public function shortcode_module_render_backend($output, $module_slug, $atts, $content) { global $TF, $tf_modules; $module = $tf_modules->get_module($module_slug); if (isset($atts['editable_markup']) && 'true' == $atts['editable_markup'] && !$TF->in_template_part && !$TF->in_archive_loop) { $output = sprintf('<div class="tf_module active_module" data-tf-module-title="%1$s" data-tf-module="%2$s" data-tf-content="%3$s" data-tf-atts="%4$s"> <div class="tf_active_module_menu"> <div class="menu_icon"> </div> <ul class="tf_dropdown"> <li> <a class="tf_lightbox_link_module-edit" title="%5$s" href="#"> <span class="ti-pencil"></span> %5$s </a> </li> <li> <a class="tf_lightbox_link_module-duplicate" title="%6$s" href="#"> <span class="ti-layers"></span> %6$s </a> </li> <li> <a class="tf_lightbox_link_module-delete" title="%7$s" href="#"> <span class="ti-close"></span> %7$s </a> </li> </ul> </div> <div class="module_label"> <strong class="module_name">%8$s</strong> <em class="module_excerpt"></em> </div> </div>', esc_attr($module->name), $module_slug, esc_attr($content), esc_attr(json_encode(tf_escape_atts($atts))), __('Edit', 'themify-flow'), __('Duplicate', 'themify-flow'), __('Delete', 'themify-flow'), esc_attr($module->name)); } return $output; }