Version Description
- New: Introducing iubenda Consent Solution integration
- Tweak: Simple HTML Dom update to 1.9
Download this release
Release Info
Developer | dfactory |
Plugin | iubenda Cookie Solution for GDPR |
Version | 2.0-beta |
Comparing to | |
See all releases |
Code changes from version 1.15.8 to 2.0-beta
- css/admin.css +47 -12
- includes/forms-list-table.php +367 -0
- includes/forms.php +665 -0
- includes/settings.php +1319 -0
- iubenda-cookie-class/simple_html_dom.php +1476 -862
- iubenda_cookie_solution.php +557 -915
- js/admin.js +182 -3
- js/frontend.js +94 -0
- languages/iubenda-cookie-law-solution-it_IT.mo +0 -0
- languages/iubenda-cookie-law-solution-it_IT.po +394 -111
- languages/iubenda-cookie-law-solution.pot +339 -75
- readme.txt +6 -4
css/admin.css
CHANGED
@@ -1,14 +1,5 @@
|
|
1 |
-
#iubenda-
|
2 |
-
|
3 |
-
|
4 |
-
width: 90%;
|
5 |
-
margin: 50px auto;
|
6 |
-
padding: 50px 6%;
|
7 |
-
box-sizing: border-box;
|
8 |
-
|
9 |
-
border-radius: 2px;
|
10 |
-
background-color: #FFFFFF;
|
11 |
-
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1)
|
12 |
}
|
13 |
.iubenda-title {
|
14 |
margin-top: 10px;
|
@@ -16,12 +7,32 @@
|
|
16 |
}
|
17 |
.iubenda-link {
|
18 |
display: table;
|
19 |
-
margin: 0 auto
|
20 |
}
|
21 |
.iubenda-text {
|
22 |
margin: 10px auto;
|
23 |
color: #434149
|
24 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
#iubenda-tabs {
|
26 |
margin: 30px auto 20px;
|
27 |
}
|
@@ -54,4 +65,28 @@
|
|
54 |
#iubenda-tabs .help-tab-content textarea {
|
55 |
margin-top: 18px;
|
56 |
width: 100%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
1 |
+
#iubenda-header {
|
2 |
+
margin-bottom: 30px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
}
|
4 |
.iubenda-title {
|
5 |
margin-top: 10px;
|
7 |
}
|
8 |
.iubenda-link {
|
9 |
display: table;
|
10 |
+
margin: 0 auto 10px;
|
11 |
}
|
12 |
.iubenda-text {
|
13 |
margin: 10px auto;
|
14 |
color: #434149
|
15 |
}
|
16 |
+
.button.button-primary.iub-autodetect-forms {
|
17 |
+
background: #1CC691;
|
18 |
+
border-color: #169970;
|
19 |
+
box-shadow: 0 1px 0 #138461;
|
20 |
+
text-shadow: 0 -1px 1px #138461,1px 0 1px #138461,0 1px 1px #138461,-1px 0 1px #138461;
|
21 |
+
display: inline-block;
|
22 |
+
margin-bottom: 30px;
|
23 |
+
}
|
24 |
+
.button.button-primary.iub-autodetect-forms:hover {
|
25 |
+
background: #1ACC94;
|
26 |
+
}
|
27 |
+
.button.button-primary.iub-autodetect-forms:focus {
|
28 |
+
box-shadow: 0 1px 0 #138461,0 0 2px 1px #1CC691;
|
29 |
+
}
|
30 |
+
#iubenda-consent-forms .tablenav.bottom {
|
31 |
+
display: none;
|
32 |
+
}
|
33 |
+
#iubenda-tabs .submit.submit-cons {
|
34 |
+
padding-top: 0;
|
35 |
+
}
|
36 |
#iubenda-tabs {
|
37 |
margin: 30px auto 20px;
|
38 |
}
|
65 |
#iubenda-tabs .help-tab-content textarea {
|
66 |
margin-top: 18px;
|
67 |
width: 100%;
|
68 |
+
}
|
69 |
+
#iubenda-tabs .postbox-container .widefat {
|
70 |
+
border: none;
|
71 |
+
box-shadow: none;
|
72 |
+
}
|
73 |
+
#iubenda-tabs .postbox-container .widefat h4 {
|
74 |
+
margin: 8px 0;
|
75 |
+
}
|
76 |
+
#iubenda-tabs .postbox-container .widefat select {
|
77 |
+
min-width: 50%;
|
78 |
+
}
|
79 |
+
#iubenda-tabs .postbox-container .widefat thead .label {
|
80 |
+
font-weight: bold;
|
81 |
+
}
|
82 |
+
#iubenda-tabs .postbox-container .widefat .table-label {
|
83 |
+
min-width: 25%;
|
84 |
+
}
|
85 |
+
#iubenda-tabs .postbox-container .widefat thead td {
|
86 |
+
border: none;
|
87 |
+
width: 50%;
|
88 |
+
}
|
89 |
+
#iubenda-tabs .postbox-container .widefat .widefat tbody td {
|
90 |
+
padding-top: 5px;
|
91 |
+
padding-bottom: 5px;
|
92 |
}
|
includes/forms-list-table.php
ADDED
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* iubenda_List_Table_Forms class.
|
8 |
+
*
|
9 |
+
* @class iubenda_List_Table_Forms
|
10 |
+
*/
|
11 |
+
class iubenda_List_Table_Forms extends WP_List_Table {
|
12 |
+
|
13 |
+
public $items;
|
14 |
+
public $extra_items;
|
15 |
+
public $base_url;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Class constructor.
|
19 |
+
*/
|
20 |
+
public function __construct() {
|
21 |
+
global $status, $page;
|
22 |
+
|
23 |
+
// set parent defaults
|
24 |
+
parent::__construct( array(
|
25 |
+
'ajax' => false
|
26 |
+
) );
|
27 |
+
|
28 |
+
$this->base_url = esc_url_raw( add_query_arg( array( 'tab' => 'cons' ), iubenda()->base_url ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Prepare the items for the table to process.
|
35 |
+
*/
|
36 |
+
public function prepare_items() {
|
37 |
+
if ( ! empty( $_GET['status'] ) && array_key_exists( $_GET['status'], iubenda()->forms->statuses ) )
|
38 |
+
$status = $_GET['status'];
|
39 |
+
else
|
40 |
+
$status = '';
|
41 |
+
|
42 |
+
$orderby = ( isset( $_GET['orderby'] ) ) ? esc_attr( $_GET['orderby'] ) : 'date';
|
43 |
+
$order = ( isset( $_GET['order'] ) ) && in_array( $_GET['order'], array( 'asc', 'desc' ) ) ? esc_attr( $_GET['order'] ) : 'desc';
|
44 |
+
|
45 |
+
$per_page = 20;
|
46 |
+
|
47 |
+
if ( isset( $_GET['number'] ) ) {
|
48 |
+
$number = (int) $_GET['number'];
|
49 |
+
} else {
|
50 |
+
$number = $per_page + min( 8, $per_page ); // grab a few extra
|
51 |
+
}
|
52 |
+
$page = $this->get_pagenum();
|
53 |
+
|
54 |
+
$args = array(
|
55 |
+
'orderby' => $orderby,
|
56 |
+
'order' => $order,
|
57 |
+
'offset' => 0,
|
58 |
+
'number' => 0,
|
59 |
+
'post_status' => $status
|
60 |
+
);
|
61 |
+
|
62 |
+
$items = iubenda()->forms->get_forms( $args );
|
63 |
+
|
64 |
+
// echo '<pre>'; print_r( $items ); echo '</pre>';
|
65 |
+
|
66 |
+
if ( is_array( $items ) ) {
|
67 |
+
$this->items = array_slice( $items, 0, $per_page );
|
68 |
+
$this->extra_items = array_slice( $items, $per_page );
|
69 |
+
}
|
70 |
+
|
71 |
+
// echo '<pre>'; print_r( $this->extra_items ); echo '</pre>';
|
72 |
+
|
73 |
+
$this->set_pagination_args( array(
|
74 |
+
'total_items' => count( $items ),
|
75 |
+
'per_page' => $per_page,
|
76 |
+
) );
|
77 |
+
|
78 |
+
$columns = $this->get_columns();
|
79 |
+
$hidden = array();
|
80 |
+
$sortable = $this->get_sortable_columns();
|
81 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Override the parent columns method. Defines the columns to use in your listing table.
|
86 |
+
*
|
87 |
+
* @return array
|
88 |
+
*/
|
89 |
+
public function get_columns() {
|
90 |
+
$columns = array(
|
91 |
+
'cb' => '<input type="checkbox"/>',
|
92 |
+
'title' => __( 'Form Title', 'iubenda' ),
|
93 |
+
'ID' => __( 'Form ID', 'iubenda' ),
|
94 |
+
'source' => __( 'Form Source', 'iubenda' ),
|
95 |
+
'fields' => __( 'Fields', 'iubenda' ),
|
96 |
+
'date' => __( 'Date', 'iubenda' ),
|
97 |
+
);
|
98 |
+
|
99 |
+
return $columns;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Define the sortable columns.
|
104 |
+
*
|
105 |
+
* @return array
|
106 |
+
*/
|
107 |
+
public function get_sortable_columns() {
|
108 |
+
$columns = array(
|
109 |
+
'title' => array( 'name', true )
|
110 |
+
);
|
111 |
+
return $columns;
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Handle single row content.
|
116 |
+
*
|
117 |
+
* @param array $item
|
118 |
+
* @return mixed
|
119 |
+
*/
|
120 |
+
public function single_row( $item ) {
|
121 |
+
$classes = array();
|
122 |
+
$classes[] = 'item-' . $item->ID;
|
123 |
+
?>
|
124 |
+
<tr id="item-<?php echo $item->ID; ?>" class="<?php echo implode( ' ', $classes ); ?>">
|
125 |
+
<?php $this->single_row_columns( $item ); ?>
|
126 |
+
</tr>
|
127 |
+
<?php
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Get the name of the default primary column.
|
132 |
+
*
|
133 |
+
* @return string Name of the default primary column, in this case, 'title'.
|
134 |
+
*/
|
135 |
+
public function get_default_primary_column_name() {
|
136 |
+
return 'title';
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Generate and display row actions links.
|
141 |
+
*
|
142 |
+
* @param object $item
|
143 |
+
* @param string $column_name
|
144 |
+
* @param string $primary
|
145 |
+
* @return string|void
|
146 |
+
*/
|
147 |
+
public function handle_row_actions( $item, $column_name, $primary ) {
|
148 |
+
if ( $column_name !== 'title' ) {
|
149 |
+
return '';
|
150 |
+
}
|
151 |
+
|
152 |
+
$output = '';
|
153 |
+
|
154 |
+
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-form_{$item->ID}" ) );
|
155 |
+
$url = add_query_arg( array( 'form_id' => $item->ID ), $this->base_url );
|
156 |
+
$edit_url = add_query_arg( array( 'action' => 'edit' ), $url );
|
157 |
+
$delete_url = add_query_arg( array( 'action' => 'delete' ), $url ) . "&$del_nonce";
|
158 |
+
|
159 |
+
// preorder it: View | Approve | Unapprove | Delete
|
160 |
+
$actions = array(
|
161 |
+
'view' => '',
|
162 |
+
'delete' => ''
|
163 |
+
);
|
164 |
+
|
165 |
+
$actions['view'] = "<a href='$edit_url' aria-label='" . esc_attr__( 'Edit this form', 'iubenda' ) . "'>" . __( 'Edit' ) . '</a>';
|
166 |
+
$actions['delete'] = "<a href='$delete_url' aria-label='" . esc_attr__( 'Delete this form', 'iubenda' ) . "'>" . __( 'Delete', 'iubenda' ) . '</a>';
|
167 |
+
|
168 |
+
$i = 0;
|
169 |
+
$output .= '<div class="row-actions">';
|
170 |
+
foreach ( $actions as $action => $link ) {
|
171 |
+
++ $i;
|
172 |
+
$sep = ( 1 === $i ) ? $sep = '' : $sep = ' | ';
|
173 |
+
$output .= '<span class="' . ( $action === 'delete' ? 'delete delete-form' : $action ) . '">' . $sep . $link . '</span>';
|
174 |
+
}
|
175 |
+
$output .= '</div>';
|
176 |
+
|
177 |
+
return $output;
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Define what data to show on each column of the table.
|
182 |
+
*
|
183 |
+
* @param array $item
|
184 |
+
* @param string $column_name
|
185 |
+
* @return mixed
|
186 |
+
*/
|
187 |
+
public function column_default( $item, $column_name ) {
|
188 |
+
$output = '';
|
189 |
+
|
190 |
+
if ( ! empty( $_GET['status'] ) && array_key_exists( $_GET['status'], iubenda()->forms->statuses ) )
|
191 |
+
$status = $_GET['status'];
|
192 |
+
else
|
193 |
+
$status = '';
|
194 |
+
|
195 |
+
// print_r( $item );
|
196 |
+
|
197 |
+
// get columns content
|
198 |
+
switch ( $column_name ) {
|
199 |
+
case 'ID':
|
200 |
+
$output = $item->ID;
|
201 |
+
break;
|
202 |
+
case 'title':
|
203 |
+
$output = '<strong>' . ( current_user_can( 'edit_post', $item->ID ) ? '<a href="' . esc_url_raw( add_query_arg( array( 'form_id' => $item->ID, 'action' => 'edit' ), $this->base_url ) ) . '">' . $item->post_title . '</a>' : $item->post_title );
|
204 |
+
|
205 |
+
if ( ! $status ) {
|
206 |
+
if ( in_array( $item->post_status, array( 'publish', 'needs_update' ) ) ) {
|
207 |
+
$output .= ' — ';
|
208 |
+
$output .= '<span class="post-state to-map-state">' . iubenda()->forms->statuses[$item->post_status] . '</span>';
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
$output .= '</strong>';
|
213 |
+
|
214 |
+
break;
|
215 |
+
case 'source':
|
216 |
+
$output = array_key_exists( $item->form_source, iubenda()->forms->sources ) ? iubenda()->forms->sources[$item->form_source] : '—';
|
217 |
+
break;
|
218 |
+
case 'fields':
|
219 |
+
$output = count( $item->form_fields );
|
220 |
+
break;
|
221 |
+
case 'date':
|
222 |
+
$output = date_i18n( $item->post_date );
|
223 |
+
break;
|
224 |
+
default:
|
225 |
+
break;
|
226 |
+
}
|
227 |
+
|
228 |
+
return $output;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Display checkboxex callback.
|
233 |
+
*
|
234 |
+
* @return string
|
235 |
+
*/
|
236 |
+
public function column_cb( $item ) {
|
237 |
+
return sprintf(
|
238 |
+
'<input type="checkbox" name="%1$s[]" value="%2$s" />', 'form', $item->ID
|
239 |
+
);
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Generate the table navigation above or below the table
|
244 |
+
*
|
245 |
+
* @since 3.1.0
|
246 |
+
* @param string $which
|
247 |
+
*/
|
248 |
+
protected function display_tablenav( $which ) {
|
249 |
+
?>
|
250 |
+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
|
251 |
+
<?php
|
252 |
+
// $this->extra_tablenav( $which );
|
253 |
+
$this->pagination( $which );
|
254 |
+
?>
|
255 |
+
|
256 |
+
<br class="clear" />
|
257 |
+
</div>
|
258 |
+
<?php
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* @param string $which
|
263 |
+
*/
|
264 |
+
protected function extra_tablenav( $which ) {
|
265 |
+
?>
|
266 |
+
<div class="alignleft actions">
|
267 |
+
<?php
|
268 |
+
if ( 'top' === $which ) {
|
269 |
+
ob_start();
|
270 |
+
|
271 |
+
$this->sources_dropdown();
|
272 |
+
|
273 |
+
$output = ob_get_clean();
|
274 |
+
|
275 |
+
if ( ! empty( $output ) ) {
|
276 |
+
echo $output;
|
277 |
+
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
|
278 |
+
}
|
279 |
+
}
|
280 |
+
?>
|
281 |
+
</div>
|
282 |
+
<?php
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Displays a sources drop-down for filtering on the list table.
|
287 |
+
*
|
288 |
+
* @return mixed
|
289 |
+
*/
|
290 |
+
protected function sources_dropdown() {
|
291 |
+
if ( ! empty( iubenda()->forms->sources ) ) {
|
292 |
+
$current = ! empty( $_GET['source'] ) && in_array( $_GET['source'], iubenda()->forms->sources ) ? esc_attr( $_GET['source'] ) : '';
|
293 |
+
echo '
|
294 |
+
<label class="screen-reader-text" for="cat">' . __( 'Filter by source', 'iubenda' ) . '</label>
|
295 |
+
<select name="source" id="filter-by-source">
|
296 |
+
<option ' . selected( '', $current, false ) . 'value="">' . __( 'All form sources', 'iubenda' ) . '</option>';
|
297 |
+
foreach ( iubenda()->forms->sources as $key => $label ) {
|
298 |
+
echo '
|
299 |
+
<option ' . selected( $key, $current, false ) . 'value="' . $key . '">' . $label . '</option>';
|
300 |
+
}
|
301 |
+
|
302 |
+
echo '</select>';
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Display views.
|
308 |
+
*
|
309 |
+
* @return array
|
310 |
+
*/
|
311 |
+
public function get_views() {
|
312 |
+
if ( ! empty( $_GET['status'] ) && array_key_exists( $_GET['status'], iubenda()->forms->statuses ) )
|
313 |
+
$status = $_GET['status'];
|
314 |
+
else
|
315 |
+
$status = '';
|
316 |
+
|
317 |
+
$orderby = ( isset( $_GET['orderby'] ) ) ? esc_attr( $_GET['orderby'] ) : '';
|
318 |
+
$order = ( isset( $_GET['order'] ) ) ? esc_attr( $_GET['order'] ) : '';
|
319 |
+
|
320 |
+
$per_page = 20;
|
321 |
+
|
322 |
+
if ( isset( $_GET['number'] ) ) {
|
323 |
+
$number = (int) $_GET['number'];
|
324 |
+
} else {
|
325 |
+
$number = $per_page + min( 8, $per_page ); // grab a few extra
|
326 |
+
}
|
327 |
+
$page = $this->get_pagenum();
|
328 |
+
$items_total = 0;
|
329 |
+
|
330 |
+
$args = array(
|
331 |
+
'orderby' => $orderby,
|
332 |
+
'order' => $order,
|
333 |
+
'offset' => 0,
|
334 |
+
'number' => 0
|
335 |
+
);
|
336 |
+
|
337 |
+
foreach ( iubenda()->forms->statuses as $key => $view ) {
|
338 |
+
$args['post_status'] = $key;
|
339 |
+
|
340 |
+
$items = iubenda()->forms->get_forms( $args );
|
341 |
+
|
342 |
+
$items_count[$key] = count( $items );
|
343 |
+
$items_total = $items_total + $items_count[$key];
|
344 |
+
}
|
345 |
+
|
346 |
+
$views = $items_total > 0 ? array(
|
347 |
+
'all' => '<a href="' . $this->base_url . '"' . ($status === '' ? ' class="current"' : '') . '>' . esc_html__( 'All' ) . ' <span class="count">(' . $items_total . ')</span></a>'
|
348 |
+
) : '';
|
349 |
+
|
350 |
+
foreach ( iubenda()->forms->statuses as $key => $view ) {
|
351 |
+
if ( (int) $items_count[$key] > 0 )
|
352 |
+
$views[$key] = '<a href="' . esc_url_raw( add_query_arg( array( 'status' => $key ), $this->base_url ) ) . '" ' . ($status === $key ? ' class="current"' : '') . '>' . sprintf( _n( '%1$s <span class="count">(%2$s)</span>', '%1$s <span class="count">(%2$s)</span>', $items_count[$key], 'iubenda' ), $view, $items_count[$key] ) . '</a>';
|
353 |
+
}
|
354 |
+
|
355 |
+
return $views;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Display empty result.
|
360 |
+
*
|
361 |
+
* @return string
|
362 |
+
*/
|
363 |
+
public function no_items() {
|
364 |
+
echo __( 'No forms found.', 'iubenda' );
|
365 |
+
}
|
366 |
+
|
367 |
+
}
|
includes/forms.php
ADDED
@@ -0,0 +1,665 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* iubenda_Forms class.
|
8 |
+
*
|
9 |
+
* @class iubenda_Forms
|
10 |
+
*/
|
11 |
+
class iubenda_Forms {
|
12 |
+
|
13 |
+
public $sources = array();
|
14 |
+
public $statuses = array();
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Class constructor.
|
18 |
+
*/
|
19 |
+
public function __construct() {
|
20 |
+
// actions
|
21 |
+
add_action( 'plugins_loaded', array( $this, 'init' ) );
|
22 |
+
add_action( 'init', array( $this, 'register_post_type' ) );
|
23 |
+
add_action( 'init', array( $this, 'register_post_status' ) );
|
24 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Initialize forms data.
|
29 |
+
*
|
30 |
+
* @return void
|
31 |
+
*/
|
32 |
+
public function init() {
|
33 |
+
// WOrdPress commenting form
|
34 |
+
$this->sources['wp_comment_form'] = 'WordPress Comment Form';
|
35 |
+
|
36 |
+
// check if Contact Form 7 is active
|
37 |
+
if ( class_exists( 'WPCF7' ) ) {
|
38 |
+
$this->sources['wpcf7'] = 'Contact Form 7';
|
39 |
+
}
|
40 |
+
|
41 |
+
$this->sources = apply_filters( 'iub_supported_form_sources', $this->sources );
|
42 |
+
|
43 |
+
$this->statuses = array(
|
44 |
+
'publish' => _x( 'To Map', 'post status', 'iubenda' ),
|
45 |
+
'mapped' => _x( 'Mapped', 'post status', 'iubenda' ),
|
46 |
+
'needs_update' => _x( 'Needs Update', 'post status', 'iubenda' ),
|
47 |
+
// 'trash' => _x( 'Ignored', 'post status', 'iubenda' )
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Enqueue frontend script.
|
53 |
+
*/
|
54 |
+
public function wp_enqueue_scripts() {
|
55 |
+
if ( ! empty( iubenda()->options['cons']['public_api_key'] ) ) {
|
56 |
+
wp_register_script( 'iubenda-forms', IUBENDA_PLUGIN_URL . '/js/frontend.js', array( 'jquery' ), iubenda()->version, true );
|
57 |
+
|
58 |
+
$args = array();
|
59 |
+
|
60 |
+
$form_args = array(
|
61 |
+
'post_status' => array( 'mapped', 'needs_update' )
|
62 |
+
);
|
63 |
+
|
64 |
+
$forms = iubenda()->forms->get_forms( $form_args );
|
65 |
+
|
66 |
+
if ( ! empty( $forms ) ) {
|
67 |
+
// required form parameters
|
68 |
+
$form_parameters = array(
|
69 |
+
'subject',
|
70 |
+
'preferences',
|
71 |
+
'exclude',
|
72 |
+
'legal_notices'
|
73 |
+
);
|
74 |
+
// loop through forms
|
75 |
+
foreach ( $forms as $form ) {
|
76 |
+
// bail if user is logged in and source is WP comment form
|
77 |
+
if ( $form->form_source == 'wp_comment_form' && is_user_logged_in() )
|
78 |
+
continue;
|
79 |
+
|
80 |
+
// we need unique identifier for the html form
|
81 |
+
// by default it's object id, used in form html id
|
82 |
+
$args[$form->form_source][$form->object_id] = array();
|
83 |
+
|
84 |
+
foreach ( $form_parameters as $parameter ) {
|
85 |
+
$parameter_name = 'form_' . $parameter;
|
86 |
+
$parameter_value = ! empty( $form->$parameter_name ) ? $form->$parameter_name : '';
|
87 |
+
|
88 |
+
switch ( $parameter ) {
|
89 |
+
case 'legal_notices' :
|
90 |
+
if ( $parameter_value && is_array( $parameter_value ) ) {
|
91 |
+
foreach( $parameter_value as $value ) {
|
92 |
+
$args[$form->form_source][$form->object_id]['consent']['legal_notices'][] = array( 'identifier' => $value );
|
93 |
+
}
|
94 |
+
}
|
95 |
+
break;
|
96 |
+
default :
|
97 |
+
if ( $parameter_value )
|
98 |
+
$args[$form->form_source][$form->object_id]['form']['map'][$parameter] = $parameter_value;
|
99 |
+
break;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
// echo '<pre>'; print_r( json_encode( $args ) ); echo '</pre>'; exit;
|
106 |
+
|
107 |
+
wp_localize_script(
|
108 |
+
'iubenda-forms',
|
109 |
+
'iubForms',
|
110 |
+
json_encode( $args )
|
111 |
+
);
|
112 |
+
|
113 |
+
wp_enqueue_script( 'iubenda-forms' );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Register iubenda form post type.
|
119 |
+
*/
|
120 |
+
public function register_post_type() {
|
121 |
+
register_post_type( 'iubenda_form', array(
|
122 |
+
'labels' => array(
|
123 |
+
'name' => __( 'Forms', 'iubenda' ),
|
124 |
+
'singular_name' => __( 'Form', 'iubenda' ),
|
125 |
+
),
|
126 |
+
'rewrite' => false,
|
127 |
+
'query_var' => false,
|
128 |
+
'public' => false,
|
129 |
+
'capability_type' => 'page'
|
130 |
+
) );
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Register iubenda form post status.
|
135 |
+
*/
|
136 |
+
public function register_post_status() {
|
137 |
+
foreach ( $this->statuses as $name => $label ) {
|
138 |
+
if ( $name === 'publish' )
|
139 |
+
continue;
|
140 |
+
|
141 |
+
register_post_status( $name, array(
|
142 |
+
'label' => $label,
|
143 |
+
'public' => true,
|
144 |
+
'exclude_from_search' => false,
|
145 |
+
'show_in_admin_all_list' => true,
|
146 |
+
'show_in_admin_status_list' => true,
|
147 |
+
'post_type' => array( 'iubenda_form' ),
|
148 |
+
// 'label_count' => _n_noop( 'Mapped <span class="count">(%s)</span>', 'Mapped <span class="count">(%s)</span>', 'iubenda' ),
|
149 |
+
) );
|
150 |
+
}
|
151 |
+
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Get iubenda forms function.
|
156 |
+
*
|
157 |
+
* @param type $args
|
158 |
+
* @return array
|
159 |
+
*/
|
160 |
+
public function get_forms( $args = array() ) {
|
161 |
+
$defaults = array(
|
162 |
+
'post_status' => 'any',
|
163 |
+
'posts_per_page' => -1,
|
164 |
+
'offset' => 0,
|
165 |
+
'orderby' => 'ID',
|
166 |
+
'order' => 'ASC',
|
167 |
+
'form_source' => 'any'
|
168 |
+
);
|
169 |
+
|
170 |
+
$args = wp_parse_args( $args, $defaults );
|
171 |
+
|
172 |
+
$args['post_type'] = 'iubenda_form';
|
173 |
+
|
174 |
+
// specific sources only
|
175 |
+
if ( $args['form_source'] != 'any' && ( is_string( $args['form_source'] ) || is_array( $args['form_source'] ) ) ) {
|
176 |
+
$args['meta_query'] = array(
|
177 |
+
array(
|
178 |
+
'key' => '_iub_form_source',
|
179 |
+
'value' => $args['form_source'],
|
180 |
+
'compare' => 'IN',
|
181 |
+
),
|
182 |
+
);
|
183 |
+
}
|
184 |
+
|
185 |
+
$q = new WP_Query();
|
186 |
+
|
187 |
+
$posts = $q->query( $args );
|
188 |
+
|
189 |
+
$metakeys = array(
|
190 |
+
'form_source',
|
191 |
+
'object_type',
|
192 |
+
'object_id',
|
193 |
+
'form_fields',
|
194 |
+
'form_subject',
|
195 |
+
'form_preferences',
|
196 |
+
'form_exclude',
|
197 |
+
'form_legal_notices'
|
198 |
+
);
|
199 |
+
|
200 |
+
if ( ! empty( $posts ) ) {
|
201 |
+
foreach ( $posts as $index => $post ) {
|
202 |
+
// get form data
|
203 |
+
$metadata_raw = get_metadata( 'post', $post->ID );
|
204 |
+
|
205 |
+
foreach ( $metakeys as $metakey ) {
|
206 |
+
$metadata = ! empty( $metadata_raw['_iub_' . $metakey][0] ) ? maybe_unserialize( $metadata_raw['_iub_' . $metakey][0] ) : '';
|
207 |
+
|
208 |
+
if ( ! empty( $metadata ) ) {
|
209 |
+
// unset empty values
|
210 |
+
if ( is_array( $metadata ) ) {
|
211 |
+
foreach ( $metadata as $metadata_key => $metadata_value ) {
|
212 |
+
if ( empty( $metadata_value ) && ! in_array( $metakey, array( 'form_legal_notices' ) ) )
|
213 |
+
unset( $metadata[$metadata_key] );
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
$posts[$index]->{$metakey} = $metadata;
|
218 |
+
}
|
219 |
+
/* object id needs to ba an integer
|
220 |
+
} elseif ( in_array( $metakey, array( 'object_id' ) ) ) {
|
221 |
+
$posts[$index]->{$metakey} = ! empty( $metadata ) ? absint( $metadata ) : 0;
|
222 |
+
}
|
223 |
+
*/
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
return $posts;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Get form function.
|
233 |
+
*
|
234 |
+
* @param int
|
235 |
+
* @return object
|
236 |
+
*/
|
237 |
+
public function get_form( $id ) {
|
238 |
+
$form_id = ! empty( $id ) ? absint( $id ) : 0;
|
239 |
+
|
240 |
+
if ( ! $form_id )
|
241 |
+
return false;
|
242 |
+
|
243 |
+
$form = get_post( $form_id );
|
244 |
+
|
245 |
+
if ( ! $form )
|
246 |
+
return false;
|
247 |
+
|
248 |
+
$metakeys = array(
|
249 |
+
'form_source',
|
250 |
+
'object_type',
|
251 |
+
'object_id',
|
252 |
+
'form_fields',
|
253 |
+
'form_subject',
|
254 |
+
'form_preferences',
|
255 |
+
'form_exclude',
|
256 |
+
'form_legal_notices'
|
257 |
+
);
|
258 |
+
|
259 |
+
// get form data
|
260 |
+
$metadata = get_metadata( 'post', $form->ID );
|
261 |
+
|
262 |
+
foreach ( $metakeys as $metakey ) {
|
263 |
+
$form->{$metakey} = ! empty( $metadata['_iub_' . $metakey][0] ) ? maybe_unserialize( $metadata['_iub_' . $metakey][0] ) : '';
|
264 |
+
}
|
265 |
+
|
266 |
+
return $form;
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Delete form function.
|
271 |
+
*
|
272 |
+
* @param int
|
273 |
+
* @return int
|
274 |
+
*/
|
275 |
+
public function delete_form( $id ) {
|
276 |
+
$form_id = ! empty( $id ) ? absint( $id ) : 0;
|
277 |
+
|
278 |
+
if ( ! $form_id )
|
279 |
+
return false;
|
280 |
+
|
281 |
+
$form = get_post( $form_id );
|
282 |
+
|
283 |
+
if ( ! $form )
|
284 |
+
return false;
|
285 |
+
|
286 |
+
$result = wp_delete_post( $id, true );
|
287 |
+
|
288 |
+
return $result;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Insert form function.
|
293 |
+
*
|
294 |
+
* @param array $args
|
295 |
+
* @return int
|
296 |
+
*/
|
297 |
+
public function save_form( $args = array() ) {
|
298 |
+
$defaults = array(
|
299 |
+
'ID' => 0,
|
300 |
+
'status' => 'publish',
|
301 |
+
'object_type' => 'post', // object type where the form data is stored
|
302 |
+
'object_id' => 0, // unique object id
|
303 |
+
'form_source' => '', // source slug
|
304 |
+
'form_title' => '', // form title
|
305 |
+
'form_date' => current_time( 'mysql' ), // form last modified date
|
306 |
+
'form_fields' => array(), // form field names array
|
307 |
+
'form_subject' => array(), // mapped form with iubenda consent subject param
|
308 |
+
'form_preferences' => array(), // mapped form with iubenda consent preferences param
|
309 |
+
'form_exclude' => array(), // mapped form with iubenda consent exclude param
|
310 |
+
'form_legal_notices' => array() // form legal notices
|
311 |
+
);
|
312 |
+
|
313 |
+
$args = wp_parse_args( $args, $defaults );
|
314 |
+
|
315 |
+
// sanitize args
|
316 |
+
$args['ID'] = ! empty( $args['ID'] ) ? (int) $args['ID'] : 0;
|
317 |
+
$args['status'] = ! empty( $args['status'] ) && in_array( $args['status'], array_keys( $this->statuses ) ) ? $args['status'] : 'publish';
|
318 |
+
$args['object_type'] = 'post';
|
319 |
+
$args['object_id'] = ! empty( $args['object_id'] ) ? (int) $args['object_id'] : 0;
|
320 |
+
$args['form_source'] = ! empty( $args['form_source'] ) && in_array( $args['form_source'], array_keys( $this->sources ) ) ? $args['form_source'] : '';
|
321 |
+
$args['form_title'] = ! empty( $args['form_title'] ) ? esc_html( $args['form_title'] ) : '';
|
322 |
+
$args['form_date'] = date( 'Y-m-d H:i:s', ( ! empty( $args['form_date'] ) ? strtotime( $args['form_date'] ) : current_time( 'mysql' ) ) );
|
323 |
+
$args['form_fields'] = ! empty( $args['form_fields'] ) && is_array( $args['form_fields'] ) ? array_map( 'esc_attr', $args['form_fields'] ) : array();
|
324 |
+
$args['form_subject'] = ! empty( $args['form_subject'] ) && is_array( $args['form_subject'] ) ? array_map( 'esc_attr', $args['form_subject'] ) : array();
|
325 |
+
$args['form_preferences'] = ! empty( $args['form_preferences'] ) && is_array( $args['form_preferences'] ) ? array_map( 'esc_attr', $args['form_preferences'] ) : array();
|
326 |
+
$args['form_exclude'] = ! empty( $args['form_exclude'] ) && is_array( $args['form_exclude'] ) ? array_map( 'esc_attr', $args['form_exclude'] ) : array();
|
327 |
+
$args['form_legal_notices'] = ! empty( $args['form_legal_notices'] ) && is_array( $args['form_legal_notices'] ) ? array_map( 'esc_attr', $args['form_legal_notices'] ) : array();
|
328 |
+
|
329 |
+
// bail if any issues
|
330 |
+
if ( ! $args['form_source'] || ! $args['form_fields'] )
|
331 |
+
return false;
|
332 |
+
|
333 |
+
$post = get_post( (int) $args['ID'] );
|
334 |
+
$update = ! $post ? false : true;
|
335 |
+
|
336 |
+
// insert new form
|
337 |
+
if ( ! $update ) {
|
338 |
+
$post_id = wp_insert_post( array(
|
339 |
+
'post_type' => 'iubenda_form',
|
340 |
+
'post_status' => $args['status'],
|
341 |
+
'post_title' => $args['form_title'],
|
342 |
+
'post_content' => '',
|
343 |
+
'post_date' => $args['form_date'],
|
344 |
+
'post_modified' => $args['form_date']
|
345 |
+
) );
|
346 |
+
// update form
|
347 |
+
} else {
|
348 |
+
$post_id = wp_update_post( array(
|
349 |
+
'ID' => $args['ID'],
|
350 |
+
'post_status' => $args['status'],
|
351 |
+
'post_modified' => $args['form_date']
|
352 |
+
) );
|
353 |
+
}
|
354 |
+
|
355 |
+
// save form source
|
356 |
+
if ( isset( $args['form_source'] ) )
|
357 |
+
update_post_meta( $post_id, '_iub_form_source', $args['form_source'] );
|
358 |
+
|
359 |
+
// save object type
|
360 |
+
if ( isset( $args['object_type'] ) )
|
361 |
+
update_post_meta( $post_id, '_iub_object_type', $args['object_type'] );
|
362 |
+
|
363 |
+
// save object id
|
364 |
+
if ( isset( $args['object_id'] ) )
|
365 |
+
update_post_meta( $post_id, '_iub_object_id', absint( $args['object_id'] ) );
|
366 |
+
|
367 |
+
// save form fields
|
368 |
+
if ( isset( $args['form_fields'] ) )
|
369 |
+
update_post_meta( $post_id, '_iub_form_fields', $args['form_fields'] );
|
370 |
+
|
371 |
+
// save form subject
|
372 |
+
if ( isset( $args['form_subject'] ) )
|
373 |
+
update_post_meta( $post_id, '_iub_form_subject', $args['form_subject'] );
|
374 |
+
|
375 |
+
// save form preferences
|
376 |
+
if ( isset( $args['form_preferences'] ) )
|
377 |
+
update_post_meta( $post_id, '_iub_form_preferences', $args['form_preferences'] );
|
378 |
+
|
379 |
+
// save form exclude
|
380 |
+
if ( isset( $args['form_exclude'] ) )
|
381 |
+
update_post_meta( $post_id, '_iub_form_exclude', $args['form_exclude'] );
|
382 |
+
|
383 |
+
// save legal notices
|
384 |
+
if ( isset( $args['form_legal_notices'] ) )
|
385 |
+
update_post_meta( $post_id, '_iub_form_legal_notices', $args['form_legal_notices'] );
|
386 |
+
|
387 |
+
return $post_id;
|
388 |
+
}
|
389 |
+
|
390 |
+
/**
|
391 |
+
* Autodetect forms action.
|
392 |
+
*
|
393 |
+
* @return bool
|
394 |
+
*/
|
395 |
+
public function autodetect_forms() {
|
396 |
+
$found_forms = $new_forms = array();
|
397 |
+
|
398 |
+
// get forms from active sources
|
399 |
+
if ( ! empty( $this->sources ) ) {
|
400 |
+
foreach ( $this->sources as $source => $source_name ) {
|
401 |
+
$found_forms[$source] = call_user_func( array( $this, 'get_source_forms' ), $source );
|
402 |
+
}
|
403 |
+
}
|
404 |
+
|
405 |
+
// insert forms
|
406 |
+
if ( ! empty( $found_forms ) ) {
|
407 |
+
foreach ( $found_forms as $source => $source_forms ) {
|
408 |
+
if ( ! empty( $source_forms ) ) {
|
409 |
+
|
410 |
+
foreach ( $source_forms as $formdata ) {
|
411 |
+
|
412 |
+
$exists = $this->get_form_by_object_id( array(
|
413 |
+
'id' => $formdata['object_id'],
|
414 |
+
'source' => $formdata['form_source']
|
415 |
+
) );
|
416 |
+
|
417 |
+
// form does not exist
|
418 |
+
if ( ! $exists ) {
|
419 |
+
$result = $this->save_form( $formdata );
|
420 |
+
|
421 |
+
if ( $result )
|
422 |
+
$new_forms['new'] = $result;
|
423 |
+
} else {
|
424 |
+
// check for fields changes
|
425 |
+
$new_fields = array_merge( array_diff( $formdata['form_fields'], $exists->form_fields ), array_diff( $exists->form_fields, $formdata['form_fields'] ) );
|
426 |
+
|
427 |
+
if ( $new_fields ) {
|
428 |
+
$new_forms['updated'] = $exists->ID;
|
429 |
+
|
430 |
+
// update form
|
431 |
+
$formdata['ID'] = $exists->ID;
|
432 |
+
|
433 |
+
// update to need status if form is already mapped
|
434 |
+
if ( $exists->post_status == 'mapped' )
|
435 |
+
$formdata['status'] = 'needs_update';
|
436 |
+
|
437 |
+
// echo '<pre>'; print_r( $formdata ); echo '</pre>'; exit;
|
438 |
+
|
439 |
+
$result = $this->save_form( $formdata );
|
440 |
+
}
|
441 |
+
}
|
442 |
+
}
|
443 |
+
}
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
447 |
+
// echo '<pre>'; print_r( $found_forms ); echo '</pre>'; exit;
|
448 |
+
|
449 |
+
return ! empty( $new_forms ) ? $new_forms : array();
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Get source forms.
|
454 |
+
*
|
455 |
+
* @param string
|
456 |
+
* @return array
|
457 |
+
*/
|
458 |
+
public function get_source_forms( $source = '' ) {
|
459 |
+
$source = ! empty( $source ) && in_array( $source, array_keys( $this->sources ) ) ? $source : '';
|
460 |
+
$forms = array();
|
461 |
+
|
462 |
+
$restricted_fields = apply_filters( "iub_{$source}_restricted_fields", array(
|
463 |
+
'submit',
|
464 |
+
'file',
|
465 |
+
'quiz'
|
466 |
+
) );
|
467 |
+
|
468 |
+
switch ( $source ) {
|
469 |
+
case 'wpcf7' :
|
470 |
+
$args = array(
|
471 |
+
'post_type' => 'wpcf7_contact_form',
|
472 |
+
'posts_per_page' => -1
|
473 |
+
);
|
474 |
+
$posts = get_posts( $args );
|
475 |
+
|
476 |
+
if ( ! empty( $posts ) ) {
|
477 |
+
foreach ( $posts as $post ) {
|
478 |
+
// get form data
|
479 |
+
$contact_form = class_exists( 'WPCF7_ContactForm' ) ? WPCF7_ContactForm::get_instance( $post->ID ) : false;
|
480 |
+
|
481 |
+
if ( ! empty( $contact_form ) ) {
|
482 |
+
$formdata = array(
|
483 |
+
'object_type' => 'post', // object type where the form data is stored
|
484 |
+
'object_id' => $post->ID, // unique object id
|
485 |
+
'form_source' => $source, // source slug
|
486 |
+
'form_title' => $post->post_title, // form title
|
487 |
+
'form_date' => $post->post_modified, // form last modified date
|
488 |
+
'form_fields' => array() // form field names array
|
489 |
+
);
|
490 |
+
|
491 |
+
$fields_raw = $contact_form->scan_form_tags();
|
492 |
+
|
493 |
+
// echo '<pre>'; print_r( $fields_raw ); echo '</pre>'; exit;
|
494 |
+
|
495 |
+
if ( ! empty( $fields_raw ) ) {
|
496 |
+
foreach ( $fields_raw as $field ) {
|
497 |
+
// specific field types only
|
498 |
+
if ( ! empty( $field['basetype'] ) && ! in_array( $field['basetype'], $restricted_fields ) ) {
|
499 |
+
$formdata['form_fields'][] = $field['name'];
|
500 |
+
}
|
501 |
+
}
|
502 |
+
}
|
503 |
+
|
504 |
+
$forms[] = $formdata;
|
505 |
+
}
|
506 |
+
|
507 |
+
// echo '<pre>'; print_r( $contact_form ); echo '</pre>'; exit;
|
508 |
+
}
|
509 |
+
}
|
510 |
+
|
511 |
+
break;
|
512 |
+
|
513 |
+
case 'wp_comment_form' :
|
514 |
+
$comment_form = '';
|
515 |
+
|
516 |
+
// get comment form for logged out user
|
517 |
+
$current_user_id = get_current_user_id();
|
518 |
+
|
519 |
+
// get first post
|
520 |
+
$post_args = array(
|
521 |
+
'numberposts' => 1,
|
522 |
+
'orderby' => 'ID',
|
523 |
+
'order' => 'ASC',
|
524 |
+
'fields' => 'ids'
|
525 |
+
);
|
526 |
+
|
527 |
+
$posts = get_posts( $post_args );
|
528 |
+
|
529 |
+
// get comment form
|
530 |
+
if ( ! empty( $posts ) ) {
|
531 |
+
wp_set_current_user( 0 );
|
532 |
+
|
533 |
+
ob_start();
|
534 |
+
|
535 |
+
comment_form( array(), $posts[0] );
|
536 |
+
|
537 |
+
$comment_form = ob_get_contents();
|
538 |
+
ob_end_clean();
|
539 |
+
|
540 |
+
wp_set_current_user( $current_user_id );
|
541 |
+
}
|
542 |
+
|
543 |
+
if ( ! empty( $comment_form ) ) {
|
544 |
+
$formdata = array(
|
545 |
+
'object_type' => 'custom', // object type where the form data is stored
|
546 |
+
'object_id' => 0, // unique object id
|
547 |
+
'form_source' => $source, // source slug
|
548 |
+
'form_title' => $this->sources[$source], // form title
|
549 |
+
'form_date' => current_time( 'mysql' ), // form last modified date
|
550 |
+
'form_fields' => array() // form field names array
|
551 |
+
);
|
552 |
+
|
553 |
+
$input_fields = array(
|
554 |
+
'input',
|
555 |
+
'textarea',
|
556 |
+
'select'
|
557 |
+
);
|
558 |
+
|
559 |
+
// DOMDoc parser
|
560 |
+
if ( iubenda()->options['cs']['parser_engine'] == 'new' ) {
|
561 |
+
libxml_use_internal_errors( true );
|
562 |
+
|
563 |
+
$document = new DOMDocument();
|
564 |
+
|
565 |
+
// set document arguments
|
566 |
+
$document->formatOutput = true;
|
567 |
+
$document->preserveWhiteSpace = false;
|
568 |
+
|
569 |
+
// load HTML
|
570 |
+
$document->loadHTML( $comment_form );
|
571 |
+
|
572 |
+
// search for nodes
|
573 |
+
foreach ( $input_fields as $input_field ) {
|
574 |
+
$fields_raw = $document->getElementsByTagName( $input_field );
|
575 |
+
|
576 |
+
if ( ! empty( $fields_raw ) && is_object( $fields_raw ) ) {
|
577 |
+
foreach ( $fields_raw as $field ) {
|
578 |
+
$field_name = $field->getAttribute( 'name' );
|
579 |
+
$field_type = $field->getAttribute( 'type' );
|
580 |
+
|
581 |
+
// exclude submit
|
582 |
+
if ( ! empty( $field_type ) && ! in_array( $field_type, array( 'submit' ) ) )
|
583 |
+
$formdata['form_fields'][] = $field->getAttribute( 'name' );
|
584 |
+
}
|
585 |
+
}
|
586 |
+
}
|
587 |
+
|
588 |
+
$forms[] = $formdata;
|
589 |
+
|
590 |
+
libxml_use_internal_errors( false );
|
591 |
+
|
592 |
+
// Simple HTML Dom parser
|
593 |
+
} else {
|
594 |
+
$html = str_get_html( $comment_form, $lowercase = true, $force_tags_closed = true, $strip = false );
|
595 |
+
|
596 |
+
if ( is_object( $html ) ) {
|
597 |
+
// search for nodes
|
598 |
+
foreach ( $input_fields as $input_field ) {
|
599 |
+
$fields_raw = $html->find( $input_field );
|
600 |
+
|
601 |
+
if ( is_array( $fields_raw ) ) {
|
602 |
+
foreach ( $fields_raw as $field ) {
|
603 |
+
$field_name = $field->name;
|
604 |
+
$field_type = $field->type;
|
605 |
+
|
606 |
+
// exclude submit
|
607 |
+
if ( ! empty( $field_type ) && ! in_array( $field_type, array( 'submit' ) ) )
|
608 |
+
$formdata['form_fields'][] = $field->getAttribute( 'name' );
|
609 |
+
}
|
610 |
+
}
|
611 |
+
}
|
612 |
+
|
613 |
+
$forms[] = $formdata;
|
614 |
+
|
615 |
+
}
|
616 |
+
}
|
617 |
+
}
|
618 |
+
|
619 |
+
break;
|
620 |
+
}
|
621 |
+
|
622 |
+
return $forms;
|
623 |
+
}
|
624 |
+
|
625 |
+
/**
|
626 |
+
* Get Post object by post_meta query
|
627 |
+
*
|
628 |
+
* @return array
|
629 |
+
*/
|
630 |
+
public function get_form_by_object_id( $args = array() ) {
|
631 |
+
// parse incoming $args into an array and merge it with $defaults
|
632 |
+
$args = wp_parse_args( $args );
|
633 |
+
|
634 |
+
// grab page
|
635 |
+
$args = array(
|
636 |
+
'meta_query' => array(
|
637 |
+
array(
|
638 |
+
'key' => '_iub_object_id',
|
639 |
+
'value' => $args['id'],
|
640 |
+
),
|
641 |
+
array(
|
642 |
+
'key' => '_iub_form_source',
|
643 |
+
'value' => $args['source'],
|
644 |
+
)
|
645 |
+
),
|
646 |
+
'post_type' => 'iubenda_form',
|
647 |
+
'post_status' => 'any',
|
648 |
+
'posts_per_page' => '1',
|
649 |
+
'fields' => 'ids'
|
650 |
+
);
|
651 |
+
|
652 |
+
// run query
|
653 |
+
$posts = get_posts( $args );
|
654 |
+
|
655 |
+
// check result
|
656 |
+
if ( ! $posts || is_wp_error( $posts ) )
|
657 |
+
return false;
|
658 |
+
|
659 |
+
$form = $this->get_form( $posts[0] );
|
660 |
+
|
661 |
+
// kick back results
|
662 |
+
return $form;
|
663 |
+
}
|
664 |
+
|
665 |
+
}
|
includes/settings.php
ADDED
@@ -0,0 +1,1319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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