PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.3.5
Brevo – Email, SMS, Web Push, Chat, and more. v3.3.5
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 1 year ago SendinblueAccount.php 1 year ago SendinblueApiClient.php 1 week ago function.wp_mail.php 8 years ago http-build-url.php 1 year ago index.php 8 years ago mailin.php 3 years ago push-admin.php 5 months ago push-amp.php 1 year ago push-api.php 3 months ago push-httpclient.php 1 year ago push-public.php 1 year ago push-settings.php 3 months ago push-utils.php 5 months ago push-woocommerce.php 11 months ago sendinblue.php 3 years ago sib-api-manager.php 1 year ago sib-form-preview.php 2 years ago sib-sms-code.php 5 months ago table-forms.php 1 year ago
table-forms.php
306 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 /**
12 * Column headers for the table
13 * @var array
14 */
15 public $_column_headers;
16
17 /**
18 * Items for the table
19 * @var array
20 */
21 public $items;
22
23 /** Class constructor */
24 public function __construct() {
25
26 parent::__construct(
27 array('singular' => __( 'Form', 'mailin' ), //singular name of the listed records
28 'plural' => __( 'Forms', 'mailin' ), //plural name of the listed records
29 'ajax' => false) //does this table support ajax?
30 );
31
32 add_action( 'admin_head', array( &$this, 'admin_header' ) );
33
34 }
35 const PAGES = [
36 'sib_page_form',
37 'sib_page_home',
38 'sib_page_statistics'
39 ];
40 /**
41 * Retrieve contacts data from the database
42 *
43 * @param int $per_page
44 * @param int $page_number
45 *
46 * @return mixed
47 */
48 public static function getForms( $per_page = 5, $page_number = 1 ) {
49
50 $result = SIB_Forms::getForms();
51 $start = ( $page_number - 1 ) * $per_page;
52 usort( $result, array(__CLASS__, 'usort_reorder' ) );
53 $result = array_slice($result, $start, $per_page);
54 return $result;
55 }
56 /**
57 * Returns the count of records in the database.
58 *
59 * @return null|string
60 */
61 public static function record_count() {
62 $result = SIB_Forms::getForms();
63 return count($result);
64 }
65 /** Text displayed when no customer data is available */
66 public function no_items() {
67 _e( 'No forms avaliable.', 'mailin' );
68 }
69 /**
70 * Render a column when no column specific method exist.
71 *
72 * @param array $item
73 * @param string $column_name
74 *
75 * @return mixed
76 */
77 public function column_default( $item, $column_name ) {
78 switch ( $column_name ) {
79 case 'id':
80 return '[sibwp_form id='.$item['id'].']';
81 case 'title':
82 case 'attributes':
83 case 'listName':
84 case 'date':
85 return $item[ $column_name ];
86 //default:
87 //return print_r( $item, true ); //Show the whole array for troubleshooting purposes
88 }
89 }
90
91 /**
92 * Render the bulk edit checkbox
93 *
94 * @param array $item
95 *
96 * @return string
97 */
98 function column_cb( $item ) {
99 return sprintf(
100 '<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['id']
101 );
102 }
103
104
105 /**
106 * Method for form title column
107 *
108 * @param array $item an array of DB data
109 *
110 * @return string
111 */
112 function column_title( $item ) {
113
114 $delete_nonce = wp_create_nonce( 'sib_delete_form' );
115
116 $title = '<strong>' . $item['title'] . '</strong>';
117 $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : '';
118 $actions = array(
119 'edit' => sprintf( '<a href="?page=%s&action=%s&id=%s">Edit</a>', $page, 'edit', absint( $item['id'] ) ),
120 'duplicate' => sprintf( '<a href="?page=%s&action=%s&id=%s">Duplicate</a>', $page, 'duplicate', absint( $item['id'] ) ),
121 '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 )
122 );
123
124 return $title . $this->row_actions( $actions );
125 }
126
127 function column_trans( $item ) {
128 $languages = apply_filters('wpml_active_languages', NULL, array());
129
130 $results = '';
131 if(!empty( $languages ))
132 {
133 foreach($languages as $language)
134 {
135 $exist = SIB_Forms_Lang::get_form_ID($item['id'], $language['language_code']);
136 $page = isset($_REQUEST['page']) && in_array(strtolower($_REQUEST['page']), self::PAGES) ? $_REQUEST['page'] : '';
137 if($exist == null)
138 {
139 $img_src = plugins_url('img/add_translation.png', dirname(__FILE__));
140
141 $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'] ) );
142 $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>';
143 }
144 else{
145 $img_src = plugins_url('img/edit_translation.png', dirname(__FILE__));
146 $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'] ) );
147 $results .= $href .'<img src="'.$img_src.'" style="margin:2px;"></a>';
148 }
149
150 }
151 }
152 return $results;
153 }
154
155 /**
156 * Associative array of columns
157 *
158 * @return array
159 */
160 function get_columns() {
161 $columns = array(
162 'cb' => '<input type="checkbox" />',
163 'title' => __( 'Form Name', 'mailin' ),
164 'id' => __( 'Shortcode', 'mailin' ),
165 'attributes' => __( 'Visible attributes', 'mailin' ),
166 'listName' => __( 'Linked List', 'mailin' ),
167 'date' => __( 'Last Update', 'mailin' )
168 );
169 if(function_exists('icl_plugin_action_links'))
170 {
171 $languages = apply_filters('wpml_active_languages', NULL, array());
172
173 $results = '';
174 if(!empty( $languages ))
175 {
176 foreach($languages as $language)
177 {
178 $results .= '<img src="'.$language['country_flag_url'].'" style="margin:2px;">';
179 }
180 }
181 $columns['trans'] = $results;
182 }
183 return $columns;
184 }
185
186
187 /**
188 * Columns to make sortable.
189 *
190 * @return array
191 */
192 public function get_sortable_columns() {
193 $sortable_columns = array(
194 'date' => array( 'date', true ),
195 'title' => array( 'title', false ),
196 );
197
198 return $sortable_columns;
199 }
200
201 /**
202 * Returns an associative array containing the bulk action
203 *
204 * @return array
205 */
206 public function get_bulk_actions() {
207 $actions = array(
208 'bulk-delete' => 'Delete'
209 );
210
211 $nonce = wp_create_nonce('mailin_bulk_action_nonce');
212 echo '<input type="hidden" name="mailin_bulk_action_nonce" value="' . esc_attr($nonce) . '">';
213
214 return $actions;
215 }
216
217
218 /**
219 * Handles data query and filter, sorting, and pagination.
220 */
221 public function prepare_items() {
222
223 $this->_column_headers = $this->get_column_info();
224
225 /** Process bulk action */
226 $this->process_bulk_action();
227
228 $per_page = $this->get_items_per_page( 'forms_per_page', 50 );
229 $current_page = $this->get_pagenum();
230 $total_items = self::record_count();
231
232 $this->set_pagination_args( array(
233 'total_items' => $total_items, //WE have to calculate the total number of items
234 'per_page' => $per_page //WE have to determine how many items to show on a page
235 ) );
236
237 $this->items = self::getForms( $per_page, $current_page );
238 }
239
240 public function process_bulk_action() {
241
242 //Detect when a bulk action is being triggered...
243 if ( 'delete' === $this->current_action() ) {
244
245 // In our file that handles the request, verify the nonce.
246 $nonce = sanitize_text_field( $_REQUEST['_wpnonce'] );
247
248 if ( ! wp_verify_nonce( $nonce, 'sib_delete_form' ) ) {
249 die( 'Go get a life script kiddies' );
250 }
251 else {
252 SIB_Forms::deleteForm( absint( sanitize_text_field($_GET['id']) ) );
253 SIB_Forms_Lang::remove_trans( absint( sanitize_text_field($_GET['id']) ) );
254 wp_redirect(add_query_arg('page', SIB_Page_Form::PAGE_ID, admin_url('admin.php'))); exit;
255 }
256
257 }
258
259 // If the delete bulk action is triggered
260 if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
261 || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
262 ) {
263 $bulk_action_nonce = isset($_REQUEST['mailin_bulk_action_nonce'] ) ? sanitize_text_field( $_REQUEST['mailin_bulk_action_nonce'] ) : "";
264 if ( ! wp_verify_nonce( $bulk_action_nonce, 'mailin_bulk_action_nonce' ) ) {
265 die( 'Go get a life script kiddies' );
266 }
267 $delete_ids = array_map('intval', $_POST['bulk-delete']);
268
269 // loop over the array of record IDs and delete them
270 foreach ( $delete_ids as $id ) {
271 if( $id > 0 ) {
272 SIB_Forms::deleteForm( $id );
273 SIB_Forms_Lang::remove_trans( $id );
274 }
275 }
276 wp_redirect(esc_url(add_query_arg(NULL,NULL))); exit;
277
278 }
279 }
280 public function pagination($which){
281 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>';
282 parent::pagination($which);
283 }
284
285 static function usort_reorder( $a, $b ) {
286 // If no sort, default to title
287 $orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_text_field($_GET['orderby']) : 'title'; // by title
288 // If no order, default to asc
289 $order = ( ! empty($_GET['order'] ) ) ? sanitize_text_field($_GET['order']) : 'ask';
290 // Determine sort order
291 $result = strcmp( $a[$orderby], $b[$orderby] );
292 // Send final sort direction to usort
293 return ( $order === 'ask' ) ? $result : -$result;
294 }
295
296 function admin_header() {
297 $page = ( isset($_GET['page'] ) ) ? sanitize_text_field( $_GET['page'] ) : false;
298 if( 'sib_page_form' != $page )
299 return;
300
301 echo '<style type="text/css">';
302 echo '.wp-list-table .column-date { width: 150px; }';
303 echo '</style>';
304 }
305 }
306