PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.1.83
Brevo – Email, SMS, Web Push, Chat, and more. v3.1.83
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / inc / table-forms.php
mailin / inc Last commit date
templates 2 years ago SendinblueAccount.php 5 years ago SendinblueApiClient.php 1 year ago function.wp_mail.php 8 years ago index.php 8 years ago mailin.php 3 years ago sendinblue.php 3 years ago sib-api-manager.php 2 years ago sib-form-preview.php 2 years ago sib-sms-code.php 3 years ago table-forms.php 1 year ago
table-forms.php
295 lines
1 <?php
2 /**
3 * Subscribe forms class
4 */
5 if ( ! class_exists( 'WP_List_Table' ) ) {
6 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
7 }
8
9 class SIB_Forms_List extends WP_List_Table {
10
11 /** Class constructor */
12 public function __construct() {
13
14 parent::__construct(
15 array('singular' => __( 'Form', 'mailin' ), //singular name of the listed records
16 'plural' => __( 'Forms', 'mailin' ), //plural name of the listed records
17 'ajax' => false) //does this table support ajax?
18 );
19
20 add_action( 'admin_head', array( &$this, 'admin_header' ) );
21
22 }
23 const PAGES = [
24 'sib_page_form',
25 'sib_page_home',
26 'sib_page_scenarios',
27 'sib_page_statistics'
28 ];
29 /**
30 * Retrieve contacts data from the database
31 *
32 * @param int $per_page
33 * @param int $page_number
34 *
35 * @return mixed
36 */
37 public static function getForms( $per_page = 5, $page_number = 1 ) {
38
39 $result = SIB_Forms::getForms();
40 $start = ( $page_number - 1 ) * $per_page;
41 usort( $result, array(__CLASS__, 'usort_reorder' ) );
42 $result = array_slice($result, $start, $per_page);
43 return $result;
44 }
45 /**
46 * Returns the count of records in the database.
47 *
48 * @return null|string
49 */
50 public static function record_count() {
51 $result = SIB_Forms::getForms();
52 return count($result);
53 }
54 /** Text displayed when no customer data is available */
55 public function no_items() {
56 _e( 'No forms avaliable.', 'mailin' );
57 }
58 /**
59 * Render a column when no column specific method exist.
60 *
61 * @param array $item
62 * @param string $column_name
63 *
64 * @return mixed
65 */
66 public function column_default( $item, $column_name ) {
67 switch ( $column_name ) {
68 case 'id':
69 return '[sibwp_form id='.$item['id'].']';
70 case 'title':
71 case 'attributes':
72 case 'listName':
73 case 'date':
74 return $item[ $column_name ];
75 //default:
76 //return print_r( $item, true ); //Show the whole array for troubleshooting purposes
77 }
78 }
79
80 /**
81 * Render the bulk edit checkbox
82 *
83 * @param array $item
84 *
85 * @return string
86 */
87 function column_cb( $item ) {
88 return sprintf(
89 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
90 );
91 }
92
93
94 /**
95 * Method for form title column
96 *
97 * @param array $item an array of DB data
98 *
99 * @return string
100 */
101 function column_title( $item ) {
102
103 $delete_nonce = wp_create_nonce( 'sib_delete_form' );
104
105 $title = '<strong>' . $item['title'] . '</strong>';
106 $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : '';
107 $actions = array(
108 'edit' => sprintf( '<a href="?page=%s&action=%s&id=%s">Edit</a>', $page, 'edit', absint( $item['id'] ) ),
109 'duplicate' => sprintf( '<a href="?page=%s&action=%s&id=%s">Duplicate</a>', $page, 'duplicate', absint( $item['id'] ) ),
110 'delete' => sprintf( '<a class="sib-form-delete" href="?page=%s&action=%s&id=%s&_wpnonce=%s">Delete</a>', $page, 'delete', absint( $item['id'] ), $delete_nonce )
111 );
112
113 return $title . $this->row_actions( $actions );
114 }
115
116 function column_trans( $item ) {
117 $languages = apply_filters('wpml_active_languages', NULL, array());
118
119 $results = '';
120 if(!empty( $languages ))
121 {
122 foreach($languages as $language)
123 {
124 $exist = SIB_Forms_Lang::get_form_ID($item['id'], $language['language_code']);
125 $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : '';
126 if($exist == null)
127 {
128 $img_src = plugins_url('img/add_translation.png', dirname(__FILE__));
129
130 $href = sprintf( '<a href="?page=%s&action=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', $page, 'edit', absint( $item['id'] ), sanitize_text_field( $language['language_code'] ) );
131 $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>';
132 }
133 else{
134 $img_src = plugins_url('img/edit_translation.png', dirname(__FILE__));
135 $href = sprintf( '<a href="?page=%s&action=%s&id=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', $page, 'edit', absint( $exist ) , absint( $item['id']), sanitize_text_field( $language['language_code'] ) );
136 $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>';
137 }
138
139 }
140 }
141 return $results;
142 }
143
144 /**
145 * Associative array of columns
146 *
147 * @return array
148 */
149 function get_columns() {
150 $columns = array(
151 'cb' => '<input type="checkbox" />',
152 'title' => __( 'Form Name', 'mailin' ),
153 'id' => __( 'Shortcode', 'mailin' ),
154 'attributes' => __( 'Visible attributes', 'mailin' ),
155 'listName' => __( 'Linked List', 'mailin' ),
156 'date' => __( 'Last Update', 'mailin' )
157 );
158 if(function_exists('icl_plugin_action_links'))
159 {
160 $languages = apply_filters('wpml_active_languages', NULL, array());
161
162 $results = '';
163 if(!empty( $languages ))
164 {
165 foreach($languages as $language)
166 {
167 $results .= '<img src="'.$language['country_flag_url'].'" style="margin:2px;">';
168 }
169 }
170 $columns['trans'] = $results;
171 }
172 return $columns;
173 }
174
175
176 /**
177 * Columns to make sortable.
178 *
179 * @return array
180 */
181 public function get_sortable_columns() {
182 $sortable_columns = array(
183 'date' => array( 'date', true ),
184 'title' => array( 'title', false ),
185 );
186
187 return $sortable_columns;
188 }
189
190 /**
191 * Returns an associative array containing the bulk action
192 *
193 * @return array
194 */
195 public function get_bulk_actions() {
196 $actions = array(
197 'bulk-delete' => 'Delete'
198 );
199
200 $nonce = wp_create_nonce('mailin_bulk_action_nonce');
201 echo '<input type="hidden" name="mailin_bulk_action_nonce" value="' . esc_attr($nonce) . '">';
202
203 return $actions;
204 }
205
206
207 /**
208 * Handles data query and filter, sorting, and pagination.
209 */
210 public function prepare_items() {
211
212 $this->_column_headers = $this->get_column_info();
213
214 /** Process bulk action */
215 $this->process_bulk_action();
216
217 $per_page = $this->get_items_per_page( 'forms_per_page', 50 );
218 $current_page = $this->get_pagenum();
219 $total_items = self::record_count();
220
221 $this->set_pagination_args( array(
222 'total_items' => $total_items, //WE have to calculate the total number of items
223 'per_page' => $per_page //WE have to determine how many items to show on a page
224 ) );
225
226 $this->items = self::getForms( $per_page, $current_page );
227 }
228
229 public function process_bulk_action() {
230
231 //Detect when a bulk action is being triggered...
232 if ( 'delete' === $this->current_action() ) {
233
234 // In our file that handles the request, verify the nonce.
235 $nonce = sanitize_text_field( $_REQUEST['_wpnonce'] );
236
237 if ( ! wp_verify_nonce( $nonce, 'sib_delete_form' ) ) {
238 die( 'Go get a life script kiddies' );
239 }
240 else {
241 SIB_Forms::deleteForm( absint( sanitize_text_field($_GET['id']) ) );
242 SIB_Forms_Lang::remove_trans( absint( sanitize_text_field($_GET['id']) ) );
243 wp_redirect(add_query_arg('page', SIB_Page_Form::PAGE_ID, admin_url('admin.php'))); exit;
244 }
245
246 }
247
248 // If the delete bulk action is triggered
249 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
250 || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
251 ) {
252 $bulk_action_nonce = isset($_REQUEST['mailin_bulk_action_nonce'] ) ? sanitize_text_field( $_REQUEST['mailin_bulk_action_nonce'] ) : "";
253 if ( ! wp_verify_nonce( $bulk_action_nonce, 'mailin_bulk_action_nonce' ) ) {
254 die( 'Go get a life script kiddies' );
255 }
256 $delete_ids = array_map('intval', $_POST['bulk-delete']);
257
258 // loop over the array of record IDs and delete them
259 foreach ( $delete_ids as $id ) {
260 if( $id > 0 ) {
261 SIB_Forms::deleteForm( $id );
262 SIB_Forms_Lang::remove_trans( $id );
263 }
264 }
265 wp_redirect(esc_url(add_query_arg(NULL,NULL))); exit;
266
267 }
268 }
269 public function pagination($which){
270 echo '<a href="'.add_query_arg(array('page' => 'sib_page_form','action'=>'edit'/*,'id'=>'new'*/), admin_url('admin.php')).'" class="btn btn-success" style="float:right; margin: 2px 1px 8px 15px;" >'.__("Add New Form", "mailin").'</a>';
271 parent::pagination($which);
272 }
273
274 static function usort_reorder( $a, $b ) {
275 // If no sort, default to title
276 $orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_text_field($_GET['orderby']) : 'title'; // by title
277 // If no order, default to asc
278 $order = ( ! empty($_GET['order'] ) ) ? sanitize_text_field($_GET['order']) : 'ask';
279 // Determine sort order
280 $result = strcmp( $a[$orderby], $b[$orderby] );
281 // Send final sort direction to usort
282 return ( $order === 'ask' ) ? $result : -$result;
283 }
284
285 function admin_header() {
286 $page = ( isset($_GET['page'] ) ) ? sanitize_text_field( $_GET['page'] ) : false;
287 if( 'sib_page_form' != $page )
288 return;
289
290 echo '<style type="text/css">';
291 echo '.wp-list-table .column-date { width: 150px; }';
292 echo '</style>';
293 }
294 }
295