PluginProbe
GetResponse Forms by Optin Cat / 1.5.2
GetResponse Forms by Optin Cat v1.5.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / powerups / 4_new_css / powerup.php

powerup.php in GetResponse Forms by Optin Cat 1.5.2, at powerups/4_new_css/powerup.php

192 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function powerup_new_css() {
4 paf_options( array(
5 'eoi_powerup_new_css' => array(
6 'type' => 'checkbox',
7 'options' => array(
8 'on' => __( 'Enabled (recommended)' ),
9 ),
10 'page' => 'eoi_powerups',
11 'title' => __( 'New CSS' ),
12 'description' => sprintf( '<p id="fca_eoi_new_css_toggle" class="description eoi_powerup_description">%s</p>', __( 'Enhances the base CSS for responsiveness and compatibility.' ) ),
13 )
14 ) );
15 }
16
17 function powerup_new_css_is_active() {
18 $paf = get_option( 'paf' );
19 $key = 'eoi_powerup_new_css';
20
21 return ! empty( $paf )
22 && is_array( $paf )
23 && ! empty( $paf[ $key ] )
24 && is_array( $paf[ $key ] )
25 && in_array( 'on', $paf[ $key ] );
26 }
27
28 function powerup_new_css_set_active( $active ) {
29 $paf = get_option( 'paf' );
30 $key = 'eoi_powerup_new_css';
31
32 if ( $active ) {
33 $paf[ $key ] = array( 'on' );
34 powerup_new_css_on_activate();
35 } else {
36 $paf[ $key ] = array();
37 powerup_new_css_on_deactivate();
38 }
39
40 update_option( 'paf', $paf );
41 }
42
43 function powerup_new_css_dismiss_notification() {
44 require_once dirname( __FILE__ ) . '/../../includes/eoi-init.php';
45 EasyOptInsInit::get_instance()->set_new_css_notification_dismissed( true );
46 }
47
48 function powerup_new_css_on_activate() {
49 $new_css_obj = new EoiNewCssMigration();
50 $new_css_obj->migrate( 'old', 'new' );
51
52 add_action( 'admin_init', 'powerup_new_css_dismiss_notification' );
53 }
54
55 function powerup_new_css_on_deactivate() {
56 $new_css_obj = new EoiNewCssMigration();
57 $new_css_obj->migrate( 'new', 'old' );
58 }
59
60 class EoiNewCssMigration {
61 private $layouts;
62 private $layout_ids;
63
64 public function migrate( $from, $to ) {
65 foreach ( get_posts( array( 'post_type' => 'easy-opt-ins', 'posts_per_page' => - 1 ) ) as $optin_form ) {
66 $this->migrate_form( $optin_form, $from, $to );
67 }
68 }
69
70 private function migrate_form( $optin_form, $from, $to ) {
71 $form_id = $optin_form->ID;
72 $fca_eoi = get_post_meta( $form_id, 'fca_eoi', true );
73
74 $fca_eoi_changed = false;
75 foreach ( $this->get_layout_ids() as $layout_id ) {
76 if ( $layout_id == 'layout_2' || $layout_id == 'postbox_2' || $layout_id == 'lightbox_2' ) {
77 $this->prepare_for_layout_2( $layout_id, $fca_eoi, $from );
78 }
79
80 if ( $this->migrate_layout( $layout_id, $fca_eoi, $from, $to ) ) {
81 $fca_eoi_changed = true;
82 }
83 }
84
85 if ( $fca_eoi_changed ) {
86 delete_post_meta( $form_id, 'fca_eoi' );
87 add_post_meta( $form_id, 'fca_eoi', $fca_eoi );
88 }
89 }
90
91 private function prepare_for_layout_2( $layout_id, &$fca_eoi, $from ) {
92 if ( empty( $fca_eoi[ $layout_id ] ) ) {
93 return;
94 }
95
96 foreach ( $fca_eoi[ $layout_id ] as $main_selector => $attributes ) {
97 foreach ( $attributes as $sub_selector => $value ) {
98 if ( $from == 'old' && $sub_selector == 'border-top-color' ) {
99 $fca_eoi[ $layout_id ][ $main_selector ]['fill'] = $value;
100 unset( $fca_eoi[ $layout_id ][ $main_selector ][ $sub_selector ] );
101 } elseif ( $from == 'new' && $sub_selector == 'fill' ) {
102 $fca_eoi[ $layout_id ][ $main_selector ]['border-top-color'] = $value;
103 unset( $fca_eoi[ $layout_id ][ $main_selector ][ $sub_selector ] );
104 }
105 }
106 }
107 }
108
109 private function migrate_layout( $layout_id, &$fca_eoi, $from, $to ) {
110 $layouts = $this->get_layouts();
111 $fca_eoi_changed = false;
112
113 if ( ! empty( $fca_eoi[ $layout_id ] ) ) {
114 $from_selectors = $layouts[ $layout_id ][ $from ];
115 $to_selectors = $layouts[ $layout_id ][ $to ];
116
117 for ( $i = 0, $len = count( $from_selectors ); $i < $len; $i++ ) {
118 $from_selector = $from_selectors[ $i ];
119 $to_selector = $to_selectors[ $i ];
120
121 if ( ! empty( $fca_eoi[ $layout_id ][ $from_selector ] ) ) {
122 $fca_eoi_changed = true;
123 $this->migrate_selector( $from_selector, $to_selector, $layout_id, $fca_eoi );
124 }
125 }
126 }
127
128 return $fca_eoi_changed;
129 }
130
131 private function migrate_selector( $from_selector, $to_selector, $layout_id, &$fca_eoi ) {
132 $fca_eoi[ $layout_id ][ $to_selector ] = $fca_eoi[ $layout_id ][ $from_selector ];
133 unset( $fca_eoi[ $layout_id ][ $from_selector ] );
134 }
135
136 private function get_layouts() {
137 if ( ! empty( $this->layouts ) ) {
138 return $this->layouts;
139 }
140
141 $layouts = array();
142
143 foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*/*/layout-new.php' ) as $path ) {
144 if ( strpos( $path, '/common/' ) !== false ) {
145 continue;
146 }
147
148 $path_info = pathinfo( $path );
149 $layout_id = basename( $path_info['dirname'] );
150 $old_layout = $path_info['dirname'] . DIRECTORY_SEPARATOR . 'layout.php';
151 $new_layout = $path;
152
153 $layouts[ $layout_id ] = array(
154 'old' => null,
155 'new' => null
156 );
157
158 $layout = null;
159
160 require $old_layout;
161 $layouts[ $layout_id ]['old'] = $this->extract_main_selectors_from_layout( $layout );
162
163 require $new_layout;
164 $layouts[ $layout_id ]['new'] = $this->extract_main_selectors_from_layout( $layout );
165 }
166
167 $this->layouts = $layouts;
168 return $layouts;
169 }
170
171 private function extract_main_selectors_from_layout( $layout ) {
172 if ( empty( $layout['editables'] ) ) {
173 return array();
174 }
175
176 $selectors = array();
177
178 foreach ( $layout['editables'] as $parts ) {
179 $selectors = array_merge( $selectors, array_keys( $parts ) );
180 }
181
182 return $selectors;
183 }
184
185 private function get_layout_ids() {
186 if ( empty( $this->layout_ids ) ) {
187 $this->layout_ids = array_keys( $this->get_layouts() );
188 }
189 return $this->layout_ids;
190 }
191 }
192