PluginProbe
Themify Builder / 7.7.3
Themify Builder v7.7.3
7.8.1 7.8.0 7.7.9 7.7.8 7.7.7 7.7.6 7.7.5 7.7.4 7.7.3 7.7.2 trunk 7.6.0 7.6.1 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.8 7.6.9 7.7.0 7.7.1
themify-builder / modules / module-tab.php

module-tab.php in Themify Builder 7.7.3, at modules/module-tab.php

123 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || exit;
3
4 /**
5 * Module Name: Tab
6 * Description: Display Tab content
7 */
8 class TB_Tab_Module extends Themify_Builder_Component_Module {
9
10
11 public static function get_module_name():string {
12 return __('Tab', 'themify');
13 }
14
15 public static function get_module_icon():string {
16 return 'layout-tab';
17 }
18
19 public static function get_js_css():array {
20 return array(
21 'css' => 1,
22 'js' => 1
23 );
24 }
25
26
27 /**
28 * Render plain content for static content.
29 *
30 * @param array $module
31 * @return string
32 */
33 public static function get_static_content(array $module):string {
34 $mod_settings = $module['mod_settings']+ array(
35 'mod_title_tab' => '',
36 'tab_content_tab' => array()
37 );
38 $text ='' !== $mod_settings['mod_title_tab']?sprintf('<h3>%s</h3>', $mod_settings['mod_title_tab']): '';
39 if (!empty($mod_settings['tab_content_tab'])) {
40 $text .= '<ul>';
41 foreach ($mod_settings['tab_content_tab'] as $content) {
42 $text .= '<li>';
43 if ( ! empty( $content['title_tab'] ) ) {
44 $text .= '<h4>' . $content['title_tab'] . '</h4>';
45 }
46 if ( isset( $content['text_tab'] ) ) {
47 $text .= $content['text_tab'];
48 } else if ( ! empty( $content['builder_content'] ) && is_array( $content['builder_content'] ) ) {
49 $text .= ThemifyBuilder_Data_Manager::_get_all_builder_text_content( $content['builder_content'] );
50 }
51 $text .= '</li>';
52 }
53 $text .= '</ul>';
54 }
55 return $text;
56 }
57
58 public static function get_styling_image_fields() : array {
59 return [
60 'bg_i' => '.ui .tab-nav li.current'
61 ];
62 }
63
64 public static function get_translatable_fields( $module, $classname ) : array {
65 $fields = [];
66 if ( ! empty( $module['mod_settings']['tab_content_tab'] ) ) {
67 foreach ( $module['mod_settings']['tab_content_tab'] as $row_index => $tab ) {
68 if ( isset( $tab['title_tab'] ) ) {
69 $fields[] = [
70 'id' => 'title_tab-' . $row_index,
71 'value' => $tab['title_tab']
72 ];
73 }
74
75 if ( isset( $tab['builder_content'] ) ) {
76 foreach ( $tab['builder_content'] as $subrow ) {
77 Themify_Builder_WPML_Integration::recursive_register_row_translatable_fields( $subrow );
78 }
79 }
80 }
81 }
82
83 return $fields;
84 }
85
86 public static function translate_module( $module_data, $translations ) {
87 /* translate titles */
88 foreach ( $translations as $item_key => $value ) {
89 list( $field, $index ) = explode( '-', $item_key );
90 if ( isset( $module_data['mod_settings']['tab_content_tab'][ $index ][ $field ] ) ) {
91 $module_data['mod_settings']['tab_content_tab'][ $index ][ $field ] = $value;
92 }
93 }
94
95 if ( ! empty( $module_data['mod_settings']['tab_content_tab'] ) ) {
96 foreach ( $module_data['mod_settings']['tab_content_tab'] as $row_index => &$tab ) {
97 if ( isset( $tab['builder_content'] ) ) {
98 foreach ( $tab['builder_content'] as &$subrow ) {
99 $subrow = Themify_Builder_WPML_Integration::recursive_translate_fields( $subrow );
100 }
101 }
102 }
103 }
104
105 return $module_data;
106 }
107
108 /**
109 * Returns a flat array of all nested modules
110 */
111 public static function get_nested_modules( array $data ) : array {
112 $modules = [];
113 if ( isset( $data['mod_settings']['tab_content_tab'][0]['builder_content'] ) ) {
114 foreach ( $data['mod_settings']['tab_content_tab'] as $tab ) {
115 foreach ( $tab['builder_content'] as $row ) {
116 $modules = array_merge( $modules, Themify_Builder::_get_modules_recursive( $row ) );
117 }
118 }
119 }
120
121 return $modules;
122 }
123 }