| 1 |
<?php |
| 2 |
/** |
| 3 |
* Enqueue Scripts Functions |
| 4 |
* |
| 5 |
* @package YOUTUBE_SHOWCASE |
| 6 |
* @since WPAS 4.0 |
| 7 |
*/ |
| 8 |
if (!defined('ABSPATH')) exit; |
| 9 |
add_action('admin_enqueue_scripts', 'youtube_showcase_load_admin_enq'); |
| 10 |
/** |
| 11 |
* Enqueue style and js for each admin entity pages and settings |
| 12 |
* |
| 13 |
* @since WPAS 4.0 |
| 14 |
* @param string $hook |
| 15 |
* |
| 16 |
*/ |
| 17 |
function youtube_showcase_load_admin_enq($hook) { |
| 18 |
global $typenow; |
| 19 |
$dir_url = YOUTUBE_SHOWCASE_PLUGIN_URL; |
| 20 |
do_action('emd_ext_admin_enq', 'youtube_showcase', $hook); |
| 21 |
$min_trigger = get_option('youtube_showcase_show_rateme_plugin_min', 0); |
| 22 |
$tracking_optin = get_option('youtube_showcase_tracking_optin', 0); |
| 23 |
if (-1 !== intval($tracking_optin) || - 1 !== intval($min_trigger)) { |
| 24 |
wp_enqueue_style('emd-plugin-rateme-css', $dir_url . 'assets/css/emd-plugin-rateme.css'); |
| 25 |
wp_enqueue_script('emd-plugin-rateme-js', $dir_url . 'assets/js/emd-plugin-rateme.js'); |
| 26 |
} |
| 27 |
if ($hook == 'widgets.php') { |
| 28 |
wp_enqueue_script('emd-widg-js', $dir_url . 'assets/js/emd-widget-admin.js', array() , '', true); |
| 29 |
return; |
| 30 |
} |
| 31 |
if ($hook == 'edit-tags.php') { |
| 32 |
return; |
| 33 |
} |
| 34 |
if (isset($_GET['page']) && $_GET['page'] == 'youtube_showcase_settings') { |
| 35 |
wp_enqueue_style('emd-accordion-css', $dir_url . 'assets/css/emd-accordion.css'); |
| 36 |
wp_enqueue_script('accordion'); |
| 37 |
wp_enqueue_style('codemirror-css', $dir_url . 'assets/ext/codemirror/codemirror.min.css'); |
| 38 |
wp_enqueue_script('codemirror-js', $dir_url . 'assets/ext/codemirror/codemirror.min.js', array() , '', true); |
| 39 |
wp_enqueue_script('codemirror-css-js', $dir_url . 'assets/ext/codemirror/css.min.js', array() , '', true); |
| 40 |
wp_enqueue_script('codemirror-jvs-js', $dir_url . 'assets/ext/codemirror/javascript.min.js', array() , '', true); |
| 41 |
return; |
| 42 |
} else if (isset($_GET['page']) && in_array($_GET['page'], Array( |
| 43 |
'youtube_showcase_notify' |
| 44 |
))) { |
| 45 |
wp_enqueue_style('emd-accordion-css', $dir_url . 'assets/css/emd-accordion.css'); |
| 46 |
wp_enqueue_script('accordion'); |
| 47 |
return; |
| 48 |
} else if (isset($_GET['page']) && in_array($_GET['page'], Array( |
| 49 |
'youtube_showcase_glossary' |
| 50 |
))) { |
| 51 |
wp_enqueue_style('emd-accordion-css', $dir_url . 'assets/css/emd-accordion.css'); |
| 52 |
wp_enqueue_script('accordion'); |
| 53 |
return; |
| 54 |
} else if (isset($_GET['page']) && $_GET['page'] == 'youtube_showcase') { |
| 55 |
wp_enqueue_style('lazyYT-css', $dir_url . 'assets/ext/lazyyt/lazyYT.min.css'); |
| 56 |
wp_enqueue_script('lazyYT-js', $dir_url . 'assets/ext/lazyyt/lazyYT.min.js'); |
| 57 |
wp_enqueue_script('getting-started-js', $dir_url . 'assets/js/getting-started.js'); |
| 58 |
return; |
| 59 |
} else if (isset($_GET['page']) && in_array($_GET['page'], Array( |
| 60 |
'youtube_showcase_store', |
| 61 |
'youtube_showcase_support' |
| 62 |
))) { |
| 63 |
wp_enqueue_style('admin-tabs', $dir_url . 'assets/css/admin-store.css'); |
| 64 |
return; |
| 65 |
} else if (isset($_GET['page']) && $_GET['page'] == 'youtube_showcase_licenses') { |
| 66 |
wp_enqueue_style('admin-css', $dir_url . 'assets/css/emd-admin.min.css'); |
| 67 |
return; |
| 68 |
} else if (isset($_GET['page']) && $_GET['page'] == 'youtube_showcase_shortcodes') { |
| 69 |
wp_enqueue_script('emd-copy-js', $dir_url . 'assets/js/emd-copy.js', array( |
| 70 |
'clipboard' |
| 71 |
) , ''); |
| 72 |
return; |
| 73 |
} |
| 74 |
if (in_array($typenow, Array( |
| 75 |
'emd_video' |
| 76 |
))) { |
| 77 |
$theme_changer_enq = 1; |
| 78 |
$sing_enq = 0; |
| 79 |
$tab_enq = 0; |
| 80 |
if ($hook == 'post.php' || $hook == 'post-new.php') { |
| 81 |
$unique_vars['msg'] = __('Please enter a unique value.', 'youtube-showcase'); |
| 82 |
$unique_vars['reqtxt'] = __('required', 'youtube-showcase'); |
| 83 |
$unique_vars['app_name'] = 'youtube_showcase'; |
| 84 |
$unique_vars['nonce'] = wp_create_nonce('emd_form'); |
| 85 |
$ent_list = get_option('youtube_showcase_ent_list'); |
| 86 |
if (!empty($ent_list[$typenow])) { |
| 87 |
$unique_vars['keys'] = $ent_list[$typenow]['unique_keys']; |
| 88 |
if (!empty($ent_list[$typenow]['req_blt'])) { |
| 89 |
$unique_vars['req_blt_tax'] = $ent_list[$typenow]['req_blt']; |
| 90 |
} |
| 91 |
} |
| 92 |
$tax_list = get_option('youtube_showcase_tax_list'); |
| 93 |
if (!empty($tax_list[$typenow])) { |
| 94 |
foreach ($tax_list[$typenow] as $txn_name => $txn_val) { |
| 95 |
if ($txn_val['required'] == 1) { |
| 96 |
$unique_vars['req_blt_tax'][$txn_name] = Array( |
| 97 |
'hier' => $txn_val['hier'], |
| 98 |
'type' => $txn_val['type'], |
| 99 |
'label' => $txn_val['label'] . ' ' . __('Taxonomy', 'youtube-showcase') |
| 100 |
); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
$rel_list = get_option('youtube_showcase_rel_list'); |
| 105 |
if (!empty($rel_list)) { |
| 106 |
foreach ($rel_list as $rel_name => $rel_val) { |
| 107 |
if ($rel_val['required'] == 1) { |
| 108 |
$rel_name = preg_replace('/^rel_/', '', $rel_name); |
| 109 |
if (($rel_val['show'] == 'any' || $rel_val['show'] == 'from') && $rel_val['from'] == $typenow) { |
| 110 |
$unique_vars['req_blt_tax']['p2p-from-' . $rel_name] = Array( |
| 111 |
'type' => 'rel', |
| 112 |
'label' => $rel_val['from_title'] . ' ' . __('Relationship', 'youtube-showcase') |
| 113 |
); |
| 114 |
} elseif ($rel_val['show'] == 'to' && $rel_val['to'] == $typenow) { |
| 115 |
$unique_vars['req_blt_tax']['p2p-to-' . $rel_name] = Array( |
| 116 |
'type' => 'rel', |
| 117 |
'label' => $rel_val['to_title'] . ' ' . __('Relationship', 'youtube-showcase') |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
wp_enqueue_script('unique_validate-js', $dir_url . 'assets/js/unique_validate.js', array( |
| 124 |
'jquery', |
| 125 |
'jquery-validate' |
| 126 |
) , YOUTUBE_SHOWCASE_VERSION, true); |
| 127 |
wp_localize_script("unique_validate-js", 'unique_vars', $unique_vars); |
| 128 |
} elseif ($hook == 'edit.php') { |
| 129 |
wp_enqueue_style('youtube-showcase-allview-css', YOUTUBE_SHOWCASE_PLUGIN_URL . '/assets/css/allview.css'); |
| 130 |
emd_lite_admin_enq_files('youtube_showcase', $hook); |
| 131 |
} |
| 132 |
switch ($typenow) { |
| 133 |
case 'emd_video': |
| 134 |
break; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
add_action('wp_enqueue_scripts', 'youtube_showcase_frontend_scripts'); |
| 139 |
/** |
| 140 |
* Enqueue style and js for each frontend entity pages and components |
| 141 |
* |
| 142 |
* @since WPAS 4.0 |
| 143 |
* |
| 144 |
*/ |
| 145 |
function youtube_showcase_frontend_scripts() { |
| 146 |
$dir_url = YOUTUBE_SHOWCASE_PLUGIN_URL; |
| 147 |
wp_register_style('emd-pagination', $dir_url . 'assets/css/emd-pagination.min.css', '', YOUTUBE_SHOWCASE_VERSION); |
| 148 |
wp_register_script('emd-widg-paging-js', $dir_url . 'assets/js/emd-widg-paging.js', '', YOUTUBE_SHOWCASE_VERSION, true); |
| 149 |
wp_register_style('youtube-showcase-allview-css', $dir_url . '/assets/css/allview.css', '', YOUTUBE_SHOWCASE_VERSION); |
| 150 |
$grid_vars = Array(); |
| 151 |
$local_vars['ajax_url'] = admin_url('admin-ajax.php'); |
| 152 |
$wpas_shc_list = get_option('youtube_showcase_shc_list'); |
| 153 |
wp_register_style('wpas-css', $dir_url . 'assets/ext/wpas/wpas.min.css', '', YOUTUBE_SHOWCASE_VERSION); |
| 154 |
wp_register_script('wpas-js', $dir_url . 'assets/ext/wpas/wpas.min.js', array( |
| 155 |
'jquery' |
| 156 |
) , YOUTUBE_SHOWCASE_VERSION); |
| 157 |
wp_register_script('video-gallery-js', $dir_url . 'assets/js/video-gallery.js', '', YOUTUBE_SHOWCASE_VERSION, true); |
| 158 |
wp_register_script('ytscjs', $dir_url . 'assets/js/ytscjs.js', '', YOUTUBE_SHOWCASE_VERSION, true); |
| 159 |
wp_register_script('ytsc-js', $dir_url . 'assets/js/ytsc.js', '', YOUTUBE_SHOWCASE_VERSION, true); |
| 160 |
do_action('emd_localize_scripts', 'youtube_showcase'); |
| 161 |
if (is_single() && get_post_type() == 'emd_video') { |
| 162 |
youtube_showcase_enq_bootstrap(); |
| 163 |
do_action('emd_enqueue_sat_view', 'youtube-showcase', 'emd_video', 'single'); |
| 164 |
wp_enqueue_style('youtube-showcase-allview-css'); |
| 165 |
youtube_showcase_enq_custom_css_js(); |
| 166 |
return; |
| 167 |
} |
| 168 |
} |
| 169 |
function youtube_showcase_enq_bootstrap($type = '') { |
| 170 |
$misc_settings = get_option('youtube_showcase_misc_settings'); |
| 171 |
if ($type == 'css' || $type == '') { |
| 172 |
if (empty($misc_settings) || (isset($misc_settings['disable_bs_css']) && $misc_settings['disable_bs_css'] == 0)) { |
| 173 |
wp_enqueue_style('wpas-css'); |
| 174 |
} |
| 175 |
} |
| 176 |
if ($type == 'js' || $type == '') { |
| 177 |
if (empty($misc_settings) || (isset($misc_settings['disable_bs_js']) && $misc_settings['disable_bs_js'] == 0)) { |
| 178 |
wp_enqueue_script('wpas-js'); |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
/** |
| 183 |
* Enqueue custom css if set in settings tool tab |
| 184 |
* |
| 185 |
* @since WPAS 5.3 |
| 186 |
* |
| 187 |
*/ |
| 188 |
function youtube_showcase_enq_custom_css_js() { |
| 189 |
$tools = get_option('youtube_showcase_tools'); |
| 190 |
if (!empty($tools['custom_css'])) { |
| 191 |
$url = home_url(); |
| 192 |
if (is_ssl()) { |
| 193 |
$url = home_url('/', 'https'); |
| 194 |
} |
| 195 |
wp_register_style('youtube-showcase-custom', false); |
| 196 |
wp_enqueue_style('youtube-showcase-custom'); |
| 197 |
wp_add_inline_style('youtube-showcase-custom', $tools['custom_css']); |
| 198 |
} |
| 199 |
if (!empty($tools['custom_js'])) { |
| 200 |
$url = home_url(); |
| 201 |
if (is_ssl()) { |
| 202 |
$url = home_url('/', 'https'); |
| 203 |
} |
| 204 |
wp_register_script('youtube-showcase-custom', false); |
| 205 |
wp_enqueue_script('youtube-showcase-custom'); |
| 206 |
wp_add_inline_script('youtube-showcase-custom', $tools['custom_js']); |
| 207 |
} |
| 208 |
} |
| 209 |
/** |
| 210 |
* Enqueue if allview css is not enqueued |
| 211 |
* |
| 212 |
* @since WPAS 4.5 |
| 213 |
* |
| 214 |
*/ |
| 215 |
function youtube_showcase_enq_allview() { |
| 216 |
if (!wp_style_is('youtube-showcase-allview-css', 'enqueued')) { |
| 217 |
wp_enqueue_style('youtube-showcase-allview-css'); |
| 218 |
} |
| 219 |
} |
| 220 |
add_action('admin_print_footer_scripts', 'youtube_showcase_edit_next_prev_button'); |
| 221 |
function youtube_showcase_edit_next_prev_button() { |
| 222 |
$screen = get_current_screen(); |
| 223 |
$supported_types = array( |
| 224 |
'emd_video' |
| 225 |
); |
| 226 |
if (strpos($screen->parent_file, 'edit.php') !== false && in_array($screen->id, $supported_types) && in_array($screen->post_type, $supported_types) && $screen->action != 'add') { |
| 227 |
$next_post = get_previous_post(); |
| 228 |
$previous_post = get_next_post(); |
| 229 |
$next_post_id = 0; |
| 230 |
if ($next_post && $next_post->ID) { |
| 231 |
$next_post_id = $next_post->ID; |
| 232 |
} |
| 233 |
$previous_post_id = 0; |
| 234 |
if ($previous_post && $previous_post->ID) { |
| 235 |
$previous_post_id = $previous_post->ID; |
| 236 |
} |
| 237 |
?> |
| 238 |
<script> |
| 239 |
if(window.jQuery) { |
| 240 |
jQuery(document).ready(function($) { |
| 241 |
$(window).load(function() { |
| 242 |
<?php if ($next_post_id) { ?> |
| 243 |
var is_next_post_available = true; |
| 244 |
<?php |
| 245 |
} else { ?> |
| 246 |
var is_next_post_available = false; |
| 247 |
<?php |
| 248 |
} |
| 249 |
if ($previous_post_id) { ?> |
| 250 |
var is_prev_post_available = true; |
| 251 |
<?php |
| 252 |
} else { ?> |
| 253 |
var is_prev_post_available = false; |
| 254 |
<?php |
| 255 |
} |
| 256 |
if ($screen->is_block_editor) { ?> |
| 257 |
if(is_prev_post_available && is_next_post_available){ |
| 258 |
$('.edit-post-header__settings').prepend('<a href="<?php echo get_edit_post_link($previous_post_id) ?>" class="prev-post components-button editor-post-preview is-button is-primary is-large">← <?php esc_html_e('Previous', 'youtube-showcase') ?></a><a href="<?php echo get_edit_post_link($next_post_id) ?>" class="next-post components-button editor-post-preview is-button is-primary is-large"><?php esc_html_e('Next', 'youtube-showcase') ?> →</a>'); |
| 259 |
}else if(is_prev_post_available && !is_next_post_available){ |
| 260 |
$('.edit-post-header__settings').prepend('<a href="<?php echo get_edit_post_link($previous_post_id) ?>" class="prev-post components-button editor-post-preview is-button is-primary is-large">← <?php esc_html_e('Previous', 'youtube-showcase') ?></a>'); |
| 261 |
}else if(is_next_post_available && !is_prev_post_available){ |
| 262 |
$('.edit-post-header__settings').prepend('<a href="<?php echo get_edit_post_link($next_post_id) ?>" class="next-post components-button editor-post-preview is-button is-primary is-large"><?php esc_html_e('Next', 'youtube-showcase') ?> →</a>'); |
| 263 |
} |
| 264 |
<?php |
| 265 |
} else { ?> |
| 266 |
if(is_prev_post_available && is_next_post_available){ |
| 267 |
$('.wrap .page-title-action').after('<a href="<?php echo get_edit_post_link($previous_post_id) ?>" class="prev-post page-title-action">← <?php esc_html_e('Previous', 'youtube-showcase') ?></a><a href="<?php echo get_edit_post_link($next_post_id) ?>" class="next-post page-title-action"><?php esc_html_e('Next', 'youtube-showcase') ?> →</a>'); |
| 268 |
}else if(is_prev_post_available && !is_next_post_available){ |
| 269 |
$('.wrap .page-title-action').after('<a href="<?php echo get_edit_post_link($previous_post_id) ?>" class="prev-post page-title-action">← <?php esc_html_e('Previous', 'youtube-showcase') ?></a>'); |
| 270 |
}else if(is_next_post_available && !is_prev_post_available){ |
| 271 |
$('.wrap .page-title-action').after('<a href="<?php echo get_edit_post_link($next_post_id) ?>" class="next-post page-title-action"><?php esc_html_e('Next', 'youtube-showcase') ?> →</a>'); |
| 272 |
} |
| 273 |
<?php |
| 274 |
} ?> |
| 275 |
}); |
| 276 |
}); |
| 277 |
} |
| 278 |
</script> |
| 279 |
<?php |
| 280 |
} |
| 281 |
} |