| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package GamiPress\Presto_Player\Functions |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Overrides GamiPress AJAX Helper for selecting posts |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
function gamipress_presto_player_ajax_get_posts() { |
| 18 |
|
| 19 |
// Security check, forces to die if not security passed |
| 20 |
check_ajax_referer( 'gamipress_admin', 'nonce' ); |
| 21 |
|
| 22 |
// Check if user can manage GamiPress |
| 23 |
if( ! current_user_can( gamipress_get_manager_capability() ) ) { |
| 24 |
wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'gamipress' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
global $wpdb; |
| 28 |
|
| 29 |
if( isset( $_REQUEST['post_type'] ) && in_array( 'presto_player_video', $_REQUEST['post_type'] ) ) { |
| 30 |
|
| 31 |
// Pull back the search string |
| 32 |
$search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : ''; |
| 33 |
$results = array(); |
| 34 |
|
| 35 |
if( gamipress_is_network_wide_active() ) { |
| 36 |
|
| 37 |
// Look for results on all sites on a multisite install |
| 38 |
|
| 39 |
foreach( gamipress_get_network_site_ids() as $site_id ) { |
| 40 |
|
| 41 |
// Switch to site |
| 42 |
switch_to_blog( $site_id ); |
| 43 |
|
| 44 |
// Get the current site name to append it to results |
| 45 |
$site_name = get_bloginfo( 'name' ); |
| 46 |
|
| 47 |
$site_videos = $wpdb->get_results( $wpdb->prepare( |
| 48 |
"SELECT v.id AS ID, v.title AS post_title |
| 49 |
FROM {$wpdb->prefix}presto_player_videos AS v |
| 50 |
WHERE v.title LIKE %s", |
| 51 |
"%%{$search}%%" |
| 52 |
) ); |
| 53 |
|
| 54 |
foreach ( $site_videos as $video ) { |
| 55 |
|
| 56 |
// Results should meet same structure like posts |
| 57 |
$results[] = array( |
| 58 |
'ID' => $video->ID, |
| 59 |
'post_title' => $video->post_title, |
| 60 |
'site_id' => $site_id, |
| 61 |
'site_name' => $site_name, |
| 62 |
); |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
// Restore current site |
| 67 |
restore_current_blog(); |
| 68 |
|
| 69 |
} |
| 70 |
} else { |
| 71 |
|
| 72 |
$results = $wpdb->get_results( $wpdb->prepare( |
| 73 |
"SELECT v.id AS ID, v.title AS post_title |
| 74 |
FROM {$wpdb->prefix}presto_player_videos AS v |
| 75 |
WHERE v.title LIKE %s", |
| 76 |
"%%{$search}%%" |
| 77 |
) ); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
// Return our results |
| 82 |
wp_send_json_success( $results ); |
| 83 |
die; |
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_presto_player_ajax_get_posts', 5 ); |
| 88 |
|
| 89 |
/** |
| 90 |
* Get Presto Player platforms |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* |
| 94 |
* @return array |
| 95 |
*/ |
| 96 |
function gamipress_preto_player_get_platforms() { |
| 97 |
|
| 98 |
return array( |
| 99 |
'youtube' => __( 'Youtube', 'gamipress' ), |
| 100 |
'vimeo' => __( 'Vimeo', 'gamipress' ), |
| 101 |
'self-hosted' => __( 'Self-hosted', 'gamipress' ), |
| 102 |
'bunny' => __( 'Bunny', 'gamipress' ), |
| 103 |
'audio' => __( 'Audio', 'gamipress' ), |
| 104 |
); |
| 105 |
|
| 106 |
} |