PluginProbe
Import Social Events / 1.6.0
Import Social Events v1.6.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-admin.php

class-import-facebook-events-admin.php in Import Social Events 1.6.0, at includes/class-import-facebook-events-admin.php

402 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @package Import_Facebook_Events
6 * @subpackage Import_Facebook_Events/admin
7 * @copyright Copyright (c) 2016, Dharmesh Patel
8 * @since 1.0.0
9 */
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * @package Import_Facebook_Events
17 * @subpackage Import_Facebook_Events/admin
18 * @author Dharmesh Patel <[email protected]>
19 */
20 class Import_Facebook_Events_Admin {
21
22
23 public $adminpage_url;
24
25 /**
26 * Initialize the class and set its properties.
27 *
28 * @since 1.0.0
29 */
30 public function __construct() {
31
32 $this->adminpage_url = admin_url('admin.php?page=facebook_import' );
33
34 add_action( 'init', array( $this, 'register_scheduled_import_cpt' ) );
35 add_action( 'init', array( $this, 'register_history_cpt' ) );
36 add_action( 'admin_menu', array( $this, 'add_menu_pages') );
37 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts') );
38 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles') );
39 add_action( 'admin_notices', array( $this, 'display_notices') );
40 add_filter( 'admin_footer_text', array( $this, 'add_import_facebook_events_credit' ) );
41 }
42
43 /**
44 * Create the Admin menu and submenu and assign their links to global varibles.
45 *
46 * @since 1.0
47 * @return void
48 */
49 public function add_menu_pages() {
50
51 add_menu_page( __( 'Import Facebook Events', 'import-facebook-events' ), __( 'Facebook Import', 'import-facebook-events' ), 'manage_options', 'facebook_import', array( $this, 'admin_page' ), 'dashicons-calendar-alt', '30' );
52 }
53
54 /**
55 * Load Admin Scripts
56 *
57 * Enqueues the required admin scripts.
58 *
59 * @since 1.0
60 * @param string $hook Page hook
61 * @return void
62 */
63 function enqueue_admin_scripts( $hook ) {
64
65 $js_dir = IFE_PLUGIN_URL . 'assets/js/';
66 wp_register_script( 'import-facebook-events', $js_dir . 'import-facebook-events-admin.js', array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), IFE_VERSION );
67 wp_enqueue_script( 'import-facebook-events' );
68
69 }
70
71 /**
72 * Load Admin Styles.
73 *
74 * Enqueues the required admin styles.
75 *
76 * @since 1.0
77 * @param string $hook Page hook
78 * @return void
79 */
80 function enqueue_admin_styles( $hook ) {
81 global $pagenow;
82 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
83 if( 'facebook_import' == $page || $pagenow == 'widgets.php' || 'post.php' == $pagenow || 'post-new.php' == $pagenow ){
84 $css_dir = IFE_PLUGIN_URL . 'assets/css/';
85 wp_enqueue_style('jquery-ui', $css_dir . 'jquery-ui.css', false, "1.12.0" );
86 wp_enqueue_style('import-facebook-events', $css_dir . 'import-facebook-events-admin.css', false, IFE_VERSION );
87 }
88 }
89
90 /**
91 * Load Admin page.
92 *
93 * @since 1.0
94 * @return void
95 */
96 function admin_page() {
97
98 ?>
99 <div class="wrap">
100 <h2><?php esc_html_e( 'Import Facebook Events', 'import-facebook-events' ); ?></h2>
101 <?php
102 // Set Default Tab to Import.
103 $tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'facebook';
104 $ntab = isset( $_GET[ 'ntab' ] ) ? $_GET[ 'ntab' ] : 'import';
105 ?>
106 <div id="poststuff">
107 <div id="post-body" class="metabox-holder columns-2">
108
109 <div id="postbox-container-1" class="postbox-container">
110 <?php
111 if( !ife_is_pro() ){
112 require_once IFE_PLUGIN_DIR . '/templates/admin/admin-sidebar.php';
113 }
114 ?>
115 </div>
116 <div id="postbox-container-2" class="postbox-container">
117
118 <h1 class="nav-tab-wrapper">
119
120 <a href="<?php echo esc_url( add_query_arg( 'tab', 'facebook', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'facebook' ) { echo 'nav-tab-active'; } ?>">
121 <?php esc_html_e( 'Import', 'import-facebook-events' ); ?>
122 </a>
123
124 <a href="<?php echo esc_url( add_query_arg( 'tab', 'ics', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'ics' ) { echo 'nav-tab-active'; } ?>">
125 <?php esc_html_e( 'Facebook .ics Import', 'import-facebook-events' ); ?>
126 </a>
127
128 <a href="<?php echo esc_url( add_query_arg( 'tab', 'scheduled', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'scheduled' ) { echo 'nav-tab-active'; } ?>">
129 <?php esc_html_e( 'Scheduled Imports', 'import-facebook-events' ); ?>
130 </a>
131
132 <a href="<?php echo esc_url( add_query_arg( 'tab', 'history', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'history' ) { echo 'nav-tab-active'; } ?>">
133 <?php esc_html_e( 'Import History', 'import-facebook-events' ); ?>
134 </a>
135
136 <a href="<?php echo esc_url( add_query_arg( 'tab', 'settings', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'settings' ) { echo 'nav-tab-active'; } ?>">
137 <?php esc_html_e( 'Settings', 'import-facebook-events' ); ?>
138 </a>
139
140 <a href="<?php echo esc_url( add_query_arg( 'tab', 'support', $this->adminpage_url ) ); ?>" class="nav-tab <?php if ( $tab == 'support' ) { echo 'nav-tab-active'; } ?>">
141 <?php esc_html_e( 'Support & Help', 'import-facebook-events' ); ?>
142 </a>
143 </h1>
144
145 <div class="import-facebook-events-page">
146
147 <?php
148 if ( $tab == 'facebook' ) {
149
150 require_once IFE_PLUGIN_DIR . '/templates/admin/facebook-import-events.php';
151
152 } elseif ( $tab == 'ics' ) {
153
154 require_once IFE_PLUGIN_DIR . '/templates/admin/ical-import-events.php';
155
156 } elseif ( $tab == 'settings' ) {
157
158 require_once IFE_PLUGIN_DIR . '/templates/admin/import-facebook-events-settings.php';
159
160 } elseif ( $tab == 'scheduled' ) {
161 if( ife_is_pro() ){
162 require_once IFEPRO_PLUGIN_DIR . '/templates/admin/scheduled-import-events.php';
163 }else{
164 do_action( 'ife_render_pro_notice' );
165 }
166
167 }elseif ( $tab == 'history' ) {
168
169 require_once IFE_PLUGIN_DIR . '/templates/admin/import-facebook-events-history.php';
170
171 } elseif ( $tab == 'support' ) {
172
173 require_once IFE_PLUGIN_DIR . '/templates/admin/import-facebook-events-support.php';
174
175 }
176 ?>
177 <div style="clear: both"></div>
178 </div>
179
180 </div>
181
182 </div>
183 </div>
184 <?php
185 }
186
187
188 /**
189 * Display notices in admin.
190 *
191 * @since 1.0.0
192 */
193 public function display_notices() {
194 global $ife_errors, $ife_success_msg, $ife_warnings, $ife_info_msg;
195
196 if ( ! empty( $ife_errors ) ) {
197 foreach ( $ife_errors as $error ) :
198 ?>
199 <div class="notice notice-error is-dismissible">
200 <p><?php echo $error; ?></p>
201 </div>
202 <?php
203 endforeach;
204 }
205
206 if ( ! empty( $ife_success_msg ) ) {
207 foreach ( $ife_success_msg as $success ) :
208 ?>
209 <div class="notice notice-success is-dismissible">
210 <p><?php echo $success; ?></p>
211 </div>
212 <?php
213 endforeach;
214 }
215
216 if ( ! empty( $ife_warnings ) ) {
217 foreach ( $ife_warnings as $warning ) :
218 ?>
219 <div class="notice notice-warning is-dismissible">
220 <p><?php echo $warning; ?></p>
221 </div>
222 <?php
223 endforeach;
224 }
225
226 if ( ! empty( $ife_info_msg ) ) {
227 foreach ( $ife_info_msg as $info ) :
228 ?>
229 <div class="notice notice-info is-dismissible">
230 <p><?php echo $info; ?></p>
231 </div>
232 <?php
233 endforeach;
234 }
235
236 }
237
238 /**
239 * Register custom post type for scheduled imports.
240 *
241 * @since 1.0.0
242 */
243 public function register_scheduled_import_cpt() {
244 $labels = array(
245 'name' => _x( 'Scheduled Import', 'post type general name', 'import-facebook-events' ),
246 'singular_name' => _x( 'Scheduled Import', 'post type singular name', 'import-facebook-events' ),
247 'menu_name' => _x( 'Scheduled Imports', 'admin menu', 'import-facebook-events' ),
248 'name_admin_bar' => _x( 'Scheduled Import', 'add new on admin bar', 'import-facebook-events' ),
249 'add_new' => _x( 'Add New', 'book', 'import-facebook-events' ),
250 'add_new_item' => __( 'Add New Import', 'import-facebook-events' ),
251 'new_item' => __( 'New Import', 'import-facebook-events' ),
252 'edit_item' => __( 'Edit Import', 'import-facebook-events' ),
253 'view_item' => __( 'View Import', 'import-facebook-events' ),
254 'all_items' => __( 'All Scheduled Imports', 'import-facebook-events' ),
255 'search_items' => __( 'Search Scheduled Imports', 'import-facebook-events' ),
256 'parent_item_colon' => __( 'Parent Imports:', 'import-facebook-events' ),
257 'not_found' => __( 'No Imports found.', 'import-facebook-events' ),
258 'not_found_in_trash' => __( 'No Imports found in Trash.', 'import-facebook-events' ),
259 );
260
261 $args = array(
262 'labels' => $labels,
263 'description' => __( 'Scheduled Imports.', 'import-facebook-events' ),
264 'public' => false,
265 'publicly_queryable' => false,
266 'show_ui' => false,
267 'show_in_menu' => false,
268 'show_in_admin_bar' => false,
269 'show_in_nav_menus' => false,
270 'can_export' => false,
271 'rewrite' => false,
272 'capability_type' => 'page',
273 'has_archive' => false,
274 'hierarchical' => false,
275 'supports' => array( 'title' ),
276 'menu_position' => 5,
277 );
278
279 register_post_type( 'fb_scheduled_imports', $args );
280 }
281
282 /**
283 * Register custom post type for Save import history.
284 *
285 * @since 1.0.0
286 */
287 public function register_history_cpt() {
288 $labels = array(
289 'name' => _x( 'Import History', 'post type general name', 'import-facebook-events' ),
290 'singular_name' => _x( 'Import History', 'post type singular name', 'import-facebook-events' ),
291 'menu_name' => _x( 'Import History', 'admin menu', 'import-facebook-events' ),
292 'name_admin_bar' => _x( 'Import History', 'add new on admin bar', 'import-facebook-events' ),
293 'add_new' => _x( 'Add New', 'book', 'import-facebook-events' ),
294 'add_new_item' => __( 'Add New', 'import-facebook-events' ),
295 'new_item' => __( 'New History', 'import-facebook-events' ),
296 'edit_item' => __( 'Edit History', 'import-facebook-events' ),
297 'view_item' => __( 'View History', 'import-facebook-events' ),
298 'all_items' => __( 'All Import History', 'import-facebook-events' ),
299 'search_items' => __( 'Search History', 'import-facebook-events' ),
300 'parent_item_colon' => __( 'Parent History:', 'import-facebook-events' ),
301 'not_found' => __( 'No History found.', 'import-facebook-events' ),
302 'not_found_in_trash' => __( 'No History found in Trash.', 'import-facebook-events' ),
303 );
304
305 $args = array(
306 'labels' => $labels,
307 'description' => __( 'Import History', 'import-facebook-events' ),
308 'public' => false,
309 'publicly_queryable' => false,
310 'show_ui' => false,
311 'show_in_menu' => false,
312 'show_in_admin_bar' => false,
313 'show_in_nav_menus' => false,
314 'can_export' => false,
315 'rewrite' => false,
316 'capability_type' => 'page',
317 'has_archive' => false,
318 'hierarchical' => false,
319 'supports' => array( 'title' ),
320 'menu_position' => 5,
321 );
322
323 register_post_type( 'ife_import_history', $args );
324 }
325
326
327 /**
328 * Add Import Facebook Events ratting text
329 *
330 * @since 1.0
331 * @return void
332 */
333 public function add_import_facebook_events_credit( $footer_text ){
334 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
335 if ( $page != '' && $page == 'facebook_import' ) {
336 $rate_url = 'https://wordpress.org/support/plugin/import-facebook-events/reviews/?rate=5#new-post';
337
338 $footer_text .= sprintf(
339 esc_html__( ' Rate %1$sImport Facebook Events%2$s %3$s', 'import-facebook-events' ),
340 '<strong>',
341 '</strong>',
342 '<a href="' . $rate_url . '" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
343 );
344 }
345 return $footer_text;
346 }
347
348 /**
349 * Get Plugin array
350 *
351 * @since 1.1.0
352 * @return array
353 */
354 public function get_xyuls_themes_plugins(){
355 return array(
356 'wp-event-aggregator' => esc_html__( 'WP Event Aggregator', 'import-facebook-events' ),
357 'import-eventbrite-events' => esc_html__( 'Import Eventbrite Events', 'import-facebook-events' ),
358 'import-meetup-events' => esc_html__( 'Import Meetup Events', 'import-facebook-events' ),
359 'wp-bulk-delete' => esc_html__( 'WP Bulk Delete', 'import-facebook-events' ),
360 'event-schema' => esc_html__( 'Event Schema / Structured Data', 'import-facebook-events' ),
361 );
362 }
363
364 /**
365 * Get Plugin Details.
366 *
367 * @since 1.1.0
368 * @return array
369 */
370 public function get_wporg_plugin( $slug ){
371
372 if( $slug == '' ){
373 return false;
374 }
375
376 $transient_name = 'support_plugin_box'.$slug;
377 $plugin_data = get_transient( $transient_name );
378 if( false === $plugin_data ){
379 if ( ! function_exists( 'plugins_api' ) ) {
380 include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
381 }
382
383 $plugin_data = plugins_api( 'plugin_information', array(
384 'slug' => $slug,
385 'is_ssl' => is_ssl(),
386 'fields' => array(
387 'banners' => true,
388 'active_installs' => true,
389 ),
390 ) );
391
392 if ( ! is_wp_error( $plugin_data ) ) {
393 set_transient( $transient_name, $plugin_data, 24 * HOUR_IN_SECONDS );
394 } else {
395 // If there was a bug on the Current Request just leave
396 return false;
397 }
398 }
399 return $plugin_data;
400 }
401 }
402