| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Assets { |
| 4 |
|
| 5 |
private $assets = array(); |
| 6 |
|
| 7 |
public function __construct() |
| 8 |
{ |
| 9 |
add_action( 'wp_enqueue_scripts', array( $this, 'public_assets' ) ); |
| 10 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) ); |
| 11 |
} |
| 12 |
|
| 13 |
public function public_assets() |
| 14 |
{ |
| 15 |
$version = WPUltimatePostGrid::option( 'assets_use_cache', '1' ) == '1' ? WPUPG_VERSION : time(); |
| 16 |
$base_layout = WPUltimatePostGrid::option( 'grid_template_force_style', '0' ) == '1' ? 'public-forced.css' : 'public.css'; |
| 17 |
|
| 18 |
wp_enqueue_style( 'wpupg_public', WPUltimatePostGrid::get()->coreUrl . '/dist/' . $base_layout, array(), $version, 'all' ); |
| 19 |
wp_register_script( 'wpupg_public', WPUltimatePostGrid::get()->coreUrl . '/dist/public.js', array( 'jquery' ), $version, true ); |
| 20 |
|
| 21 |
wp_localize_script( 'wpupg_public', 'wpupg_public', array( |
| 22 |
'ajax_url' => WPUltimatePostGrid::get()->helper('ajax')->url(), |
| 23 |
'animationSpeed' => WPUltimatePostGrid::option( 'grid_animation_speed', '0.8' ) . 's', |
| 24 |
'animationShow' => $this->animation_string_to_array( WPUltimatePostGrid::option( 'grid_animation_show', 'opacity: 1' ) ), |
| 25 |
'animationHide' => $this->animation_string_to_array( WPUltimatePostGrid::option( 'grid_animation_hide', 'opacity: 0' ) ), |
| 26 |
'nonce' => wp_create_nonce( 'wpupg_grid' ), |
| 27 |
'rtl' => is_rtl(), |
| 28 |
'dropdown_hide_search' => WPUltimatePostGrid::option( 'filters_dropdown_hide_search', '0' ) == '1' ? true : false, |
| 29 |
'link_class' => WPUltimatePostGrid::option( 'grid_links_class', '' ), |
| 30 |
)); |
| 31 |
} |
| 32 |
|
| 33 |
public function admin_assets( $hook ) |
| 34 |
{ |
| 35 |
$version = WPUltimatePostGrid::option( 'assets_use_cache', '1' ) == '1' ? WPUPG_VERSION : time(); |
| 36 |
|
| 37 |
$screen = get_current_screen(); |
| 38 |
if ( in_array( $hook, array( 'post.php', 'post-new.php' ) ) && WPUPG_POST_TYPE === $screen->post_type ) { |
| 39 |
wp_enqueue_style( 'wp-color-picker' ); |
| 40 |
wp_enqueue_style( 'wpupg_admin_form', WPUltimatePostGrid::get()->coreUrl . '/dist/admin-form.css', array(), $version, 'all' ); |
| 41 |
wp_enqueue_script( 'wpupg_admin_form', WPUltimatePostGrid::get()->coreUrl . '/dist/admin-form.js', array( 'jquery', 'jquery-ui-datepicker', 'wp-color-picker' ), $version, true ); |
| 42 |
|
| 43 |
wp_localize_script( 'wpupg_admin_form', 'wpupg_admin', array( |
| 44 |
'ajax_url' => WPUltimatePostGrid::get()->helper('ajax')->url(), |
| 45 |
)); |
| 46 |
} |
| 47 |
|
| 48 |
wp_enqueue_style( 'wpupg_admin_post', WPUltimatePostGrid::get()->coreUrl . '/dist/admin.css', array(), $version, 'all' ); |
| 49 |
wp_enqueue_script( 'wpupg_admin_post', WPUltimatePostGrid::get()->coreUrl . '/dist/admin.js', array( 'jquery' ), $version, true ); |
| 50 |
wp_localize_script( 'wpupg_admin_post', 'wpupg_admin_post', array( |
| 51 |
'text_add_grid_image' => __( 'Add Grid Image', 'wp-ultimate-post-grid' ), |
| 52 |
'text_remove_grid_image' => __( 'Remove Grid Image', 'wp-ultimate-post-grid' ), |
| 53 |
)); |
| 54 |
} |
| 55 |
|
| 56 |
private function animation_string_to_array( $string ) |
| 57 |
{ |
| 58 |
$array = array(); |
| 59 |
|
| 60 |
$options = explode( ', ', $string ); |
| 61 |
foreach( $options as $option ) { |
| 62 |
list( $k, $v ) = explode( ': ', $option ); |
| 63 |
$array[$k] = $v; |
| 64 |
} |
| 65 |
|
| 66 |
return $array; |
| 67 |
} |
| 68 |
|
| 69 |
public function add() |
| 70 |
{ |
| 71 |
$assets = func_get_args(); |
| 72 |
|
| 73 |
foreach( $assets as $asset ) |
| 74 |
{ |
| 75 |
if( isset( $asset['file'] ) ) { |
| 76 |
|
| 77 |
if( !isset( $asset['type'] ) ) { |
| 78 |
$asset['type'] = pathinfo( $asset['file'], PATHINFO_EXTENSION ); |
| 79 |
} |
| 80 |
|
| 81 |
if( !isset( $asset['priority'] ) ) { |
| 82 |
$asset['priority'] = 10; |
| 83 |
} |
| 84 |
|
| 85 |
// Set a URL and DIR variable |
| 86 |
if( isset( $asset['direct'] ) && $asset['direct'] ) { |
| 87 |
$asset['url'] = $asset['file']; |
| 88 |
$asset['dir'] = $asset['file']; |
| 89 |
} else { |
| 90 |
$base_url = WPUltimatePostGrid::get()->coreUrl; |
| 91 |
$base_dir = WPUltimatePostGrid::get()->coreDir; |
| 92 |
|
| 93 |
if( isset( $asset['premium'] ) && $asset['premium'] ) { |
| 94 |
$base_url = WPUltimatePostGridPremium::get()->premiumUrl; |
| 95 |
$base_dir = WPUltimatePostGridPremium::get()->premiumDir; |
| 96 |
} |
| 97 |
|
| 98 |
$asset['url'] = $base_url . $asset['file']; |
| 99 |
$asset['dir'] = $base_dir . $asset['file']; |
| 100 |
} |
| 101 |
|
| 102 |
$this->assets[] = $asset; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |