PluginProbe
Import Social Events / 1.2.0
Import Social Events v1.2.0
1.9.1 1.9.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 All 61 releases
import-facebook-events / includes / class-import-facebook-events-list-table.php

class-import-facebook-events-list-table.php in Import Social Events 1.2.0, at includes/class-import-facebook-events-list-table.php

530 lines 15.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * List table for scheduled import.
4 *
5 * @link http://xylusthemes.com/
6 * @since 1.0.0
7 *
8 * @package Import_Facebook_Events
9 * @subpackage Import_Facebook_Events/includes
10 */
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) exit;
13
14 if ( ! class_exists( 'WP_List_Table' ) ) {
15 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
16 }
17
18 /**
19 * Class respoinsible for generate list table for scheduled import.
20 */
21 class Import_Facebook_Events_List_Table extends WP_List_Table {
22
23 /**
24 * Initialize the class and set its properties.
25 *
26 * @since 1.0.0
27 */
28 public function __construct() {
29 global $status, $page;
30 // Set parent defaults.
31 parent::__construct( array(
32 'singular' => 'fb_scheduled_import', // singular name of the listed records.
33 'plural' => 'fb_scheduled_imports', // plural name of the listed records.
34 'ajax' => false, // does this table support ajax?
35 ) );
36 }
37
38 /**
39 * Setup output for default column.
40 *
41 * @since 1.0.0
42 * @param array $item Items.
43 * @param string $column_name Column name.
44 * @return string
45 */
46 function column_default( $item, $column_name ) {
47 return $item[ $column_name ];
48 }
49
50 /**
51 * Setup output for title column.
52 *
53 * @since 1.0.0
54 * @param array $item Items.
55 * @return array
56 */
57 function column_title( $item ) {
58
59 $ife_url_delete_args = array(
60 'page' => wp_unslash( $_REQUEST['page'] ),
61 'ife_action' => 'ife_simport_delete',
62 'import_id' => absint( $item['ID'] ),
63 );
64 // Build row actions.
65 $actions = array(
66 'delete' => sprintf( '<a href="%1$s" onclick="return confirm(\'Warning!! Are you sure to Delete this scheduled import? Scheduled import will be permanatly deleted.\')">%2$s</a>',esc_url( wp_nonce_url( add_query_arg( $ife_url_delete_args ), 'ife_delete_import_nonce' ) ), esc_html__( 'Delete', 'import-facebook-events' ) ),
67 );
68
69 // Return the title contents.
70 return sprintf('<strong>%1$s</strong><span>%4$s</span> <span style="color:silver">(id:%2$s)</span>%3$s',
71 $item['title'],
72 $item['ID'],
73 $this->row_actions( $actions ),
74 __('Origin', 'import-facebook-events') . ': <b>' . ucfirst( $item["import_origin"] ) . '</b>'
75 );
76 }
77
78 /**
79 * Setup output for Action column.
80 *
81 * @since 1.0.0
82 * @param array $item Items.
83 * @return array
84 */
85 function column_action( $item ) {
86
87 $xtmi_run_import_args = array(
88 'page' => wp_unslash( $_REQUEST['page'] ),
89 'ife_action' => 'ife_run_import',
90 'import_id' => $item['ID'],
91 );
92
93 // Return the title contents.
94 return sprintf( '<a class="button-primary" href="%1$s">%2$s</a><br/>%3$s',
95 esc_url( wp_nonce_url( add_query_arg( $xtmi_run_import_args ), 'ife_run_import_nonce' ) ),
96 esc_html__( 'Import Now', 'import-facebook-events' ),
97 $item['last_import']
98 );
99 }
100
101 function column_cb($item){
102 return sprintf(
103 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
104 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("video")
105 /*$2%s*/ $item['ID'] //The value of the checkbox should be the record's id
106 );
107 }
108
109 /**
110 * Get column title.
111 *
112 * @since 1.0.0
113 */
114 function get_columns() {
115 $columns = array(
116 'cb' => '<input type="checkbox" />',
117 'title' => __( 'Scheduled import', 'import-facebook-events' ),
118 'import_status' => __( 'Import Event Status', 'import-facebook-events' ),
119 'import_category' => __( 'Import Category', 'import-facebook-events' ),
120 'import_frequency' => __( 'Import Frequency', 'import-facebook-events' ),
121 'action' => __( 'Action', 'import-facebook-events' ),
122 );
123 return $columns;
124 }
125
126 public function get_bulk_actions() {
127
128 return array(
129 'delete' => __( 'Delete', 'import-facebook-events' ),
130 );
131
132 }
133
134 /**
135 * Prepare Meetup url data.
136 *
137 * @since 1.0.0
138 */
139 function prepare_items( $origin = '' ) {
140 $per_page = 10;
141 $columns = $this->get_columns();
142 $hidden = array( 'ID' );
143 $sortable = $this->get_sortable_columns();
144
145 $this->_column_headers = array( $columns, $hidden, $sortable );
146
147 $this->process_bulk_action();
148
149 if( $origin != '' ){
150 $data = $this->get_scheduled_import_data( $origin );
151 }else{
152 $data = $this->get_scheduled_import_data();
153 }
154
155 if ( ! empty( $data ) ) {
156 $total_items = ( $data['total_records'] )? (int) $data['total_records'] : 0;
157 // Set data to items.
158 $this->items = ( $data['import_data'] )? $data['import_data'] : array();
159
160 $this->set_pagination_args( array(
161 'total_items' => $total_items, // WE have to calculate the total number of items.
162 'per_page' => $per_page, // WE have to determine how many items to show on a page.
163 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages.
164 ) );
165 }
166 }
167
168 /**
169 * Get Meetup url data.
170 *
171 * @since 1.0.0
172 */
173 function get_scheduled_import_data( $origin = '' ) {
174 global $ife_events;
175
176 $scheduled_import_data = array( 'total_records' => 0, 'import_data' => array() );
177 $per_page = 10;
178 $current_page = $this->get_pagenum();
179
180 $query_args = array(
181 'post_type' => 'fb_scheduled_imports',
182 'posts_per_page' => $per_page,
183 'paged' => $current_page,
184 );
185
186 if( $origin != '' ){
187 $query_args['meta_key'] = 'import_origin';
188 $query_args['meta_value'] = esc_attr( $origin );
189 }
190 $importdata_query = new WP_Query( $query_args );
191 $scheduled_import_data['total_records'] = ( $importdata_query->found_posts ) ? (int) $importdata_query->found_posts : 0;
192 // The Loop.
193 if ( $importdata_query->have_posts() ) {
194 while ( $importdata_query->have_posts() ) {
195 $importdata_query->the_post();
196
197 $import_id = get_the_ID();
198 $import_data = get_post_meta( $import_id, 'import_eventdata', true );
199 $import_origin = get_post_meta( $import_id, 'import_origin', true );
200 $import_plugin = isset( $import_data['import_into'] ) ? $import_data['import_into'] : '';
201 $import_status = isset( $import_data['event_status'] ) ? $import_data['event_status'] : '';
202
203 $term_names = array();
204 $import_terms = isset( $import_data['event_cats'] ) ? $import_data['event_cats'] : array();
205
206 if ( $import_terms && ! empty( $import_terms ) ) {
207 foreach ( $import_terms as $term ) {
208 $get_term = '';
209 if( $import_plugin == 'tec' ){
210
211 $get_term = get_term( $term, $ife_events->tec->get_taxonomy() );
212
213 }elseif( $import_plugin == 'em' ){
214
215 $get_term = get_term( $term, $ife_events->em->get_taxonomy() );
216
217 }elseif( $import_plugin == 'eventon' ){
218
219 $get_term = get_term( $term, $ife_events->eventon->get_taxonomy() );
220
221 }elseif( $import_plugin == 'event_organizer' ){
222
223 $get_term = get_term( $term, $ife_events->event_organizer->get_taxonomy() );
224
225 }elseif( $import_plugin == 'aioec' ){
226
227 $get_term = get_term( $term, $ife_events->aioec->get_taxonomy() );
228
229 }elseif( $import_plugin == 'my_calendar' ){
230
231 $get_term = get_term( $term, $ife_events->my_calendar->get_taxonomy() );
232
233 }elseif( $import_plugin == 'ife' ){
234
235 $get_term = get_term( $term, $ife_events->ife->get_taxonomy() );
236 }else{
237 $get_term = get_term( $term, $ife_events->tec->get_taxonomy() );
238 }
239
240 if( !is_wp_error( $get_term ) && !empty( $get_term ) ){
241 $term_names[] = $get_term->name;
242 }
243 }
244 }
245
246 $last_import_history_date = '';
247 $history_args = array(
248 'post_type' => 'ife_import_history',
249 'post_status' => 'publish',
250 'posts_per_page' => 1,
251 'meta_key' => 'schedule_import_id',
252 'meta_value' => $import_id,
253
254 );
255
256 $history = new WP_Query( $history_args );
257 if ( $history->have_posts() ) {
258 while ( $history->have_posts() ) {
259 $history->the_post();
260 $last_import_history_date = sprintf( __( 'Last Import: %s ago', 'import-facebook-events' ), human_time_diff( get_the_date( 'U' ), current_time( 'timestamp' ) ) );
261 }
262 }
263 wp_reset_postdata();
264
265 $scheduled_import_data['import_data'][] = array(
266 'ID' => $import_id,
267 'title' => get_the_title(),
268 'import_status' => ucfirst( $import_status ),
269 'import_category' => implode( ', ', $term_names ),
270 'import_frequency'=> isset( $import_data['import_frequency'] ) ? ucfirst( $import_data['import_frequency'] ) : '',
271 'import_origin' => $import_origin,
272 'last_import' => $last_import_history_date,
273 );
274 }
275 }
276 // Restore original Post Data.
277 wp_reset_postdata();
278 return $scheduled_import_data;
279 }
280 }
281
282 /**
283 * Class respoinsible for generate list table for scheduled import.
284 */
285 class Import_Facebook_Events_History_List_Table extends WP_List_Table {
286
287 /**
288 * Initialize the class and set its properties.
289 *
290 * @since 1.0.0
291 */
292 public function __construct() {
293 global $status, $page;
294 // Set parent defaults.
295 parent::__construct( array(
296 'singular' => 'import_history', // singular name of the listed records.
297 'plural' => 'fb_import_histories', // plural name of the listed records.
298 'ajax' => false, // does this table support ajax?
299 ) );
300 }
301
302 /**
303 * Setup output for default column.
304 *
305 * @since 1.0.0
306 * @param array $item Items.
307 * @param string $column_name Column name.
308 * @return string
309 */
310 function column_default( $item, $column_name ) {
311 return $item[ $column_name ];
312 }
313
314 /**
315 * Setup output for title column.
316 *
317 * @since 1.0.0
318 * @param array $item Items.
319 * @return array
320 */
321 function column_title( $item ) {
322
323 $ife_url_delete_args = array(
324 'page' => wp_unslash( $_REQUEST['page'] ),
325 'tab' => wp_unslash( $_REQUEST['tab'] ),
326 'ife_action' => 'ife_history_delete',
327 'history_id' => absint( $item['ID'] ),
328 );
329 // Build row actions.
330 $actions = array(
331 'delete' => sprintf( '<a href="%1$s" onclick="return confirm(\'Warning!! Are you sure to Delete this import history? Import history will be permanatly deleted.\')">%2$s</a>',esc_url( wp_nonce_url( add_query_arg( $ife_url_delete_args ), 'ife_delete_history_nonce' ) ), esc_html__( 'Delete', 'import-facebook-events' ) ),
332 );
333
334 // Return the title contents.
335 return sprintf('<strong>%1$s</strong><span>%3$s</span> %2$s',
336 $item['title'],
337 $this->row_actions( $actions ),
338 __('Origin', 'import-facebook-events') . ': <b>' . ucfirst( get_post_meta( $item['ID'], 'import_origin', true ) ) . '</b>'
339 );
340 }
341
342 /**
343 * Setup output for Action column.
344 *
345 * @since 1.0.0
346 * @param array $item Items.
347 * @return array
348 */
349 function column_stats( $item ) {
350
351 $created = get_post_meta( $item['ID'], 'created', true );
352 $updated = get_post_meta( $item['ID'], 'updated', true );
353 $skipped = get_post_meta( $item['ID'], 'skipped', true );
354
355 $success_message = '<span style="color: silver"><strong>';
356 if( $created > 0 ){
357 $success_message .= sprintf( __( '%d Created', 'import-facebook-events' ), $created )."<br>";
358 }
359 if( $updated > 0 ){
360 $success_message .= sprintf( __( '%d Updated', 'import-facebook-events' ), $updated )."<br>";
361 }
362 if( $skipped > 0 ){
363 $success_message .= sprintf( __( '%d Skipped', 'import-facebook-events' ), $skipped ) ."<br>";
364 }
365 $success_message .= "</strong></span>";
366
367 // Return the title contents.
368 return $success_message;
369 }
370
371 function column_cb($item){
372 return sprintf(
373 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
374 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("video")
375 /*$2%s*/ $item['ID'] //The value of the checkbox should be the record's id
376 );
377 }
378
379 /**
380 * Get column title.
381 *
382 * @since 1.0.0
383 */
384 function get_columns() {
385 $columns = array(
386 'cb' => '<input type="checkbox" />',
387 'title' => __( 'Import', 'import-facebook-events' ),
388 'import_category' => __( 'Import Category', 'import-facebook-events' ),
389 'import_date' => __( 'Import Date', 'import-facebook-events' ),
390 'stats' => __( 'Import Stats', 'import-facebook-events' ),
391 );
392 return $columns;
393 }
394
395 public function get_bulk_actions() {
396
397 return array(
398 'delete' => __( 'Delete', 'import-facebook-events' ),
399 );
400
401 }
402
403 /**
404 * Prepare Meetup url data.
405 *
406 * @since 1.0.0
407 */
408 function prepare_items( $origin = '' ) {
409 $per_page = 10;
410 $columns = $this->get_columns();
411 $hidden = array( 'ID' );
412 $sortable = $this->get_sortable_columns();
413
414 $this->_column_headers = array( $columns, $hidden, $sortable );
415
416 $this->process_bulk_action();
417
418 if( $origin != '' ){
419 $data = $this->get_import_history_data( $origin );
420 }else{
421 $data = $this->get_import_history_data();
422 }
423
424 if ( ! empty( $data ) ) {
425 $total_items = ( $data['total_records'] )? (int) $data['total_records'] : 0;
426 // Set data to items.
427 $this->items = ( $data['import_data'] )? $data['import_data'] : array();
428
429 $this->set_pagination_args( array(
430 'total_items' => $total_items, // WE have to calculate the total number of items.
431 'per_page' => $per_page, // WE have to determine how many items to show on a page.
432 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages.
433 ) );
434 }
435 }
436
437 /**
438 * Get Meetup url data.
439 *
440 * @since 1.0.0
441 */
442 function get_import_history_data( $origin = '' ) {
443 global $ife_events;
444
445 $scheduled_import_data = array( 'total_records' => 0, 'import_data' => array() );
446 $per_page = 10;
447 $current_page = $this->get_pagenum();
448
449 $query_args = array(
450 'post_type' => 'ife_import_history',
451 'posts_per_page' => $per_page,
452 'paged' => $current_page,
453 );
454
455 if( $origin != '' ){
456 $query_args['meta_key'] = 'import_origin';
457 $query_args['meta_value'] = esc_attr( $origin );
458 }
459
460 $importdata_query = new WP_Query( $query_args );
461 $scheduled_import_data['total_records'] = ( $importdata_query->found_posts ) ? (int) $importdata_query->found_posts : 0;
462 // The Loop.
463 if ( $importdata_query->have_posts() ) {
464 while ( $importdata_query->have_posts() ) {
465 $importdata_query->the_post();
466
467 $import_id = get_the_ID();
468 $import_data = get_post_meta( $import_id, 'import_data', true );
469 $import_origin = get_post_meta( $import_id, 'import_origin', true );
470 $import_plugin = isset( $import_data['import_into'] ) ? $import_data['import_into'] : '';
471
472 $term_names = array();
473 $import_terms = isset( $import_data['event_cats'] ) ? $import_data['event_cats'] : array();
474
475 if ( $import_terms && ! empty( $import_terms ) ) {
476 foreach ( $import_terms as $term ) {
477 $get_term = '';
478 if( $import_plugin == 'tec' ){
479
480 $get_term = get_term( $term, $ife_events->tec->get_taxonomy() );
481
482 }elseif( $import_plugin == 'em' ){
483
484 $get_term = get_term( $term, $ife_events->em->get_taxonomy() );
485
486 }elseif( $import_plugin == 'eventon' ){
487
488 $get_term = get_term( $term, $ife_events->eventon->get_taxonomy() );
489
490 }elseif( $import_plugin == 'event_organizer' ){
491
492 $get_term = get_term( $term, $ife_events->event_organizer->get_taxonomy() );
493
494 }elseif( $import_plugin == 'aioec' ){
495
496 $get_term = get_term( $term, $ife_events->aioec->get_taxonomy() );
497
498 }elseif( $import_plugin == 'my_calendar' ){
499
500 $get_term = get_term( $term, $ife_events->my_calendar->get_taxonomy() );
501
502 }elseif( $import_plugin == 'ife' ){
503
504 $get_term = get_term( $term, $ife_events->ife->get_taxonomy() );
505 }else{
506
507 $get_term = get_term( $term, $ife_events->tec->get_taxonomy() );
508
509 }
510
511 if( !is_wp_error( $get_term ) && !empty( $get_term ) ){
512 $term_names[] = $get_term->name;
513 }
514 }
515 }
516
517 $scheduled_import_data['import_data'][] = array(
518 'ID' => $import_id,
519 'title' => get_the_title(),
520 'import_category' => implode( ', ', $term_names ),
521 'import_date' => get_the_date("F j Y, h:i A"),
522 );
523 }
524 }
525 // Restore original Post Data.
526 wp_reset_postdata();
527 return $scheduled_import_data;
528 }
529 }
530