| 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 <dspatel44@gmail.com> |
| 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 |
|
| 82 |
$css_dir = IFE_PLUGIN_URL . 'assets/css/'; |
| 83 |
wp_enqueue_style('jquery-ui', $css_dir . 'jquery-ui.css', false, "1.12.0" ); |
| 84 |
wp_enqueue_style('import-facebook-events', $css_dir . 'import-facebook-events-admin.css', false, "" ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Load Admin page. |
| 89 |
* |
| 90 |
* @since 1.0 |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
function admin_page() { |
| 94 |
|
| 95 |
?> |
| 96 |
<div class="wrap"> |
| 97 |
<h2><?php esc_html_e( 'Import Facebook Events', 'import-facebook-events' ); ?></h2> |
| 98 |
<?php |
| 99 |
// Set Default Tab to Import. |
| 100 |
$tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'facebook'; |
| 101 |
$ntab = isset( $_GET[ 'ntab' ] ) ? $_GET[ 'ntab' ] : 'import'; |
| 102 |
?> |
| 103 |
<div id="poststuff"> |
| 104 |
<div id="post-body" class="metabox-holder columns-2"> |
| 105 |
|
| 106 |
<div id="postbox-container-1" class="postbox-container"> |
| 107 |
<?php require_once IFE_PLUGIN_DIR . '/templates/admin-sidebar.php'; ?> |
| 108 |
</div> |
| 109 |
<div id="postbox-container-2" class="postbox-container"> |
| 110 |
|
| 111 |
<h1 class="nav-tab-wrapper"> |
| 112 |
|
| 113 |
<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'; } ?>"> |
| 114 |
<?php esc_html_e( 'Import', 'import-facebook-events' ); ?> |
| 115 |
</a> |
| 116 |
|
| 117 |
<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'; } ?>"> |
| 118 |
<?php esc_html_e( 'Scheduled Imports', 'import-facebook-events' ); ?> |
| 119 |
</a> |
| 120 |
|
| 121 |
<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'; } ?>"> |
| 122 |
<?php esc_html_e( 'Import History', 'import-facebook-events' ); ?> |
| 123 |
</a> |
| 124 |
|
| 125 |
<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'; } ?>"> |
| 126 |
<?php esc_html_e( 'Settings', 'import-facebook-events' ); ?> |
| 127 |
</a> |
| 128 |
|
| 129 |
<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'; } ?>"> |
| 130 |
<?php esc_html_e( 'Support & Help', 'import-facebook-events' ); ?> |
| 131 |
</a> |
| 132 |
</h1> |
| 133 |
|
| 134 |
<div class="import-facebook-events-page"> |
| 135 |
|
| 136 |
<?php |
| 137 |
if ( $tab == 'facebook' ) { |
| 138 |
|
| 139 |
require_once IFE_PLUGIN_DIR . '/templates/facebook-import-events.php'; |
| 140 |
|
| 141 |
} elseif ( $tab == 'settings' ) { |
| 142 |
|
| 143 |
require_once IFE_PLUGIN_DIR . '/templates/import-facebook-events-settings.php'; |
| 144 |
|
| 145 |
} elseif ( $tab == 'scheduled' ) { |
| 146 |
|
| 147 |
require_once IFE_PLUGIN_DIR . '/templates/scheduled-import-events.php'; |
| 148 |
|
| 149 |
}elseif ( $tab == 'history' ) { |
| 150 |
|
| 151 |
require_once IFE_PLUGIN_DIR . '/templates/import-facebook-events-history.php'; |
| 152 |
|
| 153 |
} elseif ( $tab == 'support' ) { |
| 154 |
|
| 155 |
require_once IFE_PLUGIN_DIR . '/templates/import-facebook-events-support.php'; |
| 156 |
|
| 157 |
} |
| 158 |
?> |
| 159 |
<div style="clear: both"></div> |
| 160 |
</div> |
| 161 |
|
| 162 |
</div> |
| 163 |
|
| 164 |
</div> |
| 165 |
</div> |
| 166 |
<?php |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
/** |
| 171 |
* Display notices in admin. |
| 172 |
* |
| 173 |
* @since 1.0.0 |
| 174 |
*/ |
| 175 |
public function display_notices() { |
| 176 |
global $ife_errors, $ife_success_msg, $ife_warnings, $ife_info_msg; |
| 177 |
|
| 178 |
if ( ! empty( $ife_errors ) ) { |
| 179 |
foreach ( $ife_errors as $error ) : |
| 180 |
?> |
| 181 |
<div class="notice notice-error is-dismissible"> |
| 182 |
<p><?php echo $error; ?></p> |
| 183 |
</div> |
| 184 |
<?php |
| 185 |
endforeach; |
| 186 |
} |
| 187 |
|
| 188 |
if ( ! empty( $ife_success_msg ) ) { |
| 189 |
foreach ( $ife_success_msg as $success ) : |
| 190 |
?> |
| 191 |
<div class="notice notice-success is-dismissible"> |
| 192 |
<p><?php echo $success; ?></p> |
| 193 |
</div> |
| 194 |
<?php |
| 195 |
endforeach; |
| 196 |
} |
| 197 |
|
| 198 |
if ( ! empty( $ife_warnings ) ) { |
| 199 |
foreach ( $ife_warnings as $warning ) : |
| 200 |
?> |
| 201 |
<div class="notice notice-warning is-dismissible"> |
| 202 |
<p><?php echo $warning; ?></p> |
| 203 |
</div> |
| 204 |
<?php |
| 205 |
endforeach; |
| 206 |
} |
| 207 |
|
| 208 |
if ( ! empty( $ife_info_msg ) ) { |
| 209 |
foreach ( $ife_info_msg as $info ) : |
| 210 |
?> |
| 211 |
<div class="notice notice-info is-dismissible"> |
| 212 |
<p><?php echo $info; ?></p> |
| 213 |
</div> |
| 214 |
<?php |
| 215 |
endforeach; |
| 216 |
} |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Register custom post type for scheduled imports. |
| 222 |
* |
| 223 |
* @since 1.0.0 |
| 224 |
*/ |
| 225 |
public function register_scheduled_import_cpt() { |
| 226 |
$labels = array( |
| 227 |
'name' => _x( 'Scheduled Import', 'post type general name', 'import-facebook-events' ), |
| 228 |
'singular_name' => _x( 'Scheduled Import', 'post type singular name', 'import-facebook-events' ), |
| 229 |
'menu_name' => _x( 'Scheduled Imports', 'admin menu', 'import-facebook-events' ), |
| 230 |
'name_admin_bar' => _x( 'Scheduled Import', 'add new on admin bar', 'import-facebook-events' ), |
| 231 |
'add_new' => _x( 'Add New', 'book', 'import-facebook-events' ), |
| 232 |
'add_new_item' => __( 'Add New Import', 'import-facebook-events' ), |
| 233 |
'new_item' => __( 'New Import', 'import-facebook-events' ), |
| 234 |
'edit_item' => __( 'Edit Import', 'import-facebook-events' ), |
| 235 |
'view_item' => __( 'View Import', 'import-facebook-events' ), |
| 236 |
'all_items' => __( 'All Scheduled Imports', 'import-facebook-events' ), |
| 237 |
'search_items' => __( 'Search Scheduled Imports', 'import-facebook-events' ), |
| 238 |
'parent_item_colon' => __( 'Parent Imports:', 'import-facebook-events' ), |
| 239 |
'not_found' => __( 'No Imports found.', 'import-facebook-events' ), |
| 240 |
'not_found_in_trash' => __( 'No Imports found in Trash.', 'import-facebook-events' ), |
| 241 |
); |
| 242 |
|
| 243 |
$args = array( |
| 244 |
'labels' => $labels, |
| 245 |
'description' => __( 'Scheduled Imports.', 'import-facebook-events' ), |
| 246 |
'public' => false, |
| 247 |
'publicly_queryable' => false, |
| 248 |
'show_ui' => false, |
| 249 |
'show_in_menu' => false, |
| 250 |
'show_in_admin_bar' => false, |
| 251 |
'show_in_nav_menus' => false, |
| 252 |
'can_export' => false, |
| 253 |
'rewrite' => false, |
| 254 |
'capability_type' => 'page', |
| 255 |
'has_archive' => false, |
| 256 |
'hierarchical' => false, |
| 257 |
'supports' => array( 'title' ), |
| 258 |
'menu_position' => 5, |
| 259 |
); |
| 260 |
|
| 261 |
register_post_type( 'fb_scheduled_imports', $args ); |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Register custom post type for Save import history. |
| 266 |
* |
| 267 |
* @since 1.0.0 |
| 268 |
*/ |
| 269 |
public function register_history_cpt() { |
| 270 |
$labels = array( |
| 271 |
'name' => _x( 'Import History', 'post type general name', 'import-facebook-events' ), |
| 272 |
'singular_name' => _x( 'Import History', 'post type singular name', 'import-facebook-events' ), |
| 273 |
'menu_name' => _x( 'Import History', 'admin menu', 'import-facebook-events' ), |
| 274 |
'name_admin_bar' => _x( 'Import History', 'add new on admin bar', 'import-facebook-events' ), |
| 275 |
'add_new' => _x( 'Add New', 'book', 'import-facebook-events' ), |
| 276 |
'add_new_item' => __( 'Add New', 'import-facebook-events' ), |
| 277 |
'new_item' => __( 'New History', 'import-facebook-events' ), |
| 278 |
'edit_item' => __( 'Edit History', 'import-facebook-events' ), |
| 279 |
'view_item' => __( 'View History', 'import-facebook-events' ), |
| 280 |
'all_items' => __( 'All Import History', 'import-facebook-events' ), |
| 281 |
'search_items' => __( 'Search History', 'import-facebook-events' ), |
| 282 |
'parent_item_colon' => __( 'Parent History:', 'import-facebook-events' ), |
| 283 |
'not_found' => __( 'No History found.', 'import-facebook-events' ), |
| 284 |
'not_found_in_trash' => __( 'No History found in Trash.', 'import-facebook-events' ), |
| 285 |
); |
| 286 |
|
| 287 |
$args = array( |
| 288 |
'labels' => $labels, |
| 289 |
'description' => __( 'Import History', 'import-facebook-events' ), |
| 290 |
'public' => false, |
| 291 |
'publicly_queryable' => false, |
| 292 |
'show_ui' => false, |
| 293 |
'show_in_menu' => false, |
| 294 |
'show_in_admin_bar' => false, |
| 295 |
'show_in_nav_menus' => false, |
| 296 |
'can_export' => false, |
| 297 |
'rewrite' => false, |
| 298 |
'capability_type' => 'page', |
| 299 |
'has_archive' => false, |
| 300 |
'hierarchical' => false, |
| 301 |
'supports' => array( 'title' ), |
| 302 |
'menu_position' => 5, |
| 303 |
); |
| 304 |
|
| 305 |
register_post_type( 'ife_import_history', $args ); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
/** |
| 310 |
* Add Import Facebook Events ratting text |
| 311 |
* |
| 312 |
* @since 1.0 |
| 313 |
* @return void |
| 314 |
*/ |
| 315 |
public function add_import_facebook_events_credit( $footer_text ){ |
| 316 |
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 317 |
if ( $page != '' && $page == 'facebook_import' ) { |
| 318 |
$rate_url = 'https://wordpress.org/support/plugin/import-facebook-events/reviews/?rate=5#new-post'; |
| 319 |
|
| 320 |
$footer_text .= sprintf( |
| 321 |
esc_html__( ' Rate %1$sImport Facebook Events%2$s %3$s', 'import-facebook-events' ), |
| 322 |
'<strong>', |
| 323 |
'</strong>', |
| 324 |
'<a href="' . $rate_url . '" target="_blank">★★★★★</a>' |
| 325 |
); |
| 326 |
} |
| 327 |
return $footer_text; |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* Get Plugin array |
| 332 |
* |
| 333 |
* @since 1.1.0 |
| 334 |
* @return array |
| 335 |
*/ |
| 336 |
public function get_xyuls_themes_plugins(){ |
| 337 |
return array( |
| 338 |
'wp-event-aggregator' => esc_html__( 'WP Event Aggregator', 'import-facebook-events' ), |
| 339 |
'import-eventbrite-events' => esc_html__( 'Import Eventbrite Events', 'import-facebook-events' ), |
| 340 |
'import-meetup-events' => esc_html__( 'Import Meetup Events', 'import-facebook-events' ), |
| 341 |
'wp-bulk-delete' => esc_html__( 'WP Bulk Delete', 'import-facebook-events' ), |
| 342 |
'event-schema' => esc_html__( 'Event Schema / Structured Data', 'import-facebook-events' ), |
| 343 |
); |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Get Plugin Details. |
| 348 |
* |
| 349 |
* @since 1.1.0 |
| 350 |
* @return array |
| 351 |
*/ |
| 352 |
public function get_wporg_plugin( $slug ){ |
| 353 |
|
| 354 |
if( $slug == '' ){ |
| 355 |
return false; |
| 356 |
} |
| 357 |
|
| 358 |
$transient_name = 'support_plugin_box'.$slug; |
| 359 |
$plugin_data = get_transient( $transient_name ); |
| 360 |
if( false === $plugin_data ){ |
| 361 |
if ( ! function_exists( 'plugins_api' ) ) { |
| 362 |
include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; |
| 363 |
} |
| 364 |
|
| 365 |
$plugin_data = plugins_api( 'plugin_information', array( |
| 366 |
'slug' => $slug, |
| 367 |
'is_ssl' => is_ssl(), |
| 368 |
'fields' => array( |
| 369 |
'banners' => true, |
| 370 |
'active_installs' => true, |
| 371 |
), |
| 372 |
) ); |
| 373 |
|
| 374 |
if ( ! is_wp_error( $plugin_data ) ) { |
| 375 |
set_transient( $transient_name, $plugin_data, 24 * HOUR_IN_SECONDS ); |
| 376 |
} else { |
| 377 |
// If there was a bug on the Current Request just leave |
| 378 |
return false; |
| 379 |
} |
| 380 |
} |
| 381 |
return $plugin_data; |
| 382 |
} |
| 383 |
} |
| 384 |
|